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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
35 | C | Fire Again | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"shortest paths"
] | C. Fire Again | 2 | 64 | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing... | The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers.
The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning... | Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. | [
"3 3\n1\n2 2\n",
"3 3\n1\n1 1\n",
"3 3\n2\n1 1 3 3\n"
] | [
"1 1\n",
"3 3\n",
"2 2"
] | none | 1,500 | [
{
"input": "3 3\n1\n2 2",
"output": "1 1"
},
{
"input": "3 3\n1\n1 1",
"output": "3 3"
},
{
"input": "3 3\n2\n1 1 3 3",
"output": "1 3"
},
{
"input": "1 1\n1\n1 1",
"output": "1 1"
},
{
"input": "2 2\n1\n2 2",
"output": "1 1"
},
{
"input": "2 2\n2\n1 1... | 1,679,979,115 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 998 | 4,505,600 | import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
k = int(input())
xy = list(map(int, input().split()))
ma, u, v = 0, 1, 1
for i in range(1, n + 1):
for j in range(1, m + 1):
c = n + m
fo... | Title: Fire Again
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th... | ```python
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
k = int(input())
xy = list(map(int, input().split()))
ma, u, v = 0, 1, 1
for i in range(1, n + 1):
for j in range(1, m + 1):
c = n + m
... | 3.716931 |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,588,701,532 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 140 | 0 | n=list(input())
l=["a","h","1","8"]
if(n[0] in l or n[1] in l):
if(n[0] in l and n[1] in l):
print(3)
else:
print(5)
else:
print(8) | Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
n=list(input())
l=["a","h","1","8"]
if(n[0] in l or n[1] in l):
if(n[0] in l and n[1] in l):
print(3)
else:
print(5)
else:
print(8)
``` | 3 | |
328 | B | Sheldon and Ice Pieces | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number *t*. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to... | The first line contains integer *t* (1<=≤<=*t*<=≤<=10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9. | Print the required number of instances. | [
"42\n23454\n",
"169\n12118999\n"
] | [
"2\n",
"1\n"
] | This problem contains very weak pretests. | 500 | [
{
"input": "42\n23454",
"output": "2"
},
{
"input": "169\n12118999",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "7\n777",
"output": "3"
},
{
"input": "18\n8118",
"output": "2"
},
{
"input": "33\n33333333",
"output": "4"
},
... | 1,568,293,890 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 18 | 342 | 409,600 | s1=input()
s2=input()
n=len(s1)
m=len(s2)
from collections import Counter
c1=Counter(s1)
c2=Counter(s2)
if c1['2'] and c1['5']:
have=(c2['2']+c2['5'])//2
elif c1['2'] or c1['5']:
have=c2['2']+c2['5']
if c1['6'] and c1['9']:
have2=(c2['6']+c2['9'])//2
elif c1['6'] or c1['9']:
have2=c2['6... | Title: Sheldon and Ice Pieces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his fav... | ```python
s1=input()
s2=input()
n=len(s1)
m=len(s2)
from collections import Counter
c1=Counter(s1)
c2=Counter(s2)
if c1['2'] and c1['5']:
have=(c2['2']+c2['5'])//2
elif c1['2'] or c1['5']:
have=c2['2']+c2['5']
if c1['6'] and c1['9']:
have2=(c2['6']+c2['9'])//2
elif c1['6'] or c1['9']:
h... | 0 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,696,341,591 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n=int(input())
l=list(map(int, input().split()))
m= max(l)
to = sum(m - wealth for wealth in l)
print(to)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n=int(input())
l=list(map(int, input().split()))
m= max(l)
to = sum(m - wealth for wealth in l)
print(to)
``` | 3 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,615,031,322 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n = int(input())
s = str(input())
ans = 'YES'
for i in range(1, n):
if i%2 == 1 and int(s[i])%2 != int(s[0]):
continue
elif i%2 == 0 and int(s[i])%2 == int(s[0]):
continue
else :
ans = 'NO'
break
print(ans)
| Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
n = int(input())
s = str(input())
ans = 'YES'
for i in range(1, n):
if i%2 == 1 and int(s[i])%2 != int(s[0]):
continue
elif i%2 == 0 and int(s[i])%2 == int(s[0]):
continue
else :
ans = 'NO'
break
print(ans)
``` | 0 | |
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "75... | 1,596,554,113 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e9;
ll f(ll k) {
return (k+1)*k/2;
}
int main() {
ll t,n,l,r,mid;
scanf("%lld",&t);
while(t--) {
scanf("%lld",&n);
l=1;
r=min(n+1,N);
while(l+1<r) {
mid=(l+r)/2;
if(f(mid)<=n)
l=mid;
else
r=mid... | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e9;
ll f(ll k) {
return (k+1)*k/2;
}
int main() {
ll t,n,l,r,mid;
scanf("%lld",&t);
while(t--) {
scanf("%lld",&n);
l=1;
r=min(n+1,N);
while(l+1<r) {
mid=(l+r)/2;
if(f(mid)<=n)
l=mid;
else
... | -1 |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,595,993,190 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 12,492,800 | # -*- coding: utf-8 -*-
"""
Created on Wed Jul 29 08:53:49 2020
@author: Harshal
"""
n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
ans=0
while len(arr)>1:
ans+=sum(arr)
x=arr.pop()
ans+=x
print(ans+arr[0])
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 29 08:53:49 2020
@author: Harshal
"""
n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
ans=0
while len(arr)>1:
ans+=sum(arr)
x=arr.pop()
ans+=x
print(ans+arr[0])
``` | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,593,882,701 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 6,656,000 | arr= list(map(int,input().split()))
side=int(arr[0]**0.5)
length=arr[1]//side
print(4*(2*side+length)) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
arr= list(map(int,input().split()))
side=int(arr[0]**0.5)
length=arr[1]//side
print(4*(2*side+length))
``` | 0 | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,584,553,324 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | pos = 0
i = 1
x = int(input())
while pos+i<=x:
if pos + i > x:
pos -= i
else:
pos += i
i += 1
print(i+1) | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
pos = 0
i = 1
x = int(input())
while pos+i<=x:
if pos + i > x:
pos -= i
else:
pos += i
i += 1
print(i+1)
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack ca... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. | Print the only integer – the maximum total value of all boxes with cakes. | [
"4 1\n1 2 2 1\n",
"7 2\n1 3 3 1 4 4 4\n",
"8 3\n7 7 8 7 7 8 1 7\n"
] | [
"2\n",
"5\n",
"6\n"
] | In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box... | 0 | [] | 1,698,000,806 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
// dp[i][k] = max_{j<=i}{dp[j][k-1]} + Merge(j, i)
void solve()
{
int n, k;
cin >> n >> k;
vector<int> a(n + 5);
for (int i = 1; i <= n; i++... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the incom... | ```python
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
// dp[i][k] = max_{j<=i}{dp[j][k-1]} + Merge(j, i)
void solve()
{
int n, k;
cin >> n >> k;
vector<int> a(n + 5);
for (int i = 1; i... | -1 | |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,673,622,866 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 93 | 23,347,200 | import math
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
cnt = {}
for i in a:
if i not in cnt:
cnt[i] = 0
cnt[i] += 1
totalComb = math.comb(len(a), 2)
for i in cnt:
if cnt[i] >= 2:
totalComb -= math.comb(cnt[i], 2)
print(totalComb)
| Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
import math
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
cnt = {}
for i in a:
if i not in cnt:
cnt[i] = 0
cnt[i] += 1
totalComb = math.comb(len(a), 2)
for i in cnt:
if cnt[i] >= 2:
totalComb -= math.comb(cnt[i], 2)
print(totalComb)
``... | 3 | |
168 | B | Wizards and Minimal Spell | PROGRAMMING | 1,700 | [
"implementation",
"strings"
] | null | null | Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.
Each spell consists of several lines. The line, whose first non-space chara... | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (<==<=220) bytes. Newlines are included in this size.
In the Windows operating system used on the... | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline.
Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | [
"# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}\n",
"#\n\n#\n"
] | [
"# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}\n",
"#\n\n#\n"
] | In the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.
In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | 1,000 | [
{
"input": " # include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}",
"output": " # include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}"
},
{
"input": "#\n\n#",
"output": "#\n\n#"
},
{
"input": "#\n \n#",
"... | 1,600,668,050 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | import sys
cache = ''
for line in sys.stdin:
try:
if line.strip()[0] == '#':
if cache != '':
print(cache)
cache = ''
print(line)
else:
for char in line:
if char not in [' ', '\n']:
... | Title: Wizards and Minimal Spell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know ... | ```python
import sys
cache = ''
for line in sys.stdin:
try:
if line.strip()[0] == '#':
if cache != '':
print(cache)
cache = ''
print(line)
else:
for char in line:
if char not in [' ', '\n']:
... | 0 | |
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,554,962,629 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 1,126,400 |
n=int(input())
ok=[]
#mindiff=float('inf')
arr1=list(map(int,input().split()))
for i in range(len(arr1)):
if arr1[i]==min(arr1):
ok.append(i)
mindiff=ok[1]-ok[0]
for i in range(2,len(ok)):
mindiff=min(mindiff,ok[i]-ok[i-1])
print(mindiff)
| Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
n=int(input())
ok=[]
#mindiff=float('inf')
arr1=list(map(int,input().split()))
for i in range(len(arr1)):
if arr1[i]==min(arr1):
ok.append(i)
mindiff=ok[1]-ok[0]
for i in range(2,len(ok)):
mindiff=min(mindiff,ok[i]-ok[i-1])
print(mindiff)
``` | 0 | |
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not ... | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20... | 1,690,887,207 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a = list(map(int, input().split()))
for i in range(len(a)):
for j in range(len(a)-i-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print(*a)
| Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the bo... | ```python
a = list(map(int, input().split()))
for i in range(len(a)):
for j in range(len(a)-i-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print(*a)
``` | 0 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,657,190,509 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 93 | 0 | l=list(map(int,input().split()))
t=0
for i in range(l[0]):
n=list(input())
if "C" in n or "M" in n or "Y" in n:
t=1
if t==1:
print("#Color")
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
l=list(map(int,input().split()))
t=0
for i in range(l[0]):
n=list(input())
if "C" in n or "M" in n or "Y" in n:
t=1
if t==1:
print("#Color")
else:
print("#Black&White")
``` | 3 | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,692,057,900 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 130,662,400 | def func(x,n):
if n == 0 :
return 1
if n % 2 == 0 :
return func(x**2,n//2)
else :
return x*func(x,n-1)
n = (int(input()))
m = (int(input()))
print(m%func(2,n)) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
def func(x,n):
if n == 0 :
return 1
if n % 2 == 0 :
return func(x**2,n//2)
else :
return x*func(x,n-1)
n = (int(input()))
m = (int(input()))
print(m%func(2,n))
``` | 0 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,479,872,382 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 278 | 7,270,400 | n = int(input())
stripes = list(map(int, input().split(" ")))
total = sum(stripes)
leftSum = 0
ways = 0
for i in range(n-1):
leftSum = leftSum + stripes[i]
if(2*leftSum == total):
ways = ways + 1
print(ways)
| Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
stripes = list(map(int, input().split(" ")))
total = sum(stripes)
leftSum = 0
ways = 0
for i in range(n-1):
leftSum = leftSum + stripes[i]
if(2*leftSum == total):
ways = ways + 1
print(ways)
``` | 3.876331 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,672,054,761 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s1=input()
s2=input()
s=s1(: :-1)
if s==s2 :
print("Yes")
else :
print("No") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s1=input()
s2=input()
s=s1(: :-1)
if s==s2 :
print("Yes")
else :
print("No")
``` | -1 |
48 | A | Rock-paper-scissors | PROGRAMMING | 900 | [
"implementation",
"schedules"
] | A. Rock-paper-scissors | 2 | 256 | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. | Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". | [
"rock\nrock\nrock\n",
"paper\nrock\nrock\n",
"scissors\nrock\nrock\n",
"scissors\npaper\nrock\n"
] | [
"?\n",
"F\n",
"?\n",
"?\n"
] | none | 0 | [
{
"input": "rock\nrock\nrock",
"output": "?"
},
{
"input": "paper\nrock\nrock",
"output": "F"
},
{
"input": "scissors\nrock\nrock",
"output": "?"
},
{
"input": "scissors\npaper\nrock",
"output": "?"
},
{
"input": "paper\npaper\nrock",
"output": "?"
},
{
... | 1,575,716,177 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 310 | 0 | def fun(a,b):
for i in range(len(a)):
if a[i]==b:
break
if i==0:
return "F"
elif i==1:
return "M"
else:
return "S"
a=set()
b={}
e=[]
b["rock"]=0
b["paper"]=0
b["scissors"]=0
for i in range(3):
c=input()
b[c]+=1
e.append(c)
... | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
def fun(a,b):
for i in range(len(a)):
if a[i]==b:
break
if i==0:
return "F"
elif i==1:
return "M"
else:
return "S"
a=set()
b={}
e=[]
b["rock"]=0
b["paper"]=0
b["scissors"]=0
for i in range(3):
c=input()
b[c]+=1
e.app... | 0 |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,692,623,207 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | t = int(input())
for _ in range(t):
x = int(input())
s = (x * (x+1)) // 2
y = 1
z = 0
while y <= x:
z += y
y *= 2
print(s - z*2)
| Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
t = int(input())
for _ in range(t):
x = int(input())
s = (x * (x+1)) // 2
y = 1
z = 0
while y <= x:
z += y
y *= 2
print(s - z*2)
``` | 3 | |
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,500,714,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,608,000 | n=int(input())
a=[[0 for col in range(n)] for row in range(n)]
b=[[0 for col in range(n)] for row in range(n)]
for i in range(n):
a[i]=list(map(int,input().split()))
b[i]=a[i]
#print(b[i])
for i in range(n):
for j in range(n):
if a[i][j]!=1:
if not any(a[i][j]-x in b[j] for x in a[i]):
print("No... | 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())
a=[[0 for col in range(n)] for row in range(n)]
b=[[0 for col in range(n)] for row in range(n)]
for i in range(n):
a[i]=list(map(int,input().split()))
b[i]=a[i]
#print(b[i])
for i in range(n):
for j in range(n):
if a[i][j]!=1:
if not any(a[i][j]-x in b[j] for x in a[i]):
... | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,647,334,767 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 124 | 102,400 | def main():
ans=0
s=input()
num=0
if(len(s)==1):
print(0)
return
else:
for x in s:
num+=int(x)
ans+=1
while(num//10!=0):
s=str(num)
... | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
def main():
ans=0
s=input()
num=0
if(len(s)==1):
print(0)
return
else:
for x in s:
num+=int(x)
ans+=1
while(num//10!=0):
s=str(num)... | 3.968816 |
40 | D | Interesting Sequence | PROGRAMMING | 2,600 | [
"math"
] | D. Interesting Sequence | 3 | 256 | Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A... | The first line contains integer *A* (1<=≤<=*A*<=<<=10300). It is guaranteed that the number doesn't contain leading zeros. | On the first output line print YES, if there could be a year in which the total population of the country equaled *A*, otherwise print NO.
If the answer is YES, then you also have to print number *k* — the number of years in which the population could equal *A*. On the next line you have to output precisely *k* space... | [
"2\n",
"3\n",
"13\n",
"1729\n"
] | [
"YES\n1\n1\n0\n",
"NO\n",
"YES\n1\n2\n0\n",
"YES\n1\n4\n1\n156\n"
] | none | 2,000 | [
{
"input": "2",
"output": "YES\n1\n1\n0"
},
{
"input": "3",
"output": "NO"
},
{
"input": "13",
"output": "YES\n1\n2\n0"
},
{
"input": "1729",
"output": "YES\n1\n4\n1\n156"
},
{
"input": "1",
"output": "NO"
},
{
"input": "156",
"output": "YES\n1\n4\... | 1,534,375,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 404 | 1,126,400 | from fractions import Fraction
import sys
sys.setrecursionlimit(1000*100)
A=int(input())
p=[]
c=1
for _ in range(300):
p.append(c)
c*=12
r=[]
for i in range(300):
for j in range(i+1):
if p[j]+p[i-j]==A:
r.append(i+1)
break
s=set()
for i in r:
for j in range(i):
... | Title: Interesting Sequence
Time Limit: 3 seconds
Memory Limit: 256 megabytes
Problem Description:
Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the momen... | ```python
from fractions import Fraction
import sys
sys.setrecursionlimit(1000*100)
A=int(input())
p=[]
c=1
for _ in range(300):
p.append(c)
c*=12
r=[]
for i in range(300):
for j in range(i+1):
if p[j]+p[i-j]==A:
r.append(i+1)
break
s=set()
for i in r:
for j in range(i... | 0 |
250 | C | Movie Critics | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*.
On the *i*-th day the festival will show a movie of genre *a**i*. We know that a movie of each of *k* genres occurs in the fes... | The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=105), where *n* is the number of movies and *k* is the number of genres.
The second line of the input contains a sequence of *n* positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*k*), where *a**i* is the genre of the *i*-th... | Print a single number — the number of the genre (from 1 to *k*) of the excluded films. If there are multiple answers, print the genre with the minimum number. | [
"10 3\n1 1 2 3 2 3 3 1 1 3\n",
"7 3\n3 1 3 2 3 1 2\n"
] | [
"3",
"1"
] | In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses... | 1,500 | [
{
"input": "10 3\n1 1 2 3 2 3 3 1 1 3",
"output": "3"
},
{
"input": "7 3\n3 1 3 2 3 1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "10 2\n1 2 2 1 1 2 1 1 2 2",
"output": "1"
},
{
"input": "10 10\n5 7 8 2 4 10 1 3 9 6",
"output": "1"
... | 1,597,912,942 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 310 | 1,843,200 | import math
#n,m=map(int,input().split())
from collections import Counter
#for i in range(n):
import math
#for _ in range(int(input())):
#n = int(input())
#for _ in range(int(input())):
#n = int(input())
import bisect
'''for _ in range(int(input())):
n=int(input())
n,k=map(int, input().split())
... | Title: Movie Critics
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*.
On the *i*-th day the festi... | ```python
import math
#n,m=map(int,input().split())
from collections import Counter
#for i in range(n):
import math
#for _ in range(int(input())):
#n = int(input())
#for _ in range(int(input())):
#n = int(input())
import bisect
'''for _ in range(int(input())):
n=int(input())
n,k=map(int, input()... | 0 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,699,204,486 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 46 | 1,126,400 | a=int(input())
b=list(map(int,input().split()))
c=1
n=[]
for i in range(a-1):
if b[i]<=b[i+1]:
c+=1
else:
c=1
n.append(c)
print(max(n)) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
a=int(input())
b=list(map(int,input().split()))
c=1
n=[]
for i in range(a-1):
if b[i]<=b[i+1]:
c+=1
else:
c=1
n.append(c)
print(max(n))
``` | -1 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,633,964,332 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 7,168,000 | n = int(input())
s = input()
while '01'in s or '10'in s:
s = s.replace('01','')
s = s.replace('10','')
print(len(s)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
n = int(input())
s = input()
while '01'in s or '10'in s:
s = s.replace('01','')
s = s.replace('10','')
print(len(s))
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,665,252,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=input()
x=[int(y) for y in input().split()]
a=[]
b=[]
for i in range(len(x)):
if x[i]%2==0:
a.append(x[i])
else:
b.append(x[i])
if len(a)>1:
print(b[0])
else:
print(a[0]) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=input()
x=[int(y) for y in input().split()]
a=[]
b=[]
for i in range(len(x)):
if x[i]%2==0:
a.append(x[i])
else:
b.append(x[i])
if len(a)>1:
print(b[0])
else:
print(a[0])
``` | 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,644,349,925 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | word= input()
hello= "hello"
for i in word:
if(len(hello)==0):
print("YES")
break
if i==hello[0]:
hello=hello[1:]
if(len(hello)!=0):
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
word= input()
hello= "hello"
for i in word:
if(len(hello)==0):
print("YES")
break
if i==hello[0]:
hello=hello[1:]
if(len(hello)!=0):
print("NO")
``` | 0 |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,571,455,936 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 327 | 32,051,200 | import sys
def B():
count = int(sys.stdin.readline().strip("\n").split(" ")[0])
arr = []
while count > 0:
arr.append(sys.stdin.readline().strip("\n").split(" "))
count = count - 1
a, b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
for cls in ... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
import sys
def B():
count = int(sys.stdin.readline().strip("\n").split(" ")[0])
arr = []
while count > 0:
arr.append(sys.stdin.readline().strip("\n").split(" "))
count = count - 1
a, b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
f... | 0 | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,654,627,715 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,a = map(int,input().split(" "))
t = list(map(int,input().split(" ")))
count = 0
flag = 0
for i in range(0,len(t)):
if(t[i]==1 and t[i+1]==1):
count += 1
flag = 1
elif(a>t.count(1)):
flag = 0
if(flag == 1):
print(count)
elif(flag == 0):
print(t.count(1)) | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
n,a = map(int,input().split(" "))
t = list(map(int,input().split(" ")))
count = 0
flag = 0
for i in range(0,len(t)):
if(t[i]==1 and t[i+1]==1):
count += 1
flag = 1
elif(a>t.count(1)):
flag = 0
if(flag == 1):
print(count)
elif(flag == 0):
print(t.count(1))
`... | 0 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,648,273,537 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 1,622 | 17,510,400 | n = int(input())
arr = []
best_length = -1
best_lo = None
best_hi = None
best_idx = 0
for i in range(n):
lo, hi = [int(x) for x in input().split()]
if hi-lo > best_length:
best_length = hi-lo
best_lo = lo
best_hi = hi
best_idx = i+1
arr.append([lo,hi])
overlap... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n = int(input())
arr = []
best_length = -1
best_lo = None
best_hi = None
best_idx = 0
for i in range(n):
lo, hi = [int(x) for x in input().split()]
if hi-lo > best_length:
best_length = hi-lo
best_lo = lo
best_hi = hi
best_idx = i+1
arr.append([lo,hi])
... | 3 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,566,309,788 | 2,147,483,647 | PyPy 3 | OK | TESTS | 85 | 374 | 16,588,800 | n = int(input())
s = input()
x = list(map(int, input().split()))
minimum = 10000000000
if s.count('RL') == 0:
print(-1)
else:
for i in range(n - 1):
if s[i] == 'R' and s[i + 1] == 'L' and x[i + 1] - x[i] < minimum:
minimum = x[i + 1] - x[i]
print(minimum // 2)
| Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n = int(input())
s = input()
x = list(map(int, input().split()))
minimum = 10000000000
if s.count('RL') == 0:
print(-1)
else:
for i in range(n - 1):
if s[i] == 'R' and s[i + 1] == 'L' and x[i + 1] - x[i] < minimum:
minimum = x[i + 1] - x[i]
print(minimum // 2)
``` | 3 | |
607 | A | Chain Reaction | PROGRAMMING | 1,600 | [
"binary search",
"dp"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however.... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beac... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | 500 | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
... | 1,617,345,969 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 467 | 11,878,400 | import sys,os,io
from sys import stdin
from bisect import bisect_left , bisect_right
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = io.BytesIO(... | Title: Chain Reaction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of d... | ```python
import sys,os,io
from sys import stdin
from bisect import bisect_left , bisect_right
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = i... | 3 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,564,332,570 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 218 | 0 | n, m = map(int, input().split())
min_for_all = n // m
kol_of_max = n - m * min_for_all
for i in range(m - kol_of_max):
print(min_for_all, end = " ")
for i in range(kol_of_max):
print(min_for_all + 1, end = " ") | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
n, m = map(int, input().split())
min_for_all = n // m
kol_of_max = n - m * min_for_all
for i in range(m - kol_of_max):
print(min_for_all, end = " ")
for i in range(kol_of_max):
print(min_for_all + 1, end = " ")
``` | 3 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,609,822,278 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 404 | 2,355,200 | #editorial is very clear
from collections import *
import bisect
import heapq
SIZE = 1000
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def bfs(xy, start):
visited[xy][start] = True
to_visit = deque()
to_visit.append((xy, start))
have_child = False
while to_visit:
xy... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
#editorial is very clear
from collections import *
import bisect
import heapq
SIZE = 1000
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def bfs(xy, start):
visited[xy][start] = True
to_visit = deque()
to_visit.append((xy, start))
have_child = False
while to_v... | 3 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,598,236,394 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 6,963,200 | def q66b():
n = int(input())
sections_list = [int(num) for num in input().split()]
max_no = -1
for i in range(len(sections_list)):
print("find_num_sections, %d" %(i))
num_sections = find_num_sections(sections_list, i)
if(num_sections > max_no):
max_no = num_sections
print(max_no)
def find_num_sections(ar... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
def q66b():
n = int(input())
sections_list = [int(num) for num in input().split()]
max_no = -1
for i in range(len(sections_list)):
print("find_num_sections, %d" %(i))
num_sections = find_num_sections(sections_list, i)
if(num_sections > max_no):
max_no = num_sections
print(max_no)
def find_num_s... | 0 |
171 | E | MYSTERIOUS LANGUAGE | PROGRAMMING | 2,000 | [
"*special"
] | null | null | You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. | This program has only one test, and it's empty (it doesn't give your program anything to read). | Output the name of the mysterious language. | [] | [] | none | 0 | [
{
"input": "1",
"output": "INTERCAL"
}
] | 1,507,455,369 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int MOD=1e9+7;
int main()
{
printf("FORTRAN\n");
return 0;
}
| Title: MYSTERIOUS LANGUAGE
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this langu... | ```python
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int MOD=1e9+7;
int main()
{
printf("FORTRAN\n");
return 0;
}
``` | -1 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,575,982,740 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | N = int(input())
R = input().split()
r = [int(i) for i in R]
S = []
for i in range(1,len(r)):
Q = (r[i]-r[0])/i
S.append(Q)
if len(set(S)) == 2:
W = list(set(S))
a = W[0]
b = W[1]
D = float(sum(S)/len(S))
if ((len(S)-1)*a + b)/len(S) == D:
k = b
else:
k = a... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
N = int(input())
R = input().split()
r = [int(i) for i in R]
S = []
for i in range(1,len(r)):
Q = (r[i]-r[0])/i
S.append(Q)
if len(set(S)) == 2:
W = list(set(S))
a = W[0]
b = W[1]
D = float(sum(S)/len(S))
if ((len(S)-1)*a + b)/len(S) == D:
k = b
else:
... | 0 |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,687,561,205 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | k=int(input())
s=input()
dic={}
for i in s:
if i not in dic:
dic[i]=1
else:
dic[i]+=1
flag=True
for i in dic:
if dic[i] != k:
flag=False
if not flag:
print(-1)
else:
ans=""
for i in dic:
ans+=i
print(ans * k) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k=int(input())
s=input()
dic={}
for i in s:
if i not in dic:
dic[i]=1
else:
dic[i]+=1
flag=True
for i in dic:
if dic[i] != k:
flag=False
if not flag:
print(-1)
else:
ans=""
for i in dic:
ans+=i
print(ans * k)
``` | 0 | |
220 | A | Little Elephant and Problem | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we ... | 500 | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000... | 1,653,390,625 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 96 | 124 | 17,510,400 | n = int(input())
a = list(map(int, input().split()))
b = a[::]
b.sort()
c = 0
for i in range(n):
if(a[i] != b[i]):
c += 1
if(c <= 2):
print("YES")
else:
print("NO") | Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to c... | ```python
n = int(input())
a = list(map(int, input().split()))
b = a[::]
b.sort()
c = 0
for i in range(n):
if(a[i] != b[i]):
c += 1
if(c <= 2):
print("YES")
else:
print("NO")
``` | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,658,232,604 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
arr = []
for i in range(n):
arr.append([0] * n)
for i in range(n):
arr[i][0] = 1
for j in range(n):
arr[0][j] = 1
mx = 1
for i in range(1, n):
for j in range(1, n):
arr[i][j] = arr[i - 1][j] + arr[i][j - 1]
mx = max(mx, arr[i][j])
print(mx) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append([0] * n)
for i in range(n):
arr[i][0] = 1
for j in range(n):
arr[0][j] = 1
mx = 1
for i in range(1, n):
for j in range(1, n):
arr[i][j] = arr[i - 1][j] + arr[i][j - 1]
mx = max(mx, arr[i][j])
print(mx)
``` | 3 | |
952 | E | Cheese Board | PROGRAMMING | 2,000 | [] | null | null | Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard). | The first line of input contains a single integer *N* (1<=≤<=*N*<=≤<=100) — the number of cheeses you have.
The next *N* lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 character... | Output a single number. | [
"9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard\n",
"6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard\n"
] | [
"3\n",
"4\n"
] | none | 0 | [
{
"input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard",
"output": "3"
},
{
"input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard",
"output": "4"
},
{
"input": "9\ngorgonzola s... | 1,653,244,030 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | from math import *
t = input
n = int(t())
a = sum(t()[-4] == 'h' for i in 'i' * n)
print(ceil(max(max(n - a, a) * 2 - 1, n) ** .5))
| Title: Cheese Board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard).
Input Specification:
The first line of input contains a single integer *N* (1<=≤<=*N*<=≤<=100) — the number of cheeses you have.
The next *N... | ```python
from math import *
t = input
n = int(t())
a = sum(t()[-4] == 'h' for i in 'i' * n)
print(ceil(max(max(n - a, a) * 2 - 1, n) ** .5))
``` | 3 | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,586,876,000 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 307,200 | def marks(n,m,li):
temp=[]
for j in range(m):
max_=-999
for i in range(n):
if li[i][j] >= max_:
max_=li[i][j]
index = i+1
for i in range(n):
if li[i][j] == max_ and index not in temp:
temp.append(index)
return len(temp)
n,m=input().split()
array=[]
for i in range(int(n)):
a=[]
for ... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
def marks(n,m,li):
temp=[]
for j in range(m):
max_=-999
for i in range(n):
if li[i][j] >= max_:
max_=li[i][j]
index = i+1
for i in range(n):
if li[i][j] == max_ and index not in temp:
temp.append(index)
return len(temp)
n,m=input().split()
array=[]
for i in range(int(n)):
a=[... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu... | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hi... | 0 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
... | 1,686,443,697 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 77 | 0 | c=0
v=[2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49]
for j in v:
print(j,flush=True)
if input()=="yes":
c+=1
if c>=2:
break
if c >=2:
print("composite")
else:
print("prime")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden n... | ```python
c=0
v=[2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49]
for j in v:
print(j,flush=True)
if input()=="yes":
c+=1
if c>=2:
break
if c >=2:
print("composite")
else:
print("prime")
``` | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,697,540,432 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,764,800 | x,y,z=map(int,input().split())
a=x*((z(z+1))//2)
print(a-y) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
x,y,z=map(int,input().split())
a=x*((z(z+1))//2)
print(a-y)
``` | -1 | |
385 | C | Bear and Prime Numbers | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"implementation",
"math",
"number theory"
] | null | null | Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=*x**i*<=≤<=107). The numbers are not necessarily distinct.
The third line contains integer *m* (1<=≤<=*m*<=≤<=50000). Each of the following *m* lines contains a pair of space-separated integ... | Print *m* integers — the answers to the queries on the order the queries appear in the input. | [
"6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n",
"7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n"
] | [
"9\n7\n0\n",
"0\n7\n"
] | Consider the first sample. Overall, the first sample has 3 queries.
1. The first query *l* = 2, *r* = 11 comes. You need to count *f*(2) + *f*(3) + *f*(5) + *f*(7) + *f*(11) = 2 + 1 + 4 + 2 + 0 = 9. 1. The second query comes *l* = 3, *r* = 12. You need to count *f*(3) + *f*(5) + *f*(7) + *f*(11) = 1 + 4 + 2 + 0 = 7.... | 1,500 | [
{
"input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4",
"output": "9\n7\n0"
},
{
"input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123",
"output": "0\n7"
},
{
"input": "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792",
"output": "0\n0\n0\n0\n9\n0\n0"
},
{
"... | 1,620,334,717 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 83,558,400 | n = int(input())
arr = list(map(int, input().split()))
ml = []
for i in range(2, max(arr) + 1):
flag = 1
for j in range(2, i // 2 + 1):
if (i % j == 0):
flag = 0
break
if (flag == 1):
c = 0
for z in arr:
if z % i == 0:
... | Title: Bear and Prime Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized b... | ```python
n = int(input())
arr = list(map(int, input().split()))
ml = []
for i in range(2, max(arr) + 1):
flag = 1
for j in range(2, i // 2 + 1):
if (i % j == 0):
flag = 0
break
if (flag == 1):
c = 0
for z in arr:
if z % i == 0:
... | 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,688,248,884 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 340 | 13,824,000 | from fractions import Fraction
hp = max(map(int, input().split()))
prob = ((6 - hp) + 1) * 0.1666
res = "1/1" if str(Fraction(round(prob, 2))) == "1" else str(Fraction(round(prob, 2)))
print(res)
| 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
from fractions import Fraction
hp = max(map(int, input().split()))
prob = ((6 - hp) + 1) * 0.1666
res = "1/1" if str(Fraction(round(prob, 2))) == "1" else str(Fraction(round(prob, 2)))
print(res)
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties:
- *G* has exactly *n* vertices, numbe... | The first line of the input contains two integers *n* and *m* — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*) — the edges of the graph *G*. It is guaranteed, that there ... | In the first line print "Yes" (without the quotes), if the string *s* Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string *s* exists, then print it on the second line of the output. The length of *s* must be exactly *n*, it must consist of only letters "a", "b" and "c" only, and... | [
"2 1\n1 2\n",
"4 3\n1 2\n1 3\n1 4\n"
] | [
"Yes\naa\n",
"No\n"
] | In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to a... | 0 | [
{
"input": "2 1\n1 2",
"output": "Yes\naa"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "No"
},
{
"input": "4 4\n1 2\n1 3\n1 4\n3 4",
"output": "Yes\nbacc"
},
{
"input": "1 0",
"output": "Yes\na"
},
{
"input": "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5... | 1,454,618,021 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 61 | 1,433,600 | v = [[0] * 555 for i in range(555)]
(n, m) = map(int, input().split())
ans = ["$"] * n
for i in range(m):
(x, y) = map(int, input().split())
x -= 1
y -= 1
v[x][y] = 1
v[y][x] = 1
for i in range(n):
v[i][i] = 1
for i in range(n):
deg = 0
for j in range(n):
deg += v[i][j]
if de... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by com... | ```python
v = [[0] * 555 for i in range(555)]
(n, m) = map(int, input().split())
ans = ["$"] * n
for i in range(m):
(x, y) = map(int, input().split())
x -= 1
y -= 1
v[x][y] = 1
v[y][x] = 1
for i in range(n):
v[i][i] = 1
for i in range(n):
deg = 0
for j in range(n):
deg += v[i][j]... | -1 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,666,034,503 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 61 | 0 | def arithm_sum(a, n, d):
return int(n/2 * (2*a+(n-1)*d))
a = int(input())
b = int(input())
distance = abs(a-b)
if distance == 1:
print(1)
else:
a_dist = distance//2
b_dist = distance - a_dist
# print(a_dist, b_dist)
a_tiredness = arithm_sum(1, a_dist, 1)
b_tiredness = a... | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
def arithm_sum(a, n, d):
return int(n/2 * (2*a+(n-1)*d))
a = int(input())
b = int(input())
distance = abs(a-b)
if distance == 1:
print(1)
else:
a_dist = distance//2
b_dist = distance - a_dist
# print(a_dist, b_dist)
a_tiredness = arithm_sum(1, a_dist, 1)
b_tir... | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,576,896,994 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 10,444,800 | n,d=map(int,input().split())
p=[int(x) for x in input().split()]
if n<=2:
print(0)
elif n==3:
if p[2]-p[0]<=d:
print(1)
else:
print(0)
else:
s=0
i=0
j=n-1
while j>=2:
for i in range (0,j-1):
if p[j]-p[i]>d:
continue
... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
n,d=map(int,input().split())
p=[int(x) for x in input().split()]
if n<=2:
print(0)
elif n==3:
if p[2]-p[0]<=d:
print(1)
else:
print(0)
else:
s=0
i=0
j=n-1
while j>=2:
for i in range (0,j-1):
if p[j]-p[i]>d:
continu... | 0 | |
787 | B | Not Afraid | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"math"
] | null | null | Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104) — number of universes and number of groups respectively.
The next *m* lines contain the information about the groups. *i*-th of them first contains an integer *k* (number of times someone joined *i*-th group, *k*<=><=0) followed by ... | In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise. | [
"4 2\n1 -3\n4 -2 3 2 -3\n",
"5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n",
"7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event. | 1,000 | [
{
"input": "4 2\n1 -3\n4 -2 3 2 -3",
"output": "YES"
},
{
"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5",
"output": "NO"
},
{
"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4",
"output": "YES"
},
{
"input": "2 1\n2 -2 2",
"output": "NO"
},
{
"input": "7 7\n1 -2\n1 6\n2 7 -6\n2... | 1,689,160,414 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 1,433,600 | n, m = map(int, input().split())
stop = False
for _ in range(m):
k, *a = map(int, input().split())
s = set(a)
if all(x > 0 or -x not in s for x in a):
stop = True
if stop:
print("YES")
else:
print("NO")
| Title: Not Afraid
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are *n* parallel universes ... | ```python
n, m = map(int, input().split())
stop = False
for _ in range(m):
k, *a = map(int, input().split())
s = set(a)
if all(x > 0 or -x not in s for x in a):
stop = True
if stop:
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,612,338,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 77 | 307,200 | input()
instring = input()
balance = []
num0 = 0
num1 = 0
for c in instring:
if c == "0":
num0 += 1
else:
num1 += 1
balance.append(num0 - num1)
d = {}
for i in range(len(balance)):
if balance[i] not in d:
d[balance[i]] = i
for i in range(len(balance)):
balance[i] = i ... | 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
input()
instring = input()
balance = []
num0 = 0
num1 = 0
for c in instring:
if c == "0":
num0 += 1
else:
num1 += 1
balance.append(num0 - num1)
d = {}
for i in range(len(balance)):
if balance[i] not in d:
d[balance[i]] = i
for i in range(len(balance)):
balan... | 0 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,665,770,411 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | jagratha=int(input())
manushulu=list(map(int,input().split()))
while(0 in manushulu):
manushulu.remove(0)
manushulu=set(manushulu)
print(len(manushulu)) | Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
jagratha=int(input())
manushulu=list(map(int,input().split()))
while(0 in manushulu):
manushulu.remove(0)
manushulu=set(manushulu)
print(len(manushulu))
``` | 3 | |
582 | A | GCD Table | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy",
"number theory"
] | null | null | The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula
Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={... | The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. I... | In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. | [
"4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"1\n42\n",
"2\n1 1 1 1\n"
] | [
"4 3 6 2",
"42 ",
"1 1 "
] | none | 750 | [
{
"input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2",
"output": "2 3 4 6 "
},
{
"input": "1\n42",
"output": "42 "
},
{
"input": "2\n1 1 1 1",
"output": "1 1 "
},
{
"input": "2\n54748096 1 641009859 1",
"output": "54748096 641009859 "
},
{
"input": "3\n1 7 923264237 374... | 1,458,500,674 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 45,465,600 | #!/usr/bin/env python3
import collections, fractions, itertools, functools, math
def fill(grid, elems, n):
a = grid[n][n]
for i in range(n):
b = grid[i][i]
g = fractions.gcd(a, b)
elems.remove(g)
elems.remove(g)
grid[n][i] = g
grid[i][n] = g
def solve():
n ... | Title: GCD Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula
Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest i... | ```python
#!/usr/bin/env python3
import collections, fractions, itertools, functools, math
def fill(grid, elems, n):
a = grid[n][n]
for i in range(n):
b = grid[i][i]
g = fractions.gcd(a, b)
elems.remove(g)
elems.remove(g)
grid[n][i] = g
grid[i][n] = g
def solve... | 0 | |
78 | D | Archer's Shot | PROGRAMMING | 2,300 | [
"binary search",
"geometry",
"math",
"two pointers"
] | D. Archer's Shot | 2 | 256 | A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playin... | The first and only line of input contains a single positive integer *k* — the archer's shot range (1<=≤<=*k*<=≤<=106). | Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator). | [
"3\n",
"4\n",
"5\n"
] | [
"7",
"13",
"19"
] | none | 2,000 | [
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "13"
},
{
"input": "5",
"output": "19"
},
{
"input": "9",
"output": "85"
},
{
"input": "11",
"output": "121"
},
{
"input": "51",
"output": "3037"
},
{
"input": "101",
"output": ... | 1,500,142,670 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 34 | 2,000 | 5,632,000 | from sys import stdin, stdout
from decimal import Decimal
n = int(stdin.readline())
ans = 0
l = 1
label = 1
x = (-1)
EPS = 10 ** (-6)
for i in range(n):
x += (1.5)
if label % 2:
y = ((3) ** (0.5)) / (2)
else:
y = (3) ** (0.5)
if x ** 2 + y ** 2 <= n ... | Title: Archer's Shot
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular h... | ```python
from sys import stdin, stdout
from decimal import Decimal
n = int(stdin.readline())
ans = 0
l = 1
label = 1
x = (-1)
EPS = 10 ** (-6)
for i in range(n):
x += (1.5)
if label % 2:
y = ((3) ** (0.5)) / (2)
else:
y = (3) ** (0.5)
if x ** 2 + y ... | 0 |
835 | C | Star sky | PROGRAMMING | 1,600 | [
"dp",
"implementation"
] | null | null | The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*).
Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at mom... | The first line contains three integers *n*, *q*, *c* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*c*<=≤<=10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next *n* lines contain the stars description. The *i*-th from these lines contains three integers *x**i*, *y**i*, *s**i* (1<=≤... | For each view print the total brightness of the viewed stars. | [
"2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5\n",
"3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51\n"
] | [
"3\n0\n3\n",
"3\n3\n5\n0\n"
] | Let's consider the first example.
At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.
At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.
At the third view, you can see both stars. At moment 5 brightness of th... | 1,250 | [
{
"input": "2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5",
"output": "3\n0\n3"
},
{
"input": "3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51",
"output": "3\n3\n5\n0"
}
] | 1,598,332,336 | 4,576 | PyPy 3 | OK | TESTS | 52 | 623 | 10,854,400 | input=__import__('sys').stdin.readline
n,q,c=map(int,input().split())
dp= [[[0 for i in range(101)] for j in range(101)]for k in range(c+1)]
for i in range(n):
x,y,s = map(int,input().split())
dp[s][x][y]+=1
for i in range(c+1):
for j in range(1,101):
for k in range(1,101):
dp[i... | Title: Star sky
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*... | ```python
input=__import__('sys').stdin.readline
n,q,c=map(int,input().split())
dp= [[[0 for i in range(101)] for j in range(101)]for k in range(c+1)]
for i in range(n):
x,y,s = map(int,input().split())
dp[s][x][y]+=1
for i in range(c+1):
for j in range(1,101):
for k in range(1,101):
... | 3 | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,585,219,431 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 155 | 0 | n, a = map(int, input().split())
t = list(map(int, input().split()))
fr = bk = a - 1
counter = 0
while fr >= 0 and bk <= len(t) - 1:
if t[fr] + t[bk] == 2:
if fr == bk:
counter += 1
else:
counter += 2
fr -= 1
bk += 1
counter += sum(t[0:fr + 1])
counter += sum(t[bk :])
... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
n, a = map(int, input().split())
t = list(map(int, input().split()))
fr = bk = a - 1
counter = 0
while fr >= 0 and bk <= len(t) - 1:
if t[fr] + t[bk] == 2:
if fr == bk:
counter += 1
else:
counter += 2
fr -= 1
bk += 1
counter += sum(t[0:fr + 1])
counter += sum... | 3 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,626,714,115 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,963,200 | y,k,n = map(int,input().split())
lst=[-1]
if(y>0 and k>0 and n>0):
for i in range(n):
if(i+y <=n and (i+y) % k == 0):
lst.append(i)
if len(lst) >1 :
del lst[0]
# res = str([ele for ele in lst])
print(' '.join(map(str,lst))) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n = map(int,input().split())
lst=[-1]
if(y>0 and k>0 and n>0):
for i in range(n):
if(i+y <=n and (i+y) % k == 0):
lst.append(i)
if len(lst) >1 :
del lst[0]
# res = str([ele for ele in lst])
print(' '.join(map(str,lst)))
``` | 0 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,676,884,344 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
c1 = sorted(input().split())
c2 = sorted(input().split())
c3 = sorted(input().split())
for i in c3:
if i in c1:
del c1[c1.index(i)]
for i in c1:
print(i) | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
n = int(input())
c1 = sorted(input().split())
c2 = sorted(input().split())
c3 = sorted(input().split())
for i in c3:
if i in c1:
del c1[c1.index(i)]
for i in c1:
print(i)
``` | 0 | |
989 | C | A Mist of Florescence | PROGRAMMING | 1,800 | [
"constructive algorithms",
"graphs"
] | null | null | "I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.
The wood can be represented by a ... | The first and only line of input contains four space-separated integers $a$, $b$, $c$ and $d$ ($1 \leq a, b, c, d \leq 100$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively. | In the first line, output two space-separated integers $n$ and $m$ ($1 \leq n, m \leq 50$) — the number of rows and the number of columns in the grid respectively.
Then output $n$ lines each consisting of $m$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and '... | [
"5 3 2 1\n",
"50 50 1 1\n",
"1 6 4 5\n"
] | [
"4 7\nDDDDDDD\nDABACAD\nDBABACD\nDDDDDDD",
"4 50\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nABABABABABABABABABABABABABABABABABABABABABABABABAB\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"7 7\nDDDDDDD\nDDDBDBD\nDDCDCDD\nDBDADBD\nDDCDCDD\nDB... | In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one. | 1,500 | [
{
"input": "5 3 2 1",
"output": "5 13\nAABABBBBCDDAD\nABAABBBBCDADD\nAAAABBBBCDDAD\nAAAABCBBCDADD\nAAAABBBBCDDDD"
},
{
"input": "50 50 1 1",
"output": "10 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABAB... | 1,657,786,272 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | s='ABCD'
a=list(map(int,input().split()))
print(48,50)
for k in range(4) :
print(s[k]*50)
cnt=0
for i in range(11) :
for j in range(50) :
if i%2==0 and j%2==1 and cnt<a[(k+1)%4]-1 :
print(s[(k+1)%4],end='')
cnt=cnt+1
else :
... | Title: A Mist of Florescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds... | ```python
s='ABCD'
a=list(map(int,input().split()))
print(48,50)
for k in range(4) :
print(s[k]*50)
cnt=0
for i in range(11) :
for j in range(50) :
if i%2==0 and j%2==1 and cnt<a[(k+1)%4]-1 :
print(s[(k+1)%4],end='')
cnt=cnt+1
else :... | 3 | |
656 | B | Scrambled | PROGRAMMING | 1,700 | [
"*special",
"implementation"
] | null | null | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt ... | The first line of input contains a single integer N (1<=≤<=*N*<=≤<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*]. | Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. | [
"1\n2\n0\n",
"2\n2 3\n1 0\n"
] | [
"0.500000\n",
"0.666667\n"
] | none | 0 | [
{
"input": "1\n2\n0",
"output": "0.500000"
},
{
"input": "2\n2 3\n1 0",
"output": "0.666667"
},
{
"input": "3\n2 4 4\n0 1 3",
"output": "1.000000"
},
{
"input": "1\n16\n15",
"output": "0.062500"
},
{
"input": "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 ... | 1,459,536,120 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 296 | 6,041,600 | from fractions import gcd
from functools import reduce
from operator import mul
n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
lcm = m[0]
if len(m) > 1:
lcm = reduce(mul, m, 1) // reduce(gcd, m, 0)
res = 0
for d in range(min(lcm, 100000)):
for i in range(n):
... | Title: Scrambled
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M... | ```python
from fractions import gcd
from functools import reduce
from operator import mul
n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
lcm = m[0]
if len(m) > 1:
lcm = reduce(mul, m, 1) // reduce(gcd, m, 0)
res = 0
for d in range(min(lcm, 100000)):
for i in rang... | 3 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,698,681,634 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | s1=input()
s2=input()
x=s1.lower()
y=s2.lower()
flag=0
for i in range(len(x)):
if ord(x[i])>ord(y[i]):
print(1)
flag=1
break
if ord(x[i])<ord(y[i]):
print(-1)
flag=1
break
if flag==0:
print(0) | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
s1=input()
s2=input()
x=s1.lower()
y=s2.lower()
flag=0
for i in range(len(x)):
if ord(x[i])>ord(y[i]):
print(1)
flag=1
break
if ord(x[i])<ord(y[i]):
print(-1)
flag=1
break
if flag==0:
print(0)
``` | 3.977 |
590 | C | Three States | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that on... | The first line of the input contains the dimensions of the map *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns respectively.
Each of the next *n* lines contain *m* characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.... | Print a single integer — the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1. | [
"4 5\n11..2\n#..22\n#.323\n.#333",
"1 5\n1#2#3\n"
] | [
"2",
"-1\n"
] | none | 1,250 | [
{
"input": "4 5\n11..2\n#..22\n#.323\n.#333",
"output": "2"
},
{
"input": "1 5\n1#2#3",
"output": "-1"
},
{
"input": "3 4\n.2..\n...3\n.1#.",
"output": "2"
},
{
"input": "10 10\n##.#..#.#2\n...###....\n#..#....##\n.....#....\n.#........\n.....#####\n...#..#...\n....###...\n##... | 1,692,898,719 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 307,200 | import sys
# sys.setrecursionlimit(1000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x)+'\n')
# from decimal import Decimal
# from random import randint
# from copy import deepcopy
from collections import deque,Counter
from heapq import heapify,heappush,heappop
# from bis... | Title: Three States
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. ... | ```python
import sys
# sys.setrecursionlimit(1000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x)+'\n')
# from decimal import Decimal
# from random import randint
# from copy import deepcopy
from collections import deque,Counter
from heapq import heapify,heappush,heappop
... | 0 | |
570 | C | Replacement | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string *s*, of all occurrences of the substring let's choose the first one, and replace thi... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300<=000) the length of the string and the number of queries.
The second line contains string *s*, consisting of *n* lowercase English letters and period signs.
The following *m* lines contain the descriptions of queries. The *i*-th line contains i... | Print *m* numbers, one per line, the *i*-th of these numbers must be equal to the value of *f*(*s*) after performing the *i*-th assignment. | [
"10 3\n.b..bz....\n1 h\n3 c\n9 f\n",
"4 4\n.cc.\n2 .\n3 .\n2 a\n1 a\n"
] | [
"4\n3\n1\n",
"1\n3\n1\n1\n"
] | Note to the first sample test (replaced periods are enclosed in square brackets).
The original string is ".b..bz....".
- after the first query *f*(hb..bz....) = 4 ("hb[..]bz...." → "hb.bz[..].." → "hb.bz[..]." → "hb.bz[..]" → "hb.bz.")- after the second query *f*(hbс.bz....) = 3 ("hbс.bz[..].." → "hb... | 1,500 | [
{
"input": "10 3\n.b..bz....\n1 h\n3 c\n9 f",
"output": "4\n3\n1"
},
{
"input": "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a",
"output": "1\n3\n1\n1"
},
{
"input": "3 3\n...\n1 .\n2 a\n3 b",
"output": "2\n0\n0"
},
{
"input": "5 1\n.....\n5 z",
"output": "3"
},
{
"input": "1 5\n... | 1,679,744,849 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | import sys
import math
input = lambda: sys.stdin.readline().rstrip()
n , m = map( int , input( ).split( ) )
s = input( )
pre = [0] * ( n + 2 )
suff = [0] * ( n + 2 )
for i in range( 1 , n + 1 ) :
if s[i-1] == '.' : pre[i] = pre[i-1] + 1
else : pre[i] = 0
for i in range( n , 0 , -1 ) :
if s[... | Title: Replacement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive period... | ```python
import sys
import math
input = lambda: sys.stdin.readline().rstrip()
n , m = map( int , input( ).split( ) )
s = input( )
pre = [0] * ( n + 2 )
suff = [0] * ( n + 2 )
for i in range( 1 , n + 1 ) :
if s[i-1] == '.' : pre[i] = pre[i-1] + 1
else : pre[i] = 0
for i in range( n , 0 , -1 ) :
... | 0 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,619,261,601 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 109 | 0 | n = int(input())
org = input()
lock = input()
cmb = 0
for i in range(n):
t = abs(int(org[i])-int(lock[i]))
cmb += min(t,10-t)
print(cmb) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
org = input()
lock = input()
cmb = 0
for i in range(n):
t = abs(int(org[i])-int(lock[i]))
cmb += min(t,10-t)
print(cmb)
``` | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,640,429,552 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 154 | 0 | k=int(input())
s=input()
dic={}
lst=[]
new_s=''
def count(s, c):
res = 0
for i in range(len(s)):
if (s[i] == c):
res = res + 1
return res
for i in s:
if i not in dic:
dic[i]=count(s,i)
lst.append(count(s,s[0]))
for key,val in dic.items():
if val not in... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k=int(input())
s=input()
dic={}
lst=[]
new_s=''
def count(s, c):
res = 0
for i in range(len(s)):
if (s[i] == c):
res = res + 1
return res
for i in s:
if i not in dic:
dic[i]=count(s,i)
lst.append(count(s,s[0]))
for key,val in dic.items():
if ... | 0 | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,501,789,598 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 4,608,000 | n = int(input())
a = input().split()
ans = 0
def f(s):
res = 0
for i in range(0,len(s)):
if 'A' <= s[i] <= 'Z':
res+=1
return res
for i in range(0,len(a)):
ans = max(ans,f(a[i]))
print(int(ans))
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = int(input())
a = input().split()
ans = 0
def f(s):
res = 0
for i in range(0,len(s)):
if 'A' <= s[i] <= 'Z':
res+=1
return res
for i in range(0,len(a)):
ans = max(ans,f(a[i]))
print(int(ans))
``` | 3 | |
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,672,823,365 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n,m=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
count=0
for i in range(n):
if a[i] in b:
b.remove(a[i])
else:
count+=1
print(count) | 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
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
count=0
for i in range(n):
if a[i] in b:
b.remove(a[i])
else:
count+=1
print(count)
``` | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,681,333,191 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 1,870 | 0 | def sum_of_digits(num):
return sum(int(digit) for digit in str(num))
def magic_transformations(n):
count = 0
while n >= 10:
n = sum_of_digits(n)
count += 1
return count
# Read input
n = int(input().strip())
# Calculate and print the result
result = magic_transformati... | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
def sum_of_digits(num):
return sum(int(digit) for digit in str(num))
def magic_transformations(n):
count = 0
while n >= 10:
n = sum_of_digits(n)
count += 1
return count
# Read input
n = int(input().strip())
# Calculate and print the result
result = magic_tr... | 3.5325 |
19 | B | Checkout Assistant | PROGRAMMING | 1,900 | [
"dp"
] | B. Checkout Assistant | 1 | 256 | Bob came to a cash & carry store, put *n* items into his trolley, and went to the checkout counter to pay. Each item is described by its price *c**i* and time *t**i* in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from... | The first input line contains number *n* (1<=≤<=*n*<=≤<=2000). In each of the following *n* lines each item is described by a pair of numbers *t**i*, *c**i* (0<=≤<=*t**i*<=≤<=2000,<=1<=≤<=*c**i*<=≤<=109). If *t**i* is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item *i*. | Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay. | [
"4\n2 10\n0 20\n1 5\n1 3\n",
"3\n0 1\n0 10\n0 100\n"
] | [
"8\n",
"111\n"
] | none | 0 | [
{
"input": "4\n2 10\n0 20\n1 5\n1 3",
"output": "8"
},
{
"input": "3\n0 1\n0 10\n0 100",
"output": "111"
},
{
"input": "2\n0 635254032\n0 75159864",
"output": "710413896"
},
{
"input": "2\n0 861438648\n1 469893784",
"output": "469893784"
},
{
"input": "2\n2 876232... | 1,565,982,874 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 307,200 | n=int(input())
global t
global c
t=[0]*n
c=[0]*n
for i in range (n) :
a,b=input().split(" ")
t[i]=int(a)
c[i]=int(b)
global save
save=[]
for i in range (n) :
save.append([])
for j in range (5002) :
save[i].append("empty")
if t[0]==0 :
save[0][0]=2000*(10^9)+1
else :
... | Title: Checkout Assistant
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob came to a cash & carry store, put *n* items into his trolley, and went to the checkout counter to pay. Each item is described by its price *c**i* and time *t**i* in seconds that a checkout assistant spends on thi... | ```python
n=int(input())
global t
global c
t=[0]*n
c=[0]*n
for i in range (n) :
a,b=input().split(" ")
t[i]=int(a)
c[i]=int(b)
global save
save=[]
for i in range (n) :
save.append([])
for j in range (5002) :
save[i].append("empty")
if t[0]==0 :
save[0][0]=2000*(10^9)+1
e... | 0 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,486,523,660 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 154 | 4,915,200 | import math
n, d = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
moves = 0
bench = 0
for i in range(1, len(b)):
if b[i] < b[i - 1]:
bench = math.ceil((b[i - 1] - b[i]) / d)
b[i] += (d * bench)
moves += bench
if b[i] == b[i - 1]:
b[i] += d
moves... | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
import math
n, d = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
moves = 0
bench = 0
for i in range(1, len(b)):
if b[i] < b[i - 1]:
bench = math.ceil((b[i - 1] - b[i]) / d)
b[i] += (d * bench)
moves += bench
if b[i] == b[i - 1]:
b[i] += d
... | 3.886379 |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a can... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S**... | 1,642,145,360 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | str_arr = []
n, m = map(int, input().split())
for i in range(n):
str_arr.append(input())
def distance(str):
count = 0
flag = False
for x in str:
if x == "S" and flag == False:
return -1
elif x == "S" and flag == True:
break
if x == "G":
... | Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of th... | ```python
str_arr = []
n, m = map(int, input().split())
for i in range(n):
str_arr.append(input())
def distance(str):
count = 0
flag = False
for x in str:
if x == "S" and flag == False:
return -1
elif x == "S" and flag == True:
break
if x =... | 0 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,631,663,723 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 468 | 23,142,400 | line=input().split(" ")
n= int(line[0])
m = int(line[1])
vect=[]
cont=[0]*n
for t in range (n):
vect.append([])
for i in range (m):
line=input().split(" ")
a= int(line[0])
b = int(line[1])
cont[a - 1]+=1
cont[b - 1] += 1
vect[a - 1].append(b-1)
vect[b - 1].append(a-1)
cent=True
tot=0
whi... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
line=input().split(" ")
n= int(line[0])
m = int(line[1])
vect=[]
cont=[0]*n
for t in range (n):
vect.append([])
for i in range (m):
line=input().split(" ")
a= int(line[0])
b = int(line[1])
cont[a - 1]+=1
cont[b - 1] += 1
vect[a - 1].append(b-1)
vect[b - 1].append(a-1)
cent=True... | 3 | |
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub... | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
... | 1,618,360,056 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 0 | n = int(input())
x = [int(x) for x in input().split()]
for i in range(10e9):
x.sort()
if x[-1] > x[0]:
a = x[-1]
x.pop()
x.append(a-x[0])
print(sum(x)) | Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that ... | ```python
n = int(input())
x = [int(x) for x in input().split()]
for i in range(10e9):
x.sort()
if x[-1] > x[0]:
a = x[-1]
x.pop()
x.append(a-x[0])
print(sum(x))
``` | -1 | |
7 | B | Memory Manager | PROGRAMMING | 1,600 | [
"implementation"
] | B. Memory Manager | 1 | 64 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The fir... | Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return inte... | [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
] | [
"1\n2\nNULL\n3\n"
] | none | 0 | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6",
"output": "1\n2\nNULL\n3"
},
{
"input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1",
"output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "14 100\nalloc 99\nalloc... | 1,616,598,230 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 307,200 | def allocCmd(memory, id, size):
cnt = 0
ind = 0
for i in range(len(memory)):
if memory[i] == '0':
if cnt == 0:
ind = i
cnt += 1
else:
cnt = 0
ind = 0
if cnt == size:
break
if (cnt < size):
... | Title: Memory Manager
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first relea... | ```python
def allocCmd(memory, id, size):
cnt = 0
ind = 0
for i in range(len(memory)):
if memory[i] == '0':
if cnt == 0:
ind = i
cnt += 1
else:
cnt = 0
ind = 0
if cnt == size:
break
if (cnt... | 0 |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,689,782,228 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 77 | 0 | n=int(input())
li=list(map(int,input().strip().split()))
i,j=0,n-1
f=1
a1,a2=0,0
while i<=j:
if f==1:
v1=li[i]
v2=li[j]
v=max(v1,v2)
if v==v1:
a1+=li[i]
i+=1
elif v==v2:
a1+=li[j]
j-=1
f*=-1
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n=int(input())
li=list(map(int,input().strip().split()))
i,j=0,n-1
f=1
a1,a2=0,0
while i<=j:
if f==1:
v1=li[i]
v2=li[j]
v=max(v1,v2)
if v==v1:
a1+=li[i]
i+=1
elif v==v2:
a1+=li[j]
j-=1
f*=-1... | 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,577,629,595 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | n=int(input())
a=0
b=0
c=0
while(n!=0):
x,y,z=list(map(int,input().split()))
a=a+x
b=b+y
c=c+z
n=n-1
if((a==0)and(b==0)and(c==0)):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
a=0
b=0
c=0
while(n!=0):
x,y,z=list(map(int,input().split()))
a=a+x
b=b+y
c=c+z
n=n-1
if((a==0)and(b==0)and(c==0)):
print("YES")
else:
print("NO")
``` | 3.938 |
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,526,584,007 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | s=list(map(int,input().split()))
t=sum(s)
e=0
if t%2!=0:
print("NO")
else:
for a in range(4):
if e==1:
break
for b in range(a+1,5):
if e==1:
break
for c in range(b+1,6):
if s[a]+s[b]+s[c]==t//2:
... | Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build ... | ```python
s=list(map(int,input().split()))
t=sum(s)
e=0
if t%2!=0:
print("NO")
else:
for a in range(4):
if e==1:
break
for b in range(a+1,5):
if e==1:
break
for c in range(b+1,6):
if s[a]+s[b]+s[c]==t//2:
... | 3 | |
888 | C | K-Dominant Character | PROGRAMMING | 1,400 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character. | The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). | Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. | [
"abacaba\n",
"zzzzz\n",
"abcde\n"
] | [
"2\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "2"
},
{
"input": "zzzzz",
"output": "1"
},
{
"input": "abcde",
"output": "3"
},
{
"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab",
"output": "8"
},
{
"input": "daabcdabbab... | 1,691,558,111 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 10,956,800 | def in_between(s, char):
a = []
idx1 = None
idx2 = None
for i, c in enumerate(s):
if c == char:
if idx1 is None:
idx1 = i
idx2 = i
a.append(i)
a.insert(0, -1)
a.append(len(s) - 1)
return max(a[i + 1] - a[i] for i in rang... | Title: K-Dominant Character
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* s... | ```python
def in_between(s, char):
a = []
idx1 = None
idx2 = None
for i, c in enumerate(s):
if c == char:
if idx1 is None:
idx1 = i
idx2 = i
a.append(i)
a.insert(0, -1)
a.append(len(s) - 1)
return max(a[i + 1] - a[i] for... | 0 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,660,369,145 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 46 | 0 | n=int(input())
s=0
l=[]
for i in range(n):
w=input()
if "OO" in w and s<1:
w=w.replace("OO",'++',1)
s+=1
l.append(w)
if s==1:
print("YES")
print(*l,sep='\n')
else:
print('NO') | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
n=int(input())
s=0
l=[]
for i in range(n):
w=input()
if "OO" in w and s<1:
w=w.replace("OO",'++',1)
s+=1
l.append(w)
if s==1:
print("YES")
print(*l,sep='\n')
else:
print('NO')
``` | 3 | |
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"i... | 1,504,626,021 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | ax,ay,bx,by,cx,cy = [ int(x) for x in input().split() ]
if (ax - bx) * (ax - bx) + (ay - by) * (ay - by) == (cx - bx) * (cx - bx) + (cy - by) * (cy - by):
print("Yes")
else:
print("No")
| Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle... | ```python
ax,ay,bx,by,cx,cy = [ int(x) for x in input().split() ]
if (ax - bx) * (ax - bx) + (ay - by) * (ay - by) == (cx - bx) * (cx - bx) + (cy - by) * (cy - by):
print("Yes")
else:
print("No")
``` | 0 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,421,582,283 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 0 | input()
a=input()
print('YES'if(set(a)-set('47')==set())&(sum(map(int,a[:len(a)//2]))==sum(map(int,a[len(a)//2:])))else'NO')
| Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
input()
a=input()
print('YES'if(set(a)-set('47')==set())&(sum(map(int,a[:len(a)//2]))==sum(map(int,a[len(a)//2:])))else'NO')
``` | 3 | |
216 | B | Forming Teams | PROGRAMMING | 1,700 | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | 1,500 | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
... | 1,626,049,593 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 592 | 31,539,200 | import math
from os import startfile
import random
from queue import Queue
import time
import heapq
import sys
n,m=list(map(int,input().split()))
adj={}
seen=set([])
invalid=set([])
for i in range(m):
a,b=list(map(int,input().split()))
if a not in adj:
adj[a]=[]
if b not in adj:
adj[... | Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each stu... | ```python
import math
from os import startfile
import random
from queue import Queue
import time
import heapq
import sys
n,m=list(map(int,input().split()))
adj={}
seen=set([])
invalid=set([])
for i in range(m):
a,b=list(map(int,input().split()))
if a not in adj:
adj[a]=[]
if b not in adj:... | 0 | |
276 | C | Little Girl and Maximum Sum | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)... | The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly.
The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements.
Each of ... | In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered.
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. | [
"3 3\n5 3 2\n1 2\n2 3\n1 3\n",
"5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n"
] | [
"25\n",
"33\n"
] | none | 1,500 | [
{
"input": "3 3\n5 3 2\n1 2\n2 3\n1 3",
"output": "25"
},
{
"input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3",
"output": "33"
},
{
"input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\... | 1,659,161,985 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 47,206,400 | from collections import defaultdict
n,q=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
d=defaultdict(int)
for _ in range(q):
l,r=map(int,input().split())
for i in range(l-1,r):
d[i]+=1
x=sorted(d,key=lambda x: d[x],reverse=True)
sum=0
k=0
for i in x:
sum+=arr[k]*d... | Title: Little Girl and Maximum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1... | ```python
from collections import defaultdict
n,q=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
d=defaultdict(int)
for _ in range(q):
l,r=map(int,input().split())
for i in range(l-1,r):
d[i]+=1
x=sorted(d,key=lambda x: d[x],reverse=True)
sum=0
k=0
for i in x:
sum... | 0 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,596,043,163 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 312 | 20,172,800 | import math
n=int(input())
l=list(map(int,input().split()))
l.sort()
if(n%2!=0):
d=l[0]**2
a=1
else:
a=0
d=0
for i in range(a,n-1,2):
d=d+(l[i+1]**2-l[i]**2)
print(d*math.pi) | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
import math
n=int(input())
l=list(map(int,input().split()))
l.sort()
if(n%2!=0):
d=l[0]**2
a=1
else:
a=0
d=0
for i in range(a,n-1,2):
d=d+(l[i+1]**2-l[i]**2)
print(d*math.pi)
``` | 3 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,656,478,156 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | a=int(input())
list=[]
for i in range(a):
n=input()
if n in list:
print("Yes")
else:
print("No")
list.append(n)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
a=int(input())
list=[]
for i in range(a):
n=input()
if n in list:
print("Yes")
else:
print("No")
list.append(n)
``` | 3 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,585,473,178 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 307,200 | n = int(input())
s = input()
se = set({})
for x in s:
se.add(x)
if n <= 26:
print(n - len(se))
else:
print(-1)
| Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n = int(input())
s = input()
se = set({})
for x in s:
se.add(x)
if n <= 26:
print(n - len(se))
else:
print(-1)
``` | 3 | |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,586,608,575 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 307,200 | l = [int(x) for x in input().split()]
l.sort()
temp = l[0]
index = 0
count = 1
for i in range(1, 6):
if(l[i] == temp):
count += 1
else:
temp = l[i]
index = i+1
count = 1
if count == 4:
break
if(count == 4):
l = l[0:index]+l[index+4:]
if(l[0]!=l... | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
l = [int(x) for x in input().split()]
l.sort()
temp = l[0]
index = 0
count = 1
for i in range(1, 6):
if(l[i] == temp):
count += 1
else:
temp = l[i]
index = i+1
count = 1
if count == 4:
break
if(count == 4):
l = l[0:index]+l[index+4:]
... | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,634,705,690 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 4,505,600 | n=int(input())
a=0
b=n/4
if(n>4):
i=1
while(i<b):
c=n-2*i
if(c%2==0 and c/2 !=i):
a=a+1
i=i+1
print(a) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
n=int(input())
a=0
b=n/4
if(n>4):
i=1
while(i<b):
c=n-2*i
if(c%2==0 and c/2 !=i):
a=a+1
i=i+1
print(a)
``` | 0 | |
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle... | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"in... | 1,632,810,733 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 93 | 20,172,800 | a, b = map(int, input().split())
ans = 0
while a != b:
a, b = max(a, b), min(a, b)
if b == 0:
break
ans += a // b
a %= b
print(ans)
| Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a squ... | ```python
a, b = map(int, input().split())
ans = 0
while a != b:
a, b = max(a, b), min(a, b)
if b == 0:
break
ans += a // b
a %= b
print(ans)
``` | 3 | |
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,391,098,424 | 2,624 | Python 3 | RUNTIME_ERROR | PRETESTS | 3 | 62 | 409,600 | n,m=map(int,input().split())
treb=list(map(int,input().split()))
est=list(map(int,input().split()))
c=[0 for i in range(treb[-1]+1)]
for i in range(n):
c[treb[i]-1]+=1
i=m-1
e=n
q=est[-1]
while i!=-1:
d=True
for j in range(min(est[i]-1,q),-1,-1):
if c[j]:
q=c[j]+1
... | 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
n,m=map(int,input().split())
treb=list(map(int,input().split()))
est=list(map(int,input().split()))
c=[0 for i in range(treb[-1]+1)]
for i in range(n):
c[treb[i]-1]+=1
i=m-1
e=n
q=est[-1]
while i!=-1:
d=True
for j in range(min(est[i]-1,q),-1,-1):
if c[j]:
q=c[j]+1
... | -1 | |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,620,037,509 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 0 | a = int(input())
b = (input().split())
for i in range(len(b)):
b[i] = int(b[i])
def func(a, b):
if 1 in (b[0], b[-1]) or a in (b[0], b[-1]):
return a - 1
else:
temp = 0
for i in range(a):
if temp == 0:
if ((b[i] == int(1)) or (b[i] == a)):
... | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
a = int(input())
b = (input().split())
for i in range(len(b)):
b[i] = int(b[i])
def func(a, b):
if 1 in (b[0], b[-1]) or a in (b[0], b[-1]):
return a - 1
else:
temp = 0
for i in range(a):
if temp == 0:
if ((b[i] == int(1)) or (b[i]... | 0 | |
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "75... | 1,657,623,791 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | X = int(input())
print(3*X /2)
| Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
X = int(input())
print(3*X /2)
``` | 0 |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You... | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"inpu... | 1,647,830,758 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 2,457,600 | def readLines(file):
f = open(file, "r")
line = f.readlines()
f.close()
return line
def writeLine(file, line):
f = open(file, "a")
f.writelines(line)
f.close()
if __name__ == "__main__":
n = int(readLines("input.txt")[0])
ls = list(map(int, readLines("input.txt")[1].sp... | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit... | ```python
def readLines(file):
f = open(file, "r")
line = f.readlines()
f.close()
return line
def writeLine(file, line):
f = open(file, "a")
f.writelines(line)
f.close()
if __name__ == "__main__":
n = int(readLines("input.txt")[0])
ls = list(map(int, readLines("input.t... | 0 | |
289 | A | Polo the Penguin and Segments | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 uni... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*... | In a single line print a single integer — the answer to the problem. | [
"2 3\n1 2\n3 4\n",
"3 7\n1 2\n3 3\n4 7\n"
] | [
"2\n",
"0\n"
] | none | 500 | [
{
"input": "2 3\n1 2\n3 4",
"output": "2"
},
{
"input": "3 7\n1 2\n3 3\n4 7",
"output": "0"
},
{
"input": "3 7\n1 10\n11 47\n74 128",
"output": "3"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "3"
},
{
"input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 ... | 1,605,341,601 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 654 | 0 | myMap = map(int , input().split())
myMap = list(myMap)
n , k , sum = myMap[0] , myMap[1] , 0
for i in range(n) :
temp = map(int , input().split())
temp = list(temp)
sum+= (temp[1] - temp[0]) + 1
sum = sum%k
if sum !=0 :
sum = k - sum
print(sum) | Title: Polo the Penguin and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]... | ```python
myMap = map(int , input().split())
myMap = list(myMap)
n , k , sum = myMap[0] , myMap[1] , 0
for i in range(n) :
temp = map(int , input().split())
temp = list(temp)
sum+= (temp[1] - temp[0]) + 1
sum = sum%k
if sum !=0 :
sum = k - sum
print(sum)
``` | 3 | |
319 | B | Psychos in a Line | PROGRAMMING | 1,900 | [
"data structures",
"implementation"
] | null | null | There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.
You're given the initial arran... | The first line of input contains integer *n* denoting the number of psychos, (1<=≤<=*n*<=≤<=105). In the second line there will be a list of *n* space separated distinct integers each in range 1 to *n*, inclusive — ids of the psychos in the line from left to right. | Print the number of steps, so that the line remains the same afterward. | [
"10\n10 9 7 8 6 5 3 4 2 1\n",
"6\n1 2 3 4 5 6\n"
] | [
"2\n",
"0\n"
] | In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1] → [10 8 4] → [10]. So, there are two steps. | 1,000 | [
{
"input": "10\n10 9 7 8 6 5 3 4 2 1",
"output": "2"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "1"
},
{
"input": "10\n10 7 4 2 5 8 9 6 3 1",
"output": "4"
},
{
"input": "15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4",
"o... | 1,648,843,416 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int v[100005];
int n;
int arb[400005];
void update(int s, int st, int dr, int pos, int val) {
if (st == dr) {
arb[s] = val;
return;
}
int m = (st + dr) / 2, ps = 2*s, pd = 2*s + 1;
if (pos <= m)
update(ps, st, m, pos, val);
e... | Title: Psychos in a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in th... | ```python
#include <bits/stdc++.h>
using namespace std;
int v[100005];
int n;
int arb[400005];
void update(int s, int st, int dr, int pos, int val) {
if (st == dr) {
arb[s] = val;
return;
}
int m = (st + dr) / 2, ps = 2*s, pd = 2*s + 1;
if (pos <= m)
update(ps, st, m, pos, v... | -1 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,645,575,327 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 92 | 0 | import math
def numberToBase(n, b):
if n == 0:
return [0]
digits = []
while n:
digits.append(int(n % b))
n //= b
return digits[::-1]
n = int(input())
x = 0
for i in range(2,n):
x+=sum([int(y) for y in numberToBase(n,i)])
print(f"{x//math.gcd(x,i-1)}/{(i-1)/... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
import math
def numberToBase(n, b):
if n == 0:
return [0]
digits = []
while n:
digits.append(int(n % b))
n //= b
return digits[::-1]
n = int(input())
x = 0
for i in range(2,n):
x+=sum([int(y) for y in numberToBase(n,i)])
print(f"{x//math.gcd(x,i-1... | 3.954 |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,659,013,203 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 77 | 1,740,800 | def main():
n, packs = list(map(int, input().split()))
sad = 0
for _ in range(n):
s, val = input().split()
val = int(val)
if s == "+":
packs += val
if s == "-":
if val > packs:
sad += 1
else:
packs -= val
... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
def main():
n, packs = list(map(int, input().split()))
sad = 0
for _ in range(n):
s, val = input().split()
val = int(val)
if s == "+":
packs += val
if s == "-":
if val > packs:
sad += 1
else:
packs ... | 3 | |
682 | C | Alyona and the Tree | PROGRAMMING | 1,600 | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call ver... | In the first line of the input integer *n* (1<=≤<=*n*<=≤<=105) is given — the number of vertices in the tree.
In the second line the sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) is given, where *a**i* is the number written on vertex *i*.
The next *n*<=-<=1 lines describe tree edges: *i**... | Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree. | [
"9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8\n"
] | [
"5\n"
] | The following image represents possible process of removing leaves from the tree: | 1,500 | [
{
"input": "9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8",
"output": "5"
},
{
"input": "6\n53 82 15 77 71 23\n5 -77\n6 -73\n2 0\n1 26\n4 -92",
"output": "0"
},
{
"input": "10\n99 60 68 46 51 11 96 41 48 99\n4 50\n6 -97\n3 -92\n7 1\n9 99\n2 79\n1 -15\n8 -6... | 1,676,303,563 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 106 | 358 | 41,881,600 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
d = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
d[i+1].append((a-1, b))
d[a-1].append((i+1, b))
x = [0]*n
q = [(0, 0, -1, 0)]
while q:
a, b, c, e = q.pop()
if ... | Title: Alyona and the Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
Th... | ```python
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
d = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
d[i+1].append((a-1, b))
d[a-1].append((i+1, b))
x = [0]*n
q = [(0, 0, -1, 0)]
while q:
a, b, c, e = q.pop(... | 3 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,380,807,608 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | #!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
print([0,4,4,4,4,4,4,4,4,4,15,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0][readln()[0] - 10])
| Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
#!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
print([0,4,4,4,4,4,4,4,4,4,15,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0][readln()[0] - 10])
``` | 3.969 |
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.