contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
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 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,513,494,770 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | a,b,c =map(int,input().split())
fraction =str(a/b)
if ('.' in fraction and 'e' not in fraction):
fraction =fraction[fraction.index('.')+1:]+'0'
if (str(c) not in fraction):
print ('-1')
else:
print (fraction.index(str(c))+1)
elif ('e' in fraction):
power =int(fraction[fraction.index('-')+1:])
base =fraction[:f... | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
a,b,c =map(int,input().split())
fraction =str(a/b)
if ('.' in fraction and 'e' not in fraction):
fraction =fraction[fraction.index('.')+1:]+'0'
if (str(c) not in fraction):
print ('-1')
else:
print (fraction.index(str(c))+1)
elif ('e' in fraction):
power =int(fraction[fraction.index('-')+1:])
base =f... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,698,002,364 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | a=list(map(int,input().split()))
a.sort()
x=a[1]
print(abs(x-a[0])+abs(x-a[1])+abs(x-a[2])) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
a=list(map(int,input().split()))
a.sort()
x=a[1]
print(abs(x-a[0])+abs(x-a[1])+abs(x-a[2]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
13 | C | Sequence | PROGRAMMING | 2,200 | [
"dp",
"sortings"
] | C. Sequence | 1 | 64 | Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of s... | The first line of the input contains single integer *N* (1<=≤<=*N*<=≤<=5000) — the length of the initial sequence. The following *N* lines contain one integer each — elements of the sequence. These numbers do not exceed 109 by absolute value. | Output one integer — minimum number of steps required to achieve the goal. | [
"5\n3 2 -1 2 11\n",
"5\n2 1 1 1 1\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\n3 2 -1 2 11",
"output": "4"
},
{
"input": "5\n2 1 1 1 1",
"output": "1"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "1\n11",
"output": "0"
},
{
"input": "2\n10 2",
"output": "8"
},
{
"input": "6\n1000000000 -1000000000 1000... | 1,666,175,481 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 7 | 466 | 67,072,000 | n = int(input())
a = list(map(int, input().split()))
ordered = sorted(set(a))
m = len(ordered)
dp = [[0] * m for _ in range(n + 1)]
for i in range(n):
min_prev = 10 ** 18
for j in range(m):
min_prev = min(min_prev, dp[i - 1][j])
dp[i][j] = min_prev + abs(a[i] - ordered[j])
print(min(dp[n - 1]))
| Title: Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. ... | ```python
n = int(input())
a = list(map(int, input().split()))
ordered = sorted(set(a))
m = len(ordered)
dp = [[0] * m for _ in range(n + 1)]
for i in range(n):
min_prev = 10 ** 18
for j in range(m):
min_prev = min(min_prev, dp[i - 1][j])
dp[i][j] = min_prev + abs(a[i] - ordered[j])
print(min(dp... | 0 | MatrixStudio/Codeforces-Python-Submissions |
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,397,588,772 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 156 | 307,200 | n = int(input())
p = [str(i) for i in range(1, n**2+1)]
res = []
for i in range(n):
l1, l2 = p[:n//2], p[len(p)-n//2:]
res.append(l1 + l2)
p = p[n//2:len(p)-n//2]
for x in res:
print(' '.join(x)) | 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())
p = [str(i) for i in range(1, n**2+1)]
res = []
for i in range(n):
l1, l2 = p[:n//2], p[len(p)-n//2:]
res.append(l1 + l2)
p = p[n//2:len(p)-n//2]
for x in res:
print(' '.join(x))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf9... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
... | 1,381,433,869 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | def phi(n):
t, i = n, 2
while i * i <= n:
if n % i == 0:
n //= i
while n % i == 0: n //= i
t -= t // i
i += 1
return t - t // n if n > 1 else t
print(phi(int(input()) - 1)) | Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 ar... | ```python
def phi(n):
t, i = n, 2
while i * i <= n:
if n % i == 0:
n //= i
while n % i == 0: n //= i
t -= t // i
i += 1
return t - t // n if n > 1 else t
print(phi(int(input()) - 1))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,585,900,948 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 140 | 0 | i=input
n=int(i())
days=i()
if days.count('SF') > days.count('FS'):
print('YES')
else:
print('NO')
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
i=input
n=int(i())
days=i()
if days.count('SF') > days.count('FS'):
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,675,053,432 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 154 | 0 | q=int(input())
w=[int(e)for e in input().split()]
a=0
b=0
for i in w:
if i%2==0:
a+=1
else:
b+=1
if a>=2:
for i in w:
if i%2==1:
print(w.index(i)+1)
if b>=2:
for i in w:
if i%2==0:
print(w.index(i)+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
q=int(input())
w=[int(e)for e in input().split()]
a=0
b=0
for i in w:
if i%2==0:
a+=1
else:
b+=1
if a>=2:
for i in w:
if i%2==1:
print(w.index(i)+1)
if b>=2:
for i in w:
if i%2==0:
print(w.index(i)+1)
``` | 3.9615 | MatrixStudio/Codeforces-Python-Submissions |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,519,540,014 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 5,632,000 | n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
s = set(a)
k = 0
for i in range(n):
if a[i] in s:
s.remove(a[i])
if len(s) == 1:
print(s.pop())
break | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
s = set(a)
k = 0
for i in range(n):
if a[i] in s:
s.remove(a[i])
if len(s) == 1:
print(s.pop())
break
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,676,138,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | n, m = input().split()
marks = []
for j in range(int(n)):
numbers = input()
numbers = [int(i) for i in numbers]
marks.append(numbers)
no_of_successful = 0
_marks = []
# Student
for z in range(int(n)):
successful = False
for i in range(int(m)):# Iterate through subjects
... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
n, m = input().split()
marks = []
for j in range(int(n)):
numbers = input()
numbers = [int(i) for i in numbers]
marks.append(numbers)
no_of_successful = 0
_marks = []
# Student
for z in range(int(n)):
successful = False
for i in range(int(m)):# Iterate through subj... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,690,362,651 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n,x = map(int,input().split())
k = n*x
print(k//2) | 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,x = map(int,input().split())
k = n*x
print(k//2)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,698,898,741 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | def patron_potencias(n):
#1378^1 = 8
#1378 ^2 = 4
#1378 ^ 3 = 2
#1378 ^ 4 = 6
#1378 ^ 5 = 8
#1378 ^6 = 4
#1378 ^7 = 2
#1378 ^8 = 6
# El patron es 8 4 2 6
ciclo = [8, 4, 2, 6]
posicion_ciclo = (n - 1) % 4
# El último dígito de 1378^n es el dígito e... | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
def patron_potencias(n):
#1378^1 = 8
#1378 ^2 = 4
#1378 ^ 3 = 2
#1378 ^ 4 = 6
#1378 ^ 5 = 8
#1378 ^6 = 4
#1378 ^7 = 2
#1378 ^8 = 6
# El patron es 8 4 2 6
ciclo = [8, 4, 2, 6]
posicion_ciclo = (n - 1) % 4
# El último dígito de 1378^n es e... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,580,889,955 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 312 | 1,331,200 | #code
n=int(input())
a=list(map(int,input().split()))
b=set(a)
for i in b:
cb=0
for j in a:
if j==i:
cb+=1;
if (n%2==1 and cb>(n/2)+1) or (n%2==0 and cb>n/2):
print("NO")
exit(0)
print("YES") | 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
#code
n=int(input())
a=list(map(int,input().split()))
b=set(a)
for i in b:
cb=0
for j in a:
if j==i:
cb+=1;
if (n%2==1 and cb>(n/2)+1) or (n%2==0 and cb>n/2):
print("NO")
exit(0)
print("YES")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,571,635,869 | 2,169 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n=int(input())
s=input()
ones=0
newn=1
ans=""
i=0
while(i<n):
if(s[i]=="1"):
j=i+1
ones=1
while(j<n and s[j]=="1"):
ones+=1
j+=1
ans+=str(ones)
i=j
else:
z=1
j=i+1
while(j<n and s[j]=="0"):
z+=... | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
n=int(input())
s=input()
ones=0
newn=1
ans=""
i=0
while(i<n):
if(s[i]=="1"):
j=i+1
ones=1
while(j<n and s[j]=="1"):
ones+=1
j+=1
ans+=str(ones)
i=j
else:
z=1
j=i+1
while(j<n and s[j]=="0"):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,553,842,151 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 0 | n,m = map(int,input().split())
a = list(map(int,input().split()))
d = {i:0 for i in range(1,n+1)}
for i in range(m):
if a[i] in d:
d[a[i]] += 1
print(min(d.values())) | Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
n,m = map(int,input().split())
a = list(map(int,input().split()))
d = {i:0 for i in range(1,n+1)}
for i in range(m):
if a[i] in d:
d[a[i]] += 1
print(min(d.values()))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
161 | A | Dress'em in Vests! | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"greedy",
"two pointers"
] | null | null | The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.
The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered him... | The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i... | In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests.
In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are ... | [
"5 3 0 0\n1 2 3 3 4\n1 3 5\n",
"3 3 2 2\n1 5 9\n3 5 7\n"
] | [
"2\n1 1\n3 2\n",
"3\n1 1\n2 2\n3 3\n"
] | In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.
In the second sample the vest size can differ... | 1,000 | [
{
"input": "5 3 0 0\n1 2 3 3 4\n1 3 5",
"output": "2\n1 1\n3 2"
},
{
"input": "3 3 2 2\n1 5 9\n3 5 7",
"output": "3\n1 1\n2 2\n3 3"
},
{
"input": "1 1 0 0\n1\n1",
"output": "1\n1 1"
},
{
"input": "1 1 0 0\n1\n2",
"output": "0"
},
{
"input": "2 3 1 4\n1 5\n1 2 2",
... | 1,516,804,977 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 5,632,000 | def dress():
par1 = list(map(int,input().split()))
par2 = list(map(int,input().split()))
par3 = list(map(int, input().split()))
n = par1[0]
m = par1[1]
x = par1[2]
y = par1[3]
j = 0
result = []
for i in range(m):
while (j<n and par2[j]+y<par3[i]):
j += 1
... | Title: Dress'em in Vests!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the s... | ```python
def dress():
par1 = list(map(int,input().split()))
par2 = list(map(int,input().split()))
par3 = list(map(int, input().split()))
n = par1[0]
m = par1[1]
x = par1[2]
y = par1[3]
j = 0
result = []
for i in range(m):
while (j<n and par2[j]+y<par3[i]):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,537,450,768 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,m=list(map(int,input().split()))
ma=list(range(1,m+1))
lk=len(ma)
sa=0
ta=list(range(2,n+1))
sa=lk+len(list(range(2,n+1)))
print(sa)
for x in range(1,m+1):
print(1,x)
for x in range(2,n+1)"
print(x,1 | Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
n,m=list(map(int,input().split()))
ma=list(range(1,m+1))
lk=len(ma)
sa=0
ta=list(range(2,n+1))
sa=lk+len(list(range(2,n+1)))
print(sa)
for x in range(1,m+1):
print(1,x)
for x in range(2,n+1)"
print(x,1
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,590,579,210 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | l = list(map(int, input().rstrip().split()))
x=[]
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
for i in range(l[0]):
x.append(abs(a[i]-b[i]))
x.sort(reverse=True)
t=l[1]+l[2]
j=0
while(t>0 and j<len(x)):
if x[j]>t:
t = 0
x[j]-=t
b... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
l = list(map(int, input().rstrip().split()))
x=[]
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
for i in range(l[0]):
x.append(abs(a[i]-b[i]))
x.sort(reverse=True)
t=l[1]+l[2]
j=0
while(t>0 and j<len(x)):
if x[j]>t:
t = 0
x[j]-=t
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,672,329,429 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n, m = input(), input()
n_cnt, m_cnt = {}, {}
for n_color, m_color in zip(n, m):
n_cnt[n_color] = n_cnt.get(n_color, 0) + 1
m_cnt[m_color] = m_cnt.get(m_color, 0) + 1
m = set(m)
if set(m) - set(n):
print(-1)
else:
ans = 0
for color in m:
ans += min(n_cnt[color], m_cnt[color])
... | 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
n, m = input(), input()
n_cnt, m_cnt = {}, {}
for n_color, m_color in zip(n, m):
n_cnt[n_color] = n_cnt.get(n_color, 0) + 1
m_cnt[m_color] = m_cnt.get(m_color, 0) + 1
m = set(m)
if set(m) - set(n):
print(-1)
else:
ans = 0
for color in m:
ans += min(n_cnt[color], m_cnt[... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,692,380,324 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | i = int(input())
num = 0
while i/2 != 0:
if int(i%2) == 1 :
num+=1
i = i/2
print(num)
| Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
i = int(input())
num = 0
while i/2 != 0:
if int(i%2) == 1 :
num+=1
i = i/2
print(num)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,513,752,034 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 77 | 5,632,000 | a_b=input().split()
a=int(a_b[0])
b=int(a_b[1])
l1=[]
l2=[]
c=0
for i in range(a):
c_d=input().split()
l1.append(int(c_d[0]))
l2.append(int(c_d[1]))
if b in l2:
d=l1[l2.index(b)]
for i in range(a):
for i in range(a):
if l1[i]<d<=l2[i]:
d=l1[i]
brea... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
a_b=input().split()
a=int(a_b[0])
b=int(a_b[1])
l1=[]
l2=[]
c=0
for i in range(a):
c_d=input().split()
l1.append(int(c_d[0]))
l2.append(int(c_d[1]))
if b in l2:
d=l1[l2.index(b)]
for i in range(a):
for i in range(a):
if l1[i]<d<=l2[i]:
d=l1[i]
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,620,447,893 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 6,860,800 | mat = []
for _ in range(3):
mat.append(list(map(int, input().split())))
l = [[0,0,0],[0,0,0],[0,0,0]]
l[0][0] = (sum([mat[i][j] for i in range(0,2) for j in range(0,2)])-mat[0][0])%2
l[0][1] = (sum([mat[i][j] for i in range(0,2) for j in range(0,3)])-mat[0][1])%2
l[0][2] = (sum([mat[i][j] for i in range(0,2)... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
mat = []
for _ in range(3):
mat.append(list(map(int, input().split())))
l = [[0,0,0],[0,0,0],[0,0,0]]
l[0][0] = (sum([mat[i][j] for i in range(0,2) for j in range(0,2)])-mat[0][0])%2
l[0][1] = (sum([mat[i][j] for i in range(0,2) for j in range(0,3)])-mat[0][1])%2
l[0][2] = (sum([mat[i][j] for i in ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin... | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the s... | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,690,946,483 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 31 | 512,000 | import functools
def compare(x, y):
return min(y[0]*2, y[1]) - min(x[0]*2, x[1])
n, f = map(int, input().split())
count = 0
list = []
for _ in range(n):
k, l = map(int, input().split())
if k >= l:
count += l
else:
list.append([k, l])
sorted_l = sorted(list, key=functool... | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass... | ```python
import functools
def compare(x, y):
return min(y[0]*2, y[1]) - min(x[0]*2, x[1])
n, f = map(int, input().split())
count = 0
list = []
for _ in range(n):
k, l = map(int, input().split())
if k >= l:
count += l
else:
list.append([k, l])
sorted_l = sorted(list, ke... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to *n*, inclusive.
For permutation *p*<==<=*p*0,<=*p*1,<=...,<=*p**n*, Polo has defined its beauty — number .
Expression means applying the operation of bitwise excluding "OR" to numbers *x* and *y*. This operation exist... | The single line contains a positive integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print integer *m* the maximum possible beauty. In the second line print any permutation of integers from 0 to *n* with the beauty equal to *m*.
If there are several suitable permutations, you are allowed to print any of them. | [
"4\n"
] | [
"20\n0 2 1 4 3\n"
] | none | 0 | [
{
"input": "4",
"output": "20\n0 2 1 4 3"
},
{
"input": "7",
"output": "56\n7 6 5 4 3 2 1 0"
},
{
"input": "1",
"output": "2\n1 0"
},
{
"input": "2",
"output": "6\n0 2 1"
},
{
"input": "3",
"output": "12\n3 2 1 0"
},
{
"input": "8",
"output": "72\n... | 1,689,345,094 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689345094.126305")# 1689345094.126324 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to *n*, inclusive.
For permutation *p*<==<=*p*0,<=*p*1,<=...,<=*p**n*, Polo has defined its beauty — number .
Expression means app... | ```python
print("_RANDOM_GUESS_1689345094.126305")# 1689345094.126324
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,696,127,909 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 0 | s=input()
x=""
s=s[0:].lower()
for i in reversed(range((len(s)))):
if s[i].isalpha():
x+=s[i]
break
if(x=="a"or x=="e" or x=="i"or x=="o"or x=="u"or x=="y"):
print("YES")
else:
print("NO")
#print(x) | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s=input()
x=""
s=s[0:].lower()
for i in reversed(range((len(s)))):
if s[i].isalpha():
x+=s[i]
break
if(x=="a"or x=="e" or x=="i"or x=="o"or x=="u"or x=="y"):
print("YES")
else:
print("NO")
#print(x)
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
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,692,426,730 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | word = input()
word = word[1:len(word) - 2]
objects = word.split(', ')
unique_objects = set(object)
print(len(unique_objects)) | 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
word = input()
word = word[1:len(word) - 2]
objects = word.split(', ')
unique_objects = set(object)
print(len(unique_objects))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,638,011,710 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | m,n = map(int,input().split())
t = max(m,n)
x = 6-t+1
y = 6
for i in range(1,7):
if(x%i == 0 and y%i == 0):
x = x/i
y = y/i
print(int(x), end='')
print('/', end='')
print(int(y))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
m,n = map(int,input().split())
t = max(m,n)
x = 6-t+1
y = 6
for i in range(1,7):
if(x%i == 0 and y%i == 0):
x = x/i
y = y/i
print(int(x), end='')
print('/', end='')
print(int(y))
``` | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,524,845,179 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 7,065,600 | side = []
for i in range(0, 4):
side.append(int(input()))
for i in range(0, len(side)):
a = i
for j in range(i+1, len(side)):
for k in range(0, len(side)):
if (side[k]>side[i] and side[k]>side[j]) and side[k]<side[j]+side[i]:
print("TRIANGLE")
exit(0);
for... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
side = []
for i in range(0, 4):
side.append(int(input()))
for i in range(0, len(side)):
a = i
for j in range(i+1, len(side)):
for k in range(0, len(side)):
if (side[k]>side[i] and side[k]>side[j]) and side[k]<side[j]+side[i]:
print("TRIANGLE")
ex... | -1 | MatrixStudio/Codeforces-Python-Submissions |
748 | B | Santa Claus and Keyboard Check | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 1,000 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,482,658,436 | 1,736 | Python 3 | CHALLENGED | CHALLENGES | 8 | 46 | 4,608,000 | a=input()
b=input()
c=[]
d=[]
for i in range(len(a)):
if a[i]!=b[i] and not [a[i],b[i]] in c and not [b[i],a[i]] in c:
if a[i] in d and not b[i] in d or not a[i] in d and b[i] in d:
print(-1)
c=1
break
c.append([a[i],b[i]])
if not a[i] in d:
... | Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke... | ```python
a=input()
b=input()
c=[]
d=[]
for i in range(len(a)):
if a[i]!=b[i] and not [a[i],b[i]] in c and not [b[i],a[i]] in c:
if a[i] in d and not b[i] in d or not a[i] in d and b[i] in d:
print(-1)
c=1
break
c.append([a[i],b[i]])
if not a[i... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
407 | A | Triangle | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the... | The first line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=1000), separated by a single space. | In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute valu... | [
"1 1\n",
"5 5\n",
"5 10\n"
] | [
"NO\n",
"YES\n2 1\n5 5\n-2 4\n",
"YES\n-10 4\n-2 -2\n1 2\n"
] | none | 500 | [
{
"input": "1 1",
"output": "NO"
},
{
"input": "5 5",
"output": "YES\n2 1\n5 5\n-2 4"
},
{
"input": "5 10",
"output": "YES\n-10 4\n-2 -2\n1 2"
},
{
"input": "2 2",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 11",
"output": "... | 1,699,490,600 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 61 | 0 | import math
x, y = map(int, input().split())
flag = 0
for vx in range(1, x):
for vy in range(1, y):
ay = int(math.sqrt(x * x - vx * vx))
by = int(math.sqrt(y * y - vy * vy))
if vx * vx + ay * ay == x * x and vy * vy + by * by == y * y:
if vx * vy == ay * by:
... | Title: Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the v... | ```python
import math
x, y = map(int, input().split())
flag = 0
for vx in range(1, x):
for vy in range(1, y):
ay = int(math.sqrt(x * x - vx * vx))
by = int(math.sqrt(y * y - vy * vy))
if vx * vx + ay * ay == x * x and vy * vy + by * by == y * y:
if vx * vy == ay * by:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,648,232,801 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 31 | 0 | string = input()
a = []
for _ in range(len(string)):
a.append(string)
string = string[-1]+string[:-1]
print(len(set(a))) | Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
string = input()
a = []
for _ in range(len(string)):
a.append(string)
string = string[-1]+string[:-1]
print(len(set(a)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,668,839,286 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a,b = map(int,input().split(" "))
if a == b:
print("%d"%(a+1),end="")
else:
print("%d"%(a*b),end="")
| Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
a,b = map(int,input().split(" "))
if a == b:
print("%d"%(a+1),end="")
else:
print("%d"%(a*b),end="")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,556,528,982 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 102,400 | a = int(input())
b = int(input())
best = 10**18
def dist(a, b):
l = max(a - b, b - a)
if l == 0: return 0
return l * (l + 1) // 2
for x in range(1, 2000):
best = min(best, dist(x, a) + dist(x, b))
print(best)
| Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a = int(input())
b = int(input())
best = 10**18
def dist(a, b):
l = max(a - b, b - a)
if l == 0: return 0
return l * (l + 1) // 2
for x in range(1, 2000):
best = min(best, dist(x, a) + dist(x, b))
print(best)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,662,919,256 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n, m = [int(i) for i in input().split()]
q = 0
for i in range(n):
a = input().split()
if "C" in a or "M" in a or "Y" in a or "W" in a:
q = 1
break
print("#Black&White" if q == 0 else "#Color") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n, m = [int(i) for i in input().split()]
q = 0
for i in range(n):
a = input().split()
if "C" in a or "M" in a or "Y" in a or "W" in a:
q = 1
break
print("#Black&White" if q == 0 else "#Color")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,634,823,465 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 62 | 4,300,800 | n,m = [int(x) for x in input().split()]
bulbs = set()
for _ in range(n):
bulbs.update(input().split()[1:])
print('YES' if len(bulbs) == m else 'NO') | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m = [int(x) for x in input().split()]
bulbs = set()
for _ in range(n):
bulbs.update(input().split()[1:])
print('YES' if len(bulbs) == m else 'NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
980 | A | Links and Pearls | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l... | The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. | Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"-o-o--",
"-o---\n",
"-o---o-\n",
"ooo\n"
] | [
"YES",
"YES",
"NO",
"YES\n"
] | none | 500 | [
{
"input": "-o-o--",
"output": "YES"
},
{
"input": "-o---",
"output": "YES"
},
{
"input": "-o---o-",
"output": "NO"
},
{
"input": "ooo",
"output": "YES"
},
{
"input": "---",
"output": "YES"
},
{
"input": "--o-o-----o----o--oo-o-----ooo-oo---o--",
"... | 1,531,739,494 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 93 | 0 | a, b, s = 0, 0, input()
for i in s:
if i == '-':
b += 1
else:
a += 1
if b % a == 0:
print('YES')
else:
print('NO') | Title: Links and Pearls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearl... | ```python
a, b, s = 0, 0, input()
for i in s:
if i == '-':
b += 1
else:
a += 1
if b % a == 0:
print('YES')
else:
print('NO')
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,695,688,984 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 93 | 13,107,200 | def OathOfTheNightsWatch():
n=int(input())
stewarts=list(map(int,input().split()))
if n<=2:
print("0")
return
stewarts.sort()
count=0
for i in range(1,n-1):
if stewarts[i]>stewarts[i-1] and stewarts[i]<stewarts[i+1]... | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
def OathOfTheNightsWatch():
n=int(input())
stewarts=list(map(int,input().split()))
if n<=2:
print("0")
return
stewarts.sort()
count=0
for i in range(1,n-1):
if stewarts[i]>stewarts[i-1] and stewarts[i]<ste... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,566,748,261 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 0 | n = int(input())
team1 = str(input())
goal1 = 1
goal2 = 0
for i in range(n-1):
t = str(input())
if(t == team1):
goal1 +=1
else:
goal2 +=1
team2 = t
if(goal1 > goal2):
print(team1)
else:
print(team2) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
team1 = str(input())
goal1 = 1
goal2 = 0
for i in range(n-1):
t = str(input())
if(t == team1):
goal1 +=1
else:
goal2 +=1
team2 = t
if(goal1 > goal2):
print(team1)
else:
print(team2)
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,689,767,183 | 2,147,483,647 | Python 3 | OK | TESTS | 5 | 30 | 0 | print(25)
| Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
print(25)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,630,847,422 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 6,963,200 | t,s = map(int,input().split())
a = list(map(int,input().split()))
b = 1
if len(a) == 1:print(1)
elif a[-1] - a[-2] > s:print(0)
else:
for i in range(t-1,-1,-1):
if a[i] - a[i-1] > s:break
else:b+=1
print(b) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
t,s = map(int,input().split())
a = list(map(int,input().split()))
b = 1
if len(a) == 1:print(1)
elif a[-1] - a[-2] > s:print(0)
else:
for i in range(t-1,-1,-1):
if a[i] - a[i-1] > s:break
else:b+=1
print(b)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
632 | F | Magic Matrix | PROGRAMMING | 2,400 | [
"brute force",
"divide and conquer",
"graphs",
"matrices",
"trees"
] | null | null | You're given a matrix *A* of size *n*<=×<=*n*.
Let's call the matrix with nonnegative elements magic if it is symmetric (so *a**ij*<==<=*a**ji*), *a**ii*<==<=0 and *a**ij*<=≤<=*max*(*a**ik*,<=*a**jk*) for all triples *i*,<=*j*,<=*k*. Note that *i*,<=*j*,<=*k* do not need to be distinct.
Determine if the matrix is mag... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2500) — the size of the matrix *A*.
Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=<<=109) — the elements of the matrix *A*.
Note that the given matrix not necessarily is symmetric and can be arbitrary. | Print ''MAGIC" (without quotes) if the given matrix *A* is magic. Otherwise print ''NOT MAGIC". | [
"3\n0 1 2\n1 0 2\n2 2 0\n",
"2\n0 1\n2 3\n",
"4\n0 1 2 3\n1 0 3 4\n2 3 0 5\n3 4 5 0\n"
] | [
"MAGIC\n",
"NOT MAGIC\n",
"NOT MAGIC\n"
] | none | 0 | [
{
"input": "3\n0 1 2\n1 0 2\n2 2 0",
"output": "MAGIC"
},
{
"input": "2\n0 1\n2 3",
"output": "NOT MAGIC"
},
{
"input": "4\n0 1 2 3\n1 0 3 4\n2 3 0 5\n3 4 5 0",
"output": "NOT MAGIC"
},
{
"input": "5\n0 2 5 9 5\n2 0 5 9 5\n5 5 0 9 4\n9 9 9 0 9\n5 5 4 9 0",
"output": "MAGI... | 1,689,111,835 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 5,000 | 415,436,800 | import sys
readline=sys.stdin.readline
from collections import defaultdict
N=int(readline())
A=[list(map(int,readline().split())) for i in range(N)]
idx=defaultdict(list)
for i in range(N):
for j in range(N):
idx[A[i][j]].append((i,j))
ans="MAGIC"
BS=[0]*N
bit=(1<<N)-1
for a in sorted(list(idx... | Title: Magic Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a matrix *A* of size *n*<=×<=*n*.
Let's call the matrix with nonnegative elements magic if it is symmetric (so *a**ij*<==<=*a**ji*), *a**ii*<==<=0 and *a**ij*<=≤<=*max*(*a**ik*,<=*a**jk*) for all triples *i*,... | ```python
import sys
readline=sys.stdin.readline
from collections import defaultdict
N=int(readline())
A=[list(map(int,readline().split())) for i in range(N)]
idx=defaultdict(list)
for i in range(N):
for j in range(N):
idx[A[i][j]].append((i,j))
ans="MAGIC"
BS=[0]*N
bit=(1<<N)-1
for a in sorte... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,696,441,691 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n=input()
if n[-1]=='6':
print("YES")
else:
print("NO") | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n=input()
if n[-1]=='6':
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
76 | A | Gift | PROGRAMMING | 2,200 | [
"dsu",
"graphs",
"sortings",
"trees"
] | A. Gift | 2 | 256 | The kingdom of Olympia consists of *N* cities and *M* bidirectional roads. Each road connects exactly two cities and two cities can be connected with more than one road. Also it possible that some roads connect city with itself making a loop.
All roads are constantly plundered with bandits. After a while bandits becam... | The first line of the input contains two integers *N* and *M* (2<=≤<=*N*<=≤<=200, 1<=≤<=*M*<=≤<=50<=000) — the number of cities and the number of roads, respectively. The second line contains two integers *G* and *S* (1<=≤<=*G*,<=*S*<=≤<=109) — the prices of gold and silver coins in tugriks. The following *M* lines con... | The output should contain the minimal cost of the gift in Olympian tugriks. If there is no gift that satisfies the given requirements output . | [
"3 3\n2 1\n1 2 10 15\n1 2 4 20\n1 3 5 1\n"
] | [
"30\n"
] | none | 0 | [
{
"input": "3 3\n2 1\n1 2 10 15\n1 2 4 20\n1 3 5 1",
"output": "30"
}
] | 1,465,930,272 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 4,608,000 | t=int(input())
for i in range(t) :
n,m,b=[int(j) for j in input().split()]
skills={}
times=[]
for j in range(n) :
xj,yj=[int(k) for k in input().split()]
if xj not in times :
skills[xj]=[yj]
else :
skills[xj].append(yj)
times.append(xj)
... | Title: Gift
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The kingdom of Olympia consists of *N* cities and *M* bidirectional roads. Each road connects exactly two cities and two cities can be connected with more than one road. Also it possible that some roads connect city with itself making... | ```python
t=int(input())
for i in range(t) :
n,m,b=[int(j) for j in input().split()]
skills={}
times=[]
for j in range(n) :
xj,yj=[int(k) for k in input().split()]
if xj not in times :
skills[xj]=[yj]
else :
skills[xj].append(yj)
times.a... | -1 | MatrixStudio/Codeforces-Python-Submissions |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,620,743,763 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 6,963,200 | m,n,d=map(int,input().split())
l=[]
for i in range(m):
c=[int(i) for i in input().split()]
for k in c:
l.append(k)
#print(l)
s=sorted(l)
#print(s)
ans=10**8
z=0
for i in range(s[0],s[-1]+1):
key=i
ct=0
f=0
for j in range(len(s)):
if abs(key-s[j])%d!=0:
... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
m,n,d=map(int,input().split())
l=[]
for i in range(m):
c=[int(i) for i in input().split()]
for k in c:
l.append(k)
#print(l)
s=sorted(l)
#print(s)
ans=10**8
z=0
for i in range(s[0],s[-1]+1):
key=i
ct=0
f=0
for j in range(len(s)):
if abs(key-s[j... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contai... | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10... | 1,609,834,807 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 778 | 18,227,200 | from collections import deque
import sys
input = sys.stdin.readline
xadj = [0, 0, -1, 1, -1, -1, 1, 1]
yadj = [1, -1, 0, 0, -1, 1, -1, 1]
res, vis = set(), dict()
x0, y0, x1, y1, = map(int, input().split())
n = int(input())
for seg in range(n):
r, a, b, = map(int, input().split())
for c in range(a, ... | Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with int... | ```python
from collections import deque
import sys
input = sys.stdin.readline
xadj = [0, 0, -1, 1, -1, -1, 1, 1]
yadj = [1, -1, 0, 0, -1, 1, -1, 1]
res, vis = set(), dict()
x0, y0, x1, y1, = map(int, input().split())
n = int(input())
for seg in range(n):
r, a, b, = map(int, input().split())
for c in... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ... | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1... | 1,676,205,658 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | def main():
a = input()
b = input()
map = {}
for i in range(len(b) - len(a) + 1):
subb = b[i : i + len(a)]
if subb in map: map[subb] += 1
else: map[subb] = 1
for j in (map.keys()):
for i in range(len(a)):
distance += (abs(int(j[i]) - int(a[... | Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de... | ```python
def main():
a = input()
b = input()
map = {}
for i in range(len(b) - len(a) + 1):
subb = b[i : i + len(a)]
if subb in map: map[subb] += 1
else: map[subb] = 1
for j in (map.keys()):
for i in range(len(a)):
distance += (abs(int(j[i]... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
343 | A | Rational Resistance | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil... | The single input line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists. | Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier. | [
"1 1\n",
"3 2\n",
"199 200\n"
] | [
"1\n",
"3\n",
"200\n"
] | In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6... | 500 | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "199 200",
"output": "200"
},
{
"input": "1 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "21 8",
"output": "7... | 1,591,673,013 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 218 | 307,200 | def gcd(a,b):
return 0 if b == 0 else a//b + gcd(b, a%b)
a, b = (int(x) for x in input().split())
print(gcd(a,b)) | Title: Rational Resistance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R... | ```python
def gcd(a,b):
return 0 if b == 0 else a//b + gcd(b, a%b)
a, b = (int(x) for x in input().split())
print(gcd(a,b))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,647,606,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def factor(num):
l1 = []
for i in range(1, num+1):
if num % i == 0:
l1.append(i)
return l1
def GCD(p, q):
l1 = factor(p)
l2 = factor(q)
gcd = -1000
for i in l1:
for j in l2:
if i == j:
gcd = i
return gcd
y, w ... | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
def factor(num):
l1 = []
for i in range(1, num+1):
if num % i == 0:
l1.append(i)
return l1
def GCD(p, q):
l1 = factor(p)
l2 = factor(q)
gcd = -1000
for i in l1:
for j in l2:
if i == j:
gcd = i
return gcd
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,678,234,075 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 21 | 62 | 0 | n = int(input())
a = int(input())
b = int(input())
c = int(input())
if a > c < b and a != c != b:
print(min(a, b) + c * (n - 2))
else:
print(min(a, b) * (n - 1))
| Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if a > c < b and a != c != b:
print(min(a, b) + c * (n - 2))
else:
print(min(a, b) * (n - 1))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,674,420,237 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 62 | 1,536,000 | n, m = map(int, input().split())
on = set()
for _ in range(n):
nums = list(map(int, input().split()))
for i in range(1, len(nums)):
on.add(nums[i])
print("YES" if len(on) == m else "NO") | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n, m = map(int, input().split())
on = set()
for _ in range(n):
nums = list(map(int, input().split()))
for i in range(1, len(nums)):
on.add(nums[i])
print("YES" if len(on) == m else "NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,586,503,995 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 307,200 | n = int(input())
a = list(map(int, input().split()))
b = max(a) + min(a)
for i in range(n):
for j in range(n):
if a[i] + a[j] == b and i != j:
print(i + 1, j + 1)
a.remove(a[i])
a.insert(i, 0)
a.remove(a[j])
a.insert(j, 0)
| Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
n = int(input())
a = list(map(int, input().split()))
b = max(a) + min(a)
for i in range(n):
for j in range(n):
if a[i] + a[j] == b and i != j:
print(i + 1, j + 1)
a.remove(a[i])
a.insert(i, 0)
a.remove(a[j])
a.insert(j, 0)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25... | 1,662,462,856 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 45,977,600 | n=int(input())
m=int(input())
y=m%pow(2,n)
print(y)
| Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" prob... | ```python
n=int(input())
m=int(input())
y=m%pow(2,n)
print(y)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different fl... | The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively.
The ... | Print $q$ integers, one per line — the answers for the queries. | [
"5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n"
] | [
"7\n5\n4\n"
] | In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit.
In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in th... | 0 | [
{
"input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3",
"output": "7\n5\n4"
},
{
"input": "2 2 0 1 1\n\n1\n1\n1 2 2 2",
"output": "3"
},
{
"input": "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3",
"output": "6\n4\n3\n5\n4"
},
{
"input": "10 10 1 8 4\n10\n... | 1,547,816,087 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | n = int(input())
# if n >= 100:
# print(n//100+n % 20+n )
s=0
a100=n //100
s=s+a100
n=n-a100*100
a20=n //20
n=n-a20*20
a10=n//10
n=n-a10*10
a5=n//5
n=n-a5*5
print (n+a100+a20+a10+a5)
# else:
# n=n
# print(10 % 3)
# print(11 % 10)
# print(1123425 % 10)
# print(1123429 % 10)
# print(35... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerat... | ```python
n = int(input())
# if n >= 100:
# print(n//100+n % 20+n )
s=0
a100=n //100
s=s+a100
n=n-a100*100
a20=n //20
n=n-a20*20
a10=n//10
n=n-a10*10
a5=n//5
n=n-a5*5
print (n+a100+a20+a10+a5)
# else:
# n=n
# print(10 % 3)
# print(11 % 10)
# print(1123425 % 10)
# print(1123429 % 10)
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 0 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,039,009 | 1,109 | Python 3 | OK | TESTS | 32 | 62 | 5,529,600 | a,b,c,d=map(int,input().split())
n=max(c,d)
v=min(2*c,2*d)
if (v-n)>=0 and n<2*b:
razm=n
if razm < 2*b and 2*b>d*2 and 2*b>c*2:
print(2*a,2*b,razm)
else:
print(-1)
else:
print(-1)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can cli... | ```python
a,b,c,d=map(int,input().split())
n=max(c,d)
v=min(2*c,2*d)
if (v-n)>=0 and n<2*b:
razm=n
if razm < 2*b and 2*b>d*2 and 2*b>c*2:
print(2*a,2*b,razm)
else:
print(-1)
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
267 | A | Subtractions | PROGRAMMING | 900 | [
"math",
"number theory"
] | null | null | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). | Print the sought number of operations for each pair on a single line. | [
"2\n4 17\n7 987654321\n"
] | [
"8\n141093479\n"
] | none | 500 | [
{
"input": "2\n4 17\n7 987654321",
"output": "8\n141093479"
},
{
"input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321",
"output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479... | 1,380,967,994 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | n=int(input())
y=[]
for x in range(n):
y.append(input())
for x in y:
noop=0
lst1=x.split()
lst1=[int(p) for p in lst1]
ma=max(lst1)
mi=min(lst1)
while(ma!=0 and mi!=0):
b=ma//mi
ma=ma-b*mi
... | Title: Subtractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one o... | ```python
n=int(input())
y=[]
for x in range(n):
y.append(input())
for x in y:
noop=0
lst1=x.split()
lst1=[int(p) for p in lst1]
ma=max(lst1)
mi=min(lst1)
while(ma!=0 and mi!=0):
b=ma//mi
ma=ma-b*mi
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
876 | B | Divisiblity of Differences | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=... | If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them... | [
"3 2 3\n1 8 4\n",
"3 3 3\n1 8 4\n",
"4 3 5\n2 7 7 7\n"
] | [
"Yes\n1 4 ",
"No",
"Yes\n2 7 7 "
] | none | 1,000 | [
{
"input": "3 2 3\n1 8 4",
"output": "Yes\n1 4 "
},
{
"input": "3 3 3\n1 8 4",
"output": "No"
},
{
"input": "4 3 5\n2 7 7 7",
"output": "Yes\n2 7 7 "
},
{
"input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825",
"output":... | 1,655,310,808 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 264 | 24,268,800 | n, k, m = map(int, input().split())
lst = list(map(int, input().split()))
d = {}
for i in lst:
r = i % m
if r not in d:
d[r] = [i]
else:
d[r].append(i)
if len(d[r]) == k:
print("Yes")
print(*d[r])
exit()
print("No")
| Title: Divisiblity of Differences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be re... | ```python
n, k, m = map(int, input().split())
lst = list(map(int, input().split()))
d = {}
for i in lst:
r = i % m
if r not in d:
d[r] = [i]
else:
d[r].append(i)
if len(d[r]) == k:
print("Yes")
print(*d[r])
exit()
print("No")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage... | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\n... | 1,619,065,344 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 409,600 | from sys import *
from math import *
from sys import stdin,stdout
from collections import *
int_arr = lambda : list(map(int,stdin.readline().strip().split()))
str_arr = lambda :list(map(str,stdin.readline().split()))
get_str = lambda : map(str,stdin.readline().strip().split())
get_int = lambda: map(int,stdin.r... | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
from sys import *
from math import *
from sys import stdin,stdout
from collections import *
int_arr = lambda : list(map(int,stdin.readline().strip().split()))
str_arr = lambda :list(map(str,stdin.readline().split()))
get_str = lambda : map(str,stdin.readline().strip().split())
get_int = lambda: map(i... | 3.960737 | MatrixStudio/Codeforces-Python-Submissions |
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,587,121,053 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 342 | 1,228,800 | n=int(input())
l=list(map(int,input().split()))
b=True
if n==2:
if l[0]==l[1]:
b=False
if n>2:
for i in range(n):
count=0
for j in range(n):
if l[i]==l[j]:
count+=1
if n<(2*count-1):
b=False
if b:
print("YES")
else:
... | 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())
l=list(map(int,input().split()))
b=True
if n==2:
if l[0]==l[1]:
b=False
if n>2:
for i in range(n):
count=0
for j in range(n):
if l[i]==l[j]:
count+=1
if n<(2*count-1):
b=False
if b:
print("YES")
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,632,127,870 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 248 | 12,185,600 | import sys
import os.path
if(os.path.exists('input.txt')) :
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
depth = 1000005
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda: list(minp())
minp = lam... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
import sys
import os.path
if(os.path.exists('input.txt')) :
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
depth = 1000005
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda: list(minp())
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,572,914,776 | 976 | Python 3 | WRONG_ANSWER | TESTS | 51 | 280 | 409,600 | import collections
import sys
def read_a_integer():
return int(sys.stdin.readline())
def read_a_list(dtype):
return list(map(dtype, sys.stdin.readline().split()))
def main():
r1, r2 = read_a_list(int)
c1, c2 = read_a_list(int)
d1, d2 = read_a_list(int)
if (r1 - c1 + d2) % 2:
... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
import collections
import sys
def read_a_integer():
return int(sys.stdin.readline())
def read_a_list(dtype):
return list(map(dtype, sys.stdin.readline().split()))
def main():
r1, r2 = read_a_list(int)
c1, c2 = read_a_list(int)
d1, d2 = read_a_list(int)
if (r1 - c1 + d... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,673,783,850 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 31 | 0 | dic={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,"g":7,'h':8,'i':9,'j':10,'k':11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,'T':20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}
cnt=0
point=1
s=input()
for ele in s:
cnt+= (min(abs(point-dic[ele]), 26- abs(point-dic[ele])))
point=dic[ele]
print(cnt) | 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
dic={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,"g":7,'h':8,'i':9,'j':10,'k':11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,'T':20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}
cnt=0
point=1
s=input()
for ele in s:
cnt+= (min(abs(point-dic[ele]), 26- abs(point-dic[ele])))
point=dic[ele]
print... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,697,369,360 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n=int(input())
x=input()
x=x.lower()
z='abcdefghijklmnopqrstuvwxyz'
t=True
for i in z:
if i not in x:
t=False
break
if t==True:
print('YES')
else:
print('NO') | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
n=int(input())
x=input()
x=x.lower()
z='abcdefghijklmnopqrstuvwxyz'
t=True
for i in z:
if i not in x:
t=False
break
if t==True:
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
347 | A | Difference Row | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). | Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. | [
"5\n100 -100 50 0 -50\n"
] | [
"100 -50 0 50 -100 \n"
] | In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.
Sequence *x*<sub class="lower-inde... | 500 | [
{
"input": "5\n100 -100 50 0 -50",
"output": "100 -50 0 50 -100 "
},
{
"input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282",
"output": "963 -795 -367 -282 -49 -26 0 764 948 -939 "
},
{
"input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ... | 1,595,297,719 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 20,172,800 | n=int(input())
l=list(map(int,input().strip().split()))
l.sort()
l.reverse()
l[1 : n-1].sort()
print(*l) | Title: Difference Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote ... | ```python
n=int(input())
l=list(map(int,input().strip().split()))
l.sort()
l.reverse()
l[1 : n-1].sort()
print(*l)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,653,407,136 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
L, R = [], []
for _ in range(n):
a, b = list(map(int, input().split()))
L.append(a)
R.append(b)
for i in range(1, n+1):
if (L[i] == min(L)) and (R[i] == max(R))
print(i)
exit()
print(-1) | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n = int(input())
L, R = [], []
for _ in range(n):
a, b = list(map(int, input().split()))
L.append(a)
R.append(b)
for i in range(1, n+1):
if (L[i] == min(L)) and (R[i] == max(R))
print(i)
exit()
print(-1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,693,318,514 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n = int(input())
magnets =(list(int(input()) for _ in range(n)))
groups = 0
for i in range(n-1):
if magnets[i] == magnets[i+1]:
groups = groups +1
print(groups)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
magnets =(list(int(input()) for _ in range(n)))
groups = 0
for i in range(n-1):
if magnets[i] == magnets[i+1]:
groups = groups +1
print(groups)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,549,559,529 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
flights = input()
x = 0
for i in range(len(flights)-1):
if flights[i] == 'S' and flights[i+1] == 'F':
x+=1
if flights[i] == 'F' and flights[i+1] == 'S':
x-=1
if x > 0:
print('YES')
else:
print('NO') | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n = int(input())
flights = input()
x = 0
for i in range(len(flights)-1):
if flights[i] == 'S' and flights[i+1] == 'F':
x+=1
if flights[i] == 'F' and flights[i+1] == 'S':
x-=1
if x > 0:
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,642,580,642 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 17,817,600 | n = int(input())
p = list(map(int,input().split()))
d = 0
h=[]
while d < n:
h.append(p[d])
d += 1
def sort(x):
m = len(x)
for k in range(0,m):
min = k
for i in range(k+1,m):
if x[min] > x[i]:
min = i
t = x[k]
x[k] = x[min]
... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
p = list(map(int,input().split()))
d = 0
h=[]
while d < n:
h.append(p[d])
d += 1
def sort(x):
m = len(x)
for k in range(0,m):
min = k
for i in range(k+1,m):
if x[min] > x[i]:
min = i
t = x[k]
x[k] = x[m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he giv... | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c*... | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input... | 1,430,226,770 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 217 | 26,828,800 | def dfs(p, f, gr, used):
if p == f:
return 1
if used[p]:
return 0
used[p] = 1
for v in gr[p]:
if dfs(v, f, gr, used):
return 1
return 0
def check(gr, u, v):
used = [0] * len(gr)
return dfs(u, v, gr, used)
n, m = (int(x) for x in input().split())
cgr = [[[] for j in range(n)] for _ in range(m)]
for i i... | Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting v... | ```python
def dfs(p, f, gr, used):
if p == f:
return 1
if used[p]:
return 0
used[p] = 1
for v in gr[p]:
if dfs(v, f, gr, used):
return 1
return 0
def check(gr, u, v):
used = [0] * len(gr)
return dfs(u, v, gr, used)
n, m = (int(x) for x in input().split())
cgr = [[[] for j in range(n)] for _ in range(m... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,647,773,359 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def Jzhuu(l,m,n):#1 3 1 4 2
for i in range(len(l)):
l[i]=l[i]//m
maxi=max(l)
res=0
for i in range(len(l)):
if l[i]==maxi:
if i>res:
res=i
return res
n,m=input().split()
l=[int(i) for i in input().split()]
result=... | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
def Jzhuu(l,m,n):#1 3 1 4 2
for i in range(len(l)):
l[i]=l[i]//m
maxi=max(l)
res=0
for i in range(len(l)):
if l[i]==maxi:
if i>res:
res=i
return res
n,m=input().split()
l=[int(i) for i in input().split()... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,689,355,013 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n = int(input())
triangular = False
sum = 0
a = 1
while sum < n:
sum += a
a += 1
if sum == n:
triangular = True
break
if triangular:
print("YES")
else:
print("NO")
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n = int(input())
triangular = False
sum = 0
a = 1
while sum < n:
sum += a
a += 1
if sum == n:
triangular = True
break
if triangular:
print("YES")
else:
print("NO")
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,697,538,011 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n=int(input())
c=input()
a=""
for i in range(n-1):
if c[i]!=c[i+1]:
a+=c[i]
print(n-len(a)-1) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n=int(input())
c=input()
a=""
for i in range(n-1):
if c[i]!=c[i+1]:
a+=c[i]
print(n-len(a)-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
7 | D | Palindrome Degree | PROGRAMMING | 2,200 | [
"hashing",
"strings"
] | D. Palindrome Degree | 1 | 256 | String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For examp... | The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. | Output the only number — the sum of the polindrome degrees of all the string's prefixes. | [
"a2A\n",
"abacaba\n"
] | [
"1",
"6"
] | none | 0 | [
{
"input": "a2A",
"output": "1"
},
{
"input": "abacaba",
"output": "6"
},
{
"input": "CCeCeCCCee",
"output": "4"
},
{
"input": "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop",
"output": "3"
},
{
"input": "odri... | 1,462,978,076 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 77,209,600 | __author__ = 'Utena'
from sys import *
def input():
return stdin.readline()
s='0'+input()
n=len(s)
l=r=0
e=1
t=0
d=[0 for i in range(n+1)]
for i in range(1,n):
l=(l*103+ord(s[i]))%1000007
r=(r+ord(s[i])*e)%1000007
e=(e*103)%1000007
if l==r:
d[i]=d[i//2]+1
t+=d[i]
p... | Title: Palindrome Degree
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome.
Let's call the pa... | ```python
__author__ = 'Utena'
from sys import *
def input():
return stdin.readline()
s='0'+input()
n=len(s)
l=r=0
e=1
t=0
d=[0 for i in range(n+1)]
for i in range(1,n):
l=(l*103+ord(s[i]))%1000007
r=(r+ord(s[i])*e)%1000007
e=(e*103)%1000007
if l==r:
d[i]=d[i//2]+1
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,697,537,907 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | s=input()
if(s==s.upper()):
print(s.capitalize())
else:
w=s[0]
w1=s[1]
if(w==w.lower()):
if(w1==w1.upper()):
print(s.capitalize())
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
s=input()
if(s==s.upper()):
print(s.capitalize())
else:
w=s[0]
w1=s[1]
if(w==w.lower()):
if(w1==w1.upper()):
print(s.capitalize())
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,676,432,274 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 13 | 46 | 0 | n = int(input())
l = input();s = 0
for i in range(n - 2):
if l[i] == l[i + 1] == l[i + 2] == 'x':
s += 1
print(s)
| Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
n = int(input())
l = input();s = 0
for i in range(n - 2):
if l[i] == l[i + 1] == l[i + 2] == 'x':
s += 1
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,504,025,624 | 6,524 | Python 3 | WRONG_ANSWER | CHALLENGES | 0 | 62 | 0 | #
tmp = list(map(int, input().split()))
l = tmp[0]
r = tmp[1]
x = tmp[2]
y = tmp[3]
k = tmp[4]
# (l,r,x,y,k) = list(map(int, input().split()))
b1 = x
b2 = y
a1 = b1 * k
a2 = b2 * k
# print("YES")
print("YES") if (l <= a1 and a1 <= r) or (l <= a1 and a1 <= r) else print("NO")
| 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
#
tmp = list(map(int, input().split()))
l = tmp[0]
r = tmp[1]
x = tmp[2]
y = tmp[3]
k = tmp[4]
# (l,r,x,y,k) = list(map(int, input().split()))
b1 = x
b2 = y
a1 = b1 * k
a2 = b2 * k
# print("YES")
print("YES") if (l <= a1 and a1 <= r) or (l <= a1 and a1 <= r) else print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,595,448,909 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 280 | 20,172,800 | n, m = map(int, input().split())
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53]
ind = primes.index(n)
if primes[ind+1] == m:
print('YES')
else:
print('NO') | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n, m = map(int, input().split())
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53]
ind = primes.index(n)
if primes[ind+1] == m:
print('YES')
else:
print('NO')
``` | 3.892425 | MatrixStudio/Codeforces-Python-Submissions |
574 | A | Bear and Elections | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate ... | Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. | [
"5\n5 1 11 2 8\n",
"4\n1 8 8 8\n",
"2\n7 6\n"
] | [
"4\n",
"6\n",
"0\n"
] | In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate ... | 500 | [
{
"input": "5\n5 1 11 2 8",
"output": "4"
},
{
"input": "4\n1 8 8 8",
"output": "6"
},
{
"input": "2\n7 6",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "10\n100 200 57 99 1 1000 200 200 200 500",
"output": "451"
},
{
"input": "16\... | 1,440,877,986 | 666 | PyPy 3 | OK | TESTS | 35 | 108 | 307,200 | n = int(input())
a = list(map(int, input().split()))
cnt = 0
while not (max(a) == a[0]):
a[a.index(max(a))] -= 1
a[0] += 1
cnt += 1
if a.count(max(a)) != 1:
cnt += 1
print(cnt) | Title: Bear and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for e... | ```python
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while not (max(a) == a[0]):
a[a.index(max(a))] -= 1
a[0] += 1
cnt += 1
if a.count(max(a)) != 1:
cnt += 1
print(cnt)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,663,154,730 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 109 | 1,536,000 | def solve():
n = [int(n) for n in input().split(" ", 2)]
x = [int(x) for x in input().split(" ", n[0])]
max_team = n[0] // 3 * 3
count = 0
i = 0
while i < len(x) and count != max_team:
if x[i] + n[1] <= 5:
count += 1
i += 1
return count // 3
print(s... | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
def solve():
n = [int(n) for n in input().split(" ", 2)]
x = [int(x) for x in input().split(" ", n[0])]
max_team = n[0] // 3 * 3
count = 0
i = 0
while i < len(x) and count != max_team:
if x[i] + n[1] <= 5:
count += 1
i += 1
return count // 3
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
5 | E | Bindian Signalizing | PROGRAMMING | 2,400 | [
"data structures"
] | E. Bindian Signalizing | 4 | 256 | Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by *n* hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night.
In case of any danger the watchman could make a fire on the hill. One watchman co... | The first line of the input data contains an integer number *n* (3<=≤<=*n*<=≤<=106), *n* — the amount of hills around the capital. The second line contains *n* numbers — heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. | Print the required amount of pairs. | [
"5\n1 2 4 5 3\n"
] | [
"7\n"
] | none | 0 | [
{
"input": "5\n1 2 4 5 3",
"output": "7"
},
{
"input": "3\n2118 2118 2118",
"output": "3"
},
{
"input": "3\n2221 1976 2221",
"output": "3"
},
{
"input": "3\n140 989 2895",
"output": "3"
},
{
"input": "4\n2440 2440 2440 2440",
"output": "6"
},
{
"input"... | 1,463,091,888 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 2,464 | 80,384,000 | #!/usr/bin/env python
def main():
n = int(input())
hill = tuple(map(int, input().split()))
pairs = 0
highest, at = max((h, k) for k, h in enumerate(hill))
last = highest
count = 0
previous = list()
push = previous.append
pop = previous.pop
for at in range(at - 1, at - n, -1... | Title: Bindian Signalizing
Time Limit: 4 seconds
Memory Limit: 256 megabytes
Problem Description:
Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by *n* hills, forming a circle. On each hill there was a watchman, who watched the neighbourh... | ```python
#!/usr/bin/env python
def main():
n = int(input())
hill = tuple(map(int, input().split()))
pairs = 0
highest, at = max((h, k) for k, h in enumerate(hill))
last = highest
count = 0
previous = list()
push = previous.append
pop = previous.pop
for at in range(at - 1, ... | 3.542273 | MatrixStudio/Codeforces-Python-Submissions |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,596,261,825 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 21,401,600 | n,m = map(int,input().split())
i=1
while(m>=0):
z=m
m -= i
i+=1
if i>n:
i=1
print(z) | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n,m = map(int,input().split())
i=1
while(m>=0):
z=m
m -= i
i+=1
if i>n:
i=1
print(z)
``` | 3.890136 | MatrixStudio/Codeforces-Python-Submissions |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,674,579,633 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | lists=list(map(int,input().split()))
x=(max(lists)+min(lists)//2
s=abs(lists[0]-x)+abs(lists[1]-x)+abs(lists[2]-x)
print(s) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
lists=list(map(int,input().split()))
x=(max(lists)+min(lists)//2
s=abs(lists[0]-x)+abs(lists[1]-x)+abs(lists[2]-x)
print(s)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,672,576,971 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 1,308 | 8,089,600 | def uppper_bound(arr, x):
l = 0
r = len(arr) - 1
while(l <= r):
m = (l+r)//2
if arr[m] <= x:
l = m + 1
else:
r = m - 1
return l
n,d = map(int, input().split())
x_list = input().split()
x_list = [int(item) for item in x_list]
sum = 0
... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
def uppper_bound(arr, x):
l = 0
r = len(arr) - 1
while(l <= r):
m = (l+r)//2
if arr[m] <= x:
l = m + 1
else:
r = m - 1
return l
n,d = map(int, input().split())
x_list = input().split()
x_list = [int(item) for item in x_list]
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
176 | B | Word Cut | PROGRAMMING | 1,700 | [
"dp"
] | null | null | Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w*<==<=*xy*. A split operation is transforming word *w*<==<=*xy* into word *u*<==<=*yx*. For ex... | The first line contains a non-empty word *start*, the second line contains a non-empty word *end*. The words consist of lowercase Latin letters. The number of letters in word *start* equals the number of letters in word *end* and is at least 2 and doesn't exceed 1000 letters.
The third line contains integer *k* (0<=≤<... | Print a single number — the answer to the problem. As this number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"ab\nab\n2\n",
"ababab\nababab\n1\n",
"ab\nba\n2\n"
] | [
"1\n",
"2\n",
"0\n"
] | The sought way in the first sample is:
ab → a|b → ba → b|a → ab
In the second sample the two sought ways are:
- ababab → abab|ab → ababab - ababab → ab|abab → ababab | 1,000 | [
{
"input": "ab\nab\n2",
"output": "1"
},
{
"input": "ababab\nababab\n1",
"output": "2"
},
{
"input": "ab\nba\n2",
"output": "0"
},
{
"input": "aaa\naaa\n0",
"output": "1"
},
{
"input": "hi\nhi\n1",
"output": "0"
},
{
"input": "abcd\ncbad\n5",
"outp... | 1,694,353,508 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 90 | 124 | 1,740,800 | class Solution:
def numberOfWays(self, s: str, t: str, k: int) -> int:
mod=10**9+7
n=len(s)
v=self.kmp(s+s,t)
g=[[v-1,v],[n-v,n-1-v]]
f=self.qmi(k,g)
if s==t:
return f[0][0]
else:
return f[0][1]
def kmp(self,s,p... | Title: Word Cut
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w... | ```python
class Solution:
def numberOfWays(self, s: str, t: str, k: int) -> int:
mod=10**9+7
n=len(s)
v=self.kmp(s+s,t)
g=[[v-1,v],[n-v,n-1-v]]
f=self.qmi(k,g)
if s==t:
return f[0][0]
else:
return f[0][1]
def km... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,632,074,369 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 122 | 6,758,400 | n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = 0
for i in l:
if i >= 0:
break
s += i
s *= -1
print(s) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = 0
for i in l:
if i >= 0:
break
s += i
s *= -1
print(s)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,686,299,642 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | nm = input()
n,m = int(nm.split()[0]),int(nm.split()[1])
nums = sorted([int(i) for i in input().split()])
print(abs(sum((nums[:m])))) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
nm = input()
n,m = int(nm.split()[0]),int(nm.split()[1])
nums = sorted([int(i) for i in input().split()])
print(abs(sum((nums[:m]))))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
825 | E | Minimal Labels | PROGRAMMING | 2,300 | [
"data structures",
"dfs and similar",
"graphs",
"greedy"
] | null | null | You are given a directed acyclic graph with *n* vertices and *m* edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.
You should assign labels to all vertices in such a way that:
- Labels form a valid permutation of length *n* — an integer sequence such that each ... | The first line contains two integer numbers *n*, *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105).
Next *m* lines contain two integer numbers *v* and *u* (1<=≤<=*v*,<=*u*<=≤<=*n*,<=*v*<=≠<=*u*) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges. | Print *n* numbers — lexicographically smallest correct permutation of labels of vertices. | [
"3 3\n1 2\n1 3\n3 2\n",
"4 5\n3 1\n4 1\n2 3\n3 4\n2 4\n",
"5 4\n3 1\n2 1\n2 3\n4 5\n"
] | [
"1 3 2 \n",
"4 1 2 3 \n",
"3 1 2 4 5 \n"
] | none | 0 | [
{
"input": "3 3\n1 2\n1 3\n3 2",
"output": "1 3 2 "
},
{
"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4",
"output": "4 1 2 3 "
},
{
"input": "5 4\n3 1\n2 1\n2 3\n4 5",
"output": "3 1 2 4 5 "
},
{
"input": "2 1\n2 1",
"output": "2 1 "
},
{
"input": "5 10\n5 2\n4 1\n2 1\n3 ... | 1,687,784,931 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | import heapq
n, m = map(int, input().split())
in_degree = [0] * (n+1)
graph = [[] for _ in range(n+1)]
for _ in range(m):
u, v = map(int, input().split())
graph[u].append(v)
in_degree[v] += 1
hp = []
for i in range(1, n+1):
if in_degree[i] == 0:
hp.append(i)
heapq.heapify(hp)... | Title: Minimal Labels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a directed acyclic graph with *n* vertices and *m* edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.
You should assign labels to all vertices in such... | ```python
import heapq
n, m = map(int, input().split())
in_degree = [0] * (n+1)
graph = [[] for _ in range(n+1)]
for _ in range(m):
u, v = map(int, input().split())
graph[u].append(v)
in_degree[v] += 1
hp = []
for i in range(1, n+1):
if in_degree[i] == 0:
hp.append(i)
heapq.h... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,591,361,036 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | def amr(r,x1,y1,x2,y2):
x = x1-x2
y = y1-y2
dist = (x**2 + y**2)**(.5)
i = 0
while dist > 0:
dist -= 2*r
i += 1
return i
a = list(map(int, input().split()))
print(amr(a[0],a[1],a[2],a[3],a[4])) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
def amr(r,x1,y1,x2,y2):
x = x1-x2
y = y1-y2
dist = (x**2 + y**2)**(.5)
i = 0
while dist > 0:
dist -= 2*r
i += 1
return i
a = list(map(int, input().split()))
print(amr(a[0],a[1],a[2],a[3],a[4]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,670,932,146 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | import sys
input = sys.stdin.readline
r = range
p = print
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return [_ for _ in (map(int,input().split()))]
inp()
a = invr()
y = dict()
max =... | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
import sys
input = sys.stdin.readline
r = range
p = print
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return [_ for _ in (map(int,input().split()))]
inp()
a = invr()
y = dic... | 0 | MatrixStudio/Codeforces-Python-Submissions |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,506,639,819 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 2,000 | 614,400 | nDoors = int(input())
pairs = input()
keys = []
doors = []
answer = 0
for x in range(0, 2 * nDoors - 2, 2):
keys.append(pairs[x])
if pairs[x + 1].lower() in keys:
del keys[keys.index(pairs[x + 1].lower())]
else:
answer += 1
print(answer)
| Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
nDoors = int(input())
pairs = input()
keys = []
doors = []
answer = 0
for x in range(0, 2 * nDoors - 2, 2):
keys.append(pairs[x])
if pairs[x + 1].lower() in keys:
del keys[keys.index(pairs[x + 1].lower())]
else:
answer += 1
print(answer)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,530,383,893 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | n,m = map(int,input().split())
l = []
for i in range(1,n+1):
x,y = map(int,input().split())
l.append(x)
l.append(y)
if(l[0]!=0 or l[2*n-1]<m):
print('NO')
exit(0)
for i in range(2,2*n):
if(l[i]>l[i-1]):
print('NO')
exit(0)
print('YES') | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n,m = map(int,input().split())
l = []
for i in range(1,n+1):
x,y = map(int,input().split())
l.append(x)
l.append(y)
if(l[0]!=0 or l[2*n-1]<m):
print('NO')
exit(0)
for i in range(2,2*n):
if(l[i]>l[i-1]):
print('NO')
exit(0)
print('YES')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,694,107,618 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | def fun(s,a):
if len(s)==0:
return a
if s[0]=='.':
a+='0'
s1=s[1:]
return fun(s1,a)
elif s[0:2]=='-.':
a+='1'
s1=s[2:]
return fun(s1,a)
elif s[0:2]=='--':
a+='2'
s1=s[2:]
return fun(s1,a)
_=input()
a=''
pr... | 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
def fun(s,a):
if len(s)==0:
return a
if s[0]=='.':
a+='0'
s1=s[1:]
return fun(s1,a)
elif s[0:2]=='-.':
a+='1'
s1=s[2:]
return fun(s1,a)
elif s[0:2]=='--':
a+='2'
s1=s[2:]
return fun(s1,a)
_=input()... | 3.9845 | MatrixStudio/Codeforces-Python-Submissions |
340 | D | Bubble Sort Graph | PROGRAMMING | 1,500 | [
"binary search",
"data structures",
"dp"
] | null | null | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with *n* elements *a*1, *a*2, ..., *a**n* in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it *G*) initially has *n* vertices and 0 edges. During Bubble Sort execution, ... | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=105). The next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*). | Output a single integer — the answer to the problem. | [
"3\n3 1 2\n"
] | [
"2\n"
] | Consider the first example. Bubble sort swaps elements 3 and 1. We add edge (1, 3). Permutation is now [1, 3, 2]. Then bubble sort swaps elements 3 and 2. We add edge (2, 3). Permutation is now sorted. We have a graph with 3 vertices and 2 edges (1, 3) and (2, 3). Its maximal independent set is [1, 2]. | 2,000 | [
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "5\n4 2 1 3 5",
"output": "3"
},
{
"input": "10\n1 9 8 10 2 3 4 6 5 7",
"output": "6"
},
{
"input": "50\n12 24 42 43 36 3 40 29 7 34 10 13 28 9 35 23 25 21 19 4 20 18 11 38 41 48 6 46 33 17 31 37 2 30 32 44 45 5 47 49 16 15 5... | 1,689,009,940 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 124 | 1,433,600 | def bubbleSortGraph(a):
n = len(a)
graph = [[] for _ in range(n)] # Создание пустого графа с n вершинами
swapped = True
while swapped:
swapped = False
for i in range(n - 1):
if a[i] > a[i + 1]:
graph[a[i] - 1].append(a[i + 1] - 1)
gra... | Title: Bubble Sort Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with *n* elements *a*1, *a*2, ..., *a**n* in ascending order. He is bored of this so simple algorithm, so he invents his own grap... | ```python
def bubbleSortGraph(a):
n = len(a)
graph = [[] for _ in range(n)] # Создание пустого графа с n вершинами
swapped = True
while swapped:
swapped = False
for i in range(n - 1):
if a[i] > a[i + 1]:
graph[a[i] - 1].append(a[i + 1] - 1)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,584,383,778 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | x,y=map(int,input().split())
a,b=map(int,input().split())
s=abs(x-a)+abs(y-b)
if(s%2==0):
print(s//2)
else:
print(s//2+1)
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
x,y=map(int,input().split())
a,b=map(int,input().split())
s=abs(x-a)+abs(y-b)
if(s%2==0):
print(s//2)
else:
print(s//2+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,584,862,331 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 0 | #q=int(input())
q=1
for _ in range(q):
l,r,k=map(int,input().split())
j=0
ans=[]
while(l<= k**j and k**j<=r):
ans.append(k**j)
j+=1
if len(ans)==0:
print(-1)
else:
print(*ans) | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
#q=int(input())
q=1
for _ in range(q):
l,r,k=map(int,input().split())
j=0
ans=[]
while(l<= k**j and k**j<=r):
ans.append(k**j)
j+=1
if len(ans)==0:
print(-1)
else:
print(*ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,679,730,680 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 124 | 0 | n = int(input())
a = [int(x) for x in input().split()]
MAX = a[0]
MIN = a[0]
res = 0
for i in range(1, n):
if a[i] > MAX:
res += 1
MAX = a[i]
if a[i] < MIN:
res += 1
MIN = a[i]
print(res)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
a = [int(x) for x in input().split()]
MAX = a[0]
MIN = a[0]
res = 0
for i in range(1, n):
if a[i] > MAX:
res += 1
MAX = a[i]
if a[i] < MIN:
res += 1
MIN = a[i]
print(res)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
785 | C | Anton and Fairy Tale | PROGRAMMING | 1,600 | [
"binary search",
"math"
] | null | null | Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that ba... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018) — the capacity of the barn and the number of grains that are brought every day. | Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one. | [
"5 2\n",
"8 1\n"
] | [
"4\n",
"5\n"
] | In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens:
- At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. - At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. - ... | 1,500 | [
{
"input": "5 2",
"output": "4"
},
{
"input": "8 1",
"output": "5"
},
{
"input": "32 5",
"output": "12"
},
{
"input": "1024 1024",
"output": "1024"
},
{
"input": "58044 52909",
"output": "53010"
},
{
"input": "996478063 658866858",
"output": "65889... | 1,688,448,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | import math
#常数n代表谷仓容量,m代表每天进货,i,a(具有同等效力)代表天数,k代表每日剩余
n,m=input().split()
k,i=int(n),1
a=1
c=int(m)
#Guess:由于m可能过大,现对m取log(base 2),分别将商部和余部放在b和c中以减少计算量
b=int(math.log2(int(m)))
c=int(m)-int(math.pow(2,b))
def find(k,i,m,n):
while k>0:
if k+int(m)>=int(n):
k=int(n)
else:
k=k+... | Title: Anton and Fairy Tale
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grai... | ```python
import math
#常数n代表谷仓容量,m代表每天进货,i,a(具有同等效力)代表天数,k代表每日剩余
n,m=input().split()
k,i=int(n),1
a=1
c=int(m)
#Guess:由于m可能过大,现对m取log(base 2),分别将商部和余部放在b和c中以减少计算量
b=int(math.log2(int(m)))
c=int(m)-int(math.pow(2,b))
def find(k,i,m,n):
while k>0:
if k+int(m)>=int(n):
k=int(n)
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,512,748,517 | 1,877 | Python 3 | OK | TESTS | 47 | 62 | 5,529,600 | n,k= map(int, input().split())
s = input()
p = []
for i in s:
p+=i
for i in range(k):
m = input().split()
for j in range(int(m[0])-1,int(m[1])):
if p[j]==m[2]:
p[j]=m[3]
s = ''
for i in p:
s+=i
print(s) | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,k= map(int, input().split())
s = input()
p = []
for i in s:
p+=i
for i in range(k):
m = input().split()
for j in range(int(m[0])-1,int(m[1])):
if p[j]==m[2]:
p[j]=m[3]
s = ''
for i in p:
s+=i
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,608,527,023 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 310 | 3,584,000 | n = int(input())
for i in range(n*n//2):
print(i+1,n*n-i) | 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())
for i in range(n*n//2):
print(i+1,n*n-i)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,503,690,960 | 60 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | import math
n = str(input())
digits = list(n)
for i in range(len(digits)):
digits[i] = int(digits[i])
left = digits[:-3]
right = digits[3:]
left_sum = sum(left)
right_sum = sum(right)
delta = left_sum - right_sum
count = 0
if delta != 0: # left sum is bigger
digits = sorted(digits)
if digits[-1] >= delta:
... | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
import math
n = str(input())
digits = list(n)
for i in range(len(digits)):
digits[i] = int(digits[i])
left = digits[:-3]
right = digits[3:]
left_sum = sum(left)
right_sum = sum(right)
delta = left_sum - right_sum
count = 0
if delta != 0: # left sum is bigger
digits = sorted(digits)
if digits[-1] >=... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,474,493,613 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | x, k, n = [int(i) for i in input().split()]
answer = str()
if x >= n:
print(-1)
else:
for i in range(n-x):
if (x+i+1)%k == 0:
answer = answer + ' ' + str(x+i+1)
if len(answer) > 0:
print(answer)
else:
print(-1) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
x, k, n = [int(i) for i in input().split()]
answer = str()
if x >= n:
print(-1)
else:
for i in range(n-x):
if (x+i+1)%k == 0:
answer = answer + ' ' + str(x+i+1)
if len(answer) > 0:
print(answer)
else:
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,677,648,009 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | # 코드포스 472A Design Tutorial: Learn from Math
import sys
put = sys.stdin.readline
n = int(put())
n1 = n // 2
n2 = n - n1
for i in range(n1):
for i1 in range(2, int(n1**0.5)+2):
if not n1 % i1:
break
else:
n1 -= 1
n2 += 1
continue
for i2 in range... | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
# 코드포스 472A Design Tutorial: Learn from Math
import sys
put = sys.stdin.readline
n = int(put())
n1 = n // 2
n2 = n - n1
for i in range(n1):
for i1 in range(2, int(n1**0.5)+2):
if not n1 % i1:
break
else:
n1 -= 1
n2 += 1
continue
for i... | 3 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.