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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,625,327,899 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 124 | 0 | A,B,C,N=map(int,input().split())
AUB=A+B-C
if AUB>=N:
print(-1)
elif AUB<0:
print(-1)
elif A<C:
print(-1)
elif B<C:
print(-1)
else:
print(N-AUB)
| Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
A,B,C,N=map(int,input().split())
AUB=A+B-C
if AUB>=N:
print(-1)
elif AUB<0:
print(-1)
elif A<C:
print(-1)
elif B<C:
print(-1)
else:
print(N-AUB)
``` | 3 | |
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-... | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
... | 1,692,740,467 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | def f(n,x,y):
if n%6==1:
return(x)
if n%6==2:
return(y)
if n%6==3:
return(y-x)
if n%6==4:
return(-x)
if n%6==5:
return(-y)
if n%6==0:
return(x-y)
x,y=map(int,input().split())
n=int(input())
print(f(n,x,y%1000000007))
| Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers... | ```python
def f(n,x,y):
if n%6==1:
return(x)
if n%6==2:
return(y)
if n%6==3:
return(y-x)
if n%6==4:
return(-x)
if n%6==5:
return(-y)
if n%6==0:
return(x-y)
x,y=map(int,input().split())
n=int(input())
print(f(n,x,y%1000000007))
``` | 0 | |
980 | A | Links and Pearls | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l... | The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. | Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"-o-o--",
"-o---\n",
"-o---o-\n",
"ooo\n"
] | [
"YES",
"YES",
"NO",
"YES\n"
] | none | 500 | [
{
"input": "-o-o--",
"output": "YES"
},
{
"input": "-o---",
"output": "YES"
},
{
"input": "-o---o-",
"output": "NO"
},
{
"input": "ooo",
"output": "YES"
},
{
"input": "---",
"output": "YES"
},
{
"input": "--o-o-----o----o--oo-o-----ooo-oo---o--",
"... | 1,627,950,509 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int n,k,p,f,i,j;
int a[100003];
int main()
{
cin>>n>>k
for(i=1;i<=n;i++)
{
if(i<=k)
{
if(i%2==1) a[i]=i/2+1,f=0;
else a[i]=n-i/2+1,f=1;
}
else
{
if(f==0) a[i]=a[i-1]+1;
el... | Title: Links and Pearls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearl... | ```python
#include <bits/stdc++.h>
using namespace std;
int n,k,p,f,i,j;
int a[100003];
int main()
{
cin>>n>>k
for(i=1;i<=n;i++)
{
if(i<=k)
{
if(i%2==1) a[i]=i/2+1,f=0;
else a[i]=n-i/2+1,f=1;
}
else
{
if(f==0) a[i]=a[i-1]+1;
... | -1 | |
652 | B | z-sort | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=><=1.
For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible". | [
"4\n1 2 2 1\n",
"5\n1 3 2 2 5\n"
] | [
"1 2 1 2\n",
"1 5 2 3 2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 1",
"output": "1 2 1 2"
},
{
"input": "5\n1 3 2 2 5",
"output": "1 5 2 3 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1"
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 ... | 1,460,580,859 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import itertools
n = int(input())
mass = list(map(int, input().split()))
odds = []
evens = []
for i in range(n):
if i % 2 == 0:
odds.append(mass[i])
else:
evens.append(mass[i])
odds.sort(reverse = True)
evens.sort()
#print(odds, evens)
tmp_mass = []
for a in itertools.zip_longest(o... | Title: z-sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=... | ```python
import itertools
n = int(input())
mass = list(map(int, input().split()))
odds = []
evens = []
for i in range(n):
if i % 2 == 0:
odds.append(mass[i])
else:
evens.append(mass[i])
odds.sort(reverse = True)
evens.sort()
#print(odds, evens)
tmp_mass = []
for a in itertools.zip... | 0 | |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,696,264,518 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | m,n = map(int,input().split())
if (m * n) % 2 == 0:
print('Malvika')
else:
print('Akshat') | Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
m,n = map(int,input().split())
if (m * n) % 2 == 0:
print('Malvika')
else:
print('Akshat')
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,690,498,180 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 0 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = [i for i in range(n)]
for i, v in enumerate(a):
ans[v-1] = i+1
print(*ans) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = [i for i in range(n)]
for i, v in enumerate(a):
ans[v-1] = i+1
print(*ans)
``` | 3 | |
730 | H | Delete Them | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pat... | The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — the total number of files and the number of files to be deleted.
The following *n* lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dot... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | [
"3 2\nab\nac\ncd\n1 2\n",
"5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n",
"4 4\na\nb\nc\ndd\n1 2 3 4\n",
"6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n"
] | [
"Yes\na?\n",
"Yes\n?es?\n",
"No\n",
"Yes\n.???\n"
] | none | 0 | [
{
"input": "3 2\nab\nac\ncd\n1 2",
"output": "Yes\na?"
},
{
"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5",
"output": "Yes\n?es?"
},
{
"input": "4 4\na\nb\nc\ndd\n1 2 3 4",
"output": "No"
},
{
"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3",
"output": "Yes\n.???... | 1,477,210,840 | 1,240 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | num_file,num_delete = map(int, input().split())
list_file = []
for i in range(num_file):
list_file.append(input())
delete_file = [int(i)-1 for i in input().split()]
ans=""
tmp = list(list_file[delete_file[0]])
for i in delete_file[1:]:
name = list(list_file[i])
for j in range(len(tmp)):
if... | Title: Delete Them
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single dele... | ```python
num_file,num_delete = map(int, input().split())
list_file = []
for i in range(num_file):
list_file.append(input())
delete_file = [int(i)-1 for i in input().split()]
ans=""
tmp = list(list_file[delete_file[0]])
for i in delete_file[1:]:
name = list(list_file[i])
for j in range(len(tmp)):
... | 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,586,775,748 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | def find(needle, haystack):
if not needle: return True
if needle[0] not in haystack:
return False
return find(needle[1:], haystack[haystack.find(needle[0])+1:])
if find("hello", input()):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
def find(needle, haystack):
if not needle: return True
if needle[0] not in haystack:
return False
return find(needle[1:], haystack[haystack.find(needle[0])+1:])
if find("hello", input()):
print("YES")
else:
print("NO")
``` | 3.93 |
633 | C | Spy Syndrome 2 | PROGRAMMING | 1,900 | [
"data structures",
"dp",
"hashing",
"implementation",
"sortings",
"string suffix structures",
"strings"
] | null | null | After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the ciphe... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered wh... | Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. | [
"30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n",
"12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n"
] | [
"Kira is childish and he hates losing \n",
"HI there HeLLo \n"
] | In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | 1,500 | [
{
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote",
"output": "Kira is childish and he hates losing "
},
{
"input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello",
"output": "HI there HeLLo "
},
{
"input": "71\nbaaaaaaaaaaa... | 1,678,903,477 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 92 | 6,860,800 | # import sys
# sys.stdout=open('C:\Program Files (x86)\Sublime Text 3\cp_setup\output.txt','w')
# sys.stdin=open('C:\Program Files (x86)\Sublime Text 3\cp_setup\input.txt','r')
import heapq
import math
import collections
import bisect
mod=10**9+7
maxi=10**3
ppow=[0]*maxi
p=31
ppow[0]=1
for i in range(1,... | Title: Spy Syndrome 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observati... | ```python
# import sys
# sys.stdout=open('C:\Program Files (x86)\Sublime Text 3\cp_setup\output.txt','w')
# sys.stdin=open('C:\Program Files (x86)\Sublime Text 3\cp_setup\input.txt','r')
import heapq
import math
import collections
import bisect
mod=10**9+7
maxi=10**3
ppow=[0]*maxi
p=31
ppow[0]=1
for i i... | -1 | |
549 | A | Face Detection | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<... | The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters. | In the single line print the number of faces on the image. | [
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] | [
"1\n",
"1\n",
"2\n",
"0\n"
] | In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In ... | 250 | [
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "... | 1,595,404,657 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 22,220,800 | n,m=map(int, input().split())
p=[]
for i in range (0,n):
l=list(map(str, input().split()))
p.append(l)
#del l[:]
l=[]
ans=[]
for i in range(n-1):
for j in range(m-1):
if p[i][j]!="x":
ans.append(p[i][j])
ans.append(p[i+1][j])
ans.append(p[i][j... | Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem a... | ```python
n,m=map(int, input().split())
p=[]
for i in range (0,n):
l=list(map(str, input().split()))
p.append(l)
#del l[:]
l=[]
ans=[]
for i in range(n-1):
for j in range(m-1):
if p[i][j]!="x":
ans.append(p[i][j])
ans.append(p[i+1][j])
ans.app... | -1 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,688,968,001 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | a = input()
new_string = a.split("WUB")
#print(new_string)
del new_string[0]
final_string = ""
#print(new_string)
for stri in new_string:
final_string=final_string+stri+" "
print(final_string)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
a = input()
new_string = a.split("WUB")
#print(new_string)
del new_string[0]
final_string = ""
#print(new_string)
for stri in new_string:
final_string=final_string+stri+" "
print(final_string)
``` | 0 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,538,482,458 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 1,000 | 307,200 | n,k = map(int,input().split())
a = list(map(int,input().split()))
p = k - (1/2)
l = 0
while sum(a) / len(a) < p:
l += 1
a.append(k)
print(l) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = k - (1/2)
l = 0
while sum(a) / len(a) < p:
l += 1
a.append(k)
print(l)
``` | 0 | |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes th... | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose bal... | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
... | 1,651,259,560 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 512,000 | #Problema G
def insertionSort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i-1
while j >= 0 and key < arr[j] :
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
a = int(input())
b = str(input())
n = b.split()
for i in range (a):
n[i] = int(n[i]... | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri... | ```python
#Problema G
def insertionSort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i-1
while j >= 0 and key < arr[j] :
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
a = int(input())
b = str(input())
n = b.split()
for i in range (a):
n[i] ... | 0 | |
877 | B | Nikita and string | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make... | The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". | Print a single integer — the maximum possible size of beautiful string Nikita can get. | [
"abba\n",
"bab\n"
] | [
"4",
"2"
] | It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 1,000 | [
{
"input": "abba",
"output": "4"
},
{
"input": "bab",
"output": "2"
},
{
"input": "bbabbbaabbbb",
"output": "9"
},
{
"input": "bbabbbbbaaba",
"output": "10"
},
{
"input": "bbabbbababaa",
"output": "9"
},
{
"input": "aabbaababbab",
"output": "8"
}... | 1,510,080,596 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a=input()
n=len(a)
la=0
lb=0
fa=1
fb=0
f=0
asd=0
if (a[0]=='a'):
la=1
else:
lb=1
fb=1
asd=1
for i in range(1, n):
if (a[i]=='a'):
if (fb==1):
la=lb+1
else:
la=max(la+1, lb+1)
else:
if (f==0 and asd!=1):
f=1
lb=la+1
else:
lb=lb+1
print (... | Title: Nikita and string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ... | ```python
a=input()
n=len(a)
la=0
lb=0
fa=1
fb=0
f=0
asd=0
if (a[0]=='a'):
la=1
else:
lb=1
fb=1
asd=1
for i in range(1, n):
if (a[i]=='a'):
if (fb==1):
la=lb+1
else:
la=max(la+1, lb+1)
else:
if (f==0 and asd!=1):
f=1
lb=la+1
else:
lb=lb+... | 0 | |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac... | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n... | 1,645,738,298 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 124 | 2,969,600 | r=lambda:[*map(int,input().split())]
l=list(r()for _ in' '*int(input()))
cm=lambda a,b:(a>b)-(a<b)
p=sum(len({(cm(a,x),cm(b,y))for a,b in l if(a==x or b==y)})>4 for x,y in l)
print(p)
| Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give... | ```python
r=lambda:[*map(int,input().split())]
l=list(r()for _ in' '*int(input()))
cm=lambda a,b:(a>b)-(a<b)
p=sum(len({(cm(a,x),cm(b,y))for a,b in l if(a==x or b==y)})>4 for x,y in l)
print(p)
``` | 3 | |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,640,929,674 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 966 | 0 | n, d =map( int ,input().split())
l=[int(i) for i in input().split(" ")]
x=0
for i in range(len(l)):
for j in range(len(l)):
if i!=j and abs(l[i]-l[j]) <= d:
x+=1
print(x) | Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n, d =map( int ,input().split())
l=[int(i) for i in input().split(" ")]
x=0
for i in range(len(l)):
for j in range(len(l)):
if i!=j and abs(l[i]-l[j]) <= d:
x+=1
print(x)
``` | 3.7585 |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,085,900 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | def min_steps_to_reach(x):
steps = x // 5
if x % 5 != 0:
steps += 1
return steps
x = int(input())
result = min_steps_to_reach(x)
print(result)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
def min_steps_to_reach(x):
steps = x // 5
if x % 5 != 0:
steps += 1
return steps
x = int(input())
result = min_steps_to_reach(x)
print(result)
``` | 3 | |
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",... | 1,454,841,342 | 5,442 | Python 3 | OK | TESTS | 56 | 62 | 307,200 | a = str(input())
b = str(input())
print(a.count(b))
| Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last... | ```python
a = str(input())
b = str(input())
print(a.count(b))
``` | 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,594,096,149 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 22 | 278 | 20,172,800 | n=int(input())
c=n-10
if c<=0:
print('0')
exit(0)
elif c>10:
print('0')
exit(0)
elif c==10:
print('15')
exit(0)
else:
print('4')
| 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
n=int(input())
c=n-10
if c<=0:
print('0')
exit(0)
elif c>10:
print('0')
exit(0)
elif c==10:
print('15')
exit(0)
else:
print('4')
``` | 0 |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,587,125,080 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 202 | 2,048,000 | n=int(input())
s=input()
c=0
r=''
for i in range(n-1):
if(s[0]=='0'):
c=0
elif(s[i]=='1'):
c=c+1
elif(s[i-1]=='1' and s[i]=='0'):
r=r+str(c)
c=0
elif(s[i-1]=='0' and s[i]=='0'):
r=r+'0'
c=0
if(s[-1]=='1' and s[-2]=='0'):
r=r+'1'
elif(s... | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
n=int(input())
s=input()
c=0
r=''
for i in range(n-1):
if(s[0]=='0'):
c=0
elif(s[i]=='1'):
c=c+1
elif(s[i-1]=='1' and s[i]=='0'):
r=r+str(c)
c=0
elif(s[i-1]=='0' and s[i]=='0'):
r=r+'0'
c=0
if(s[-1]=='1' and s[-2]=='0'):
r=r+'... | -1 | |
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the... | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
... | 1,496,678,024 | 2,924 | Python 3 | OK | TESTS | 85 | 62 | 307,200 | def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield(number)
input_parser = parser()
def get_word():
global input_parser
return next(input_parser)
def get_number():
data = get_word()
try:... | Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 a... | ```python
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield(number)
input_parser = parser()
def get_word():
global input_parser
return next(input_parser)
def get_number():
data = get_word()... | 3 | |
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,634,927,514 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 4,505,600 | F=input()
M=input()
S=input()
Beater={"paper":"scissors","scissors":"rock","rock":"paper"}
if S==Beater[F] and F==M:
print("S")
elif F==Beater[S] and S==M:
print("F")
elif M==Beater[F] and F==S:
print("M")
else:
print("?")
| 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
F=input()
M=input()
S=input()
Beater={"paper":"scissors","scissors":"rock","rock":"paper"}
if S==Beater[F] and F==M:
print("S")
elif F==Beater[S] and S==M:
print("F")
elif M==Beater[F] and F==S:
print("M")
else:
print("?")
``` | 3.968608 |
593 | B | Anton and Lines | PROGRAMMING | 1,600 | [
"geometry",
"sortings"
] | null | null | The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of t... | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≤<=*x*1<=<<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two ... | Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes). | [
"4\n1 2\n1 2\n1 0\n0 1\n0 2\n",
"2\n1 3\n1 0\n-1 3\n",
"2\n1 3\n1 0\n0 2\n",
"2\n1 3\n1 0\n0 3\n"
] | [
"NO",
"YES",
"YES",
"NO"
] | In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. | 1,000 | [
{
"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2",
"output": "NO"
},
{
"input": "2\n1 3\n1 0\n-1 3",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 2",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 3",
"output": "NO"
},
{
"input": "2\n0 1\n-1000000 1000000\n1000000 -1000000"... | 1,698,433,706 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 1,000 | 19,660,800 | import sys
def log(*args,**kwargs):
kwargs["file"] = kwargs.get("file",sys.stderr)
print(*args,**kwargs)
n = int(input())
x1,x2 = map(int,input().strip().split())
y1s = []
y2s = []
for i in range(n):
m,c = map(int,input().strip().split())
y1s.append(m*x1+c)
y2s.append(m*x2+c)
#... | Title: Anton and Lines
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*... | ```python
import sys
def log(*args,**kwargs):
kwargs["file"] = kwargs.get("file",sys.stderr)
print(*args,**kwargs)
n = int(input())
x1,x2 = map(int,input().strip().split())
y1s = []
y2s = []
for i in range(n):
m,c = map(int,input().strip().split())
y1s.append(m*x1+c)
y2s.append(m*x2... | 0 | |
911 | F | Tree Destruction | PROGRAMMING | 2,400 | [
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | You are given an unweighted tree with *n* vertices. Then *n*<=-<=1 following operations are applied to the tree. A single operation consists of the following steps:
1. choose two leaves; 1. add the length of the simple path between them to the answer; 1. remove one of the chosen leaves from the tree.
Initial answ... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105) — the number of vertices in the tree.
Next *n*<=-<=1 lines describe the edges of the tree in form *a**i*,<=*b**i* (1<=≤<=*a**i*, *b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). It is guaranteed that given graph is a tree. | In the first line print one integer number — maximal possible answer.
In the next *n*<=-<=1 lines print the operations in order of their applying in format *a**i*,<=*b**i*,<=*c**i*, where *a**i*,<=*b**i* — pair of the leaves that are chosen in the current operation (1<=≤<=*a**i*, *b**i*<=≤<=*n*), *c**i* (1<=≤<=*c**i*... | [
"3\n1 2\n1 3\n",
"5\n1 2\n1 3\n2 4\n2 5\n"
] | [
"3\n2 3 3\n2 1 1\n",
"9\n3 5 5\n4 3 3\n4 1 1\n4 2 2\n"
] | none | 0 | [
{
"input": "3\n1 2\n1 3",
"output": "3\n2 3 3\n2 1 1"
},
{
"input": "5\n1 2\n1 3\n2 4\n2 5",
"output": "9\n3 5 5\n4 3 3\n4 1 1\n4 2 2"
},
{
"input": "2\n1 2",
"output": "1\n2 1 1"
},
{
"input": "4\n1 3\n1 4\n1 2",
"output": "5\n3 4 4\n2 3 3\n2 1 1"
},
{
"input": "... | 1,693,562,841 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1693562841.5007517")# 1693562841.500775 | Title: Tree Destruction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an unweighted tree with *n* vertices. Then *n*<=-<=1 following operations are applied to the tree. A single operation consists of the following steps:
1. choose two leaves; 1. add the length of the si... | ```python
print("_RANDOM_GUESS_1693562841.5007517")# 1693562841.500775
``` | 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,651,426,180 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n=int(input())
a=list(map(int,input().split()))
even=[]
uneven=[]
for i in range(n):
if a[i]%2==0:
even.append(i)
else:
uneven.append(i)
#print(i, even, uneven)
if len(even)<len(uneven):
print(even[0]+1)
else:
print(uneven[0]+1)
| 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())
a=list(map(int,input().split()))
even=[]
uneven=[]
for i in range(n):
if a[i]%2==0:
even.append(i)
else:
uneven.append(i)
#print(i, even, uneven)
if len(even)<len(uneven):
print(even[0]+1)
else:
print(uneven[0]+1)
``` | 3.977 |
54 | A | Presents | PROGRAMMING | 1,300 | [
"implementation"
] | A. Presents | 2 | 256 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c... | The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*).
The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the incr... | Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days. | [
"5 2\n1 3\n",
"10 1\n3 6 7 8\n"
] | [
"3",
"10"
] | none | 500 | [
{
"input": "5 2\n1 3",
"output": "3"
},
{
"input": "10 1\n3 6 7 8",
"output": "10"
},
{
"input": "5 5\n1 3",
"output": "1"
},
{
"input": "10 3\n3 3 6 9",
"output": "3"
},
{
"input": "5 2\n0",
"output": "2"
},
{
"input": "1 1\n0",
"output": "1"
},... | 1,546,844,076 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 218 | 0 | n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = n//k
for i in range(1,a[0]+1):
ans += (a[i]%k!=0)
print(ans) | Title: Presents
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the spec... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = n//k
for i in range(1,a[0]+1):
ans += (a[i]%k!=0)
print(ans)
``` | 0 |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,529,257,658 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 409,600 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: alpha
"""
from functools import reduce
maxNumOfKill = list(map(lambda x: int(x), input().split()))[1] + 1
powerArr = list(map(lambda x: int(x), input().split()))
coinsArr = list(map(lambda x: int(x), input().split()))
knightInfo = list(map(lam... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: alpha
"""
from functools import reduce
maxNumOfKill = list(map(lambda x: int(x), input().split()))[1] + 1
powerArr = list(map(lambda x: int(x), input().split()))
coinsArr = list(map(lambda x: int(x), input().split()))
knightInfo = li... | 0 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,648,277,287 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 80 | 77 | 2,560,000 | n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]*n
for i in range(n):
c[i] = abs(a[i] - b[i])
k = k1 + k2
while k != 0:
max_value = c[0]
max_index = 0
for i, v in enumerate(c):
if v > max_value:
max_valu... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]*n
for i in range(n):
c[i] = abs(a[i] - b[i])
k = k1 + k2
while k != 0:
max_value = c[0]
max_index = 0
for i, v in enumerate(c):
if v > max_value:
... | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,692,455,876 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n = int(input())
points = list(map(int, input().split()))
amazing_performances = 0
for i in range(1, n):
if points[i] > points[0:i]:
amazing_performances += 1
print(amazing_performances) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
points = list(map(int, input().split()))
amazing_performances = 0
for i in range(1, n):
if points[i] > points[0:i]:
amazing_performances += 1
print(amazing_performances)
``` | -1 | |
311 | A | The Closest Pair | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.
The problem is the follows. Given *n* points in the plane, find a pair of points betwe... | A single line which contains two space-separated integers *n* and *k* (2<=≤<=*n*<=≤<=2000, 1<=≤<=*k*<=≤<=109). | If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print *n* lines, and the *i*-th line contains two integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) representing the coordinates of the *i*-th point.
The conditions below must be held:
- All the point... | [
"4 3\n",
"2 100\n"
] | [
"0 0\n0 1\n1 0\n1 1\n",
"no solution\n"
] | none | 500 | [
{
"input": "4 3",
"output": "0 0\n0 1\n1 0\n1 1"
},
{
"input": "2 100",
"output": "no solution"
},
{
"input": "5 6",
"output": "0 0\n0 1\n0 2\n0 3\n0 4"
},
{
"input": "8 20",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7"
},
{
"input": "6 15",
"output": "n... | 1,550,930,211 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | n, k = map(int, input().split())
if (2 * k > n * (n-1)):
print("no solution")
else:
print('\n'.join(["{} {}".format(0,i) for i in range(0,n)]))
| Title: The Closest Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time L... | ```python
n, k = map(int, input().split())
if (2 * k > n * (n-1)):
print("no solution")
else:
print('\n'.join(["{} {}".format(0,i) for i in range(0,n)]))
``` | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,686,771,330 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | s=int(input())
b=list(map(int,input().split()))
c=0
p=0
k=sum(b)
for i in b:
p+=i
k-=i
c+=1
if p>k:
break
print(c) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
s=int(input())
b=list(map(int,input().split()))
c=0
p=0
k=sum(b)
for i in b:
p+=i
k-=i
c+=1
if p>k:
break
print(c)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.
Both participants communicated to each other a set ... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 12$) — the number of pairs the first participant communicated to the second and vice versa.
The second line contains $n$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from first participant to the second.
The third line c... | If you can deduce the shared number with certainty, print that number.
If you can with certainty deduce that both participants know the shared number, but you do not know it, print $0$.
Otherwise print $-1$. | [
"2 2\n1 2 3 4\n1 5 3 4\n",
"2 2\n1 2 3 4\n1 5 6 4\n",
"2 3\n1 2 4 5\n1 2 1 3 2 3\n"
] | [
"1\n",
"0\n",
"-1\n"
] | In the first example the first participant communicated pairs $(1,2)$ and $(3,4)$, and the second communicated $(1,5)$, $(3,4)$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $(3,4)$. Thus, the first participant has $(1,2)$ and the second has $(1,5)$, and at... | 0 | [
{
"input": "2 2\n1 2 3 4\n1 5 3 4",
"output": "1"
},
{
"input": "2 2\n1 2 3 4\n1 5 6 4",
"output": "0"
},
{
"input": "2 3\n1 2 4 5\n1 2 1 3 2 3",
"output": "-1"
},
{
"input": "2 1\n1 2 1 3\n1 2",
"output": "1"
},
{
"input": "4 4\n1 2 3 4 5 6 7 8\n2 3 4 5 6 7 8 1",... | 1,529,171,705 | 4,805 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 77 | 0 | n , m = map(int,input().split())
l = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
o = 0
d = []
def divide_chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
x = list(divide_chunks(l, 2))
y = list(divide_chunks(k, 2))
for i in x:
if i in y:
x.remo... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have a... | ```python
n , m = map(int,input().split())
l = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
o = 0
d = []
def divide_chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
x = list(divide_chunks(l, 2))
y = list(divide_chunks(k, 2))
for i in x:
if i in y:
... | 0 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,694,087,554 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n , h = map(int, input().split())
l = list(map(int, input().split()))
width = n
for i in l:
if i > h:
width += 1
print(width) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n , h = map(int, input().split())
l = list(map(int, input().split()))
width = n
for i in l:
if i > h:
width += 1
print(width)
``` | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,698,558,583 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | s=input()
print([s,s.capitalize()][s[1:]==s[1:].upper()]) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
s=input()
print([s,s.capitalize()][s[1:]==s[1:].upper()])
``` | 0 | |
919 | A | Supermarket | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation"
] | null | null | We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo.
Now imagine you'd... | The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples.
The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ... | The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$.
Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ... | [
"3 5\n1 2\n3 4\n1 3\n",
"2 1\n99 100\n98 99\n"
] | [
"1.66666667\n",
"0.98989899\n"
] | In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan.
In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan. | 500 | [
{
"input": "3 5\n1 2\n3 4\n1 3",
"output": "1.66666667"
},
{
"input": "2 1\n99 100\n98 99",
"output": "0.98989899"
},
{
"input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8... | 1,654,537,940 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n,m = list(map(int,input().split()))
lst = []
for nt in range(n):
st = list(map(int,input().split()))
lst.append(st[0]/st[1])
print(min(lst)*m)
| Title: Supermarket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo... | ```python
n,m = list(map(int,input().split()))
lst = []
for nt in range(n):
st = list(map(int,input().split()))
lst.append(st[0]/st[1])
print(min(lst)*m)
``` | 3 | |
915 | B | Browser | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong ... | The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. | Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*]. | [
"6 3 2 4\n",
"6 3 1 3\n",
"5 2 1 5\n"
] | [
"5\n",
"1\n",
"0\n"
] | In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current ... | 0 | [
{
"input": "6 3 2 4",
"output": "5"
},
{
"input": "6 3 1 3",
"output": "1"
},
{
"input": "5 2 1 5",
"output": "0"
},
{
"input": "100 1 1 99",
"output": "99"
},
{
"input": "100 50 1 99",
"output": "50"
},
{
"input": "100 99 1 99",
"output": "1"
},... | 1,516,354,424 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 5,632,000 | import sys
a = list(map(int,input().split()))
n,pos,l,r = a[0],a[1],a[2],a[3]
res = 0
if l != 1 and r != n and l <= pos and pos <= r :
res = min( pos - l + 1 + r - l + 1, r - pos + 1 + r - l + 1 )
elif l == 1 and r != n:
res = abs(r - pos) + 1
elif r == n and l != 1:
res = abs(l - pos) + 1 | Title: Browser
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *... | ```python
import sys
a = list(map(int,input().split()))
n,pos,l,r = a[0],a[1],a[2],a[3]
res = 0
if l != 1 and r != n and l <= pos and pos <= r :
res = min( pos - l + 1 + r - l + 1, r - pos + 1 + r - l + 1 )
elif l == 1 and r != n:
res = abs(r - pos) + 1
elif r == n and l != 1:
res = abs(l -... | 0 | |
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th... | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ... | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2... | 1,647,265,053 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 |
def solve() :
c=0
for i in arr[:-1]:
c+= d - i
return c
d=int(input())
n=int(input())
arr=[int(x) for x in input().split()]
print(solve())
'''
t=int(input())
for i in range(t) :
print(solve())
n,m= [int(x) for x in input().split()]
n=int(input())
arr=[]
for i in r... | Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any ... | ```python
def solve() :
c=0
for i in arr[:-1]:
c+= d - i
return c
d=int(input())
n=int(input())
arr=[int(x) for x in input().split()]
print(solve())
'''
t=int(input())
for i in range(t) :
print(solve())
n,m= [int(x) for x in input().split()]
n=int(input())
arr=[]
... | 3 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,618,896,437 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | x=int(input())
p=101
q=101
arr=[int(x) for x in input().split()]
for n in arr:
#n=int(input())
if n<p:
q=p
p=n
elif(n!=p and n<q):
q=n
if(q==101):
print("No")
else:
print(q)
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
x=int(input())
p=101
q=101
arr=[int(x) for x in input().split()]
for n in arr:
#n=int(input())
if n<p:
q=p
p=n
elif(n!=p and n<q):
q=n
if(q==101):
print("No")
else:
print(q)
``` | 0 |
197 | B | Limit | PROGRAMMING | 1,400 | [
"math"
] | null | null | You are given two polynomials:
- *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*.
Calculate limit . | The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=100) — degrees of polynomials *P*(*x*) and *Q*(*x*) correspondingly.
The second line contains *n*<=+<=1 space-separated integers — the factors of polynomial *P*(*x*): *a*0, *a*1, ..., *a**n*<=-<=1, *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100... | If the limit equals <=+<=∞, print "Infinity" (without quotes). If the limit equals <=-<=∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where *p... | [
"2 1\n1 1 1\n2 5\n",
"1 0\n-1 3\n2\n",
"0 1\n1\n1 0\n",
"2 2\n2 1 6\n4 5 -7\n",
"1 1\n9 0\n-5 2\n"
] | [
"Infinity\n",
"-Infinity\n",
"0/1\n",
"1/2\n",
"-9/5\n"
] | Let's consider all samples:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c28febca257452afdfcbd6984ba8623911f9bdbc.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e55ecd04e54a45e5e0092ec9a5c1ea03bb... | 500 | [
{
"input": "2 1\n1 1 1\n2 5",
"output": "Infinity"
},
{
"input": "1 0\n-1 3\n2",
"output": "-Infinity"
},
{
"input": "0 1\n1\n1 0",
"output": "0/1"
},
{
"input": "2 2\n2 1 6\n4 5 -7",
"output": "1/2"
},
{
"input": "1 1\n9 0\n-5 2",
"output": "-9/5"
},
{
... | 1,636,914,240 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 62 | 0 | import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return... | Title: Limit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two polynomials:
- *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*.
Calculate l... | ```python
import sys
import math
from sys import stdin, stdout
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(... | -1 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,602,514,573 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 186 | 307,200 | n = int(input())
inp = []
users = {}
for elem in range(n):
a = input().split()
a[1] = int(a[1])
inp.append(a)
if users.get(a[0]):
users[a[0]] += a[1]
else:
users[a[0]] = a[1]
# print(inp)
# print(users)
max = -1000000000000000001
user = ''
count_max = 0
for i in users... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n = int(input())
inp = []
users = {}
for elem in range(n):
a = input().split()
a[1] = int(a[1])
inp.append(a)
if users.get(a[0]):
users[a[0]] += a[1]
else:
users[a[0]] = a[1]
# print(inp)
# print(users)
max = -1000000000000000001
user = ''
count_max = 0
for ... | 0 |
772 | B | Volatile Kite | PROGRAMMING | 1,800 | [
"geometry"
] | null | null | You are given a convex polygon *P* with *n* distinct vertices *p*1,<=*p*2,<=...,<=*p**n*. Vertex *p**i* has coordinates (*x**i*,<=*y**i*) in the 2D plane. These vertices are listed in clockwise order.
You can choose a real number *D* and move each vertex of the polygon a distance of at most *D* from their original pos... | The first line has one integer *n* (4<=≤<=*n*<=≤<=1<=000) — the number of vertices.
The next *n* lines contain the coordinates of the vertices. Line *i* contains two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th vertex. These points are guaranteed to be given in cloc... | Print one real number *D*, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The ch... | [
"4\n0 0\n0 1\n1 1\n1 0\n",
"6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4\n"
] | [
"0.3535533906\n",
"1.0000000000\n"
] | Here is a picture of the first sample
<img class="tex-graphics" src="https://espresso.codeforces.com/f83aa076d2f437f9bb785cae769c3ae310eff351.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Here is an example of making the polygon non-convex.
<img class="tex-graphics" src="https://espresso.codeforces.com/fbadb8... | 1,000 | [
{
"input": "4\n0 0\n0 1\n1 1\n1 0",
"output": "0.3535533906"
},
{
"input": "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4",
"output": "1.0000000000"
},
{
"input": "19\n449447997 711296339\n530233434 692216537\n535464528 613140435\n535533467 100893188\n530498867 -265063956\n519107979 -271820709\... | 1,492,360,994 | 4,094 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,529,600 | import math
from decimal import Decimal
n = int(input())
d = [[0,0] for i in range(n)]
for i in range(n):
d[i] = list(map(int,input().split()))
def cnt(m):
l = m - 1;
if (l < 0): l = n - 1;
r = (m + 1) % n
a = math.sqrt((d[l][0] - d[m][0])**2 + (d[l][1] - d[m][1]) ** 2)
b = math.sqrt(... | Title: Volatile Kite
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a convex polygon *P* with *n* distinct vertices *p*1,<=*p*2,<=...,<=*p**n*. Vertex *p**i* has coordinates (*x**i*,<=*y**i*) in the 2D plane. These vertices are listed in clockwise order.
You can choose a re... | ```python
import math
from decimal import Decimal
n = int(input())
d = [[0,0] for i in range(n)]
for i in range(n):
d[i] = list(map(int,input().split()))
def cnt(m):
l = m - 1;
if (l < 0): l = n - 1;
r = (m + 1) % n
a = math.sqrt((d[l][0] - d[m][0])**2 + (d[l][1] - d[m][1]) ** 2)
b = ... | 0 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,503,461,549 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | a=['0']*4
b=[""]*4
c=[0]*4
for i in range(4):
a[i],b[i]=map(str,input().split('.'))
c[i]=len(b[i])
c=sorted(c)
x=0
if(c[0]*2<=c[1]):
x=1
if(c[2]*2<=c[3]):
if(x==0):
x=2
else:
x=0
if(x==1):
for i in range(4):
if(len(b[i])==c[0]):
print(a[i])
... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
a=['0']*4
b=[""]*4
c=[0]*4
for i in range(4):
a[i],b[i]=map(str,input().split('.'))
c[i]=len(b[i])
c=sorted(c)
x=0
if(c[0]*2<=c[1]):
x=1
if(c[2]*2<=c[3]):
if(x==0):
x=2
else:
x=0
if(x==1):
for i in range(4):
if(len(b[i])==c[0]):
pri... | 3 | |
980 | C | Posterized | PROGRAMMING | 1,700 | [
"games",
"greedy"
] | null | null | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref... | The first line of input contains two integers $n$ and $k$ ($1 \leq n \leq 10^5$, $1 \leq k \leq 256$), the number of pixels in the image, and the maximum size of a group, respectively.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ($0 \leq p_i \leq 255$), where $p_i$ is the color of the $i$-th pixel. | Print $n$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter. | [
"4 3\n2 14 3 4\n",
"5 2\n0 2 1 255 254\n"
] | [
"0 12 3 3\n",
"0 1 1 254 254\n"
] | One possible way to group colors and assign keys for the first sample:
Color $2$ belongs to the group $[0,2]$, with group key $0$.
Color $14$ belongs to the group $[12,14]$, with group key $12$.
Colors $3$ and $4$ belong to group $[3, 5]$, with group key $3$.
Other groups won't affect the result so they are not lis... | 1,500 | [
{
"input": "4 3\n2 14 3 4",
"output": "0 12 3 3"
},
{
"input": "5 2\n0 2 1 255 254",
"output": "0 1 1 254 254"
},
{
"input": "10 3\n112 184 161 156 118 231 191 128 91 229",
"output": "110 182 159 154 116 229 189 126 89 229"
},
{
"input": "9 3\n174 149 118 124 166 146 219 233 ... | 1,614,955,891 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 8 | 108 | 2,150,400 | # cook your dish here
from collections import Counter
from sys import stdin, stdout
n,kkkkk=map(int, stdin.readline().split())
x=list(map(int, stdin.readline().split()))
dic=Counter()
for i in x:
if dic[i]!=0:
print(min(dic[i]),end=" ")
else:
a=i-kkkkk+1
if a... | Title: Posterized
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th intege... | ```python
# cook your dish here
from collections import Counter
from sys import stdin, stdout
n,kkkkk=map(int, stdin.readline().split())
x=list(map(int, stdin.readline().split()))
dic=Counter()
for i in x:
if dic[i]!=0:
print(min(dic[i]),end=" ")
else:
a=i-kkkkk+1
... | -1 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,691,467,695 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | M, N = map(int, input().split())
if M > N:
M, N = N, M
max_dominos = (M * N) // 2
print(max_dominos)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M, N = map(int, input().split())
if M > N:
M, N = N, M
max_dominos = (M * N) // 2
print(max_dominos)
``` | 3.977 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,587,045,249 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 342 | 0 | '''Young Physicist Solution
'''
N = int(input())
x, y, z = 0, 0, 0
for row in range(N):
xn, yn, zn = list(map(int, input().split()))
x += xn
y += yn
z += zn
if x == 0 and y == 0 and z == 0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
'''Young Physicist Solution
'''
N = int(input())
x, y, z = 0, 0, 0
for row in range(N):
xn, yn, zn = list(map(int, input().split()))
x += xn
y += yn
z += zn
if x == 0 and y == 0 and z == 0:
print('YES')
else:
print('NO')
``` | 3.9145 |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,669,439,483 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | a,b = map(int,input().split(" "))
status = True
def isPrime(num):
i =2
while i <=num//2:
if num%i ==0:
return False
i+=1
return True
i =a
while i <=b:
if not isPrime(i) and (i ==a or i ==b):
status = False
break
if isPrime(i) and i !=... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
a,b = map(int,input().split(" "))
status = True
def isPrime(num):
i =2
while i <=num//2:
if num%i ==0:
return False
i+=1
return True
i =a
while i <=b:
if not isPrime(i) and (i ==a or i ==b):
status = False
break
if isPrime(i... | 3.969 |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,684,979,005 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | f = input()
b = f[::-1]
s1 = input()
s2 = input()
i = -1
j = -1
try:
i = f.index(s1)
j = f.index(s2, i+len(s1))
except:
pass
forward = bool(j > -1)
i = -1
j = -1
try:
i = b.index(s1)
j = b.index(s2, i+len(s1))
except:
pass
backward = bool(j > -1)
if forward:
if b... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
f = input()
b = f[::-1]
s1 = input()
s2 = input()
i = -1
j = -1
try:
i = f.index(s1)
j = f.index(s2, i+len(s1))
except:
pass
forward = bool(j > -1)
i = -1
j = -1
try:
i = b.index(s1)
j = b.index(s2, i+len(s1))
except:
pass
backward = bool(j > -1)
if forward:... | 3.938 |
389 | B | Fox and Cross | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
Ciel wants to draw several... | The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board.
Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. | Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". | [
"5\n.#...\n####.\n.####\n...#.\n.....\n",
"4\n####\n####\n####\n####\n",
"6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n",
"6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n",
"3\n...\n...\n...\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In example 1, you can draw two crosses. The picture below shows what they look like.
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all. | 1,000 | [
{
"input": "4\n####\n####\n####\n####",
"output": "NO"
},
{
"input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.",
"output": "YES"
},
{
"input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.",
"output": "NO"
},
{
"input": "5\n.....\n.#...\n####.\n.####\n...#.",
... | 1,623,887,009 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 62 | 0 | qtd = int(input())
matriz = []*qtd
velha = 0
for i in range(qtd):
lista = list(input())
matriz.append(lista)
for i in range(qtd):
for j in range(qtd):
if (matriz[i][j] == '#'):
velha+=1
if (velha %5==0):
print("YES")
else:
print("NO")
| Title: Fox and Cross
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of t... | ```python
qtd = int(input())
matriz = []*qtd
velha = 0
for i in range(qtd):
lista = list(input())
matriz.append(lista)
for i in range(qtd):
for j in range(qtd):
if (matriz[i][j] == '#'):
velha+=1
if (velha %5==0):
print("YES")
else:
print("NO")
``` | 0 | |
220 | B | Little Elephant and Array | PROGRAMMING | 1,800 | [
"constructive algorithms",
"data structures"
] | null | null | The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. T... | In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query. | [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] | [
"3\n1\n"
] | none | 1,000 | [
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,515,522,601 | 3,301 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 4,000 | 35,328,000 | from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
d = {}
for i in range(n):
v = values[i]
if v in d:
d[v].append(i)
else:
d[v] = [i]
challengers = []
for v in d:
if len(d[v]) >= v:
... | Title: Little Elephant and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant... | ```python
from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
d = {}
for i in range(n):
v = values[i]
if v in d:
d[v].append(i)
else:
d[v] = [i]
challengers = []
for v in d:
if len(d[v... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,695,162,628 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | word = input()
word_lowercase = word.lower()
count_uppercase = 0
for i in range(0, len(word)):
if word[i] != word_lowercase[i]:
count_uppercase += 1
if count_uppercase > len(word)/2:
print(word.upper())
else:
print(word_lowercase) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
word_lowercase = word.lower()
count_uppercase = 0
for i in range(0, len(word)):
if word[i] != word_lowercase[i]:
count_uppercase += 1
if count_uppercase > len(word)/2:
print(word.upper())
else:
print(word_lowercase)
``` | 3.977 |
894 | C | Marco and GCD Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"math"
] | null | null | In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.
When he woke up, he only remembered that the key was a sequence of positive integers of some length *n*, but forgot the exact sequence. Let the elements of the sequence ... | The first line contains a single integer *m* (1<=≤<=*m*<=≤<=1000) — the size of the set *S*.
The second line contains *m* integers *s*1,<=*s*2,<=...,<=*s**m* (1<=≤<=*s**i*<=≤<=106) — the elements of the set *S*. It's guaranteed that the elements of the set are given in strictly increasing order, that means *s*1<=<<... | If there is no solution, print a single line containing -1.
Otherwise, in the first line print a single integer *n* denoting the length of the sequence, *n* should not exceed 4000.
In the second line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the sequence.
We can show that if a solution e... | [
"4\n2 4 6 12\n",
"2\n2 3\n"
] | [
"3\n4 6 12",
"-1\n"
] | In the first example 2 = *gcd*(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among *gcd*(*a*<sub class="lower-index">*i*</sub>, *a*<sub class="lower-index">*i* + 1</sub>, ..., *a*<sub class="lower-index">*j*</sub>) for every 1 ≤ *i*... | 1,500 | [
{
"input": "4\n2 4 6 12",
"output": "7\n2 2 4 2 6 2 12"
},
{
"input": "2\n2 3",
"output": "-1"
},
{
"input": "2\n1 6",
"output": "3\n1 1 6"
},
{
"input": "3\n1 2 7",
"output": "5\n1 1 2 1 7"
},
{
"input": "1\n1",
"output": "1\n1"
},
{
"input": "2\n1 10... | 1,619,530,620 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 109 | 2,457,600 | n=int(input());
s=list(map(int,input().split()));
p=s[0];
for i in s:
if(i%p):
print(-1);
exit(0);
ans=[];
for i in s:
ans+=[i,p];
print(len(ans));
print(*ans); | Title: Marco and GCD Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.
When he woke up, he only remembered that the key was a sequen... | ```python
n=int(input());
s=list(map(int,input().split()));
p=s[0];
for i in s:
if(i%p):
print(-1);
exit(0);
ans=[];
for i in s:
ans+=[i,p];
print(len(ans));
print(*ans);
``` | 3 | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,656,473,344 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | # -*- coding: utf-8 -*-
"""codeforces 622B
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1fnRVrX6kGGXBPnaZduqeU_eo6w87jUi5
"""
T=input()
a=int(input())
h=int(T[ :-3])
m=int(T[-2: ])
x=a//60
y=a%60
hour=h+x
min=m+y
if min>=60:
min=min-60
ho... | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
# -*- coding: utf-8 -*-
"""codeforces 622B
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1fnRVrX6kGGXBPnaZduqeU_eo6w87jUi5
"""
T=input()
a=int(input())
h=int(T[ :-3])
m=int(T[-2: ])
x=a//60
y=a%60
hour=h+x
min=m+y
if min>=60:
min=mi... | 3 | |
356 | A | Knight Tournament | PROGRAMMING | 1,500 | [
"data structures",
"dsu"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th f... | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | 500 | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"out... | 1,682,608,460 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 13,004,800 | n, m = map(int, input().split())
vivo, vencedor = [True] * (n + 2), [0] * (n + 2)
for _ in range(m):
l, r, x = map(int, input().split())
for i in range(l, r + 1):
if i != x and vivo[i]:
vencedor[i] = x
vivo[i] = False
print(' '.join(map(str, vencedor[1:-1])))
... | Title: Knight Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're j... | ```python
n, m = map(int, input().split())
vivo, vencedor = [True] * (n + 2), [0] * (n + 2)
for _ in range(m):
l, r, x = map(int, input().split())
for i in range(l, r + 1):
if i != x and vivo[i]:
vencedor[i] = x
vivo[i] = False
print(' '.join(map(str, vencedor[1:-1])))
... | 0 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,695,104,106 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 10,854,400 | n = int(input())
bills = list(map(int, input().split()))
change_25 = 0
change_50 = 0
for bill in bills:
if bill == 25:
change_25 += 1
elif bill == 50:
if change_25 >= 1:
change_25 -= 1
change_50 += 1
else:
print("NO")
break
elif bill ... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n = int(input())
bills = list(map(int, input().split()))
change_25 = 0
change_50 = 0
for bill in bills:
if bill == 25:
change_25 += 1
elif bill == 50:
if change_25 >= 1:
change_25 -= 1
change_50 += 1
else:
print("NO")
break
... | 3 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,597,941,579 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 8,806,400 | n,m = map(int,input().split())
a=[]
s = ''
for i in range(m):
a.append(input())
lec = input().split()
for r in lec:
for b in a:
c = b.split()
if r in c:
if len(c[0])==len(c[1]):
s += c[0] + " "
elif len(c[0])<len(c[1]) :
s+= c[0]... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n,m = map(int,input().split())
a=[]
s = ''
for i in range(m):
a.append(input())
lec = input().split()
for r in lec:
for b in a:
c = b.split()
if r in c:
if len(c[0])==len(c[1]):
s += c[0] + " "
elif len(c[0])<len(c[1]) :
... | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,692,398,077 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 124 | 2,867,200 | def prime(n):
factor = set()
d = 2
while d * d <= n:
while n % d == 0:
factor.add(d)
n //= d
d += 1
if n >1:
factor.add(n)
return factor
n = int(input())
count = 0
for i in range(2, n+1):
ans = prime(i)
if len... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
def prime(n):
factor = set()
d = 2
while d * d <= n:
while n % d == 0:
factor.add(d)
n //= d
d += 1
if n >1:
factor.add(n)
return factor
n = int(input())
count = 0
for i in range(2, n+1):
ans = prime(i)
... | 3.963659 |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "59... | 1,492,533,589 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 5,529,600 | n = int(input())
if n == 0:
print(1)
else:
ans = 1
for i in range(n - 1):
ans *= 3
print(ans % 1000003) | Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
n = int(input())
if n == 0:
print(1)
else:
ans = 1
for i in range(n - 1):
ans *= 3
print(ans % 1000003)
``` | 3.9587 |
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n5100... | 1,615,464,531 | 531 | PyPy 3 | OK | TESTS | 48 | 171 | 10,444,800 | import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify, nlargest
from copy import deepcopy
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sy... | Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di... | ```python
import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify, nlargest
from copy import deepcopy
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(m... | 3 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,655,216,780 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n=int(input())
str=input()
if n%2:
print(str[1::2][::-1]+str[0::2])
else:
print(str[0::2][::-1]+str[1::2])
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n=int(input())
str=input()
if n%2:
print(str[1::2][::-1]+str[0::2])
else:
print(str[0::2][::-1]+str[1::2])
``` | 3 | |
346 | A | Alice and Bob | PROGRAMMING | 1,600 | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 500 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
... | 1,586,279,540 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | n=int(input())
arr=list(map(int,input().split(' ')))
c=0
for el1 in arr:
for el2 in arr:
if(abs(el1-el2) not in arr and el1!=el2):
arr.append(abs(el1-el2))
c+=1
else:
break
if(c%2==0):
print("Bob")
else:
print("Alice")
| Title: Alice and Bob
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following ... | ```python
n=int(input())
arr=list(map(int,input().split(' ')))
c=0
for el1 in arr:
for el2 in arr:
if(abs(el1-el2) not in arr and el1!=el2):
arr.append(abs(el1-el2))
c+=1
else:
break
if(c%2==0):
print("Bob")
else:
print("Alice"... | 0 | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,687,157,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | import sys
n = int(input())
a = list(map(int, input().split()))
#first array should have odd negative numbers
#second array should have even negative numbers
#third array should have one or more zeroes
#each array should have atleast one integer
neg = 0
ze = 0
for i in a:
if i < 0:
neg += 1... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
import sys
n = int(input())
a = list(map(int, input().split()))
#first array should have odd negative numbers
#second array should have even negative numbers
#third array should have one or more zeroes
#each array should have atleast one integer
neg = 0
ze = 0
for i in a:
if i < 0:
... | 0 | |
983 | A | Finite or not? | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. | For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] | $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | 500 | [
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfini... | 1,698,611,386 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
long long p, q, b;
cin >> p >> q >> b;
long long g = __gcd(p, q);
q /= g;
b = __gcd(q, b);
while (b ... | Title: Finite or not?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ ... | ```python
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
long long p, q, b;
cin >> p >> q >> b;
long long g = __gcd(p, q);
q /= g;
b = __gcd(q, b);
... | -1 | |
0 | none | none | none | 0 | [
"none"
] | 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. | 0 | [
{
"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,511,414,127 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | num1, num2, num3, num4, num5, num6= input('Enter 6 numbers: ').split()
num1 = int(num1)
num2 = int(num2)
num3 = int(num3)
num4 = int(num4)
num5 = int(num5)
num6 = int(num6)
if ((num1+num2+num3)==(num4+num5+num6)):
print("Yes")
elif ((num1+num2+num4)==(num3+num5+num6)):
print("Yes")
elif ((num1+num2... | Title: none
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 exac... | ```python
num1, num2, num3, num4, num5, num6= input('Enter 6 numbers: ').split()
num1 = int(num1)
num2 = int(num2)
num3 = int(num3)
num4 = int(num4)
num5 = int(num5)
num6 = int(num6)
if ((num1+num2+num3)==(num4+num5+num6)):
print("Yes")
elif ((num1+num2+num4)==(num3+num5+num6)):
print("Yes")
elif (... | 0 | |
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,650,763,915 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | from collections import deque
r, c = tuple(map(int, input().replace("\n","").split()))
land_map = [[0]*c for _ in range(r)]
for i in range(r):
line = input().rstrip("\n")
for j in range(c):
if line[j] == '.' or line[j] == '#':
land_map[i][j] = line[j]
else:
l... | 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
from collections import deque
r, c = tuple(map(int, input().replace("\n","").split()))
land_map = [[0]*c for _ in range(r)]
for i in range(r):
line = input().rstrip("\n")
for j in range(c):
if line[j] == '.' or line[j] == '#':
land_map[i][j] = line[j]
else:
... | 0 | |
638 | B | Making Genome in Berland | PROGRAMMING | 1,500 | [
"*special",
"dfs and similar",
"strings"
] | null | null | Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragmen... | In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. | [
"3\nbcd\nab\ncdef\n",
"4\nx\ny\nz\nw\n"
] | [
"abcdef\n",
"xyzw\n"
] | none | 1,000 | [
{
"input": "3\nbcd\nab\ncdef",
"output": "abcdef"
},
{
"input": "4\nx\ny\nz\nw",
"output": "xyzw"
},
{
"input": "25\nef\nfg\ngh\nhi\nij\njk\nkl\nlm\nmn\nno\nab\nbc\ncd\nde\nop\npq\nqr\nrs\nst\ntu\nuv\nvw\nwx\nxy\nyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\nf... | 1,458,548,892 | 73,692 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,120,000 | #number = random.randrange(start, stop, step)
n = int(input())
arr = []
arr2 = ""
for i in range(n):
arr.append(str(input()))
res = []
count = -1
z = 0
while len(arr) != 0:
z = 0
flag = False
for j in range(len(arr)):
for k in arr[j]:
for s in range(j,len(arr)):
if a... | Title: Making Genome in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can... | ```python
#number = random.randrange(start, stop, step)
n = int(input())
arr = []
arr2 = ""
for i in range(n):
arr.append(str(input()))
res = []
count = -1
z = 0
while len(arr) != 0:
z = 0
flag = False
for j in range(len(arr)):
for k in arr[j]:
for s in range(j,len(arr)):
... | 0 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,648,879,625 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | #██████████ █ █ /█\ █ █ ███ /█\ ██████████████
"█ █ █ /███\ █ █ █ ██ /███\ /██/ "
#█ █ █ /█████\ █ █ █ ██ /█████\ /██/
"█ █ █ █!:) █ █ █ █ ██ █ █ /██/ ... | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
#██████████ █ █ /█\ █ █ ███ /█\ ██████████████
"█ █ █ /███\ █ █ █ ██ /███\ /██/ "
#█ █ █ /█████\ █ █ █ ██ /█████\ /██/
"█ █ █ █!:) █ █ █ █ ██ █ █ /... | 0 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,636,880,611 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,505,600 | flag=True
s=input()
for i in range(len(s)-1):
if s[i] not in 'aeioun':
if str[i+1] not in 'aeiou':
flag=False
if i==len(str)-2:
if str[-1] not in 'aeioun':
flag=False
if flag == True:
print('YES')
else:
print('NO')
| Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
flag=True
s=input()
for i in range(len(s)-1):
if s[i] not in 'aeioun':
if str[i+1] not in 'aeiou':
flag=False
if i==len(str)-2:
if str[-1] not in 'aeioun':
flag=False
if flag == True:
print('YES')
else:
print('NO')
``` | -1 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,458,888,639 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,812,800 | #!/usr/bin/env python
from __future__ import print_function
from six.moves import input, range
uniq_elems = {}
dups = []
n = int(input())
l = []
for i in range(0, n):
x, y = [int(j) for j in input().split()]
if x == y:
l.append((x, y))
else:
if (x, y) in uniq_elems:
assert (y,... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
#!/usr/bin/env python
from __future__ import print_function
from six.moves import input, range
uniq_elems = {}
dups = []
n = int(input())
l = []
for i in range(0, n):
x, y = [int(j) for j in input().split()]
if x == y:
l.append((x, y))
else:
if (x, y) in uniq_elems:
... | -1 | |
924 | A | Mystical Mosaic | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a rectangular grid of *n* rows of *m* initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the grid, respectively.
Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desir... | If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it w... | 500 | [
{
"input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..",
"output": "Yes"
},
{
"input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..",
"output": "No"
},
{
"input": "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#",
"output": "No"
},
{
"input": "1 1\n#",
"o... | 1,690,495,599 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1690495599.0685108")# 1690495599.0685327 | Title: Mystical Mosaic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a rectangular grid of *n* rows of *m* initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-emp... | ```python
print("_RANDOM_GUESS_1690495599.0685108")# 1690495599.0685327
``` | 0 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,601,552,909 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | d = {}
res = ''
t = 0
for _ in range(int(input())):
s = input()
if s not in d:
d[s] = 1
else:
d[s] += 1
if d[s] > t:
res = s
t = d[s]
print(res) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
d = {}
res = ''
t = 0
for _ in range(int(input())):
s = input()
if s not in d:
d[s] = 1
else:
d[s] += 1
if d[s] > t:
res = s
t = d[s]
print(res)
``` | 3.9455 |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,671,295,054 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | for i in range(int(input())):
c=0
d=0
s=[]
x=[]
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
a=s.append(a)
a=s.append(c)
a=s.append(e)
b=x.append(b)
b=x.append(d)
b=x.append(f)
for i in range(len(s)):
... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
for i in range(int(input())):
c=0
d=0
s=[]
x=[]
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
a=s.append(a)
a=s.append(c)
a=s.append(e)
b=x.append(b)
b=x.append(d)
b=x.append(f)
for i in range(len(s)... | -1 | |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,445,765,417 | 1,817 | Python 3 | OK | TESTS | 27 | 420 | 3,174,400 | def solve():
N, M = map(int, input().split())
name = input()
td = {}
for c in 'abcdefghijklmnopqrstuvwxyz':
td[c] = c
for i in range(M):
p, m = input().split()
if p == m:
continue
pt = td[p]
mt = td[m]
del td[p]
del td[m]
... | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
def solve():
N, M = map(int, input().split())
name = input()
td = {}
for c in 'abcdefghijklmnopqrstuvwxyz':
td[c] = c
for i in range(M):
p, m = input().split()
if p == m:
continue
pt = td[p]
mt = td[m]
del td[p]
del td[m... | 3 | |
626 | A | Robot Sequence | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s... | The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands.
The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code. | Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square. | [
"6\nURLLDR\n",
"4\nDLUU\n",
"7\nRLRLRLR\n"
] | [
"2\n",
"0\n",
"12\n"
] | In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.
Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result. | 500 | [
{
"input": "6\nURLLDR",
"output": "2"
},
{
"input": "4\nDLUU",
"output": "0"
},
{
"input": "7\nRLRLRLR",
"output": "12"
},
{
"input": "1\nR",
"output": "0"
},
{
"input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL... | 1,566,419,574 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 140 | 0 | n=int(input())
a=input()
ans=0
for i in range(n+1):
for j in range(i):
l=a[j:i].count("L")
r=a[j:i].count("R")
u=a[j:i].count("U")
d=a[j:i].count("D")
if l==r and u==d:
ans+=1
print(ans)
| Title: Robot Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively... | ```python
n=int(input())
a=input()
ans=0
for i in range(n+1):
for j in range(i):
l=a[j:i].count("L")
r=a[j:i].count("R")
u=a[j:i].count("U")
d=a[j:i].count("D")
if l==r and u==d:
ans+=1
print(ans)
``` | 3 | |
839 | B | Game of the Rows | PROGRAMMING | 1,900 | [
"brute force",
"greedy",
"implementation"
] | null | null | Daenerys Targaryen has an army consisting of *k* groups of soldiers, the *i*-th group contains *a**i* soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has *n* rows, each of them has 8 seats. We ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10000, 1<=≤<=*k*<=≤<=100) — the number of rows and the number of groups of soldiers, respectively.
The second line contains *k* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=10000), where *a**i* denotes the number of soldiers in the *i*-th ... | If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).
You can choose the case (lower or upper) for each letter arbitrary. | [
"2 2\n5 8\n",
"1 2\n7 1\n",
"1 2\n4 4\n",
"1 4\n2 2 1 2\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, Daenerys can place the soldiers like in the figure below:
In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.
In the third example Daenerys can place the first group on seats (... | 1,000 | [
{
"input": "2 2\n5 8",
"output": "YES"
},
{
"input": "1 2\n7 1",
"output": "NO"
},
{
"input": "1 2\n4 4",
"output": "YES"
},
{
"input": "1 4\n2 2 1 2",
"output": "YES"
},
{
"input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778... | 1,598,273,154 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 12 | 156 | 20,172,800 | from sys import stdin
n,k = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
if sum(a) <= n*3:
print('YES')
else:
a.sort(reverse=True)
four = n
two = n*2
one = 0
v = True
for x in a:
if x%2 == 1:
if one:
one -= 1
x -= 1
... | Title: Game of the Rows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Daenerys Targaryen has an army consisting of *k* groups of soldiers, the *i*-th group contains *a**i* soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought a... | ```python
from sys import stdin
n,k = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
if sum(a) <= n*3:
print('YES')
else:
a.sort(reverse=True)
four = n
two = n*2
one = 0
v = True
for x in a:
if x%2 == 1:
if one:
one -= 1
... | 0 | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,618,489,650 | 2,147,483,647 | Python 3 | OK | TESTS | 157 | 62 | 0 | a, b = sorted(input()), int(input())
for i in range(len(a)):
for j in range(i+1, len(a)):
c = int(str.join('', a))
a[i], a[j] = a[j], a[i]
d = int(str.join('', a))
if c <= d <= b:
continue
else:
a[i], a[j] = a[j], a[i]
print(str.join('', a)) | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
a, b = sorted(input()), int(input())
for i in range(len(a)):
for j in range(i+1, len(a)):
c = int(str.join('', a))
a[i], a[j] = a[j], a[i]
d = int(str.join('', a))
if c <= d <= b:
continue
else:
a[i], a[j] = a[j], a[i]
print(str.join('', a))
``` | 3 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,641,304,581 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | """https://codeforces.com/problemset/problem/577/A"""
rows, num = [int(x) for x in input().split()]
times = 0
for row in range(rows):
for column in range(rows):
if (row + 1) * (column + 1) == num:
times += 1
print(times)
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
"""https://codeforces.com/problemset/problem/577/A"""
rows, num = [int(x) for x in input().split()]
times = 0
for row in range(rows):
for column in range(rows):
if (row + 1) * (column + 1) == num:
times += 1
print(times)
``` | 0 | |
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,584,771,694 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 139 | 0 | tests = int(input())
list =[]
for number in range(tests):
a= str(input())
list.append(a)
flag = 0
for temp in range(tests):
for temp1 in range(temp):
if list[temp]==list[temp1]:
flag = 1
break
if flag :
print('YES')
else:
print('NO') | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
tests = int(input())
list =[]
for number in range(tests):
a= str(input())
list.append(a)
flag = 0
for temp in range(tests):
for temp1 in range(temp):
if list[temp]==list[temp1]:
flag = 1
break
if flag :
print('YES')
else:
print(... | 0 | |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,533,847,305 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
pos = []
land = []
for i in range(n):
p, l = list(map(int,input().strip().split(' ')))
pos.append(p):
land.append(p + l)
c = 0
for i in land:
if i in pos:
c += 1
if c == 2:
print("YES")
break
if c != 2:
print("NO") | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
n = int(input())
pos = []
land = []
for i in range(n):
p, l = list(map(int,input().strip().split(' ')))
pos.append(p):
land.append(p + l)
c = 0
for i in land:
if i in pos:
c += 1
if c == 2:
print("YES")
break
if c != 2:
print("NO")
``` | -1 |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,697,557,705 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | n = int(input())
a = []
for i in range(n):
a.append([*input()])
yes = True
for i in range(n):
for j in range(n):
if i == j or i + j == n-1:
if a[i][j] != a[0][0]:
yes = not yes
break
elif a[i][j] == a[0][0] or a[i][j] != a[0][1]:
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
a = []
for i in range(n):
a.append([*input()])
yes = True
for i in range(n):
for j in range(n):
if i == j or i + j == n-1:
if a[i][j] != a[0][0]:
yes = not yes
break
elif a[i][j] == a[0][0] or a[i][j] != a[0][1]:... | 0 | |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,585,051,404 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 156 | 0 | import sys
n=int(sys.stdin.readline())
sher=list(input())
mon=list(input())
sher.sort()
mon.sort()
#minimum no of flicks Mon will get
c=mon.copy()
d=sher.copy()
i=0
j=0
ans1=0
ans2=0
while(i<n and j<n):
if c[i]>=d[j]:
i+=1
j+=1
else:
i+=1
ans1+=1
print(ans1) ... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
import sys
n=int(sys.stdin.readline())
sher=list(input())
mon=list(input())
sher.sort()
mon.sort()
#minimum no of flicks Mon will get
c=mon.copy()
d=sher.copy()
i=0
j=0
ans1=0
ans2=0
while(i<n and j<n):
if c[i]>=d[j]:
i+=1
j+=1
else:
i+=1
ans1+=1
pr... | 3 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,695,846,408 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
percent = list(map(int, input().split()))
print(sum(percent)/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
percent = list(map(int, input().split()))
print(sum(percent)/n)
``` | 3 | |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,654,917,753 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 93 | 307,200 | import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
g = [input()[:-1].lower().split(' reposted ') for _ in range(n)]
d = defaultdict(int)
d['polycarp'] = 1
for i in range(n):
d[g[i][0]] += d[g[i][1]] + 1
print(max(d.values()))
| Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
g = [input()[:-1].lower().split(' reposted ') for _ in range(n)]
d = defaultdict(int)
d['polycarp'] = 1
for i in range(n):
d[g[i][0]] += d[g[i][1]] + 1
print(max(d.values()))
``` | 3 | |
267 | A | Subtractions | PROGRAMMING | 900 | [
"math",
"number theory"
] | null | null | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). | Print the sought number of operations for each pair on a single line. | [
"2\n4 17\n7 987654321\n"
] | [
"8\n141093479\n"
] | none | 500 | [
{
"input": "2\n4 17\n7 987654321",
"output": "8\n141093479"
},
{
"input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321",
"output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479... | 1,635,453,267 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 140 | 20,684,800 | n = int(input())
def compute(a, b):
iters = 0
while a > 0 and b > 0:
if a > b:
iters += a // b
a %= b
else:
iters += b // a
b %= a
return iters
for _ in range(n):
a, b = tuple(map(int, input().split()))
print(compute(a,... | Title: Subtractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one o... | ```python
n = int(input())
def compute(a, b):
iters = 0
while a > 0 and b > 0:
if a > b:
iters += a // b
a %= b
else:
iters += b // a
b %= a
return iters
for _ in range(n):
a, b = tuple(map(int, input().split()))
print(... | 3 | |
439 | B | Devu, the Dumb Guy | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other ... | The first line will contain two space separated integers *n*, *x* (1<=≤<=*n*,<=*x*<=≤<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | 1,000 | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3... | 1,619,779,498 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 186 | 7,577,600 | n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
for i in range(n):
c+=x[i]*max((m-i),1)
print(c) | Title: Devu, the Dumb Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co... | ```python
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
for i in range(n):
c+=x[i]*max((m-i),1)
print(c)
``` | 3 | |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for ... | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use al... | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"i... | 1,664,028,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | from collections import defaultdict
n, k = map(int,input().split())
arr = list(map(int,input().split()))
index = defaultdict(list)
for i,n in enumerate(arr):
index[n].append(i)
ans = []
for n in sorted(set(arr)):
i = 0
while k-n>=0 and i<len(index[n]):
k-=n
ans.append(str(in... | Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr ... | ```python
from collections import defaultdict
n, k = map(int,input().split())
arr = list(map(int,input().split()))
index = defaultdict(list)
for i,n in enumerate(arr):
index[n].append(i)
ans = []
for n in sorted(set(arr)):
i = 0
while k-n>=0 and i<len(index[n]):
k-=n
ans.app... | 0 | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,517,938,478 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 5,632,000 | number = input().strip()
if len(number) <= 4:
print("no")
else:
numOne = 0
for x in range(len(number)-4, len(number)):
if number[x] == 1:
numOne += 1
if numOne <= 1:
print("yes")
else:
pring("no")
| Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
number = input().strip()
if len(number) <= 4:
print("no")
else:
numOne = 0
for x in range(len(number)-4, len(number)):
if number[x] == 1:
numOne += 1
if numOne <= 1:
print("yes")
else:
pring("no")
``` | 0 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,676,617,905 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 78 | 0 | def solve():
n, k = [int(x) for x in input().split()]
print((n + k) - (n % k))
solve()
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
def solve():
n, k = [int(x) for x in input().split()]
print((n + k) - (n % k))
solve()
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,619,866,969 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | d={"":0,"-":1,"--":2}
c=input()
pos=0
l=[]
for i in range(len(c)):
if c[i]==".":
l.append(c[pos:i+1])
pos=i+1
for j in l:
if len(j)%2==0:
l1=(len(j)-2)//2
print("2"*l1,end="")
print("1",end="")
else:
l1=(len(j)-1)//2
print("2"*l1,end... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
d={"":0,"-":1,"--":2}
c=input()
pos=0
l=[]
for i in range(len(c)):
if c[i]==".":
l.append(c[pos:i+1])
pos=i+1
for j in l:
if len(j)%2==0:
l1=(len(j)-2)//2
print("2"*l1,end="")
print("1",end="")
else:
l1=(len(j)-1)//2
print(... | 3.969 |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,631,788,433 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 77 | 6,963,200 | def dfs(x,p):
if x==1:
l[x]=0
prob[x]=1
else:
l[x]=l[p]+1
prob[x]=1/(len(graph[p])-1)*prob[p]
if p==1:
prob[x]=1/(len(graph[p]))*prob[p]
for k in graph[x]:
if k!=p:
dfs(k,x)
if len(graph[x])==1 and x!=1:
leaf.ap... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
def dfs(x,p):
if x==1:
l[x]=0
prob[x]=1
else:
l[x]=l[p]+1
prob[x]=1/(len(graph[p])-1)*prob[p]
if p==1:
prob[x]=1/(len(graph[p]))*prob[p]
for k in graph[x]:
if k!=p:
dfs(k,x)
if len(graph[x])==1 and x!=1:
... | -1 | |
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"o... | 1,634,934,223 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 4,505,600 | n = int(input())
a = list(map(int, input().split()))
# v = "YES"
# if(sum(a)%200==0):
# if(n%2!=0):
# if(100 not in a):
# v = "NO"
# else:
# v = "NO"
# print(v)
count1 = 0
count2 = 0
for i in a:
if(i==100):
count1 += 1
elif(i==200):
count2 += 1
if(count1%2==0 and count2%2==0):
prin... | Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w... | ```python
n = int(input())
a = list(map(int, input().split()))
# v = "YES"
# if(sum(a)%200==0):
# if(n%2!=0):
# if(100 not in a):
# v = "NO"
# else:
# v = "NO"
# print(v)
count1 = 0
count2 = 0
for i in a:
if(i==100):
count1 += 1
elif(i==200):
count2 += 1
if(count1%2==0 and count2%2==... | 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,606,293,213 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 307,200 | def main():
char_in_hello = [char for char in 'hello']
message = input()
chars_to_remove = [char for char in message if char not in char_in_hello]
final_word = message
for char in chars_to_remove:
final_word = final_word.replace(char, '')
word_list = [char for char in final_wo... | 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
def main():
char_in_hello = [char for char in 'hello']
message = input()
chars_to_remove = [char for char in message if char not in char_in_hello]
final_word = message
for char in chars_to_remove:
final_word = final_word.replace(char, '')
word_list = [char for char i... | -1 |
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,601,907,227 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 80 | 466 | 0 | s=0
for _ in range(int(input())):
x,y,z=map(int,input().split())
s+=x+y+z
if(s):
print("NO")
else:
print("YES")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
s=0
for _ in range(int(input())):
x,y,z=map(int,input().split())
s+=x+y+z
if(s):
print("NO")
else:
print("YES")
``` | 0 |
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"input": "100\n... | 1,638,351,844 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 61 | 0 |
def main_function():
n = int(input())
a = sorted([int(i) for i in input().split(" ")])
hash_a = {}
for i in a:
if i in hash_a:
hash_a[i] += 1
else:
hash_a[i] = 1
counter = 0
is_there_non_zero = True
while is_there_non_zero:
in... | Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to a... | ```python
def main_function():
n = int(input())
a = sorted([int(i) for i in input().split(" ")])
hash_a = {}
for i in a:
if i in hash_a:
hash_a[i] += 1
else:
hash_a[i] = 1
counter = 0
is_there_non_zero = True
while is_there_non_zero:
... | 0 | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,683,715,622 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | m, s = map(int, input().split())
ns = ""
while s > 0:
if s - 9 > 0:
s = s - 9
ns += '9'
else:
break
if s > 0:
ns += str(s)
if len(ns) == m:
print(ns[::-1], ns)
else:
print(-1, -1)
| Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
m, s = map(int, input().split())
ns = ""
while s > 0:
if s - 9 > 0:
s = s - 9
ns += '9'
else:
break
if s > 0:
ns += str(s)
if len(ns) == m:
print(ns[::-1], ns)
else:
print(-1, -1)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,640,890,138 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 216 | 0 | s = input()
up = [i for i in s if i.isupper()]
sm = [i for i in s if i.islower()]
if len(up) <= len(sm):
print(s.lower())
else:
print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
up = [i for i in s if i.isupper()]
sm = [i for i in s if i.islower()]
if len(up) <= len(sm):
print(s.lower())
else:
print(s.upper())
``` | 3.946 |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,585,396,607 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 218 | 0 | from sys import stdin,stdout
str1 = stdin.readline().strip()
str1 = str1.replace(' ','')
print('YES' if str1[-2].upper() in ['A', 'E', 'I', 'O', 'U', 'Y'] else 'NO') | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
from sys import stdin,stdout
str1 = stdin.readline().strip()
str1 = str1.replace(' ','')
print('YES' if str1[-2].upper() in ['A', 'E', 'I', 'O', 'U', 'Y'] else 'NO')
``` | 3.9455 |
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,590,390,507 | 507 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 204,800 | import math
n,d = map(int,input().split())
l = list(map(int,input().split()))
c=0
for i in range(1,n):
if l[i]<=l[i-1]:
m = abs(l[i]-l[i-1])
c+=int(math.ceil(m/d))
l[i] = l[i]+(d)*2
print(c)
| 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 = map(int,input().split())
l = list(map(int,input().split()))
c=0
for i in range(1,n):
if l[i]<=l[i-1]:
m = abs(l[i]-l[i-1])
c+=int(math.ceil(m/d))
l[i] = l[i]+(d)*2
print(c)
``` | 0 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,576,251,422 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 0 | n=int(input())
l=[]
for i in range(n):
l1=[int(x) for x in input().split()]
l.append(l1)
x=0
y=0
z=0
for i in l:
x=x+i[0]
y=y+i[1]
z=z+i[2]
if(x==0 and y==0 and z==0):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
l=[]
for i in range(n):
l1=[int(x) for x in input().split()]
l.append(l1)
x=0
y=0
z=0
for i in l:
x=x+i[0]
y=y+i[1]
z=z+i[2]
if(x==0 and y==0 and z==0):
print("YES")
else:
print("NO")
``` | 3.9455 |
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output"... | 1,558,037,451 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 139 | 0 | a, b = map(int, input().split())
x, y, z = map(int, input().split())
a_need = 0
b_need = 0
# yellow
a_need = x * 2
# green
a_need += y
b_need += y
# blue
b_need += z * 3
a_need = (a_need - a) if a_need > a else 0
b_need = (b_need - b) if b_need > b else 0
need_total = a_need + b_need
if need... | Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obta... | ```python
a, b = map(int, input().split())
x, y, z = map(int, input().split())
a_need = 0
b_need = 0
# yellow
a_need = x * 2
# green
a_need += y
b_need += y
# blue
b_need += z * 3
a_need = (a_need - a) if a_need > a else 0
b_need = (b_need - b) if b_need > b else 0
need_total = a_need + b_need
... | 3 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,529,495,158 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 810 | 8,396,800 | import math
a,b=input().split()
a,b=[int(a),int(b)]
n=int(input())
g=math.gcd(a,b)
ar=[]
i=1
while i*i<=g:
if g%i==0:
ar.append(i)
ar.append(g//i)
i+=1
ar.sort(reverse=True)
for i in range(0,n):
c,d=input().split()
c,d=[int(c),int(d)]
i=0
flag=0
if c==d:
... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
import math
a,b=input().split()
a,b=[int(a),int(b)]
n=int(input())
g=math.gcd(a,b)
ar=[]
i=1
while i*i<=g:
if g%i==0:
ar.append(i)
ar.append(g//i)
i+=1
ar.sort(reverse=True)
for i in range(0,n):
c,d=input().split()
c,d=[int(c),int(d)]
i=0
flag=0
if... | 3.78186 |
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.