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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,670,673,544 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # LUOGU_RID: 97031267
n=int(input())
for i in range(n):
s=input()
a=len(s)
if a>10:
print(s[0]+str(a-2)+s[a-1])
else:
print(s)
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
# LUOGU_RID: 97031267
n=int(input())
for i in range(n):
s=input()
a=len(s)
if a>10:
print(s[0]+str(a-2)+s[a-1])
else:
print(s)
``` | 3.977 |
430 | B | Balls Game | PROGRAMMING | 1,400 | [
"brute force",
"two pointers"
] | null | null | Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at... | The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*.
It is guaranteed th... | Print a single integer — the maximum number of balls Iahub can destroy. | [
"6 2 2\n1 1 2 2 1 1\n",
"1 1 1\n1\n"
] | [
"6\n",
"0\n"
] | none | 1,000 | [
{
"input": "6 2 2\n1 1 2 2 1 1",
"output": "6"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 2 1\n2 1 2 2 1 2 2 1 1 2",
"output": "5"
},
{
"input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2",
"... | 1,553,285,735 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | def remover(lista,n):
valor = 0
cont = 0
for i in range(n):
if valor == lista[i]:
cont+=1
else:
valor = lista[i]
cont = 1
if i==n-1 or lista[i+1]!=lista[i]:
if cont >= 3:
for j in range(cont):
... | Title: Balls Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more conti... | ```python
def remover(lista,n):
valor = 0
cont = 0
for i in range(n):
if valor == lista[i]:
cont+=1
else:
valor = lista[i]
cont = 1
if i==n-1 or lista[i+1]!=lista[i]:
if cont >= 3:
for j in range(cont):
... | 0 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,598,874,296 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 6,963,200 | n, m=map(int, input().split())
count=0
a=[]
for i in range(n):
st=input()
for j in range(m):
if st[j]=='*':
a+=[(i,j)] #Takes data where the '*' is present as tuple
for i in range(2):
if a[i][0]-a[i+1][0]==0:
break #Finds where there are consecutive '*', that is where theft will not occur
#y == R... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
n, m=map(int, input().split())
count=0
a=[]
for i in range(n):
st=input()
for j in range(m):
if st[j]=='*':
a+=[(i,j)] #Takes data where the '*' is present as tuple
for i in range(2):
if a[i][0]-a[i+1][0]==0:
break #Finds where there are consecutive '*', that is where theft will not occu... | 3 | |
959 | B | Mahmoud and Ehab and the message | PROGRAMMING | 1,200 | [
"dsu",
"greedy",
"implementation"
] | null | null | Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word ... | The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of l... | The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning. | [
"5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n",
"5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n"
] | [
"107",
"116"
] | In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | 1,000 | [
{
"input": "5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "107"
},
{
"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "116"
},
{
"input": "1 1 1\na\n1000000000\n1 1\na",
"output": ... | 1,654,170,477 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 22 | 732 | 45,158,400 |
import sys ;input = sys.stdin.readline
n,k,m=map(int,input().split())
st=list(input().strip().split())
ct=list(map(int,input().strip().split()))
dic={}
for i in range(k):
ki=list(map(int,input().strip().split()))
cost=10000000000
for j in range(1,len(ki)):
cost=min(cost,ct[ki[j]-1])
for j in ra... | Title: Mahmoud and Ehab and the message
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words... | ```python
import sys ;input = sys.stdin.readline
n,k,m=map(int,input().split())
st=list(input().strip().split())
ct=list(map(int,input().strip().split()))
dic={}
for i in range(k):
ki=list(map(int,input().strip().split()))
cost=10000000000
for j in range(1,len(ki)):
cost=min(cost,ct[ki[j]-1])
f... | 3 | |
808 | D | Array Division | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"implementation"
] | null | null | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | [
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | 0 | [
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4... | 1,638,711,707 | 1,607 | PyPy 3 | OK | TESTS | 115 | 358 | 23,961,600 | n = int(input())
A = list(map(int, input().split()))
from itertools import accumulate
def check(A):
s = sum(A)
if s%2 != 0:
return False
C = [0]+A
C = list(accumulate(C))
for i in range(n):
if C[i+1] == s//2:
return True
S = set()
for i in range(n):... | Title: Array Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to... | ```python
n = int(input())
A = list(map(int, input().split()))
from itertools import accumulate
def check(A):
s = sum(A)
if s%2 != 0:
return False
C = [0]+A
C = list(accumulate(C))
for i in range(n):
if C[i+1] == s//2:
return True
S = set()
for i in... | 3 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,691,453,501 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 34 | 92 | 0 | x = int(input())
z = []
w = []
z[0:] = map(int,input().split())
step = 0
o = 0
u = []
v = 0
q = list(z)
w = list(z)
for i in range(len(z)):
if min(z) == z[i]:
v = i
elif max(z) == z[i]:
u.append(i)
#break
c = x-u[0]
s = v
#print(v)
#print(u[0])
if (u[0] > v):
... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
x = int(input())
z = []
w = []
z[0:] = map(int,input().split())
step = 0
o = 0
u = []
v = 0
q = list(z)
w = list(z)
for i in range(len(z)):
if min(z) == z[i]:
v = i
elif max(z) == z[i]:
u.append(i)
#break
c = x-u[0]
s = v
#print(v)
#print(u[0])
if (u[0] ... | -1 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,698,618,063 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | s1=input()
s2=input()
ch1=s1.upper()
ch2=s2.upper()
i,s=0,0
if ch1==ch2:
print(0)
while i<min(len(ch2),len(ch1)) and s==0:
if ch1[i]<ch2[i]:
s=1
print(-1)
elif ch1[i]>ch2[i]:
s=1
print(1)
i+=1 | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
s1=input()
s2=input()
ch1=s1.upper()
ch2=s2.upper()
i,s=0,0
if ch1==ch2:
print(0)
while i<min(len(ch2),len(ch1)) and s==0:
if ch1[i]<ch2[i]:
s=1
print(-1)
elif ch1[i]>ch2[i]:
s=1
print(1)
i+=1
``` | 3.977 |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$... | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
... | 1,525,414,103 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 202 | 10,240,000 | def main():
input()
s = set()
for w in input().split():
l = [0] * 26
for c in w:
l[ord(c) - 97] = 1
s.add(tuple(l))
print(len(s))
if __name__ == '__main__':
main()
| Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the ... | ```python
def main():
input()
s = set()
for w in input().split():
l = [0] * 26
for c in w:
l[ord(c) - 97] = 1
s.add(tuple(l))
print(len(s))
if __name__ == '__main__':
main()
``` | 3 | |
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,612,812,713 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 819,200 | from string import ascii_lowercase
lc = 0
uc = 0
s = input()
for sym in s:
if sym in ascii_lowercase:
lc += 1
else:
uc += 1
if uc > lc:
print(s.upper())
else:
print(s.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
from string import ascii_lowercase
lc = 0
uc = 0
s = input()
for sym in s:
if sym in ascii_lowercase:
lc += 1
else:
uc += 1
if uc > lc:
print(s.upper())
else:
print(s.lower())
``` | 3.959974 |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,693,384,346 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 78 | 716,800 | a = input()
b = input()
x = len(a) - 1
y = len(b) - 1
n = 0
flg = 0
while x >= 0 and y >= 0:
if a[x] == b[y]:
x -= 1
y -= 1
n += 1
else:
break
print(len(a)+len(b)-(2*n)) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
a = input()
b = input()
x = len(a) - 1
y = len(b) - 1
n = 0
flg = 0
while x >= 0 and y >= 0:
if a[x] == b[y]:
x -= 1
y -= 1
n += 1
else:
break
print(len(a)+len(b)-(2*n))
``` | 3 | |
62 | A | A Student's Dream | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | A. A Student's Dream | 2 | 256 | Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess... | The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly. | Print YES or NO, that is, the answer to Petr Palych's question. | [
"5 1\n10 5\n",
"4 5\n3 3\n",
"1 2\n11 6\n"
] | [
"YES",
"YES",
"NO"
] | The boy and the girl don't really care who goes to the left. | 500 | [
{
"input": "5 1\n10 5",
"output": "YES"
},
{
"input": "4 5\n3 3",
"output": "YES"
},
{
"input": "1 2\n11 6",
"output": "NO"
},
{
"input": "1 1\n1 1",
"output": "YES"
},
{
"input": "2 2\n1 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "NO"... | 1,623,871,433 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 154 | 0 | al, ar = map(int, input().split())
bl, br = map(int, input().split())
if al-1<=br<=2*al+2 or ar-1<=bl<=2*ar+2:
print("YES")
else:
print("NO")
| Title: A Student's Dream
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming t... | ```python
al, ar = map(int, input().split())
bl, br = map(int, input().split())
if al-1<=br<=2*al+2 or ar-1<=bl<=2*ar+2:
print("YES")
else:
print("NO")
``` | 3.9615 |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,677,349,456 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 5,939,200 | n, t = list(map(int, input().split()))
books = list(map(int, input().split()))
res = 0
i=0
while i<n:
if books[i]<t:
Sum = books[i]
j=i+1
while j<n and Sum+books[j]<=t:
Sum += books[j]
j+=1
res = max(res, j-i)
i+=1
print(res)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n, t = list(map(int, input().split()))
books = list(map(int, input().split()))
res = 0
i=0
while i<n:
if books[i]<t:
Sum = books[i]
j=i+1
while j<n and Sum+books[j]<=t:
Sum += books[j]
j+=1
res = max(res, j-i)
i+=1
print(re... | 0 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,458,237,388 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
a = []
for i in range(n) :
a.append(input())
c = []
for i in range(len(a)-1,-1,-1) :
for q in range(i) :
if a[-q-1] == a[-i-1] :
break
else :
c.append(a[i])
for i in range(len(c)):
print(c[i])
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
n = int(input())
a = []
for i in range(n) :
a.append(input())
c = []
for i in range(len(a)-1,-1,-1) :
for q in range(i) :
if a[-q-1] == a[-i-1] :
break
else :
c.append(a[i])
for i in range(len(c)):
print(c[i])
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,690,550,640 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | # your code goes here
def main():
n = int(input())
a = list(map(int, input().split()))
even = {}
odd = {}
for i in range(n):
if a[i] % 2 == 0:
even[i + 1] = a[i]
else:
odd[i + 1] = a[i]
if len(even) == 1:
it = iter(even.items())
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
# your code goes here
def main():
n = int(input())
a = list(map(int, input().split()))
even = {}
odd = {}
for i in range(n):
if a[i] % 2 == 0:
even[i + 1] = a[i]
else:
odd[i + 1] = a[i]
if len(even) == 1:
it = iter(even.it... | 3.977 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,659,359,358 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s = input()
i = 0
s1 = ""
while i != len(s):
if s[i] == ".":
s1 += "0"
i += 1
elif s[i:i+2] == "-.":
s1 += "1"
i += 2
elif s[i:i+2] == "--":
s1 += "2"
i += 2
print(s1) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
s = input()
i = 0
s1 = ""
while i != len(s):
if s[i] == ".":
s1 += "0"
i += 1
elif s[i:i+2] == "-.":
s1 += "1"
i += 2
elif s[i:i+2] == "--":
s1 += "2"
i += 2
print(s1)
``` | 3.977 |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,591,519,579 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 716,800 | k = int(input())
if int((k//2)*'8')>10**18:
print(-1)
elif k%2==0:
print((k//2)*'8')
else:
print(((k//2)*'8')+'0') | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
k = int(input())
if int((k//2)*'8')>10**18:
print(-1)
elif k%2==0:
print((k//2)*'8')
else:
print(((k//2)*'8')+'0')
``` | 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,622,582,373 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | word1 = str(input())
lower = 0
upper = 0
for letter in word1:
if letter.islower():
lower += 1
if letter.isupper():
upper += 1
if lower >= upper:
print(word1.lower())
else:
print(word1.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word1 = str(input())
lower = 0
upper = 0
for letter in word1:
if letter.islower():
lower += 1
if letter.isupper():
upper += 1
if lower >= upper:
print(word1.lower())
else:
print(word1.upper())
``` | 3.9455 |
12 | C | Fruits | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | C. Fruits | 1 | 256 | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of A... | The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of t... | Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n"
] | [
"7 19\n",
"11 30\n"
] | none | 0 | [
{
"input": "5 3\n4 2 1 10 5\napple\norange\nmango",
"output": "7 19"
},
{
"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange",
"output": "11 30"
},
{
"input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl",
"output": "173 173"
},
{
"input"... | 1,676,807,809 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 0 | tag_numb,len_of_dic=map(int,input().split())
tag_array=[int(x) for x in input().split()]
tag_array.sort()
temp_dic={}
arr=[]
temp_counter=0
for _ in range(len_of_dic):
word=input()
if word not in temp_dic:
temp_dic[word]=temp_counter
temp_counter +=1
try:
arr[temp_dic[wor... | Title: Fruits
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some ... | ```python
tag_numb,len_of_dic=map(int,input().split())
tag_array=[int(x) for x in input().split()]
tag_array.sort()
temp_dic={}
arr=[]
temp_counter=0
for _ in range(len_of_dic):
word=input()
if word not in temp_dic:
temp_dic[word]=temp_counter
temp_counter +=1
try:
arr[te... | 3.977 |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,665,493,573 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | # Алгоритм нахождения НОД делением
# Большее число делим на меньшее.
# Если делится без остатка, то меньшее число и есть НОД (следует выйти из цикла).
# Если есть остаток, то большее число заменяем на остаток от деления.
# Переходим к пункту 1.
a1, a2 = map(int, input().split())
if a1 < a2:
a1, a2 = a2, a1... | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
# Алгоритм нахождения НОД делением
# Большее число делим на меньшее.
# Если делится без остатка, то меньшее число и есть НОД (следует выйти из цикла).
# Если есть остаток, то большее число заменяем на остаток от деления.
# Переходим к пункту 1.
a1, a2 = map(int, input().split())
if a1 < a2:
a1, a... | 0 | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,665,308,036 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 374 | 4,915,200 | def lex(f,s):
for i in range(len(f)):
if(f[i]>s[i]):
return "first";
if(s[i]>f[i]):
return "second"
if(len(f)>len(s)):
return "first"
if(len(s)>len(f)):
return 'second'
return -1
f = []
s = []
s1 = 0
s2 = 0
n = int(input())
last... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
def lex(f,s):
for i in range(len(f)):
if(f[i]>s[i]):
return "first";
if(s[i]>f[i]):
return "second"
if(len(f)>len(s)):
return "first"
if(len(s)>len(f)):
return 'second'
return -1
f = []
s = []
s1 = 0
s2 = 0
n = int(inpu... | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,674,549,958 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n = int(input())
m = list(map(int, input().split()))
res = 0
k = 0
for i in range(3):
if m[i] % 2 == 0:
k += 1
if k > 1:
for item in m:
if item % 2 != 0:
res = item
else:
for item in m:
if item % 2 == 0:
res = item
print(m.index(res) + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
m = list(map(int, input().split()))
res = 0
k = 0
for i in range(3):
if m[i] % 2 == 0:
k += 1
if k > 1:
for item in m:
if item % 2 != 0:
res = item
else:
for item in m:
if item % 2 == 0:
res = item
print(m.index(res) + 1)
``` | 3.977 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,621,984,985 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 49 | 218 | 0 | trails = int(input())
x1 = 0
z1 = 0
y1 = 0
i = 0
while i < trails:
x, y, z = input().split()
x1 = x1 - int(x)
z1 = z1 - int(z)
y1 = y1 - int(y)
i = i + 1
if x1 + y1 + x1 ==0 :
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
trails = int(input())
x1 = 0
z1 = 0
y1 = 0
i = 0
while i < trails:
x, y, z = input().split()
x1 = x1 - int(x)
z1 = z1 - int(z)
y1 = y1 - int(y)
i = i + 1
if x1 + y1 + x1 ==0 :
print('YES')
else:
print('NO')
``` | 0 |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1... | 1,613,899,233 | 2,147,483,647 | PyPy 3 | OK | TESTS | 92 | 202 | 10,752,000 | n=int(input())
a=list(map(int,input().split()))
l = [1]*n
r = [1]*n
for i in range(1,n):
if a[i-1]<a[i]:l[i]+=l[i-1]
for i in range(n-2,0,-1):
if a[i+1]>a[i]:r[i]+=r[i+1]
ans = max(max(l),max(r))
if ans<n:
ans+=1
for i in range(1,n-1):
if a[i-1]+1<a[i+1]:
ans= max(ans,l[i-1]+r[i+1]+1)
print(ans... | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the... | ```python
n=int(input())
a=list(map(int,input().split()))
l = [1]*n
r = [1]*n
for i in range(1,n):
if a[i-1]<a[i]:l[i]+=l[i-1]
for i in range(n-2,0,-1):
if a[i+1]>a[i]:r[i]+=r[i+1]
ans = max(max(l),max(r))
if ans<n:
ans+=1
for i in range(1,n-1):
if a[i-1]+1<a[i+1]:
ans= max(ans,l[i-1]+r[i+1]+1)... | 3 | |
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats... | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integer — the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisl... | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d... | 1,477,279,609 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 78 | 0 | s=input()
a=int(s[:-1])-1
print(a//4*16+(a%2)*7+' fedabc'.index(s[-1])) | Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' ... | ```python
s=input()
a=int(s[:-1])-1
print(a//4*16+(a%2)*7+' fedabc'.index(s[-1]))
``` | 3 | |
900 | D | Unusual Sequences | PROGRAMMING | 2,000 | [
"bitmasks",
"combinatorics",
"dp",
"math",
"number theory"
] | null | null | Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answer modulo 109<=+<=7.
*gcd* here means the [greatest common divisor](https://en.wikipedia.org/wiki/Great... | The only line contains two positive integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=109). | Print the number of such sequences modulo 109<=+<=7. | [
"3 9\n",
"5 8\n"
] | [
"3\n",
"0\n"
] | There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).
There are no suitable sequences in the second test. | 2,000 | [
{
"input": "3 9",
"output": "3"
},
{
"input": "5 8",
"output": "0"
},
{
"input": "2 12",
"output": "27"
},
{
"input": "1 8",
"output": "120"
},
{
"input": "1 9",
"output": "252"
},
{
"input": "1000000000 1000000000",
"output": "1"
},
{
"inp... | 1,537,895,391 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 |
# coding: utf-8
# In[26]:
def gcd(n1, n2):
if n2 == 0:
return int(n1)
else:
return gcd(n2, n1%n2)
def unusualSeq(n1, n2):
result = gcd(n1,n2)
if result == 1:
print(0)
else:
print(result)
a = input()
b = a.split()
unusualSeq(int(b[0]),int(b[1]))
| Title: Unusual Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answe... | ```python
# coding: utf-8
# In[26]:
def gcd(n1, n2):
if n2 == 0:
return int(n1)
else:
return gcd(n2, n1%n2)
def unusualSeq(n1, n2):
result = gcd(n1,n2)
if result == 1:
print(0)
else:
print(result)
a = input()
b = a.split()
unusualSeq(int(b[0]),int(b[1]))
... | 0 | |
812 | B | Sagheer, the Hausmeister | PROGRAMMING | 1,600 | [
"bitmasks",
"brute force",
"dp"
] | null | null | Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of *n* floors with stairs at the left and the right sid... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively.
The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then ... | Print a single integer — the minimum total time needed to turn off all the lights. | [
"2 2\n0010\n0100\n",
"3 4\n001000\n000010\n000010\n",
"4 3\n01110\n01110\n01110\n01110\n"
] | [
"5\n",
"12\n",
"18\n"
] | In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.
In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th... | 1,000 | [
{
"input": "2 2\n0010\n0100",
"output": "5"
},
{
"input": "3 4\n001000\n000010\n000010",
"output": "12"
},
{
"input": "4 3\n01110\n01110\n01110\n01110",
"output": "18"
},
{
"input": "3 2\n0000\n0100\n0100",
"output": "4"
},
{
"input": "1 89\n0000000000000000000000... | 1,698,481,015 | 2,147,483,647 | Python 3 | OK | TESTS | 72 | 46 | 0 | n_and_m = input()
n, m = n_and_m.split() #n - кол-во целых чисел, k - кол-во элем. заданной посл-ти меньше либо равны x(результат программы)
n = int(n)
m = int(m)
p = [input() for y in range(n)][::-1]
l = r = d = 0
i = j = 0
for y, t in enumerate(p):
if '1' in t:
l, r = min(l - i, r - j) + 2 * ... | Title: Sagheer, the Hausmeister
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goe... | ```python
n_and_m = input()
n, m = n_and_m.split() #n - кол-во целых чисел, k - кол-во элем. заданной посл-ти меньше либо равны x(результат программы)
n = int(n)
m = int(m)
p = [input() for y in range(n)][::-1]
l = r = d = 0
i = j = 0
for y, t in enumerate(p):
if '1' in t:
l, r = min(l - i, r -... | 3 | |
938 | C | Constructing Tests | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"constructive algorithms"
] | null | null | Let's denote a *m*-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size *m*<=×<=*m* of this matrix contains at least one zero.
Consider the following problem:
You are given two integers *n* and *m*. You have to construct an *m*-free square matrix of size *... | The first line contains one integer *t* (1<=≤<=*t*<=≤<=100) — the number of tests you have to construct.
Then *t* lines follow, *i*-th line containing one integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Note that in hacks you have to set *t*<==<=1. | For each test you have to construct, output two positive numbers *n**i* and *m**i* (1<=≤<=*m**i*<=≤<=*n**i*<=≤<=109) such that the maximum number of 1's in a *m**i*-free *n**i*<=×<=*n**i* matrix is exactly *x**i*. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test... | [
"3\n21\n0\n1\n"
] | [
"5 2\n1 1\n-1\n"
] | none | 0 | [
{
"input": "3\n21\n0\n1",
"output": "5 2\n1 1\n-1"
},
{
"input": "1\n420441920",
"output": "-1"
},
{
"input": "1\n4",
"output": "-1"
},
{
"input": "1\n297540",
"output": "546 22"
},
{
"input": "1\n9",
"output": "-1"
},
{
"input": "1\n144",
"output"... | 1,520,502,958 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 5,632,000 |
def find(x):
if x == 0:
return(1,1)
for c_1 in range(2, max(int(x/2), 2)):
if not (x % c_1):
if Try(x, c_1, int(x / c_1)):
c_2 = int(x / c_1)
n = int((c_1 + c_2) / 2)
b = int(abs(c_1 - c_2) / 2)
if b == 0:
continue
m = int(n / b)
return [n,m]
else:
continue
retu... | Title: Constructing Tests
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote a *m*-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size *m*<=×<=*m* of this matrix contains at least one zero.
Consider the following pro... | ```python
def find(x):
if x == 0:
return(1,1)
for c_1 in range(2, max(int(x/2), 2)):
if not (x % c_1):
if Try(x, c_1, int(x / c_1)):
c_2 = int(x / c_1)
n = int((c_1 + c_2) / 2)
b = int(abs(c_1 - c_2) / 2)
if b == 0:
continue
m = int(n / b)
return [n,m]
else:
cont... | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,677,077,190 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 78 | 5,324,800 | n = int(input())
x = list(map(int, input().split()))
z = x.count(-1)
y = 0
sum = 0
for i in range(0, n):
if x[i] > 0:
sum += x[i]
y += x[i]
elif x[i] < 0 and sum > 0:
sum -= 1
print(abs((y-sum)-z))
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n = int(input())
x = list(map(int, input().split()))
z = x.count(-1)
y = 0
sum = 0
for i in range(0, n):
if x[i] > 0:
sum += x[i]
y += x[i]
elif x[i] < 0 and sum > 0:
sum -= 1
print(abs((y-sum)-z))
``` | 3 | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,623,571,395 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,150,400 | n = int(input())
c = list(map(int,input().split()))
c.sort()
ans_left = 0
ans_right = 0
l = 0
r = n-1
while l <= r:
mid = l + (r-l)//2
if c[mid]*2 >= c[-1]:
ans_left = mid
r = mid-1
else:
l = mid+1
l = 0
r = n-1
while l <= r:
mid = l + (r-l)//2
if c[mid] <= ... | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
n = int(input())
c = list(map(int,input().split()))
c.sort()
ans_left = 0
ans_right = 0
l = 0
r = n-1
while l <= r:
mid = l + (r-l)//2
if c[mid]*2 >= c[-1]:
ans_left = mid
r = mid-1
else:
l = mid+1
l = 0
r = n-1
while l <= r:
mid = l + (r-l)//2
if ... | -1 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,689,500,953 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 921,600 | columns = input().split(" ")
squares=list(input())
calories =0
for square in squares :
calories+= int(columns[int(square) - 1])
print(calories) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
columns = input().split(" ")
squares=list(input())
calories =0
for square in squares :
calories+= int(columns[int(square) - 1])
print(calories)
``` | 3 | |
145 | A | Lucky Conversion | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 500 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,551,682,560 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 310 | 409,600 | a = input()
b = input()
index = 0
wrong = {'4': 0,
'7': 0}
while index < len(a):
if a[index] != b[index]:
wrong[a[index]] += 1
index += 1
# c = abs(wrong['4'] - wrong['7'])
print(max(wrong['4'], wrong['7']))
| Title: Lucky Conversion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are no... | ```python
a = input()
b = input()
index = 0
wrong = {'4': 0,
'7': 0}
while index < len(a):
if a[index] != b[index]:
wrong[a[index]] += 1
index += 1
# c = abs(wrong['4'] - wrong['7'])
print(max(wrong['4'], wrong['7']))
``` | 3 | |
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,633,345,102 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 6,758,400 | # -*- coding: utf-8 -*-
"""
Created on Mon Oct 4 18:41:02 2021
@author: Asus
"""
s=input()
upper=len([letter for letter in s if letter.isupper()])
lower=len(s)-int(upper)
print (s.upper() if upper>lower else s.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
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 4 18:41:02 2021
@author: Asus
"""
s=input()
upper=len([letter for letter in s if letter.isupper()])
lower=len(s)-int(upper)
print (s.upper() if upper>lower else s.lower())
``` | 3.956411 |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,694,786,904 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | a,b = map(int,input().split())
while b != 0:
b -= 1
if a % 10 == 0:
a = a // 10
else:
a -= 1
print(a) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
a,b = map(int,input().split())
while b != 0:
b -= 1
if a % 10 == 0:
a = a // 10
else:
a -= 1
print(a)
``` | 3 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,631,277,928 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 77 | 6,963,200 | a,b=input().split( )
a,b=int(a)%5*[int(a)//5+1]+-int(a)%5*[int(a)//5]+5*[int(a)//5],int(b)%5*[int(b)//5+1]+-int(b)%5*[int(b)//5]+5*[int(b)//5]
print(a[0]*b[3]+a[1]*b[2]+a[2]*b[1]+a[3]*b[0]+a[4]*b[4])
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
a,b=input().split( )
a,b=int(a)%5*[int(a)//5+1]+-int(a)%5*[int(a)//5]+5*[int(a)//5],int(b)%5*[int(b)//5+1]+-int(b)%5*[int(b)//5]+5*[int(b)//5]
print(a[0]*b[3]+a[1]*b[2]+a[2]*b[1]+a[3]*b[0]+a[4]*b[4])
``` | 3 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,665,754,426 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
l1 = list(map(int,input().split()))
xl = []
for i in l1:
if i in xl:
continue
else:
xl.append(i)
for j in xl:
if l1.count(j) == 1:
print(j,0)
else:
k = l1.index(j) + 1
while k < n:
if l1[k] == j:
break
... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
n = int(input())
l1 = list(map(int,input().split()))
xl = []
for i in l1:
if i in xl:
continue
else:
xl.append(i)
for j in xl:
if l1.count(j) == 1:
print(j,0)
else:
k = l1.index(j) + 1
while k < n:
if l1[k] == j:
... | 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,458,516,935 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 62 | 4,812,800 | a,b,c=map(int,input().split())
while b:b,a=a%b,b
print('NO'if c%a else'YES')
| 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
a,b,c=map(int,input().split())
while b:b,a=a%b,b
print('NO'if c%a else'YES')
``` | 0 | |
802 | M | April Fools' Problem (easy) | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers *n*, *k* and a sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output... | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2200). The second line contains *n* space-separated integers *a*1,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104). | Output one number. | [
"8 5\n1 1 1 1 1 1 1 1\n",
"10 3\n16 8 2 4 512 256 32 128 64 1\n",
"5 1\n20 10 50 30 46\n",
"6 6\n6 6 6 6 6 6\n",
"1 1\n100\n"
] | [
"5",
"7",
"10",
"36",
"100"
] | none | 0 | [
{
"input": "8 5\n1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "10 3\n16 8 2 4 512 256 32 128 64 1",
"output": "7"
},
{
"input": "5 1\n20 10 50 30 46",
"output": "10"
},
{
"input": "6 6\n6 6 6 6 6 6",
"output": "36"
},
{
"input": "1 1\n100",
"output": "100"
... | 1,694,382,280 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 14 | 62 | 1,536,000 | n, k = map(int, input().split())
b = list(map(int, input().split()))
c = sorted(b)
print(sum(c[:k]))
| Title: April Fools' Problem (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers *n*, *k* and a sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. They also came up with a beautif... | ```python
n, k = map(int, input().split())
b = list(map(int, input().split()))
c = sorted(b)
print(sum(c[:k]))
``` | 3 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,688,980,017 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 46 | 102,400 | s = input()
p = s.count('AB')
q = s.count('BA')
r = s.count('ABA')
t = s.count('BAB')
n = p+q-r-t
if n >= 2 and p > 0 and q > 0:
print('YES')
else:
print('NO')
| Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
s = input()
p = s.count('AB')
q = s.count('BA')
r = s.count('ABA')
t = s.count('BAB')
n = p+q-r-t
if n >= 2 and p > 0 and q > 0:
print('YES')
else:
print('NO')
``` | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,698,901,905 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 154 | 0 | n=input()
str=n[0].upper()+n[1:]
print(str)
#kjkjhv
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
n=input()
str=n[0].upper()+n[1:]
print(str)
#kjkjhv
``` | 3 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,628,349,604 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 7,065,600 | import random
num,key = input().split()
word = []
word2 = ''
for x in range(1,int(num)+1):
if x <= int(key):
word.append(chr(random.randint(97,122)))
elif x > int(key):
word += word[random.randint(0,int(key)-1)]
for x in word:
word2 += x
print(word2)... | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
import random
num,key = input().split()
word = []
word2 = ''
for x in range(1,int(num)+1):
if x <= int(key):
word.append(chr(random.randint(97,122)))
elif x > int(key):
word += word[random.randint(0,int(key)-1)]
for x in word:
word2 += x
pr... | 0 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,689,429,910 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | from collections import defaultdict
strings = input()
n = len(strings)
dictt = defaultdict(int)
i = 0
j = 0
while i < n - 2:
if strings[i:i+2] == "AB":
j = i + 2
break;
else:
i += 1
flag = False
m = n
while m >= j:
if reversed(strings[m-2:m]) == "BA":
fla... | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
from collections import defaultdict
strings = input()
n = len(strings)
dictt = defaultdict(int)
i = 0
j = 0
while i < n - 2:
if strings[i:i+2] == "AB":
j = i + 2
break;
else:
i += 1
flag = False
m = n
while m >= j:
if reversed(strings[m-2:m]) == "BA":
... | 0 | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,621,861,235 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 218 | 1,331,200 | x=int(input())
if x==0:
print(0)
exit()
k=1
x=abs(x)
while (k*(k+1))//2<x:
k+=1
if x==(k*(k+1))//2:
print(k)
else:
res=k*(k+1)//2-x
if res%2==0:
print(k)
else:
k+=1
for i in range(1,k+1):
if k*(k+1)//2-i*2==x:
print(k)
break
else:
print(k+1) | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
x=int(input())
if x==0:
print(0)
exit()
k=1
x=abs(x)
while (k*(k+1))//2<x:
k+=1
if x==(k*(k+1))//2:
print(k)
else:
res=k*(k+1)//2-x
if res%2==0:
print(k)
else:
k+=1
for i in range(1,k+1):
if k*(k+1)//2-i*2==x:
print(k)
break
else:
... | 3.881082 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,692,962,790 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 0 | x= input().split(" ")
width= int(x[1])
area= int(x[2])
ans= 0
while width>0:
length= int(x[0])
while length>0:
ans+=1
length-=area
width-= area
print(ans) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
x= input().split(" ")
width= int(x[1])
area= int(x[2])
ans= 0
while width>0:
length= int(x[0])
while length>0:
ans+=1
length-=area
width-= area
print(ans)
``` | 0 |
817 | D | Imbalanced Array | PROGRAMMING | 1,900 | [
"data structures",
"divide and conquer",
"dsu",
"sortings"
] | null | null | You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. | Print one integer — the imbalance value of *a*. | [
"3\n1 4 1\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3\n1 4 1",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10\n1 4 4 3 5 2 4 2 4 5",
"output": "123"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "245"
},
{
"input": "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5... | 1,498,303,582 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | from itertools import combinations
num_elements = int(input().split()[0])
elements = [int(x) for x in input().split()]
indices = [elements[i[0]:i[1]+1] for i in combinations(range(num_elements), 2)]
the_sum = 0
for i in indices:
list(i).sort()
the_sum += i[-1]-i[0]
print (the_sum) | Title: Imbalanced Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array ... | ```python
from itertools import combinations
num_elements = int(input().split()[0])
elements = [int(x) for x in input().split()]
indices = [elements[i[0]:i[1]+1] for i in combinations(range(num_elements), 2)]
the_sum = 0
for i in indices:
list(i).sort()
the_sum += i[-1]-i[0]
print (the_sum... | 0 | |
291 | A | Spyke Talks | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is t... | Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. | [
"6\n0 1 7 1 7 10\n",
"3\n1 1 1\n",
"1\n0\n"
] | [
"2\n",
"-1\n",
"0\n"
] | In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | 500 | [
{
"input": "6\n0 1 7 1 7 10",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n2 2 1 1 3",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n4 21 3 21 21 1 1 2 2 3",
"ou... | 1,674,733,846 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 154 | 0 | q = int(input())
w = list(map(int, input().split()))
w.sort()
e = -3
r = 0
for i in range(q - 1):
if w[i] != e:
e = w[i]
if w[i] == w[i + 1]:
r += 1
else:
if w[i] == w[i + 1]:
print(-1)
break
else:
print(r) | Title: Spyke Talks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each othe... | ```python
q = int(input())
w = list(map(int, input().split()))
w.sort()
e = -3
r = 0
for i in range(q - 1):
if w[i] != e:
e = w[i]
if w[i] == w[i + 1]:
r += 1
else:
if w[i] == w[i + 1]:
print(-1)
break
else:
print(r)
``` | 0 | |
990 | C | Bracket Sequences Concatenation Problem | PROGRAMMING | 1,500 | [
"implementation"
] | null | null | A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg... | The first line contains one integer $n \, (1 \le n \le 3 \cdot 10^5)$ — the number of bracket sequences. The following $n$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $3 \cdot 10^5$. | In the single line print a single integer — the number of pairs $i, j \, (1 \le i, j \le n)$ such that the bracket sequence $s_i + s_j$ is a regular bracket sequence. | [
"3\n)\n()\n(\n",
"2\n()\n()\n"
] | [
"2\n",
"4\n"
] | In the first example, suitable pairs are $(3, 1)$ and $(2, 2)$.
In the second example, any pair is suitable, namely $(1, 1), (1, 2), (2, 1), (2, 2)$. | 0 | [
{
"input": "3\n)\n()\n(",
"output": "2"
},
{
"input": "2\n()\n()",
"output": "4"
},
{
"input": "7\n()(\n)\n)(\n())\n(((\n()()()\n()",
"output": "6"
},
{
"input": "6\n(\n((\n(((\n))))\n)))))\n))))))",
"output": "0"
},
{
"input": "9\n(()\n((())\n(\n)\n(()()(()())))\... | 1,528,628,362 | 3,262 | Python 3 | WRONG_ANSWER | TESTS | 4 | 202 | 4,505,600 | n=int(input())
openw=[0 for i in range(300001)]
closew=[0 for j in range(300001)]
reg=0
for i in range(n):
r=input()
c=0
o=0
e=1
for y in r:
if y==")":
c=c+1
else:
o=o+1
if c>o:
e=2
if (o==c and e==1):
reg=reg+1
elif (o>c and e==1):
openw[o-c]=openw[o-c]+1
elif (o<c):
c... | Title: Bracket Sequences Concatenation Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting ... | ```python
n=int(input())
openw=[0 for i in range(300001)]
closew=[0 for j in range(300001)]
reg=0
for i in range(n):
r=input()
c=0
o=0
e=1
for y in r:
if y==")":
c=c+1
else:
o=o+1
if c>o:
e=2
if (o==c and e==1):
reg=reg+1
elif (o>c and e==1):
openw[o-c]=openw[o-c]+1
elif (... | 0 | |
408 | B | Garland | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie... | The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the ... | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | [
"aaabbac\naabbccac\n",
"a\nz\n"
] | [
"6\n",
"-1"
] | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot mak... | 1,000 | [
{
"input": "aaabbac\naabbccac",
"output": "6"
},
{
"input": "a\nz",
"output": "-1"
},
{
"input": "r\nr",
"output": "1"
},
{
"input": "stnsdn\nndnndsn",
"output": "4"
},
{
"input": "yqfqfp\ntttwtqq",
"output": "-1"
},
{
"input": "zzbbrrtrtzr\ntbbtrrrzr"... | 1,558,537,526 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 124 | 409,600 | # ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
from collections import Counter as C
if __name__ == "__main__":
s = str(input())
t = str(in... | Title: Garland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.... | ```python
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
from collections import Counter as C
if __name__ == "__main__":
s = str(input())
... | 3 | |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,602,307,617 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 186 | 0 | n,mod=map(int,input().split())
sum=0
for i in range(1,n+1):
s=str(i);
t=s[::-1]
sum+=int(s+t)
sum%=mod
print(sum) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thi... | ```python
n,mod=map(int,input().split())
sum=0
for i in range(1,n+1):
s=str(i);
t=s[::-1]
sum+=int(s+t)
sum%=mod
print(sum)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,648,752,850 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 0 | import math
# theater
n, m, a = input().split()
output = 0
flag1 = True
flag2 = True
if int(n) <= int(a):
flag1 = False
if int(m) <= int(a):
flag2 = False
if flag1:
if int(n) % int(a) != 0:
output += math.ceil(int(n) / int(a))
else:
output += int(n) / int(a)
if flag2:
... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
# theater
n, m, a = input().split()
output = 0
flag1 = True
flag2 = True
if int(n) <= int(a):
flag1 = False
if int(m) <= int(a):
flag2 = False
if flag1:
if int(n) % int(a) != 0:
output += math.ceil(int(n) / int(a))
else:
output += int(n) / int(a)
i... | 0 |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,481,717,130 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 154 | 0 | n=int(input())
arr=[int(i) for i in input().split(" ")]
flag=0
set_A=set(arr)
for x in set_A:
if arr.count(x)>(int((n+1)/2)):
flag=1
break
if(flag==0):
print('YES')
else:
print('NO')
| Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
n=int(input())
arr=[int(i) for i in input().split(" ")]
flag=0
set_A=set(arr)
for x in set_A:
if arr.count(x)>(int((n+1)/2)):
flag=1
break
if(flag==0):
print('YES')
else:
print('NO')
``` | 3 | |
285 | C | Building Permutation | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"2\n3 0\n",
"3\n-1 -1 2\n"
] | [
"2\n",
"6\n"
] | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | 1,500 | [
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100... | 1,647,085,848 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 389 | 30,105,600 | n=int(input())
a_lst=list(range(1,n+1))
lst=sorted(map(int,input().split()))
steps=0
for i in range(n):
steps+=abs(i+1-lst[i])
print(steps)
| Title: Building 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, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *... | ```python
n=int(input())
a_lst=list(range(1,n+1))
lst=sorted(map(int,input().split()))
steps=0
for i in range(n):
steps+=abs(i+1-lst[i])
print(steps)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,488,795,321 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 11 | 4,757 | 268,390,400 | n = int(input())
x = list(map(int, input().split()))
v = list(map(int, input().split()))
print(max([
abs(x[i1] - x[i2]) / (v[i1] + v[i2])
for i1 in range(n)
for i2 in range(n)
])) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
n = int(input())
x = list(map(int, input().split()))
v = list(map(int, input().split()))
print(max([
abs(x[i1] - x[i2]) / (v[i1] + v[i2])
for i1 in range(n)
for i2 in range(n)
]))
``` | 0 | |
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,551,370,625 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 93 | 0 | x,y=map(int,input().split())
if abs(x-y)>=2:
print('NO')
else:
print('YES') | 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
x,y=map(int,input().split())
if abs(x-y)>=2:
print('NO')
else:
print('YES')
``` | 0 | |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,565,694,446 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | t = input()
num = int(t[0:t.index('of') - 1])
date = t[t.index('of') + 3:]
if date == 'week':
if num <= 3:
print("53")
else:
print("52")
if date == 'month':
if num <= 29:
print("12")
elif num == 30:
print("11")
else:
print("7") | Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
t = input()
num = int(t[0:t.index('of') - 1])
date = t[t.index('of') + 3:]
if date == 'week':
if num <= 3:
print("53")
else:
print("52")
if date == 'month':
if num <= 29:
print("12")
elif num == 30:
print("11")
else:
print("7")
``` | 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,619,806,202 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 307,200 | p=input("")
sum=0
q=0
for i in p:
num=ord(i)-96
if q==0:
if (num-1)>abs(27-num):
sum+=(27-num)
else:
sum+=(num-1)
q+=1
else:
pnum=ord(p[q-1])-96
if num>pnum:
num,pnum=pnum,num
if abs(pnum-num)>abs(26-pnu... | 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
p=input("")
sum=0
q=0
for i in p:
num=ord(i)-96
if q==0:
if (num-1)>abs(27-num):
sum+=(27-num)
else:
sum+=(num-1)
q+=1
else:
pnum=ord(p[q-1])-96
if num>pnum:
num,pnum=pnum,num
if abs(pnum-num)>... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,570,590,753 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | #69A-Young Physicist
n=int(input())
n1=0
n2=0
n3=0
for i in range(0,n):
str1=input()
list1=str1.split(' ')
n1+=int(list1[0])
n2+=int(list1[1])
n3+=int(list1[2])
if n1 == 0 and n2 == 0 and n3 == 0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
#69A-Young Physicist
n=int(input())
n1=0
n2=0
n3=0
for i in range(0,n):
str1=input()
list1=str1.split(' ')
n1+=int(list1[0])
n2+=int(list1[1])
n3+=int(list1[2])
if n1 == 0 and n2 == 0 and n3 == 0:
print('YES')
else:
print('NO')
``` | 3.938 |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,695,825,304 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | a, b, c, d = map(int, input().split())
e = 10**(-6)
b1, q = a/b, (((d-c)/d)*((b-a)/b))
qn, m = q, b1/(q-1)
r1, r2 = m*(q-1), m*(q*q-1)
qn = q**3
while abs(r2-r1) >= e:
r1 = r2
r2 = m*(qn-1)
qn *= q
print(r2) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a, b, c, d = map(int, input().split())
e = 10**(-6)
b1, q = a/b, (((d-c)/d)*((b-a)/b))
qn, m = q, b1/(q-1)
r1, r2 = m*(q-1), m*(q*q-1)
qn = q**3
while abs(r2-r1) >= e:
r1 = r2
r2 = m*(qn-1)
qn *= q
print(r2)
``` | 0 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,669,378,397 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 202 | 0 | input()
nub = [int(i) for i in input().split(" ")]
teams = min(nub.count(1), nub.count(2), nub.count(3))
print(teams)
for x in range(teams):
index = nub.index(1)
nub[index] = 0
print(index+1, end = " ")
index = nub.index(2)
nub[index] = 0
print(index+1, end = " ")
index = nub.index(3)
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
input()
nub = [int(i) for i in input().split(" ")]
teams = min(nub.count(1), nub.count(2), nub.count(3))
print(teams)
for x in range(teams):
index = nub.index(1)
nub[index] = 0
print(index+1, end = " ")
index = nub.index(2)
nub[index] = 0
print(index+1, end = " ")
index = nub.i... | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,550,040,596 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 109 | 0 | def curFloor(arr):
res = 0
for i in range(0, len(arr), 2):
if arr[i]==1 or arr[i+1]==1: res += 1
return res
n, m = [int(x) for x in input().split()]
ans = 0
for i in range(n):
arr = [int(x) for x in input().split()]
ans += curFloor(arr)
print(ans) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
def curFloor(arr):
res = 0
for i in range(0, len(arr), 2):
if arr[i]==1 or arr[i+1]==1: res += 1
return res
n, m = [int(x) for x in input().split()]
ans = 0
for i in range(n):
arr = [int(x) for x in input().split()]
ans += curFloor(arr)
print(ans)
``` | 3 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,618,751,778 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n,k=map(int,input().split())
status=0
if 1<=n and n<=pow(10,18) and k<=n and 1<=k and k<=pow(10,18):
if n%2==0 and k%2==0 and n!=k:
status=1
else:
status=0
if status==0:
print('YES')
else:
print('NO') | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
n,k=map(int,input().split())
status=0
if 1<=n and n<=pow(10,18) and k<=n and 1<=k and k<=pow(10,18):
if n%2==0 and k%2==0 and n!=k:
status=1
else:
status=0
if status==0:
print('YES')
else:
print('NO')
``` | 0 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,541,589,598 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 108 | 0 | def findAll(num):
a=1
b=num-1
res=[]
while a!=b:
res.append((a,b))
a+=1
b-=1
return res
def isPrime(num):
a=num-1
while a!=1:
if num%a!=0:
a-=1
else:
return False
return True
num=int(input())
if num==2:
print('1 1')
if... | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
def findAll(num):
a=1
b=num-1
res=[]
while a!=b:
res.append((a,b))
a+=1
b-=1
return res
def isPrime(num):
a=num-1
while a!=1:
if num%a!=0:
a-=1
else:
return False
return True
num=int(input())
if num==2:
print... | -1 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,519,487,308 | 808 | Python 3 | OK | TESTS | 73 | 78 | 5,632,000 | import sys
a = input()
n = int(input())
s = ''
for i in a:
if (i == 'O') or (i == 'o'):
s = s + '0'
else:
if (i == 'l') or (i == 'I') or (i == 'L') or (i == 'i'):
s = s + '1'
else:
s = s + i.lower()
for j in range(n):
a = input()
str = ''
... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
import sys
a = input()
n = int(input())
s = ''
for i in a:
if (i == 'O') or (i == 'o'):
s = s + '0'
else:
if (i == 'l') or (i == 'I') or (i == 'L') or (i == 'i'):
s = s + '1'
else:
s = s + i.lower()
for j in range(n):
a = input()
st... | 3 | |
284 | B | Cows and Poker Game | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be... | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". | The first line should contain a single integer denoting the number of players that can currently show their hands. | [
"6\nAFFAAA\n",
"3\nAFI\n"
] | [
"4\n",
"1\n"
] | In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | 1,000 | [
{
"input": "6\nAFFAAA",
"output": "4"
},
{
"input": "3\nAFI",
"output": "1"
},
{
"input": "3\nFFF",
"output": "0"
},
{
"input": "3\nFIF",
"output": "1"
},
{
"input": "3\nAAA",
"output": "3"
},
{
"input": "3\nIII",
"output": "0"
},
{
"input"... | 1,622,864,965 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 248 | 512,000 | def main():
n = int(input())
cows = input()
i_cont = cows.count("I")
if i_cont == 0:
cont = 0
for i in range(n-1, -1, -1):
if cows[i] == 'A':
cont += 1
print(cont)
elif i_cont == 1:
print(1)
else:
print(0)
main(... | Title: Cows and Poker Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player who... | ```python
def main():
n = int(input())
cows = input()
i_cont = cows.count("I")
if i_cont == 0:
cont = 0
for i in range(n-1, -1, -1):
if cows[i] == 'A':
cont += 1
print(cont)
elif i_cont == 1:
print(1)
else:
prin... | 3 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,588,712,220 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 |
def pfactor(num):
res = []
tmpnum = num
for i in range(2, num + 1):
while tmpnum % i == 0:
tmpnum /= i
res.append(i)
return res
n = int(input())
arr = [int(x) for x in list(input())]
arr2 = []
for num in arr:
if num >= 2:
for item in pfactor(n... | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
def pfactor(num):
res = []
tmpnum = num
for i in range(2, num + 1):
while tmpnum % i == 0:
tmpnum /= i
res.append(i)
return res
n = int(input())
arr = [int(x) for x in list(input())]
arr2 = []
for num in arr:
if num >= 2:
for item in... | 0 | |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,699,236,765 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 389 | 12,697,600 | import sys
# region fastio
input = lambda: sys.stdin.readline().rstrip()
sint = lambda: int(input())
mint = lambda: map(int, input().split())
ints = lambda: list(map(int, input().split()))
# endregion fastio
# MOD = 998_244_353
# MOD = 10 ** 9 + 7
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
# DIR8 =... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
import sys
# region fastio
input = lambda: sys.stdin.readline().rstrip()
sint = lambda: int(input())
mint = lambda: map(int, input().split())
ints = lambda: list(map(int, input().split()))
# endregion fastio
# MOD = 998_244_353
# MOD = 10 ** 9 + 7
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL... | 3 | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,672,130,119 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | # for i in range(5005):
# count[i]=0
# for i in range(n):
# count[arr[i]]=count.get(arr[i], 0) + 1
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
mid=int(n/2)
set1=set()
for i in range(n):
if i !=mid:
set1.add(abs(a[mid]-a[i]))
if len(set1)==1:
print("YES")
else:
print("... | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
# for i in range(5005):
# count[i]=0
# for i in range(n):
# count[arr[i]]=count.get(arr[i], 0) + 1
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
mid=int(n/2)
set1=set()
for i in range(n):
if i !=mid:
set1.add(abs(a[mid]-a[i]))
if len(set1)==1:
print("YES")
else:... | 0 | |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,432,914,007 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = int(input())
a = [i for i in "".join(list(input().split())).split('0') if i != '']
ans = 0
if len(a) > 0:
if len(a[0]) > 1:
ans += len(a[0])+1
else:
ans += 2
for i in range(1, len(a)-1):
if len(a[i]) == 1:
ans += 2
else:
ans += len(a)+2... | Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
n = int(input())
a = [i for i in "".join(list(input().split())).split('0') if i != '']
ans = 0
if len(a) > 0:
if len(a[0]) > 1:
ans += len(a[0])+1
else:
ans += 2
for i in range(1, len(a)-1):
if len(a[i]) == 1:
ans += 2
else:
ans +... | 0 | |
18 | D | Seller Bob | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB me... | The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than... | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | 0 | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23... | 1,553,433,791 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | n = int(input())
win = []
sell = []
profit = 0
for i in range(1,n+1,1):
s, x = map(str,input().split())
if s == "win":
win.append(int(x))
if s == "sell":
sell.append(int(x))
sell = sorted(sell)
b = len(win)
for j in range(0,len(sell),1):
for i in range(0,b,1):
... | Title: Seller Bob
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he... | ```python
n = int(input())
win = []
sell = []
profit = 0
for i in range(1,n+1,1):
s, x = map(str,input().split())
if s == "win":
win.append(int(x))
if s == "sell":
sell.append(int(x))
sell = sorted(sell)
b = len(win)
for j in range(0,len(sell),1):
for i in range(0,b... | 0 |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,681,468,989 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 405 | 0 | ans=0
n=int(input())
s=dict()
s['Tetrahedron']= 4
s['Cube']=6
s['Octahedron']=8
s['Dodecahedron']=12
s['Icosahedron']=20
for _ in range(n):
string=input()
ans+=s[string]
print(ans)
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
ans=0
n=int(input())
s=dict()
s['Tetrahedron']= 4
s['Cube']=6
s['Octahedron']=8
s['Dodecahedron']=12
s['Icosahedron']=20
for _ in range(n):
string=input()
ans+=s[string]
print(ans)
``` | 3 | |
828 | A | Restaurant Tables | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d... | Print the total number of people the restaurant denies service to. | [
"4 1 2\n1 2 1 1\n",
"4 1 1\n1 1 2 1\n"
] | [
"0\n",
"2\n"
] | In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin... | 500 | [
{
"input": "4 1 2\n1 2 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 2 1",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 2\n2 2",
"output": "0"
},
{
"input": "5 1 3\n1 2 2 2 1",
"output": "1"
},
{
"input": "7 6 1\n1 1 1 1 1 1... | 1,501,450,689 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | #!usr/bin/python 3
def main():
a=input().split(' ')
a=[int(x) for x in a]
lst=input().split(' ')
lst=[int(x) for x in lst]
spots=a[1]+2*a[2]
lst_sum=sum(lst)
print(lst_sum-spots)
if __name__=='__main__':
main()
| Title: Restaurant Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, i... | ```python
#!usr/bin/python 3
def main():
a=input().split(' ')
a=[int(x) for x in a]
lst=input().split(' ')
lst=[int(x) for x in lst]
spots=a[1]+2*a[2]
lst_sum=sum(lst)
print(lst_sum-spots)
if __name__=='__main__':
main()
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,481,339,665 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 122 | 307,200 | n=int(input())
ddd=0
l1=[int(o) for o in input().split()]
if n>4:
for x in range(1,n-1):
l=[int(i) for i in l1]
if l[x]!=(l[x-1]/2+l[x+1]/2):
l[x]=(int(l1[x-1]/2+l1[x+1]/2))
d=(l[n-2]-l[1])/(n-3)
a=0
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
ddd=0
l1=[int(o) for o in input().split()]
if n>4:
for x in range(1,n-1):
l=[int(i) for i in l1]
if l[x]!=(l[x-1]/2+l[x+1]/2):
l[x]=(int(l1[x-1]/2+l1[x+1]/2))
d=(l[n-2]-l[1])/(n-3)
a=0... | -1 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,689,162,957 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | def l(n):
ln = [4,7,47,74,444,447,474,477,744,747,774,777]
for i in ln:
if n%i == 0:
return True
return False
n = int(input())
is_l = l(n)
if is_l:
print("YES")
else:
print("NO") | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def l(n):
ln = [4,7,47,74,444,447,474,477,744,747,774,777]
for i in ln:
if n%i == 0:
return True
return False
n = int(input())
is_l = l(n)
if is_l:
print("YES")
else:
print("NO")
``` | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,660,840,261 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
a=list(map(str,input().split()))[:m]
for i in a:
if i=='B' or i=='W' or i=='G':
l1.append(i)
else:
l2.append(i)
if len(l1)<=len(l2):
print('#Color')
elif len(l1)>0 and len(l2)==0:
print('#Bla... | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
a=list(map(str,input().split()))[:m]
for i in a:
if i=='B' or i=='W' or i=='G':
l1.append(i)
else:
l2.append(i)
if len(l1)<=len(l2):
print('#Color')
elif len(l1)>0 and len(l2)==0:
p... | 0 | |
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,621,691,799 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 77 | 0 | s=['Sheldon','Leonard','Penny','Rajesh','Howard']
a=int(input())
a=a-1
while a>=5:
a=a-5
a=a//2
print(s[a]) | 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
s=['Sheldon','Leonard','Penny','Rajesh','Howard']
a=int(input())
a=a-1
while a>=5:
a=a-5
a=a//2
print(s[a])
``` | 3.9615 |
448 | D | Multiplication Table | PROGRAMMING | 1,800 | [
"binary search",
"brute force"
] | null | null | Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* ... | The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*). | Print the *k*-th largest number in a *n*<=×<=*m* multiplication table. | [
"2 2 2\n",
"2 3 4\n",
"1 10 5\n"
] | [
"2\n",
"3\n",
"5\n"
] | A 2 × 3 multiplication table looks like this: | 2,000 | [
{
"input": "2 2 2",
"output": "2"
},
{
"input": "2 3 4",
"output": "3"
},
{
"input": "1 10 5",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "10 1 7",
"output": "7"
},
{
"input": "10 10 33",
"output": "14"
},
{
"input": "... | 1,676,281,329 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 1,843,200 | import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
# for _ i... | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multi... | ```python
import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
... | 0 | |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,584,798,740 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 155 | 1,126,400 | number = int(input())
answer = list()
if number % 2 == 0 and number % 4 == 0:
print(0)
answer.append(number//2)
index = 1
while index <= number//4:
answer.append(index)
answer.append(number + 1 - index)
index += 1
elif number % 2 == 0 and number % 4 != 0:
print(1)
answer.append(number//2)
ans... | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
number = int(input())
answer = list()
if number % 2 == 0 and number % 4 == 0:
print(0)
answer.append(number//2)
index = 1
while index <= number//4:
answer.append(index)
answer.append(number + 1 - index)
index += 1
elif number % 2 == 0 and number % 4 != 0:
print(1)
answer.append(number... | 0 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,644,938,148 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 154 | 0 | a=input()
b=input()
c=int(a)+int(b)
x=str(c)
for i in a:
if i=='0':
a=a.replace(i,'')
for i in b:
if i == '0':
b=b.replace(i,'')
for i in x:
if i == '0':
x=x.replace(i,'')
if int(a)+int(b)==int(x):
print('YES')
else:print('NO')
| Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a=input()
b=input()
c=int(a)+int(b)
x=str(c)
for i in a:
if i=='0':
a=a.replace(i,'')
for i in b:
if i == '0':
b=b.replace(i,'')
for i in x:
if i == '0':
x=x.replace(i,'')
if int(a)+int(b)==int(x):
print('YES')
else:print('NO')
``` | 3.9615 |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ... | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are... | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, M... | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1... | 1,672,932,855 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 62 | 0 | r = 0
ch, c = 0, 0
l = list(map(int, input().split()))
t, k = l[0], l[1]
a = list(map(int, input().split()))
while len(a) != 0:
if a[0] > k:
ch += 1
if a[len(a)-1] > k:
ch += 1
if a[0] <= k:
c += 1
del(a[0])
if True if len(a) != 0 and a[len(a)-1] <= k else Fa... | Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his... | ```python
r = 0
ch, c = 0, 0
l = list(map(int, input().split()))
t, k = l[0], l[1]
a = list(map(int, input().split()))
while len(a) != 0:
if a[0] > k:
ch += 1
if a[len(a)-1] > k:
ch += 1
if a[0] <= k:
c += 1
del(a[0])
if True if len(a) != 0 and a[len(a)-1] <=... | 3 | |
278 | B | New Problem | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Yo... | The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive. | Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title. | [
"5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n"
] | [
"j\n",
"ab\n"
] | In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | 1,000 | [
{
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear",
"output": "j"
},
{
"input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc",
"output": "ab"
},
{
"input": "1\na",
"output": "b"
},
{
"input": "1\nb",
"output": "a"
},
{
"input": "1\nz",
"o... | 1,427,735,967 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 218 | 2,662,400 | n = int(input())
all = set()
for w in range(n):
s = input()
for i in range(len(s) + 1):
for j in range(i):
all.add(s[j:i])
cnt = 0
limit = 26
l = 1
while True:
s = ''
tmp = cnt
for i in range(l):
s = chr(ord('a') + tmp % 26) + s
tmp //= 26
if s not in all:
print(s)
break
cnt += 1
if cnt == limit:
... | Title: New Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You'... | ```python
n = int(input())
all = set()
for w in range(n):
s = input()
for i in range(len(s) + 1):
for j in range(i):
all.add(s[j:i])
cnt = 0
limit = 26
l = 1
while True:
s = ''
tmp = cnt
for i in range(l):
s = chr(ord('a') + tmp % 26) + s
tmp //= 26
if s not in all:
print(s)
break
cnt += 1
if cnt =... | 3 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,695,645,421 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 124 | 0 | n = int(input())
h = [0] * n
g = [0] * n
for i in range(n):
h[i], g[i] = input().split()
h[i] = int(h[i])
g[i] = int(g[i])
c = 0
for i in range(n):
for j in range(n):
if j != i:
if h[i] == g[j]:
c += 1
print(c)
| Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
n = int(input())
h = [0] * n
g = [0] * n
for i in range(n):
h[i], g[i] = input().split()
h[i] = int(h[i])
g[i] = int(g[i])
c = 0
for i in range(n):
for j in range(n):
if j != i:
if h[i] == g[j]:
c += 1
print(c)
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,688,911,963 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 124 | 0 | l=list(map(int,input()))
l.append(0);c=p=0
for i in range(len(l)):
if not l[i]:
c=max(c,i-p);p=i+1
p=0;l.pop();l.append(1)
for i in range(len(l)):
if l[i]:
c=max(c,i-p);p=i+1
if c>= 7:
print('YES')
else:
print('NO')
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
l=list(map(int,input()))
l.append(0);c=p=0
for i in range(len(l)):
if not l[i]:
c=max(c,i-p);p=i+1
p=0;l.pop();l.append(1)
for i in range(len(l)):
if l[i]:
c=max(c,i-p);p=i+1
if c>= 7:
print('YES')
else:
print('NO')
``` | 3.969 |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,601,667,853 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 108 | 0 | l,r,x,y,k=map(int,input().split());print("NO"if (r<k*x or l>k*y)else"YES") | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
l,r,x,y,k=map(int,input().split());print("NO"if (r<k*x or l>k*y)else"YES")
``` | 0 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,643,296,930 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | n = input()
p = input()
m = input()
d = { "A" : 0, "B" : 0, 'C' : 0}
k = [n,p,m]
s = ""
for i in k:
if i[1] == ">":
d[i[0]] +=1
else:
d[i[2]] +=1
if d["A"] == d["B"] == d["C"]:
print("Impossible")
else:
for i in range(3):
for j in d:
if d[j] == i:
s +=... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
n = input()
p = input()
m = input()
d = { "A" : 0, "B" : 0, 'C' : 0}
k = [n,p,m]
s = ""
for i in k:
if i[1] == ">":
d[i[0]] +=1
else:
d[i[2]] +=1
if d["A"] == d["B"] == d["C"]:
print("Impossible")
else:
for i in range(3):
for j in d:
if d[j] == i:
... | 3.977 |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,684,865,237 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, m = map(int, input().split())
if n % m == 0:
req = n // m
moves = 0
moves += req // 2
moves += req % 2
print(m * moves)
else:
print(-1) | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
n, m = map(int, input().split())
if n % m == 0:
req = n // m
moves = 0
moves += req // 2
moves += req % 2
print(m * moves)
else:
print(-1)
``` | 0 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,688,717,419 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 216 | 13,516,800 | n=int(input())
temp=list(map(int,input().split()))
min=min(temp)
idx=0
for i,v in enumerate(temp):
if v==min:
idx=i
temp.remove(min)
if min in temp:
print("Still Rozdil")
else:
print(idx+1)
| Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
n=int(input())
temp=list(map(int,input().split()))
min=min(temp)
idx=0
for i,v in enumerate(temp):
if v==min:
idx=i
temp.remove(min)
if min in temp:
print("Still Rozdil")
else:
print(idx+1)
``` | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,694,005,074 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n=int(input())
cand=n**2
s=0
for i in range(1,cand+1):
s=s+i
result=[]
ch=""
t=[i for i in range (1,cand+1)]
for i in range (n):
for j in range (n//2):
ch=str(max(t))+" "+str(min(t))+" "
t.remove(max(t))
t.remove(min(t))
print(ch)
result=[]
ch=""
... | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n=int(input())
cand=n**2
s=0
for i in range(1,cand+1):
s=s+i
result=[]
ch=""
t=[i for i in range (1,cand+1)]
for i in range (n):
for j in range (n//2):
ch=str(max(t))+" "+str(min(t))+" "
t.remove(max(t))
t.remove(min(t))
print(ch)
result=[]
ch=""
... | 0 | |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,454,866,742 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 61 | 62 | 0 | n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = b - c
ans = (n - c) // d
res = max(n // a, (n - d * ans) // a + ans)
print(res)
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = b - c
ans = (n - c) // d
res = max(n // a, (n - d * ans) // a + ans)
print(res)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,662,991,042 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,m = map(int,input().split())
print(floor(N*M*0.5) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n,m = map(int,input().split())
print(floor(N*M*0.5)
``` | -1 |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,546,969,032 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 108 | 0 | n=int(input())
ht={"polycarp":1}
m=0
for i in range(n):
inp=input().split(" ")
ht[inp[0].lower()]=ht[inp[2].lower()]+1
temp=ht[inp[0].lower()]
m=max(m, temp)
print(m)
| Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
n=int(input())
ht={"polycarp":1}
m=0
for i in range(n):
inp=input().split(" ")
ht[inp[0].lower()]=ht[inp[2].lower()]+1
temp=ht[inp[0].lower()]
m=max(m, temp)
print(m)
``` | 3 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,616,473,532 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 248 | 1,843,200 | n = int(input())
li = list(map(int,input().split()))
ans = []
for i in range(n):
a = li[i]
count = 1
try:
while a>=li[i+count]:
a = li[i+count]
count+=1
except:
pass
r = (count-1)
a = li[i]
... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
n = int(input())
li = list(map(int,input().split()))
ans = []
for i in range(n):
a = li[i]
count = 1
try:
while a>=li[i+count]:
a = li[i+count]
count+=1
except:
pass
r = (count-1)
a = l... | 3.934567 |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,572,459,286 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n = int(input())
s = input()
c = 0
for i in range (n):
if s[i] == s[i].upper() and s[i] != " ":
c+=1
print(c)
| Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = int(input())
s = input()
c = 0
for i in range (n):
if s[i] == s[i].upper() and s[i] != " ":
c+=1
print(c)
``` | 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,699,721,646 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | # // Problem: A. Anton and Letters
# // Contest: Codeforces - Codeforces Round 253 (Div. 2)
# // URL: https://codeforces.com/problemset/problem/443/A
# // Memory Limit: 256 MB
# // Time Limit: 2000 ms
# // Author: Anisphia (EuphyChanDaisuki)
# //
# // Powered by CP Editor (https://cpeditor.org)
#
inp = inp... | 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
# // Problem: A. Anton and Letters
# // Contest: Codeforces - Codeforces Round 253 (Div. 2)
# // URL: https://codeforces.com/problemset/problem/443/A
# // Memory Limit: 256 MB
# // Time Limit: 2000 ms
# // Author: Anisphia (EuphyChanDaisuki)
# //
# // Powered by CP Editor (https://cpeditor.org)
#
... | 3 | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,517,951,329 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 35 | 1,000 | 5,632,000 | from math import log
n,i = map(int,input().split())
c = 0
while i>0:
c = int(log(i,2))
i %= 2**c
print (int(c+1)) | Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
from math import log
n,i = map(int,input().split())
c = 0
while i>0:
c = int(log(i,2))
i %= 2**c
print (int(c+1))
``` | 0 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,652,946,643 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 280 | 8,806,400 | from itertools import groupby
n = int(input())
print(max(len(list(g)) for _, g in groupby(input() for _ in range(n)))) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
from itertools import groupby
n = int(input())
print(max(len(list(g)) for _, g in groupby(input() for _ in range(n))))
``` | 3 | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,698,047,598 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 374 | 7,884,800 | n = int(input())
b= [0]*1000001
b[1]=b[0]=1
for i in range(2,1000):
if not b[i]:
for j in range(i+i,1000001,i):
b[j] = 1
for i in range(n):
x = list(map(int,input().split()))
for j in range(len(x)):
t = int(x[j]**0.5)
if t*t == x[j] and not b[t]:
p... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
n = int(input())
b= [0]*1000001
b[1]=b[0]=1
for i in range(2,1000):
if not b[i]:
for j in range(i+i,1000001,i):
b[j] = 1
for i in range(n):
x = list(map(int,input().split()))
for j in range(len(x)):
t = int(x[j]**0.5)
if t*t == x[j] and not b[t]:
... | -1 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,566,985,931 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 140 | 102,400 | n,m=map(int,input().split())
a=0
b=0
c=0
for i in range(1,7):
if abs(n-i)==abs(m-i):
c=1
else:
if abs(n-i)>abs(m-i):
a=a+1
else:
b+=1
print(b,c,a) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
n,m=map(int,input().split())
a=0
b=0
c=0
for i in range(1,7):
if abs(n-i)==abs(m-i):
c=1
else:
if abs(n-i)>abs(m-i):
a=a+1
else:
b+=1
print(b,c,a)
``` | 0 | |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20... | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output"... | 1,587,305,468 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 19:15:09 2020
@author: USER
"""
l=[int(x) for x in input().split()]
l.sort()
print(l[0])
for i in range(4,-1,-1):
if l.count(l[i])==2:
l.pop(i-1)
l.pop(i-1)
break
elif l.count(l[i])>2:
l.pop(i-2)
l.pop(i... | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 19:15:09 2020
@author: USER
"""
l=[int(x) for x in input().split()]
l.sort()
print(l[0])
for i in range(4,-1,-1):
if l.count(l[i])==2:
l.pop(i-1)
l.pop(i-1)
break
elif l.count(l[i])>2:
l.pop(i-2)
... | 0 | |
992 | A | Nastya and an Array | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. | [
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | 500 | [
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
... | 1,654,605,328 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 7,065,600 | tamanho = int(input())
numeros = [int(i) for i in input().split()]
rodadas = 0
numerosDiferentes = []
for i in numeros:
if ((i not in numerosDiferentes) and (i != 0)):
numerosDiferentes.append(i)
rodadas += 1
print(rodadas) | Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second ... | ```python
tamanho = int(input())
numeros = [int(i) for i in input().split()]
rodadas = 0
numerosDiferentes = []
for i in numeros:
if ((i not in numerosDiferentes) and (i != 0)):
numerosDiferentes.append(i)
rodadas += 1
print(rodadas)
``` | 0 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,596,456,398 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 20,172,800 | I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n,a,b=M()
if b<=0:
print(abs(a+b)%n)
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
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n,a,b=M()
if b<=0:
print(abs(a+b)%n)
else:
print((a+b)%n)
``` | 0 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,588,748,335 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | a=int(input());s=0
for i in range(1,10):
for j in range(1<<i):
n=""
for k in range(i):n+=str(j&(1<<k))
n=n.replace("0","4").replace("1","7")
if (a>=int(n)):s+=1
print(s) | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
a=int(input());s=0
for i in range(1,10):
for j in range(1<<i):
n=""
for k in range(i):n+=str(j&(1<<k))
n=n.replace("0","4").replace("1","7")
if (a>=int(n)):s+=1
print(s)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.