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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,654,800,963 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | # 265A
stones = input()
seq = input()
pos = 1
for inst in seq:
if stones[pos-1] == inst:
pos+=1
print(pos) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
# 265A
stones = input()
seq = input()
pos = 1
for inst in seq:
if stones[pos-1] == inst:
pos+=1
print(pos)
``` | 3 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,610,722,655 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 217 | 14,336,000 | n=int(input())
a=list(map(int,input().split()))
s=input()
p=sorted(a)
for i in range(n-1):
if s[i]=="1":
if a[i]>a[i+1]:
a[i],a[i+1]=a[i+1],a[i]
if p==a:
print("YES")
else:
print("NO")
| Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
n=int(input())
a=list(map(int,input().split()))
s=input()
p=sorted(a)
for i in range(n-1):
if s[i]=="1":
if a[i]>a[i+1]:
a[i],a[i+1]=a[i+1],a[i]
if p==a:
print("YES")
else:
print("NO")
``` | 0 | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,613,067,922 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 307,200 | def EA(a, b, c):
if((a+b)>c):
if(a==c or b==c):
return 'Yes'
else:
return 'No'
if((a+b)<c):
if((c-(a+b))%a==0 or (c-(a+b))%b==0):
return'Yes'
else:
return 'No'
if((a+b)==c):
return'Yes'
N=input().split()
print(EA(int(N[0]), int(N[1]), int(N[2]))) | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
def EA(a, b, c):
if((a+b)>c):
if(a==c or b==c):
return 'Yes'
else:
return 'No'
if((a+b)<c):
if((c-(a+b))%a==0 or (c-(a+b))%b==0):
return'Yes'
else:
return 'No'
if((a+b)==c):
return'Yes'
N=input().split()
print(EA(int(N[0]), int(N[1]), int(N[2])))
``` | 0 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,643,905,911 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | x=int(input("input"))
y=10
z=x-y
if z<=0:
print("0")
elif z>=12:
print("0")
elif z<13 and z!=10:
print("4")
elif z==10:
print("15")
| Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
x=int(input("input"))
y=10
z=x-y
if z<=0:
print("0")
elif z>=12:
print("0")
elif z<13 and z!=10:
print("4")
elif z==10:
print("15")
``` | 0 |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,689,897,191 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n = (set(input()))
if ' ' in n :
n.remove(' ')
if ',' in n :
n.remove(',')
n.remove('{')
n.remove('}')
print(len(n))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
n = (set(input()))
if ' ' in n :
n.remove(' ')
if ',' in n :
n.remove(',')
n.remove('{')
n.remove('}')
print(len(n))
``` | 3 | |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,492,358,429 | 1,529 | PyPy 3 | OK | TESTS | 35 | 109 | 23,347,200 | x = input()
y = input()
n = len(x)
z = ""
for i in range(n):
z += min(x[i], y[i])
if z != y: print(-1)
else: print(z)
| Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string... | ```python
x = input()
y = input()
n = len(x)
z = ""
for i in range(n):
z += min(x[i], y[i])
if z != y: print(-1)
else: print(z)
``` | 3 | |
803 | D | Magazine Ad | PROGRAMMING | 1,900 | [
"binary search",
"greedy"
] | null | null | The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th... | The first line contains number *k* (1<=≤<=*k*<=≤<=105).
The second line contains the text of the ad — non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters. | Output minimal width of the ad. | [
"4\ngarage for sa-le\n",
"4\nEdu-ca-tion-al Ro-unds are so fun\n"
] | [
"7\n",
"10\n"
] | Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
The second example: | 0 | [
{
"input": "4\ngarage for sa-le",
"output": "7"
},
{
"input": "4\nEdu-ca-tion-al Ro-unds are so fun",
"output": "10"
},
{
"input": "1\nj",
"output": "1"
},
{
"input": "10\nb",
"output": "1"
},
{
"input": "1\nQGVsfZevMD",
"output": "10"
},
{
"input": "1... | 1,493,430,998 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 1,000 | 13,004,800 | import sys
inf = 1 << 30
def solve():
def check(mid):
if a_max > mid:
return False
tot = 1
line = 0
for ai in a:
if line + ai > mid:
tot += 1
line = ai
if tot > k:
retur... | Title: Magazine Ad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen... | ```python
import sys
inf = 1 << 30
def solve():
def check(mid):
if a_max > mid:
return False
tot = 1
line = 0
for ai in a:
if line + ai > mid:
tot += 1
line = ai
if tot > k:
... | 0 | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,616,573,115 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 42 | 109 | 0 | x,y=map(int,input().split())
x=x-y+1
if(y==0 or x<0 or x%2!=0):
print('No')
else:
print('Yes')
| Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
x,y=map(int,input().split())
x=x-y+1
if(y==0 or x<0 or x%2!=0):
print('No')
else:
print('Yes')
``` | 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,677,499,829 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | l = list(map(int,input().split()))
k = l[0]
r = l[1]
s = k
i = 2
count = 1
while True :
if s%10 == 0 :
print(count)
break
elif s%10 == r:
print(count)
break
else:
print(s)
s = k*i
count += 1
i += 1
... | 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
l = list(map(int,input().split()))
k = l[0]
r = l[1]
s = k
i = 2
count = 1
while True :
if s%10 == 0 :
print(count)
break
elif s%10 == r:
print(count)
break
else:
print(s)
s = k*i
count += 1
i += 1
... | 0 | |
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output":... | 1,670,297,256 | 2,147,483,647 | Python 3 | OK | TESTS | 198 | 46 | 0 | n=int(input())
dic={1:[0,1],2:[0,2],3:[0,2],4:[0,2],5:[0,2],6:[1,2],7:[2,2]}
if n%7==0:
temp=n//7
print(temp*2,temp*2)
else:
if n>7:
a=n//7
ma=a*2+dic[n%7][1]
mi=a*2+dic[n%7][0]
print(mi,ma)
else:
print(dic[n][0],dic[n][1]) | Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim... | ```python
n=int(input())
dic={1:[0,1],2:[0,2],3:[0,2],4:[0,2],5:[0,2],6:[1,2],7:[2,2]}
if n%7==0:
temp=n//7
print(temp*2,temp*2)
else:
if n>7:
a=n//7
ma=a*2+dic[n%7][1]
mi=a*2+dic[n%7][0]
print(mi,ma)
else:
print(dic[n][0],dic[n][1])
``` | 3 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,622,673,832 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n1,n2=map(int,input().split())
if n1==n2:
print("YES")
elif n2==n1+1:
print("YES")
else:
print("NO") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
n1,n2=map(int,input().split())
if n1==n2:
print("YES")
elif n2==n1+1:
print("YES")
else:
print("NO")
``` | 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,693,415,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | word = input("Enter your word here : ")
letters = [*word]
length = len(letters)
if length>10 :
abbreviation = letters[0] + str(length-2) + letters[-1]
print(abbreviation)
else :
print(word)
| 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
word = input("Enter your word here : ")
letters = [*word]
length = len(letters)
if length>10 :
abbreviation = letters[0] + str(length-2) + letters[-1]
print(abbreviation)
else :
print(word)
``` | 0 |
424 | B | Megacity | PROGRAMMING | 1,200 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the numbe... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | [
"4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n",
"4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n",
"2 1\n1 1 999997\n2 2 1\n"
] | [
"2.8284271\n",
"1.4142136\n",
"-1"
] | none | 1,000 | [
{
"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1",
"output": "2.8284271"
},
{
"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1",
"output": "1.4142136"
},
{
"input": "2 1\n1 1 999997\n2 2 1",
"output": "-1"
},
{
"input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10",
"out... | 1,531,556,535 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 0 | import math
if __name__ == '__main__':
n, s = map(int, input().split())
d = dict()
for i in range(n):
x, y, k = map(int, input().split())
if not (x * x + y * y) in d:
d[x * x + y * y] = k
else:
d[x * x + y * y] += k
flag = False
a = []
for key i... | Title: Megacity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding... | ```python
import math
if __name__ == '__main__':
n, s = map(int, input().split())
d = dict()
for i in range(n):
x, y, k = map(int, input().split())
if not (x * x + y * y) in d:
d[x * x + y * y] = k
else:
d[x * x + y * y] += k
flag = False
a = []
... | 3 | |
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the p... | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"i... | 1,656,492,402 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 | from collections import Counter
print('SFeicrosntd'[len([i for i in Counter(input()).values() if i%2])%2::2]) | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The... | ```python
from collections import Counter
print('SFeicrosntd'[len([i for i in Counter(input()).values() if i%2])%2::2])
``` | 0 | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,683,673,616 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | m, s = map(int, input().split())
# Find the minimum possible number
min_num = '1' + '0' * (m - 1) # Smallest number with m digits
if int(min_num) > s:
min_num = str(s) + '0' * (m - 1) # Smallest number with sum of digits s
if int(min_num) < s - 9 * (m - 1):
min_num = str(s - 9 * (m - 1)) + '9' * (m - ... | Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
m, s = map(int, input().split())
# Find the minimum possible number
min_num = '1' + '0' * (m - 1) # Smallest number with m digits
if int(min_num) > s:
min_num = str(s) + '0' * (m - 1) # Smallest number with sum of digits s
if int(min_num) < s - 9 * (m - 1):
min_num = str(s - 9 * (m - 1)) + '... | 0 | |
690 | F1 | Tree of Life (easy) | PROGRAMMING | 1,300 | [] | null | null | Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points... | The first line of the input contains a single integer *n* – the number of vertices in the tree (1<=≤<=*n*<=≤<=10000). The vertices are labeled with the numbers from 1 to *n*. Then *n*<=-<=1 lines follow, each describing one edge using two space-separated numbers *a* *b* – the labels of the vertices connected by the edg... | Print one integer – the number of lifelines in the tree. | [
"4\n1 2\n1 3\n1 4\n",
"5\n1 2\n2 3\n3 4\n3 5\n"
] | [
"3",
"4"
] | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | 0 | [
{
"input": "4\n1 2\n1 3\n1 4",
"output": "3"
},
{
"input": "5\n1 2\n2 3\n3 4\n3 5",
"output": "4"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "3\n2 1\n3 2",
"output": "1"
},
{
"input": "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "11"
... | 1,599,729,566 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | a=int(input());ans=0
z=[list(map(int,input().split())) for _ in " "*(a-1)]
z.sort();k=a-1
r =lambda x:(x*(x+1))//2;t=0
for i in range(k-1):
if z[i][0]==z[i+1][0]:t+=1
else:ans+=r(t);t=0
ans+=r(t);t=0
for i in range(k-1):
if z[i][1]==z[i+1][1]:t+=1
else:ans+=r(t);t=0
ans+=r(t);t=0
for i in ra... | Title: Tree of Life (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a r... | ```python
a=int(input());ans=0
z=[list(map(int,input().split())) for _ in " "*(a-1)]
z.sort();k=a-1
r =lambda x:(x*(x+1))//2;t=0
for i in range(k-1):
if z[i][0]==z[i+1][0]:t+=1
else:ans+=r(t);t=0
ans+=r(t);t=0
for i in range(k-1):
if z[i][1]==z[i+1][1]:t+=1
else:ans+=r(t);t=0
ans+=r(t);t=0
f... | 0 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,530,724,440 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n,k=map(int,input().split())
l=[int(i) for i in input().split()]
mini=l[n-1]
prft=0
for i in range(n-2,-1,-1):
curr=l[i]-mini-k
#print(curr)
prft=max(prft,curr)
if l[i]<mini:
mini=l[i]
print(prft)
| Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
mini=l[n-1]
prft=0
for i in range(n-2,-1,-1):
curr=l[i]-mini-k
#print(curr)
prft=max(prft,curr)
if l[i]<mini:
mini=l[i]
print(prft)
``` | 0 | |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,683,969,428 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 62 | 0 | q=input()
s=input()
c='qwertyuiopasdfghjkl;zxcvbnm,./'
s1=''
if q=='R':
for i in s:
s1+=c[(c.find(i))-1]
else:
for i in s:
s1+=c[(c.find(i))+1]
print(s1)
| Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
q=input()
s=input()
c='qwertyuiopasdfghjkl;zxcvbnm,./'
s1=''
if q=='R':
for i in s:
s1+=c[(c.find(i))-1]
else:
for i in s:
s1+=c[(c.find(i))+1]
print(s1)
``` | 3 | |
137 | C | History | PROGRAMMING | 1,500 | [
"sortings"
] | null | null | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the Wo... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th... | Print the only integer — the answer to the problem. | [
"5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"5\n1 100\n2 50\n51 99\n52 98\n10 60\n",
"1\n1 1000000000\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | 1,500 | [
{
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6",
"output": "4"
},
{
"input": "5\n1 100\n2 50\n51 99\n52 98\n10 60",
"output": "4"
},
{
"input": "1\n1 1000000000",
"output": "0"
},
{
"input": "2\n100 1000\n500 1500",
"output": "0"
},
{
"input": "4\n1 100\n50 150\n120 200\... | 1,592,667,472 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 0 | l=list(tuple(map(int,input().split())) for _ in range(int(input())))
l.sort(key=lambda x:(x[0],-x[1]))
print(sum(i[0]>l[0][0] and i[1]<l[0][1] for i in l))
| Title: History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other ... | ```python
l=list(tuple(map(int,input().split())) for _ in range(int(input())))
l.sort(key=lambda x:(x[0],-x[1]))
print(sum(i[0]>l[0][0] and i[1]<l[0][1] for i in l))
``` | 0 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,634,793,954 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 4,505,600 | tap = [[0, 0, 0, 0, 0]]
lights = [[1]*3]*3
for _ in range(3):
m = list(map(int, input().split()))
m.insert(0, 0)
m.append(0)
tap.append(m)
tap.append([0, 0, 0, 0, 0])
for i in range(1, 4):
for j in range(1, 4):
total = tap[i-1][j]+ tap[i][j-1] + tap[i][j] + tap[i][j+1]+ tap[i+1][j]... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
tap = [[0, 0, 0, 0, 0]]
lights = [[1]*3]*3
for _ in range(3):
m = list(map(int, input().split()))
m.insert(0, 0)
m.append(0)
tap.append(m)
tap.append([0, 0, 0, 0, 0])
for i in range(1, 4):
for j in range(1, 4):
total = tap[i-1][j]+ tap[i][j-1] + tap[i][j] + tap[i][j+1]+ t... | 0 | |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,671,740,840 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | n=int(input())
x=n
y=n
while n%10!=0:
n=n+1
while x%10!=0:
x=x-1
if (y-x)>(n-y):
print(n)
else:
print(x)
| Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n=int(input())
x=n
y=n
while n%10!=0:
n=n+1
while x%10!=0:
x=x-1
if (y-x)>(n-y):
print(n)
else:
print(x)
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,645,529,166 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 1,638,400 | queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
x = int(input())
for i in range (x-1):
queue.append(queue[0])
queue.append(queue.pop(queue.index(queue[0])))
print(queue[0])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
x = int(input())
for i in range (x-1):
queue.append(queue[0])
queue.append(queue.pop(queue.index(queue[0])))
print(queue[0])
``` | 0 |
955 | C | Sad powers | PROGRAMMING | 2,100 | [
"binary search",
"math",
"number theory"
] | null | null | You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*. | The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). | Output *Q* lines — the answers to the queries. | [
"6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n"
] | [
"2\n1\n0\n3\n17\n1111\n"
] | In query one the suitable numbers are 1 and 4. | 1,500 | [
{
"input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000",
"output": "2\n1\n0\n3\n17\n1111"
},
{
"input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770",
"output... | 1,521,902,482 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 7,065,600 | import math
n=int(input())
out=[]
for i in range (n):
[l,r]=[int(i) for i in input().split()]
a=math.floor(r**0.5)
count=0
X=[]
if l==1:
count+=1
for j in range (2,a+1):
pmin=math.floor(math.log(l,j))
if pmin<2:
pmin=2
pmax=math.floor(math.log(r,j))
... | Title: Sad powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*.
Input ... | ```python
import math
n=int(input())
out=[]
for i in range (n):
[l,r]=[int(i) for i in input().split()]
a=math.floor(r**0.5)
count=0
X=[]
if l==1:
count+=1
for j in range (2,a+1):
pmin=math.floor(math.log(l,j))
if pmin<2:
pmin=2
pmax=math.floor(math.lo... | 0 | |
621 | B | Wet Shark and Bishops | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation"
] | null | null | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops.
Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ... | Output one integer — the number of pairs of bishops which attack each other. | [
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"3\n1 1\n2 3\n3 5\n"
] | [
"6\n",
"0\n"
] | In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal. | 1,000 | [
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5",
"output": "6"
},
{
"input": "3\n1 1\n2 3\n3 5",
"output": "0"
},
{
"input": "3\n859 96\n634 248\n808 72",
"output": "0"
},
{
"input": "3\n987 237\n891 429\n358 145",
"output": "0"
},
{
"input": "3\n411 81\n149 907\n611 114"... | 1,684,477,413 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 68 | 1,123 | 9,216,000 | n=int(input())
leftDiagonals=[0]*2001
rightDiagonals=[0]*2001
for i in range(n):
x,y=map(int,input().split())
rightDiagonals[x+y]+=1
leftDiagonals[1000+(x-y)]+=1
ans=0
for i in range(2001):
if leftDiagonals[i]>0:
ans+=(leftDiagonals[i]*(leftDiagonals[i]-1))//2
if rightDiagonal... | Title: Wet Shark and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
We... | ```python
n=int(input())
leftDiagonals=[0]*2001
rightDiagonals=[0]*2001
for i in range(n):
x,y=map(int,input().split())
rightDiagonals[x+y]+=1
leftDiagonals[1000+(x-y)]+=1
ans=0
for i in range(2001):
if leftDiagonals[i]>0:
ans+=(leftDiagonals[i]*(leftDiagonals[i]-1))//2
if rig... | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,513,769,249 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 124 | 5,632,000 | from math import gcd
n=int(input())
s=0
for i in range(2,n):
k=n
while k!=0:
s+=k%i
k=k//i
p=gcd(s,n-2)
print(str(s//p)+"/"+str((n-2)//p))
| Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
from math import gcd
n=int(input())
s=0
for i in range(2,n):
k=n
while k!=0:
s+=k%i
k=k//i
p=gcd(s,n-2)
print(str(s//p)+"/"+str((n-2)//p))
``` | 3.896038 |
510 | B | Fox And Two Dots | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter. | Output "Yes" if there exists a cycle, and "No" otherwise. | [
"3 4\nAAAA\nABCA\nAAAA\n",
"3 4\nAAAA\nABCA\nAADA\n",
"4 4\nYYYR\nBYBY\nBBBY\nBBBY\n",
"7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n",
"2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n"
] | In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | 1,000 | [
{
"input": "3 4\nAAAA\nABCA\nAAAA",
"output": "Yes"
},
{
"input": "3 4\nAAAA\nABCA\nAADA",
"output": "No"
},
{
"input": "4 4\nYYYR\nBYBY\nBBBY\nBBBY",
"output": "Yes"
},
{
"input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB",
"output": "Yes"
},
{
... | 1,685,324,616 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 46 | 1,228,800 | def dfs(i, j, frmi, frmj, co):
global ok
if i < 1 or j < 1 or i > m or j > n:
return
if graph[i][j] != co:
return
if vis[i][j]:
ok = True
return
vis[i][j] = True
for y in range(4):
nxti = i + dx[y]
nxtj = j + dy[y]
if... | Title: Fox And Two Dots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase La... | ```python
def dfs(i, j, frmi, frmj, co):
global ok
if i < 1 or j < 1 or i > m or j > n:
return
if graph[i][j] != co:
return
if vis[i][j]:
ok = True
return
vis[i][j] = True
for y in range(4):
nxti = i + dx[y]
nxtj = j + dy[y]
... | -1 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,592,571,216 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 512,000 | n=int(input())
s=input()
p=input()
c=0
for i in range(n):
t=abs(int(s[i])-int(p[i]))
if(t==1 or t==9):
c+=1
elif(t==2 or t==8):
c+=2
elif(t==3 or t==7):
c+=3
elif(t==4 or t==6):
c+=4
else:
c+=t
print(c) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n=int(input())
s=input()
p=input()
c=0
for i in range(n):
t=abs(int(s[i])-int(p[i]))
if(t==1 or t==9):
c+=1
elif(t==2 or t==8):
c+=2
elif(t==3 or t==7):
c+=3
elif(t==4 or t==6):
c+=4
else:
c+=t
print(c)
``` | 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,686,595,096 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s = input()
t = list(reversed(input()))
t = ''.join(t)
if s==t:
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
s = input()
t = list(reversed(input()))
t = ''.join(t)
if s==t:
print('YES')
else:
print('NO')
``` | 3.977 |
52 | C | Circular RMQ | PROGRAMMING | 2,200 | [
"data structures"
] | C. Circular RMQ | 1 | 256 | You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it:
- *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (in... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200000). The next line contains initial state of the array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=106<=≤<=*a**i*<=≤<=106), *a**i* are integer. The third line contains integer *m* (0<=≤<=*m*<=≤<=200000), *m* — the number of operartons. Next *m* lines contain one operat... | For each *rmq* operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n"
] | [
"1\n0\n0\n"
] | none | 1,500 | [
{
"input": "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1",
"output": "1\n0\n0"
},
{
"input": "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1",
"output": "-2\n-1\n0\n0"
},
{
"input": "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1",
"ou... | 1,589,865,784 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 560 | 32,665,600 | # http://codeforces.com/problemset/problem/52/C
import bisect # bisect.bisect(list, value)
import collections
import re
import sys
import threading
class Node:
# my under range is [l, r]
l = 0
r = 0
mini = 0
incre = 0
N = [Node() for _ in range(1000000)]
n = int(sys.stdin.readl... | Title: Circular RMQ
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it:
- *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*;... | ```python
# http://codeforces.com/problemset/problem/52/C
import bisect # bisect.bisect(list, value)
import collections
import re
import sys
import threading
class Node:
# my under range is [l, r]
l = 0
r = 0
mini = 0
incre = 0
N = [Node() for _ in range(1000000)]
n = int(sys.s... | -1 |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,551,262,942 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 0 | while True:
try:
n,x=map(int,input().split())
except:
break
thelist=list(map(int,input().split()))
thelist.sort()
time1=time2=0
for i in range(0,x):
if i not in thelist:
time1+=1
time1=time1+thelist.count(x)
print(time1)
| Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
while True:
try:
n,x=map(int,input().split())
except:
break
thelist=list(map(int,input().split()))
thelist.sort()
time1=time2=0
for i in range(0,x):
if i not in thelist:
time1+=1
time1=time1+thelist.count(x)
print(time1)
``` | 3 | |
1,006 | B | Polycarp's Practice | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann... | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are p... | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ... | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | 0 | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
... | 1,626,719,243 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 6,963,200 | n,k=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a,reverse=True)
b=b[:k]
c=k
print(sum(b))
j=0
for i in range(n):
if(a[i] in b and c!=1):
print(i+1-j,end=' ')
j=i+1
b.remove(a[i])
c-=1
if(c==1):
print(n-j)
break | Title: Polycarp's Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a,reverse=True)
b=b[:k]
c=k
print(sum(b))
j=0
for i in range(n):
if(a[i] in b and c!=1):
print(i+1-j,end=' ')
j=i+1
b.remove(a[i])
c-=1
if(c==1):
print(n-j)
break
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the mi... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. | [
"5\n2 2 3 4 6\n",
"4\n2 4 6 8\n",
"3\n2 6 9\n"
] | [
"5\n",
"-1\n",
"4\n"
] | In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | 0 | [
{
"input": "5\n2 2 3 4 6",
"output": "5"
},
{
"input": "4\n2 4 6 8",
"output": "-1"
},
{
"input": "3\n2 6 9",
"output": "4"
},
{
"input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21",
"output": "15"
},
{
"input": "12\n10 10 14 14 14 14 14 14 14 14 21 21",
... | 1,511,079,825 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 1,341 | 5,632,000 | import math
def iterArr(arr, num):
dist = num
for i in range(num):
for j in range(i+1, num):
if math.gcd(arr[i], arr[j]) == 1:
if j-i < dist:
dist = j-i
return dist
n = int(input())
arrIn = list(map(int, input().split()))
i = arrIn.count... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greate... | ```python
import math
def iterArr(arr, num):
dist = num
for i in range(num):
for j in range(i+1, num):
if math.gcd(arr[i], arr[j]) == 1:
if j-i < dist:
dist = j-i
return dist
n = int(input())
arrIn = list(map(int, input().split()))
i = a... | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,696,992,225 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | # https://codeforces.com/contestInvitation/78ea5638ecc7ec3128a10ee42dd0e8bb693ef050
n,m,a,b=map(int,input().split())
ru=0
t=0
while t<n:
ru+=b
t+=m
# print(t,ru)
if t>n:
ru-=b
ru+=(t-n)*a
print(ru)
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
# https://codeforces.com/contestInvitation/78ea5638ecc7ec3128a10ee42dd0e8bb693ef050
n,m,a,b=map(int,input().split())
ru=0
t=0
while t<n:
ru+=b
t+=m
# print(t,ru)
if t>n:
ru-=b
ru+=(t-n)*a
print(ru)
``` | 0 | |
958 | F2 | Lightsabers (medium) | PROGRAMMING | 1,800 | [
"binary search",
"two pointers"
] | null | null | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=2·105) and *m* (1<=≤<=*m*<=≤<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) – the desired ... | Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output <=-<=1. | [
"8 3\n3 3 1 2 2 1 1 3\n3 1 1\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1",
"output": "1"
},
{
"input": "6 5\n1 2 4 2 4 3\n0 0 1 0 0",
"output": "0"
},
{
"input": "1 1\n1\n1",
"output": "0"
},
{
"input": "2 1\n1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1\n2",
"output": "0"
},
{
"inpu... | 1,638,353,667 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 614,400 | from collections import defaultdict
n, m = map(int,input().split())
arr = [int(x) for x in input().split()]
cnt = [0] + [int(x) for x in input().split()]
def can(mid):
d = defaultdict(int)
ac = 0
for i in range(mid):
if(cnt[arr[i]] > d[arr[i]]):
if(cnt[arr[i]] - 1 == d[arr[i]]):... | Title: Lightsabers (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throug... | ```python
from collections import defaultdict
n, m = map(int,input().split())
arr = [int(x) for x in input().split()]
cnt = [0] + [int(x) for x in input().split()]
def can(mid):
d = defaultdict(int)
ac = 0
for i in range(mid):
if(cnt[arr[i]] > d[arr[i]]):
if(cnt[arr[i]] - 1 == d... | 0 | |
887 | B | Cubes for Masha | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a ro... | In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. | Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. | [
"3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n"
] | [
"87",
"98"
] | In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | 1,000 | [
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7",
"output": "87"
},
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9",
"output": "98"
},
{
"input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5",
"output": "5"
},
{
"input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8",
... | 1,509,745,403 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 48 | 77 | 0 | n = int(input())
cubes = [[int(elem) for elem in input().split(' ')] for i in range(n)]
def f(cubes):
dic = {}
for i in range(n):
for elem in cubes[i]:
if elem in dic:
dic[elem] += 1
else: dic[elem] = 1
for i in range(1, 10):
if not i in dic:
... | Title: Cubes for Masha
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her ne... | ```python
n = int(input())
cubes = [[int(elem) for elem in input().split(' ')] for i in range(n)]
def f(cubes):
dic = {}
for i in range(n):
for elem in cubes[i]:
if elem in dic:
dic[elem] += 1
else: dic[elem] = 1
for i in range(1, 10):
if not i in dic... | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,692,715,870 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 31 | 0 | def __main__():
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.extend(y)
x = list(set(x))
x.sort()
if x == list(range(1, n+1)) or x == list(range(0, n+1)):
print("I become the guy.")
else:
print("Oh, my keyboard!")
... | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
def __main__():
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.extend(y)
x = list(set(x))
x.sort()
if x == list(range(1, n+1)) or x == list(range(0, n+1)):
print("I become the guy.")
else:
print("Oh, my key... | 0 | |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to th... | 1,622,891,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | import math
d={}
while(1):
try:
s=input()
d[s]=len(s)
except EOFError:
break
k=list(d.values())
v=list(d.keys())
ma=max(k)
print((ma+2)*"*")
for i in range(len(k)):
val=ma-k[i]
o=(val//2)
s=(val-o)
if i!=len(k)-1:
print("*"," "*o,v[i]," "*s,"*",se... | Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You ... | ```python
import math
d={}
while(1):
try:
s=input()
d[s]=len(s)
except EOFError:
break
k=list(d.values())
v=list(d.keys())
ma=max(k)
print((ma+2)*"*")
for i in range(len(k)):
val=ma-k[i]
o=(val//2)
s=(val-o)
if i!=len(k)-1:
print("*"," "*o,v[i]," ... | 0 |
197 | B | Limit | PROGRAMMING | 1,400 | [
"math"
] | null | null | You are given two polynomials:
- *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*.
Calculate limit . | The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=100) — degrees of polynomials *P*(*x*) and *Q*(*x*) correspondingly.
The second line contains *n*<=+<=1 space-separated integers — the factors of polynomial *P*(*x*): *a*0, *a*1, ..., *a**n*<=-<=1, *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100... | If the limit equals <=+<=∞, print "Infinity" (without quotes). If the limit equals <=-<=∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where *p... | [
"2 1\n1 1 1\n2 5\n",
"1 0\n-1 3\n2\n",
"0 1\n1\n1 0\n",
"2 2\n2 1 6\n4 5 -7\n",
"1 1\n9 0\n-5 2\n"
] | [
"Infinity\n",
"-Infinity\n",
"0/1\n",
"1/2\n",
"-9/5\n"
] | Let's consider all samples:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c28febca257452afdfcbd6984ba8623911f9bdbc.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e55ecd04e54a45e5e0092ec9a5c1ea03bb... | 500 | [
{
"input": "2 1\n1 1 1\n2 5",
"output": "Infinity"
},
{
"input": "1 0\n-1 3\n2",
"output": "-Infinity"
},
{
"input": "0 1\n1\n1 0",
"output": "0/1"
},
{
"input": "2 2\n2 1 6\n4 5 -7",
"output": "1/2"
},
{
"input": "1 1\n9 0\n-5 2",
"output": "-9/5"
},
{
... | 1,594,898,638 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 374 | 20,582,400 | import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right,bisect
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
n,m=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
b... | Title: Limit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two polynomials:
- *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*.
Calculate l... | ```python
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right,bisect
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
n,m=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().sp... | 3 | |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,659,957,059 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n, k = map(int, input().split())
s = list(input())
def numer(a):
if a == 'A':
return 0
elif a == 'B':
return 1
elif a == 'C':
return 2
elif a == 'D':
return 3
elif a == 'E':
return 4
elif a == 'F':
return 5
elif a == 'G':
... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
n, k = map(int, input().split())
s = list(input())
def numer(a):
if a == 'A':
return 0
elif a == 'B':
return 1
elif a == 'C':
return 2
elif a == 'D':
return 3
elif a == 'E':
return 4
elif a == 'F':
return 5
elif a =... | 0 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,530,996,426 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 265 | 8,192,000 | n = int(input())
a = list(map(int, input().split()))
ans = 0
vis = set()
dp = [0] * (n + 1)
for i in reversed(range(n)):
vis.add(a[i])
dp[i] = len(vis)
vis.clear()
for i, x in enumerate(a):
if x in vis:
continue
vis.add(x)
ans += dp[i+1]
print(ans)
| Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
n = int(input())
a = list(map(int, input().split()))
ans = 0
vis = set()
dp = [0] * (n + 1)
for i in reversed(range(n)):
vis.add(a[i])
dp[i] = len(vis)
vis.clear()
for i, x in enumerate(a):
if x in vis:
continue
vis.add(x)
ans += dp[i+1]
print(ans)
``` | 3 | |
35 | A | Shell Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Shell Game | 2 | 64 | Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ... | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered... | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | [
"1\n1 2\n2 1\n2 1\n",
"1\n2 1\n3 1\n1 3\n"
] | [
"2\n",
"2\n"
] | none | 500 | [
{
"input": "1\n1 2\n2 1\n2 1",
"output": "2"
},
{
"input": "1\n2 1\n3 1\n1 3",
"output": "2"
},
{
"input": "3\n3 1\n2 1\n1 2",
"output": "1"
},
{
"input": "1\n1 3\n1 2\n2 3",
"output": "2"
},
{
"input": "3\n3 2\n3 1\n3 1",
"output": "2"
},
{
"input": "... | 1,635,955,902 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 | #!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-04 00:06:14
LastEditTime: 2021-11-04 00:11:17
Description: Shell Game
FilePath: CF35A.py
'''
def func():
init = int(input())
lst = [0] * 4
lst[init] = 1
for _ in range(3):
a, b = map(int, input().strip().split())
lst[... | Title: Shell Game
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put... | ```python
#!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-04 00:06:14
LastEditTime: 2021-11-04 00:11:17
Description: Shell Game
FilePath: CF35A.py
'''
def func():
init = int(input())
lst = [0] * 4
lst[init] = 1
for _ in range(3):
a, b = map(int, input().strip().split())
... | -1 |
413 | A | Data Recovery | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer ... | The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures ... | If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). | [
"2 1 1 2\n1\n",
"3 1 1 3\n2\n",
"2 1 1 3\n2\n"
] | [
"Correct\n",
"Correct\n",
"Incorrect\n"
] | In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3... | 500 | [
{
"input": "2 1 1 2\n1",
"output": "Correct"
},
{
"input": "3 1 1 3\n2",
"output": "Correct"
},
{
"input": "2 1 1 3\n2",
"output": "Incorrect"
},
{
"input": "3 1 1 5\n3",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 5",
"output": "Correct"
},
{
"input... | 1,531,723,779 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | def poss(v,mint,maxt):
m=len(v)
is_min=0
is_max=0
for c in v:
if c<mint or c>maxt:
return 0
for c in v:
if is_max and is_min:
return 1
if c==maxt:
is_max=1
if c==mint:
is_min=1
if is_max and not is_mi... | Title: Data Recovery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each ... | ```python
def poss(v,mint,maxt):
m=len(v)
is_min=0
is_max=0
for c in v:
if c<mint or c>maxt:
return 0
for c in v:
if is_max and is_min:
return 1
if c==maxt:
is_max=1
if c==mint:
is_min=1
if is_max and... | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,663,571,415 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | ab,bc,ca = map(int,input().split())
a = []
c = []
for i in range(1,int(ab**0.5)+1):
if ab%i==0:
a.append(i)
if i**i !=ab:
a.append(ab//i)
for j in range(1,int(bc**0.5)+1):
if bc%j==0:
c.append(j)
if j**j !=bc:
c.append(bc//j)
for k i... | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
ab,bc,ca = map(int,input().split())
a = []
c = []
for i in range(1,int(ab**0.5)+1):
if ab%i==0:
a.append(i)
if i**i !=ab:
a.append(ab//i)
for j in range(1,int(bc**0.5)+1):
if bc%j==0:
c.append(j)
if j**j !=bc:
c.append(bc//j)
... | 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,678,514,133 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String rohanth = sc.next();
String shanmukh = sc.next();
StringBuilder solution = new StringBuilder();
for (int i = 0; i < rohanth.length()... | 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
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String rohanth = sc.next();
String shanmukh = sc.next();
StringBuilder solution = new StringBuilder();
for (int i = 0; i < rohant... | -1 |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,599,671,044 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | import math
n=int(input())
m=int(input())
n=math.pow(2, n)
print(m%n) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
import math
n=int(input())
m=int(input())
n=math.pow(2, n)
print(m%n)
``` | 0 | |
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand o... | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are ... | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 10000000000000000... | 1,528,360,921 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 716,800 | n, h = list(map(int, input().split()))
best = n
for m in range(1, n):
t = ((h + m - 1) * max(m - h, 0) + m * (m + 1)) // 2
l = max(m - h, 0) + m
# print(m, l, t)
if t <= n:
l, t = l + (n - t) // m, t + ((n - t) // m) * m
# print(m, l, t)
if t < n:
t = n
l... | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars... | ```python
n, h = list(map(int, input().split()))
best = n
for m in range(1, n):
t = ((h + m - 1) * max(m - h, 0) + m * (m + 1)) // 2
l = max(m - h, 0) + m
# print(m, l, t)
if t <= n:
l, t = l + (n - t) // m, t + ((n - t) // m) * m
# print(m, l, t)
if t < n:
t = n
... | 0 | |
19 | D | Points | PROGRAMMING | 2,800 | [
"data structures"
] | D. Points | 2 | 256 | Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is directed up. Pete gives Bob requests of three types:
- add x y — on the sheet of paper Bob... | The first input line contains number *n* (1<=≤<=*n*<=≤<=2·105) — amount of requests. Then there follow *n* lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input... | For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (*x*,<=*y*). If there are no points strictly above and to the right of point (*x*,<=*y*), output -1. | [
"7\nadd 1 1\nadd 3 4\nfind 0 0\nremove 1 1\nfind 0 0\nadd 1 1\nfind 0 0\n",
"13\nadd 5 5\nadd 5 6\nadd 5 7\nadd 6 5\nadd 6 6\nadd 6 7\nadd 7 5\nadd 7 6\nadd 7 7\nfind 6 6\nremove 7 7\nfind 6 6\nfind 4 4\n"
] | [
"1 1\n3 4\n1 1\n",
"7 7\n-1\n5 5\n"
] | none | 0 | [] | 1,665,683,298 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 6,246,400 | import bisect
Q,n=10**10,2**17
M,l,e,d=Q*Q,[0]*2*n,[],[]
def c(w,k):
if l[k]//Q<=w//Q or l[k]%Q<=w%Q: return M
if k>=n:
return l[k]
return min(c(w,k<<1),c(w,k<<1|1))
def f(w):
j=c(w,1)
if j<M:
print(j//Q,j%Q)
else:
print(-1)
def u(p,v):
p=p+n
l[p]=v
while p>1:... | Title: Points
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is direc... | ```python
import bisect
Q,n=10**10,2**17
M,l,e,d=Q*Q,[0]*2*n,[],[]
def c(w,k):
if l[k]//Q<=w//Q or l[k]%Q<=w%Q: return M
if k>=n:
return l[k]
return min(c(w,k<<1),c(w,k<<1|1))
def f(w):
j=c(w,1)
if j<M:
print(j//Q,j%Q)
else:
print(-1)
def u(p,v):
p=p+n
l[p]=v
... | 0 |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,592,856,266 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 6,656,000 | n=int(input())
c=0
l=[]
while (n > 0):
c=c+1
temp = n;
m = 0;
p = 1;
while (temp):
rem = temp % 10;
temp = int(temp / 10);
if (rem != 0):
m += p;
p *= 10;
l.append(m)
n = n - m;
print(c)
print(*l) | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
n=int(input())
c=0
l=[]
while (n > 0):
c=c+1
temp = n;
m = 0;
p = 1;
while (temp):
rem = temp % 10;
temp = int(temp / 10);
if (rem != 0):
m += p;
p *= 10;
l.append(m)
n = n - m;
print(c)
print(*l)
``` | 3 | |
286 | C | Main Sequence | PROGRAMMING | 2,100 | [
"greedy",
"implementation"
] | null | null | As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since prehistoric times. A bracket type is a positive integer. The shamans define ... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=109).
The third line contains integer *t* (0<=≤<=*t*<=≤<=*n*), followed by *t* distinct integers *q*1,<=*q*2,<=...,<=*q**t* (1<=≤<=*q**i*<=≤<=*n*).
The numbers in e... | Print a single string "NO" (without the quotes) if Vova is mistaken and a suitable sequence {*x*1,<=*x*2,<=...,<=*x**n*} doesn't exist.
Otherwise, in the first line print "YES" (without the quotes) and in the second line print *n* integers *x*1,<=*x*2,<=...,<=*x**n* (|*x**i*|<==<=*p**i*; *x**q**j*<=<<=0). If there ... | [
"2\n1 1\n0\n",
"4\n1 1 1 1\n1 3\n",
"3\n1 1 1\n0\n",
"4\n1 2 2 1\n2 3 4\n"
] | [
"YES\n1 -1\n",
"YES\n1 1 -1 -1\n",
"NO\n",
"YES\n1 2 -2 -1\n"
] | none | 1,500 | [] | 1,678,446,785 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 60,620,800 | def solve():
n= int(input())
l = list(map(int, input().split()))
neg = list(map(int, input().split()))[1:]
for i in neg:
l[i-1] *= -1
# print(l)
if n%2 == 0:
st = []
extraCount = n//2 - len(neg)
for ind, i in enumerate(l):
if i < 0:
... | Title: Main Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different t... | ```python
def solve():
n= int(input())
l = list(map(int, input().split()))
neg = list(map(int, input().split()))[1:]
for i in neg:
l[i-1] *= -1
# print(l)
if n%2 == 0:
st = []
extraCount = n//2 - len(neg)
for ind, i in enumerate(l):
if i <... | 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,588,001,199 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | n=int(input())
a=input()
b=a
a=a.replace("ogogogo","***")
a=a.replace("ogogo","***")
a=a.replace("ogo","***")
b=b.replace("ogo","***")
b=b.replace("ogogo","***")
b=b.replace("ogogogo","***")
l=[a,b]
print(min(l))
| 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
n=int(input())
a=input()
b=a
a=a.replace("ogogogo","***")
a=a.replace("ogogo","***")
a=a.replace("ogo","***")
b=b.replace("ogo","***")
b=b.replace("ogogo","***")
b=b.replace("ogogogo","***")
l=[a,b]
print(min(l))
``` | 0 | |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,588,909,090 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 404 | 30,105,600 | from sys import stdin
def main():
n, k = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
d = 0
count = [0] * (10 ** 5 + 1)
start = 0
end = 0
ml = n + 1
ms = -1
me = -1
while end < n:
while end < n and d < k:
co... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
from sys import stdin
def main():
n, k = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
d = 0
count = [0] * (10 ** 5 + 1)
start = 0
end = 0
ml = n + 1
ms = -1
me = -1
while end < n:
while end < n and d < k:
... | 3 | |
937 | B | Vile Grasshoppers | PROGRAMMING | 1,400 | [
"brute force",
"math",
"number theory"
] | null | null | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh... | The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109). | Output the number of the highest suitable branch. If there are none, print -1 instead. | [
"3 6\n",
"3 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | 1,000 | [
{
"input": "3 6",
"output": "5"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "5 50",
"output": "49"
},
{
"input": "944192806 944193066",
"output": "944192807"
},
{
"input": "1000000000 1000000000",
"output":... | 1,538,596,097 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 889 | 0 | import math
def prime(m):
if m == 2:
return 1
if m % 2 == 0:
return 0
for i in range(3, round(math.sqrt(m)) + 1, 2):
if m % i == 0:
return 0
return 1
p, y = map(int, input().split())
res_1 = res_2 = 0
for j in range(y, p, -1):
if prime(j):
... | Title: Vile Grasshoppers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor... | ```python
import math
def prime(m):
if m == 2:
return 1
if m % 2 == 0:
return 0
for i in range(3, round(math.sqrt(m)) + 1, 2):
if m % i == 0:
return 0
return 1
p, y = map(int, input().split())
res_1 = res_2 = 0
for j in range(y, p, -1):
if pri... | 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,677,524,943 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | x=input()
c=0
j=0
for i in x:
if 'A'<=i<="Z" :
c+=1
if'a'<=i<='z':
j+=1
if c>j:
print(x.upper())
else: print(x.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
x=input()
c=0
j=0
for i in x:
if 'A'<=i<="Z" :
c+=1
if'a'<=i<='z':
j+=1
if c>j:
print(x.upper())
else: print(x.lower())
``` | 3.977 |
233 | B | Non-square Equation | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"math"
] | null | null | Let's consider equation:
where *x*,<=*n* are positive integers, *s*(*x*) is the function, equal to the sum of digits of number *x* in the decimal number system.
You are given an integer *n*, find the smallest positive integer root of equation *x*, or else determine that there are no such roots. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1018) — the equation parameter.
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. | Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer *x* (*x*<=><=0), that the equation given in the statement holds. | [
"2\n",
"110\n",
"4\n"
] | [
"1\n",
"10\n",
"-1\n"
] | In the first test case *x* = 1 is the minimum root. As *s*(1) = 1 and 1<sup class="upper-index">2</sup> + 1·1 - 2 = 0.
In the second test case *x* = 10 is the minimum root. As *s*(10) = 1 + 0 = 1 and 10<sup class="upper-index">2</sup> + 1·10 - 110 = 0.
In the third test case the equation has no roots. | 1,000 | [
{
"input": "2",
"output": "1"
},
{
"input": "110",
"output": "10"
},
{
"input": "4",
"output": "-1"
},
{
"input": "8",
"output": "2"
},
{
"input": "10000000100000000",
"output": "100000000"
},
{
"input": "10000006999999929",
"output": "99999999"
... | 1,637,198,274 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 186 | 1,433,600 | def dsum(n):
m = 0
while n>0:
m += n%10
n //= 10
return m
def bs(s,n):
l,r=0,int(1e9)
while l<=r:
m = (l+r)//2
nn = m*(m+s)
if nn==n: return m
if nn>n: r = m-1
if nn<n: l = m+1
return -1
def solv(n):
for s in r... | Title: Non-square Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider equation:
where *x*,<=*n* are positive integers, *s*(*x*) is the function, equal to the sum of digits of number *x* in the decimal number system.
You are given an integer *n*, find the smallest posi... | ```python
def dsum(n):
m = 0
while n>0:
m += n%10
n //= 10
return m
def bs(s,n):
l,r=0,int(1e9)
while l<=r:
m = (l+r)//2
nn = m*(m+s)
if nn==n: return m
if nn>n: r = m-1
if nn<n: l = m+1
return -1
def solv(n):
... | 3 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,665,589,648 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 26 | 124 | 1,024,000 | a = list(input())
b = list(input())
cnt = 0
for i in range(len(a)):
if a[i] != b[i]:
cnt += 1
if cnt > 2:
print("NO")
break
else:
if cnt == 2:
print("YES")
else:
print("NO")
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
a = list(input())
b = list(input())
cnt = 0
for i in range(len(a)):
if a[i] != b[i]:
cnt += 1
if cnt > 2:
print("NO")
break
else:
if cnt == 2:
print("YES")
else:
print("NO")
``` | -1 | |
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,594,965,128 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 310 | 22,016,000 | lix=[]
liy=[]
n = int(input())
count=0
for _ in range(n):
x,y = map(int,input().split())
lix.append(x)
liy.append(y)
for i in range(n):
x = lix[i]
y = liy[i]
r=le=u=lw=0
for j in range(n):
if lix[j] > x and liy[j] == y:
r += 1
elif lix[j] < x and ... | 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
lix=[]
liy=[]
n = int(input())
count=0
for _ in range(n):
x,y = map(int,input().split())
lix.append(x)
liy.append(y)
for i in range(n):
x = lix[i]
y = liy[i]
r=le=u=lw=0
for j in range(n):
if lix[j] > x and liy[j] == y:
r += 1
elif lix[j... | 3 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,672,904,158 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | if __name__ == '__main__':
n = int(input())
line = input().split()
w = line[0:n]
print(w)
| Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
if __name__ == '__main__':
n = int(input())
line = input().split()
w = line[0:n]
print(w)
``` | 0 | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,586,962,044 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 109 | 307,200 | #Wrong Substraction
# n,k= input().split()
# n= int(n)
# k = int(k)
# for i in range(k):
# if(n%10==0):
# n=n/10
# else:
# n-=1
# n=int(n)
# print(n)
#Easy Question
# n = int(input())
# h = 0
# for i in range(n):
# ... | 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
#Wrong Substraction
# n,k= input().split()
# n= int(n)
# k = int(k)
# for i in range(k):
# if(n%10==0):
# n=n/10
# else:
# n-=1
# n=int(n)
# print(n)
#Easy Question
# n = int(input())
# h = 0
# for i in range(n):
... | 0 | |
45 | A | Codecraft III | PROGRAMMING | 900 | [
"implementation"
] | A. Codecraft III | 2 | 256 | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa... | The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. | Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. | [
"November\n3\n",
"May\n24\n"
] | [
"February\n",
"May\n"
] | none | 0 | [
{
"input": "November\n3",
"output": "February"
},
{
"input": "May\n24",
"output": "May"
},
{
"input": "April\n0",
"output": "April"
},
{
"input": "September\n0",
"output": "September"
},
{
"input": "August\n0",
"output": "August"
},
{
"input": "June\n1... | 1,620,924,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 6,656,000 | lst = [0,"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
a = input()
b = int(input())
if b % 12 ==0:
print(a)
else:
b = b + lst.index(a)
b = b % 12
print(lst[b]) | Title: Codecraft III
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *... | ```python
lst = [0,"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
a = input()
b = int(input())
if b % 12 ==0:
print(a)
else:
b = b + lst.index(a)
b = b % 12
print(lst[b])
``` | 0 |
886 | D | Restoration of string | PROGRAMMING | 2,000 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set.
Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.
The total length of the strings doesn't exceed 105. | Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings. | [
"4\nmail\nai\nlru\ncf\n",
"3\nkek\npreceq\ncheburek\n"
] | [
"cfmailru\n",
"NO\n"
] | One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum. | 2,000 | [
{
"input": "4\nmail\nai\nlru\ncf",
"output": "cfmailru"
},
{
"input": "3\nkek\npreceq\ncheburek",
"output": "NO"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nab\nba",
"output": "NO"
},
{
"input": "2\nac\nbc",
"output": "NO"
},
{
"input": "2\nc... | 1,510,509,759 | 7,059 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 62 | 0 | n=int(input())
a=[]
for i in range(n):
a.append(input())
for j in range(len(a)-1):
if a[-1] in a[j]:
a[-1:]=[]
break
if a[j] in a[-1]:
a[j:j+1]=[]
break
for i in range(len(a)):
k=a[i][-1]
l=1
for j in range(len(a)):
... | Title: Restoration of string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily fr... | ```python
n=int(input())
a=[]
for i in range(n):
a.append(input())
for j in range(len(a)-1):
if a[-1] in a[j]:
a[-1:]=[]
break
if a[j] in a[-1]:
a[j:j+1]=[]
break
for i in range(len(a)):
k=a[i][-1]
l=1
for j in range(len(... | 0 | |
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,582,317,795 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | str1 = input()
str2 = input()
str1 = str1.lower()
str2 = str2.lower()
text = str2[::-1]
if text == str1:
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
str1 = input()
str2 = input()
str1 = str1.lower()
str2 = str2.lower()
text = str2[::-1]
if text == str1:
print("YES")
else:
print("NO")
``` | 3.9455 |
424 | C | Magic Formulas | PROGRAMMING | 1,600 | [
"math"
] | null | null | People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
Here, "mod" means the operation of taking the residue after dividing.
The expression means applying ... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=106). The next line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=2·109). | The only line of output should contain a single integer — the value of *Q*. | [
"3\n1 2 3\n"
] | [
"3\n"
] | none | 1,500 | [
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n65535 0",
"output": "65534"
},
{
"input": "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015",
"output": "948506286"
},
{... | 1,450,078,030 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 78,950,400 | from operator import xor
n=int(input())
arr=[0 for i in range(0,1000010)]
ans=0
p=[int(i) for i in input().split()]
for i in range(0,n):
arr[i+1]=xor(i+1, arr[i])
ans=xor(ans,p[i])
ans=xor(ans,arr[i])
if i>1:
x=(n-i)//i
sh=n-i-x*i
ans=xor(ans,arr[sh])
if x%2=... | Title: Magic Formulas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
He... | ```python
from operator import xor
n=int(input())
arr=[0 for i in range(0,1000010)]
ans=0
p=[int(i) for i in input().split()]
for i in range(0,n):
arr[i+1]=xor(i+1, arr[i])
ans=xor(ans,p[i])
ans=xor(ans,arr[i])
if i>1:
x=(n-i)//i
sh=n-i-x*i
ans=xor(ans,arr[sh])
... | 0 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,636,946,741 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 61 | 0 | s = input()
n = len(s)
if s[-1] not in "aeioun":
x = "NO"
else:
x = "YES"
for i in range(n - 1):
if s[i] not in "aeioun":
if s[i + 1] not in "aeiou":
x = "NO"
print(x)
| Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
s = input()
n = len(s)
if s[-1] not in "aeioun":
x = "NO"
else:
x = "YES"
for i in range(n - 1):
if s[i] not in "aeioun":
if s[i + 1] not in "aeiou":
x = "NO"
print(x)
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,689,092,707 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | remix = input()
remix = remix.replace("WUB", " ")
remix = remix.strip()
remix = ' '.join(remix.split())
print(remix) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
remix = input()
remix = remix.replace("WUB", " ")
remix = remix.strip()
remix = ' '.join(remix.split())
print(remix)
``` | 3 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,529,393,501 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 409,600 | # Codeforces Round #486 (Div. 3)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
n,m = getIntList()
x = getIntList()
y = getIntList... | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
# Codeforces Round #486 (Div. 3)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
n,m = getIntList()
x = getIntList()
y = ... | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,593,486,755 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 108 | 6,758,400 | s, v1, v2, t1, t2 = map(int, input().split())
svt1 = v1 * s + 2 * t1
svt2 = v2 * s + 2 * t2
if svt1 < svt2:
print("First")
elif svt1 > svt2:
print("Second")
else:
print("Friendship")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s, v1, v2, t1, t2 = map(int, input().split())
svt1 = v1 * s + 2 * t1
svt2 = v2 * s + 2 * t2
if svt1 < svt2:
print("First")
elif svt1 > svt2:
print("Second")
else:
print("Friendship")
``` | 3 | |
667 | B | Coat of Anticubism | PROGRAMMING | 1,100 | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-... | The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso alrea... | Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | 1,000 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707... | 1,610,441,939 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 93 | 3,379,200 | n=int(input())
arr=list(map(int,input().split()))
ma=max(arr)
su=sum(arr)
su=su-ma
ans=ma-su
ans=ans+1
print(ans)
| Title: Coat of Anticubism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, ... | ```python
n=int(input())
arr=list(map(int,input().split()))
ma=max(arr)
su=sum(arr)
su=su-ma
ans=ma-su
ans=ans+1
print(ans)
``` | 3 | |
549 | B | Looksery Party | PROGRAMMING | 2,300 | [
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy"
] | null | null | The Looksery company, consisting of *n* staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends messages to his contacts about how cool it is. At the same time everyone is trying to spend as much tim... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of employees of company Looksery.
Next *n* lines contain the description of the contact lists of the employees. The *i*-th of these lines contains a string of length *n*, consisting of digits zero and one, specifying the contact list of the ... | In the first line print a single integer *m* — the number of employees who should come to the party so that Igor loses the dispute.
In the second line print *m* space-separated integers — the numbers of these employees in an arbitrary order.
If Igor wins the dispute in any case, print -1.
If there are multiple possi... | [
"3\n101\n010\n001\n0 1 2\n",
"1\n1\n1\n",
"4\n1111\n0101\n1110\n0001\n1 0 1 0\n"
] | [
"1\n1 \n",
"0\n\n",
"4\n1 2 3 4 \n"
] | In the first sample Igor supposes that the first employee will receive 0 messages. Since he isn't contained in any other contact list he must come to the party in order to receive one message from himself. If he is the only who come to the party then he will receive 1 message, the second employee will receive 0 message... | 1,750 | [
{
"input": "3\n101\n010\n001\n0 1 2",
"output": "1\n1 "
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "4\n1111\n0101\n1110\n0001\n1 0 1 0",
"output": "4\n1 2 3 4 "
},
{
"input": "2\n11\n01\n0 2",
"output": "1\n1 "
},
{
"input": "5\n10110\n01110\n00101\n0001... | 1,433,654,045 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
const int N = 200;
char st[N][N];
int n;
int a[N];
int ans[N], ansn;
int findZero(int a[], int n) {
for (int i = 0; i < n; i++)
if (a[i] == 0) return i;
... | Title: Looksery Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Looksery company, consisting of *n* staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends mes... | ```python
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
const int N = 200;
char st[N][N];
int n;
int a[N];
int ans[N], ansn;
int findZero(int a[], int n) {
for (int i = 0; i < n; i++)
if (a[i] == 0) ... | -1 | |
551 | C | GukiZ hates Boxes | PROGRAMMING | 2,200 | [
"binary search",
"greedy"
] | null | null | Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way.
In total there are *n* piles of boxes, arranged in a line, from left to right, *i*-th pile (1<=≤<=*i*<=≤<=*n*) containing *a**i* boxes. Luckily, *m* students are willing to help GukiZ by removing all the ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105), the number of piles of boxes and the number of GukiZ's students.
The second line contains *n* integers *a*1,<=*a*2,<=... *a**n* (0<=≤<=*a**i*<=≤<=109) where *a**i* represents the number of boxes on *i*-th pile. It's guaranteed that at least o... | In a single line, print one number, minimum time needed to remove all the boxes in seconds. | [
"2 1\n1 1\n",
"3 2\n1 0 2\n",
"4 100\n3 4 5 4\n"
] | [
"4\n",
"5\n",
"5\n"
] | First sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second), then move to the second pile (1 second) and finally remove the box from second pile (1 second).
Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box fr... | 1,750 | [
{
"input": "2 1\n1 1",
"output": "4"
},
{
"input": "3 2\n1 0 2",
"output": "5"
},
{
"input": "4 100\n3 4 5 4",
"output": "5"
},
{
"input": "5 8\n121351 0 13513 0 165454",
"output": "37544"
},
{
"input": "6 6\n0 10 0 0 10 0",
"output": "8"
},
{
"input":... | 1,689,320,829 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def min_time_to_remove_boxes(n, m, boxes):
def boxes_removed_in_time(boxes, t):
n = 0
boxes = boxes[::-1] # reverse the boxes for efficient operations
while boxes and not boxes[-1]:
boxes.pop()
if not boxes:
return 0
while True:
n... | Title: GukiZ hates Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way.
In total there are *n* piles of boxes, arranged in a line, from left to right, *i*-th pile (1<=≤<=*i*... | ```python
def min_time_to_remove_boxes(n, m, boxes):
def boxes_removed_in_time(boxes, t):
n = 0
boxes = boxes[::-1] # reverse the boxes for efficient operations
while boxes and not boxes[-1]:
boxes.pop()
if not boxes:
return 0
while True:
... | 0 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,514,748,159 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 62 | 5,529,600 | s1,s2=input().split()
ans=s1[0]
for j in s1[1:]:
if j<s2[0]:
ans=ans+j
else:
break
ans+=s2[0]
print(ans) | Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
s1,s2=input().split()
ans=s1[0]
for j in s1[1:]:
if j<s2[0]:
ans=ans+j
else:
break
ans+=s2[0]
print(ans)
``` | 3 | |
980 | A | Links and Pearls | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l... | The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. | Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"-o-o--",
"-o---\n",
"-o---o-\n",
"ooo\n"
] | [
"YES",
"YES",
"NO",
"YES\n"
] | none | 500 | [
{
"input": "-o-o--",
"output": "YES"
},
{
"input": "-o---",
"output": "YES"
},
{
"input": "-o---o-",
"output": "NO"
},
{
"input": "ooo",
"output": "YES"
},
{
"input": "---",
"output": "YES"
},
{
"input": "--o-o-----o----o--oo-o-----ooo-oo---o--",
"... | 1,594,367,231 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 20,172,800 | s = input()
links = 0
pearls = 0
if "o" in s: pearls = s.count("o")
if "-" in s: links = s.count("-")
if pearls==0 or links%pearls:
print("NO")
else:
print("YES")
# - -
# o o
#
#
# | Title: Links and Pearls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearl... | ```python
s = input()
links = 0
pearls = 0
if "o" in s: pearls = s.count("o")
if "-" in s: links = s.count("-")
if pearls==0 or links%pearls:
print("NO")
else:
print("YES")
# - -
# o o
#
#
#
``` | 0 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,658,091,597 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 61 | 409,600 | import string # to get abc instead of typing it in a varibel
abc = string.ascii_lowercase
# take word from user to calculate n of steps in both directations
word = input() # note that input always returns a string
counter = 0 # to counter n of rotations
pointer = 'a' # pointer starts from a as me... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
import string # to get abc instead of typing it in a varibel
abc = string.ascii_lowercase
# take word from user to calculate n of steps in both directations
word = input() # note that input always returns a string
counter = 0 # to counter n of rotations
pointer = 'a' # pointer starts fr... | 3 | |
385 | C | Bear and Prime Numbers | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"implementation",
"math",
"number theory"
] | null | null | Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=*x**i*<=≤<=107). The numbers are not necessarily distinct.
The third line contains integer *m* (1<=≤<=*m*<=≤<=50000). Each of the following *m* lines contains a pair of space-separated integ... | Print *m* integers — the answers to the queries on the order the queries appear in the input. | [
"6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n",
"7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n"
] | [
"9\n7\n0\n",
"0\n7\n"
] | Consider the first sample. Overall, the first sample has 3 queries.
1. The first query *l* = 2, *r* = 11 comes. You need to count *f*(2) + *f*(3) + *f*(5) + *f*(7) + *f*(11) = 2 + 1 + 4 + 2 + 0 = 9. 1. The second query comes *l* = 3, *r* = 12. You need to count *f*(3) + *f*(5) + *f*(7) + *f*(11) = 1 + 4 + 2 + 0 = 7.... | 1,500 | [
{
"input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4",
"output": "9\n7\n0"
},
{
"input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123",
"output": "0\n7"
},
{
"input": "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792",
"output": "0\n0\n0\n0\n9\n0\n0"
},
{
"... | 1,390,586,775 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 3,072,000 | import bisect
if __name__ == "__main__":
n = int(input())
x = [int(i) for i in input().split()]
m = int(input())
q = []
prange = [0,0]
for i in range(m):
l_str, r_str = input().split()
l, r = int(l_str), int(r_str)
if l < prange[0]:
prange[0] = l
i... | Title: Bear and Prime Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized b... | ```python
import bisect
if __name__ == "__main__":
n = int(input())
x = [int(i) for i in input().split()]
m = int(input())
q = []
prange = [0,0]
for i in range(m):
l_str, r_str = input().split()
l, r = int(l_str), int(r_str)
if l < prange[0]:
prange[0] = l... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,597,473,413 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | m=int(input())
n=list(map(int,input().split()))
r=0
for i in n:
r+=i
print(r) | 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
m=int(input())
n=list(map(int,input().split()))
r=0
for i in n:
r+=i
print(r)
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he r... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108). | If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | [
"5 2\n",
"5 3",
"7 2\n"
] | [
"1 2 3 4 5\n",
"2 4 3 7 1",
"-1\n"
] | *gcd*(*x*, *y*) is greatest common divisor of *x* and *y*. | 0 | [
{
"input": "5 2",
"output": "1 2 3 4 5"
},
{
"input": "5 3",
"output": "2 4 5 6 7"
},
{
"input": "7 2",
"output": "-1"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "2 0",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input"... | 1,590,758,812 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 140 | 0 | n,k = [int(i) for i in input().split()]
if k<n//2 or n<=1:
print(-1)
else:
if n%2==0:
m = n-2
summ = 0
st = 10**8
while(m>0):
print(st,end=' ')
st+=1
print(st,end=' ')
summ+=1
st+=1
m-=2
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first mov... | ```python
n,k = [int(i) for i in input().split()]
if k<n//2 or n<=1:
print(-1)
else:
if n%2==0:
m = n-2
summ = 0
st = 10**8
while(m>0):
print(st,end=' ')
st+=1
print(st,end=' ')
summ+=1
st+=1
m-... | 0 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,677,694,221 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | a = input()
b = input()
s = input()
s = sorted(s)
x = a+b
x = sorted(x)
p = ""
for i in range(len(x)):
p+=x[i]
res = ""
for _ in range(len(s)):
res+=s[_]
if res == p:
print("YES")
else:
print("NO") | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
a = input()
b = input()
s = input()
s = sorted(s)
x = a+b
x = sorted(x)
p = ""
for i in range(len(x)):
p+=x[i]
res = ""
for _ in range(len(s)):
res+=s[_]
if res == p:
print("YES")
else:
print("NO")
``` | 3 | |
482 | A | Diverse Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of number... | The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). | Print *n* integers forming the permutation. If there are multiple answers, print any of them. | [
"3 2\n",
"3 1\n",
"5 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] | By |*x*| we denote the absolute value of number *x*. | 500 | [
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": ... | 1,673,240,957 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def permutation(n, k):
p = []
for i in range(1, k+1):
p.append(i)
for i in range(k+1, n+1):
p.append(i)
return p
print(permutation(10, 5)) # prints [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(permutation(10, 6)) # prints [1, 2, 3, 4, 5, 6, 10, 9, 8, 7]
| Title: Diverse Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<... | ```python
def permutation(n, k):
p = []
for i in range(1, k+1):
p.append(i)
for i in range(k+1, n+1):
p.append(i)
return p
print(permutation(10, 5)) # prints [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(permutation(10, 6)) # prints [1, 2, 3, 4, 5, 6, 10, 9, 8, 7]
``` | 0 | |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,485,704,661 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 5,017,600 | import sys
import re
length,swaps=map(int,sys.stdin.readline().split())
wordS=input()
word=list(wordS)
for i in range(swaps):
a,b=map(str,sys.stdin.readline().split())
if a==b:
pass
wordS=''.join(word)
aocc=[m.start() for m in re.finditer(a, wordS)]
bocc=[m.start() for m in re.finditer(b, wo... | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
import sys
import re
length,swaps=map(int,sys.stdin.readline().split())
wordS=input()
word=list(wordS)
for i in range(swaps):
a,b=map(str,sys.stdin.readline().split())
if a==b:
pass
wordS=''.join(word)
aocc=[m.start() for m in re.finditer(a, wordS)]
bocc=[m.start() for m in re.find... | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,666,301,392 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | k=int(input())
l=[]
for i in range(k):
a=int(input())
n=(360)/(180-a)
l.append(n)
for j in range(len(l)):
if l[j]%1==0:
print("YES")
else:
print("NO")
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
k=int(input())
l=[]
for i in range(k):
a=int(input())
n=(360)/(180-a)
l.append(n)
for j in range(len(l)):
if l[j]%1==0:
print("YES")
else:
print("NO")
``` | 3 | |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,578,225,502 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 109 | 0 | a,b,c,d=map(int,input().split())
if c>a or c>b:
print(-1)
exit(0)
a-=c
if(a+b>=d):
print(-1)
exit(0)
print(d-a-b) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
a,b,c,d=map(int,input().split())
if c>a or c>b:
print(-1)
exit(0)
a-=c
if(a+b>=d):
print(-1)
exit(0)
print(d-a-b)
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,683,389,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 62 | 0 | def prime(s):
if s <= 1:
return False
for i in range(2, s):
if s % i == 0:
return False
return True
n, m = list(map(int, input().split()))
if prime(n):
if m > n and prime(m):
print("YES")
else:
print("NO")
| Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
def prime(s):
if s <= 1:
return False
for i in range(2, s):
if s % i == 0:
return False
return True
n, m = list(map(int, input().split()))
if prime(n):
if m > n and prime(m):
print("YES")
else:
print("NO")
``` | 0 |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,677,440,823 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | output=[[1,1,1],[1,1,1],[1,1,1]]
r1=list(map(lambda x:int(x)%2,input().split()))
r2=list(map(lambda x:int(x)%2,input().split()))
r3=list(map(lambda x:int(x)%2,input().split()))
l=[r1,r2,r3]
for i in range(3):
for j in range(3):
if l[i][j]:
if i==0:
if j==0:
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
output=[[1,1,1],[1,1,1],[1,1,1]]
r1=list(map(lambda x:int(x)%2,input().split()))
r2=list(map(lambda x:int(x)%2,input().split()))
r3=list(map(lambda x:int(x)%2,input().split()))
l=[r1,r2,r3]
for i in range(3):
for j in range(3):
if l[i][j]:
if i==0:
if j==0:... | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,695,731,052 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | import sys
input = sys.stdin.readline
import math as m
import heapq as hq
import time
def inp():
return list(map(int,input().split()))
mod=1000000007
def binpow(a,b,m):
res=1
while b>0:
if b&1:
res=(res*a)%m
a=(a*a)%m
b>>=1
return res%m
def phi... | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
import sys
input = sys.stdin.readline
import math as m
import heapq as hq
import time
def inp():
return list(map(int,input().split()))
mod=1000000007
def binpow(a,b,m):
res=1
while b>0:
if b&1:
res=(res*a)%m
a=(a*a)%m
b>>=1
return res%m
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 0 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,387,009,413 | 3,093 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | import sys
n = int(sys.stdin.readline())
a = [int(sys.stdin.readline()) for i in range(n)]
fst = [n for i in range(n)]
a.sort()
for i in range(n):
start = fst[i - 1] if i > 0 else 0
for j in range(start, n):
if a[j] >= a[i] * 2:
fst[i] = j
break
for i in range(n-1, -1, -1):
if n - fst[i... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of ... | ```python
import sys
n = int(sys.stdin.readline())
a = [int(sys.stdin.readline()) for i in range(n)]
fst = [n for i in range(n)]
a.sort()
for i in range(n):
start = fst[i - 1] if i > 0 else 0
for j in range(start, n):
if a[j] >= a[i] * 2:
fst[i] = j
break
for i in range(n-1, -1, -1):
if... | 0 | |
215 | B | Olympic Medal | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/... | The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta... | Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists. | [
"3 1 2 3\n1 2\n3 3 2 1\n1 2\n",
"4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n"
] | [
"2.683281573000\n",
"2.267786838055\n"
] | In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1. | 500 | [
{
"input": "3 1 2 3\n1 2\n3 3 2 1\n1 2",
"output": "2.683281573000"
},
{
"input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1",
"output": "2.267786838055"
},
{
"input": "1 5\n1 3\n1 7\n515 892",
"output": "3.263613058533"
},
{
"input": "2 3 2\n3 2 3 1\n2 2 1\n733 883",
"output": "2.... | 1,591,765,560 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 310 | 1,945,600 | import math
r = list(map(int, input().split()))
r = r[1:]
p1 = list(map(int, input().split()))
p1 = p1[1:]
p2 = list(map(int, input().split()))
p2 = p2[1:]
a, b = map(int, input().split())
r1 = max(r)
minm = 1000000000
ratio = min(p2) / max(p1)
r2 = (r1 * r1) / (1 + (ratio * a / b))
print(math.sqrt(r2)) | Title: Olympic Medal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/... | ```python
import math
r = list(map(int, input().split()))
r = r[1:]
p1 = list(map(int, input().split()))
p1 = p1[1:]
p2 = list(map(int, input().split()))
p2 = p2[1:]
a, b = map(int, input().split())
r1 = max(r)
minm = 1000000000
ratio = min(p2) / max(p1)
r2 = (r1 * r1) / (1 + (ratio * a / b))
print(math.sqrt(r2))
``` | 3 | |
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,587,462,233 | 2,633 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n, a, b = [int(x) for x in input().split()]
if abs(b) == n or b == 0:
print(a)
elif b < 0:
print(n + a - b)
else:
print(a + b - n)
| 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()]
if abs(b) == n or b == 0:
print(a)
elif b < 0:
print(n + a - b)
else:
print(a + b - n)
``` | 0 | |
519 | C | A and B and Team Training | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session. | Print the maximum number of teams that can be formed. | [
"2 6\n",
"4 5\n"
] | [
"2\n",
"3\n"
] | Let's represent the experienced players as XP and newbies as NB.
In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).
In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB). | 1,500 | [
{
"input": "2 6",
"output": "2"
},
{
"input": "4 5",
"output": "3"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "500000 500000",
"output": "333333"
},
{
"input": "70 100",
"output": "56"
},
{
"input": ... | 1,666,180,522 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 46 | 0 | a, b = map(int, input().split())
if a // 3 > b or b // 3 > a:
print(min(a,b))
else:
print(((a + b) // 3)) | Title: A and B and Team Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to dea... | ```python
a, b = map(int, input().split())
if a // 3 > b or b // 3 > a:
print(min(a,b))
else:
print(((a + b) // 3))
``` | 0 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,692,951,619 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 77 | 13,516,800 | n = int(input()) # Read the number of elements in the list
a = list(map(int, input().split())) # Read the list of integers
max_length = 1 # Initialize the maximum length of increasing subarray
current_length = 1 # Initialize the length of the current increasing subarray
for i in range(1, n):
if a[i] >=... | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n = int(input()) # Read the number of elements in the list
a = list(map(int, input().split())) # Read the list of integers
max_length = 1 # Initialize the maximum length of increasing subarray
current_length = 1 # Initialize the length of the current increasing subarray
for i in range(1, n):
... | 3 | |
712 | B | Memory and Trident | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move... | The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | [
"RRU\n",
"UDUR\n",
"RUUR\n"
] | [
"-1\n",
"1\n",
"2\n"
] | In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses ... | 1,000 | [
{
"input": "RRU",
"output": "-1"
},
{
"input": "UDUR",
"output": "1"
},
{
"input": "RUUR",
"output": "2"
},
{
"input": "DDDD",
"output": "2"
},
{
"input": "RRRR",
"output": "2"
},
{
"input": "RRRUUD",
"output": "2"
},
{
"input": "UDURLRDURL... | 1,672,850,877 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | s = input()
if len(s) % 2 != 0:
print(-1)
else:
u = 0
d = 0
r = 0
l = 0
for i in s:
if i == 'U':
u += 1
elif i == 'D':
d += 1
elif i == 'R':
r += 1
else:
l += 1
print(max(abs(u-d),abs(r-l))... | Title: Memory and Trident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he shou... | ```python
s = input()
if len(s) % 2 != 0:
print(-1)
else:
u = 0
d = 0
r = 0
l = 0
for i in s:
if i == 'U':
u += 1
elif i == 'D':
d += 1
elif i == 'R':
r += 1
else:
l += 1
print(max(abs(u-d)... | 0 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,697,124,151 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | s1,s2,s3,s4=map(int,input().split())
tab1=[s2,s3,s4]
tab2=[s1]
for i in tab1:
if i not in tab2:
tab2.append(i)
print(4-len(tab2))
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
s1,s2,s3,s4=map(int,input().split())
tab1=[s2,s3,s4]
tab2=[s1]
for i in tab1:
if i not in tab2:
tab2.append(i)
print(4-len(tab2))
``` | 3 | |
484 | A | Bits | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms"
] | null | null | Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the... | The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000).
Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). | For each query print the answer in a separate line. | [
"3\n1 2\n2 4\n1 10\n"
] | [
"1\n3\n7\n"
] | The binary representations of numbers from 1 to 10 are listed below:
1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub>
2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub>
3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub>
4<sub class="lower-index">10</su... | 500 | [
{
"input": "3\n1 2\n2 4\n1 10",
"output": "1\n3\n7"
},
{
"input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10... | 1,601,020,946 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 307,200 | # -*- coding: utf-8 -*-
"""
Created on Fri Sep 25 08:39:04 2020
@author: Dark Soul
"""
def BinToDec(s):
n=len(s)
ans=0
for i in range(n-1,-1,-1):
ans+=int(s[i])*(2**(n-i-1))
return ans
t=int(input(''))
cnt=0
for _ in range(t):
[l,r]=list(map(int,input().split()))
... | Title: Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 25 08:39:04 2020
@author: Dark Soul
"""
def BinToDec(s):
n=len(s)
ans=0
for i in range(n-1,-1,-1):
ans+=int(s[i])*(2**(n-i-1))
return ans
t=int(input(''))
cnt=0
for _ in range(t):
[l,r]=list(map(int,input().... | 0 | |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,686,697,672 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
def find(A):
global N
P = deque(A[:])
ans = int(''.join(P))
for _ ... | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
def find(A):
global N
P = deque(A[:])
ans = int(''.join(P))
... | 0 | |
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,686,414,548 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=input()
d=input()
d1="".join(list(reversed(d.split())))
if(s==d1):
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
s=input()
d=input()
d1="".join(list(reversed(d.split())))
if(s==d1):
print("YES")
else:
print("NO")
``` | 0 |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,623,828,093 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 124 | 0 | sq = []
i = 0
while i < 3:
row = [int(x) for x in input().split()]
sq.append(row)
i += 1
eq1 = sum(sq[1]) - sum(sq[0])
eq2 = sum(sq[2])
sq[0][0] = (eq1 + eq2) // 2
sq[1][1] = sum(sq[0]) - sum(sq[1])
sq[2][2] = sum(sq[0]) - sum(sq[2])
for i in range(3):
for j in range(3):
... | Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
sq = []
i = 0
while i < 3:
row = [int(x) for x in input().split()]
sq.append(row)
i += 1
eq1 = sum(sq[1]) - sum(sq[0])
eq2 = sum(sq[2])
sq[0][0] = (eq1 + eq2) // 2
sq[1][1] = sum(sq[0]) - sum(sq[1])
sq[2][2] = sum(sq[0]) - sum(sq[2])
for i in range(3):
for j in range(3)... | 3 | |
520 | B | Two Buttons | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . | Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | 1,000 | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"outpu... | 1,699,805,673 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 62 | 0 | def solve():
n, m = map(int, input().split())
if m < n:
print(n - m)
else:
res = 0
while n < m:
if m % 2 == 1:
m += 1
else:
m //= 2
res += 1
print(res + (n - m))
if __name__ == "__main__":
... | Title: Two Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by t... | ```python
def solve():
n, m = map(int, input().split())
if m < n:
print(n - m)
else:
res = 0
while n < m:
if m % 2 == 1:
m += 1
else:
m //= 2
res += 1
print(res + (n - m))
if __name__ == "__m... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 0 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,671,608,499 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,150,400 | n=input()
a=[input() for _ in range(n)]
g=[]
def E():
print ('Impossible')
exit(0)
for i in range(1,n):
l=min(len(a[i-1]),len(a[i]))
for j in range(l):
if a[i-1][j]!=a[i][j]:
g+=[(ord(a[i-1][j]),ord(a[i][j]))]
break
if l==len(a[i]) and a[i][j]==a[i-1][j]:
E()
r=[0]*128
f=1
while f:
f=0
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
n=input()
a=[input() for _ in range(n)]
g=[]
def E():
print ('Impossible')
exit(0)
for i in range(1,n):
l=min(len(a[i-1]),len(a[i]))
for j in range(l):
if a[i-1][j]!=a[i][j]:
g+=[(ord(a[i-1][j]),ord(a[i][j]))]
break
if l==len(a[i]) and a[i][j]==a[i-1][j]:
E()
r=[0]*128
f=1
while ... | -1 | |
837 | C | Two Seals | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | One very important person has a piece of paper in the form of a rectangle *a*<=×<=*b*.
Also, he has *n* seals. Each seal leaves an impression on the paper in the form of a rectangle of the size *x**i*<=×<=*y**i*. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees... | The first line contains three integer numbers *n*, *a* and *b* (1<=≤<=*n*,<=*a*,<=*b*<=≤<=100).
Each of the next *n* lines contain two numbers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=100). | Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0. | [
"2 2 2\n1 2\n2 1\n",
"4 10 9\n2 3\n1 1\n5 10\n9 11\n",
"3 10 10\n6 6\n7 7\n20 5\n"
] | [
"4\n",
"56\n",
"0\n"
] | In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large... | 0 | [
{
"input": "2 2 2\n1 2\n2 1",
"output": "4"
},
{
"input": "4 10 9\n2 3\n1 1\n5 10\n9 11",
"output": "56"
},
{
"input": "3 10 10\n6 6\n7 7\n20 5",
"output": "0"
},
{
"input": "2 1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "2 1 2\n1 1\n1 1",
"output": "2"
},
... | 1,630,679,439 | 1,239 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 109 | 20,172,800 | import sys
input = sys.stdin.readline
n, a, b = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
xi, yi = xy[i]
si = xi * yi
if si > a * b:
continue
for j in range(i + 1, n):
xj, yj = xy[j]
sj = xj * yj
... | Title: Two Seals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One very important person has a piece of paper in the form of a rectangle *a*<=×<=*b*.
Also, he has *n* seals. Each seal leaves an impression on the paper in the form of a rectangle of the size *x**i*<=×<=*y**i*. Each impres... | ```python
import sys
input = sys.stdin.readline
n, a, b = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
xi, yi = xy[i]
si = xi * yi
if si > a * b:
continue
for j in range(i + 1, n):
xj, yj = xy[j]
sj = ... | 0 | |
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he giv... | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c*... | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input... | 1,685,533,833 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 77 | 4,812,800 | import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def dfs(u,i,v):
global l
global z
vis[u]=1
if u==v:
z=1
return 0
for w in l[i][u]:
if vis[w]==0:
dfs(w,i,v)
n,m=map(int,input().split())
l=[[[] for j in range(101)... | Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting v... | ```python
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def dfs(u,i,v):
global l
global z
vis[u]=1
if u==v:
z=1
return 0
for w in l[i][u]:
if vis[w]==0:
dfs(w,i,v)
n,m=map(int,input().split())
l=[[[] for j in ... | 3 | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,685,054,110 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 62 | 0 | n = int(input())
if n%10 == 0:
n = 8
else:
n = n%8
n = 8**n
n = str(n)
print(n[-1]) | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n = int(input())
if n%10 == 0:
n = 8
else:
n = n%8
n = 8**n
n = str(n)
print(n[-1])
``` | 0 | |
120 | B | Quiz League | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 ... | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | [
"5 5\n0 1 0 1 0\n",
"2 1\n1 1\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "5 5\n0 1 0 1 0",
"output": "2"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "3 2\n1 0 0",
"output": "1"
},
{
"input": "3 3\n0 1 0",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "6 3\n0 0 1 1 0 1",
"output":... | 1,668,174,568 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | import sys
def qinput():
return sys.stdin.readline().strip()
def qprint(string):
sys.stdout.write(string)
def solve(n, k, a):
index = k - 1
while a[index] != 1:
index += 1
if index == n:
index = 0
return index + 1
if __name__ == "__main__":
n, k =... | Title: Quiz League
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a quest... | ```python
import sys
def qinput():
return sys.stdin.readline().strip()
def qprint(string):
sys.stdout.write(string)
def solve(n, k, a):
index = k - 1
while a[index] != 1:
index += 1
if index == n:
index = 0
return index + 1
if __name__ == "__main__":
... | -1 |
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.