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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
441 | D | Valera and Swaps | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dsu",
"graphs",
"implementation",
"math",
"string suffix structures"
] | null | null | A permutation *p* of length *n* is a sequence of distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*). A permutation is an identity permutation, if for any *i* the following equation holds *p**i*<==<=*i*.
A swap (*i*,<=*j*) is the operation that swaps elements *p**i* and *p**j* in the permutation. Let'... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3000) — the length of permutation *p*. The second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — Valera's initial permutation. The last line contains integer *m* (0<=≤<=*m*<=<<=*n*). | In the first line, print integer *k* — the minimum number of swaps.
In the second line, print 2*k* integers *x*1,<=*x*2,<=...,<=*x*2*k* — the description of the swap sequence. The printed numbers show that you need to consecutively make swaps (*x*1,<=*x*2), (*x*3,<=*x*4), ..., (*x*2*k*<=-<=1,<=*x*2*k*).
If there are... | [
"5\n1 2 3 4 5\n2\n",
"5\n2 1 4 5 3\n2\n"
] | [
"2\n1 2 1 3 ",
"1\n1 2 "
] | Sequence *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*s*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ..., *y*<sub class="lower-index">*s*</sub>, if there is such integer *r* (1 ≤... | 2,000 | [] | 1,690,900,392 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690900392.4285388")# 1690900392.428559 | Title: Valera and Swaps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation *p* of length *n* is a sequence of distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*). A permutation is an identity permutation, if for any *i* the following equation holds *p**i*<==<=*i*... | ```python
print("_RANDOM_GUESS_1690900392.4285388")# 1690900392.428559
``` | 0 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,681,415,568 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | from math import floor
[x,y] = list(map(int, input().rstrip().split()))
t = x
left_over = x
while left_over != 0:
left_over = floor(left_over / y)
t += left_over
print(t) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
from math import floor
[x,y] = list(map(int, input().rstrip().split()))
t = x
left_over = x
while left_over != 0:
left_over = floor(left_over / y)
t += left_over
print(t)
``` | 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,444,413,316 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <stdio.h>
int main ()
{
int i,j,n,x[200],count=0,d[200],s[200];
scanf("%d",&n);
for(i=1;i<=n;i++) {
scanf("%d %d",&x[i],&d[i]);
s[i]=x[i]+d[i];
}
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
if(i==j) {
continue;
}
... | 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
#include <stdio.h>
int main ()
{
int i,j,n,x[200],count=0,d[200],s[200];
scanf("%d",&n);
for(i=1;i<=n;i++) {
scanf("%d %d",&x[i],&d[i]);
s[i]=x[i]+d[i];
}
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
if(i==j) {
continue;
... | -1 |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,685,519,724 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 46 | 0 | s=input()
sl=[]
o={'>':'<','}':'{',']':'[',')':'('}
def of(c):
if o[c]==sl[-1]:
del sl[-1]
return
sl.append(c)
flag=0
for i in s:
if i in '<{[(':
sl.append(i)
continue
if []==sl:
flag=1
break
of(i)
if 1==flag:
print('Impossible')
else:
l=0
... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
s=input()
sl=[]
o={'>':'<','}':'{',']':'[',')':'('}
def of(c):
if o[c]==sl[-1]:
del sl[-1]
return
sl.append(c)
flag=0
for i in s:
if i in '<{[(':
sl.append(i)
continue
if []==sl:
flag=1
break
of(i)
if 1==flag:
print('Impossible')
else:... | 0 | |
786 | B | Legacy | PROGRAMMING | 2,300 | [
"data structures",
"graphs",
"shortest paths"
] | null | null | Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.
There are *n* planets in their universe numbered from 1 to *n*. Rick is in planet number *s* (the earth) and he doesn't know where Morty is. As we all... | The first line of input contains three integers *n*, *q* and *s* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*s*<=≤<=*n*) — number of planets, number of plans and index of earth respectively.
The next *q* lines contain the plans. Each line starts with a number *t*, type of that plan (1<=≤<=*t*<=≤<=3). If *t*<==<=1 then it is foll... | In the first and only line of output print *n* integers separated by spaces. *i*-th of them should be minimum money to get from earth to *i*-th planet, or <=-<=1 if it's impossible to get to that planet. | [
"3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17\n",
"4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16\n"
] | [
"0 28 12 \n",
"0 -1 -1 12 \n"
] | In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2. | 1,000 | [
{
"input": "3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17",
"output": "0 28 12 "
},
{
"input": "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16",
"output": "0 -1 -1 12 "
},
{
"input": "6 1 5\n1 3 6 80612370",
"output": "-1 -1 -1 -1 0 -1 "
},
{
"input": "10 8 7\n1 10 ... | 1,491,314,984 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | xc
xc
xc
xc
x
cx
cx
c
xc
x
cx
c
xc
xc
xc
x
cx
xcxc
x
cx
c
xc
xc
x
cx
cx
c
xc
xc
x
cx
cx | Title: Legacy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.
There are *n* planets in their universe numbered from 1 to... | ```python
xc
xc
xc
xc
x
cx
cx
c
xc
x
cx
c
xc
xc
xc
x
cx
xcxc
x
cx
c
xc
xc
x
cx
cx
c
xc
xc
x
cx
cx
``` | -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,573,840,893 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 310 | 1,740,800 | t=int(input())
d,l={},[]
for _ in range(t):
s,n=map(str,input().split())
if s in d:
d[s]+=int(n)
else:
d[s]=int(n)
l.append((s,d[s]))
ma=max(d.values())
t=0
q=[]
for i,j in l:
q.append(i)
#print(q)
for i,j in l:
if d[i]==ma and j>=ma :
print(i)
break
... | 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
t=int(input())
d,l={},[]
for _ in range(t):
s,n=map(str,input().split())
if s in d:
d[s]+=int(n)
else:
d[s]=int(n)
l.append((s,d[s]))
ma=max(d.values())
t=0
q=[]
for i,j in l:
q.append(i)
#print(q)
for i,j in l:
if d[i]==ma and j>=ma :
print(i)
break
... | 3.83203 |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,696,365,085 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 77 | 0 | n = int(input())
col = n//100
n = n-(n//100)*100
col += n//20
n = n-(n//20)*20
col += n//10
n = n-(n//10)*10
col += n//5
n = n-(n//5)*5
col += n//1
n = n-(n//1)*1
print(col) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
n = int(input())
col = n//100
n = n-(n//100)*100
col += n//20
n = n-(n//20)*20
col += n//10
n = n-(n//10)*10
col += n//5
n = n-(n//5)*5
col += n//1
n = n-(n//1)*1
print(col)
``` | 3 | |
394 | A | Counting Sticks | PROGRAMMING | 0 | [
"brute force",
"implementation"
] | null | null | When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add... | The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. | If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print... | [
"||+|=|||||\n",
"|||||+||=||\n",
"|+|=||||||\n",
"||||+||=||||||\n"
] | [
"|||+|=||||\n",
"Impossible\n",
"Impossible\n",
"||||+||=||||||\n"
] | In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth s... | 500 | [
{
"input": "||+|=|||||",
"output": "|||+|=||||"
},
{
"input": "|||||+||=||",
"output": "Impossible"
},
{
"input": "|+|=||||||",
"output": "Impossible"
},
{
"input": "||||+||=||||||",
"output": "||||+||=||||||"
},
{
"input": "||||||||||||+|||||||||||=||||||||||||||... | 1,586,942,609 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 14 | 140 | 0 | try:
lst=list(input())
x=lst.count('|')
#print(x)
if x%2!=0:
print("Impossible")
elif x==0:
print("Impossible")
elif x==1:
print("Impossible")
elif x==2:
print("Impossible")
else:
left=lst[:lst.index('=')].count('|')
right=lst[lst.index('='):].count('|')
#print(left,right)
if l... | Title: Counting Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our te... | ```python
try:
lst=list(input())
x=lst.count('|')
#print(x)
if x%2!=0:
print("Impossible")
elif x==0:
print("Impossible")
elif x==1:
print("Impossible")
elif x==2:
print("Impossible")
else:
left=lst[:lst.index('=')].count('|')
right=lst[lst.index('='):].count('|')
#print(left,righ... | 0 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,657,481,570 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | n,m=map(int,input().split())
y=1
for i in range(n):
a=list(map(str,input().split()))
for j in a:
if j!='W' and j!='B' and j!='G':
y=0
if y==1:
print('#Black&White')
else:
print('#Color')
| Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n,m=map(int,input().split())
y=1
for i in range(n):
a=list(map(str,input().split()))
for j in a:
if j!='W' and j!='B' and j!='G':
y=0
if y==1:
print('#Black&White')
else:
print('#Color')
``` | 3 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,660,932,947 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | first_input = [int(x) for x in input().split()]
n = first_input[0]
m = first_input[1]
second_input = [int(x) for x in input().split()]
list = []
for i in range(n):
list.append(0)
for j in second_input:
list[j-1] += 1
print(min(list))
| Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
first_input = [int(x) for x in input().split()]
n = first_input[0]
m = first_input[1]
second_input = [int(x) for x in input().split()]
list = []
for i in range(n):
list.append(0)
for j in second_input:
list[j-1] += 1
print(min(list))
``` | 3 | |
625 | C | K-special Tables | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you ar... | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | 1,000 | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
... | 1,689,016,363 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 52 | 218 | 10,342,400 | import collections
import math
import copy
def main():
#n = int(input())
n,k = list(map(int,input().split()))
#m = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
#a = list(map(int,input().split()))
solution(n,k)
def solution(n,k):
max_num = n*n-(n-... | Title: K-special Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects... | ```python
import collections
import math
import copy
def main():
#n = int(input())
n,k = list(map(int,input().split()))
#m = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
#a = list(map(int,input().split()))
solution(n,k)
def solution(n,k):
max_num... | 3 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,575,319,458 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 140 | 0 | count = int(0)
count2 = int(0)
count3 = int(0)
count4 = int(0)
low=int(0)
s = input()
size = len(s)
i=0
for i in range(size):
if(s[i]=='i'):
count = count + 1
elif(s[i]=='t'):
count2 = count2 + 1
elif(s[i]=='n'):
count3 = count3 + 1
elif(s[i]=='e'):
coun... | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
count = int(0)
count2 = int(0)
count3 = int(0)
count4 = int(0)
low=int(0)
s = input()
size = len(s)
i=0
for i in range(size):
if(s[i]=='i'):
count = count + 1
elif(s[i]=='t'):
count2 = count2 + 1
elif(s[i]=='n'):
count3 = count3 + 1
elif(s[i]=='e'):
... | -1 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,685,048,364 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import math
def pavimento(n,m,a):
return max(math.ceil(n/a),math.ceil(m/a))**2
lista=list(map(int,input().split()))
n=lista[0]
m=lista[1]
a=lista[2]
print(pavimento(n,m,a))
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
def pavimento(n,m,a):
return max(math.ceil(n/a),math.ceil(m/a))**2
lista=list(map(int,input().split()))
n=lista[0]
m=lista[1]
a=lista[2]
print(pavimento(n,m,a))
``` | 0 |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,635,360,715 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,198,400 | import math
d, h, v, e = map(int, input().split())
area = math.pi * (d / 2) ** 2
t = (A * h) / (v - A * e)
if v <= area * e:
print('NO')
else:
print('Yes')
print(t)
| Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
import math
d, h, v, e = map(int, input().split())
area = math.pi * (d / 2) ** 2
t = (A * h) / (v - A * e)
if v <= area * e:
print('NO')
else:
print('Yes')
print(t)
``` | -1 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,587,517,429 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 45 | 218 | 307,200 | n = int(input())
li = []
for i in range(n):
x, y = map(int, input().split())
li.append((x, y))
cnt = 0
vis = {}
for i in range(n):
for j in range(n):
if i == j:
continue
if li[i] not in vis or li[j] not in vis:
if li[i][0] == li[j][0] or li[i][1] == li[j][... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
n = int(input())
li = []
for i in range(n):
x, y = map(int, input().split())
li.append((x, y))
cnt = 0
vis = {}
for i in range(n):
for j in range(n):
if i == j:
continue
if li[i] not in vis or li[j] not in vis:
if li[i][0] == li[j][0] or li[i][1]... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,661,478,235 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | str = input().strip()
c, C, i, l = 0, 0, 0, len(str)
while i < l:
if ord(str[i]) > 96:
c += 1
else:
C += 1
i += 1
if c < C:
print(str.upper())
else:
print(str.lower())
| 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
str = input().strip()
c, C, i, l = 0, 0, 0, len(str)
while i < l:
if ord(str[i]) > 96:
c += 1
else:
C += 1
i += 1
if c < C:
print(str.upper())
else:
print(str.lower())
``` | 3.977 |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,575,456,786 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 108 | 0 | s2=input()
s3=[]
w=0
for i in range(len(s2)):
if s2[i] =='A':
s3.append(w)
w=0
continue
elif s2[i]=='O':
s3.append(w)
w=0
continue
elif s2[i]=='U':
s3.append(w)
w=0
continue
elif s2[i]=='E':
s3.append(w)
w=0
continue
elif s2[i]=='Y':
s3.... | Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
s2=input()
s3=[]
w=0
for i in range(len(s2)):
if s2[i] =='A':
s3.append(w)
w=0
continue
elif s2[i]=='O':
s3.append(w)
w=0
continue
elif s2[i]=='U':
s3.append(w)
w=0
continue
elif s2[i]=='E':
s3.append(w)
w=0
continue
elif s2[i]=='Y'... | -1 | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,502,525,580 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n = int(input())
ch1 = str(input())
count = 0
max = 0
for i in range(n):
if( ch1[i] <= 'Z' and ch1[i] >= 'A' ):
count = count + 1
if( ch1[i] == ' '):
if( max <= count ):
max = count
count = 0
print( max )
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = int(input())
ch1 = str(input())
count = 0
max = 0
for i in range(n):
if( ch1[i] <= 'Z' and ch1[i] >= 'A' ):
count = count + 1
if( ch1[i] == ' '):
if( max <= count ):
max = count
count = 0
print( max )
``` | 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,591,850,932 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | #ashu@gate22
s=input()
lentgh=len(s)
no_upper=0
no_lower=0
for i in s:
if i.isupper():
no_upper+=1
else:
no_lower+=1
if no_lower>=no_upper:
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
#ashu@gate22
s=input()
lentgh=len(s)
no_upper=0
no_lower=0
for i in s:
if i.isupper():
no_upper+=1
else:
no_lower+=1
if no_lower>=no_upper:
print(s.lower())
else:
print(s.upper())
``` | 3.9455 |
774 | C | Maximum Number | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "711111111111111111111111111111111111111111111111... | 1,491,408,544 | 2,044 | Python 3 | OK | TESTS | 21 | 202 | 6,451,200 | a = int(input())
if ( a % 2 ):
print('7', end='')
a -= 3
while (a > 0) :
a -= 2
print('1', end='') | Title: Maximum Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 o... | ```python
a = int(input())
if ( a % 2 ):
print('7', end='')
a -= 3
while (a > 0) :
a -= 2
print('1', end='')
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,593,717,920 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | from math import*
n=int(input())
ans=0
for i in range(int(log10(n))):
ans+=9*10**i
print(ans+(n-ans)*len(str(n))) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
from math import*
n=int(input())
ans=0
for i in range(int(log10(n))):
ans+=9*10**i
print(ans+(n-ans)*len(str(n)))
``` | 0 | |
808 | G | Anthem of Berland | PROGRAMMING | 2,300 | [
"dp",
"strings"
] | null | null | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105).
The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105).
Product of lengths of strings |*s*|·|*t*| won't exceed 107. | Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. | [
"winlose???winl???w??\nwin\n",
"glo?yto?e??an?\nor\n",
"??c?????\nabcab\n"
] | [
"5\n",
"3\n",
"2\n"
] | In the first example the resulting string *s* is "winlosewinwinlwinwin"
In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab"... | 0 | [
{
"input": "winlose???winl???w??\nwin",
"output": "5"
},
{
"input": "glo?yto?e??an?\nor",
"output": "3"
},
{
"input": "??c?????\nabcab",
"output": "2"
},
{
"input": "ddddd\nd",
"output": "5"
},
{
"input": "ww?ww\nw",
"output": "5"
},
{
"input": "?????\... | 1,495,282,685 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | z = input()
s = input()
ls = len(s)
res = 0
ss = [0] * (ls + 1)
i, j = 0, 1
while j < ls:
while j < ls and s[i] == s[j]:
i += 1
j += 1
ss[j] = i
if j == ls:
ss[j] = i
if i == 0:
j += 1
else:
i = 0
j = 0
n = len(z)
while i < n:
while... | Title: Anthem of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there i... | ```python
z = input()
s = input()
ls = len(s)
res = 0
ss = [0] * (ls + 1)
i, j = 0, 1
while j < ls:
while j < ls and s[i] == s[j]:
i += 1
j += 1
ss[j] = i
if j == ls:
ss[j] = i
if i == 0:
j += 1
else:
i = 0
j = 0
n = len(z)
while i < n:
... | 0 | |
729 | A | Interview with Oleg | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 500 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input":... | 1,604,469,927 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 108 | 0 | from math import ceil
n = int(input())
x = input()
p = ['ogo']+['ogo'+'go'*i for i in range(1,50)]
j = ceil((n-3)/2)
if n<3:
print(x)
else:
for i in range(100, 0, -1):
ss = 'o' + 'go' * i
while ss in x:
x = x.replace(ss,'***')
print(x)
| Title: Interview with Oleg
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a fi... | ```python
from math import ceil
n = int(input())
x = input()
p = ['ogo']+['ogo'+'go'*i for i in range(1,50)]
j = ceil((n-3)/2)
if n<3:
print(x)
else:
for i in range(100, 0, -1):
ss = 'o' + 'go' * i
while ss in x:
x = x.replace(ss,'***')
print(x)
``` | 3 | |
557 | A | Ilya and Diplomas | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | null | null | Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the fir... | In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first... | [
"6\n1 5\n2 6\n3 7\n",
"10\n1 2\n1 3\n1 5\n",
"6\n1 3\n2 2\n2 2\n"
] | [
"1 2 3 \n",
"2 3 5 \n",
"2 2 2 \n"
] | none | 500 | [
{
"input": "6\n1 5\n2 6\n3 7",
"output": "1 2 3 "
},
{
"input": "10\n1 2\n1 3\n1 5",
"output": "2 3 5 "
},
{
"input": "6\n1 3\n2 2\n2 2",
"output": "2 2 2 "
},
{
"input": "55\n1 1000000\n40 50\n10 200",
"output": "5 40 10 "
},
{
"input": "3\n1 1\n1 1\n1 1",
"o... | 1,437,043,393 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def console_line_to_int_arr(string):
return [int(i) for i in string.split(" ")]
########################
n = int(input())
arr = [console_line_to_int_arr(input()), console_line_to_int_arr(input()), console_line_to_int_arr(input())]
n = n - arr[0][0] - arr[1][0] - arr[2][0]
for i in arr:
print(arr, n)
... | Title: Ilya and Diplomas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the re... | ```python
def console_line_to_int_arr(string):
return [int(i) for i in string.split(" ")]
########################
n = int(input())
arr = [console_line_to_int_arr(input()), console_line_to_int_arr(input()), console_line_to_int_arr(input())]
n = n - arr[0][0] - arr[1][0] - arr[2][0]
for i in arr:
print(... | 0 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,663,791,525 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 62 | 0 | s=input()
t=int(input())
z=10100000021490214901902490214091491041290109411204929041209421490129040921490124901490214901490
s2=s
for i in range(t):
k=input()
if k.startswith(s):
if len(k)<=z:
z=len(k)
s2=k
print(s2) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s=input()
t=int(input())
z=10100000021490214901902490214091491041290109411204929041209421490129040921490124901490214901490
s2=s
for i in range(t):
k=input()
if k.startswith(s):
if len(k)<=z:
z=len(k)
s2=k
print(s2)
``` | 0 |
911 | D | Inversion Counting | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=><=*j* and *a**i*<=<<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1500) — the size of the permutation.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of the permutation. These integers are pairwise distinct.
The third line contains one integer *m* (1<=≤<=*m*<=≤<=2·105) — the... | Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise. | [
"3\n1 2 3\n2\n1 2\n2 3\n",
"4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n"
] | [
"odd\neven\n",
"odd\nodd\nodd\neven\n"
] | The first example:
1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2).
The second example:
1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], i... | 0 | [
{
"input": "3\n1 2 3\n2\n1 2\n2 3",
"output": "odd\neven"
},
{
"input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3",
"output": "odd\nodd\nodd\neven"
},
{
"input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5",
"output": "odd\nodd\neven\nodd\neven"
},
{
"input": "3\n2 1 3\n3\n2 3\n1 ... | 1,514,655,904 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 1,700 | 21,504,000 | n = int(input())
lst = []
for x in input().split():
lst.append(int(x))
m = int(input())
pair = []
for x in range(m):
(l, r) = map(int, input().split())
pair.append((l, r))
k = 0
for x in range(0, len(lst) - 1):
for y in range(x + 1, len(lst)):
if lst[y] < lst[x]:
... | Title: Inversion Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=><=*j* an... | ```python
n = int(input())
lst = []
for x in input().split():
lst.append(int(x))
m = int(input())
pair = []
for x in range(m):
(l, r) = map(int, input().split())
pair.append((l, r))
k = 0
for x in range(0, len(lst) - 1):
for y in range(x + 1, len(lst)):
if lst[y] < lst[x]:
... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,684,505,744 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n,m=map(int,input().split())
f=n*m
r=int(f/2)
print(r) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n,m=map(int,input().split())
f=n*m
r=int(f/2)
print(r)
``` | 3.977 |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,591,722,548 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 2,744 | 1,638,400 | n=int(input())
dic={}
for i in range(1,n+1):
dic[i*i]=0
ans=0
for i in range(1,n+1):
for j in range(i,n+1):
if (i*i)+(j*j) in dic:
ans+=1
print(ans)
| Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
n=int(input())
dic={}
for i in range(1,n+1):
dic[i*i]=0
ans=0
for i in range(1,n+1):
for j in range(i,n+1):
if (i*i)+(j*j) in dic:
ans+=1
print(ans)
``` | 3 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,477,149,973 | 1,272 | Python 3 | OK | TESTS | 78 | 109 | 614,400 | n = int(input())
s = input()
l = 0
pos = 0
for i in range(len(s)):
if s[i] == '>':
l += 1
if l == 1:
pos = i
r = s.rfind("<")
ans = 0
if l > 0 and pos < r:
ans = r - pos + 1
print(len(s) - ans)
| Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
n = int(input())
s = input()
l = 0
pos = 0
for i in range(len(s)):
if s[i] == '>':
l += 1
if l == 1:
pos = i
r = s.rfind("<")
ans = 0
if l > 0 and pos < r:
ans = r - pos + 1
print(len(s) - ans)
``` | 3 | |
24 | A | Ring road | PROGRAMMING | 1,400 | [
"graphs"
] | A. Ring road | 2 | 256 | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly tw... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* t... | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | [
"3\n1 3 1\n1 2 1\n3 2 1\n",
"3\n1 3 1\n1 2 5\n3 2 1\n",
"6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n"
] | [
"1\n",
"2\n",
"39\n",
"0\n"
] | none | 0 | [
{
"input": "3\n1 3 1\n1 2 1\n3 2 1",
"output": "1"
},
{
"input": "3\n1 3 1\n1 2 5\n3 2 1",
"output": "2"
},
{
"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42",
"output": "39"
},
{
"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5",
"output": "0"
},
{
"input": "5\n... | 1,545,325,821 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 248 | 0 | n = int(input())
road = [map(int,input().split()) for i in range(n)]
graf = [[] for i in range(n + 1)]
s = 0
for a,b,c in road:
graf[a].append((b,0))
graf[b].append((a,c))
s += c
vis = [0] * (n + 1)
def dfs(u,p):
d = 0
for v,c in graf[u]:
if v != p and vis[v] == 0:
vis[v] = 1
d += d... | Title: Ring road
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were conne... | ```python
n = int(input())
road = [map(int,input().split()) for i in range(n)]
graf = [[] for i in range(n + 1)]
s = 0
for a,b,c in road:
graf[a].append((b,0))
graf[b].append((a,c))
s += c
vis = [0] * (n + 1)
def dfs(u,p):
d = 0
for v,c in graf[u]:
if v != p and vis[v] == 0:
vis[v] = 1
... | 3.938 |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,642,523,155 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 108 | 716,800 | a=input()
b=input()
l=len(a)-1
m=len(b)-1
while l>=0 and m>=0 and a[l]==b[m]:
l-=1
m-=1
print(l+m+2) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
a=input()
b=input()
l=len(a)-1
m=len(b)-1
while l>=0 and m>=0 and a[l]==b[m]:
l-=1
m-=1
print(l+m+2)
``` | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,692,204,947 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a = int(input())
b = int(input())
c = int(input())
print(max(a*b*c, (a+b)*c, (b+c)*a))
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a = int(input())
b = int(input())
c = int(input())
print(max(a*b*c, (a+b)*c, (b+c)*a))
``` | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,699,897,144 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 93 | 1,536,000 | rijec = input()
def racun(rijec):
zbroj = 0
for i in range(len(rijec)):
if rijec[i]=='Q':
for j in range(i+1,len(rijec)):
if rijec[j]=='A':
for x in range(j+1,len(rijec)):
if rijec[x]=='Q':
zbroj+=1
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
rijec = input()
def racun(rijec):
zbroj = 0
for i in range(len(rijec)):
if rijec[i]=='Q':
for j in range(i+1,len(rijec)):
if rijec[j]=='A':
for x in range(j+1,len(rijec)):
if rijec[x]=='Q':
zbr... | 3 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,679,999,198 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | b=int(input())
n=input()
c=0
d=0
for i in n:
if i=='S':
c=c+1
for j in range(len(n)-1):
if n[j:j+2]=='SF':
d=d+1
if c==1:
if d==1:
print("YES")
else:
print("NO")
else:
if d>1:
print("Yes")
else:
print("NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
b=int(input())
n=input()
c=0
d=0
for i in n:
if i=='S':
c=c+1
for j in range(len(n)-1):
if n[j:j+2]=='SF':
d=d+1
if c==1:
if d==1:
print("YES")
else:
print("NO")
else:
if d>1:
print("Yes")
else:
print("NO")
`... | 0 | |
328 | A | IQ Test | PROGRAMMING | 1,800 | [
"implementation"
] | null | null | Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 ... | The first line contains exactly four integer numbers between 1 and 1000, inclusively. | Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.
Print 42 if the given sequence is not an arithmetic or geometric progression. | [
"836 624 412 200\n",
"1 334 667 1000\n"
] | [
"-12\n",
"1333\n"
] | This problem contains very weak pretests! | 500 | [
{
"input": "836 624 412 200",
"output": "-12"
},
{
"input": "1 334 667 1000",
"output": "1333"
},
{
"input": "501 451 400 350",
"output": "42"
},
{
"input": "836 624 412 200",
"output": "-12"
},
{
"input": "1 334 667 1000",
"output": "1333"
},
{
"input... | 1,604,956,253 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#include <cmath>
using namespace std;
int main () {
IOS
ll arr [4];
double sum = 0;
for(int i = 0 ; i < 4 ; i++) {
cin >> arr[i];
sum =arr[i] + sum ;
}
double r = arr[1] / arr[0];
double... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progressi... | ```python
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#include <cmath>
using namespace std;
int main () {
IOS
ll arr [4];
double sum = 0;
for(int i = 0 ; i < 4 ; i++) {
cin >> arr[i];
sum =arr[i] + sum ;
}
double r = arr[1] / arr[0... | -1 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,676,029,900 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 17,408,000 | n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
first = 0
second = 0
for i in b:
first+=a.index(i)+1
second+=n-a.index(i)
print(first,second) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
first = 0
second = 0
for i in b:
first+=a.index(i)+1
second+=n-a.index(i)
print(first,second)
``` | 0 | |
978 | C | Letters | PROGRAMMING | 1,000 | [
"binary search",
"implementation",
"two pointers"
] | null | null | There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$.
A postman delivers letters. Sometimes there is no specific dormitory and roo... | The first line contains two integers $n$ and $m$ $(1 \le n, m \le 2 \cdot 10^{5})$ — the number of dormitories and the number of letters.
The second line contains a sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^{10})$, where $a_i$ equals to the number of rooms in the $i$-th dormitory. The third line contains a se... | Print $m$ lines. For each letter print two integers $f$ and $k$ — the dormitory number $f$ $(1 \le f \le n)$ and the room number $k$ in this dormitory $(1 \le k \le a_f)$ to deliver the letter. | [
"3 6\n10 15 12\n1 9 12 23 26 37\n",
"2 3\n5 10000000000\n5 6 9999999999\n"
] | [
"1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n",
"1 5\n2 1\n2 9999999994\n"
] | In the first example letters should be delivered in the following order:
- the first letter in room $1$ of the first dormitory - the second letter in room $9$ of the first dormitory - the third letter in room $2$ of the second dormitory - the fourth letter in room $13$ of the second dormitory - the fifth letter i... | 0 | [
{
"input": "3 6\n10 15 12\n1 9 12 23 26 37",
"output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"
},
{
"input": "2 3\n5 10000000000\n5 6 9999999999",
"output": "1 5\n2 1\n2 9999999994"
},
{
"input": "1 1\n1\n1",
"output": "1 1"
},
{
"input": "5 15\n10 20 30 20 10\n1 6 10 11 15 30 31 54... | 1,667,480,927 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 1,840 | 23,756,800 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(1,n):
a[i]+=a[i-1]
def rbinsearch(a, n,x):
l = -1
r = n - 1
while r - l > 1:
d = (l + r) // 2
if x <= a[d]:
r = d
else:
l = d
re... | Title: Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered fro... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(1,n):
a[i]+=a[i-1]
def rbinsearch(a, n,x):
l = -1
r = n - 1
while r - l > 1:
d = (l + r) // 2
if x <= a[d]:
r = d
else:
l =... | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,525,440,517 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 13,209,600 | line0=list(map(int,input().split()))
S=list(map(int,input().split()))
n,v_total,v_need=line0[0],line0[1],line0[2]
S_others=S[1:]
S_others.sort()
S0=S[0]
count=0
percent=S[0]/(S[0]+sum(S_others))
while percent<(v_need/v_total):
count+=1
S_others.pop()
percent=S[0]/(S[0]+sum(S_others))
pri... | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
line0=list(map(int,input().split()))
S=list(map(int,input().split()))
n,v_total,v_need=line0[0],line0[1],line0[2]
S_others=S[1:]
S_others.sort()
S0=S[0]
count=0
percent=S[0]/(S[0]+sum(S_others))
while percent<(v_need/v_total):
count+=1
S_others.pop()
percent=S[0]/(S[0]+sum(S_others))
... | 0 | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,525,547,693 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 93 | 7,065,600 | n, m = map(int, input().split())
arr = []
mx = [int(-1) for x in range(m)]
for _ in range(n):
temp = [int(x) for x in input().strip()]
for i,x in enumerate(temp):
mx[i] = max(mx[i], x)
arr.append(temp)
cnt = int(0)
for ar in arr:
for i,x in enumerate(ar):
if mx[i] == x:
cnt +... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
n, m = map(int, input().split())
arr = []
mx = [int(-1) for x in range(m)]
for _ in range(n):
temp = [int(x) for x in input().strip()]
for i,x in enumerate(temp):
mx[i] = max(mx[i], x)
arr.append(temp)
cnt = int(0)
for ar in arr:
for i,x in enumerate(ar):
if mx[i] == x:
... | 3 | |
318 | B | Strings of Power | PROGRAMMING | 1,300 | [
"implementation",
"strings",
"two pointers"
] | null | null | Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons... | Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters. | Print exactly one number — the number of powerful substrings of the given string.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"heavymetalisheavymetal\n",
"heavymetalismetal\n",
"trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n"
] | [
"3",
"2",
"3"
] | In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.
In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal". | 500 | [
{
"input": "heavymetalisheavymetal",
"output": "3"
},
{
"input": "heavymetalismetal",
"output": "2"
},
{
"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou",
"output": "3"
},
{
"input": "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmm... | 1,696,382,720 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 966 | 3,072,000 | # بسم الله الرحمن الرحيم
# صلو على نبينا محمد صلى الله عليه و سلم
##############--->>>>> Mohamed Mostafa Mohamed Abdelhamed <<<<<---##############
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ ... | Title: Strings of Power
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" an... | ```python
# بسم الله الرحمن الرحيم
# صلو على نبينا محمد صلى الله عليه و سلم
##############--->>>>> Mohamed Mostafa Mohamed Abdelhamed <<<<<---##############
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| ... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,633,114,701 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | x,y = input('enter: ').split()
surface = int(x) * int(y)
result = surface/2
print(int(result)) | 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
x,y = input('enter: ').split()
surface = int(x) * int(y)
result = surface/2
print(int(result))
``` | 0 |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,676,520,817 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a,b=[int(x) for x in input().split(" ")]
p=[b]
while(b>a):
if(b%2==0):
b=b//2
print(b)
p.insert(0,b)
elif((b-1)%10==0):
b=(b-1)//10
print(b)
p.insert(0,b)
else:
break
if(p[0]==a):
print("YES")
print(len(p))
print(p)
els... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
a,b=[int(x) for x in input().split(" ")]
p=[b]
while(b>a):
if(b%2==0):
b=b//2
print(b)
p.insert(0,b)
elif((b-1)%10==0):
b=(b-1)//10
print(b)
p.insert(0,b)
else:
break
if(p[0]==a):
print("YES")
print(len(p))
pri... | 0 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,699,308,052 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k , h = map(int,input().split())
for n in range(1,100):
m = k * n
if m % 10 == 0:
print(n)
break
elif (m - h) % 10 == 0:
print(n)
break | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k , h = map(int,input().split())
for n in range(1,100):
m = k * n
if m % 10 == 0:
print(n)
break
elif (m - h) % 10 == 0:
print(n)
break
``` | 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,689,759,463 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n = int(input())
contests = list(map(int, input().split()))
increasing = 0
decreasing = 0
for i in range(1, n):
if contests[i] > contests[i-1]:
increasing += 1
elif contests[i] < contests[i-1]:
decreasing += 1
amazing = max(increasing, decreasing)
print(amazing)
| 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())
contests = list(map(int, input().split()))
increasing = 0
decreasing = 0
for i in range(1, n):
if contests[i] > contests[i-1]:
increasing += 1
elif contests[i] < contests[i-1]:
decreasing += 1
amazing = max(increasing, decreasing)
print(amazing)
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,694,933,506 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | if __name__=="__main__":
num1=int(input())
num2=int(input())
ans = num1^num2
print(ans) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
if __name__=="__main__":
num1=int(input())
num2=int(input())
ans = num1^num2
print(ans)
``` | 0 |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,493,028,221 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,529,600 | s = input();
f = True;
if (s[0] == 'V' )&( s[1] == 'K'):
x = 1
else: x = 0
for index in range(2,len(s)):
if s[index] == 'K':
if s[index - 1] == 'V' :
x +=1;
elif s[index - 2] == 'K':
f = False;
elif (s[index - 1] == 'V' )& (s[index - 2] == 'V'):
f = False;
if f:
print (x)
else:
print (... | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s = input();
f = True;
if (s[0] == 'V' )&( s[1] == 'K'):
x = 1
else: x = 0
for index in range(2,len(s)):
if s[index] == 'K':
if s[index - 1] == 'V' :
x +=1;
elif s[index - 2] == 'K':
f = False;
elif (s[index - 1] == 'V' )& (s[index - 2] == 'V'):
f = False;
if f:
print (x)
else:... | 0 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,484,465,185 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 4,608,000 | def to_dec(bina):
res = 0
b = 2**len(bina)
for i in range(len(bina)):
b = b//2
if bina[i] == 1:
res = res + b
return res
def to_bin(d):
res = []
while d > 0:
res.insert(0, d%2)
d = d //2
return "".join(map(str, res))[::-1]
... | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
def to_dec(bina):
res = 0
b = 2**len(bina)
for i in range(len(bina)):
b = b//2
if bina[i] == 1:
res = res + b
return res
def to_bin(d):
res = []
while d > 0:
res.insert(0, d%2)
d = d //2
return "".join(map(str, res))[::-1]... | 3 | |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment... | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 2... | 1,692,977,992 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
l = list(map(int, input().split()))
sorted_l = sorted(l)
if sorted_l == l[::-1]:
print("yes")
print(f"1 {len(l)}")
else:
start, end = 0, 0
for i in range(len(l) - 1):
v1, v2 = l[i], l[i + 1]
if v1 > v2 and start == 0:
start = i
elif v1 < v2 and start... | Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your frie... | ```python
n = int(input())
l = list(map(int, input().split()))
sorted_l = sorted(l)
if sorted_l == l[::-1]:
print("yes")
print(f"1 {len(l)}")
else:
start, end = 0, 0
for i in range(len(l) - 1):
v1, v2 = l[i], l[i + 1]
if v1 > v2 and start == 0:
start = i
elif v1 < v2... | 0 | |
990 | B | Micro-World | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer c... | The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. | Print the only integer — minimal possible number of bacteria can remain. | [
"7 1\n101 53 42 102 101 55 54\n",
"6 5\n20 15 10 15 20 25\n",
"7 1000000\n1 1 1 1 1 1 1\n"
] | [
"3\n",
"1\n",
"7\n"
] | The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
I... | 0 | [
{
"input": "7 1\n101 53 42 102 101 55 54",
"output": "3"
},
{
"input": "6 5\n20 15 10 15 20 25",
"output": "1"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 4\n8",
"output": "1"
},
{
"inp... | 1,528,653,698 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # -*- coding: utf-8 -*-
"""
@Project : 牛客网
@File : 2.py
@Time : 2018/6/10 18:23
@Author : Koushiro
B. Micro-World
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a Petri dish with bacteria and you are preparing to dive into the hars... | Title: Micro-World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Pe... | ```python
# -*- coding: utf-8 -*-
"""
@Project : 牛客网
@File : 2.py
@Time : 2018/6/10 18:23
@Author : Koushiro
B. Micro-World
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a Petri dish with bacteria and you are preparing to dive int... | -1 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,537,171,372 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 280 | 0 | n,x,y = map(int,input().split())
import math
if((x/n)*100>=y):
print(0)
else:
z = math.ceil((y*n)/100)
print(z-x) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
n,x,y = map(int,input().split())
import math
if((x/n)*100>=y):
print(0)
else:
z = math.ceil((y*n)/100)
print(z-x)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,664,132,761 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | if __name__ == '__main__':
s = input()
t = input()
lower = 0
upper = 0
for char in s:
upper += 1
lower += 1
if t == s[::-1]:
print ('YES')
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
if __name__ == '__main__':
s = input()
t = input()
lower = 0
upper = 0
for char in s:
upper += 1
lower += 1
if t == s[::-1]:
print ('YES')
else:
print("NO")
``` | 3.977 |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,685,411,683 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n=int(input())
li=list(map(int,input().split()))
c=-1
m=li.index(max(li))
f=True
for i in range(n-1):
if (li.index(max(li))==0 and li.index(min(li))==n-1) or min(li)==li[-1] :
print(0)
f=False
break
if li[i]<li[i+1]:
li[i],li[i+1]=li[i+1],li[i]
c+=1
if f:
... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n=int(input())
li=list(map(int,input().split()))
c=-1
m=li.index(max(li))
f=True
for i in range(n-1):
if (li.index(max(li))==0 and li.index(min(li))==n-1) or min(li)==li[-1] :
print(0)
f=False
break
if li[i]<li[i+1]:
li[i],li[i+1]=li[i+1],li[i]
c+=1
... | 0 | |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,617,971,739 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 171 | 5,939,200 | n, m = map(int, input().split())
a = {input() for _ in range(n)}
b ={input() for _ in range(m)}
u = len(a.intersection(b))
print("NO") if m - u + u // 2 >= n - u + (u + 1) // 2 else print("YES") | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
n, m = map(int, input().split())
a = {input() for _ in range(n)}
b ={input() for _ in range(m)}
u = len(a.intersection(b))
print("NO") if m - u + u // 2 >= n - u + (u + 1) // 2 else print("YES")
``` | 3 | |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,584,625,428 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 124 | 0 | l = list(input().split())
if l[-1] == "month":
if int(l[0])<=29:
print(12)
elif int(l[0])==30:
print(11)
else:
print(7)
else:
if int(l[0])== 5 or int(l[0])==6:
print(53)
else:
print(52) | Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
l = list(input().split())
if l[-1] == "month":
if int(l[0])<=29:
print(12)
elif int(l[0])==30:
print(11)
else:
print(7)
else:
if int(l[0])== 5 or int(l[0])==6:
print(53)
else:
print(52)
``` | 3 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,606,988,384 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | n = int(input())
l = ""
s = set()
while(n):
a = input()
l+=a
s.add(a)
n-=1
if l == l[::-1] and len(s) == 2:
print('YES')
else:
print('NO')
| Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
l = ""
s = set()
while(n):
a = input()
l+=a
s.add(a)
n-=1
if l == l[::-1] and len(s) == 2:
print('YES')
else:
print('NO')
``` | 0 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,665,029,606 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a = int(input())
b = 0
for i in range(1, n//2+1):
if (a-i) % i == 0:
b += 1
print(b) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
a = int(input())
b = 0
for i in range(1, n//2+1):
if (a-i) % i == 0:
b += 1
print(b)
``` | -1 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,544,586,255 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 33 | 218 | 0 | r, g, b = list(map(int, input().split()))
br, bg, bb = r // 3, g // 3, b // 3
rr, rg, rb = r % 3, g % 3, b % 3
bm = min(rr, rg, rb)
result = br + bg + bb + bm
if(bm == 0 and rr + rg + rb == 4):
result = result + 1
print(result) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
r, g, b = list(map(int, input().split()))
br, bg, bb = r // 3, g // 3, b // 3
rr, rg, rb = r % 3, g % 3, b % 3
bm = min(rr, rg, rb)
result = br + bg + bb + bm
if(bm == 0 and rr + rg + rb == 4):
result = result + 1
print(result)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,673,022,275 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,150,400 | n= int(input())
s = list(map(int,input().split()))
for i in range (n):
if(n>10):
a = len(s)
b = a-2
print(s[0],b,s[n])
else:
print(s) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n= int(input())
s = list(map(int,input().split()))
for i in range (n):
if(n>10):
a = len(s)
b = a-2
print(s[0],b,s[n])
else:
print(s)
``` | -1 |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,687,240,366 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | #-*- coding = utf-8 -*-
#@Time : 2023/6/20 13:38
#@Author : xht
#@File : 514A.py
#@Software: PyCharm
l = input()
res = ''
for i in l:
res += str(min(9 - int(i) , int(i)))
print(int(res)) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
#-*- coding = utf-8 -*-
#@Time : 2023/6/20 13:38
#@Author : xht
#@File : 514A.py
#@Software: PyCharm
l = input()
res = ''
for i in l:
res += str(min(9 - int(i) , int(i)))
print(int(res))
``` | 0 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,673,891,112 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | hml = []
awl = []
count = 0
n = int(input())
for _ in range(n):
hm, aw = map(int, input().split())
hml.append(hm)
awl.append(aw)
for i in hml:
if i in awl:
count+= awl.count(i)
print(count) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
hml = []
awl = []
count = 0
n = int(input())
for _ in range(n):
hm, aw = map(int, input().split())
hml.append(hm)
awl.append(aw)
for i in hml:
if i in awl:
count+= awl.count(i)
print(count)
``` | 3 | |
797 | B | Odd sum | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequen... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | [
"4\n-2 2 -3 1\n",
"3\n2 -5 -3\n"
] | [
"3\n",
"-1\n"
] | In the first example sum of the second and the fourth elements is 3. | 0 | [
{
"input": "4\n-2 2 -3 1",
"output": "3"
},
{
"input": "3\n2 -5 -3",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046",
"ou... | 1,645,361,286 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 124 | 2,457,600 | import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from sys import stdin, stdout
import io
import math
import heapq
import bisect
import collections
import copy
import collections,sys,threading
def ceil(a, b):
return (a + b - 1) // b
inf = float('inf')
de... | Title: Odd sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains... | ```python
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from sys import stdin, stdout
import io
import math
import heapq
import bisect
import collections
import copy
import collections,sys,threading
def ceil(a, b):
return (a + b - 1) // b
inf = float(... | 0 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,593,596,682 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 93 | 0 | n, a, b = [int(x) for x in input().split()]
c = 1
if b < 0:
c = -1
for i in range(abs(b)):
a += c
if a > n or a < 1:
a = n
print(a)
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
n, a, b = [int(x) for x in input().split()]
c = 1
if b < 0:
c = -1
for i in range(abs(b)):
a += c
if a > n or a < 1:
a = n
print(a)
``` | 0 | |
90 | B | African Crossword | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. African Crossword | 2 | 256 | An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid. | Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. | [
"3 3\ncba\nbcd\ncbc\n",
"5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n"
] | [
"abcd",
"codeforces"
] | none | 1,000 | [
{
"input": "3 3\ncba\nbcd\ncbc",
"output": "abcd"
},
{
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf",
"output": "codeforces"
},
{
"input": "4 4\nusah\nusha\nhasu\nsuha",
"output": "ahhasusu"
},
{
"input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz",
"output... | 1,534,847,910 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 41 | 2,000 | 102,400 | n, m = map(int, input().split())
v = []
for _ in range(n):
v.append(input())
for i in range(n):
for j in range(m):
remain = True
for k in range(n):
if v[k][j] == v[i][j] and k != i:
remain = False
for k in range(m):
if v[i][k] == v[i][j... | Title: African Crossword
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To s... | ```python
n, m = map(int, input().split())
v = []
for _ in range(n):
v.append(input())
for i in range(n):
for j in range(m):
remain = True
for k in range(n):
if v[k][j] == v[i][j] and k != i:
remain = False
for k in range(m):
if v[i][k]... | 0 |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,554,019,091 | 251 | Python 3 | OK | TESTS | 22 | 327 | 3,891,200 | s = list(map(int, input()))
cnt = 0
for i in range(len(s) - 1):
if (s[i] * 2 + s[i + 1]) % 4 == 0:
cnt += i + 1
if s[i] % 4 == 0:
cnt += 1
if s[-1] % 4 == 0:
cnt += 1
print(cnt)
| Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
s = list(map(int, input()))
cnt = 0
for i in range(len(s) - 1):
if (s[i] * 2 + s[i + 1]) % 4 == 0:
cnt += i + 1
if s[i] % 4 == 0:
cnt += 1
if s[-1] % 4 == 0:
cnt += 1
print(cnt)
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,593,854,267 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 0 | y,w=list(map(int,input().split()))
print ('2' if max(y,w) is 3 else '5' if max(y,w) is 2 else '1',"/", sep="", end="")
print ('1' if max(y,w) is 1 else '2' if max(y,w) is 4 else '3' if max(y,w) is 5 or max(y,w) is 3 else '6')
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
y,w=list(map(int,input().split()))
print ('2' if max(y,w) is 3 else '5' if max(y,w) is 2 else '1',"/", sep="", end="")
print ('1' if max(y,w) is 1 else '2' if max(y,w) is 4 else '3' if max(y,w) is 5 or max(y,w) is 3 else '6')
``` | 3.891 |
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,686,336,795 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | m = int(input())
n = int(input())
x = (m*n)//2
print(x) | 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 = int(input())
n = int(input())
x = (m*n)//2
print(x)
``` | -1 |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,671,895,848 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 46 | 0 | l1=list(map(int, input().split()))
l2=list(map(int, input().split()))
print(max(abs(l1[0]-l2[0]), abs(l1[1]-l2[1]))) | Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
l1=list(map(int, input().split()))
l2=list(map(int, input().split()))
print(max(abs(l1[0]-l2[0]), abs(l1[1]-l2[1])))
``` | 3 | |
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,636,864,891 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 154 | 31,232,000 | from collections import defaultdict
def is_super_central(point, xmap, ymap):
x, y = point
yList = xmap[x]
xList = ymap[y]
if not xList or not yList:
return False
l, r = False, False
for xi in xList:
if xi < x:
l = True
if xi > x:
r ... | 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
from collections import defaultdict
def is_super_central(point, xmap, ymap):
x, y = point
yList = xmap[x]
xList = ymap[y]
if not xList or not yList:
return False
l, r = False, False
for xi in xList:
if xi < x:
l = True
if xi > x:
... | 3 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,691,894,884 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | x = input().split()
n = int(x[0])
h = int(x[1])
w = 0
heights = input().split()
for y in heights:
if int(y)>h:
w += 2
else:
w += 1
print(w)
| 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
x = input().split()
n = int(x[0])
h = int(x[1])
w = 0
heights = input().split()
for y in heights:
if int(y)>h:
w += 2
else:
w += 1
print(w)
``` | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,581,217,083 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 108 | 307,200 | n = int(input())
if (n == 0):
print(15)
else:
num_input = input()
a = [0]
if (n > 1):
num_input = num_input.split(" ");
for i in range(n):
a.append(int(num_input[i]))
else:
a.append = int(num_input)
a.append(90)
timeWatch = 90
for i in ra... | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
n = int(input())
if (n == 0):
print(15)
else:
num_input = input()
a = [0]
if (n > 1):
num_input = num_input.split(" ");
for i in range(n):
a.append(int(num_input[i]))
else:
a.append = int(num_input)
a.append(90)
timeWatch = 90
f... | -1 | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,695,832,759 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 154 | 0 | txt = input()
s=set()
for i in range(len(txt)):
s.add(txt[i])
if len(s) % 2 == 0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!') | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
txt = input()
s=set()
for i in range(len(txt)):
s.add(txt[i])
if len(s) % 2 == 0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*.
More formally, there is a singly liked list built on an array of *n* elements. Element with index *i* contains two integers: *value**i* ... | The first line contains three integers *n*, *start*, *x* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*start*<=≤<=*n*, 0<=≤<=*x*<=≤<=109) — the number of elements in the list, the index of the first element and the integer *x*. | To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to *x*, or -1, if there is no such integer. | [
"5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n"
] | [
"? 1\n? 2\n? 3\n? 4\n? 5\n! 81"
] | You can read more about singly linked list by the following link: [https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list](https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list)
The illustration for the first sample case. Start and finish elements are marked dark. <img class="tex-graphics" src="https://e... | 0 | [
{
"input": "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4",
"output": "81\n1003"
},
{
"input": "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1",
"output": "-1\n1002"
},
{
"input": "1 1 0\n0 -1",
"output": "0\n2"
},
{
"input": "1 1 2\n0 -1",
"output": "-1\n1002"
},
{
"input": "1 1 100000... | 1,503,600,149 | 7,649 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 78 | 921,600 | import random
import sys
n, start, x = map(int, input().split())
A = set()
maxn = 0
maxval = 0
num = 0
for i in range(min(n, 1000)):
a = random.randint(1, n)
print("?", a)
num+=1
sys.stdout.flush()
value, next = map(int, input().split())
if value <= x:
maxn = max(maxn, valu... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*.
More formally, there is a singly liked list bu... | ```python
import random
import sys
n, start, x = map(int, input().split())
A = set()
maxn = 0
maxval = 0
num = 0
for i in range(min(n, 1000)):
a = random.randint(1, n)
print("?", a)
num+=1
sys.stdout.flush()
value, next = map(int, input().split())
if value <= x:
maxn = max(... | 0 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,615,051,090 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 280 | 19,046,400 | n=int(input())
p=list(map(int,input().split()))
i=0
j=n-1
sm1=p[i]
sm2=p[j]
nmx=0
while i<j:
if sm1<sm2:
i+=1
sm1+=p[i]
elif sm1>sm2:
j-=1
sm2+=p[j]
else:
i+=1
j-=1
nmx=max(nmx,sm1)
sm1+=p[i]
sm2+=p[j]
print(nmx)
| Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
n=int(input())
p=list(map(int,input().split()))
i=0
j=n-1
sm1=p[i]
sm2=p[j]
nmx=0
while i<j:
if sm1<sm2:
i+=1
sm1+=p[i]
elif sm1>sm2:
j-=1
sm2+=p[j]
else:
i+=1
j-=1
nmx=max(nmx,sm1)
sm1+=p[i]
sm2+=p[j]
prin... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,622,018,094 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 0 | n = int(input())
x,y,z = [0]*n,[0]*n,[0]*n
for i in range(n):
x[i],y[i],z[i] = input().split()
x[i],y[i],z[i] = int(x[i]),int(y[i]),int(z[i])
if (sum(x))**2 + (sum(y))**2 + sum(z)**2 == 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())
x,y,z = [0]*n,[0]*n,[0]*n
for i in range(n):
x[i],y[i],z[i] = input().split()
x[i],y[i],z[i] = int(x[i]),int(y[i]),int(z[i])
if (sum(x))**2 + (sum(y))**2 + sum(z)**2 == 0:
print("YES")
else:
print("NO")
``` | 3.969 |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a pro... | The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* — the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "100000... | 1,647,537,954 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | a=list(map(int,input().split()))
a.sort()
if (a[1]*2)<=(a[0]+a[2]):print(a[1])
else:print(a[0]) | Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *... | ```python
a=list(map(int,input().split()))
a.sort()
if (a[1]*2)<=(a[0]+a[2]):print(a[1])
else:print(a[0])
``` | 0 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,525,189,741 | 6,241 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 1,559 | 10,752,000 | n, q = map(int, input().split())
a = list(map(int, input().split()))
z = list(map(int, input().split()))
def binsearch(x, k):
left = 0
right = len(x)
while left != right - 1:
mid = (left + right) // 2
if x[mid] > k:
right = mid
else:
left = mid
return right
#print(binsearch([1, 2, 3, 4, 5, 8 ,67], 3)) ... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
n, q = map(int, input().split())
a = list(map(int, input().split()))
z = list(map(int, input().split()))
def binsearch(x, k):
left = 0
right = len(x)
while left != right - 1:
mid = (left + right) // 2
if x[mid] > k:
right = mid
else:
left = mid
return right
#print(binsearch([1, 2, 3, 4, 5, 8 ,... | 0 | |
543 | A | Writing Code | PROGRAMMING | 1,800 | [
"dp"
] | null | null | Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that he writes.
Let's call a sequence of non-negative integers *v*1,<=*v*2,<=...,<=*v**n* a plan, if *... | The first line contains four integers *n*, *m*, *b*, *mod* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*b*<=≤<=500; 1<=≤<=*mod*<=≤<=109<=+<=7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.
The next line co... | Print a single integer — the answer to the problem modulo *mod*. | [
"3 3 3 100\n1 1 1\n",
"3 6 5 1000000007\n1 2 3\n",
"3 5 6 11\n1 2 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | none | 500 | [
{
"input": "3 3 3 100\n1 1 1",
"output": "10"
},
{
"input": "3 6 5 1000000007\n1 2 3",
"output": "0"
},
{
"input": "3 5 6 11\n1 2 1",
"output": "0"
},
{
"input": "2 3 3 1000\n1 2",
"output": "1"
},
{
"input": "3 10 10 150691913\n8 7 10",
"output": "0"
},
{... | 1,606,288,827 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | a = list(map(int, input().split()))
n = a[0]
m = a[1]
b = a[2]
ac = list(map(int,input().split()))
ac = [0] + ac
dp = [[[0 for k in range(b+1)] for _ in range(m+1)] for z in range(n+1)]
for i in range(n+1) :
for x in range(b+1) :
dp[i][0][x] = 1
for i in range(1,n+1) :
for j in rang... | Title: Writing Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that h... | ```python
a = list(map(int, input().split()))
n = a[0]
m = a[1]
b = a[2]
ac = list(map(int,input().split()))
ac = [0] + ac
dp = [[[0 for k in range(b+1)] for _ in range(m+1)] for z in range(n+1)]
for i in range(n+1) :
for x in range(b+1) :
dp[i][0][x] = 1
for i in range(1,n+1) :
for... | 0 | |
887 | D | Ratings and Reality Shows | PROGRAMMING | 2,400 | [
"data structures",
"two pointers"
] | null | null | There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by *a* and after each fashion show decreases by *b* (designers do too many experiments nowadays).... | In first line there are 7 positive integers *n*, *a*, *b*, *c*, *d*, *start*, *len* (1<=≤<=*n*<=≤<=3·105, 0<=≤<=*start*<=≤<=109, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*len*<=≤<=109), where *n* is a number of fashion shows and photo shoots, *a*, *b*, *c* and *d* are rating changes described above, *start* is an initial rating o... | Print one non-negative integer *t* — the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print <=-<=1. | [
"5 1 1 1 4 0 5\n1 1\n2 1\n3 1\n4 0\n5 0\n",
"1 1 2 1 2 1 2\n1 0\n"
] | [
"6",
"-1"
] | none | 2,000 | [
{
"input": "5 1 1 1 4 0 5\n1 1\n2 1\n3 1\n4 0\n5 0",
"output": "6"
},
{
"input": "1 1 2 1 2 1 2\n1 0",
"output": "-1"
},
{
"input": "10 1 1 1 2 0 10\n1 1\n2 1\n3 0\n4 0\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1",
"output": "5"
}
] | 1,510,422,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | input_str = input().split()
n = int(input_str[0])
a = int(input_str[1])
b = int(input_str[2])
c = int(input_str[3])
d = int(input_str[4])
start = int(input_str[5])
len = int(input_str[6])
events = []
for _ in range(n):
event_str = input().split()
events.append((int(event_str[0]), int(event_str[1]... | Title: Ratings and Reality Shows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rat... | ```python
input_str = input().split()
n = int(input_str[0])
a = int(input_str[1])
b = int(input_str[2])
c = int(input_str[3])
d = int(input_str[4])
start = int(input_str[5])
len = int(input_str[6])
events = []
for _ in range(n):
event_str = input().split()
events.append((int(event_str[0]), int(ev... | 0 | |
553 | A | Kyoya and Colored Balls | PROGRAMMING | 1,500 | [
"combinatorics",
"dp",
"math"
] | null | null | Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of... | The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] | [
"3\n",
"1680\n"
] | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | 250 | [
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n3... | 1,695,531,355 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | import sys
#sys.setrecursionlimit(20000)
#from collections import deque #Counter
#from itertools import accumulate, product
#from functools import reduce
#from math import gcd #sqrt
import math
def rall():
return [x.strip() for x in sys.stdin.readlines()]
def rl():
return sys.stdin.readline().strip()
def rl_t... | Title: Kyoya and Colored Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by o... | ```python
import sys
#sys.setrecursionlimit(20000)
#from collections import deque #Counter
#from itertools import accumulate, product
#from functools import reduce
#from math import gcd #sqrt
import math
def rall():
return [x.strip() for x in sys.stdin.readlines()]
def rl():
return sys.stdin.readline().strip(... | 3 | |
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ... | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, fin... | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
... | 1,633,465,253 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 6,963,200 | [d, sumTime] = [int(val) for val in input().split()]
offsetMax = []
Min = []
for _ in range(d):
[minTime, maxTime] = [int(val) for val in input().split()]
offsetMax.append(maxTime-minTime)
Min.append(minTime)
found = False
if sum(Min) > sumTime:
print('No')
else:
sumTime -= sum(Min)... | Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. ... | ```python
[d, sumTime] = [int(val) for val in input().split()]
offsetMax = []
Min = []
for _ in range(d):
[minTime, maxTime] = [int(val) for val in input().split()]
offsetMax.append(maxTime-minTime)
Min.append(minTime)
found = False
if sum(Min) > sumTime:
print('No')
else:
sumTime -... | -1 | |
290 | B | QR code | PROGRAMMING | 1,500 | [
"*special",
"implementation"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space. | Output a single integer. | [
"1 1\n",
"3 7\n",
"13 10\n"
] | [
"0\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "1 1",
"output": "0"
},
{
"input": "3 7",
"output": "0"
},
{
"input": "13 10",
"output": "1"
},
{
"input": "6 12",
"output": "1"
},
{
"input": "14 14",
"output": "0"
},
{
"input": "19 14",
"output": "0"
},
{
"input": "21 18",
... | 1,653,152,981 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | def db(num):
s = ''
if num >= 1:
db(num // 2)
s += str((num % 2))
return s
a,b = [int(x) for x in input().split()]
c = (db(a+b))
print(c) | Title: QR code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space.
Output Specification:
Output a single integer.
Demo Input:
['1 1\n', '3 7\n', '13 10\n']
Demo Output:
['0... | ```python
def db(num):
s = ''
if num >= 1:
db(num // 2)
s += str((num % 2))
return s
a,b = [int(x) for x in input().split()]
c = (db(a+b))
print(c)
``` | 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,505,574,210 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 93 | 0 | n = int(input())
if n % 2 == 0:
r = n // 2
else:
r = n // 2 + 1
for i in range(1, r):
a = i
b = n - i
f = 0
for j in range(2, min(a, b)):
if a % j == 0 and b % j == 0:
f = 1
if f == 0:
a1 = a
b1 = b
print(a1, b1) | 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
n = int(input())
if n % 2 == 0:
r = n // 2
else:
r = n // 2 + 1
for i in range(1, r):
a = i
b = n - i
f = 0
for j in range(2, min(a, b)):
if a % j == 0 and b % j == 0:
f = 1
if f == 0:
a1 = a
b1 = b
print(a1, b1)
``` | 0 | |
952 | A | Quirky Quantifiers | PROGRAMMING | 800 | [
"math"
] | null | null | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1. | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). | Output 0 or 1. | [
"13\n",
"927\n",
"48\n"
] | [
"1\n",
"1\n",
"0\n"
] | none | 0 | [
{
"input": "13",
"output": "1"
},
{
"input": "927",
"output": "1"
},
{
"input": "48",
"output": "0"
},
{
"input": "10",
"output": "0"
},
{
"input": "999",
"output": "1"
},
{
"input": "142",
"output": "0"
},
{
"input": "309",
"output": "... | 1,615,900,008 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 62 | 0 | num = int(input())
print(num%2)
| Title: Quirky Quantifiers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1.
Input Specification:
The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output Specification:
Output 0 or 1.
Demo Input:
['1... | ```python
num = int(input())
print(num%2)
``` | 3 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,664,647,954 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n,k=map(int,input().split())
l=list(map(int,input().split()))
s=set(l)
m=[]
if len(s)!=k:
print('NO')
else:
print('YES')
for i in s:
m.append(str(l.index(i)+1))
print(' '.join(m)) | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=set(l)
m=[]
if len(s)!=k:
print('NO')
else:
print('YES')
for i in s:
m.append(str(l.index(i)+1))
print(' '.join(m))
``` | 0 | |
837 | D | Round Subset | PROGRAMMING | 2,100 | [
"dp",
"math"
] | null | null | Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible. | The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<=200,<=1<=≤<=*k*<=≤<=*n*).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1018). | Print maximal roundness of product of the chosen subset of length *k*. | [
"3 2\n50 4 20\n",
"5 3\n15 16 3 25 9\n",
"3 3\n9 77 13\n"
] | [
"3\n",
"3\n",
"0\n"
] | In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0. | 0 | [
{
"input": "3 2\n50 4 20",
"output": "3"
},
{
"input": "5 3\n15 16 3 25 9",
"output": "3"
},
{
"input": "3 3\n9 77 13",
"output": "0"
},
{
"input": "1 1\n200000000",
"output": "8"
},
{
"input": "1 1\n3",
"output": "0"
},
{
"input": "3 1\n10000000000000... | 1,663,339,325 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 61 | 2,867,200 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[-1] * 26 for _ in range(k + 1)]
dp[0][0] = 0
for i in range(n):
num, c2, c5 = a[i], 0, 0
while num % 5 == 0:
num //= 5
c5 += 1
while num % 2 == 0:
num //= 2
... | Title: Round Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected number... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[-1] * 26 for _ in range(k + 1)]
dp[0][0] = 0
for i in range(n):
num, c2, c5 = a[i], 0, 0
while num % 5 == 0:
num //= 5
c5 += 1
while num % 2 == 0:
n... | 0 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,598,853,283 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 6,758,400 | for _ in range(0,int(input())):
x=int(input())
if x%3==0 or x%7==0:
print("YES")
elif (x%7)%3==0 or (x%3)%7==0:
print("YES")
else:
print("NO") | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
for _ in range(0,int(input())):
x=int(input())
if x%3==0 or x%7==0:
print("YES")
elif (x%7)%3==0 or (x%3)%7==0:
print("YES")
else:
print("NO")
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,642,574,273 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n1=input())#a
n2=(input())#b
sum=int(n1)+int(n2)#a+b
length=len(n1)
sum_s=str(sum)
sum_s_new=sum_s.replace("1","2")
N=len(sum_s)
proper_sum="0"*(length-N)+sum_s_new
print(int(proper_sum))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n1=input())#a
n2=(input())#b
sum=int(n1)+int(n2)#a+b
length=len(n1)
sum_s=str(sum)
sum_s_new=sum_s.replace("1","2")
N=len(sum_s)
proper_sum="0"*(length-N)+sum_s_new
print(int(proper_sum))
``` | -1 |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th... | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight ... | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": ... | 1,690,559,573 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n , t = map(int , input().split())
x = sorted([i for i in input()])
coutner = 0
i = 1
t2 = t
while t - 1 > 0 and i < n :
if ord(x[i]) - ord(x[i-1])> 1 :
coutner += ord(x[i]) - ord("a") + 1
t-=1
i+=1
if t2 == 1 :
print( ord(x[0]) - ord("a") + 1)
elif coutner ==0 :
print("... | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca... | ```python
n , t = map(int , input().split())
x = sorted([i for i in input()])
coutner = 0
i = 1
t2 = t
while t - 1 > 0 and i < n :
if ord(x[i]) - ord(x[i-1])> 1 :
coutner += ord(x[i]) - ord("a") + 1
t-=1
i+=1
if t2 == 1 :
print( ord(x[0]) - ord("a") + 1)
elif coutner ==0 :
... | 0 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,591,443,591 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n=int(input())
def funk(n):
for i in range(n):
for j in range(n):
if (i*(i+1))/2 + (j*(j+1))/2 == n:
return 'YES'
else:
return 'NO' | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n=int(input())
def funk(n):
for i in range(n):
for j in range(n):
if (i*(i+1))/2 + (j*(j+1))/2 == n:
return 'YES'
else:
return 'NO'
``` | 0 | |
557 | A | Ilya and Diplomas | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | null | null | Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the fir... | In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first... | [
"6\n1 5\n2 6\n3 7\n",
"10\n1 2\n1 3\n1 5\n",
"6\n1 3\n2 2\n2 2\n"
] | [
"1 2 3 \n",
"2 3 5 \n",
"2 2 2 \n"
] | none | 500 | [
{
"input": "6\n1 5\n2 6\n3 7",
"output": "1 2 3 "
},
{
"input": "10\n1 2\n1 3\n1 5",
"output": "2 3 5 "
},
{
"input": "6\n1 3\n2 2\n2 2",
"output": "2 2 2 "
},
{
"input": "55\n1 1000000\n40 50\n10 200",
"output": "5 40 10 "
},
{
"input": "3\n1 1\n1 1\n1 1",
"o... | 1,680,863,222 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 77 | 0 | n = int(input())
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
res = [a1,a2,a3]
if sum(res) < n: res[0] += min(b1-a1, n-sum(res))
if sum(res) < n: res[1] += min(b2-a2, n-sum(res))
if sum(res) < n: res[2] += n-sum(res)
print(" ".join(str(x) for x in re... | Title: Ilya and Diplomas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the re... | ```python
n = int(input())
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
res = [a1,a2,a3]
if sum(res) < n: res[0] += min(b1-a1, n-sum(res))
if sum(res) < n: res[1] += min(b2-a2, n-sum(res))
if sum(res) < n: res[2] += n-sum(res)
print(" ".join(str(x) f... | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,666,701,333 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 2,252,800 | s=list(input())
t=list(input())
move=0
s1=len(s)
t1=len(t)
while s!=t:
if s1>t1:
s.pop(0)
move+=1
s1-=1
elif s1<t1:
t.pop(0)
move+=1
t1-=1
else:
t.pop(0)
s.pop(0)
move+=2
s1-=1
t1-=1
print(move) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s=list(input())
t=list(input())
move=0
s1=len(s)
t1=len(t)
while s!=t:
if s1>t1:
s.pop(0)
move+=1
s1-=1
elif s1<t1:
t.pop(0)
move+=1
t1-=1
else:
t.pop(0)
s.pop(0)
move+=2
s1-=1
t1-=1
pri... | 0 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,637,525,091 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 7,372,800 | n, b, d = map(int, input().split())
size = list(map(int, input().split()))
t = 0
total = 0
for i in range(n):
if size[i] > b:
size[i] = 0
total += size[i]
if total > d:
t += 1
total = 0
print(t)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
size = list(map(int, input().split()))
t = 0
total = 0
for i in range(n):
if size[i] > b:
size[i] = 0
total += size[i]
if total > d:
t += 1
total = 0
print(t)
``` | 3 | |
687 | C | The Values You Can Make | PROGRAMMING | 1,900 | [
"dp"
] | null | null | Pari wants to buy an expensive chocolate from Arya. She has *n* coins, the value of the *i*-th coin is *c**i*. The price of the chocolate is *k*, so Pari will take a subset of her coins with sum equal to *k* and give it to Arya.
Looking at her coins, a question came to her mind: after giving the coins to Arya, what va... | The first line contains two integers *n* and *k* (1<=<=≤<=<=*n*,<=*k*<=<=≤<=<=500) — the number of coins and the price of the chocolate, respectively.
Next line will contain *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=500) — the values of Pari's coins.
It's guaranteed that one can make value *k* using t... | First line of the output must contain a single integer *q*— the number of suitable values *x*. Then print *q* integers in ascending order — the values that Arya can make for some subset of coins of Pari that pays for the chocolate. | [
"6 18\n5 6 1 10 12 2\n",
"3 50\n25 25 50\n"
] | [
"16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 \n",
"3\n0 25 50 \n"
] | none | 1,500 | [
{
"input": "6 18\n5 6 1 10 12 2",
"output": "16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 "
},
{
"input": "3 50\n25 25 50",
"output": "3\n0 25 50 "
},
{
"input": "1 79\n79",
"output": "2\n0 79 "
},
{
"input": "1 114\n114",
"output": "2\n0 114 "
},
{
"input": "5 1\n... | 1,539,256,246 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 2,000 | 182,681,600 |
def PerfectSum(arr, summ):
cols = summ+1
prev_row = [[]]*cols
current_row = [[]]*cols
prev_row[0] = [[]]
current_row[0] = [[]]
for value in arr:
for j in range(1, cols):
complement = j - value
comb = []
if complement >= 0:
for c in pre... | Title: The Values You Can Make
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari wants to buy an expensive chocolate from Arya. She has *n* coins, the value of the *i*-th coin is *c**i*. The price of the chocolate is *k*, so Pari will take a subset of her coins with sum equal to *k* and... | ```python
def PerfectSum(arr, summ):
cols = summ+1
prev_row = [[]]*cols
current_row = [[]]*cols
prev_row[0] = [[]]
current_row[0] = [[]]
for value in arr:
for j in range(1, cols):
complement = j - value
comb = []
if complement >= 0:
fo... | 0 | |
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,462,984,112 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 4,608,000 | from sys import stdin
n=int(input())
inp=[stdin.readline().strip("\n").split() for i in range(n)]
maxscore=0
board={}
maxp=set()
for i in inp :
name,s=i[0],int(i[1])
if name not in board :
board[name]=int(s)
else :
board[name]+=int(s)
maxscore=max(board.values())
for i... | 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
from sys import stdin
n=int(input())
inp=[stdin.readline().strip("\n").split() for i in range(n)]
maxscore=0
board={}
maxp=set()
for i in inp :
name,s=i[0],int(i[1])
if name not in board :
board[name]=int(s)
else :
board[name]+=int(s)
maxscore=max(board.values... | 0 |
911 | C | Three Garlands | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s... | The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't... | 0 | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
... | 1,598,790,550 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 109 | 20,377,600 | a=[int(x) for x in input().split()]
b=set(a)
if len(b)==3:
print("NO")
else:
print("YES")
| Title: Three Garlands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its st... | ```python
a=[int(x) for x in input().split()]
b=set(a)
if len(b)==3:
print("NO")
else:
print("YES")
``` | 0 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,674,417,480 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
r = [0] * (n + 1)
c = [0] * (n + 1)
ans = []
for i in range(1, n * n + 1):
a, b = map(int, input().split())
if not r[a] or not c[b]:
ans.append(i)
r[a] = 1
c[b] = 1
print(ans) | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
n = int(input())
r = [0] * (n + 1)
c = [0] * (n + 1)
ans = []
for i in range(1, n * n + 1):
a, b = map(int, input().split())
if not r[a] or not c[b]:
ans.append(i)
r[a] = 1
c[b] = 1
print(ans)
``` | 0 | |
38 | B | Chess | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | B. Chess | 2 | 256 | Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board b... | The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way... | Print a single number which is the required number of ways. | [
"a1\nb2\n",
"a8\nd4\n"
] | [
"44\n",
"38\n"
] | none | 0 | [
{
"input": "a1\nb2",
"output": "44"
},
{
"input": "a8\nd4",
"output": "38"
},
{
"input": "a8\nf1",
"output": "42"
},
{
"input": "f8\nh3",
"output": "42"
},
{
"input": "g8\nb7",
"output": "42"
},
{
"input": "h1\ng5",
"output": "42"
},
{
"inp... | 1,594,400,472 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 342 | 20,684,800 | import sys
input = sys.stdin.readline
import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
r=ip()
k=ip()
d=defaultdict(int)
j=1... | Title: Chess
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of wa... | ```python
import sys
input = sys.stdin.readline
import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
r=ip()
k=ip()
d=defaultdic... | 3.875972 |
289 | A | Polo the Penguin and Segments | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 uni... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers *i*... | In a single line print a single integer — the answer to the problem. | [
"2 3\n1 2\n3 4\n",
"3 7\n1 2\n3 3\n4 7\n"
] | [
"2\n",
"0\n"
] | none | 500 | [
{
"input": "2 3\n1 2\n3 4",
"output": "2"
},
{
"input": "3 7\n1 2\n3 3\n4 7",
"output": "0"
},
{
"input": "3 7\n1 10\n11 47\n74 128",
"output": "3"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "3"
},
{
"input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 ... | 1,656,339,762 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 2,000 | 4,608,000 | n,k=list(map(int,input().split()))
arr=[]
for i in range(n):
arr.append(list(map(int,input().split())))
arr1=[]
for i in arr:
for j in range(i[0],i[1]+1):
if j not in arr1:
arr1.append(j)
x=len(arr1)
z=x
if x%k==0:
print(0)
else:
while True:
if z%k==0:
... | Title: Polo the Penguin and Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*).
He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]... | ```python
n,k=list(map(int,input().split()))
arr=[]
for i in range(n):
arr.append(list(map(int,input().split())))
arr1=[]
for i in arr:
for j in range(i[0],i[1]+1):
if j not in arr1:
arr1.append(j)
x=len(arr1)
z=x
if x%k==0:
print(0)
else:
while True:
if z... | 0 | |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th... | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight ... | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": ... | 1,610,786,110 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 93 | 3,481,600 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def cint(c):
return ord(c) - 96
####################################################
def find_m... | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca... | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def cint(c):
return ord(c) - 96
####################################################
... | 3 | |
424 | D | Biathlon Track | PROGRAMMING | 2,300 | [
"binary search",
"brute force",
"constructive algorithms",
"data structures",
"dp"
] | null | null | Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoroughly and to build all the necessary Olympic facilities as early as possible. First, a biathlon track will be built.
To construct a bi... | The first line of the input contains three integers *n*, *m* and *t* (3<=≤<=*n*,<=*m*<=≤<=300, 1<=≤<=*t*<=≤<=109) — the sizes of the land plot and the desired distance covering time.
The second line also contains three integers *t**p*, *t**u* and *t**d* (1<=≤<=*t**p*,<=*t**u*,<=*t**d*<=≤<=100) — the time the average b... | In a single line of the output print four positive integers — the number of the row and the number of the column of the upper left corner and the number of the row and the number of the column of the lower right corner of the rectangle that is chosen for the track. | [
"6 7 48\n3 6 2\n5 4 8 3 3 7 9\n4 1 6 8 7 1 1\n1 6 4 6 4 8 6\n7 2 6 1 6 9 4\n1 9 8 6 3 9 2\n4 5 6 8 4 3 7"
] | [
"4 3 6 7\n"
] | none | 2,500 | [] | 1,398,421,160 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | __author__ = 'Lipen'
def main():
n, m, t = map(int, input().split())
tp, tu, td = map(int, input().split())
data = []
for _ in range(n):
data.append(list(map(int, input().split())))
def count(x1, y1, x2, y2):
c = 0
for i in range(x1, x2):
if data[i][... | Title: Biathlon Track
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoroughly and to build all the necessar... | ```python
__author__ = 'Lipen'
def main():
n, m, t = map(int, input().split())
tp, tu, td = map(int, input().split())
data = []
for _ in range(n):
data.append(list(map(int, input().split())))
def count(x1, y1, x2, y2):
c = 0
for i in range(x1, x2):
i... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.