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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
618 | A | Slime Combining | PROGRAMMING | 800 | [
"implementation"
] | null | null | Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of... | The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000). | Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left. | [
"1\n",
"2\n",
"3\n",
"8\n"
] | [
"1\n",
"2\n",
"2 1\n",
"4\n"
] | In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. S... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "8",
"output": "4"
},
{
"input": "100000",
"output": "17 16 11 10 8 6"
},
{
"input": "12345",
"output": "14 13 6 5 4 1"
},
{
"in... | 1,454,088,604 | 1,204 | Python 3 | OK | TESTS | 27 | 62 | 0 | n = int(input())
res = []
while n > 0:
res.append(n%2)
n//=2
ans=[]
for i in range(len(res)):
if(res[i])>0:
ans.append(i+1)
ans.reverse()
print(' '.join(map(str, ans)))
| Title: Slime Combining
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, y... | ```python
n = int(input())
res = []
while n > 0:
res.append(n%2)
n//=2
ans=[]
for i in range(len(res)):
if(res[i])>0:
ans.append(i+1)
ans.reverse()
print(' '.join(map(str, ans)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
926 | B | Add Points | PROGRAMMING | 1,800 | [] | null | null | There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct.
Determine the number *m* — the smallest number of points you should add on the line to make the distances between all neighboring points equal. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100<=000) — the number of points.
The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order. | Print a single integer *m* — the smallest number of points you should add on the line to make the distances between all neighboring points equal. | [
"3\n-5 10 5\n",
"6\n100 200 400 300 600 500\n",
"4\n10 9 0 -1\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | 0 | [
{
"input": "3\n-5 10 5",
"output": "1"
},
{
"input": "6\n100 200 400 300 600 500",
"output": "0"
},
{
"input": "4\n10 9 0 -1",
"output": "8"
},
{
"input": "3\n1 4 7",
"output": "0"
},
{
"input": "3\n1 4 6",
"output": "3"
},
{
"input": "3\n1 2 6",
"... | 1,521,306,736 | 5,836 | Python 3 | OK | TESTS | 134 | 373 | 15,667,200 | n = input().split(' ')
a = list(map(int, input().split()))
a.sort()
i = 0;
d = []
while i < len(a) - 1:
d.append(a[i + 1] - a[i])
i += 1
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
g = 0
if len(d) == 1:
g = d[0]
else:
g = gcd(d[0], d[1])
i = 2
while i < len(d):
... | Title: Add Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct.
Determine the number *m* — the smallest number of points you should add on the line to make ... | ```python
n = input().split(' ')
a = list(map(int, input().split()))
a.sort()
i = 0;
d = []
while i < len(a) - 1:
d.append(a[i + 1] - a[i])
i += 1
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
g = 0
if len(d) == 1:
g = d[0]
else:
g = gcd(d[0], d[1])
i = 2
while i < ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,516,468,359 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 154 | 5,632,000 | n,m=map(int,input().split())
a=1
while True:
if m<a:
break
m-=a
if a==n:
a=1
else:
a+=1
print(m) | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n,m=map(int,input().split())
a=1
while True:
if m<a:
break
m-=a
if a==n:
a=1
else:
a+=1
print(m)
``` | 3.95101 | 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,677,553 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 420 | 21,606,400 | n = int(input())
x = 1
while n > x:
n -= x
x += 1
print(n) | 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
n = int(input())
x = 1
while n > x:
n -= x
x += 1
print(n)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,501,426,340 | 1,040 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 4,608,000 | n, k = [int(i) for i in input().split()]
a = input()
d = [[n, 0] for i in range(26)]
for i in range(n):
s = ord(a[i]) - ord('A')
d[s][0] = min(d[s][0], i)
d[s][1] = i
ev = []
for i in d:
if i[0] != n:
ev.append([i[0], 1])
ev.append([i[1], 0])
ev.sort()
b = 0
mb = 0
for i i... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
n, k = [int(i) for i in input().split()]
a = input()
d = [[n, 0] for i in range(26)]
for i in range(n):
s = ord(a[i]) - ord('A')
d[s][0] = min(d[s][0], i)
d[s][1] = i
ev = []
for i in d:
if i[0] != n:
ev.append([i[0], 1])
ev.append([i[1], 0])
ev.sort()
b = 0
mb = ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,696,748,316 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 216 | 6,860,800 | import sys
import bisect
from math import *
from queue import PriorityQueue
# Fast input reading
def input():
return sys.stdin.readline().rstrip()
# Constants
MOD = 10**9 + 7
INF = float('inf')
# Utility functions
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
... | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
import sys
import bisect
from math import *
from queue import PriorityQueue
# Fast input reading
def input():
return sys.stdin.readline().rstrip()
# Constants
MOD = 10**9 + 7
INF = float('inf')
# Utility functions
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lc... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,686,111,066 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | x, m = map(int, input().split())
servers = {}
for _ in range(x):
name, ip = input().split()
servers[ip] = name
for _ in range(m):
command, ip = input().split()
print(command, ip + ';', '#' + servers[ip])
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
x, m = map(int, input().split())
servers = {}
for _ in range(x):
name, ip = input().split()
servers[ip] = name
for _ in range(m):
command, ip = input().split()
print(command, ip + ';', '#' + servers[ip])
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,699,050,529 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 31 | 0 | q,e=map(int,input().split())
w=list(input().split())
h=0
for i in range (q):
if int(w[i])>e:
h=h+2
else:
h=h+1
print(h)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
q,e=map(int,input().split())
w=list(input().split())
h=0
for i in range (q):
if int(w[i])>e:
h=h+2
else:
h=h+1
print(h)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,639,318,261 | 2,147,483,647 | Python 3 | OK | TESTS | 8 | 46 | 0 | k = int(input())
mas = []
for i in range (k):
mas.append(int(input()))
for i in range (k):
n = mas[i]
if n < 3 or (n>3 and n<6) or n == 8 or n == 11:
print ('NO')
else:
print ('YES')
| Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
k = int(input())
mas = []
for i in range (k):
mas.append(int(input()))
for i in range (k):
n = mas[i]
if n < 3 or (n>3 and n<6) or n == 8 or n == 11:
print ('NO')
else:
print ('YES')
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
357 | A | Group of Students | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got ... | The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0. | If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. | [
"5\n3 4 3 2 1\n6 8\n",
"5\n0 3 3 4 2\n3 10\n",
"2\n2 5\n3 6\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | 500 | [
{
"input": "5\n3 4 3 2 1\n6 8",
"output": "3"
},
{
"input": "5\n0 3 3 4 2\n3 10",
"output": "4"
},
{
"input": "2\n2 5\n3 6",
"output": "0"
},
{
"input": "3\n0 1 0\n2 10",
"output": "0"
},
{
"input": "5\n2 2 2 2 2\n5 5",
"output": "0"
},
{
"input": "10\... | 1,681,113,248 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 46 | 0 | n = int(input())
t = list(map(int, input().split()))
volpl = 0
volmin = 0
for i in range(n):
volmin += t[i]
x, y = map(int, input().split())
for i in range(n - 1, -1, -1):
volpl += t[i]
volmin -= t[i]
if x <= volpl <= y:
if x <= volmin <= y:
print(i + 1)
... | Title: Group of Students
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According ... | ```python
n = int(input())
t = list(map(int, input().split()))
volpl = 0
volmin = 0
for i in range(n):
volmin += t[i]
x, y = map(int, input().split())
for i in range(n - 1, -1, -1):
volpl += t[i]
volmin -= t[i]
if x <= volpl <= y:
if x <= volmin <= y:
print(i + 1)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,567,098,058 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 233 | 14,643,200 | length = int(input());
canteens = list(map(int, input().split(' ')));
last = canteens[-1];
array = set();
for i in range(length - 1, -1, -1):
if canteens[i] not in array:
array.add(canteens[i]);
last = i;
print(canteens[last]); | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
length = int(input());
canteens = list(map(int, input().split(' ')));
last = canteens[-1];
array = set();
for i in range(length - 1, -1, -1):
if canteens[i] not in array:
array.add(canteens[i]);
last = i;
print(canteens[last]);
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,640,942,795 | 2,147,483,647 | PyPy 3 | OK | TESTS | 68 | 92 | 0 | n=int(input())
x=int(input())
p=[[0,1,2],[1,0,2],[1,2,0],[2,1,0],[2,0,1],[0,2,1],[0,1,2]]
print(p[int(n%6)][x]) | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
n=int(input())
x=int(input())
p=[[0,1,2],[1,0,2],[1,2,0],[2,1,0],[2,0,1],[0,2,1],[0,1,2]]
print(p[int(n%6)][x])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,694,356,370 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n,h=input().split()
n=int(n)
h=int(h)
i=0
width=0
sum=0
while i<n:
a=int(input())
if a>h:
width=2
else:
width=1
sum=sum+width
i+=1
print(sum)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n,h=input().split()
n=int(n)
h=int(h)
i=0
width=0
sum=0
while i<n:
a=int(input())
if a>h:
width=2
else:
width=1
sum=sum+width
i+=1
print(sum)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,537,538,161 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 374 | 7,065,600 | n,s,t = map(int,input().split())
p = [int(x) for x in input().split()]
c = p[s-1]
r=1
f=0
if(s==t):
print(0)
else:
while(r<n):
c = p[c-1]
r+=1
if(c==t):
f=1
print(r)
break
if(f==0):
print(-1) | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
n,s,t = map(int,input().split())
p = [int(x) for x in input().split()]
c = p[s-1]
r=1
f=0
if(s==t):
print(0)
else:
while(r<n):
c = p[c-1]
r+=1
if(c==t):
f=1
print(r)
break
if(f==0):
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
113 | A | Grammar Lessons | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | A. Grammar Lessons | 5 | 256 | Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of spee... | The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible tha... | If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). | [
"petr\n",
"etis atis animatis etis atis amatis\n",
"nataliala kataliala vetra feinites\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "petr",
"output": "YES"
},
{
"input": "etis atis animatis etis atis amatis",
"output": "NO"
},
{
"input": "nataliala kataliala vetra feinites",
"output": "YES"
},
{
"input": "qweasbvflios",
"output": "YES"
},
{
"input": "lios lios petr initis qwe",
... | 1,553,425,991 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | adjectives, noun, verbs, genders = [], -1, [], set()
for i, word in enumerate(input().split()):
if word.endswith('lios'):
genders.add(0)
adjectives.append(i)
elif word.endswith('liala'):
genders.add(1)
adjectives.append(i)
elif word.endswith('etr'):
if noun... | Title: Grammar Lessons
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the lang... | ```python
adjectives, noun, verbs, genders = [], -1, [], set()
for i, word in enumerate(input().split()):
if word.endswith('lios'):
genders.add(0)
adjectives.append(i)
elif word.endswith('liala'):
genders.add(1)
adjectives.append(i)
elif word.endswith('etr'):
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,651,604,643 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n=int(input())
dp=[[-1]*n]*n
def f(i,j):
if i==0 or j==0:
return 1
if dp[i-1][j-1]!=-1:
return dp[i][j]
return f(i-1,j)+f(i,j-1)
print(f(n-1,n-1))
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n=int(input())
dp=[[-1]*n]*n
def f(i,j):
if i==0 or j==0:
return 1
if dp[i-1][j-1]!=-1:
return dp[i][j]
return f(i-1,j)+f(i,j-1)
print(f(n-1,n-1))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,647,659,525 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 186 | 1,536,000 | from collections import Counter
n,m = map(int,input().split())
l = []
for i in range(n):
s = input()
l.append(s)
x = []
y = []
for i in range(n):
for j in range(m):
if l[i][j] == '*':
x.append(i)
y.append(j)
xc = Counter(x)
yc = Counter(y)
for k,v... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
from collections import Counter
n,m = map(int,input().split())
l = []
for i in range(n):
s = input()
l.append(s)
x = []
y = []
for i in range(n):
for j in range(m):
if l[i][j] == '*':
x.append(i)
y.append(j)
xc = Counter(x)
yc = Counter(y)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,675,482,762 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def gcd(a,b):
maxx=max(a,b)
minn=min(a,b)
while maxx%minn!=0:
temp=maxx
maxx=minn
minn=temp%minn
return minn
n=int(input())
if n<=2:
print(n)
continue
if n==3:
print(gcd(n,n-1)
continue
a1=n
a2=n-1
a3=n-2
g=gcd(a1,a2)
g=gcd(g,a3)
l=(a1*a2*a3)/g
print(l) | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
def gcd(a,b):
maxx=max(a,b)
minn=min(a,b)
while maxx%minn!=0:
temp=maxx
maxx=minn
minn=temp%minn
return minn
n=int(input())
if n<=2:
print(n)
continue
if n==3:
print(gcd(n,n-1)
continue
a1=n
a2=n-1
a3=n-2
g=gcd(a1,a2)
g=gcd(g,a3)
l=(a1*a2*a3)/g
print(l)
`... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,697,042,733 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n = int(input())
v = input()[:n]
c = set(v.lower())
print("Yes" if len(c) >= 26 else "No")
#Pangra
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
n = int(input())
v = input()[:n]
c = set(v.lower())
print("Yes" if len(c) >= 26 else "No")
#Pangra
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
128 | B | String | PROGRAMMING | 2,100 | [
"brute force",
"constructive algorithms",
"hashing",
"implementation",
"string suffix structures",
"strings"
] | null | null | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j... | The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105). | Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes). | [
"aa\n2\n",
"abc\n5\n",
"abab\n7\n"
] | [
"a\n",
"bc\n",
"b\n"
] | In the second sample before string "bc" follow strings "a", "ab", "abc", "b". | 1,500 | [
{
"input": "aa\n2",
"output": "a"
},
{
"input": "abc\n5",
"output": "bc"
},
{
"input": "abab\n7",
"output": "b"
},
{
"input": "codeforces\n1",
"output": "c"
},
{
"input": "cccc\n8",
"output": "ccc"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n27",
"o... | 1,462,277,474 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 8 | 1,746 | 45,260,800 | import queue
from queue import PriorityQueue
a = input()
n = int(input())
c=list(a)
l = len(c)
num = 0
if (l*l+l)/2 < n:
print('No such line.')
else:
d = PriorityQueue()
#
for i in range(l):
d.put((c[i],i))
while num < n:
num += 1
t,f = d.get()
if f<l... | Title: String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*m... | ```python
import queue
from queue import PriorityQueue
a = input()
n = int(input())
c=list(a)
l = len(c)
num = 0
if (l*l+l)/2 < n:
print('No such line.')
else:
d = PriorityQueue()
#
for i in range(l):
d.put((c[i],i))
while num < n:
num += 1
t,f = d.get()
... | -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,643,132,749 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | if __name__ == "__main__":
a, b = map(int, input().strip().split())
print(a + (a-1)//(b- 1)) | 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
if __name__ == "__main__":
a, b = map(int, input().strip().split())
print(a + (a-1)//(b- 1))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,696,265,575 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main() {
int n,h, count = 0;
cin >> n >> h;
while (n){
int x;
cin >> x;
if (x > h)
count++;
count++;
n--;
}
cout << count;
} | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
#include <iostream>
using namespace std;
int main() {
int n,h, count = 0;
cin >> n >> h;
while (n){
int x;
cin >> x;
if (x > h)
count++;
count++;
n--;
}
cout << count;
}
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,683,925,948 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input()) # Number of servers
tasks = list(map(int, input().split())) # Tasks assigned to each server
total_tasks = sum(tasks)
avg_tasks = total_tasks // n
seconds = 0
for num_tasks in tasks:
if num_tasks > avg_tasks:
seconds += num_tasks - avg_tasks
print(seconds) | Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
n = int(input()) # Number of servers
tasks = list(map(int, input().split())) # Tasks assigned to each server
total_tasks = sum(tasks)
avg_tasks = total_tasks // n
seconds = 0
for num_tasks in tasks:
if num_tasks > avg_tasks:
seconds += num_tasks - avg_tasks
print(seconds)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,689,023,813 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 93 | 13,516,800 | n = int(input())
b = [int(x) for x in input().split()]
cnt = 1
ans = 1
for i in range(1, len(b)):
if b[i] >= b[i - 1]:
cnt += 1
else:
cnt = 1
if cnt > ans:
ans = cnt
print(ans) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n = int(input())
b = [int(x) for x in input().split()]
cnt = 1
ans = 1
for i in range(1, len(b)):
if b[i] >= b[i - 1]:
cnt += 1
else:
cnt = 1
if cnt > ans:
ans = cnt
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
319 | C | Kalila and Dimna in the Logging Industry | PROGRAMMING | 2,100 | [
"dp",
"geometry"
] | null | null | Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain sa... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line of input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line of input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (0<=≤<=*b**i*<=≤<=109).
It's guaranteed that *a*1<==<=1, *b**n*<==<=0, *a*1<=&l... | The only line of output must contain the minimum cost of cutting all the trees completely.
Please, do not write 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\n1 2 3 4 5\n5 4 3 2 0\n",
"6\n1 2 3 10 20 30\n6 5 4 3 2 0\n"
] | [
"25\n",
"138\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 4 5\n5 4 3 2 0",
"output": "25"
},
{
"input": "6\n1 2 3 10 20 30\n6 5 4 3 2 0",
"output": "138"
}
] | 1,694,991,022 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 307,200 | # Timestamp: 09_17_2023_18_50_22
import sys
from collections import deque
def cross(L1, L2):
return (L2[1] - L1[1]) / (L1[0] - L2[0])
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
dp = [0]*n
hull = ... | Title: Kalila and Dimna in the Logging Industry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle a... | ```python
# Timestamp: 09_17_2023_18_50_22
import sys
from collections import deque
def cross(L1, L2):
return (L2[1] - L1[1]) / (L1[0] - L2[0])
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
dp = [0]*n
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,690,594,830 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 77 | 1,740,800 | n, k = input().split()
n,k=int(n),int(k)
a = input().split()
fit = 0
for i in a:
if int(i) + k <=5:
fit += 1
print(fit//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = input().split()
n,k=int(n),int(k)
a = input().split()
fit = 0
for i in a:
if int(i) + k <=5:
fit += 1
print(fit//3)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!
It is well-known that there are *n* cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that ... | The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*m*<=≤<=2·105) — the number of cities and the number of roads in Berland, respectively.
The roads description follow, one in each line. Each description is a pair of two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*)... | In the first line print *w* — the maximum possible number of episodes. The next *w* lines should contain the episodes in format *x*, *y*, *z* — the three integers denoting the ids of the cities in the order of the wizard's visits. | [
"4 5\n1 2\n3 2\n2 4\n3 4\n4 1\n",
"5 8\n5 3\n1 2\n4 5\n5 1\n2 5\n4 3\n1 4\n3 2\n"
] | [
"2\n1 4 2\n4 3 2\n",
"4\n1 4 5\n2 3 4\n1 5 3\n5 2 1\n"
] | none | 0 | [] | 1,690,486,313 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690486313.5697582")# 1690486313.569777 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!
It is well-known that there are *n* cities in Berland, some pairs of which are connected by bidirectional ro... | ```python
print("_RANDOM_GUESS_1690486313.5697582")# 1690486313.569777
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,628,597,841 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 78 | 6,963,200 | l=list(map(int,input().split()))
s=sum(l)
if s&1:
print("NO")
else:
s//=2
res=False
for i in range(4):
f=l[i]
for j in range(i+1,6):
t=f+l[j]
for k in range(j+1,6):
if (t+l[k])==s:
res=True
if res:
pri... | Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build ... | ```python
l=list(map(int,input().split()))
s=sum(l)
if s&1:
print("NO")
else:
s//=2
res=False
for i in range(4):
f=l[i]
for j in range(i+1,6):
t=f+l[j]
for k in range(j+1,6):
if (t+l[k])==s:
res=True
if res:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,528,729,679 | 5,579 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 77 | 0 | np=list(map(int,input().split()))
n=np[0]
p=np[1]
s=list(input())
counter=0
for i in range(n-p):
if(s[i]==s[i+p]):
if(s[i]=='.'):
s[i]='0'
s[i+p]='1'
counter+=1
else:
if(s[i]=='.')and(s[i+p]=='0'):
s[i]='1'
counter+=1
... | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
np=list(map(int,input().split()))
n=np[0]
p=np[1]
s=list(input())
counter=0
for i in range(n-p):
if(s[i]==s[i+p]):
if(s[i]=='.'):
s[i]='0'
s[i+p]='1'
counter+=1
else:
if(s[i]=='.')and(s[i+p]=='0'):
s[i]='1'
count... | -1 | 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,656,159,079 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 |
z=input()
up=0
low=0
for i in z:
if i.isupper():
up+=1
else:
low+=1
if low>=up:
print(z.lower())
else:
print(z.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
z=input()
up=0
low=0
for i in z:
if i.isupper():
up+=1
else:
low+=1
if low>=up:
print(z.lower())
else:
print(z.upper())
``` | 3.969 | 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,594,995,933 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,656,000 | n=input()
s=""
for i in n:
if i not in s:
s+=i
if "helo" in s:
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
n=input()
s=""
for i in n:
if i not in s:
s+=i
if "helo" in s:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
884 | E | Binary Matrix | PROGRAMMING | 2,500 | [
"dsu"
] | null | null | You are given a matrix of size *n*<=×<=*m*. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.
Note that the memory limit is unusual! | The first line contains two numbers *n* and *m* (1<=≤<=*n*<=≤<=212, 4<=≤<=*m*<=≤<=214) — the number of rows and columns, respectively. It is guaranteed that *m* is divisible by 4.
Then the representation of matrix follows. Each of *n* next lines contains one-digit hexadecimal numbers (that is, these numbers can be re... | Print the number of connected components consisting of 1's. | [
"3 4\n1\nA\n8\n",
"2 8\n5F\nE3\n",
"1 4\n0\n"
] | [
"3\n",
"2\n",
"0\n"
] | In the first example the matrix is:
It is clear that it has three components.
The second example:
It is clear that the number of components is 2.
There are no 1's in the third example, so the answer is 0. | 0 | [
{
"input": "3 4\n1\nA\n8",
"output": "3"
},
{
"input": "2 8\n5F\nE3",
"output": "2"
},
{
"input": "1 4\n0",
"output": "0"
},
{
"input": "1 4\nD",
"output": "2"
},
{
"input": "10 120\n4100B3BC23752433106B89343D9BA9\nD0412141283A93738E2805121044D9\nB111606365A975606... | 1,510,152,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 716,800 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/8 09:50
"""
M, N = map(int, input().split())
A = []
for i in range(M):
A.append(list(input()))
def tob(valChar):
... | Title: Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a matrix of size *n*<=×<=*m*. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a co... | ```python
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/8 09:50
"""
M, N = map(int, input().split())
A = []
for i in range(M):
A.append(list(input()))
def tob(valC... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,584,136,901 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 512,000 | import math
def yesno(num, entrada):
if(len(entrada)==0):
return 0
medidas = [int(valor) for valor in entrada]
medidas.sort()
sum = 0
if(len(entrada)%2 != 0):
for i in range(len(medidas)):
if(i%2 == 0):
sum += math.pi * medidas[i]**2
else:
sum -= math.pi * medidas[i]*... | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
import math
def yesno(num, entrada):
if(len(entrada)==0):
return 0
medidas = [int(valor) for valor in entrada]
medidas.sort()
sum = 0
if(len(entrada)%2 != 0):
for i in range(len(medidas)):
if(i%2 == 0):
sum += math.pi * medidas[i]**2
else:
sum -= math.pi * m... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,357,747 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | a = input()
a = int(a)
if a == 1 or a == 2:
print('NO')
elif a % 2 == 0:
print('YES')
else:
print('NO') | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
a = input()
a = int(a)
if a == 1 or a == 2:
print('NO')
elif a % 2 == 0:
print('YES')
else:
print('NO')
``` | 3.954 | 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,579,776,145 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 109 | 307,200 | num_input = input()
num_input = num_input.split(" ")
n = int(num_input[0])
d = int(num_input[1])
input_string = input()
cur_index = 0
jump = 0
jumping = False
while (cur_index < n - 1):
jumping = False
for i in range(d, 0, -1):
# if cur_index + i < n:
# print(input_stri... | 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
num_input = input()
num_input = num_input.split(" ")
n = int(num_input[0])
d = int(num_input[1])
input_string = input()
cur_index = 0
jump = 0
jumping = False
while (cur_index < n - 1):
jumping = False
for i in range(d, 0, -1):
# if cur_index + i < n:
# print(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,548,071,580 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | import math
r,x,y,a,b=map(int,input().split())
print(max(0,int(math.sqrt((a-x)*(a-x)+(b-y)*(b-y))//r)-1))
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
r,x,y,a,b=map(int,input().split())
print(max(0,int(math.sqrt((a-x)*(a-x)+(b-y)*(b-y))//r)-1))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
621 | C | Wet Shark and Flowers | PROGRAMMING | 1,700 | [
"combinatorics",
"math",
"number theory",
"probabilities"
] | null | null | There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too.
Each shark will grow some number of flowers *s**i*. For *i*-th shark value *s**i* is random integer equipro... | The first line of the input contains two space-separated integers *n* and *p* (3<=≤<=*n*<=≤<=100<=000,<=2<=≤<=*p*<=≤<=109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that *p* is prime.
The *i*-th of the following *n* lines contains information about *i*-th shark — two space-separat... | Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer... | [
"3 2\n1 2\n420 421\n420420 420421\n",
"3 5\n1 4\n2 3\n11 14\n"
] | [
"4500.0\n",
"0.0\n"
] | A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.
Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of ... | 1,500 | [
{
"input": "3 2\n1 2\n420 421\n420420 420421",
"output": "4500.0"
},
{
"input": "3 5\n1 4\n2 3\n11 14",
"output": "0.0"
},
{
"input": "3 3\n3 3\n2 4\n1 1",
"output": "4666.666666666667"
},
{
"input": "5 5\n5 204\n420 469\n417 480\n442 443\n44 46",
"output": "3451.25"
},... | 1,641,379,895 | 2,147,483,647 | Python 3 | OK | TESTS | 94 | 499 | 10,854,400 | n, p = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
def g(x):
global p
# количетво чисел кратных n от 1 до x
return x // p
def f(i, j):
# return (((g(a[i][1]) - g(a[i][0] - 1)) + (g(a[j][1]) - g(a[j][0] - 1)))) / (
# (a[i... | Title: Wet Shark and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too.
... | ```python
n, p = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
def g(x):
global p
# количетво чисел кратных n от 1 до x
return x // p
def f(i, j):
# return (((g(a[i][1]) - g(a[i][0] - 1)) + (g(a[j][1]) - g(a[j][0] - 1)))) / (
# ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,656,440,797 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | l1=[int(i) for i in input().split()]
d1=l1[0]
d2=l1[1]
d3=l1[-1]
count=0
if d1<d2:
count=count+d1
if d3<d1+d2:
count=count+d3
if d2<d3+d1:
count=count+d2
else :
count=count+d3+d1
else :
count=count+d1+d2
if d2<d3+d1:
... | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
l1=[int(i) for i in input().split()]
d1=l1[0]
d2=l1[1]
d3=l1[-1]
count=0
if d1<d2:
count=count+d1
if d3<d1+d2:
count=count+d3
if d2<d3+d1:
count=count+d2
else :
count=count+d3+d1
else :
count=count+d1+d2
if d2<d3+d1:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,426,096 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 249 | 268,390,400 | num = input()
a = num.split(" ")[0]
b = num.split(" ")[1]
i = 0
while a<=b:
a = a*3
b = b*2
i +=1
print(i) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
num = input()
a = num.split(" ")[0]
b = num.split(" ")[1]
i = 0
while a<=b:
a = a*3
b = b*2
i +=1
print(i)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,679,310,646 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | from math import sqrt
def solve():
a,b,c,d=map(int,input().split())
mish=max((3*a)//10,a-(a//250)*c)
vas=max((3*b)//10,b-(b//250)*d)
print ("Misha") if mish>vas else print("Vasya") if vas>mish else print("Tie")
solve()
| Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
from math import sqrt
def solve():
a,b,c,d=map(int,input().split())
mish=max((3*a)//10,a-(a//250)*c)
vas=max((3*b)//10,b-(b//250)*d)
print ("Misha") if mish>vas else print("Vasya") if vas>mish else print("Tie")
solve()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
999 | E | Reachability from the Capital | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way. | The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_... | Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. | [
"9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n",
"5 4 5\n1 2\n2 3\n3 4\n4 1\n"
] | [
"3\n",
"1\n"
] | The first example is illustrated by the following:
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following:
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci... | 0 | [
{
"input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1",
"output": "3"
},
{
"input": "5 4 5\n1 2\n2 3\n3 4\n4 1",
"output": "1"
},
{
"input": "5000 0 2956",
"output": "4999"
},
{
"input": "2 0 2",
"output": "1"
},
{
"input": "2 1 1\n1 2",
"output": "0"... | 1,682,714,479 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | n, m, s = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
u, v = map(int, input().split())
graph[u-1].append(v-1)
visited = [False] * n
visited[s-1] = True
def dfs(u):
visited[u] = True
for v in graph[u]:
if not visited[v]:
dfs(v)
dfs(s-1)
num_visited... | Title: Reachability from the Capital
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities r... | ```python
n, m, s = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
u, v = map(int, input().split())
graph[u-1].append(v-1)
visited = [False] * n
visited[s-1] = True
def dfs(u):
visited[u] = True
for v in graph[u]:
if not visited[v]:
dfs(v)
dfs(s-1)
n... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,683,921,256 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 1,126,400 | v1=input()
import string
gg=string.ascii_letters
v1=v1.split(",")
b=[]
for i in v1:
for j in i:
if j in gg:
b.append(j)
print(len(set(b))) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
v1=input()
import string
gg=string.ascii_letters
v1=v1.split(",")
b=[]
for i in v1:
for j in i:
if j in gg:
b.append(j)
print(len(set(b)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,601,809,890 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 140 | 0 | from sys import stdin, stdout # only need for big input
def read_int_from_line():
return list(map(int, input().split()))
def solve():
n, a = read_int_from_line()
a -= 1
t = read_int_from_line()
count = t[a]
for i in range(1, n):
i1 = a - i
i2 = a + i
target = []
... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
from sys import stdin, stdout # only need for big input
def read_int_from_line():
return list(map(int, input().split()))
def solve():
n, a = read_int_from_line()
a -= 1
t = read_int_from_line()
count = t[a]
for i in range(1, n):
i1 = a - i
i2 = a + i
target =... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and *n* columns. At the beginning of the game the hero is in some cell of the left... | Each test contains from one to ten sets of the input data. The first line of the test contains a single integer *t* (1<=≤<=*t*<=≤<=10 for pretests and tests or *t*<==<=1 for hacks; see the Notes section for details) — the number of sets.
Then follows the description of *t* sets of the input data.
The first line of t... | For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise. | [
"2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n",
"2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n"
] | [
"YES\nNO\n",
"YES\nNO\n"
] | In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the ... | 0 | [] | 1,445,347,332 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | def schet(x,y,l):
global rail
global res
if x==l-1 or rail[y][x]=="*":
res="YES"
return
elif rail[y][x]!=".":
return
if rail[y][x+1]==".":
schet(x+2,y,l)
if rail[y-1][x+1]==".":
schet(x+3,y-1,l)
if rail[y+1][x+1]==".":
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of thr... | ```python
def schet(x,y,l):
global rail
global res
if x==l-1 or rail[y][x]=="*":
res="YES"
return
elif rail[y][x]!=".":
return
if rail[y][x+1]==".":
schet(x+2,y,l)
if rail[y-1][x+1]==".":
schet(x+3,y-1,l)
if rail[y+1][x+1]==".":... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,693,371,864 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=input("")
b=input("")
c=a.length()
i=0
j=c-1
for i in range(c//2):
swap(a[i], a[j])
i++
j--
if (a==b):
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
a=input("")
b=input("")
c=a.length()
i=0
j=c-1
for i in range(c//2):
swap(a[i], a[j])
i++
j--
if (a==b):
print("YES")
else:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,698,134,035 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | n=int(input())
seq=sorted(list(map(int,input().split())))
ttl=0
ct=0
i=0
while len(seq)>0:
if ttl>seq[0]:
s0=seq[0]
while 1:
if seq[0]==s0:
seq.pop(0)
else:
break
else:
ttl+=seq[0]
ct+=1
seq.pop(0)
p... | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
n=int(input())
seq=sorted(list(map(int,input().split())))
ttl=0
ct=0
i=0
while len(seq)>0:
if ttl>seq[0]:
s0=seq[0]
while 1:
if seq[0]==s0:
seq.pop(0)
else:
break
else:
ttl+=seq[0]
ct+=1
seq... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
396 | C | On Changing Tree | PROGRAMMING | 0 | [
"data structures",
"graphs",
"trees"
] | null | null | You are given a rooted tree consisting of *n* vertices numbered from 1 to *n*. The root of the tree is a vertex number 1.
Initially all vertices contain number 0. Then come *q* queries, each query has one of the two types:
- The format of the query: 1 *v* *x* *k*. In response to the query, you need to add to the num... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=... *p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is the number of the vertex that is the parent of vertex *i* in the tree.
The third line contains integer *q* (1<=... | For each query of the second type print on a single line the number written in the vertex from the query. Print the number modulo 1000000007 (109<=+<=7). | [
"3\n1 1\n3\n1 1 2 1\n2 1\n2 2\n"
] | [
"2\n1\n"
] | You can read about a rooted tree here: http://en.wikipedia.org/wiki/Tree_(graph_theory). | 1,500 | [
{
"input": "3\n1 1\n3\n1 1 2 1\n2 1\n2 2",
"output": "2\n1"
},
{
"input": "10\n1 2 3 4 4 3 3 6 7\n10\n1 6 13 98\n1 7 17 66\n1 5 32 39\n1 1 9 5\n1 7 27 11\n1 1 24 79\n1 5 87 86\n2 2\n1 5 9 38\n2 5",
"output": "999999956\n999999832"
},
{
"input": "1\n\n1\n2 1",
"output": "0"
}
] | 1,584,855,926 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 140 | 0 | n = int(input())
pxk = [[0 for i in range(3)] for i in range(n + 2)]
ps = ['', ''] + input().split(' ')
for i in range(2, n + 1):
pxk[i][0] = int(ps[i])
q = int(input())
for i in range(q):
qs = [int(i) for i in input().split(' ')]
if qs[0] == 1:
pxk[qs[1]][1] += qs[2]
pxk[qs[1]][2] += qs[3]
elif qs[0] == 2:
... | Title: On Changing Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree consisting of *n* vertices numbered from 1 to *n*. The root of the tree is a vertex number 1.
Initially all vertices contain number 0. Then come *q* queries, each query has one of the two t... | ```python
n = int(input())
pxk = [[0 for i in range(3)] for i in range(n + 2)]
ps = ['', ''] + input().split(' ')
for i in range(2, n + 1):
pxk[i][0] = int(ps[i])
q = int(input())
for i in range(q):
qs = [int(i) for i in input().split(' ')]
if qs[0] == 1:
pxk[qs[1]][1] += qs[2]
pxk[qs[1]][2] += qs[3]
elif qs[... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,697,120,876 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 92 | 307,200 | from functools import lru_cache
lru_cache(maxsize=None)
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
output=a[n-1]-a[0]
for i in range(1,m-n+1):
if a[i+n-1]-a[i]<output:
output=a[i+n-1]-a[i]
print(output) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
from functools import lru_cache
lru_cache(maxsize=None)
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
output=a[n-1]-a[0]
for i in range(1,m-n+1):
if a[i+n-1]-a[i]<output:
output=a[i+n-1]-a[i]
print(output)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,653,067,131 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=input()
a=input()
ans=a[0]
for i in range(1,n):
if (i%2) == (n%2):
ans=a[i]+ans
else:
ans+=a[i]
print ans
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n=input()
a=input()
ans=a[0]
for i in range(1,n):
if (i%2) == (n%2):
ans=a[i]+ans
else:
ans+=a[i]
print ans
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
821 | B | Okabe and Banana Trees | PROGRAMMING | 1,300 | [
"brute force",
"math"
] | null | null | Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ... | The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). | Print the maximum number of bananas Okabe can get from the trees he cuts. | [
"1 5\n",
"2 3\n"
] | [
"30\n",
"25\n"
] | The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas. | 1,000 | [
{
"input": "1 5",
"output": "30"
},
{
"input": "2 3",
"output": "25"
},
{
"input": "4 6",
"output": "459"
},
{
"input": "6 3",
"output": "171"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 1",
"output": "55"
},
{
"input": "20 10",
... | 1,498,454,247 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 77 | 5,529,600 | def check(x,y):
f1 = x*(x+1)//2
f2 = y*(y+1)//2
return (x+1)*f2 + (y+1)*f1
if __name__ =="__main__":
m,b = map(int,input().split())
y = b
ma = 0
for i in range(0,m*b+1,m):
if check(i,y)>ma:
ma = check(i,y)
y-=1
print(ma)
| Title: Okabe and Banana Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers a... | ```python
def check(x,y):
f1 = x*(x+1)//2
f2 = y*(y+1)//2
return (x+1)*f2 + (y+1)*f1
if __name__ =="__main__":
m,b = map(int,input().split())
y = b
ma = 0
for i in range(0,m*b+1,m):
if check(i,y)>ma:
ma = check(i,y)
y-=1
print(ma)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,631,377,393 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 6,758,400 | import math
n = input()
ns = list(map(int, n.split(' ')))
x = ns[1]
while ns[0] <= ns[1]:
x = math.gcd(x,ns[0])
ns[0] += 1
print(x)
| Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
import math
n = input()
ns = list(map(int, n.split(' ')))
x = ns[1]
while ns[0] <= ns[1]:
x = math.gcd(x,ns[0])
ns[0] += 1
print(x)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | 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.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ... | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100... | 1,670,678,111 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | def get(l):
# make minimum number near l and greatest number upto r or bigger.
L = '7'*len(str(l))
if L<str(l):
L = '4'*len(str)+'4'
return L
else:
l1 = list(str(l))
L1 = list(L)
for i in range(len(L)):
if L1[i]==l1[i]:
cont... | Title: Lucky Sum
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.
Let *... | ```python
def get(l):
# make minimum number near l and greatest number upto r or bigger.
L = '7'*len(str(l))
if L<str(l):
L = '4'*len(str)+'4'
return L
else:
l1 = list(str(l))
L1 = list(L)
for i in range(len(L)):
if L1[i]==l1[i]:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,677,866,010 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | a,b,k,t = map(int,input().split())
s = input()
ts = 0
for i in range(len(s)):
if int(s[i]) == a: ts+=a
elif int(s[i]) == b: ts+=b
elif int(s[i]) == k: ts+=k
elif int(s[i]) == t: ts+=t
print(ts) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a,b,k,t = map(int,input().split())
s = input()
ts = 0
for i in range(len(s)):
if int(s[i]) == a: ts+=a
elif int(s[i]) == b: ts+=b
elif int(s[i]) == k: ts+=k
elif int(s[i]) == t: ts+=t
print(ts)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,621,182,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | s=input()
k=int(input())
b=len(s)//k
flag=c=0
for i in range(0,len(s),k):
a=s[i:i+b]
if a!=a[::-1]:
flag+=1
break
if flag:
print("NO")
else:
print("YES") | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
s=input()
k=int(input())
b=len(s)//k
flag=c=0
for i in range(0,len(s),k):
a=s[i:i+b]
if a!=a[::-1]:
flag+=1
break
if flag:
print("NO")
else:
print("YES")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,682,602,287 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | from math import ceil
n,m=map(int,input().split())
print(ceil(n*m/5))
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
from math import ceil
n,m=map(int,input().split())
print(ceil(n*m/5))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
745 | B | Hongcow Solves A Puzzle | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed tha... | The first line of input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500), the dimensions of the puzzle piece.
The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty ... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | [
"2 3\nXXX\nXXX\n",
"2 2\n.X\nXX\n",
"5 5\n.....\n..X..\n.....\n.....\n.....\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | 1,000 | [
{
"input": "2 3\nXXX\nXXX",
"output": "YES"
},
{
"input": "2 2\n.X\nXX",
"output": "NO"
},
{
"input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | 1,481,997,859 | 5,359 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 217 | 33,177,600 | n, m = [int(x) for x in input().split()]
grid = []
grid1 = ['']*m
V = [0]*n
Z = [0]*m
for i in range(n):
grid.append(input())
V[i] = grid[i].count('X')
for j in range(m):
grid1[j] += grid[i][j]
for i in range(m):
Z[i] = grid1[i].count('X')
if sum(V) == sum(Z) == 1:
print("YES")
... | Title: Hongcow Solves A Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where t... | ```python
n, m = [int(x) for x in input().split()]
grid = []
grid1 = ['']*m
V = [0]*n
Z = [0]*m
for i in range(n):
grid.append(input())
V[i] = grid[i].count('X')
for j in range(m):
grid1[j] += grid[i][j]
for i in range(m):
Z[i] = grid1[i].count('X')
if sum(V) == sum(Z) == 1:
pri... | 0 | 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,663,710,493 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | """
"""
class UltraFast:
def solve(self, num1, num2):
res = ""
for i in range(len(num1)):
if num1[i] == num2[i]:
res += "0"
else:
res += "1"
return res
if __name__ == "__main__":
uf = UltraFast()
num1 = list(input())
num2... | 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
"""
"""
class UltraFast:
def solve(self, num1, num2):
res = ""
for i in range(len(num1)):
if num1[i] == num2[i]:
res += "0"
else:
res += "1"
return res
if __name__ == "__main__":
uf = UltraFast()
num1 = list(input()... | 3.9885 | MatrixStudio/Codeforces-Python-Submissions |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,513,486,533 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 5,529,600 | n=int(input())
line=[int(i) for i in input().split()]
if n>3:
s=[]
k=0
gap=0
for i in range(1,n-1):
if line[i+1]-line[i]==line[i]-line[i-1]:
gap=line[i+1]-line[i]
else:
s.append(line[i-1])
s.append(line[i])
s.append(line[i+1])
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
line=[int(i) for i in input().split()]
if n>3:
s=[]
k=0
gap=0
for i in range(1,n-1):
if line[i+1]-line[i]==line[i]-line[i-1]:
gap=line[i+1]-line[i]
else:
s.append(line[i-1])
s.append(line[i])
s.append(li... | 0 | MatrixStudio/Codeforces-Python-Submissions |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,598,766,467 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 1,433,600 | a = input()
s = []
for i in a:
s.append(i)
s.reverse()
s = ''.join(s)
print(a+s) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
a = input()
s = []
for i in a:
s.append(i)
s.reverse()
s = ''.join(s)
print(a+s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
468 | C | Hack it! | PROGRAMMING | 2,500 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018). | Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=<<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | 1,500 | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 2492213340204320744986569... | 1,653,688,000 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,867,200 | def ds(x):
y = x
s = 0
while(y > 0):
s += y%10
y /= 10
return s
n = 9*int(input())
rem = ds(10**69-n)-ds(n)-ds(n+1)
mul = 0
while (rem > 9):
mul *= 10
mul += 9
rem -= 9
mul *= 10
mul += rem
print(mul*10**69-n+1 + " " + mul*10**69+n+1)
| Title: Hack it!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X ... | ```python
def ds(x):
y = x
s = 0
while(y > 0):
s += y%10
y /= 10
return s
n = 9*int(input())
rem = ds(10**69-n)-ds(n)-ds(n+1)
mul = 0
while (rem > 9):
mul *= 10
mul += 9
rem -= 9
mul *= 10
mul += rem
print(mul*10**69-n+1 + " " + mul*10**69+n+1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "... | 1,620,656,367 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 77 | 6,758,400 | x,y=map(int,input().split())
if(x==y or (x==2 and y==4) or (x==4 and y==2)):
print("=")
elif(x==1 or (x==2 and y==3)):
print("<")
elif(y==1 or (x==3 and y==2)):
print(">")
elif(x<y):
print(">")
else:
print("<") | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out tha... | ```python
x,y=map(int,input().split())
if(x==y or (x==2 and y==4) or (x==4 and y==2)):
print("=")
elif(x==1 or (x==2 and y==3)):
print("<")
elif(y==1 or (x==3 and y==2)):
print(">")
elif(x<y):
print(">")
else:
print("<")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,575,288,205 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 0 | n=input()
s=input()
count=0
for i in s:
count+=1
if i=='0':
break
print(count) | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n=input()
s=input()
count=0
for i in s:
count+=1
if i=='0':
break
print(count)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
652 | A | Gabriel and Caterpillar | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when ... | The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=<<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeter... | Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer <=-<=1. | [
"10 30\n2 1\n",
"10 13\n1 1\n",
"10 19\n1 2\n",
"1 50\n5 4\n"
] | [
"1\n",
"0\n",
"-1\n",
"1\n"
] | In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the n... | 0 | [
{
"input": "10 30\n2 1",
"output": "1"
},
{
"input": "10 13\n1 1",
"output": "0"
},
{
"input": "10 19\n1 2",
"output": "-1"
},
{
"input": "1 50\n5 4",
"output": "1"
},
{
"input": "1 1000\n2 1",
"output": "82"
},
{
"input": "999 1000\n1 1",
"output"... | 1,585,401,038 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 124 | 307,200 |
h1 , h2 = map(int , input().split())
inc , dec = map(int , input().split())
temp = h1
j = 1
if inc <= dec and h1 + inc * 8 < h2:
print(-1)
exit(0)
h1 += inc * 8
if h1 >= h2:
print(0)
exit(0)
h1 -= dec * 12
while h1 < h2:
h1 += inc * 12
if h1 >= h2:
break
h1 -= dec * 12
... | Title: Gabriel and Caterpillar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*... | ```python
h1 , h2 = map(int , input().split())
inc , dec = map(int , input().split())
temp = h1
j = 1
if inc <= dec and h1 + inc * 8 < h2:
print(-1)
exit(0)
h1 += inc * 8
if h1 >= h2:
print(0)
exit(0)
h1 -= dec * 12
while h1 < h2:
h1 += inc * 12
if h1 >= h2:
break
h1 -= d... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,566,040,987 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | from math import sqrt,ceil
a,b=map(int,input().split())
if ceil(sqrt(a))==int(sqrt(a)):
print("valera")
else:
print("vladik") | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
from math import sqrt,ceil
a,b=map(int,input().split())
if ceil(sqrt(a))==int(sqrt(a)):
print("valera")
else:
print("vladik")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,602,939,333 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | from math import *
n, v = map(int, input().split())
l = list()
k = 0
index = list()
for i in range (0, n):
l.append(list())
s = input()
s = s[2:len(s)]
l[i] = s.split()
l[i] = list(map(lambda x : int(x), l[i]))
print(l[i][0])
if(l[i][0] < v):
index.append(i+1)
k+=1
print(k)
if k ... | Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
from math import *
n, v = map(int, input().split())
l = list()
k = 0
index = list()
for i in range (0, n):
l.append(list())
s = input()
s = s[2:len(s)]
l[i] = s.split()
l[i] = list(map(lambda x : int(x), l[i]))
print(l[i][0])
if(l[i][0] < v):
index.append(i+1)
k+=1
print... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,691,832,202 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | s=input()
l=[]
n=s.count('WUB')
x=0
for i in range(n):
l.append(s.find('WUB',x))
x=l[i]+1
for i in range(len(l)-1):
if abs(l[i+1]-l[i])>3:
print(s[l[i]+3:l[i+1]],end=' ')
if l[len(l)-1]+3<len(s)-1:
print(s[l[len(l)-1]+3:]) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
s=input()
l=[]
n=s.count('WUB')
x=0
for i in range(n):
l.append(s.find('WUB',x))
x=l[i]+1
for i in range(len(l)-1):
if abs(l[i+1]-l[i])>3:
print(s[l[i]+3:l[i+1]],end=' ')
if l[len(l)-1]+3<len(s)-1:
print(s[l[len(l)-1]+3:])
``` | 0 | 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,668,088,389 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | def check(board, y, x):
c = board[y-1][x-1]+board[y-1][x]+ board[y-1][x+1]+board[y][x-1]+board[y][x+1]+board[y+1][x-1]+board[y+1][x]+board[y+1][x+1]
if board[y][x] and (c<2 or c>3):
return 0
elif board[y][x]==0 and c==3:
return 1
return board[y][x]
n, m = map(int, input().split())... | 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
def check(board, y, x):
c = board[y-1][x-1]+board[y-1][x]+ board[y-1][x+1]+board[y][x-1]+board[y][x+1]+board[y+1][x-1]+board[y+1][x]+board[y+1][x+1]
if board[y][x] and (c<2 or c>3):
return 0
elif board[y][x]==0 and c==3:
return 1
return board[y][x]
n, m = map(int, input(... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i... | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ... | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\... | 1,682,602,861 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 10,547,200 | class ObjTemp:
def __init__(self):
self.soma = 0
def contarQuadros(cells, i, j, res, objTemp):
if (cells[i][j] == '*' or res[i][j] != None):
return
valorRetorno = 0
if (i > 0 and cells[i-1][j] == '*'):
valorRetorno += 1
if (i < len(cells)-1 and ... | Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'... | ```python
class ObjTemp:
def __init__(self):
self.soma = 0
def contarQuadros(cells, i, j, res, objTemp):
if (cells[i][j] == '*' or res[i][j] != None):
return
valorRetorno = 0
if (i > 0 and cells[i-1][j] == '*'):
valorRetorno += 1
if (i < len(cel... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,693,157,493 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 103 | 1,013 | 14,028,800 | n = int(input())
costs = list(map(int, input().split()))
costs.sort()
k = int(input())
for _ in range(k):
x = int(input())
l = 0
r = n-1
ans = 0
while l<=r:
mid = l+(r-l)//2
if costs[mid]<=x:
ans = mid+1
l = mid+1
else:
r = mid-1
print... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
n = int(input())
costs = list(map(int, input().split()))
costs.sort()
k = int(input())
for _ in range(k):
x = int(input())
l = 0
r = n-1
ans = 0
while l<=r:
mid = l+(r-l)//2
if costs[mid]<=x:
ans = mid+1
l = mid+1
else:
r = mid-1... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
1,010 | F | Tree | PROGRAMMING | 3,400 | [
"fft",
"graphs",
"trees"
] | null | null | The Main Martian Tree grows on Mars. It is a binary tree (a rooted tree, with no more than two sons at each vertex) with $n$ vertices, where the root vertex has the number $1$. Its fruits are the Main Martian Fruits. It's summer now, so this tree does not have any fruit yet.
Autumn is coming soon, and leaves and branc... | The first line contains two integers: $n$ and $x$ ($1 \le n \le 10^5$, $0 \le x \le 10^{18}$) — the size of the tree and the number of fruits in the root.
The $i$-th of the following $(n-1)$ lines contains two integers $a_i$ and $b_i$ ($1 \le a_i, b_i \le n$) — vertices connected by the $i$-th edge of the tree.
It is... | Print one number — the number of configurations of the resulting tree modulo $998244353$. | [
"3 2\n1 2\n1 3\n",
"2 5\n1 2\n",
"4 10\n1 2\n1 3\n3 4\n"
] | [
"13\n",
"7\n",
"441\n"
] | Consider the first example. <img class="tex-graphics" src="https://espresso.codeforces.com/5d4507ad53aaf6b231fe52f14f47257b4e5a6677.png" style="max-width: 100.0%;max-height: 100.0%;"/>
There are $2$ fruits at the vertex $1$. The following $13$ options are possible:
- there is no vertex $2$, there is no vertex $3$; <i... | 2,750 | [] | 1,610,966,902 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import math
print(4) | Title: Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Main Martian Tree grows on Mars. It is a binary tree (a rooted tree, with no more than two sons at each vertex) with $n$ vertices, where the root vertex has the number $1$. Its fruits are the Main Martian Fruits. It's summer n... | ```python
import math
print(4)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,531,669,303 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 436 | 28,364,800 | n = int(input())
p = list(reversed(sorted(list(map(int, input().split())))))
a = p
for i in range(1, n):
a[i] += a[i - 1]
s = a[-1]
for i in range(n - 1):
s += a[n - 1 - i]
print(s)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n = int(input())
p = list(reversed(sorted(list(map(int, input().split())))))
a = p
for i in range(1, n):
a[i] += a[i - 1]
s = a[-1]
for i in range(n - 1):
s += a[n - 1 - i]
print(s)
``` | 3 | 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,614,517,340 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m, n = map(int, input().split())
if ((int(m) * int(n)) % 2) == 0:
y = ((int(m) * int(n) * 0.5))
print(int(y))
elif((int(m) * int(n)) % 2) == 1:
y = (((int(m) * int(n)) - 1) * 0.5)
print(int(y))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = map(int, input().split())
if ((int(m) * int(n)) % 2) == 0:
y = ((int(m) * int(n) * 0.5))
print(int(y))
elif((int(m) * int(n)) % 2) == 1:
y = (((int(m) * int(n)) - 1) * 0.5)
print(int(y))
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,603,254,802 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | n,m=list(map(int,input().split()))
n_max=n
n_min=n
lst=list(map(int,input().split()))
maxx=0
minn=0
lst_max=lst[:]
lst_min=lst[:]
while n_max>0:
lst_max=sorted(lst_max,reverse=True)
maxx+=lst_max[0]
lst_max[0]=lst_max[0]-1
n_max-=1
i=0
while n_min>0:
lst_min=sorted(lst)
if ls... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
n,m=list(map(int,input().split()))
n_max=n
n_min=n
lst=list(map(int,input().split()))
maxx=0
minn=0
lst_max=lst[:]
lst_min=lst[:]
while n_max>0:
lst_max=sorted(lst_max,reverse=True)
maxx+=lst_max[0]
lst_max[0]=lst_max[0]-1
n_max-=1
i=0
while n_min>0:
lst_min=sorted(lst)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,593,068,110 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 218 | 6,963,200 | n = int(input())
womansOrChilds = []
childs = []
mans = []
rats = []
captains = []
for _ in range(n):
s = input()
s = s.split()
if s[1] == 'rat':
rats.append(s[0])
if s[1] == 'man':
mans.append(s[0])
if s[1] == 'woman':
womansOrChilds.append(s[0])
if s[... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
n = int(input())
womansOrChilds = []
childs = []
mans = []
rats = []
captains = []
for _ in range(n):
s = input()
s = s.split()
if s[1] == 'rat':
rats.append(s[0])
if s[1] == 'man':
mans.append(s[0])
if s[1] == 'woman':
womansOrChilds.append(s[0])
... | 3.93253 | MatrixStudio/Codeforces-Python-Submissions |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,657,887,760 | 2,147,483,647 | Python 3 | OK | TESTS | 74 | 46 | 0 | a,b,c,d=map(int,input().split())
l=abs(a-c)
m=abs(b-d)
if a==c:
print(a+m,b,c+m,d)
elif b==d:
print(a,b+l,c,d+l)
elif l!=m:
print(-1)
else:
print(a,d,c,b) | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
a,b,c,d=map(int,input().split())
l=abs(a-c)
m=abs(b-d)
if a==c:
print(a+m,b,c+m,d)
elif b==d:
print(a,b+l,c,d+l)
elif l!=m:
print(-1)
else:
print(a,d,c,b)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
409 | H | A + B Strikes Back | PROGRAMMING | 1,500 | [
"*special",
"brute force",
"constructive algorithms",
"dsu",
"implementation"
] | null | null | A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? | The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. | Output the sum of the given integers. | [
"5 14\n",
"381 492\n"
] | [
"19\n",
"873\n"
] | none | 0 | [
{
"input": "5 14",
"output": "19"
},
{
"input": "381 492",
"output": "873"
},
{
"input": "536 298",
"output": "834"
},
{
"input": "143 522",
"output": "665"
},
{
"input": "433 126",
"output": "559"
},
{
"input": "723 350",
"output": "1073"
},
{... | 1,644,839,272 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | a,b=map(int,input().split())
c=4
print(a+b) | Title: A + B Strikes Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
Input ... | ```python
a,b=map(int,input().split())
c=4
print(a+b)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th... | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{... | 1,538,249,594 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | x=int(input())
a=[str(i)for i in input()]
k=0
for i in a:
if a.count(i)>k:
k=a.count(i)
a=[str(i)for i in input()]
h=0
for i in a:
if a.count(i)>h:
h=a.count(i)
a=[str(i)for i in input()]
p=0
for i in a:
if a.count(i)>p:
p=a.count(i)
if k>h and k>p:
print("Kuro")
elif p>h and p>k:
print("K... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friend... | ```python
x=int(input())
a=[str(i)for i in input()]
k=0
for i in a:
if a.count(i)>k:
k=a.count(i)
a=[str(i)for i in input()]
h=0
for i in a:
if a.count(i)>h:
h=a.count(i)
a=[str(i)for i in input()]
p=0
for i in a:
if a.count(i)>p:
p=a.count(i)
if k>h and k>p:
print("Kuro")
elif p>h and p>k:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,632,245,297 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 22,425,600 | a=int(input())
b=int(input())
if a==b:
print(a)
else:
print(1) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
a=int(input())
b=int(input())
if a==b:
print(a)
else:
print(1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
837 | F | Prefix Sums | PROGRAMMING | 2,400 | [
"binary search",
"brute force",
"combinatorics",
"math",
"matrices"
] | null | null | Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*).
You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=≤<=1018). *n* is the size of array *A*0.
The second line contains *n* integers *A*00,<=*A*01... *A*0*n*<=-<=1 — the elements of *A*0 (0<=≤<=*A*0*i*<=≤<=109). At least two elements of *A*0 are positive. | Print the minimum *i* such that *A**i* contains a number which is larger or equal than *k*. | [
"2 2\n1 1\n",
"3 6\n1 1 1\n",
"3 1\n1 0 1\n"
] | [
"1\n",
"2\n",
"0\n"
] | none | 0 | [
{
"input": "2 2\n1 1",
"output": "1"
},
{
"input": "3 6\n1 1 1",
"output": "2"
},
{
"input": "3 1\n1 0 1",
"output": "0"
},
{
"input": "3 1000000000000000000\n5 4 5",
"output": "632455531"
},
{
"input": "4 1000000000000000000\n0 4 4 5",
"output": "707106780"
... | 1,669,143,856 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 93 | 22,118,400 | from sys import stdin
input=lambda :stdin.readline()[:-1]
def matmul(A,B):
res = [[0]*len(B[0]) for _ in [None]*len(A)]
for i, resi in enumerate(res):
for k, aik in enumerate(A[i]):
for j,bkj in enumerate(B[k]):
resi[j] += aik*bkj
resi[j] = min(resi[... | Title: Prefix Sums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*).... | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
def matmul(A,B):
res = [[0]*len(B[0]) for _ in [None]*len(A)]
for i, resi in enumerate(res):
for k, aik in enumerate(A[i]):
for j,bkj in enumerate(B[k]):
resi[j] += aik*bkj
resi[j] =... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
985 | A | Chess Placing | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move... | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100, *n* is even) — the size of the chessboard.
The second line of the input contains integer numbers (1<=≤<=*p**i*<=≤<=*n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct. | Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color. | [
"6\n1 2 6\n",
"10\n1 2 3 4 5\n"
] | [
"2\n",
"10\n"
] | In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.
In the second example the possible strategy is to move... | 0 | [
{
"input": "6\n1 2 6",
"output": "2"
},
{
"input": "10\n1 2 3 4 5",
"output": "10"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 ... | 1,549,370,318 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n=int(input())
l=[int(i) for i in input().split()]
l1=[i for i in range(2,n+1,2)]
l2=[i for i in range(1,n,2)]
s1=sum(abs(l1[i]-l[i]) for i in range(n//2))
s2=sum(abs(l2[i]-l[i]) for i in range(n//2))
#print(s1,s2)
print(min(s1,s2)) | Title: Chess Placing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than... | ```python
n=int(input())
l=[int(i) for i in input().split()]
l1=[i for i in range(2,n+1,2)]
l2=[i for i in range(1,n,2)]
s1=sum(abs(l1[i]-l[i]) for i in range(n//2))
s2=sum(abs(l2[i]-l[i]) for i in range(n//2))
#print(s1,s2)
print(min(s1,s2))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,648,904,498 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 904 | 2,457,600 | import math
n=int(input())
c=0
for i in range(1,n+1):
for j in range(i,n+1):
p=math.sqrt(i*i+j*j)
if p<=n:
if p.is_integer():
c+=1
print(c) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
import math
n=int(input())
c=0
for i in range(1,n+1):
for j in range(i,n+1):
p=math.sqrt(i*i+j*j)
if p<=n:
if p.is_integer():
c+=1
print(c)
``` | 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,648,307,460 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | from math import lcm
n,m,z=map(int,input().split())
print(z//lcm(n,m)) | 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
from math import lcm
n,m,z=map(int,input().split())
print(z//lcm(n,m))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,510,510,140 | 7,440 | PyPy 3 | OK | TESTS | 53 | 124 | 307,200 | l=tuple(map(int, input().split()))
su=sum(l)
if su%2!=0:
print('NO')
else:
su//=2
b=False
for i in range(6):
for j in range(6):
if i==j:
break
for h in range(6):
if h==i or h==j:
break
b=l[i... | Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build ... | ```python
l=tuple(map(int, input().split()))
su=sum(l)
if su%2!=0:
print('NO')
else:
su//=2
b=False
for i in range(6):
for j in range(6):
if i==j:
break
for h in range(6):
if h==i or h==j:
break
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
370 | A | Rook, Bishop and King | PROGRAMMING | 1,100 | [
"graphs",
"math",
"shortest paths"
] | null | null | Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of... | The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb... | Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. | [
"4 3 1 6\n",
"5 5 5 6\n"
] | [
"2 1 3\n",
"1 0 1\n"
] | none | 500 | [
{
"input": "4 3 1 6",
"output": "2 1 3"
},
{
"input": "5 5 5 6",
"output": "1 0 1"
},
{
"input": "1 1 8 8",
"output": "2 1 7"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 1 1 8",
"output": "1 0 7"
},
{
"input": "8 1 1 1",
"output": "... | 1,635,588,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 46 | 4,710,400 | from collections import deque
inp = tuple(int(x) for x in input().split())
king = inp[:2]
dest = inp[2:]
n = 8
def queenCheck(king,queen):
if king[0] == queen[0] or king[1] == queen[1] or abs(king[1]-queen[1]) == abs(king[0]-queen[0]):
return True
return False
def bfsRook(king,... | Title: Rook, Bishop and King
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=... | ```python
from collections import deque
inp = tuple(int(x) for x in input().split())
king = inp[:2]
dest = inp[2:]
n = 8
def queenCheck(king,queen):
if king[0] == queen[0] or king[1] == queen[1] or abs(king[1]-queen[1]) == abs(king[0]-queen[0]):
return True
return False
def bfs... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
638 | A | Home Numbers | PROGRAMMING | 1,100 | [
"*special",
"constructive algorithms",
"math"
] | null | null | The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the pictur... | The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. | Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*. | [
"4 2\n",
"8 5\n"
] | [
"2\n",
"3\n"
] | In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left. | 500 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "100000 100000",... | 1,458,543,391 | 68,191 | Python 3 | OK | TESTS | 69 | 62 | 4,812,800 | inp = input().split()
n = int(inp[0])
a = int(inp[1])
if a % 2 != 0:
print((a // 2) + 1)
else:
print((n - a) // 2 + 1)
| Title: Home Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are nu... | ```python
inp = input().split()
n = int(inp[0])
a = int(inp[1])
if a % 2 != 0:
print((a // 2) + 1)
else:
print((n - a) // 2 + 1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbe... | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000... | 1,632,339,252 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 140 | 7,884,800 | # / *
#
# / \ | | / \ | | | |
# / __\ | | / __\ |--| | |
# / \ |__ | __ / \ | | \__ /
#
# __ __
# / \ | / | ) / \ | )
# / __\ |< |-< / __\ |-<
# / \ | \ |__) / \ | \
#
# * /
def main():
k, st = int(input()), ... | Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th... | ```python
# / *
#
# / \ | | / \ | | | |
# / __\ | | / __\ |--| | |
# / \ |__ | __ / \ | | \__ /
#
# __ __
# / \ | / | ) / \ | )
# / __\ |< |-< / __\ |-<
# / \ | \ |__) / \ | \
#
# * /
def main():
k, st = int(... | 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,597,214,750 | 50 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 7,168,000 | n, m = [int(a) for a in input().strip().split(' ')]
s = input()
dic = 'abcdefghijklmnopqrstuvwxyz'
res = 0
cnt = 0
for c in dic:
i, j = 0, 0
while j<n:
if s[j]==c:
res = max(res, j-i+1)
j += 1
else:
if cnt<m:
cnt += 1
res = max(... | 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
n, m = [int(a) for a in input().strip().split(' ')]
s = input()
dic = 'abcdefghijklmnopqrstuvwxyz'
res = 0
cnt = 0
for c in dic:
i, j = 0, 0
while j<n:
if s[j]==c:
res = max(res, j-i+1)
j += 1
else:
if cnt<m:
cnt += 1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,593,613,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 109 | 614,400 | n=int(input())
l=list(map(int,input().split()))
k=-l[0]
t=0
for i in range(1,n):
if k<=0:
t+=k
k=0
k+=(l[i-1]-l[i])
print(abs(t)) | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
n=int(input())
l=list(map(int,input().split()))
k=-l[0]
t=0
for i in range(1,n):
if k<=0:
t+=k
k=0
k+=(l[i-1]-l[i])
print(abs(t))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,689,873,775 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 61 | 0 | n, l = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
a.append(l)
a = sorted(a)
d = []
for i in range(n + 1):
d.append(a[i + 1] - a[i])
print(max(max(d) / 2, a[1] - a[0], a[-1] - a[-2])) | Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
n, l = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
a.append(l)
a = sorted(a)
d = []
for i in range(n + 1):
d.append(a[i + 1] - a[i])
print(max(max(d) / 2, a[1] - a[0], a[-1] - a[-2]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple soluti... | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"i... | 1,689,743,668 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 184 | 2,150,400 | n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
s, b = [0]*(n+1), [0]*(n+1)
l, r = [0]*(n+1), [0]*(n+1)
a = [0] + a
for i in range(1, n+1):
s[i] = s[i-1] + a[i]
for i in range(k, n+1):
b[i] = s[i] - s[i-k]
l[i] = l[i-1] if b[l[i-1]] > b[i] else i
b = ... | Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on... | ```python
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
s, b = [0]*(n+1), [0]*(n+1)
l, r = [0]*(n+1), [0]*(n+1)
a = [0] + a
for i in range(1, n+1):
s[i] = s[i-1] + a[i]
for i in range(k, n+1):
b[i] = s[i] - s[i-k]
l[i] = l[i-1] if b[l[i-1]] > b[i] else... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,643,013,703 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 156 | 204,800 | z=int(input())
if z%7==0:
print('7'*(z//7))
else:
ans=-1
for k in range(0,z//7+1):
if (z-k*7)%4==0:
ans=k
if ans==-1:
print(-1)
else:
print('4'*((z-ans*7)//4),end="")
print('7'*ans)
| Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
z=int(input())
if z%7==0:
print('7'*(z//7))
else:
ans=-1
for k in range(0,z//7+1):
if (z-k*7)%4==0:
ans=k
if ans==-1:
print(-1)
else:
print('4'*((z-ans*7)//4),end="")
print('7'*ans)
``` | 3.960619 | MatrixStudio/Codeforces-Python-Submissions |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,693,939,582 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | # Input the number of friends and the fence height
n, h = map(int, input().split())
# Input the heights of friends as a list
heights = list(map(int, input().split()))
# Initialize the minimum width of the road
width = 0
# Iterate through the heights and calculate the width
for height in heights:
if he... | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
# Input the number of friends and the fence height
n, h = map(int, input().split())
# Input the heights of friends as a list
heights = list(map(int, input().split()))
# Initialize the minimum width of the road
width = 0
# Iterate through the heights and calculate the width
for height in heights:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,494,547,982 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 25,395,200 | x=input()
x=x.split()
a=[]
b=[]
numero=0
for k in range (1,int(x[0])+1):
a.append(k)
for h in range (1,int(x[1])+1):
b.append(h)
for yonax in range (len(a)):
for carol in range (len(b)):
if (int(a[yonax])+int(b[carol]))%5==0:
numero=numero+1
p... | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
x=input()
x=x.split()
a=[]
b=[]
numero=0
for k in range (1,int(x[0])+1):
a.append(k)
for h in range (1,int(x[1])+1):
b.append(h)
for yonax in range (len(a)):
for carol in range (len(b)):
if (int(a[yonax])+int(b[carol]))%5==0:
numero=n... | 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,542,003,263 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 218 | 0 | n = int(input())
print(*range(1, n+1))
| 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())
print(*range(1, n+1))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Дано целое неотрицательное число *k* и *n* неотрицательных целых чисел *a*1,<=*a*2,<=...,<=*a**n*. Записывая некоторые из этих чисел друг за другом в произвольном порядке и, возможно, используя какие-то из них несколько раз (а какие-то вообще не используя), требуется составить кратчайшее (наименьшее по количеству цифр)... | В первой строке содержится два целых числа *n* (1<=≤<=*n*<=≤<=1<=000<=000) и *k* (1<=≤<=*k*<=≤<=1000) — количество чисел и требуемый делитель соответственно.
Во второй строке содержится *n* целых чисел *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Если ответ существует, в первой строке выведите «YES» (без кавычек), а во второй строке — искомое кратчайшее число без ведущих нулей. В случае если ответа не существует, в единственной строке выходных данных выведите «NO» (без кавычек). | [
"2 3\n123 1\n",
"1 10\n1\n",
"3 4\n1 2 3\n",
"3 777\n12 23 345\n"
] | [
"YES\n123",
"NO\n",
"YES\n12",
"YES\n121212"
] | none | 0 | [] | 1,458,748,149 | 2,949 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 4,608,000 | n = int(input())
k = int(input())
A = [0] * n
for i in range(n):
A[i] = int(input())
B = [0] * n
d = 0
for i in range(n):
if A[i] % k == 0:
B[d] = A[i]
d = d + 1
if d > 0:
print('YES')
else:
print('NO')
mina = 1000000
for i in range(n):
if B... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Дано целое неотрицательное число *k* и *n* неотрицательных целых чисел *a*1,<=*a*2,<=...,<=*a**n*. Записывая некоторые из этих чисел друг за другом в произвольном порядке и, возможно, используя какие-то из них несколько раз (а как... | ```python
n = int(input())
k = int(input())
A = [0] * n
for i in range(n):
A[i] = int(input())
B = [0] * n
d = 0
for i in range(n):
if A[i] % k == 0:
B[d] = A[i]
d = d + 1
if d > 0:
print('YES')
else:
print('NO')
mina = 1000000
for i in range(n):... | -1 | 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,084,964 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 |
w = int(input())
l = w//5
if(w%5==0):
step=l
else:
step=l+1
print(step) | 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
w = int(input())
l = w//5
if(w%5==0):
step=l
else:
step=l+1
print(step)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,639,814,032 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 186 | 0 | t=int(input())
a=[]
for i in range(t):
s=input()
a.append(s)
l=set(a)
print(len(l)) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
t=int(input())
a=[]
for i in range(t):
s=input()
a.append(s)
l=set(a)
print(len(l))
``` | 3.9535 | MatrixStudio/Codeforces-Python-Submissions |
870 | C | Maximum splitting | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"math",
"number theory"
] | null | null | You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prim... | The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries.
*q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | [
"1\n12\n",
"2\n6\n8\n",
"3\n1\n2\n3\n"
] | [
"3\n",
"1\n2\n",
"-1\n-1\n-1\n"
] | 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings. | 1,500 | [
{
"input": "1\n12",
"output": "3"
},
{
"input": "2\n6\n8",
"output": "1\n2"
},
{
"input": "3\n1\n2\n3",
"output": "-1\n-1\n-1"
},
{
"input": "6\n1\n2\n3\n5\n7\n11",
"output": "-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "3\n4\n6\n9",
"output": "1\n1\n1"
},
{
... | 1,658,636,568 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | import sys
input = sys.stdin.readline
q = int(input())
while(q):
n = int(input())
c = n // 4 if n % 2 == 0 else n // 4 - n % 4
if(c <= 0):
print(-1)
else:
print(c)
q -= 1 | Title: Maximum splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, o... | ```python
import sys
input = sys.stdin.readline
q = int(input())
while(q):
n = int(input())
c = n // 4 if n % 2 == 0 else n // 4 - n % 4
if(c <= 0):
print(-1)
else:
print(c)
q -= 1
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,682,671,484 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | #141A
s1=input() #abc
s2=input() #def
s3=input() #acdefc
S1=[i.lower() for i in s1]
S2=[i.lower() for i in s2]
S3=[i.lower() for i in s3]
S1.sort()
S2.sort()
S3.sort()
if len(S1)+len(S2)!=len(S3):
print("NO")
else:
for i in S1:
if i in S3:
S3.remove(i)
... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
#141A
s1=input() #abc
s2=input() #def
s3=input() #acdefc
S1=[i.lower() for i in s1]
S2=[i.lower() for i in s2]
S3=[i.lower() for i in s3]
S1.sort()
S2.sort()
S3.sort()
if len(S1)+len(S2)!=len(S3):
print("NO")
else:
for i in S1:
if i in S3:
S3.remove(i)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
673 | B | Problems for Round | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset ... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following *m* lines contains a pair of similar problems *u**i* and *v**i* (1<=≤<=*u**i*,<... | Print one integer — the number of ways to split problems in two divisions. | [
"5 2\n1 4\n5 2\n",
"3 3\n1 2\n2 3\n1 3\n",
"3 2\n3 1\n3 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sa... | 750 | [
{
"input": "5 2\n1 4\n5 2",
"output": "2"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "0"
},
{
"input": "3 2\n3 1\n3 2",
"output": "1"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 0",
"output": "2"
... | 1,464,804,009 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 61 | 5,120,000 | (total, similar) = (int(_) for _ in input().split())
first = set()
second = set()
for _ in range(similar):
(x, y) = (int(_) for _ in input().split())
first.add(max(x, y))
second.add(min(x, y))
if first & second:
print(0)
else:
print(max(min(first)-max(second), 0))
| Title: Problems for Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems... | ```python
(total, similar) = (int(_) for _ in input().split())
first = set()
second = set()
for _ in range(similar):
(x, y) = (int(_) for _ in input().split())
first.add(max(x, y))
second.add(min(x, y))
if first & second:
print(0)
else:
print(max(min(first)-max(second), 0))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.