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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,697,047,883 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | import sys
input=sys.stdin.readline
n, k = map(int, input().split())
l = list(map(int, input().split()))
print(sum(1 for i in l if i >= l[k - 1] and i > 0)) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
import sys
input=sys.stdin.readline
n, k = map(int, input().split())
l = list(map(int, input().split()))
print(sum(1 for i in l if i >= l[k - 1] and i > 0))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,616,435,855 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 307,200 | def gcd(x, y):
if x > y:
small = y
else:
small = x
for i in range(1, small+1):
if((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
n,s=int(input()),0
for i in range(2,n):
k=n
while k!=0:
s+=k%i
k//=i
p=gcd(s,n-... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
def gcd(x, y):
if x > y:
small = y
else:
small = x
for i in range(1, small+1):
if((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
n,s=int(input()),0
for i in range(2,n):
k=n
while k!=0:
s+=k%i
k//=i
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
120 | C | Winnie-the-Pooh and honey | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, separated by spaces (1<=≤<=*a**i*<=≤<=100). | Print a single number — how many kilos of honey gets Piglet. | [
"3 3\n15 8 10\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3 3\n15 8 10",
"output": "9"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "3 4\n3 8 2",
"output": "5"
},
{
"input": "3 2\n95 25 49",
"output": "151"
},
{
"input": "3 1\n8 3 2",
"output": "5"
},
{
"input": "5 1\n4 7 9 5 7",
"outpu... | 1,626,834,711 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,656,000 | n,k = map(int,input().split())
l = list(map(int,input().split()))
t = 0
for x in l:
if x < k*3:t += x%k
else:
t+=x - k*3
print(t) | Title: Winnie-the-Pooh and honey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie an... | ```python
n,k = map(int,input().split())
l = list(map(int,input().split()))
t = 0
for x in l:
if x < k*3:t += x%k
else:
t+=x - k*3
print(t)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
233 | B | Non-square Equation | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"math"
] | null | null | Let's consider equation:
where *x*,<=*n* are positive integers, *s*(*x*) is the function, equal to the sum of digits of number *x* in the decimal number system.
You are given an integer *n*, find the smallest positive integer root of equation *x*, or else determine that there are no such roots. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1018) — the equation parameter.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer *x* (*x*<=><=0), that the equation given in the statement holds. | [
"2\n",
"110\n",
"4\n"
] | [
"1\n",
"10\n",
"-1\n"
] | In the first test case *x* = 1 is the minimum root. As *s*(1) = 1 and 1<sup class="upper-index">2</sup> + 1·1 - 2 = 0.
In the second test case *x* = 10 is the minimum root. As *s*(10) = 1 + 0 = 1 and 10<sup class="upper-index">2</sup> + 1·10 - 110 = 0.
In the third test case the equation has no roots. | 1,000 | [
{
"input": "2",
"output": "1"
},
{
"input": "110",
"output": "10"
},
{
"input": "4",
"output": "-1"
},
{
"input": "8",
"output": "2"
},
{
"input": "10000000100000000",
"output": "100000000"
},
{
"input": "10000006999999929",
"output": "99999999"
... | 1,671,723,690 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 1,638,400 | import math
def fact(n):
i=1
l=[]
while i<=math.sqrt(n):
if n%i==0:
l.append(i)
l.append(int(n/i))
i+=1
return l
def sum_digit(n):
n1=str(n)
a=len(n1)
sum1=0
for i in range (0,a):
sum1+=int(n1[i])
return sum1
n=int(... | Title: Non-square Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider equation:
where *x*,<=*n* are positive integers, *s*(*x*) is the function, equal to the sum of digits of number *x* in the decimal number system.
You are given an integer *n*, find the smallest posi... | ```python
import math
def fact(n):
i=1
l=[]
while i<=math.sqrt(n):
if n%i==0:
l.append(i)
l.append(int(n/i))
i+=1
return l
def sum_digit(n):
n1=str(n)
a=len(n1)
sum1=0
for i in range (0,a):
sum1+=int(n1[i])
return sum1... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
244 | B | Undoubtedly Lucky Numbers | PROGRAMMING | 1,600 | [
"bitmasks",
"brute force",
"dfs and similar"
] | null | null | Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==<=4, and *y*<==<=7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer *a* undoubtedly lucky, if... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Polycarpus's number. | Print a single integer that says, how many positive integers that do not exceed *n* are undoubtedly lucky. | [
"10\n",
"123\n"
] | [
"10\n",
"113\n"
] | In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "123",
"output": "113"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "1000",
"output": "352"
},
{
"input": "1000000000",
"output": "40744"
},
{
"input": "999999... | 1,518,695,742 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 5,632,000 | import math
def ncr(n,r):
f = math.factorial
return f(n) // f(r) // f(n-r)
n = int(input())
c = len(str(n))
count=0
for i in range(1,10):
for j in range(1,c):
count+=1
for i in range(1,10):
for j in range(10):
if i!=j:
for k in range(1,c-1):
for l in range(1,k+1):
count += ncr(k, l)
s=str(... | Title: Undoubtedly Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==... | ```python
import math
def ncr(n,r):
f = math.factorial
return f(n) // f(r) // f(n-r)
n = int(input())
c = len(str(n))
count=0
for i in range(1,10):
for j in range(1,c):
count+=1
for i in range(1,10):
for j in range(10):
if i!=j:
for k in range(1,c-1):
for l in range(1,k+1):
count += ncr(k, ... | 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,635,053,851 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 4,505,600 | n,m = map(int,input().split())
bulbs = [0]*m
for i in range(n):
button = list(map(int,input().split()))
for j in range(button[0]):
bulbs[button[j+1]-1] = 1
if bulbs.count(0) == 0:
print("YES")
else:
print("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())
bulbs = [0]*m
for i in range(n):
button = list(map(int,input().split()))
for j in range(button[0]):
bulbs[button[j+1]-1] = 1
if bulbs.count(0) == 0:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,615,539,710 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | from sys import stdin
a, b, c, n = map(int, stdin.readline().split())
val = n - ((a - c) + (b - c)) - c
print(val if val < n and val > 0 else -1) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
from sys import stdin
a, b, c, n = map(int, stdin.readline().split())
val = n - ((a - c) + (b - c)) - c
print(val if val < n and val > 0 else -1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
482 | A | Diverse Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*.
Your task is to find such permutation *p* of length *n*, that the group of number... | The single line of the input contains two space-separated positive integers *n*, *k* (1<=≤<=*k*<=<<=*n*<=≤<=105). | Print *n* integers forming the permutation. If there are multiple answers, print any of them. | [
"3 2\n",
"3 1\n",
"5 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n"
] | By |*x*| we denote the absolute value of number *x*. | 500 | [
{
"input": "3 2",
"output": "1 3 2"
},
{
"input": "3 1",
"output": "1 2 3"
},
{
"input": "5 2",
"output": "1 3 2 4 5"
},
{
"input": "5 4",
"output": "1 5 2 4 3"
},
{
"input": "10 4",
"output": "1 10 2 9 8 7 6 5 4 3"
},
{
"input": "10 3",
"output": ... | 1,657,605,193 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 109 | 14,336,000 | import sys
import math
import collections
import heapq
input=sys.stdin.readline
n,k=(int(i) for i in input().split())
l=[1]
d=0
i=2
j=n
c=1
while(d<k-1):
if(c%2==1):
l.append(j)
j-=1
else:
l.append(i)
i+=1
c+=1
d+=1
if(c%2==0):
for x in range(j,i-... | Title: Diverse Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<... | ```python
import sys
import math
import collections
import heapq
input=sys.stdin.readline
n,k=(int(i) for i in input().split())
l=[1]
d=0
i=2
j=n
c=1
while(d<k-1):
if(c%2==1):
l.append(j)
j-=1
else:
l.append(i)
i+=1
c+=1
d+=1
if(c%2==0):
for x in ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of th... | Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"... | 1,678,972,509 | 2,147,483,647 | PyPy 3 | OK | TESTS | 9 | 62 | 0 | I=input
n,p=map(int,I().split())
a=k=0
for i in [4<len(I())for _ in ' '*n][::-1]:k+=a*p+i*p//2;a=a*2+i
print(k) | Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers sh... | ```python
I=input
n,p=map(int,I().split())
a=k=0
for i in [4<len(I())for _ in ' '*n][::-1]:k+=a*p+i*p//2;a=a*2+i
print(k)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
221 | B | Little Elephant and Numbers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described num... | A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109). | In a single line print an integer — the answer to the problem. | [
"1\n",
"10\n"
] | [
"1\n",
"2\n"
] | none | 1,000 | [
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "47",
"output": "1"
},
{
"input": "100",
"output": "5"
},
{
"input": "128",
"output": "6"
},
{
"input": "2",
"output": "1"
},
{
"input": "17",
"output": "2"
... | 1,416,519,666 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 0 | x=int(input())
digit=""
for i in range(10):
if str(i) in str(x):
digit+=str(i)
counter=0
for i in range(1,x//2+1):
if x%i==0:
for j in str(i):
if j in digit:
counter+=1
break
print(counter+1) | Title: Little Elephant and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least o... | ```python
x=int(input())
digit=""
for i in range(10):
if str(i) in str(x):
digit+=str(i)
counter=0
for i in range(1,x//2+1):
if x%i==0:
for j in str(i):
if j in digit:
counter+=1
break
print(counter+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Felix the Robot is preparing for a probability theory exam. Unfortunately, during the semester, he took a course of the belles-lettres instead of studying the subject, so now he does not know the answer to any of the upcoming exam's questions. One thing is for sure: Felix needs help!
The exam for robots is an online e... | none | none | [] | [] | none | 11,673 | [] | 1,465,741,562 | 19,562 | Python 3 | SKIPPED | PRETESTS | 100 | 77 | 5,222,400 | import sys
a = ["00000","00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010","11011","11100","11101","11110","11111"]
for i in range(32):
print(a[i]*1000)
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Felix the Robot is preparing for a probability theory exam. Unfortunately, during the semester, he took a course of the belles-lettres instead of studying the subject, so now he does not know the answer to any of the upcoming exam... | ```python
import sys
a = ["00000","00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010","11011","11100","11101","11110","11111"]
for i in range(32):
print(a[i]... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,683,057,376 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 0 | import sys
f = sys.stdin.readline()
length = len(f) - 1
f = int(f, base=2)
s = int(sys.stdin.readline(), base=2)
result = f ^ s
result = format(result, 'b')
print(('0'*(length - len(result))) + result) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
import sys
f = sys.stdin.readline()
length = len(f) - 1
f = int(f, base=2)
s = int(sys.stdin.readline(), base=2)
result = f ^ s
result = format(result, 'b')
print(('0'*(length - len(result))) + result)
``` | 3.9845 | MatrixStudio/Codeforces-Python-Submissions |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,381,255,099 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n = input()
t = n[1] + n[0]
if n[3:] >= t:
h = str(int(n[:2]) + 1)
print(h + ':' + h[1] + h[0])
else: print(n[:3] + n[1] + n[0]) | Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
n = input()
t = n[1] + n[0]
if n[3:] >= t:
h = str(int(n[:2]) + 1)
print(h + ':' + h[1] + h[0])
else: print(n[:3] + n[1] + n[0])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege... | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the firs... | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9... | 1,496,839,483 | 1,783 | Python 3 | WRONG_ANSWER | TESTS | 21 | 62 | 307,200 | import sys
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = [0]*n
d = {}
x,y = -1,-1
for i in range(n):
if a[i] == b[i]:
c[i] = a[i]
d[a[i]] = True
e... | Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her... | ```python
import sys
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = [0]*n
d = {}
x,y = -1,-1
for i in range(n):
if a[i] == b[i]:
c[i] = a[i]
d[a[i]] = True ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
937 | B | Vile Grasshoppers | PROGRAMMING | 1,400 | [
"brute force",
"math",
"number theory"
] | null | null | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh... | The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109). | Output the number of the highest suitable branch. If there are none, print -1 instead. | [
"3 6\n",
"3 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | 1,000 | [
{
"input": "3 6",
"output": "5"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "5 50",
"output": "49"
},
{
"input": "944192806 944193066",
"output": "944192807"
},
{
"input": "1000000000 1000000000",
"output":... | 1,526,478,974 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 93 | 7,065,600 | p,y = map(int, input().split())
for b in range(y - int(y % 2 == 0), p, -2):
for i in range(3, min(int(b ** 0.5) + 1, p + 1), 2):
if b % i == 0:
break
else:
print(b)
break
else:
print(-1) | Title: Vile Grasshoppers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor... | ```python
p,y = map(int, input().split())
for b in range(y - int(y % 2 == 0), p, -2):
for i in range(3, min(int(b ** 0.5) + 1, p + 1), 2):
if b % i == 0:
break
else:
print(b)
break
else:
print(-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,687,252,394 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 46 | 0 | pos = input()
if (pos[0] == 'a' or pos[0] == 'h') and (pos[1] == '1' or pos[1] == '8'):
print(3)
elif (pos[0] == 'a' or pos[0] == 'h') or (pos[1] == '1' or pos[1] == '8'):
print(5)
else:
print(8)
| Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
pos = input()
if (pos[0] == 'a' or pos[0] == 'h') and (pos[1] == '1' or pos[1] == '8'):
print(3)
elif (pos[0] == 'a' or pos[0] == 'h') or (pos[1] == '1' or pos[1] == '8'):
print(5)
else:
print(8)
``` | 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,680,504,221 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 156 | 2,867,200 | t = int(input())
ar = []
for i in range(t):
a = int(input())
ar.append(a)
c = 0
for i in range(1,len(ar)-1):
if ar[i] != ar[i-1] and ar[i] != ar[i+1]:
c += 2
elif ar[i] != ar[i-1]:
c += 1
if t == 1:
print(1)
elif c == 1:
print(c+1)
else:
print(c)
| 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
t = int(input())
ar = []
for i in range(t):
a = int(input())
ar.append(a)
c = 0
for i in range(1,len(ar)-1):
if ar[i] != ar[i-1] and ar[i] != ar[i+1]:
c += 2
elif ar[i] != ar[i-1]:
c += 1
if t == 1:
print(1)
elif c == 1:
print(c+1)
else:
pr... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,668,095,225 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 46 | 0 | from math import floor
a, b = map(int, input().split())
d = 0
a1 = a
while a+(a%b) >= b:
d += a / b
a /= b
print(floor(d + a1)) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
from math import floor
a, b = map(int, input().split())
d = 0
a1 = a
while a+(a%b) >= b:
d += a / b
a /= b
print(floor(d + a1))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
825 | B | Five-In-a-Row | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i... | You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed th... | Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. | [
"XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X",
"output": "NO"
},
{
"input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.",
"output": "N... | 1,690,188,034 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 156 | 62 | 0 | x=[]
biao=0
for i in range(10):
y=list(input())
x.append(y)
for i in range(10):
for j in range(6):
if x[i][j]=="X" or x[i][j]==".":
z=[]
for k in range(5):
z.append(x[i][j+k])
if z.count("X")==4 and z.count("O")==0:
biao... | Title: Five-In-a-Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some t... | ```python
x=[]
biao=0
for i in range(10):
y=list(input())
x.append(y)
for i in range(10):
for j in range(6):
if x[i][j]=="X" or x[i][j]==".":
z=[]
for k in range(5):
z.append(x[i][j+k])
if z.count("X")==4 and z.count("O")==0:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
17 | B | Hierarchy | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"greedy",
"shortest paths"
] | B. Hierarchy | 2 | 64 | Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: «employee *a**i* is ready to become a supervisor of emp... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=1000) — amount of employees in the company. The following line contains *n* space-separated numbers *q**j* (0<=≤<=*q**j*<=≤<=106)— the employees' qualifications. The following line contains number *m* (0<=≤<=*m*<=≤<=10000) — amount of received applications. The f... | Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it. | [
"4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5\n",
"3\n1 2 3\n2\n3 1 2\n3 1 3\n"
] | [
"11\n",
"-1\n"
] | In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1. | 0 | [
{
"input": "4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5",
"output": "11"
},
{
"input": "3\n1 2 3\n2\n3 1 2\n3 1 3",
"output": "-1"
},
{
"input": "1\n2\n0",
"output": "0"
},
{
"input": "2\n5 3\n4\n1 2 0\n1 2 5\n1 2 0\n1 2 7",
"output": "0"
},
{
"input": "3\n9 4 5\n5\... | 1,680,543,533 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 528 | 6,553,600 | # imports
import sys
from os import path
from collections import *
from itertools import *
import heapq
from math import *
from typing import List
import re
mod = 1e9+7
oo = float("inf")
# IO
if (path.exists('cf')):
sys.stdin = open("in.txt", "r")
sys.stdout = open("out.txt", "w")
# solut... | Title: Hierarchy
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applicati... | ```python
# imports
import sys
from os import path
from collections import *
from itertools import *
import heapq
from math import *
from typing import List
import re
mod = 1e9+7
oo = float("inf")
# IO
if (path.exists('cf')):
sys.stdin = open("in.txt", "r")
sys.stdout = open("out.txt", "w")
... | 3.819172 | MatrixStudio/Codeforces-Python-Submissions |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,683,197,698 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 102,400 | from sys import stdin, stderr, stdout
from math import *
from bisect import *
from collections import Counter, deque, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush
input = lambda: stdin.buffer.readline().decode().rstrip()
# Solution here
"""
"""
res = []
from itertools import chain,... | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
from sys import stdin, stderr, stdout
from math import *
from bisect import *
from collections import Counter, deque, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush
input = lambda: stdin.buffer.readline().decode().rstrip()
# Solution here
"""
"""
res = []
from itertools imp... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,662,300,598 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n = input()
upper = 0
lower = 0
for i in n :
if i.isupper():
upper+=1
else:
lower +=1
if upper > lower:
n= n.upper()
else:
n =n.lower()
print(n) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
n = input()
upper = 0
lower = 0
for i in n :
if i.isupper():
upper+=1
else:
lower +=1
if upper > lower:
n= n.upper()
else:
n =n.lower()
print(n)
``` | 3.977 | 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,571,510,128 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 280 | 0 | a = input()
V = "AEIOUYaeiouy"
ans = ""
s = 0
for j in range(len(a)-2,-1,-1):
if ( a[j] != " "):
ans = a[j]
break
for i in range(len(V)):
if ( ans == V[i] ):
s = 1
if (s == 1):
print("YES")
else:
print("NO")
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
a = input()
V = "AEIOUYaeiouy"
ans = ""
s = 0
for j in range(len(a)-2,-1,-1):
if ( a[j] != " "):
ans = a[j]
break
for i in range(len(V)):
if ( ans == V[i] ):
s = 1
if (s == 1):
print("YES")
else:
print("NO")
``` | 3.93 | MatrixStudio/Codeforces-Python-Submissions |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,696,409,054 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n = int(input())
m = [4,7,47,74,44,77,444,777,447,474,744,477,747,774]
s = 0
for i in m :
if n % int(i) == 0:
s += 1
if s > 0:
print('YES')
else:
print('NO')
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
m = [4,7,47,74,44,77,444,777,447,474,744,477,747,774]
s = 0
for i in m :
if n % int(i) == 0:
s += 1
if s > 0:
print('YES')
else:
print('NO')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are *n* piles of cows, with the *i*-th pile containing *a**i* cows. During each player's turn, that player calls upon... | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=109).
The second line contains *n* integers, *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=109) describing the initial state of the game. | Output the name of the winning player, either "Kevin" or "Nicky" (without quotes). | [
"2 1\n3 4\n",
"1 2\n3\n"
] | [
"Kevin\n",
"Nicky\n"
] | In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky... | 0 | [
{
"input": "2 1\n3 4",
"output": "Kevin"
},
{
"input": "1 2\n3",
"output": "Nicky"
},
{
"input": "4 5\n20 21 22 25",
"output": "Kevin"
},
{
"input": "5 1\n1 7 7 6 6",
"output": "Kevin"
},
{
"input": "7 1\n8 6 10 10 1 5 8",
"output": "Kevin"
},
{
"input... | 1,691,653,136 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691653136.870704")# 1691653136.8707194 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are *n* piles of cows, with... | ```python
print("_RANDOM_GUESS_1691653136.870704")# 1691653136.8707194
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte... | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2... | 1,498,401,698 | 398 | PyPy 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace CF317
{
internal class Program
{
private static void Main(string[] args)
{
var sr = new InputReader(Console.In);
//... | Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi... | ```python
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace CF317
{
internal class Program
{
private static void Main(string[] args)
{
var sr = new InputReader(Console.In);
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
936 | C | Lock Puzzle | PROGRAMMING | 2,300 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!
Of course, there is a code lock is installed on the safe. The lock... | The first line contains an integer *n*, the length of the strings *s* and *t* (1<=≤<=*n*<=≤<=2<=000).
After that, there are two strings *s* and *t*, consisting of *n* lowercase Latin letters each. | If it is impossible to get string *t* from string *s* using no more than 6100 operations «shift», print a single number <=-<=1.
Otherwise, in the first line output the number of operations *k* (0<=≤<=*k*<=≤<=6100). In the next line output *k* numbers *x**i* corresponding to the operations «shift *x**i*» (0<=≤<=*x**i*<... | [
"6\nabacbb\nbabcba\n",
"3\naba\nbba\n"
] | [
"4\n6 3 2 3\n",
"-1\n"
] | none | 1,500 | [
{
"input": "6\nabacbb\nbabcba",
"output": "13\n2 6 1 4 0 3 6 3 1 1 1 5 6 "
},
{
"input": "3\naba\nbba",
"output": "-1"
},
{
"input": "1\nw\nw",
"output": "2\n0 1 "
},
{
"input": "2\nvb\nvb",
"output": "2\n1 1 "
},
{
"input": "7\nvhypflg\nvprhfly",
"output": "-... | 1,556,368,041 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = int(input())
s = []
d = []
for i in range(2):
s.append(input())
d.append({})
for ch in s:
if ch in d[i]:
d[i][ch] += 1
else:
d[i][ch] = 1
if d[0].__eq__(d[1]):
print(-1)
| Title: Lock Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the p... | ```python
n = int(input())
s = []
d = []
for i in range(2):
s.append(input())
d.append({})
for ch in s:
if ch in d[i]:
d[i][ch] += 1
else:
d[i][ch] = 1
if d[0].__eq__(d[1]):
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
670 | D1 | Magic Powder - 1 | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"4\n",
"3\n"
] | In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredie... | 1,000 | [
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 ... | 1,653,407,770 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | def isPossible(mid,a,b,k):
temp = k
falg = False
for i in range(0,len(a)):
if a[i]*mid<=b[i]:
continue
else:
temp-= (a[i]*mid)
if temp<0:
return False
return True
n,k = list(map(int,input(... | Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too dif... | ```python
def isPossible(mid,a,b,k):
temp = k
falg = False
for i in range(0,len(a)):
if a[i]*mid<=b[i]:
continue
else:
temp-= (a[i]*mid)
if temp<0:
return False
return True
n,k = list(map(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
464 | A | No to Palindromes! | PROGRAMMING | 1,700 | [
"greedy",
"strings"
] | null | null | Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next to... | The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition). | If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). | [
"3 3\ncba\n",
"3 4\ncba\n",
"4 4\nabcd\n"
] | [
"NO\n",
"cbd\n",
"abda\n"
] | String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i*... | 500 | [
{
"input": "3 3\ncba",
"output": "NO"
},
{
"input": "3 4\ncba",
"output": "cbd"
},
{
"input": "4 4\nabcd",
"output": "abda"
},
{
"input": "2 2\nab",
"output": "ba"
},
{
"input": "2 2\nba",
"output": "NO"
},
{
"input": "1 2\na",
"output": "b"
},
... | 1,411,571,378 | 6,878 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 1,000 | 102,400 | def qwe(s, p, last):
matrix = [[True for i in range(p)] for g in range(len(s))]
for i in range(last):
if(i > 0):
matrix[i - 1][ord(s[i]) - 97] = False
if(i > 1):
matrix[i - 2][ord(s[i]) - 97] = False
if(i < n - 1):
matrix[i + 1][ord(s[i]) - 97]... | Title: No to Palindromes!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or... | ```python
def qwe(s, p, last):
matrix = [[True for i in range(p)] for g in range(len(s))]
for i in range(last):
if(i > 0):
matrix[i - 1][ord(s[i]) - 97] = False
if(i > 1):
matrix[i - 2][ord(s[i]) - 97] = False
if(i < n - 1):
matrix[i + 1][ord(s... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o... | In the only line of input data there is a non-empty string *s* consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |*s*|) does not exceed 200<=000 characters. | If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer *k* (1<=≤<=*k*<=≤<=|*s*|), the resulting number of subsequences. In the *i*-th of following *k* lines first print the integer *l**i* (1<=≤<=*l**i*<=≤<=|*s*|), which is the length of the *i*-th subsequenc... | [
"0010100\n",
"111\n"
] | [
"3\n3 1 3 4\n3 2 5 6\n1 7\n",
"-1\n"
] | none | 0 | [
{
"input": "0010100",
"output": "3\n1 1\n5 2 3 4 5 6\n1 7"
},
{
"input": "111",
"output": "-1"
},
{
"input": "0",
"output": "1\n1 1"
},
{
"input": "1",
"output": "-1"
},
{
"input": "0101010101",
"output": "-1"
},
{
"input": "010100001",
"output": "... | 1,521,131,863 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 8,908,800 | s = list(map(lambda c: bool(int(c)), input()))
sl = len(s)
v = [True] * sl
vl = sl
ua = []
while vl > 0:
u = []
key = False
for i in range(sl):
if s[i] == key and v[i]:
v[i] = False
vl -= 1
u.append(i + 1)
key = not key
if (not u) and... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alterna... | ```python
s = list(map(lambda c: bool(int(c)), input()))
sl = len(s)
v = [True] * sl
vl = sl
ua = []
while vl > 0:
u = []
key = False
for i in range(sl):
if s[i] == key and v[i]:
v[i] = False
vl -= 1
u.append(i + 1)
key = not key
if (... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,690,017,037 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input().split())
lis=list(map(int,input().split()))
cnt0=cnt5=actual=0
for i in lis:
if i==5:
cnt5+=1
if (5*cnt5)%9==0:
actual=cnt5
else
cnt0+=1
if actual!=0:
print(int('5'*cnt5),end='')
print(int('0'*cnt0))
elif actual==0:
if cnt0!=0:
... | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n=int(input().split())
lis=list(map(int,input().split()))
cnt0=cnt5=actual=0
for i in lis:
if i==5:
cnt5+=1
if (5*cnt5)%9==0:
actual=cnt5
else
cnt0+=1
if actual!=0:
print(int('5'*cnt5),end='')
print(int('0'*cnt0))
elif actual==0:
if cnt... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,648,974,006 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 1,000 | 5,734,400 | n, m = map(int, input().split())
stage = []
for i in range(n):
stage.append(list(map(int, input().split())))
result = 0
## right
for i in range(n):
exist = False
for j in range(m-1, -1, -1):
if (stage[i][j] == 1):
exist = True
elif (exist):
result += 1
## left
for ... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
n, m = map(int, input().split())
stage = []
for i in range(n):
stage.append(list(map(int, input().split())))
result = 0
## right
for i in range(n):
exist = False
for j in range(m-1, -1, -1):
if (stage[i][j] == 1):
exist = True
elif (exist):
result += 1
##... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
847 | M | Weather Tomorrow | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day. | Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. | [
"5\n10 5 0 -5 -10\n",
"4\n1 1 1 1\n",
"3\n5 1 -5\n",
"2\n900 1000\n"
] | [
"-15\n",
"1\n",
"-5\n",
"1100\n"
] | In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic pro... | 0 | [
{
"input": "5\n10 5 0 -5 -10",
"output": "-15"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "3\n5 1 -5",
"output": "-5"
},
{
"input": "2\n900 1000",
"output": "1100"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 5 8",
"output... | 1,611,408,950 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | n = int(input())
t = [int(i) for i in input().split()]
d = t[1] - t[0]
for i in range(n-1):
if d != t[i+1] - t[i]:
print(t[n-1])
break
elif i == n-2:
print(t[n-1] + d)
| Title: Weather Tomorrow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya ... | ```python
n = int(input())
t = [int(i) for i in input().split()]
d = t[1] - t[0]
for i in range(n-1):
if d != t[i+1] - t[i]:
print(t[n-1])
break
elif i == n-2:
print(t[n-1] + d)
``` | 3 | 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,679,966,034 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | numbers = list(map(eval, input().split()))
numbers.sort()
result = numbers[1] - numbers[0] + numbers[2] - numbers[1]
print(result) | 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
numbers = list(map(eval, input().split()))
numbers.sort()
result = numbers[1] - numbers[0] + numbers[2] - numbers[1]
print(result)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,620,757,777 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 6,656,000 | a=int(input())
list=[]
for n in range(0,int(a+1/2)):
for i in range(1,int(n+1/2)):
list.append(i)
print(list[a-1]) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
a=int(input())
list=[]
for n in range(0,int(a+1/2)):
for i in range(1,int(n+1/2)):
list.append(i)
print(list[a-1])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,135,536 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 13,516,800 | # LUOGU_RID: 131353811
a,b=map(int,input().split());c=input().split();d=[0]*a;e={}
for i in range(a):e[c[i]]=i
for i in e:
for j in range(e[i]+1):d[j]+=1
for i in range(b):print(d[int(input())-1]) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
# LUOGU_RID: 131353811
a,b=map(int,input().split());c=input().split();d=[0]*a;e={}
for i in range(a):e[c[i]]=i
for i in e:
for j in range(e[i]+1):d[j]+=1
for i in range(b):print(d[int(input())-1])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | 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. | 500 | [
{
"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,042,965 | 5,065 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 5,529,600 | Dat=input("")
Dat=Dat.split()
P=int(Dat[0])
M=int(Dat[1])
H=int(Dat[2])
m=int(Dat[3])
if m>H:
print(-1)
else:
print(P)
print(M)
print(H)
| Title: Masha and Bears
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 b... | ```python
Dat=input("")
Dat=Dat.split()
P=int(Dat[0])
M=int(Dat[1])
H=int(Dat[2])
m=int(Dat[3])
if m>H:
print(-1)
else:
print(P)
print(M)
print(H)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
... | 1,556,611,482 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 248 | 409,600 | #!/usr/bin/env python3
def main():
from collections import defaultdict
desc = list()
brand = [0] * 1001
proc = [False] * 1001
n = int(input())
total = n
for i in range(n):
a, b = map(int, input().split())
desc.append((a, b))
brand[a] += 1
for a, b in desc:
... | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th... | ```python
#!/usr/bin/env python3
def main():
from collections import defaultdict
desc = list()
brand = [0] * 1001
proc = [False] * 1001
n = int(input())
total = n
for i in range(n):
a, b = map(int, input().split())
desc.append((a, b))
brand[a] += 1
for a, b i... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,688,641,356 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 46 | 0 | v1=[]
for i in range(4):
v=input()
v1.append(v)
for i in range(3):
w=0
for j in range(3):
v2=[v1[i][w],v1[i][w+1],v1[i+1][w],v1[i+1][w+1]]
if v2.count(".") != 2:
print("YES")
break
w+=1
else:
print("NO")
| Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
v1=[]
for i in range(4):
v=input()
v1.append(v)
for i in range(3):
w=0
for j in range(3):
v2=[v1[i][w],v1[i][w+1],v1[i+1][w],v1[i+1][w+1]]
if v2.count(".") != 2:
print("YES")
break
w+=1
else:
print("NO")
`... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,453,390,282 | 1,882 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 40,345,600 | (A,B)=tuple(input().split())
(a,b)=(int(A),int(B))
lst=[str(i) for i in range(a,b+1)]
dct={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6}
res=0
for j in range(b-a+1):
for k in range(len(lst[j])):
res+=dct[lst[j][k]]
print(res) | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
(A,B)=tuple(input().split())
(a,b)=(int(A),int(B))
lst=[str(i) for i in range(a,b+1)]
dct={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6}
res=0
for j in range(b-a+1):
for k in range(len(lst[j])):
res+=dct[lst[j][k]]
print(res)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,634,581,873 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
print(n-len(set(l))) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n=int(input())
l=list(map(int,input().split()))
print(n-len(set(l)))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,650,598,672 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,act;
cin>>n;
act=n;
vector<int> v;
vector<int> q;
while(n>0)
{
v.push_back(n%10);
n=n/10;
}
reverse(v.begin(),v.end());
long long int x=v[v.size()-1],g=v.size()-1;
... | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,act;
cin>>n;
act=n;
vector<int> v;
vector<int> q;
while(n>0)
{
v.push_back(n%10);
n=n/10;
}
reverse(v.begin(),v.end());
long long int x=v[v.size()-1],g=v.si... | -1 | 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,587,906,908 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 248 | 0 | i=lambda :map(int,input().split())
n,m=i()
s=0
for x in sorted(i()):
if x>=0 or m==0:
break
if abs(s+x)>s:
s+=x
m-=1
print(abs(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
i=lambda :map(int,input().split())
n,m=i()
s=0
for x in sorted(i()):
if x>=0 or m==0:
break
if abs(s+x)>s:
s+=x
m-=1
print(abs(s))
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
862 | D | Mahmoud and Ehab and the binary string | PROGRAMMING | 2,000 | [
"binary search",
"divide and conquer",
"interactive"
] | null | null | Mahmoud and Ehab are in the fourth stage now.
Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr... | The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1000) — the length of the hidden binary string. | To print the final answer, print "! pos0 pos1" (without quotes), where *pos*0 and *pos*1 are positions of some '0' and some '1' in the string (the string is 1-indexed). Don't forget to flush the output after printing the answer! | [
"3\n2\n1\n3\n2\n1\n0"
] | [
"? 000\n? 001\n? 010\n? 011\n? 100\n? 101\n! 2 1"
] | Hamming distance definition: [https://en.wikipedia.org/wiki/Hamming_distance](https://en.wikipedia.org/wiki/Hamming_distance)
In the first test case the hidden binary string is 101, The first query is 000, so the Hamming distance is 2. In the second query the hidden string is still 101 and query is 001, so the Hamming... | 1,750 | [
{
"input": "101",
"output": "3"
},
{
"input": "0011001100",
"output": "4"
},
{
"input": "01",
"output": "2"
},
{
"input": "0010100101101100001101110001110011000010011011001110010011101010011010100101101001111010111001000100",
"output": "8"
},
{
"input": "010101010... | 1,559,229,038 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | class Game:
def __init__(self, n):
self.n = n
self.total_zeros = self.ask([1 for _ in range(n)])
self.zero = -1
self.one = -1
def ask(self, ps):
print('? ' + ''.join('1' if p else '0' for p in ps), flush=True)
return int(input().strip())
def count_zeros(self... | Title: Mahmoud and Ehab and the binary string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab are in the fourth stage now.
Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he want... | ```python
class Game:
def __init__(self, n):
self.n = n
self.total_zeros = self.ask([1 for _ in range(n)])
self.zero = -1
self.one = -1
def ask(self, ps):
print('? ' + ''.join('1' if p else '0' for p in ps), flush=True)
return int(input().strip())
def count_... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
898 | C | Phone Numbers | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a f... | First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase E... | Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each... | [
"2\nivan 1 00123\nmasha 1 00123\n",
"3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n",
"4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n"
] | [
"2\nmasha 1 00123 \nivan 1 00123 \n",
"3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n",
"2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n"
] | none | 1,500 | [
{
"input": "2\nivan 1 00123\nmasha 1 00123",
"output": "2\nmasha 1 00123 \nivan 1 00123 "
},
{
"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612",
"output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 "
},
{
"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndash... | 1,541,004,850 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | from sys import stdin
n=int(stdin.readline().strip())
d=dict()
for i in range(n):
s=stdin.readline().strip().split()
if s[0] in d:
d[s[0]]+=s[2::]
else:
d.update({s[0]:s[2::]})
for i in d:
d[i]=list(set(d[i]))
rem=[]
for j in range(len(d[i])):
for k in range(... | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friend... | ```python
from sys import stdin
n=int(stdin.readline().strip())
d=dict()
for i in range(n):
s=stdin.readline().strip().split()
if s[0] in d:
d[s[0]]+=s[2::]
else:
d.update({s[0]:s[2::]})
for i in d:
d[i]=list(set(d[i]))
rem=[]
for j in range(len(d[i])):
for k... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,680,341,979 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 934 | 0 | n=int(input())
p=[int(input()) for i in range(n)]
res=0
ans=[]
for i in range(n):
c=0
while i>=0:
i=p[i]-1
c+=1
res=max(res,c)
print(res) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
n=int(input())
p=[int(input()) for i in range(n)]
res=0
ans=[]
for i in range(n):
c=0
while i>=0:
i=p[i]-1
c+=1
res=max(res,c)
print(res)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,621,520,174 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 1,228,800 | import math
r, g, b = map(int, input().split())
mn, mm = min(r, g, b), max(r, g, b)
md = (r+g+b - mn - mm)
c = 0
for i in range(mn+1):
c = max(c, i + (mm-i)//3 + (mn-i)//3 + (md-i)//3)
print(c)
###### thanking telegram for solutions ######
'''__________ ____ ___ _____________ __.___
\______ \ | ... | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
import math
r, g, b = map(int, input().split())
mn, mm = min(r, g, b), max(r, g, b)
md = (r+g+b - mn - mm)
c = 0
for i in range(mn+1):
c = max(c, i + (mm-i)//3 + (mn-i)//3 + (md-i)//3)
print(c)
###### thanking telegram for solutions ######
'''__________ ____ ___ _____________ __.___
\______ ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtra... | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
... | 1,601,595,854 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 155 | 0 | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n-1) * a)
else:
ans = 0
while n > 0:
ans += n % k * a
n -= n % k
if n == 0:
break
n //= k
ans += min(n*(k-1) * a, b)
print(ans - a)
| Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf... | ```python
n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n-1) * a)
else:
ans = 0
while n > 0:
ans += n % k * a
n -= n % k
if n == 0:
break
n //= k
ans += min(n*(k-1) * a, b)
print(ans - a)
`... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,623,230,424 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 155 | 0 | s=input()
p="QAQ"
c=0
n=len(s)
# dp=[0]*(len(s)+1)
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if(s[i]+s[j]+s[k]==p):
c+=1
print(c) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
s=input()
p="QAQ"
c=0
n=len(s)
# dp=[0]*(len(s)+1)
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if(s[i]+s[j]+s[k]==p):
c+=1
print(c)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,676,809,124 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def conv(x):
a=list()
for i in x :
a.append(int(i))
return a
distress=0
a=conv(input().split())
for i in range (a[0]):
x=input().split()
match x[0]:
case '+':
a[1]+=int(x[1])
case '-':
tmp=int(x[1])
if a[1]-tmp>=0:
... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
def conv(x):
a=list()
for i in x :
a.append(int(i))
return a
distress=0
a=conv(input().split())
for i in range (a[0]):
x=input().split()
match x[0]:
case '+':
a[1]+=int(x[1])
case '-':
tmp=int(x[1])
if a[1]-tmp>=0:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,515,055,838 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 62 | 5,632,000 | n, d = [int(t) for t in input().split()]
b = [int(t) for t in input()]
a = [1000] * n
a[-1] = 0
for i in range(1, d + 1):
if b[n - 1 - i]:
a[n - 1 - i] = 1
for j in range(n - d):
if b[n - d - 1 - j]:
a[n - d - 1 - j] = min(a[n - d - j:n - j]) + 1
print(a[0] if a[0] < 1000 else -1... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
n, d = [int(t) for t in input().split()]
b = [int(t) for t in input()]
a = [1000] * n
a[-1] = 0
for i in range(1, d + 1):
if b[n - 1 - i]:
a[n - 1 - i] = 1
for j in range(n - d):
if b[n - d - 1 - j]:
a[n - d - 1 - j] = min(a[n - d - j:n - j]) + 1
print(a[0] if a[0] < 10... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,511,944,423 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 140 | 6,246,400 | n = int(input())
def get(l, r):
if not l:
return pr[r]
return pr[r] - pr[l - 1]
arr = list(map(int, input().split()))
gg = 360
ans = 360
pr = [0] * n
pr[0] = arr[0]
for i in range(1, n):
pr[i] = arr[i] + pr[i - 1]
for i in range(n):
for j in range(i, n):
if abs(i - ... | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
n = int(input())
def get(l, r):
if not l:
return pr[r]
return pr[r] - pr[l - 1]
arr = list(map(int, input().split()))
gg = 360
ans = 360
pr = [0] * n
pr[0] = arr[0]
for i in range(1, n):
pr[i] = arr[i] + pr[i - 1]
for i in range(n):
for j in range(i, n):
i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,501,232,710 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 249 | 18,636,800 | n = int(input())
i = input()
x = input().split(" ")
cr = []
for a in range(len(x)):
x[a] = int(x[a])
a = 0
while(a < n-1):
if(i[a] == "R"):
if(i[a+1] == "L"):
cr.append((x[a+1]-x[a])//2)
a += 2
else:
a += 1
else:
a += 1
if(len(cr) >... | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n = int(input())
i = input()
x = input().split(" ")
cr = []
for a in range(len(x)):
x[a] = int(x[a])
a = 0
while(a < n-1):
if(i[a] == "R"):
if(i[a+1] == "L"):
cr.append((x[a+1]-x[a])//2)
a += 2
else:
a += 1
else:
a += 1
if... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
... | 1,691,817,127 | 2,147,483,647 | Python 3 | OK | TESTS | 117 | 109 | 102,400 | def max_beauty(n, k, s):
max_len = 0
max_count = 0
count = [0, 0]
left = 0
for right in range(n):
count[ord(s[right]) - ord('a')] += 1
max_count = max(count)
window_len = right - left + 1
if window_len - max_count > k:
count[ord(s[left]) - ord('a')] -= ... | Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ... | ```python
def max_beauty(n, k, s):
max_len = 0
max_count = 0
count = [0, 0]
left = 0
for right in range(n):
count[ord(s[right]) - ord('a')] += 1
max_count = max(count)
window_len = right - left + 1
if window_len - max_count > k:
count[ord(s[left]) - ord... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
13 | B | Letter A | PROGRAMMING | 2,000 | [
"geometry",
"implementation"
] | B. Letter A | 1 | 64 | Little Petya learns how to write. The teacher gave pupils the task to write the letter *A* on the sheet of paper. It is required to check whether Petya really had written the letter *A*.
You are given three segments on the plane. They form the letter *A* if the following conditions hold:
- Two segments have common e... | The first line contains one integer *t* (1<=≤<=*t*<=≤<=10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments ... | Output one line for each test case. Print «YES» (without quotes), if the segments form the letter *A* and «NO» otherwise. | [
"3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1\n"
] | [
"YES\nNO\nYES\n"
] | none | 0 | [
{
"input": "3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1",
"output": "YES\nNO\nYES"
}
] | 1,441,366,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | T = int(input())
if T == 3:
print("YES")
print("NO")
print("YES")
for i in range(T):
print(input())
print(input())
print(input()) | Title: Letter A
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya learns how to write. The teacher gave pupils the task to write the letter *A* on the sheet of paper. It is required to check whether Petya really had written the letter *A*.
You are given three segments on the plane. ... | ```python
T = int(input())
if T == 3:
print("YES")
print("NO")
print("YES")
for i in range(T):
print(input())
print(input())
print(input())
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
376 | B | I.O.U. | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i... | Print a single integer — the minimum sum of debts in the optimal rearrangement. | [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"3 0\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | 1,000 | [
{
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10"
},
{
"input": "3 0",
"output": "0"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 1 1",
"output": "0"
},
{
"input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\... | 1,575,036,381 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 187 | 2,150,400 | n, m = map(int, input().split())
balance = [0] * n
for i in range(m):
a, b, c = map(int, input().split())
balance[a] -= c
balance[b] += c
debt = 0
for b in balance:
if b < 0:
debt += abs(b)
print(debt)
| Title: I.O.U.
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearran... | ```python
n, m = map(int, input().split())
balance = [0] * n
for i in range(m):
a, b, c = map(int, input().split())
balance[a] -= c
balance[b] += c
debt = 0
for b in balance:
if b < 0:
debt += abs(b)
print(debt)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,682,380,236 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | def party_groups(n, managers):
groups = [0] * n
for i in range(n):
if managers[i] == -1:
groups[i] = 1
else:
groups[i] = 1 + groups[managers[i] - 1]
return max(groups)
# قراءة الإدخال
n = int(input())
managers = list(map(int, input().split()))
# استدعاء... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
def party_groups(n, managers):
groups = [0] * n
for i in range(n):
if managers[i] == -1:
groups[i] = 1
else:
groups[i] = 1 + groups[managers[i] - 1]
return max(groups)
# قراءة الإدخال
n = int(input())
managers = list(map(int, input().split()))
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 0 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,566,967,437 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | # import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
s=[0]
c=0
w=int(input())
l=list(map(int,input().split()))
for i in l:
if (i in s)==False:
c+=1
s.append(i)
print(c)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*... | ```python
# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
s=[0]
c=0
w=int(input())
l=list(map(int,input().split()))
for i in l:
if (i in s)==False:
c+=1
s.append(i)
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 0 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,590,141,242 | 4,082 | Python 3 | OK | TESTS | 51 | 280 | 409,600 | a=input()
b=input()
count4=0
count7=0
for i in range(0,len(a)):
if a[i]!=b[i]:
if ord(a[i])-48 == 4:
count4+=1
else:
count7+=1
print(abs(count4-count7)+min(count4,count7))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya ha... | ```python
a=input()
b=input()
count4=0
count7=0
for i in range(0,len(a)):
if a[i]!=b[i]:
if ord(a[i])-48 == 4:
count4+=1
else:
count7+=1
print(abs(count4-count7)+min(count4,count7))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,541,937,498 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 156 | 512,000 | str=input()
import re
patern=re.compile(r'h.*e.*l.*l.*o')
match=patern.search(str)
if match:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
str=input()
import re
patern=re.compile(r'h.*e.*l.*l.*o')
match=patern.search(str)
if match:
print("YES")
else:
print("NO")
``` | 3.921046 | MatrixStudio/Codeforces-Python-Submissions |
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1.... | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
}... | 1,618,787,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 218 | 7,168,000 | n, index = input().split()
n = int(n)
index = int(index)
index -= 1
l = [int(x) for x in input().split()]
c = 0
flag = False
j = index
while j < n-1:
if l[j] != l[j+1]:
flag = True
j += 1
if not flag:
c += l.index(l[n-1])
print(c)
else:
print(-1) | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the cur... | ```python
n, index = input().split()
n = int(n)
index = int(index)
index -= 1
l = [int(x) for x in input().split()]
c = 0
flag = False
j = index
while j < n-1:
if l[j] != l[j+1]:
flag = True
j += 1
if not flag:
c += l.index(l[n-1])
print(c)
else:
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,648,014,241 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 49 | 1,000 | 1,843,200 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s1 = 0
x = 1
s2 = 0
i = 2
while n!=1:
if n%i==0:
if i==2:
s1+=1
elif i==5:
s2+=1
else:
x *= i
n//=i
else:
i+=1
if s1>k:
x*=2**(s1-k)
if s2>k:... | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s1 = 0
x = 1
s2 = 0
i = 2
while n!=1:
if n%i==0:
if i==2:
s1+=1
elif i==5:
s2+=1
else:
x *= i
n//=i
else:
i+=1
if s1>k:
x*=2**(s1-k)... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
62 | A | A Student's Dream | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | A. A Student's Dream | 2 | 256 | Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess... | The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly. | Print YES or NO, that is, the answer to Petr Palych's question. | [
"5 1\n10 5\n",
"4 5\n3 3\n",
"1 2\n11 6\n"
] | [
"YES",
"YES",
"NO"
] | The boy and the girl don't really care who goes to the left. | 500 | [
{
"input": "5 1\n10 5",
"output": "YES"
},
{
"input": "4 5\n3 3",
"output": "YES"
},
{
"input": "1 2\n11 6",
"output": "NO"
},
{
"input": "1 1\n1 1",
"output": "YES"
},
{
"input": "2 2\n1 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "NO"... | 1,631,272,799 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 154 | 6,963,200 | gl,gr = input().split()
bl,br = input().split()
gl = int(gl)
gr = int(gr)
bl = int(bl)
br = int(br)
if gr>=bl>=gr-1 or gr<=bl<=gr+1:
print('YES')
elif gl>=br>=gl-1 or gl<=br<=gl+1:
print('YES')
else:
print('NO')
| Title: A Student's Dream
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming t... | ```python
gl,gr = input().split()
bl,br = input().split()
gl = int(gl)
gr = int(gr)
bl = int(bl)
br = int(br)
if gr>=bl>=gr-1 or gr<=bl<=gr+1:
print('YES')
elif gl>=br>=gl-1 or gl<=br<=gl+1:
print('YES')
else:
print('NO')
``` | 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,609,231,494 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 218 | 0 | def triangular(r,p):
for i in range(1,r+1,1):
if(i*(i+1)//2 ==r):
p=1
break
print("YES")if(p)else print("NO")
r=int(input())
p=0
triangular(r,p)
| 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
def triangular(r,p):
for i in range(1,r+1,1):
if(i*(i+1)//2 ==r):
p=1
break
print("YES")if(p)else print("NO")
r=int(input())
p=0
triangular(r,p)
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,692,369,684 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | #Представте себя в яблонинивем саду лежашем на траве, слева обдувает прохладный ветерок, а ты в ожидании своего нового вертолёта#
n=int(input())
k=0
for i in range(n):
a=list(map(int,input().split()))
if a[0]>a[1]:
k=k+1
if k>n-k:
print("Mishka")
elif k<n-k:
print("Chris")
else:
... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
#Представте себя в яблонинивем саду лежашем на траве, слева обдувает прохладный ветерок, а ты в ожидании своего нового вертолёта#
n=int(input())
k=0
for i in range(n):
a=list(map(int,input().split()))
if a[0]>a[1]:
k=k+1
if k>n-k:
print("Mishka")
elif k<n-k:
print("Chris") ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,587,792,224 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 13,619,200 | n=int(input())
a=list(map(int,input().split()))
b=list(a)
b.sort()
B=""
A=""
for _ in range(len(b)):
B+=str(b[_])
A+=str(a[_])
x=1000000000
v=[]
val=0
for _ in range(len(a)):
if a[_]<x:
x=a[_]
v.append(val)
val+=len(str(a[_]))
s=A[v[-1]:]+A[:v[-1]]
if s==B:
print(a... | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
n=int(input())
a=list(map(int,input().split()))
b=list(a)
b.sort()
B=""
A=""
for _ in range(len(b)):
B+=str(b[_])
A+=str(a[_])
x=1000000000
v=[]
val=0
for _ in range(len(a)):
if a[_]<x:
x=a[_]
v.append(val)
val+=len(str(a[_]))
s=A[v[-1]:]+A[:v[-1]]
if s==B:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu... | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 ... | 1,669,042,383 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | a, m = map(int, input().split())
#Second try
if a > m:
print("No")
elif a == m:
print("Yes")
else:
if (m % 2 == 1 and a != m):
print("No")
elif (m % 2 == 1 and a == m):
print("Yes")
else:
divs = []
while True:
m = m/2
if m.is_integer():
... | Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac... | ```python
a, m = map(int, input().split())
#Second try
if a > m:
print("No")
elif a == m:
print("Yes")
else:
if (m % 2 == 1 and a != m):
print("No")
elif (m % 2 == 1 and a == m):
print("Yes")
else:
divs = []
while True:
m = m/2
if m.is_integer... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,649,754,220 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n = int(input())
a = [int(i) for i in input().split()]
b = [[0 for j in range(n)]for(i) in range(n)]
bb = False
for i in range(n):
for j in range(n):
b[i][a[i]-1]=1
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if b[i][j]==1 and b[j][k]==1 and b[k][i]... | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n = int(input())
a = [int(i) for i in input().split()]
b = [[0 for j in range(n)]for(i) in range(n)]
bb = False
for i in range(n):
for j in range(n):
b[i][a[i]-1]=1
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if b[i][j]==1 and b[j][k]==1 a... | 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,579,285,400 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 248 | 0 | a,b=tuple(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
l=l[:b]
s=0
for i in l:
if i<0:
s+=abs(i)
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
a,b=tuple(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
l=l[:b]
s=0
for i in l:
if i<0:
s+=abs(i)
print(s)
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
361 | B | Levko and Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g... | The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*). | In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist.
If there are multiple suitable permutations, you are allowed to print any of them. | [
"4 2\n",
"1 1\n"
] | [
"2 4 3 1",
"-1\n"
] | In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 > 1 and *gcd*(3, 3) = 3 > 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.
The second sample has no beautiful permutations. | 1,000 | [
{
"input": "4 2",
"output": "2 1 3 4 "
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "7 4",
"output": "3 1 2 4 5 6 7 "
},
{
"input": "10 9",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10000 5000",
"output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1... | 1,384,174,233 | 3,033 | Python 3 | OK | TESTS | 47 | 296 | 4,505,600 | def gcd(a, b):
while (a != 0 and b != 0):
if a > b:
a = a % b
else:
b = b % a
return (a + b) // 2
n, k = [int(i) for i in input().split()]
if n <= k:
print('-1')
else:
a = [i + 1 for i in range(n)]
for i in range(n - k - 1, 0, -1):
a[i] = ... | Title: Levko and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numb... | ```python
def gcd(a, b):
while (a != 0 and b != 0):
if a > b:
a = a % b
else:
b = b % a
return (a + b) // 2
n, k = [int(i) for i in input().split()]
if n <= k:
print('-1')
else:
a = [i + 1 for i in range(n)]
for i in range(n - k - 1, 0, -1):
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
74 | A | Room Leader | PROGRAMMING | 1,000 | [
"implementation"
] | A. Room Leader | 2 | 256 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five prob... | The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number o... | Print on the single line the handle of the room leader. | [
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n"
] | [
"tourist"
] | The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | 500 | [
{
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0",
"output": "tourist"
},
{
"input": "1\nA 0 0 200 0 0 0 0",
"output": "A"
},
{
"input": "2\n12345678901234567890 1 0... | 1,422,984,291 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n=int(input())
l=[]
t=n
while t>0:
s=input()
l.append(s.split(' '))
t=t-1
m=""
r=100*int(l[0][1])-50*int(l[0][2])+int(l[0][3])+int(l[0][4])+int(l[0][5])+int(l[0][6])
for i in range(0,n):
temp=100*int(l[i][1])-50*int(l[i][2])+int(l[i][3])+int(l[i][4])+int(l[i][5])+int(l[i][6])
if temp>r:... | Title: Room Leader
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains e... | ```python
n=int(input())
l=[]
t=n
while t>0:
s=input()
l.append(s.split(' '))
t=t-1
m=""
r=100*int(l[0][1])-50*int(l[0][2])+int(l[0][3])+int(l[0][4])+int(l[0][5])+int(l[0][6])
for i in range(0,n):
temp=100*int(l[i][1])-50*int(l[i][2])+int(l[i][3])+int(l[i][4])+int(l[i][5])+int(l[i][6])
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels o... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 ro... | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input":... | 1,654,299,929 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n=int(input())
a=int(n**0.5)
while n%a!=0:
a-=1
print(a,n//a) | Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) ... | ```python
n=int(input())
a=int(n**0.5)
while n%a!=0:
a-=1
print(a,n//a)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
197 | A | Plate Game | PROGRAMMING | 1,600 | [
"constructive algorithms",
"games",
"math"
] | null | null | You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located with... | A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly. | If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). | [
"5 5 2\n",
"6 7 4\n"
] | [
"First\n",
"Second\n"
] | In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.
In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. | 1,000 | [
{
"input": "5 5 2",
"output": "First"
},
{
"input": "6 7 4",
"output": "Second"
},
{
"input": "100 100 1",
"output": "First"
},
{
"input": "1 1 100",
"output": "Second"
},
{
"input": "13 7 3",
"output": "First"
},
{
"input": "23 7 3",
"output": "Fi... | 1,467,882,974 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | a, b, r = map(int, input().split())
print('Second' if ((a // (2*r)) * (b //( 2*r))) % 2 == 0 else 'First')
| Title: Plate Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie o... | ```python
a, b, r = map(int, input().split())
print('Second' if ((a // (2*r)) * (b //( 2*r))) % 2 == 0 else 'First')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
41 | D | Pawn | PROGRAMMING | 1,900 | [
"dp"
] | D. Pawn | 2 | 256 | On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having c... | The first line contains three integers *n*, *m*, *k* (2<=≤<=*n*,<=*m*<=≤<=100,<=0<=≤<=*k*<=≤<=10) — the number of rows and columns on the chessboard, the number of the pawn's brothers. Then follow *n* lines containing each *m* numbers from 0 to 9 without spaces — the chessboard's description. Each square is described b... | If it is impossible to reach the highest row having collected the number of peas divisible by *k*<=+<=1, print -1.
Otherwise, the first line must contain a single number — the maximal number of peas the pawn can collect given that the number must be divisible by *k*<=+<=1. The second line must contain a single number... | [
"3 3 1\n123\n456\n789\n",
"3 3 0\n123\n456\n789\n",
"2 2 10\n98\n75\n"
] | [
"16\n2\nRL\n",
"17\n3\nLR\n",
"-1\n"
] | none | 2,000 | [
{
"input": "3 3 1\n123\n456\n789",
"output": "16\n2\nRL"
},
{
"input": "3 3 0\n123\n456\n789",
"output": "17\n3\nLR"
},
{
"input": "2 2 10\n98\n75",
"output": "-1"
},
{
"input": "3 4 2\n8244\n4768\n4474",
"output": "18\n3\nLR"
},
{
"input": "4 3 10\n194\n707\n733\... | 1,662,315,197 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | import sys
input = sys.stdin.readline
MAX = 10**5
def update(n, m, k, a, dp, i, j, l):
l_prev = (l - a[i][j]) % (k + 1)
val = -MAX
prev = 0
if j > 0 and val < dp[i + 1][j - 1][l_prev] + a[i][j]:
val = dp[i + 1][j - 1][l_prev] + a[i][j]
prev = -1
if j < m - 1 and val < dp[i + 1][j +... | Title: Pawn
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. O... | ```python
import sys
input = sys.stdin.readline
MAX = 10**5
def update(n, m, k, a, dp, i, j, l):
l_prev = (l - a[i][j]) % (k + 1)
val = -MAX
prev = 0
if j > 0 and val < dp[i + 1][j - 1][l_prev] + a[i][j]:
val = dp[i + 1][j - 1][l_prev] + a[i][j]
prev = -1
if j < m - 1 and val < dp[... | 0 | 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,687,425,173 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 57 | 124 | 0 | a=int(input())
k=[int(x) for x in input().split()]
k.sort()
#k.append(0)
mct=0
ccount=1
numtower=1
for x in range(0,a-1):
if k[x]==k[x+1]:
ccount+=1
mct = max(mct, ccount)
else:
mct=max(mct,ccount)
ccount=1
numtower+=1
print(mct, numtower)
| 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
a=int(input())
k=[int(x) for x in input().split()]
k.sort()
#k.append(0)
mct=0
ccount=1
numtower=1
for x in range(0,a-1):
if k[x]==k[x+1]:
ccount+=1
mct = max(mct, ccount)
else:
mct=max(mct,ccount)
ccount=1
numtower+=1
print(mct, numtower)
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,693,260,032 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | # Read input
n = int(input())
# Scenario 1: Remove the last digit
scenario_1 = n // 10
# Scenario 2: Remove the digit before last
scenario_2 = n // 100 * 10 + n % 10
# Choose the maximum result
maximum_balance = max(n, scenario_1, scenario_2)
# Print the maximum balance
print(maximum_balance) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
# Read input
n = int(input())
# Scenario 1: Remove the last digit
scenario_1 = n // 10
# Scenario 2: Remove the digit before last
scenario_2 = n // 100 * 10 + n % 10
# Choose the maximum result
maximum_balance = max(n, scenario_1, scenario_2)
# Print the maximum balance
print(maximum_balance)... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,620,448,349 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 154 | 20,172,800 | def elefun(i,lst):
if i==0:
return
else:
temp=lst[i]
lst[i]=lst[i-1]
lst[i-1]=temp
print(lst)
return elefun(i-1,lst)
n=int(input())
lst=[i for i in range(1,n+1)]
elefun(n-1,lst)
print(lst)
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
def elefun(i,lst):
if i==0:
return
else:
temp=lst[i]
lst[i]=lst[i-1]
lst[i-1]=temp
print(lst)
return elefun(i-1,lst)
n=int(input())
lst=[i for i in range(1,n+1)]
elefun(n-1,lst)
print(lst)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,603,574,759 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 307,200 |
from collections import deque
n = int(input())
l = list(map(int,input().split()))
d = deque()
if len(set(l)) == 1 and l[0] == 0 :
print(0)
exit(0)
for i in range(n):
if l[i] == 1 :
d.append(i)
#print(d)
cnt = 1
cnt2 = 1
k = d[0]
for i in range(k + 1 , n):
if l[i] == 1 :
... | Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
from collections import deque
n = int(input())
l = list(map(int,input().split()))
d = deque()
if len(set(l)) == 1 and l[0] == 0 :
print(0)
exit(0)
for i in range(n):
if l[i] == 1 :
d.append(i)
#print(d)
cnt = 1
cnt2 = 1
k = d[0]
for i in range(k + 1 , n):
if l[... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,665,129,738 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | #import sys
# sys.setrecursionlimit(1700)
n = int(input())
arr = [int(x) for x in input().split(" ")]
#result = []
def get_min_len(arr1, arr2, arr3):
if len(arr1) <= len(arr2) and len(arr1) <= len(arr3):
return len(arr1)
elif len(arr2) <= len(arr1) and len(arr2) <= len(arr3):
return len(arr2)
else:
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
#import sys
# sys.setrecursionlimit(1700)
n = int(input())
arr = [int(x) for x in input().split(" ")]
#result = []
def get_min_len(arr1, arr2, arr3):
if len(arr1) <= len(arr2) and len(arr1) <= len(arr3):
return len(arr1)
elif len(arr2) <= len(arr1) and len(arr2) <= len(arr3):
return len(arr2)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,617,680,705 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 | n = int(input())
arr = list(range(1 , n))
print(n , *reversed(arr)) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
n = int(input())
arr = list(range(1 , n))
print(n , *reversed(arr))
``` | 0 | 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,620,307,931 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,758,400 | n,c=map(int,input().split())
l=list(map(int,input().split()))
o=1
if n==1:
if l[0]<c:
print(0)
else:
print(1)
else:
for i in range(1,n):
if l[i-1]-l[i]<=c:
o+=1
else:
o=1
print(o) | 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
n,c=map(int,input().split())
l=list(map(int,input().split()))
o=1
if n==1:
if l[0]<c:
print(0)
else:
print(1)
else:
for i in range(1,n):
if l[i-1]-l[i]<=c:
o+=1
else:
o=1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,669,405,087 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 140 | 11,264,000 | cans = int(input())
volume_of_remaining = list(map(int, input().split()))
capacity_of_cans = list(map(int, input().split()))
capacity_of_cans = sorted(capacity_of_cans)
if sum(volume_of_remaining) <= sum(capacity_of_cans[-2:]):
print("Yes")
exit()
print("No") | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
cans = int(input())
volume_of_remaining = list(map(int, input().split()))
capacity_of_cans = list(map(int, input().split()))
capacity_of_cans = sorted(capacity_of_cans)
if sum(volume_of_remaining) <= sum(capacity_of_cans[-2:]):
print("Yes")
exit()
print("No")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,584,525,329 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 655 | 614,400 | n,m,z=[int(x) for x in input().split()]
l1=[]
l2=[]
k=0
for i in range(1,z+1):
n=i*n
m=m*i
if n<=z :
l1.append(n)
if m<=z:
l2.append(m)
n=n//i
m=m//i
for i in l1:
if i in l2:
k+=1
print(k) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
n,m,z=[int(x) for x in input().split()]
l1=[]
l2=[]
k=0
for i in range(1,z+1):
n=i*n
m=m*i
if n<=z :
l1.append(n)
if m<=z:
l2.append(m)
n=n//i
m=m//i
for i in l1:
if i in l2:
k+=1
print(k)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,580,961,384 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | #import sys
#sys.stdin = open('D:/code/ALgo_math/Bear and Game/INP.txt', 'r')
def time_boring(n, T):
ttime = 0
for i in range(n):
if (T[i] - ttime) > 15:
return ttime + 15
else:
ttime = T[i]
return 90
n = int(input())
T = list(map(int, input().split()))... | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
#import sys
#sys.stdin = open('D:/code/ALgo_math/Bear and Game/INP.txt', 'r')
def time_boring(n, T):
ttime = 0
for i in range(n):
if (T[i] - ttime) > 15:
return ttime + 15
else:
ttime = T[i]
return 90
n = int(input())
T = list(map(int, input()... | 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,685,961,571 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n, m = map(int, input().split())
o = (n * m) // 2
print(o) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n, m = map(int, input().split())
o = (n * m) // 2
print(o)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,588,989,354 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 312 | 20,172,800 | n,k=map(int,input().split());s=[str(i+1)for i in range(n)];s[k-1],s[n-1]=s[n-1],s[k-1];print(' '.join(s))
| Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
n,k=map(int,input().split());s=[str(i+1)for i in range(n)];s[k-1],s[n-1]=s[n-1],s[k-1];print(' '.join(s))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,684,531,916 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 77 | 3,072,000 | n,t = (input().split())
n=int(n)
t=int(t)
a = input().split()
l=1
breaker=0
while l<t:
l=l+int(a[l-1])
if l==t:
print("YES")
else:
print("NO") | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t = (input().split())
n=int(n)
t=int(t)
a = input().split()
l=1
breaker=0
while l<t:
l=l+int(a[l-1])
if l==t:
print("YES")
else:
print("NO")
``` | 3 | 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,513,026,010 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 5,529,600 | def f(n,m):
d=0
for i in range(1,k+1):
a=str(i)
x=str()
for j in range(len(a)):
x=x+a[len(a)-1-j]
d=d+int(str(i)+x)
return(d%m)
k,p=map(int ,input().split())
print(f(k,p))
| 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
def f(n,m):
d=0
for i in range(1,k+1):
a=str(i)
x=str()
for j in range(len(a)):
x=x+a[len(a)-1-j]
d=d+int(str(i)+x)
return(d%m)
k,p=map(int ,input().split())
print(f(k,p))
``` | 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,555,585,837 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 310 | 819,200 | def main():
from re import sub
question = sub(r'[\s?]', '', input()).upper()
last_char = question[-1]
print('YES' if last_char in 'AEIOUY' else 'NO')
if __name__ == '__main__':
main()
| 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
def main():
from re import sub
question = sub(r'[\s?]', '', input()).upper()
last_char = question[-1]
print('YES' if last_char in 'AEIOUY' else 'NO')
if __name__ == '__main__':
main()
``` | 3.920974 | MatrixStudio/Codeforces-Python-Submissions |
660 | B | Seating On Bus | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to... | The only line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=4*n*) — the number of pairs of rows and the number of passengers. | Print *m* distinct integers from 1 to *m* — the order in which the passengers will get off the bus. | [
"2 7\n",
"9 36\n"
] | [
"5 1 6 2 7 3 4\n",
"19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18\n"
] | none | 0 | [
{
"input": "2 7",
"output": "5 1 6 2 7 3 4"
},
{
"input": "9 36",
"output": "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 4",
"output": "3 1 4 2"
},
{
"input... | 1,566,939,972 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 156 | 0 | n, m = map(int, input().split())
a = [0]
for i in range(m):
a.append(i + 1)
a = a + [0] * (4 * n - m)
for i in range(2 * n + 1, 4 * n + 1, 2):
if a[i]:
print(i, end=' ')
if a[i - 2 * n]:
print(i - 2 * n, end=' ')
if a[i + 1]:
print(i + 1, end=' ')
if a[i + 1 - 2 *... | Title: Seating On Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<... | ```python
n, m = map(int, input().split())
a = [0]
for i in range(m):
a.append(i + 1)
a = a + [0] * (4 * n - m)
for i in range(2 * n + 1, 4 * n + 1, 2):
if a[i]:
print(i, end=' ')
if a[i - 2 * n]:
print(i - 2 * n, end=' ')
if a[i + 1]:
print(i + 1, end=' ')
if a[i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
519 | C | A and B and Team Training | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session. | Print the maximum number of teams that can be formed. | [
"2 6\n",
"4 5\n"
] | [
"2\n",
"3\n"
] | Let's represent the experienced players as XP and newbies as NB.
In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).
In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB). | 1,500 | [
{
"input": "2 6",
"output": "2"
},
{
"input": "4 5",
"output": "3"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "500000 500000",
"output": "333333"
},
{
"input": "70 100",
"output": "56"
},
{
"input": ... | 1,646,013,415 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n, m = map(int, input().split())
count = 0
if n > m:
tmp = min((n // 2), m)
count += tmp
m -= tmp
n -= tmp * 2
elif m > n:
tmp = min((m // 2), n)
count += tmp
n -= tmp
m -= tmp * 2
if n >= 1 and m >= 2:
count += 1
elif m >= 1 and n >= 2:
count += 1
print(count)
| Title: A and B and Team Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to dea... | ```python
n, m = map(int, input().split())
count = 0
if n > m:
tmp = min((n // 2), m)
count += tmp
m -= tmp
n -= tmp * 2
elif m > n:
tmp = min((m // 2), n)
count += tmp
n -= tmp
m -= tmp * 2
if n >= 1 and m >= 2:
count += 1
elif m >= 1 and n >= 2:
count += 1
print(count)
`... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a can... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S**... | 1,687,610,058 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,m=[int(i) for i in input().split()]
l=[]
for i in range(n):
l.append(input())
a=True
for i in range(len(l)):
if(l[i].find('G')>l[i].find('S')):
a=False
break
p=l[i].find('G')
q=l[i].find('S')
for j in range(i+1,len(l)):
z=l[j].find('S')
if(p<=z and q>z):
a=False
break
if(a==Fals... | Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of th... | ```python
n,m=[int(i) for i in input().split()]
l=[]
for i in range(n):
l.append(input())
a=True
for i in range(len(l)):
if(l[i].find('G')>l[i].find('S')):
a=False
break
p=l[i].find('G')
q=l[i].find('S')
for j in range(i+1,len(l)):
z=l[j].find('S')
if(p<=z and q>z):
a=False
break
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
689 | D | Friends and Subsequences | PROGRAMMING | 2,100 | [
"binary search",
"data structures"
] | null | null | Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?
Every one of them has an integer sequences *a* and *b* of length *n*. Being given a query of the form of pair of integers... | The first line contains only integer *n* (1<=≤<=*n*<=≤<=200<=000).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the sequence *a*.
The third line contains *n* integer numbers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109) — the sequence *b*. | Print the only integer number — the number of occasions the robot will count, thus for how many pairs is satisfied. | [
"6\n1 2 3 2 1 4\n6 7 1 2 3 2\n",
"3\n3 3 3\n1 1 1\n"
] | [
"2\n",
"0\n"
] | The occasions in the first sample case are:
1.*l* = 4,*r* = 4 since *max*{2} = *min*{2}.
2.*l* = 4,*r* = 5 since *max*{2, 1} = *min*{2, 3}.
There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1. | 2,000 | [
{
"input": "6\n1 2 3 2 1 4\n6 7 1 2 3 2",
"output": "2"
},
{
"input": "3\n3 3 3\n1 1 1",
"output": "0"
},
{
"input": "17\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388... | 1,468,742,393 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 1,638 | 38,092,800 | from bisect import bisect
HISENTINEL = 10**9 + 1
LOSENTINEL = -HISENTINEL
def main():
length = int(input())
a = [int(fld) for fld in input().strip().split()]
b = [int(fld) for fld in input().strip().split()]
print(countmaxminsubseq(a, b))
def countmaxminsubseq(a, b):
leq, lgt = ge... | Title: Friends and Subsequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?
Every one o... | ```python
from bisect import bisect
HISENTINEL = 10**9 + 1
LOSENTINEL = -HISENTINEL
def main():
length = int(input())
a = [int(fld) for fld in input().strip().split()]
b = [int(fld) for fld in input().strip().split()]
print(countmaxminsubseq(a, b))
def countmaxminsubseq(a, b):
leq... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
161 | D | Distance in Tree | PROGRAMMING | 1,800 | [
"dfs and similar",
"dp",
"trees"
] | null | null | A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of ex... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*k*<=≤<=500) — the number of vertices and the required distance between the vertices.
Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), where *a**i* and *b**i* ... | Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them.
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. | [
"5 2\n1 2\n2 3\n3 4\n2 5\n",
"5 3\n1 2\n2 3\n3 4\n4 5\n"
] | [
"4\n",
"2\n"
] | In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | 2,000 | [
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "4"
},
{
"input": "5 3\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "9"
},
{
"input": "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "10"
... | 1,686,018,732 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 342 | 12,288,000 | import builtins
from typing import *
from collections import *
from heapq import *
from functools import lru_cache
import sys
input = sys.stdin.readline
class Input:
@staticmethod
def str():
return input().strip()
@staticmethod
def int():
return int(input())
@staticmethod
de... | Title: Distance in Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices an... | ```python
import builtins
from typing import *
from collections import *
from heapq import *
from functools import lru_cache
import sys
input = sys.stdin.readline
class Input:
@staticmethod
def str():
return input().strip()
@staticmethod
def int():
return int(input())
@staticmet... | -1 | 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,509,109,307 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 39 | 124 | 0 | import math
def isPrime(num):
if num==2 or num==3:
test=True
if num>3:
for counter in range(2,math.floor(math.sqrt(num)+1)):
if num%counter==0:
test=False
break
else:
test=True
return test
primes=lis... | 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
import math
def isPrime(num):
if num==2 or num==3:
test=True
if num>3:
for counter in range(2,math.floor(math.sqrt(num)+1)):
if num%counter==0:
test=False
break
else:
test=True
return test
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
670 | D1 | Magic Powder - 1 | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"4\n",
"3\n"
] | In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredie... | 1,000 | [
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 ... | 1,691,661,389 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 46 | 102,400 | n, k = list(map(int, input().split()))
ing = list(map(int, input().split()))
qnty = list(map(int, input().split()))
import heapq
ans = []
for i in range(n):
ans.append([qnty[i]//ing[i], i])
heapq.heapify(ans)
while k:
_, i = heapq.heappop(ans)
qnty[i] += 1
k -= 1
heapq.heappush(a... | Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too dif... | ```python
n, k = list(map(int, input().split()))
ing = list(map(int, input().split()))
qnty = list(map(int, input().split()))
import heapq
ans = []
for i in range(n):
ans.append([qnty[i]//ing[i], i])
heapq.heapify(ans)
while k:
_, i = heapq.heappop(ans)
qnty[i] += 1
k -= 1
heapq.... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,377,050 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | import math
n = int(input())
print(n//5 + math.ceil((n%5) / 5)) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
import math
n = int(input())
print(n//5 + math.ceil((n%5) / 5))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,608,345,221 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 1,000 | 34,099,200 | from heapq import heappush , heappop
n,m = map(int, input().split())
dat = [[] for i in range(n+1)]
for i in range(1,m+1):
a,b,w = map(int, input().split())
dat[a].append([b,w])
dat[b].append([a,w])
dis = [float('inf') for i in range(n+1)]
path = [0 for i in range(n+1)]
q = [(0,1)]
while q:
s1,s2 = heappop(q)
f... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
from heapq import heappush , heappop
n,m = map(int, input().split())
dat = [[] for i in range(n+1)]
for i in range(1,m+1):
a,b,w = map(int, input().split())
dat[a].append([b,w])
dat[b].append([a,w])
dis = [float('inf') for i in range(n+1)]
path = [0 for i in range(n+1)]
q = [(0,1)]
while q:
s1,s2 = hea... | 0 | MatrixStudio/Codeforces-Python-Submissions |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,517,223,009 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 62 | 5,632,000 | d,h,v,e =map(int,input().split())
area=3.14159*d*d/4
if e<(v/area):
print("YES")
t=h*area/(v-(e*area))
print(t)
else:
print("NO")
#667A | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
d,h,v,e =map(int,input().split())
area=3.14159*d*d/4
if e<(v/area):
print("YES")
t=h*area/(v-(e*area))
print(t)
else:
print("NO")
#667A
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For e... | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
... | 1,665,878,951 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 77 | 2,764,800 | s = input()
t = ''.join(c for c in s if c != '1')
o = s.count('1')
if '2' in t:
i = t.index('2')
print(t[:i] + '1'*o + t[i:])
else:
print(t + '1'*o) | Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ... | ```python
s = input()
t = ''.join(c for c in s if c != '1')
o = s.count('1')
if '2' in t:
i = t.index('2')
print(t[:i] + '1'*o + t[i:])
else:
print(t + '1'*o)
``` | 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.