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
103
B
Cthulhu
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
B. Cthulhu
2
256
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=). Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). Fo...
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
[ "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n", "6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n" ]
[ "FHTAGN!", "NO" ]
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1. A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* &gt; 0). A rooted tree is a tree where one ve...
1,000
[ { "input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4", "output": "FHTAGN!" }, { "input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2", "output": "NO" }, { "input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8", "output": "FHTAGN!" }, { "input": "5 4\n1 5\n1 3\n1 4\n3 2", "outpu...
1,521,464,046
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
7,065,600
import sys def getroot(lab, u): if lab[u] == -1: return u lab[u] = getroot(lab, lab[u]) return lab[u] def union(lab, cou, a, b): if cou[a] > cou[b]: cou[a] += cou[b] lab[b] = a else: cou[b] += cou[a] lab[a] = b def inp(): return map(int, input().split()...
Title: Cthulhu Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively colle...
```python import sys def getroot(lab, u): if lab[u] == -1: return u lab[u] = getroot(lab, lab[u]) return lab[u] def union(lab, cou, a, b): if cou[a] > cou[b]: cou[a] += cou[b] lab[b] = a else: cou[b] += cou[a] lab[a] = b def inp(): return map(int, input...
-1
MatrixStudio/Codeforces-Python-Submissions
876
A
Trip For Meal
PROGRAMMING
900
[ "math" ]
null
null
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ...
First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits. Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses. Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses. Fourth line contains an integer *c* ...
Output one number — minimum distance in meters Winnie must go through to have a meal *n* times.
[ "3\n2\n3\n1\n", "1\n2\n3\n5\n" ]
[ "3\n", "0\n" ]
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3. In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
500
[ { "input": "3\n2\n3\n1", "output": "3" }, { "input": "1\n2\n3\n5", "output": "0" }, { "input": "10\n1\n8\n3", "output": "9" }, { "input": "7\n10\n5\n6", "output": "30" }, { "input": "9\n9\n7\n5", "output": "42" }, { "input": "9\n37\n85\n76", "outpu...
1,594,442,988
2,147,483,647
PyPy 3
OK
TESTS
48
140
20,172,800
n = int(input()) a = int(input()) b = int(input()) c = int(input()) n -=1 indeed=0 if min(a,b,c)==a: shortestpath=a elif min(a,b,c)==b: shortestpath=b else: indeed=1 shortestpath = c intermediary = min(a,b) ans=0 while n>0: if indeed: indeed=0 ans+=intermediary ...
Title: Trip For Meal Time Limit: None seconds Memory Limit: None megabytes Problem Description: Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair...
```python n = int(input()) a = int(input()) b = int(input()) c = int(input()) n -=1 indeed=0 if min(a,b,c)==a: shortestpath=a elif min(a,b,c)==b: shortestpath=b else: indeed=1 shortestpath = c intermediary = min(a,b) ans=0 while n>0: if indeed: indeed=0 ans+=int...
3
MatrixStudio/Codeforces-Python-Submissions
375
D
Tree and Queries
PROGRAMMING
2,400
[ "data structures", "dfs and similar", "trees" ]
null
null
You have a rooted tree consisting of *n* vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to *n*. Then we represent the color of vertex *v* as *c**v*. The tree root is a vertex with number 1. In this problem you need to answer to *m* queries. Each ...
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105). The next line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105). The next *n*<=-<=1 lines contain the edges of the tree. The *i*-th line contains the numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤...
Print *m* integers — the answers to the queries in the order the queries appear in the input.
[ "8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3\n", "4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1 1\n" ]
[ "2\n2\n1\n0\n1\n", "4\n" ]
A subtree of vertex *v* in a rooted tree with root *r* is a set of vertices {*u* : *dist*(*r*, *v*) + *dist*(*v*, *u*) = *dist*(*r*, *u*)}. Where *dist*(*x*, *y*) is the length (in edges) of the shortest path between vertices *x* and *y*.
2,000
[ { "input": "8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3", "output": "2\n2\n1\n0\n1" }, { "input": "4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1 1", "output": "4" } ]
1,463,754,197
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
31,846,400
__author__ = 'Utena' from sys import * def input(): return stdin.readline() N = 100005 dfs_order_color=[0]*N dfs_st=[0]*N dfs_ed=[0]*N sz=[0]*N cnt=[0]*N sum=[0]*N youngest_child=[0]*N conn=[[]for i in range(2*N)] conn_child=[0]*(2*N) next_query=[0]*N dfs=0 def connect(x,y): conn[x].append(y) ...
Title: Tree and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a rooted tree consisting of *n* vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to *n*. Then we represent the color of vertex *v* as *c**...
```python __author__ = 'Utena' from sys import * def input(): return stdin.readline() N = 100005 dfs_order_color=[0]*N dfs_st=[0]*N dfs_ed=[0]*N sz=[0]*N cnt=[0]*N sum=[0]*N youngest_child=[0]*N conn=[[]for i in range(2*N)] conn_child=[0]*(2*N) next_query=[0]*N dfs=0 def connect(x,y): conn[x].a...
0
MatrixStudio/Codeforces-Python-Submissions
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,638,954,735
2,147,483,647
Python 3
OK
TESTS
42
124
0
row, col = map(int, input().split()) lst = [list(input()) for _ in range(row)] tranposeLst = [] for i in range(col): inner = [] for j in range(row): inner.append(0) tranposeLst.append(inner) for i in range(row): if "S" not in lst[i]: lst[i] = ["X"] * col for j i...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python row, col = map(int, input().split()) lst = [list(input()) for _ in range(row)] tranposeLst = [] for i in range(col): inner = [] for j in range(row): inner.append(0) tranposeLst.append(inner) for i in range(row): if "S" not in lst[i]: lst[i] = ["X"] * col ...
3
MatrixStudio/Codeforces-Python-Submissions
830
A
Office Keys
PROGRAMMING
1,800
[ "binary search", "brute force", "dp", "greedy", "sortings" ]
null
null
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine th...
The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are ...
Print the minimum time (in seconds) needed for all *n* to reach the office with keys.
[ "2 4 50\n20 100\n60 10 40 80\n", "1 2 10\n11\n15 7\n" ]
[ "50\n", "7\n" ]
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is...
500
[ { "input": "2 4 50\n20 100\n60 10 40 80", "output": "50" }, { "input": "1 2 10\n11\n15 7", "output": "7" }, { "input": "2 5 15\n10 4\n29 23 21 22 26", "output": "23" }, { "input": "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163", "output": "1394...
1,698,451,699
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
62
204,800
import sys import collections input = sys.stdin.buffer.readline def rl(): return list(map(int, input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int, input().split()) def debug(v): print(f"value is {v}") return dp = [[0,0] for _ in rang...
Title: Office Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office...
```python import sys import collections input = sys.stdin.buffer.readline def rl(): return list(map(int, input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int, input().split()) def debug(v): print(f"value is {v}") return dp = [[0,0] for...
0
MatrixStudio/Codeforces-Python-Submissions
391
A
Genetic Engineering
PROGRAMMING
0
[ "implementation", "two pointers" ]
null
null
You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'. ...
The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}. This problem doesn't have subproblems. You will get 3 points for the correct submission.
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
[ "GTTAAAG\n", "AACCAACCAAAAC\n" ]
[ "1\n", "5\n" ]
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.
3
[ { "input": "GTTAAAG", "output": "1" }, { "input": "AACCAACCAAAAC", "output": "5" }, { "input": "GTGAATTTCC", "output": "2" }, { "input": "CAGGGGGCCGCCCATGAAAAAAACCCGGCCCCTTGGGAAAACTTGGGTTA", "output": "7" }, { "input": "CCCTTCACCCGGATCCAAATCCCTTAGAAATAATCCCCGACGGC...
1,550,541,150
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
108
0
#input for the string for code code=input() curr=code[0] curr_count=1 add_count=0 for i in range(1,len(code)): if code[i]==curr: curr_count+=1 else: curr=code[i] #print("curr is now:"+str(curr)) #if even number if curr_count%2==0: add_count+=1 ...
Title: Genetic Engineering Time Limit: None seconds Memory Limit: None megabytes Problem Description: You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one prot...
```python #input for the string for code code=input() curr=code[0] curr_count=1 add_count=0 for i in range(1,len(code)): if code[i]==curr: curr_count+=1 else: curr=code[i] #print("curr is now:"+str(curr)) #if even number if curr_count%2==0: add_co...
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,678,840,917
2,147,483,647
Python 3
OK
TESTS
71
92
0
# Read the input string remixed_song = input() # Replace all occurrences of "WUB" with a space and strip leading/trailing spaces original_song = remixed_song.replace("WUB", " ").strip() # Replace multiple spaces with a single space original_song = " ".join(original_song.split()) # Print the original song p...
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 # Read the input string remixed_song = input() # Replace all occurrences of "WUB" with a space and strip leading/trailing spaces original_song = remixed_song.replace("WUB", " ").strip() # Replace multiple spaces with a single space original_song = " ".join(original_song.split()) # Print the origin...
3
MatrixStudio/Codeforces-Python-Submissions
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,597,429,337
2,147,483,647
Python 3
OK
TESTS
40
108
307,200
a = int(input()) b = int(input()) d = max(a-b,b-a) if d%2 == 0: y = int(d/2) else: y = int(d/2)+1 f1 = 0 for i in range(1,int(d/2)+1): f1 += i f2 = 0 for i in range(1,y+1): f2 += i if d == 1: print(1) else: print(f1+f2)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python a = int(input()) b = int(input()) d = max(a-b,b-a) if d%2 == 0: y = int(d/2) else: y = int(d/2)+1 f1 = 0 for i in range(1,int(d/2)+1): f1 += i f2 = 0 for i in range(1,y+1): f2 += i if d == 1: print(1) else: print(f1+f2) ```
3
MatrixStudio/Codeforces-Python-Submissions
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,694,539,184
2,147,483,647
Python 3
OK
TESTS
15
46
0
k_n_w = input().split() k_n_w = list(map(int, k_n_w)) money = sum(k_n_w[0]*i for i in range(1, k_n_w[2]+1)) if money >= k_n_w[1]: print(money - k_n_w[1]) else: print(0)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He h...
```python k_n_w = input().split() k_n_w = list(map(int, k_n_w)) money = sum(k_n_w[0]*i for i in range(1, k_n_w[2]+1)) if money >= k_n_w[1]: print(money - k_n_w[1]) else: print(0) ```
3
MatrixStudio/Codeforces-Python-Submissions
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, al...
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": ...
1,695,503,610
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
19
46
0
n = int(input()) # x = 1378**n # print(x % 10) if n % 4 == 0 and n % 3 != 0 : print(6) elif n == 0 : print(1) elif n % 2 == 0 : print(4) elif n % 3 == 0 or n % 7 == 0 : print(2) else : print(8)
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques...
```python n = int(input()) # x = 1378**n # print(x % 10) if n % 4 == 0 and n % 3 != 0 : print(6) elif n == 0 : print(1) elif n % 2 == 0 : print(4) elif n % 3 == 0 or n % 7 == 0 : print(2) else : print(8) ```
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,621,245,193
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
inp1 = int(input()) inp2 = int(input()) a='' for i in range(len(inp1)): if inp1[i] == inp2[i]: a+='0' else: a+='1' print(a)
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 inp1 = int(input()) inp2 = int(input()) a='' for i in range(len(inp1)): if inp1[i] == inp2[i]: a+='0' else: a+='1' print(a) ```
-1
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,305,728
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
60
0
x = int(input()) if 100>= x >= 1: if x%4 == 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 x = int(input()) if 100>= x >= 1: if x%4 == 0: print('YES') else: print('NO') ```
0
MatrixStudio/Codeforces-Python-Submissions
863
B
Kayaking
PROGRAMMING
1,500
[ "brute force", "greedy", "sortings" ]
null
null
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact...
The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Print minimum possible total instability.
[ "2\n1 2 3 4\n", "4\n1 3 4 6 3 4 100 200\n" ]
[ "1\n", "5\n" ]
none
0
[ { "input": "2\n1 2 3 4", "output": "1" }, { "input": "4\n1 3 4 6 3 4 100 200", "output": "5" }, { "input": "3\n305 139 205 406 530 206", "output": "102" }, { "input": "3\n610 750 778 6 361 407", "output": "74" }, { "input": "5\n97 166 126 164 154 98 221 7 51 47", ...
1,511,588,428
5,428
Python 3
WRONG_ANSWER
TESTS
1
46
5,529,600
n=int(input()) w=list(map(int,input().split())) w.sort() ans=[] v=[] s=0 for i in range(len(w)): for j in range(i+1,len(w)): v=w[:i]+w[i+1:j]+w[j+1:] for c in range(0,len(v),2): s+=v[c] for g in range(1,len(v),2) : s=s-v[g] ans.append(abs(s)) pri...
Title: Kayaking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they hav...
```python n=int(input()) w=list(map(int,input().split())) w.sort() ans=[] v=[] s=0 for i in range(len(w)): for j in range(i+1,len(w)): v=w[:i]+w[i+1:j]+w[j+1:] for c in range(0,len(v),2): s+=v[c] for g in range(1,len(v),2) : s=s-v[g] ans.append(ab...
0
MatrixStudio/Codeforces-Python-Submissions
868
A
Bark to Unlock
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p...
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to b...
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" produ...
250
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { ...
1,518,225,948
2,147,483,647
Python 3
OK
TESTS
90
62
5,632,000
password = input() n = int(input()) know = [] for _ in range(n): know.append(input()) def hi(): for x in know: for y in know: if password in x + y: return "YES" return "NO" print(hi()) exit(0)
Title: Bark to Unlock Time Limit: None seconds Memory Limit: None megabytes Problem Description: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passw...
```python password = input() n = int(input()) know = [] for _ in range(n): know.append(input()) def hi(): for x in know: for y in know: if password in x + y: return "YES" return "NO" print(hi()) exit(0) ```
3
MatrixStudio/Codeforces-Python-Submissions
1,009
D
Relatively Prime Graph
PROGRAMMING
1,700
[ "brute force", "constructive algorithms", "graphs", "greedy", "math" ]
null
null
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
The only line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of vertices and the number of edges.
If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $i$-th of the next $m$ lines should contain the $i$-th edge $(v_i, u_i)$ of the resulting graph ($1 \le v_i, ...
[ "5 6\n", "6 12\n" ]
[ "Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4\n", "Impossible\n" ]
Here is the representation of the graph from the first example: <img class="tex-graphics" src="https://espresso.codeforces.com/7a1353a992545456c007e3071fa0a06fe46fc64e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
0
[ { "input": "5 6", "output": "Possible\n2 1\n3 1\n4 1\n5 1\n3 2\n5 2" }, { "input": "6 12", "output": "Impossible" }, { "input": "572 99643", "output": "Possible\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1...
1,689,444,188
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
print("_RANDOM_GUESS_1689444188.7605479")# 1689444188.7605689
Title: Relatively Prime Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair...
```python print("_RANDOM_GUESS_1689444188.7605479")# 1689444188.7605689 ```
0
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,693,559,047
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
s = list(input()) consecutive_l = False for i in range(len(s) - 1): if s[i] == 'l' and s[i + 1] == 'l': consecutive_l = True unique_s = "" for char in s: if char not in unique_s: unique_s += char if 'helo' in unique_s and consecutive_l: 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 s = list(input()) consecutive_l = False for i in range(len(s) - 1): if s[i] == 'l' and s[i + 1] == 'l': consecutive_l = True unique_s = "" for char in s: if char not in unique_s: unique_s += char if 'helo' in unique_s and consecutive_l: print("YES") else: ...
0
MatrixStudio/Codeforces-Python-Submissions
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20...
1,651,971,128
2,147,483,647
PyPy 3-64
OK
TESTS
61
154
614,400
import sys from collections import Counter input = sys.stdin.readline L = int(input()) A = list(map(int, input().split())) C = Counter(A).most_common() print(C[0][1], len(C))
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct...
```python import sys from collections import Counter input = sys.stdin.readline L = int(input()) A = list(map(int, input().split())) C = Counter(A).most_common() print(C[0][1], len(C)) ```
3.960356
MatrixStudio/Codeforces-Python-Submissions
180
C
Letter
PROGRAMMING
1,400
[ "dp" ]
null
null
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to...
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
[ "PRuvetSTAaYA\n", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "helloworld\n" ]
[ "5\n", "0\n", "0\n" ]
none
0
[ { "input": "PRuvetSTAaYA", "output": "5" }, { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0" }, { "input": "helloworld", "output": "0" }, { "input": "P", "output": "0" }, { "input": "t", "output": "0" }, { "input": "XdJ", "output": "1...
1,679,073,363
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
92
0
s = input( ) l = 0 r = len( s ) s1 = 0 s2 = 0 for i in range( len( s ) - 1 , 0 , -1 ) : if s[i] >= 'A' and s[i] <= 'A' : l = i break for i in range( l ) : if s[i] >= 'a' and s[i] <= 'z' : s1 += 1 for i in range( len( s ) ) : if s[i] >= 'a' and s[i] <= 'z' : ...
Title: Letter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them...
```python s = input( ) l = 0 r = len( s ) s1 = 0 s2 = 0 for i in range( len( s ) - 1 , 0 , -1 ) : if s[i] >= 'A' and s[i] <= 'A' : l = i break for i in range( l ) : if s[i] >= 'a' and s[i] <= 'z' : s1 += 1 for i in range( len( s ) ) : if s[i] >= 'a' and s[i] <= 'z'...
0
MatrixStudio/Codeforces-Python-Submissions
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20...
1,589,997,325
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
15
280
0
N = int(input()) L = [int(i) for i in input().split()] h = [L.count(L[i]) for i in range(len(L))] cubes = 0 towers = 0 for i in L: if L.count(i) > 1: cubes += L.count(i) towers += 1 while i in L: L.remove(i) print(max(h), N - cubes + towers)
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct...
```python N = int(input()) L = [int(i) for i in input().split()] h = [L.count(L[i]) for i in range(len(L))] cubes = 0 towers = 0 for i in L: if L.count(i) > 1: cubes += L.count(i) towers += 1 while i in L: L.remove(i) print(max(h), N - cubes + towers) ```
0
MatrixStudio/Codeforces-Python-Submissions
411
A
Password Check
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
[ "abacaba\n", "X12345\n", "CONTEST_is_STARTED!!11\n" ]
[ "Too weak\n", "Too weak\n", "Correct\n" ]
none
0
[ { "input": "abacaba", "output": "Too weak" }, { "input": "X12345", "output": "Too weak" }, { "input": "CONTEST_is_STARTED!!11", "output": "Correct" }, { "input": "1zA__", "output": "Correct" }, { "input": "1zA_", "output": "Too weak" }, { "input": "zA_...
1,664,000,005
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
c,k,l=0,0,0 p=input('') if len(p)>=5: for i in range(len(p)): if ord(p[i])>=65 and ord(p[i])<=90: c+=1 if ord(p[i])>=97 and ord(p[i])<=122: k+=1 if p[i].isdigit(): l+=1 if c>0 and k>0 and l>0: print('Correct') else: pri...
Title: Password Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password...
```python c,k,l=0,0,0 p=input('') if len(p)>=5: for i in range(len(p)): if ord(p[i])>=65 and ord(p[i])<=90: c+=1 if ord(p[i])>=97 and ord(p[i])<=122: k+=1 if p[i].isdigit(): l+=1 if c>0 and k>0 and l>0: print('Correct') else: ...
0
MatrixStudio/Codeforces-Python-Submissions
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ...
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain ...
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg...
1,579,987,306
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define f(i,a,n) for(int i=a;i<n;i++) #define ve vector #define ss second #define ff first #define pf pop_front #define pob pop_back #define psf push_front #define res(x) cout<<x<<'\n' #define read(...
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from...
```python #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define f(i,a,n) for(int i=a;i<n;i++) #define ve vector #define ss second #define ff first #define pf pop_front #define pob pop_back #define psf push_front #define res(x) cout<<x<<'\n' #de...
-1
MatrixStudio/Codeforces-Python-Submissions
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the...
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "ou...
1,646,887,932
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
def solve(): a = [[True if i=="#" else False for i in input()] for i in range(4)] for j in range(4): for i in range(4): try: t = [a[j][i], a[j][i-1], a[j-1][i], a[j-1][i-1]] if t.count(True) >= 3: print("YES") ...
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o...
```python def solve(): a = [[True if i=="#" else False for i in input()] for i in range(4)] for j in range(4): for i in range(4): try: t = [a[j][i], a[j][i-1], a[j-1][i], a[j-1][i-1]] if t.count(True) >= 3: print("YES") ...
0
MatrixStudio/Codeforces-Python-Submissions
344
B
Simple Molecules
PROGRAMMING
1,200
[ "brute force", "graphs", "math" ]
null
null
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one...
The single line of the input contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=106) — the valence numbers of the given atoms.
If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
[ "1 1 2\n", "3 4 5\n", "4 1 1\n" ]
[ "0 1 1\n", "1 3 2\n", "Impossible\n" ]
The first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case. The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms. The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds ...
1,000
[ { "input": "1 1 2", "output": "0 1 1" }, { "input": "3 4 5", "output": "1 3 2" }, { "input": "4 1 1", "output": "Impossible" }, { "input": "1 1 1", "output": "Impossible" }, { "input": "1000000 1000000 1000000", "output": "500000 500000 500000" }, { "i...
1,699,633,077
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def solve(a,b,c): x2 = int((a-b+c)/2) x3 = int(c-x2) x1 = int(a-x2) if min(x1,x2,x3)<0: return 'Impossible' if x1+x2!=a or x1+x3!=b or x2+x3!=c: print(x1,x2,x3) return 'Impossible' return str(int(x1)) + " " + str(x3) + " " + str(x2) arr = [int(a) for a in input(...
Title: Simple Molecules Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each ato...
```python def solve(a,b,c): x2 = int((a-b+c)/2) x3 = int(c-x2) x1 = int(a-x2) if min(x1,x2,x3)<0: return 'Impossible' if x1+x2!=a or x1+x3!=b or x2+x3!=c: print(x1,x2,x3) return 'Impossible' return str(int(x1)) + " " + str(x3) + " " + str(x2) arr = [int(a) for a...
0
MatrixStudio/Codeforces-Python-Submissions
771
A
Bear and Friendship Condition
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that...
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ...
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
250
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { ...
1,632,047,072
2,147,483,647
Python 3
OK
TESTS
96
639
53,145,600
n,m = map(int,input().split()) v = [0]*150005 s = [set([i]) for i in range(150005)] for _ in ' '*m: a,b = map(int,input().split()) s[a].add(b) s[b].add(a) for i in range(n): if not v[i]: for j in s[i]: v[j]=1 if s[j]!=s[i]: print('NO'); exit(0) print('YES')
Title: Bear and Friendship Condition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through...
```python n,m = map(int,input().split()) v = [0]*150005 s = [set([i]) for i in range(150005)] for _ in ' '*m: a,b = map(int,input().split()) s[a].add(b) s[b].add(a) for i in range(n): if not v[i]: for j in s[i]: v[j]=1 if s[j]!=s[i]: print('NO'); exit(0) print...
3
MatrixStudio/Codeforces-Python-Submissions
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }...
1,605,893,380
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
15
202
7,372,800
n=int(input()) arr=[int(x) for x in input().split()] count=0 ind=-1 for i in range(n): if(i==0): continue elif(i==n-1): if(arr[i]<arr[i-1]): ind=i count+=1 else: if(arr[i]<arr[i-1] and arr[i]<arr[i+1]): count+=1 ind=i if(...
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ...
```python n=int(input()) arr=[int(x) for x in input().split()] count=0 ind=-1 for i in range(n): if(i==0): continue elif(i==n-1): if(arr[i]<arr[i-1]): ind=i count+=1 else: if(arr[i]<arr[i-1] and arr[i]<arr[i+1]): count+=1 ...
0
MatrixStudio/Codeforces-Python-Submissions
538
A
Cutting Banner
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ...
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
[ "CODEWAITFORITFORCES\n", "BOTTOMCODER\n", "DECODEFORCES\n", "DOGEFORCES\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "CODEWAITFORITFORCES", "output": "YES" }, { "input": "BOTTOMCODER", "output": "NO" }, { "input": "DECODEFORCES", "output": "YES" }, { "input": "DOGEFORCES", "output": "NO" }, { "input": "ABACABA", "output": "NO" }, { "input": "CODEFORCE", ...
1,432,881,523
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
23
62
0
a, s, ok = "CODEFORCES", input(), False for i in range(len(a)): if s.startswith(a[:i]) and s.endswith(a[i:]): ok = True break print("YES" if ok else "NO")
Title: Cutting Banner Time Limit: None seconds Memory Limit: None megabytes Problem Description: A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ...
```python a, s, ok = "CODEFORCES", input(), False for i in range(len(a)): if s.startswith(a[:i]) and s.endswith(a[i:]): ok = True break print("YES" if ok else "NO") ```
0
MatrixStudio/Codeforces-Python-Submissions
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130...
1,680,169,926
2,147,483,647
Python 3
OK
TESTS
21
46
0
t = int(input()) for _ in range(t): n = int(input()) total_sum = n * (n + 1) // 2 power_of_two = 1 while power_of_two <= n: total_sum -= 2 * power_of_two power_of_two *= 2 print(total_sum)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be...
```python t = int(input()) for _ in range(t): n = int(input()) total_sum = n * (n + 1) // 2 power_of_two = 1 while power_of_two <= n: total_sum -= 2 * power_of_two power_of_two *= 2 print(total_sum) ```
3
MatrixStudio/Codeforces-Python-Submissions
892
A
Greed
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans. The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<...
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).
[ "2\n3 5\n3 6\n", "3\n6 8 9\n6 10 12\n", "5\n0 0 5 0 0\n1 1 8 10 5\n", "4\n4 1 0 3\n5 2 2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample, there are already 2 cans, so the answer is "YES".
500
[ { "input": "2\n3 5\n3 6", "output": "YES" }, { "input": "3\n6 8 9\n6 10 12", "output": "NO" }, { "input": "5\n0 0 5 0 0\n1 1 8 10 5", "output": "YES" }, { "input": "4\n4 1 0 3\n5 2 2 3", "output": "YES" }, { "input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9...
1,619,162,443
2,147,483,647
PyPy 3
OK
TESTS
39
280
13,516,800
n = int(input()) sisa = sum(list(map(int, input().split()))) kapa = list(map(int, input().split())) kapa.sort(reverse=True) if kapa[0] + kapa[1] >= sisa: print('YES') else: print('NO')
Title: Greed Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he c...
```python n = int(input()) sisa = sum(list(map(int, input().split()))) kapa = list(map(int, input().split())) kapa.sort(reverse=True) if kapa[0] + kapa[1] >= sisa: print('YES') else: print('NO') ```
3
MatrixStudio/Codeforces-Python-Submissions
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ...
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain ...
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg...
1,664,033,844
2,147,483,647
Python 3
OK
TESTS
46
155
716,800
n = int(input()) s = str(input()) cont = 0 dic = {} for i in range(0, ((n*2)-2), 1): if i%2 == 0: if s[i] in dic: dic[(s[i])] += 1 else: dic[(s[i])] = 1 else: q = s[i].lower() if q in dic: if dic[q] >= 1: dic[q] -= 1 else: cont += 1 else: cont +=1...
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from...
```python n = int(input()) s = str(input()) cont = 0 dic = {} for i in range(0, ((n*2)-2), 1): if i%2 == 0: if s[i] in dic: dic[(s[i])] += 1 else: dic[(s[i])] = 1 else: q = s[i].lower() if q in dic: if dic[q] >= 1: dic[q] -= 1 else: cont += 1 else: ...
3
MatrixStudio/Codeforces-Python-Submissions
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,627,458,480
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
122
6,963,200
l = [] n = int(input()) f = 1 d = 0 b = 0 for i in range(n): a, b = map(str, input().split()) a = a + b l.append(a) for i in range(len(l)-1): if l[i] == l[i + 1]: f += 1 print(f)
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python l = [] n = int(input()) f = 1 d = 0 b = 0 for i in range(n): a, b = map(str, input().split()) a = a + b l.append(a) for i in range(len(l)-1): if l[i] == l[i + 1]: f += 1 print(f) ```
0
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,612,648,150
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
307,200
#collaborated with Prasoon def func(temp1,temp2,temp3,temp4): counter=0 i_position=0 max_var=0 if temp1.count(temp4)<=temp3: return temp2 for i in range(temp2): if temp1[i]!=temp4: counter+=1 while (counter>temp3) and (i_position<temp2): if te...
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 #collaborated with Prasoon def func(temp1,temp2,temp3,temp4): counter=0 i_position=0 max_var=0 if temp1.count(temp4)<=temp3: return temp2 for i in range(temp2): if temp1[i]!=temp4: counter+=1 while (counter>temp3) and (i_position<temp2): ...
0
MatrixStudio/Codeforces-Python-Submissions
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input...
1,621,456,623
2,147,483,647
Python 3
OK
TESTS
33
514
24,576,000
import heapq INF = 10**13 def dijk(st, d, p, g): q = [(d[st], st)] while q: ln, v = heapq.heappop(q) if(ln > d[v]): continue for (to, w) in (g[v]): if d[to] > ln + w: d[to] = ln + w p[to] = v heapq.heappush(q, (d[to], to)) def main(): n, m = map(int, input().split()) g ...
Title: Dijkstra? Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. Input Specification: The first line contains two integers *n* a...
```python import heapq INF = 10**13 def dijk(st, d, p, g): q = [(d[st], st)] while q: ln, v = heapq.heappop(q) if(ln > d[v]): continue for (to, w) in (g[v]): if d[to] > ln + w: d[to] = ln + w p[to] = v heapq.heappush(q, (d[to], to)) def main(): n, m = map(int, input().spl...
3.559895
MatrixStudio/Codeforces-Python-Submissions
513
A
Game
PROGRAMMING
800
[ "constructive algorithms", "math" ]
null
null
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2...
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output "First" if the first player wins and "Second" otherwise.
[ "2 2 1 2\n", "2 1 1 1\n" ]
[ "Second\n", "First\n" ]
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
3
[ { "input": "2 2 1 2", "output": "Second" }, { "input": "2 1 1 1", "output": "First" }, { "input": "5 7 4 1", "output": "Second" }, { "input": "5 7 1 4", "output": "Second" }, { "input": "5 7 10 10", "output": "Second" }, { "input": "5 7 1 10", "out...
1,652,437,799
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
a,b=map(int,input().split()) if (a//b)%2==0 : print("First") else : print("Second") #yefqegfwef
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba...
```python a,b=map(int,input().split()) if (a//b)%2==0 : print("First") else : print("Second") #yefqegfwef ```
-1
MatrixStudio/Codeforces-Python-Submissions
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,627,178,087
2,147,483,647
Python 3
OK
TESTS
30
124
6,758,400
s = input() i = 0 while i<len(s): if s[i]=='.': print(0, end='') i += 1 elif s[i+1]=='.': print(1, end='') i += 2 else: print(2, end='') i += 2
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ...
```python s = input() i = 0 while i<len(s): if s[i]=='.': print(0, end='') i += 1 elif s[i+1]=='.': print(1, end='') i += 2 else: print(2, end='') i += 2 ```
3.956411
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,695,484,074
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
61
0
x = input() x_ = x[1:-1] if x_: print(len(x_.split(','))) else: print(0)
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 x = input() x_ = x[1:-1] if x_: print(len(x_.split(','))) else: print(0) ```
0
MatrixStudio/Codeforces-Python-Submissions
180
C
Letter
PROGRAMMING
1,400
[ "dp" ]
null
null
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to...
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
[ "PRuvetSTAaYA\n", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "helloworld\n" ]
[ "5\n", "0\n", "0\n" ]
none
0
[ { "input": "PRuvetSTAaYA", "output": "5" }, { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0" }, { "input": "helloworld", "output": "0" }, { "input": "P", "output": "0" }, { "input": "t", "output": "0" }, { "input": "XdJ", "output": "1...
1,553,857,719
2,147,483,647
PyPy 3
OK
TESTS
40
310
1,638,400
s = input() n = len(s) A, B = [0] * n, [0] * n for i in range(n): A[i] = A[i-1] + s[i].islower() B[-i-1] = B[-i] + s[-i-1].isupper() print(min(a + b for a, b in zip(A, B)) - 1)
Title: Letter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them...
```python s = input() n = len(s) A, B = [0] * n, [0] * n for i in range(n): A[i] = A[i-1] + s[i].islower() B[-i-1] = B[-i] + s[-i-1].isupper() print(min(a + b for a, b in zip(A, B)) - 1) ```
3
MatrixStudio/Codeforces-Python-Submissions
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,682,656,588
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
0
input() a = list(map(int, input().split())) b = list(map(int, input().split())) max_a = max(a) min_a = min(a) temp = [0] * (max_a + min_a) for i in a: temp[int(i) + min_a - 1] += 1 for i in range(1, len(temp)): temp[i] += temp[i - 1] ans = [0] * len(b) for i in range(len(b)): ans[i] = temp[b[i] ...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python input() a = list(map(int, input().split())) b = list(map(int, input().split())) max_a = max(a) min_a = min(a) temp = [0] * (max_a + min_a) for i in a: temp[int(i) + min_a - 1] += 1 for i in range(1, len(temp)): temp[i] += temp[i - 1] ans = [0] * len(b) for i in range(len(b)): ans[i] = ...
-1
MatrixStudio/Codeforces-Python-Submissions
792
B
Counting-out Rhyme
PROGRAMMING
1,300
[ "implementation" ]
null
null
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T...
The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1). The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109).
Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step.
[ "7 5\n10 4 11 4 1\n", "3 2\n2 5\n" ]
[ "4 2 5 6 1 \n", "3 2 \n" ]
Let's consider first example: - In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader...
0
[ { "input": "7 5\n10 4 11 4 1", "output": "4 2 5 6 1 " }, { "input": "3 2\n2 5", "output": "3 2 " }, { "input": "2 1\n1", "output": "2 " }, { "input": "2 1\n2", "output": "1 " }, { "input": "2 1\n3", "output": "2 " }, { "input": "10 7\n5 10 4 3 8 10 6",...
1,490,627,307
2,007
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
5,222,400
from collections import deque N, K = map(int, input().split()) A = list(map(int, input().split())) q = deque(range(1, N+1)) ret = [] for k in range(K): for a in range(A[k]): q.append(q.popleft()) ret.append(q.popleft()) print(' '.join([str(r)for r in ret]))
Title: Counting-out Rhyme Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ...
```python from collections import deque N, K = map(int, input().split()) A = list(map(int, input().split())) q = deque(range(1, N+1)) ret = [] for k in range(K): for a in range(A[k]): q.append(q.popleft()) ret.append(q.popleft()) print(' '.join([str(r)for r in ret])) ```
0
MatrixStudio/Codeforces-Python-Submissions
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e...
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels ...
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", ...
1,677,133,172
2,147,483,647
PyPy 3-64
OK
TESTS
54
62
0
k,r=(map(int, input().split())) g=k i=1 while (k%10!=0 and (k-r)%10!=0): i+=1 k=g*i print(i)
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his ...
```python k,r=(map(int, input().split())) g=k i=1 while (k%10!=0 and (k-r)%10!=0): i+=1 k=g*i print(i) ```
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,620,731,255
2,147,483,647
Python 3
OK
TESTS
34
77
6,758,400
n=int(input()) s=str(input()) s=s[::-1] s1=s[1::2] s2=s[::2] s2=s2[::-1] print(s1+s2)
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=int(input()) s=str(input()) s=s[::-1] s1=s[1::2] s2=s[::2] s2=s2[::-1] print(s1+s2) ```
3
MatrixStudio/Codeforces-Python-Submissions
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is...
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not ...
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20...
1,689,422,168
2,147,483,647
Python 3
OK
TESTS
32
46
0
n = int(input()) columns = list(map(int, input().split())) ans = '' while n: for c in range(len(columns) - 1): if columns[c] > columns[c+1]: qu = columns[c] - columns[c+1] columns[c] -= qu columns [c+1] += qu n -= 1 for c in columns:print(c, end =' ')
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the bo...
```python n = int(input()) columns = list(map(int, input().split())) ans = '' while n: for c in range(len(columns) - 1): if columns[c] > columns[c+1]: qu = columns[c] - columns[c+1] columns[c] -= qu columns [c+1] += qu n -= 1 for c in columns:print(c, end ='...
3
MatrixStudio/Codeforces-Python-Submissions
892
B
Wrath
PROGRAMMING
1,200
[ "greedy", "implementation", "two pointers" ]
null
null
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people. Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
Print one integer — the total number of alive people after the bell rings.
[ "4\n0 1 0 10\n", "2\n0 0\n", "10\n1 1 3 0 0 0 2 1 0 3\n" ]
[ "1\n", "2\n", "3\n" ]
In first sample the last person kills everyone in front of him.
1,000
[ { "input": "4\n0 1 0 10", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3" }, { "input": "10\n0 0 2 0 0 3 3 2 2 0", "output": "2" }, { "input": "1\n0", "output": "1" }, { "input": "5\n0 0 0 1 0"...
1,537,684,024
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
124
0
n=int(input()) lst=[int(x) for x in input().split()] x=0 mst=[] while x!=n-2: y=x+1 while y!=n-1 and lst[x]<lst[y]: y+=1 mst+=[lst[y-1]] x=y print(len(mst))
Title: Wrath Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ...
```python n=int(input()) lst=[int(x) for x in input().split()] x=0 mst=[] while x!=n-2: y=x+1 while y!=n-1 and lst[x]<lst[y]: y+=1 mst+=[lst[y-1]] x=y print(len(mst)) ```
0
MatrixStudio/Codeforces-Python-Submissions
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,686,675,245
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
7,168,000
# m, s = list(map(int, input().split())) # min_n = -1 # max_n = -1 # for i in range(1, int("9" * m) + 1): # if len(str(i)) == m: # x = sum(list(map(int, list(str(i))))) # if x == s and min_n == -1: # min_n = i # elif x == s: # max_n = i # print(min_n, max_n)...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python # m, s = list(map(int, input().split())) # min_n = -1 # max_n = -1 # for i in range(1, int("9" * m) + 1): # if len(str(i)) == m: # x = sum(list(map(int, list(str(i))))) # if x == s and min_n == -1: # min_n = i # elif x == s: # max_n = i # print(min...
0
MatrixStudio/Codeforces-Python-Submissions
421
A
Pasha and Hamsters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams...
The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line...
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
[ "4 2 3\n1 2\n2 3 4\n", "5 5 2\n3 4 1 2 5\n2 3\n" ]
[ "1 1 2 2\n", "1 1 1 1 1\n" ]
none
500
[ { "input": "4 2 3\n1 2\n2 3 4", "output": "1 1 2 2" }, { "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1" }, { "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7...
1,398,169,464
563
Python 3
OK
TESTS
32
62
0
n, a, b = tuple(map(int, str.split(input()))) a_s = set(map(int, str.split(input()))) b_s = set(map(int, str.split(input()))) def yoba(n, a_s, b_s): for i in range(1, n + 1): yield 1 if i in a_s else 2 print(str.join(" ", map(str, yoba(n, a_s, b_s))))
Title: Pasha and Hamsters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between...
```python n, a, b = tuple(map(int, str.split(input()))) a_s = set(map(int, str.split(input()))) b_s = set(map(int, str.split(input()))) def yoba(n, a_s, b_s): for i in range(1, n + 1): yield 1 if i in a_s else 2 print(str.join(" ", map(str, yoba(n, a_s, b_s)))) ```
3
MatrixStudio/Codeforces-Python-Submissions
754
E
Dasha and cyclic table
PROGRAMMING
2,600
[ "bitmasks", "brute force", "fft", "strings", "trees" ]
null
null
Dasha is fond of challenging puzzles: Rubik's Cube 3<=×<=3<=×<=3, 4<=×<=4<=×<=4, 5<=×<=5<=×<=5 and so on. This time she has a cyclic table of size *n*<=×<=*m*, and each cell of the table contains a lowercase English letter. Each cell has coordinates (*i*,<=*j*) (0<=≤<=*i*<=&lt;<=*n*, 0<=≤<=*j*<=&lt;<=*m*). The table is...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=400) — the cyclic table sizes. Each of the next *n* lines contains a string of *m* lowercase English characters — the description of the cyclic table. The next line contains two integers *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=400) — the sizes of the patt...
Print *n* lines. Each of the *n* lines should contain *m* characters. Each of the characters should equal '0' or '1'. The *j*-th character of the *i*-th (0-indexed) line should be equal to '1', in case the cell (*i*,<=*j*) is an appearance position, otherwise it should be equal to '0'.
[ "5 7\nqcezchs\nhhedywq\nwikywqy\nqckrqzt\nbqexcxz\n3 2\n??\nyw\n?q\n", "10 10\nfwtoayylhw\nyyaryyjawr\nywrdzwhscy\nhnsyyxiphn\nbnjwzyyjvo\nkkjgseenwn\ngvmiflpcsy\nlxvkwrobwu\nwyybbcocyy\nyysijsvqry\n2 2\n??\nyy\n", "8 6\nibrgxl\nxqdcsg\nokbcgi\ntvpetc\nxgxxig\nigghzo\nlmlaza\ngpswzv\n1 4\ngx??\n" ]
[ "0000100\n0001001\n0000000\n0000000\n0000000\n", "1000100000\n0000000001\n0001000000\n0000010000\n0000000000\n0000000000\n0000000000\n0100000010\n1000000001\n0000010000\n", "000100\n000001\n000000\n000000\n010001\n000000\n000000\n000000\n" ]
none
2,500
[]
1,689,414,990
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689414990.539216")# 1689414990.5392358
Title: Dasha and cyclic table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dasha is fond of challenging puzzles: Rubik's Cube 3<=×<=3<=×<=3, 4<=×<=4<=×<=4, 5<=×<=5<=×<=5 and so on. This time she has a cyclic table of size *n*<=×<=*m*, and each cell of the table contains a lowercase Engl...
```python print("_RANDOM_GUESS_1689414990.539216")# 1689414990.5392358 ```
0
MatrixStudio/Codeforces-Python-Submissions
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo...
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,688,412,757
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
3,000
12,390,400
n = int(input()) x = input().split(' ') x = [int(n) for n in x] for i in range(len(x)): if i == 0: mi = abs(x[1] - x[0]) mx = abs(x[len(x)-1] - x[0]) elif i == len(x)-1: mi = abs(x[len(x)-1] - x[len(x)-2]) mx = abs(x[len(x) - 1] - x[0]) else: mi = abs(x...
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love...
```python n = int(input()) x = input().split(' ') x = [int(n) for n in x] for i in range(len(x)): if i == 0: mi = abs(x[1] - x[0]) mx = abs(x[len(x)-1] - x[0]) elif i == len(x)-1: mi = abs(x[len(x)-1] - x[len(x)-2]) mx = abs(x[len(x) - 1] - x[0]) else: ...
0
MatrixStudio/Codeforces-Python-Submissions
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,674,488,829
2,147,483,647
Python 3
OK
TESTS
37
122
0
n = int(input()) a = list(map(int , input().split())) b = 0 for i in range(1,n): hd = a[0:i] if max(hd) < a[i] or min(hd) > a[i]: b = b + 1 print(b)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python n = int(input()) a = list(map(int , input().split())) b = 0 for i in range(1,n): hd = a[0:i] if max(hd) < a[i] or min(hd) > a[i]: b = b + 1 print(b) ```
3
MatrixStudio/Codeforces-Python-Submissions
534
B
Covered Path
PROGRAMMING
1,400
[ "dp", "greedy", "math" ]
null
null
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constan...
The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<...
Print the maximum possible length of the path segment in meters.
[ "5 6\n4 2\n", "10 10\n10 0\n" ]
[ "26", "100" ]
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
1,000
[ { "input": "5 6\n4 2", "output": "26" }, { "input": "10 10\n10 0", "output": "100" }, { "input": "87 87\n2 10", "output": "174" }, { "input": "1 11\n6 2", "output": "36" }, { "input": "100 10\n10 10", "output": "550" }, { "input": "1 1\n100 10", "o...
1,673,878,340
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
61
0
I = lambda : map(int, input().split()) s, e = I() t, d = I() a = [0]*t a[0], a[-1] = s, e i, j = 1, t-2 while( i<j ): a[i] = a[i-1] + d a[j] = a[j+1] + d i += 1 j -= 1 if t%2: a[i] = max(a[i-1], a[i+1]) print(sum(a))
Title: Covered Path Time Limit: None seconds Memory Limit: None megabytes Problem Description: The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the ...
```python I = lambda : map(int, input().split()) s, e = I() t, d = I() a = [0]*t a[0], a[-1] = s, e i, j = 1, t-2 while( i<j ): a[i] = a[i-1] + d a[j] = a[j+1] + d i += 1 j -= 1 if t%2: a[i] = max(a[i-1], a[i+1]) print(sum(a)) ```
0
MatrixStudio/Codeforces-Python-Submissions
272
D
Dima and Two Sequences
PROGRAMMING
1,600
[ "combinatorics", "math", "sortings" ]
null
null
Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*). Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that...
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). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces. The last line contains integer *m* ...
In the single line print the remainder after dividing the answer to the problem by number *m*.
[ "1\n1\n2\n7\n", "2\n1 2\n2 3\n11\n" ]
[ "1\n", "2\n" ]
In the first sample you can get only one sequence: (1, 1), (2, 1). In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2.
2,000
[ { "input": "1\n1\n2\n7", "output": "1" }, { "input": "2\n1 2\n2 3\n11", "output": "2" }, { "input": "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5...
1,621,058,476
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
186
0
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) m = int(input()) a.extend(b) a.sort() ans = 1 i=0 while i<len(a): p = a[i] count = 0 while i<len(a) and p==a[i]: count+=1 i+=1 ans =( ans%m )*(count%m) ans = ans%m print(a...
Title: Dima and Two Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*). Now Dima wants to count the ...
```python n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) m = int(input()) a.extend(b) a.sort() ans = 1 i=0 while i<len(a): p = a[i] count = 0 while i<len(a) and p==a[i]: count+=1 i+=1 ans =( ans%m )*(count%m) ans = ans%...
0
MatrixStudio/Codeforces-Python-Submissions
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,524,891,359
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
154
7,065,600
n = int(input()) d = {} max_name = "" max_score = float('-inf') names = [] scores = [] for i in range(n): name, score = tuple(input().split()) score = int(score) names.append(name) scores.append(score) if score > max_score: max_score = score for i in range(len(...
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python n = int(input()) d = {} max_name = "" max_score = float('-inf') names = [] scores = [] for i in range(n): name, score = tuple(input().split()) score = int(score) names.append(name) scores.append(score) if score > max_score: max_score = score for i in ...
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,693,710,222
2,147,483,647
Python 3
OK
TESTS
62
46
0
a,b=map(int,input().split()) count=0 while a<=b: a=a*3 b=b*2 count+=1 print(count)
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 a,b=map(int,input().split()) count=0 while a<=b: a=a*3 b=b*2 count+=1 print(count) ```
3
MatrixStudio/Codeforces-Python-Submissions
19
A
World Football Cup
PROGRAMMING
1,400
[ "implementation" ]
A. World Football Cup
2
64
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: - the final tournament features *n* teams (*n* is always even) - the first *n*<=/<=2 t...
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=50) — amount of the teams, taking part in the final tournament of World Cup. The following *n* lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following *...
Output *n*<=/<=2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.
[ "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n", "2\na\nA\na-A 2:1\n" ]
[ "A\nD\n", "a\n" ]
none
0
[ { "input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD" }, { "input": "2\na\nA\na-A 2:1", "output": "a" }, { "input": "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92", "output": "EULEUbCmfrmqxtzvg"...
1,595,766,165
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
6,963,200
# -*- coding: utf-8 -*- dic,lista = {},[] n = int(input()) for i in range(n): dic[input()] = {'points': 0,'scored': 0,'missed': 0} matches = [input().split() for j in range(int(n*(n-1)/2))] for j in range(len(matches)): goals1,goals2 = int(matches[j][1][0]),int(matches[j][1][2]) team1,team2 = m...
Title: World Football Cup Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup reg...
```python # -*- coding: utf-8 -*- dic,lista = {},[] n = int(input()) for i in range(n): dic[input()] = {'points': 0,'scored': 0,'missed': 0} matches = [input().split() for j in range(int(n*(n-1)/2))] for j in range(len(matches)): goals1,goals2 = int(matches[j][1][0]),int(matches[j][1][2]) team1...
0
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,598,982,569
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
34
109
0
def main(): typed = input() result = "hello" index = 0 foo = False for s in typed: if index == 4: foo = True break if s == result[index]: index += 1 if foo: print("YES") else: print("NO") main()
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 def main(): typed = input() result = "hello" index = 0 foo = False for s in typed: if index == 4: foo = True break if s == result[index]: index += 1 if foo: print("YES") else: print("NO") mai...
0
MatrixStudio/Codeforces-Python-Submissions
18
C
Stripe
PROGRAMMING
1,200
[ "data structures", "implementation" ]
C. Stripe
2
64
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
[ "9\n1 5 -6 7 9 -16 0 -2 2\n", "3\n1 1 1\n", "2\n0 0\n" ]
[ "3\n", "0\n", "1\n" ]
none
0
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2", "output": "3" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "4\n100 1 10 111", "output": "1" }, { "input": "10\n0 4 -3 0 -2 2 -3 -3 2 5", "output": "3" }, { "input": "...
1,670,669,706
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n; cin >> n; vector<ll> v(n); ll sum=0; for (int i=0;i<n;i++){ cin >> v[i]; sum+=v[i]; } int c=0; int sum1=0; for (int i=0;i<n-1;i++){ sum1+=v[i]; ...
Title: Stripe Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ...
```python #include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n; cin >> n; vector<ll> v(n); ll sum=0; for (int i=0;i<n;i++){ cin >> v[i]; sum+=v[i]; } int c=0; int sum1=0; for (int i=0;i<n-1;i++){ sum1+...
-1
MatrixStudio/Codeforces-Python-Submissions
325
B
Stadium and Games
PROGRAMMING
1,800
[ "binary search", "math" ]
null
null
Daniel is organizing a football tournament. He has come up with the following tournament format: 1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1018), the number of games that should be played. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print all possible numbers of invited teams in ascending order, one per line. If exactly *n* games cannot be played, output one number: -1.
[ "3\n", "25\n", "2\n" ]
[ "3\n4\n", "20\n", "-1\n" ]
none
1,000
[ { "input": "3", "output": "3\n4" }, { "input": "25", "output": "20" }, { "input": "2", "output": "-1" }, { "input": "1", "output": "2" }, { "input": "15", "output": "10\n16" }, { "input": "314", "output": "-1" }, { "input": "524800", "o...
1,373,739,757
4,957
Python 3
WRONG_ANSWER
TESTS
37
218
5,222,400
import math from fractions import Decimal from decimal import * getcontext().prec = 100 x=int(input()) def tows(n): ans=0 while(n>0): ans+=2**n n-=1 return ans n=50 d=tows(200) k=True answer=[] for n in range(200,-1,-1): d=tows(n) b=(d -1) ans=[] s=Decimal(b**2+8*x) s=s.s...
Title: Stadium and Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Daniel is organizing a football tournament. He has come up with the following tournament format: 1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one g...
```python import math from fractions import Decimal from decimal import * getcontext().prec = 100 x=int(input()) def tows(n): ans=0 while(n>0): ans+=2**n n-=1 return ans n=50 d=tows(200) k=True answer=[] for n in range(200,-1,-1): d=tows(n) b=(d -1) ans=[] s=Decimal(b**2+8*x)...
0
MatrixStudio/Codeforces-Python-Submissions
385
C
Bear and Prime Numbers
PROGRAMMING
1,700
[ "binary search", "brute force", "data structures", "dp", "implementation", "math", "number theory" ]
null
null
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *...
The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=*x**i*<=≤<=107). The numbers are not necessarily distinct. The third line contains integer *m* (1<=≤<=*m*<=≤<=50000). Each of the following *m* lines contains a pair of space-separated integ...
Print *m* integers — the answers to the queries on the order the queries appear in the input.
[ "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n", "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n" ]
[ "9\n7\n0\n", "0\n7\n" ]
Consider the first sample. Overall, the first sample has 3 queries. 1. The first query *l* = 2, *r* = 11 comes. You need to count *f*(2) + *f*(3) + *f*(5) + *f*(7) + *f*(11) = 2 + 1 + 4 + 2 + 0 = 9. 1. The second query comes *l* = 3, *r* = 12. You need to count *f*(3) + *f*(5) + *f*(7) + *f*(11) = 1 + 4 + 2 + 0 = 7....
1,500
[ { "input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4", "output": "9\n7\n0" }, { "input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123", "output": "0\n7" }, { "input": "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792", "output": "0\n0\n0\n0\n9\n0\n0" }, { "...
1,695,908,080
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
3
2,043
536,883,200
# Version 20.0 import os, sys, math, itertools from collections import deque, defaultdict, OrderedDict, Counter from bisect import bisect, bisect_left, bisect_right, insort from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop ii = lambda : int(input()) si = lambda : input() ...
Title: Bear and Prime Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized b...
```python # Version 20.0 import os, sys, math, itertools from collections import deque, defaultdict, OrderedDict, Counter from bisect import bisect, bisect_left, bisect_right, insort from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop ii = lambda : int(input()) si = lambda : in...
0
MatrixStudio/Codeforces-Python-Submissions
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ...
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe repos...
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc...
1,595,624,809
2,147,483,647
Python 3
OK
TESTS
36
93
6,656,000
n = int(input()) reposts = {} for i in range(n): s = input().split() name1, name2 = s[0].lower(), s[2].lower() if name2 == "polycarp": reposts[name1] = 2 else: reposts[name1] = reposts[name2] + 1 print(max(reposts.values()))
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. ...
```python n = int(input()) reposts = {} for i in range(n): s = input().split() name1, name2 = s[0].lower(), s[2].lower() if name2 == "polycarp": reposts[name1] = 2 else: reposts[name1] = reposts[name2] + 1 print(max(reposts.values())) ```
3
MatrixStudio/Codeforces-Python-Submissions
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "ou...
1,691,227,580
2,147,483,647
Python 3
OK
TESTS
36
62
0
n = int(input()) def is_happy(arg): n = list(str(arg)) for i in range(len(n)): if n[i] != '4' and n[i] != '7': return False else: return True for i in range(4, n + 1): if is_happy(i): if n % i == 0: print('YES') break else:...
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) def is_happy(arg): n = list(str(arg)) for i in range(len(n)): if n[i] != '4' and n[i] != '7': return False else: return True for i in range(4, n + 1): if is_happy(i): if n % i == 0: print('YES') br...
3
MatrixStudio/Codeforces-Python-Submissions
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,689,835,501
2,147,483,647
PyPy 3-64
OK
TESTS
43
62
0
n=input() for i in range(len(n)): dig=min(int(n[i]),9-int(n[i])) if i==0 and dig==0: dig=9 print(dig,end="") print()
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python n=input() for i in range(len(n)): dig=min(int(n[i]),9-int(n[i])) if i==0 and dig==0: dig=9 print(dig,end="") print() ```
3
MatrixStudio/Codeforces-Python-Submissions
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,416,997,475
2,147,483,647
Python 3
OK
TESTS
32
154
0
#!/usr/bin/env python3 n = int(input()) num = list(map(int, input().split())) count_even, count_odd, last_even, last_odd = 0, 0, 0, 0 i = 0 for i in range(n): if num[i] % 2 == 0: last_even = i + 1 count_even += 1 else: last_odd = i + 1 count_odd += 1 print(last_odd if count_odd < count_even el...
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 #!/usr/bin/env python3 n = int(input()) num = list(map(int, input().split())) count_even, count_odd, last_even, last_odd = 0, 0, 0, 0 i = 0 for i in range(n): if num[i] % 2 == 0: last_even = i + 1 count_even += 1 else: last_odd = i + 1 count_odd += 1 print(last_odd if count_odd < cou...
3.9615
MatrixStudio/Codeforces-Python-Submissions
757
B
Bash's Big Day
PROGRAMMING
1,400
[ "greedy", "math", "number theory" ]
null
null
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of *k*<=&gt;<=1 Pokemon with strengths {*...
The input consists of two lines. The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab. The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon.
Print single integer — the maximum number of Pokemons Bash can take.
[ "3\n2 3 4\n", "5\n2 3 4 6 7\n" ]
[ "2\n", "3\n" ]
*gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a...
1,000
[ { "input": "3\n2 3 4", "output": "2" }, { "input": "5\n2 3 4 6 7", "output": "3" }, { "input": "3\n5 6 4", "output": "2" }, { "input": "8\n41 74 4 27 85 39 100 36", "output": "4" }, { "input": "6\n89 20 86 81 62 23", "output": "3" }, { "input": "71\n23...
1,697,907,538
2,147,483,647
PyPy 3-64
OK
TESTS
134
124
16,384,000
# Version 21.0 import os, sys, math, itertools from collections import deque, defaultdict, OrderedDict, Counter from bisect import bisect, bisect_left, bisect_right, insort from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop offline = __debug__ if not offline: import io ...
Title: Bash's Big Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr...
```python # Version 21.0 import os, sys, math, itertools from collections import deque, defaultdict, OrderedDict, Counter from bisect import bisect, bisect_left, bisect_right, insort from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop offline = __debug__ if not offline: imp...
3
MatrixStudio/Codeforces-Python-Submissions
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input...
1,653,947,389
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
77
0
from heapq import heappush, heappop, heapify from math import inf def dijkstra(G): n = len(G) dist = [inf]*n visited = [False]*n parent = [-1]*n q = [(0, 0)] dist[0] = 0 # heapify(q) while q: _, u = heappop(q) for v, w in G[u]: if not visited[v] a...
Title: Dijkstra? Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. Input Specification: The first line contains two integers *n* a...
```python from heapq import heappush, heappop, heapify from math import inf def dijkstra(G): n = len(G) dist = [inf]*n visited = [False]*n parent = [-1]*n q = [(0, 0)] dist[0] = 0 # heapify(q) while q: _, u = heappop(q) for v, w in G[u]: if not vi...
0
MatrixStudio/Codeforces-Python-Submissions
545
C
Woodcutters
PROGRAMMING
1,500
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t...
Print a single number — the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ...
1,750
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10...
1,673,722,978
2,147,483,647
Python 3
OK
TESTS
67
296
5,222,400
l = [] r = [] n = int(input()) for i in range(n): x, h = map(int, input().split()) l.append(x) r.append(h) ans = 0 for i in range(1, n - 1): if r[i] < l[i] - l[i - 1]: ans += 1 elif r[i] < l[i + 1] - l[i]: ans += 1 l[i] += r[i] if n == 1: ans += 1 else: ...
Title: Woodcutters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b...
```python l = [] r = [] n = int(input()) for i in range(n): x, h = map(int, input().split()) l.append(x) r.append(h) ans = 0 for i in range(1, n - 1): if r[i] < l[i] - l[i - 1]: ans += 1 elif r[i] < l[i + 1] - l[i]: ans += 1 l[i] += r[i] if n == 1: ans += 1...
3
MatrixStudio/Codeforces-Python-Submissions
1,009
B
Minimum Ternary String
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For e...
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
[ "100210\n", "11222121\n", "20\n" ]
[ "001120\n", "11112222\n", "20\n" ]
none
0
[ { "input": "100210", "output": "001120" }, { "input": "11222121", "output": "11112222" }, { "input": "20", "output": "20" }, { "input": "1002", "output": "0012" }, { "input": "10", "output": "01" }, { "input": "000021", "output": "000012" }, { ...
1,532,342,836
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
249
716,800
n = [i for i in input()] i = 0 while i != len(n) - 1: if (n[i] == "1" and n[i+1] == "0") or (n[i] == "2" and n[i+1] == "1"): n[i], n[i+1] = n[i+1], n[i] i = i - 1 if i != 0 else i else: i += 1 print(''.join(n))
Title: Minimum Ternary String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ...
```python n = [i for i in input()] i = 0 while i != len(n) - 1: if (n[i] == "1" and n[i+1] == "0") or (n[i] == "2" and n[i+1] == "1"): n[i], n[i+1] = n[i+1], n[i] i = i - 1 if i != 0 else i else: i += 1 print(''.join(n)) ```
0
MatrixStudio/Codeforces-Python-Submissions
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ...
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1...
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43...
1,456,001,743
2,147,483,647
Python 3
OK
TESTS
45
216
1,638,400
import math, re, sys, string, operator, functools, fractions, collections sys.setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) mod=int(1e9+7) eps=1e-6 pi=math.acos(-1.0) ######################...
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val...
```python import math, re, sys, string, operator, functools, fractions, collections sys.setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) mod=int(1e9+7) eps=1e-6 pi=math.acos(-1.0) ############...
3
MatrixStudio/Codeforces-Python-Submissions
287
B
Pipeline
PROGRAMMING
1,700
[ "binary search", "math" ]
null
null
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has onl...
The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1018, 2<=≤<=*k*<=≤<=109). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.
[ "4 3\n", "5 5\n", "8 4\n" ]
[ "2\n", "1\n", "-1\n" ]
none
1,500
[ { "input": "4 3", "output": "2" }, { "input": "5 5", "output": "1" }, { "input": "8 4", "output": "-1" }, { "input": "1000000000000000000 1000000000", "output": "-1" }, { "input": "499999998500000001 1000000000", "output": "999955279" }, { "input": "49...
1,672,930,929
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
62
2,867,200
import resource, sys sys.setrecursionlimit(10000) resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1)) from collections import * from functools import * from heapq import * inf = 10e9 n, k = map(int, input().split()) def f(n, a, l): # Sum of all terms in a finite AP with the last term as 'l' = n/2(a +...
Title: Pipeline Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe c...
```python import resource, sys sys.setrecursionlimit(10000) resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1)) from collections import * from functools import * from heapq import * inf = 10e9 n, k = map(int, input().split()) def f(n, a, l): # Sum of all terms in a finite AP with the last term as 'l'...
-1
MatrixStudio/Codeforces-Python-Submissions
778
B
Bitwise Formula
PROGRAMMING
1,800
[ "bitmasks", "brute force", "dfs and similar", "expression parsing", "implementation" ]
null
null
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer *m*, bit depth of the game, which means that all numbers in the game will consist of *m* bits. Then he asks Peter to choose some *m*-bit number. After ...
The first line contains two integers *n* and *m*, the number of variables and bit depth, respectively (1<=≤<=*n*<=≤<=5000; 1<=≤<=*m*<=≤<=1000). The following *n* lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, ...
In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as *m*-bit binary numb...
[ "3 3\na := 101\nb := 011\nc := ? XOR b\n", "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n" ]
[ "011\n100\n", "0\n0\n" ]
In the first sample if Peter chooses a number 011<sub class="lower-index">2</sub>, then *a* = 101<sub class="lower-index">2</sub>, *b* = 011<sub class="lower-index">2</sub>, *c* = 000<sub class="lower-index">2</sub>, the sum of their values is 8. If he chooses the number 100<sub class="lower-index">2</sub>, then *a* = ...
1,000
[ { "input": "3 3\na := 101\nb := 011\nc := ? XOR b", "output": "011\n100" }, { "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb", "output": "0\n0" }, { "input": "2 10\nb := 0100101101\na := ? XOR b", "output": "0100101101\n1011010010" }, { "input": "1 ...
1,488,106,436
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
3,000
6,963,200
import operator n, m = map(int, input().split()) elems = dict() var_order = [] d_op = dict() d_op[' AND '] = operator.and_ d_op[' OR '] = operator.or_ d_op[' XOR '] = operator.xor def find_val(pos, x_val): elems_val = dict() elems_val['?'] = x_val result = 0 for var in var_order: op, rg = el...
Title: Bitwise Formula Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer *m*, bit depth of the game, which means that all n...
```python import operator n, m = map(int, input().split()) elems = dict() var_order = [] d_op = dict() d_op[' AND '] = operator.and_ d_op[' OR '] = operator.or_ d_op[' XOR '] = operator.xor def find_val(pos, x_val): elems_val = dict() elems_val['?'] = x_val result = 0 for var in var_order: o...
0
MatrixStudio/Codeforces-Python-Submissions
318
B
Strings of Power
PROGRAMMING
1,300
[ "implementation", "strings", "two pointers" ]
null
null
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters.
Print exactly one number — the number of powerful substrings of the given string. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "heavymetalisheavymetal\n", "heavymetalismetal\n", "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n" ]
[ "3", "2", "3" ]
In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful. In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".
500
[ { "input": "heavymetalisheavymetal", "output": "3" }, { "input": "heavymetalismetal", "output": "2" }, { "input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "output": "3" }, { "input": "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmm...
1,693,240,964
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
4,915,200
s = input() n = len(s) count = 0 i = 0 while i < n-4: if s[i:i+5] == "heavy": j = i + 5 while j < n-4: if s[j:j+5] == "metal": count += 1 j += 1 i += 1 print(count)
Title: Strings of Power Time Limit: None seconds Memory Limit: None megabytes Problem Description: Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" an...
```python s = input() n = len(s) count = 0 i = 0 while i < n-4: if s[i:i+5] == "heavy": j = i + 5 while j < n-4: if s[j:j+5] == "metal": count += 1 j += 1 i += 1 print(count) ```
0
MatrixStudio/Codeforces-Python-Submissions
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ...
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooo...
1,697,068,568
2,147,483,647
PyPy 3-64
OK
TESTS
18
62
0
n = int(input()) fib = [1, 1] while fib[-1] < 1001: fib.append(fib[-1] + fib[-2]) res = "" for i in range(1, n+1): if i in fib: res += "O" else: res += "o" print(res)
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should o...
```python n = int(input()) fib = [1, 1] while fib[-1] < 1001: fib.append(fib[-1] + fib[-2]) res = "" for i in range(1, n+1): if i in fib: res += "O" else: res += "o" print(res) ```
3
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,250,903
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
first = input().split(" ") second = input().split(" ") new = [] even=[] odd=[] tally = [] g = 0 for n in second: new.append(int(n)) for x in range(len(second)): if x%2 ==0: even.append(x) else: odd.append(x) for y in range(int(len(second)/2)): if new[odd[y]-1] > new[even[...
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 first = input().split(" ") second = input().split(" ") new = [] even=[] odd=[] tally = [] g = 0 for n in second: new.append(int(n)) for x in range(len(second)): if x%2 ==0: even.append(x) else: odd.append(x) for y in range(int(len(second)/2)): if new[odd[y]-1] >...
0
MatrixStudio/Codeforces-Python-Submissions
978
B
File Name
PROGRAMMING
800
[ "greedy", "strings" ]
null
null
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
[ "6\nxxxiii\n", "5\nxxoxx\n", "10\nxxxxxxxxxx\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
0
[ { "input": "6\nxxxiii", "output": "1" }, { "input": "5\nxxoxx", "output": "0" }, { "input": "10\nxxxxxxxxxx", "output": "8" }, { "input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "98" }, { ...
1,657,302,972
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
def solve(): n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) if a[0]==a[-1]: print(0) else: if sum(a)%n!=0: print(-1) else: avg = int(sum(a) / n) count = 0 for i in range(n): ...
Title: File Name Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let...
```python def solve(): n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) if a[0]==a[-1]: print(0) else: if sum(a)%n!=0: print(-1) else: avg = int(sum(a) / n) count = 0 for i in range(n): ...
-1
MatrixStudio/Codeforces-Python-Submissions
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,643,375,304
2,147,483,647
PyPy 3
OK
TESTS
41
93
614,400
t=int(input()) if t%2==0: x=t//2 print(x) print("2 "*(x-1),end="") print("2") else: x=(t-3)//2 print(t//2) print("2 "*x,end="") print("3")
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python t=int(input()) if t%2==0: x=t//2 print(x) print("2 "*(x-1),end="") print("2") else: x=(t-3)//2 print(t//2) print("2 "*x,end="") print("3") ```
3
MatrixStudio/Codeforces-Python-Submissions
908
C
New Year and Curling
PROGRAMMING
1,500
[ "brute force", "geometry", "implementation", "math" ]
null
null
Carol is currently curling. She has *n* disks each with radius *r* on the 2D plane. Initially she has all these disks above the line *y*<==<=10100. She then will slide the disks towards the line *y*<==<=0 one by one in order from 1 to *n*. When she slides the *i*-th disk, she will place its center at the point (*...
The first line will contain two integers *n* and *r* (1<=≤<=*n*,<=*r*<=≤<=1<=000), the number of disks, and the radius of the disks, respectively. The next line will contain *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=1<=000) — the *x*-coordinates of the disks.
Print a single line with *n* numbers. The *i*-th number denotes the *y*-coordinate of the center of the *i*-th disk. The output will be accepted if it has absolute or relative error at most 10<=-<=6. Namely, let's assume that your answer for a particular value of a coordinate is *a* and the answer of the jury is *b*. ...
[ "6 2\n5 5 6 8 3 12\n" ]
[ "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\n" ]
The final positions of the disks will look as follows: In particular, note the position of the last disk.
1,000
[ { "input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613" }, { "input": "1 1\n5", "output": "1" }, { "input": "5 300\n939 465 129 611 532", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391" }, { "input": "5 ...
1,514,579,063
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
5,734,400
import math n,r=map(int,input().split()) x=list(map(int,input().split())) y=[r] def collision(t,a): for i in range(len(t)-1,-1,-1): if (a<=t[i]+2*r and a>=t[i]-2*r): if t[i]==a: return y[i]+2*r else: return(y...
Title: New Year and Curling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Carol is currently curling. She has *n* disks each with radius *r* on the 2D plane. Initially she has all these disks above the line *y*<==<=10100. She then will slide the disks towards the line *y*<==<=0 one b...
```python import math n,r=map(int,input().split()) x=list(map(int,input().split())) y=[r] def collision(t,a): for i in range(len(t)-1,-1,-1): if (a<=t[i]+2*r and a>=t[i]-2*r): if t[i]==a: return y[i]+2*r else: ...
0
MatrixStudio/Codeforces-Python-Submissions
195
D
Analyzing Polyline
PROGRAMMING
1,900
[ "geometry", "math", "sortings" ]
null
null
As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that. Let's consider a set of fun...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of functions. Each of the following *n* lines contains two space-separated integer numbers *k**i*,<=*b**i* (<=-<=109<=≤<=*k**i*,<=*b**i*<=≤<=109) that determine the *i*-th function.
Print a single number — the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions.
[ "1\n1 0\n", "3\n1 0\n0 2\n-1 1\n", "3\n-2 -4\n1 7\n-5 1\n" ]
[ "1\n", "2\n", "3\n" ]
none
2,000
[ { "input": "1\n1 0", "output": "1" }, { "input": "3\n1 0\n0 2\n-1 1", "output": "2" }, { "input": "3\n-2 -4\n1 7\n-5 1", "output": "3" }, { "input": "10\n9 9\n-5 2\n-2 9\n0 6\n6 7\n-1 -10\n-8 6\n3 6\n-3 -9\n0 4", "output": "8" }, { "input": "10\n-4 -9\n5 9\n-4 -1\...
1,535,496,038
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
51
902
4,608,000
s = set() for _ in range(int(input())): k, b = map(int, input().split()) if b and k: s.add(k / b) elif k: s.add(0) print(len(s))
Title: Analyzing Polyline Time Limit: None seconds Memory Limit: None megabytes Problem Description: As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only...
```python s = set() for _ in range(int(input())): k, b = map(int, input().split()) if b and k: s.add(k / b) elif k: s.add(0) print(len(s)) ```
0
MatrixStudio/Codeforces-Python-Submissions
466
C
Number of Ways
PROGRAMMING
1,700
[ "binary search", "brute force", "data structures", "dp", "two pointers" ]
null
null
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=...
The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*.
Print a single integer — the number of ways to split the array into three parts with the same sum.
[ "5\n1 2 3 0 3\n", "4\n0 1 -1 0\n", "2\n4 1\n" ]
[ "2\n", "1\n", "0\n" ]
none
1,500
[ { "input": "5\n1 2 3 0 3", "output": "2" }, { "input": "4\n0 1 -1 0", "output": "1" }, { "input": "2\n4 1", "output": "0" }, { "input": "9\n0 0 0 0 0 0 0 0 0", "output": "28" }, { "input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2", "output": "0" }, { "input": "1\...
1,699,597,660
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
2,560,000
n=int(input()) a=list(map(int,input().split())) num=0 if sum(a)%3!=0: print(0) else: x=int(sum(a)/3) for i in range(n-1): for j in range(i+1,n-1): if sum(a[0:i+1])==x and sum(a[i+1:j+1])==x and sum(a[j+1:n])==x: num+=1 else: num+=0 ...
Title: Number of Ways Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s...
```python n=int(input()) a=list(map(int,input().split())) num=0 if sum(a)%3!=0: print(0) else: x=int(sum(a)/3) for i in range(n-1): for j in range(i+1,n-1): if sum(a[0:i+1])==x and sum(a[i+1:j+1])==x and sum(a[j+1:n])==x: num+=1 else: ...
0
MatrixStudio/Codeforces-Python-Submissions
227
A
Where do I Turn?
PROGRAMMING
1,300
[ "geometry" ]
null
null
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight...
The first input line contains two space-separated integers *x**a*,<=*y**a* (|*x**a*|,<=|*y**a*|<=≤<=109) — the coordinates of point *A*. The second line contains the coordinates of point *B* in the same form, the third line contains the coordinates of point *C*. It is guaranteed that all points are pairwise different....
Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes).
[ "0 0\n0 1\n1 1\n", "-1 -1\n-3 -3\n-4 -4\n", "-4 -6\n-3 -7\n-2 -6\n" ]
[ "RIGHT\n", "TOWARDS\n", "LEFT\n" ]
The picture to the first sample: The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory. The picture to the second sample:
500
[ { "input": "0 0\n0 1\n1 1", "output": "RIGHT" }, { "input": "-1 -1\n-3 -3\n-4 -4", "output": "TOWARDS" }, { "input": "-4 -6\n-3 -7\n-2 -6", "output": "LEFT" }, { "input": "-44 57\n-118 -41\n-216 33", "output": "RIGHT" }, { "input": "39 100\n90 85\n105 136", "o...
1,672,959,740
2,147,483,647
Python 3
OK
TESTS
48
124
0
def encontra_vetor(a, b): return b[0] - a[0], b[1] - a[1] a = tuple(map(int, input().split())) b = tuple(map(int, input().split())) c = tuple(map(int, input().split())) vetor_ab = encontra_vetor(a, b) vetor_bc = encontra_vetor(b, c) det = (vetor_ab[0] * vetor_bc[1]) - (vetor_bc[0] * vetor_ab[1]) if det == 0: ...
Title: Where do I Turn? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the...
```python def encontra_vetor(a, b): return b[0] - a[0], b[1] - a[1] a = tuple(map(int, input().split())) b = tuple(map(int, input().split())) c = tuple(map(int, input().split())) vetor_ab = encontra_vetor(a, b) vetor_bc = encontra_vetor(b, c) det = (vetor_ab[0] * vetor_bc[1]) - (vetor_bc[0] * vetor_ab[1]) if d...
3
MatrixStudio/Codeforces-Python-Submissions
25
E
Test
PROGRAMMING
2,200
[ "hashing", "strings" ]
E. Test
2
256
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring *s*1, the second enters an infinite loop...
There are exactly 3 lines in the input data. The *i*-th line contains string *s**i*. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.
Output one number — what is minimal length of the string, containing *s*1, *s*2 and *s*3 as substrings.
[ "ab\nbc\ncd\n", "abacaba\nabaaba\nx\n" ]
[ "4\n", "11\n" ]
none
0
[ { "input": "ab\nbc\ncd", "output": "4" }, { "input": "abacaba\nabaaba\nx", "output": "11" }, { "input": "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls", "output": "100" }, { "input": "jwdezvgfm\nmdoqvylpuvyk\nqylld...
1,690,730,037
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
38
2,000
10,752,000
from itertools import permutations import sys import io import os MOD = 998244353 # 1000000007 INV2 = (MOD + 1) >> 1 # pow(2, MOD - 2, MOD) inf = 1 << 60 def Z_algorithm(s: str): n = len(s) Z_alg = [0] * n Z_alg[0], i, j = n, 1, 0 while i < n: while i + j < n and s[j] == s[i + ...
Title: Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong an...
```python from itertools import permutations import sys import io import os MOD = 998244353 # 1000000007 INV2 = (MOD + 1) >> 1 # pow(2, MOD - 2, MOD) inf = 1 << 60 def Z_algorithm(s: str): n = len(s) Z_alg = [0] * n Z_alg[0], i, j = n, 1, 0 while i < n: while i + j < n and s[j]...
0
MatrixStudio/Codeforces-Python-Submissions
938
C
Constructing Tests
PROGRAMMING
1,700
[ "binary search", "brute force", "constructive algorithms" ]
null
null
Let's denote a *m*-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size *m*<=×<=*m* of this matrix contains at least one zero. Consider the following problem: You are given two integers *n* and *m*. You have to construct an *m*-free square matrix of size *...
The first line contains one integer *t* (1<=≤<=*t*<=≤<=100) — the number of tests you have to construct. Then *t* lines follow, *i*-th line containing one integer *x**i* (0<=≤<=*x**i*<=≤<=109). Note that in hacks you have to set *t*<==<=1.
For each test you have to construct, output two positive numbers *n**i* and *m**i* (1<=≤<=*m**i*<=≤<=*n**i*<=≤<=109) such that the maximum number of 1's in a *m**i*-free *n**i*<=×<=*n**i* matrix is exactly *x**i*. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test...
[ "3\n21\n0\n1\n" ]
[ "5 2\n1 1\n-1\n" ]
none
0
[ { "input": "3\n21\n0\n1", "output": "5 2\n1 1\n-1" }, { "input": "1\n420441920", "output": "-1" }, { "input": "1\n4", "output": "-1" }, { "input": "1\n297540", "output": "546 22" }, { "input": "1\n9", "output": "-1" }, { "input": "1\n144", "output"...
1,563,160,643
3,443
PyPy 3
OK
TESTS
24
155
1,433,600
import math def div(k): res = [] for i in range(1,int(math.sqrt(k))+2): if k % i == 0: res.append(i) return res t = int(input()) for i in range(t): x = int(input()) if x == 0: print("1 1") elif x == 1: print(-1) else: ...
Title: Constructing Tests Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's denote a *m*-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size *m*<=×<=*m* of this matrix contains at least one zero. Consider the following pro...
```python import math def div(k): res = [] for i in range(1,int(math.sqrt(k))+2): if k % i == 0: res.append(i) return res t = int(input()) for i in range(t): x = int(input()) if x == 0: print("1 1") elif x == 1: print(-1) el...
3
MatrixStudio/Codeforces-Python-Submissions
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and c...
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712",...
1,631,083,360
2,147,483,647
PyPy 3
OK
TESTS
71
248
1,331,200
n = int(input()) m = 2*n+0.5 l = int(n**(1/2)) flag = 0 for i in range(1,l+1): a = (m-((i+0.5)**(2)))**(1/2)-0.5 if a == int((m-((i+0.5)**(2)))**(1/2)-0.5) and a != 0: print("Yes") flag = 1 break i = i+1 if flag == 0: print("No")
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent...
```python n = int(input()) m = 2*n+0.5 l = int(n**(1/2)) flag = 0 for i in range(1,l+1): a = (m-((i+0.5)**(2)))**(1/2)-0.5 if a == int((m-((i+0.5)**(2)))**(1/2)-0.5) and a != 0: print("Yes") flag = 1 break i = i+1 if flag == 0: print("No") ```
3
MatrixStudio/Codeforces-Python-Submissions
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,683,007,043
2,147,483,647
Python 3
OK
TESTS
102
46
0
n1=input() n2=input() j=0 a="" for i in n1: if i==n2[j]: a=a+"0" j+=1 else: a=a+"1" j+=1 print(a)
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 n1=input() n2=input() j=0 a="" for i in n1: if i==n2[j]: a=a+"0" j+=1 else: a=a+"1" j+=1 print(a) ```
3.9885
MatrixStudio/Codeforces-Python-Submissions
190
C
STL
PROGRAMMING
1,500
[ "dfs and similar" ]
null
null
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer. We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integer...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the type dictated by Gena contains. The second line contains space-separated words, said by Gena. Each of them is either "pair" or "int" (without the quotes). It is guaranteed that the total number of words does not exceed 105 ...
If it is possible to add the punctuation marks so as to get a correct type of language X-- as a result, print a single line that represents the resulting type. Otherwise, print "Error occurred" (without the quotes). Inside the record of a type should not be any extra spaces and other characters. It is guaranteed that...
[ "3\npair pair int int int\n", "1\npair int\n" ]
[ "pair&lt;pair&lt;int,int&gt;,int&gt;", "Error occurred" ]
none
1,500
[ { "input": "3\npair pair int int int", "output": "pair<pair<int,int>,int>" }, { "input": "1\npair int", "output": "Error occurred" }, { "input": "4\npair pair int int pair int int", "output": "pair<pair<int,int>,pair<int,int>>" }, { "input": "4\npair pair pair int int int int...
1,621,870,882
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
0
n=int(input()) l=[x for x in input().split()] i=l.count("int") p=l.count("pair") if p>=i or p<i-1: print("Error occurred") else: for j in l: if j=='pair': print("pair<",end='') for j in range(1,i): if j%2!=0: print("int",end='') else: ...
Title: STL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer. We all know that programs often store sets of integers. For example, if we hav...
```python n=int(input()) l=[x for x in input().split()] i=l.count("int") p=l.count("pair") if p>=i or p<i-1: print("Error occurred") else: for j in l: if j=='pair': print("pair<",end='') for j in range(1,i): if j%2!=0: print("int",end='') else: ...
0
MatrixStudio/Codeforces-Python-Submissions
507
B
Amr and Pins
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b...
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 0 0 0 4", "output": "1" }, { "input": "1 1 1 4 4", "output": "3" }, { "input": "4 5 6 5 6", "output": "0" }, { "input": "10 20 0 40 0", "output": "1" }, { "input": "9 20 0 40 0", "output": "2" }, { "input": "5 -1 -6 -5 1", "output": "...
1,608,227,369
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
108
0
import math r,x,y,a,b=map(int,input().split()) t=(((a-x)*(a-x))+((b-y)*(b-y))) print(math.ceil((math.sqrt(18))//2*r))
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()) t=(((a-x)*(a-x))+((b-y)*(b-y))) print(math.ceil((math.sqrt(18))//2*r)) ```
0
MatrixStudio/Codeforces-Python-Submissions
687
B
Remainders Game
PROGRAMMING
1,800
[ "chinese remainder theorem", "math", "number theory" ]
null
null
Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000).
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise.
[ "4 5\n2 3 5 12\n", "2 7\n2 3\n" ]
[ "Yes\n", "No\n" ]
In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <img align="middle" ...
1,000
[ { "input": "4 5\n2 3 5 12", "output": "Yes" }, { "input": "2 7\n2 3", "output": "No" }, { "input": "1 6\n8", "output": "No" }, { "input": "2 3\n9 4", "output": "Yes" }, { "input": "4 16\n19 16 13 9", "output": "Yes" }, { "input": "5 10\n5 16 19 9 17", ...
1,508,826,383
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
36
1,000
80,793,600
import sys (n , k) = map(int , input().split()) arr = map(int , input().split()) primes = {} d = 2 while d * d <= k: cnt = 0 while k % d == 0: k /= d cnt += 1 if cnt > 0: primes[d] = cnt d += 1 if k != 1: primes[k] = 1 lcm = {} for k in primes.keys(): ...
Title: Remainders Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*...
```python import sys (n , k) = map(int , input().split()) arr = map(int , input().split()) primes = {} d = 2 while d * d <= k: cnt = 0 while k % d == 0: k /= d cnt += 1 if cnt > 0: primes[d] = cnt d += 1 if k != 1: primes[k] = 1 lcm = {} for k in primes.ke...
0
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,570,727,508
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
s = input() a = [] countered = 0 for alpha in s: if alpha not in a: a.append(alpha) if alpha == 'l': countered += 1 elif alpha == 'l' and countered <2: a.append(alpha) countered += 1 for alpha in a: check = False if alpha in 'hello': ...
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 s = input() a = [] countered = 0 for alpha in s: if alpha not in a: a.append(alpha) if alpha == 'l': countered += 1 elif alpha == 'l' and countered <2: a.append(alpha) countered += 1 for alpha in a: check = False if alpha in 'hello...
0
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*<=&gt;<=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,595,487
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
x = int(input(())) e = [] def main(a, b): if a == 0: e.append(b) elif a > 0: main(a - 1, b + 1) or main(a - 2, b + 1) or main(a - 3, b + 1) or main(a - 4, b + 1) or main(a - 5, b + 1) main(x, 0) print(min(e))
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*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python x = int(input(())) e = [] def main(a, b): if a == 0: e.append(b) elif a > 0: main(a - 1, b + 1) or main(a - 2, b + 1) or main(a - 3, b + 1) or main(a - 4, b + 1) or main(a - 5, b + 1) main(x, 0) print(min(e)) ```
0
MatrixStudio/Codeforces-Python-Submissions
803
A
Maximal Binary Matrix
PROGRAMMING
1,400
[ "constructive algorithms" ]
null
null
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicograph...
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
If the answer exists then output resulting matrix. Otherwise output -1.
[ "2 1\n", "3 2\n", "2 5\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n" ]
none
0
[ { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "2 5", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "20 398", "output": "1 1 1 1 ...
1,590,847,333
2,147,483,647
PyPy 3
OK
TESTS
168
186
2,560,000
import sys import math def IO(): sys.stdin=open("pyinput.txt", 'r') sys.stdout=open("pyoutput.txt", 'w') def GCD(a, b): if(b==0): return a else: return GCD(b, a%b) def LCM(a, b): return a*(b//GCD(a, b)) def scan(TYPE_1, TYPE_2=0): if(TYPE_1==int): return map(int, sys.stdin.readline().strip()....
Title: Maximal Binary Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes...
```python import sys import math def IO(): sys.stdin=open("pyinput.txt", 'r') sys.stdout=open("pyoutput.txt", 'w') def GCD(a, b): if(b==0): return a else: return GCD(b, a%b) def LCM(a, b): return a*(b//GCD(a, b)) def scan(TYPE_1, TYPE_2=0): if(TYPE_1==int): return map(int, sys.stdin.readline(...
3
MatrixStudio/Codeforces-Python-Submissions
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string...
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11)...
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output"...
1,492,807,129
2,147,483,647
Python 3
OK
TESTS
43
77
5,529,600
s = input().strip() p = "bear" l = len(s) start = 0 total = 0 while True: i = s.find(p, start) if i==-1: break prev = (i-start)+1 multiplier = l - (i+3) total += prev * multiplier start = i+1 print(total)
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j...
```python s = input().strip() p = "bear" l = len(s) start = 0 total = 0 while True: i = s.find(p, start) if i==-1: break prev = (i-start)+1 multiplier = l - (i+3) total += prev * multiplier start = i+1 print(total) ```
3
MatrixStudio/Codeforces-Python-Submissions
787
B
Not Afraid
PROGRAMMING
1,300
[ "greedy", "implementation", "math" ]
null
null
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick...
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104) — number of universes and number of groups respectively. The next *m* lines contain the information about the groups. *i*-th of them first contains an integer *k* (number of times someone joined *i*-th group, *k*<=&gt;<=0) followed by ...
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
[ "4 2\n1 -3\n4 -2 3 2 -3\n", "5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n", "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
1,000
[ { "input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES" }, { "input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO" }, { "input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES" }, { "input": "2 1\n2 -2 2", "output": "NO" }, { "input": "7 7\n1 -2\n1 6\n2 7 -6\n2...
1,490,352,084
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
56
62
5,529,600
def main(): n, m = map(int, input().split()) for i in range(m): numbers = tuple(map(int, input().split())) s = set() is_safe = False for t in numbers: if -t in s: is_safe = True break s.add(t) if is_safe =...
Title: Not Afraid Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are *n* parallel universes ...
```python def main(): n, m = map(int, input().split()) for i in range(m): numbers = tuple(map(int, input().split())) s = set() is_safe = False for t in numbers: if -t in s: is_safe = True break s.add(t) if...
0
MatrixStudio/Codeforces-Python-Submissions
217
A
Ice Skating
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves...
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* ...
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182...
1,665,084,900
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
124
0
x=int(input()) ans=0 a=[0]*2000 b=[0]*2000 p=[] for i in range(x): y,z=map(int,input().split()) p.append([y,z]) y=p[i][0] z=p[i][1] a[y]=1 b[z]=1 for i in range(x-1): y=p[i][0] z=p[i][1] if(a[y]==0) and (b[z]==0): ans+=1 a[y]=1 b[z]=1 print(ans)
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha...
```python x=int(input()) ans=0 a=[0]*2000 b=[0]*2000 p=[] for i in range(x): y,z=map(int,input().split()) p.append([y,z]) y=p[i][0] z=p[i][1] a[y]=1 b[z]=1 for i in range(x-1): y=p[i][0] z=p[i][1] if(a[y]==0) and (b[z]==0): ans+=1 a[y]=1 b[z]=1 print(ans) ```
0
MatrixStudio/Codeforces-Python-Submissions
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi...
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel...
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input"...
1,687,501,311
2,147,483,647
PyPy 3-64
OK
TESTS
37
140
11,571,200
import math, heapq from sys import stdin from collections import Counter, defaultdict, deque, namedtuple, OrderedDict from bisect import bisect_right, bisect_left from typing import List, DefaultDict from itertools import permutations from copy import deepcopy def sieve_of_eratosthenes(n): is_prime = ...
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first ...
```python import math, heapq from sys import stdin from collections import Counter, defaultdict, deque, namedtuple, OrderedDict from bisect import bisect_right, bisect_left from typing import List, DefaultDict from itertools import permutations from copy import deepcopy def sieve_of_eratosthenes(n): i...
3
MatrixStudio/Codeforces-Python-Submissions
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,577,303,343
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
218
307,200
import math n = [int(x) for x in input().split()] yes = 1 for i in range(n[0]+1,n[1]): yes = 1 sqrt = int(math.sqrt(i))+1 for j in range(2,sqrt): if(i%j==0): yes =0 break if(yes!=0): break if(yes!=0): print("NO") else: yes = 1 sqrt = int(math.sqrt(n...
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python import math n = [int(x) for x in input().split()] yes = 1 for i in range(n[0]+1,n[1]): yes = 1 sqrt = int(math.sqrt(i))+1 for j in range(2,sqrt): if(i%j==0): yes =0 break if(yes!=0): break if(yes!=0): print("NO") else: yes = 1 sqrt = int(m...
0
MatrixStudio/Codeforces-Python-Submissions
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta...
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" },...
1,547,725,305
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
108
0
n = int(input()) arr = ["" for i in range(n)] cnt = 0 for i in range(n): s = input() for j in range(n): arr[j] += s[j] a = s.count("C") cnt += a - 1 for i in arr: a = i.count("C") b = [i for i in range(1, a)] cnt += sum(b) print(cnt)
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with s...
```python n = int(input()) arr = ["" for i in range(n)] cnt = 0 for i in range(n): s = input() for j in range(n): arr[j] += s[j] a = s.count("C") cnt += a - 1 for i in arr: a = i.count("C") b = [i for i in range(1, a)] cnt += sum(b) print(cnt) ```
0
MatrixStudio/Codeforces-Python-Submissions
670
A
Holidays
PROGRAMMING
900
[ "brute force", "constructive algorithms", "greedy", "math" ]
null
null
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
[ "14\n", "2\n" ]
[ "4 4\n", "0 2\n" ]
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
500
[ { "input": "14", "output": "4 4" }, { "input": "2", "output": "0 2" }, { "input": "1", "output": "0 1" }, { "input": "3", "output": "0 2" }, { "input": "4", "output": "0 2" }, { "input": "5", "output": "0 2" }, { "input": "6", "output":...
1,693,658,121
2,147,483,647
Python 3
OK
TESTS
198
46
0
n = int(input()) weeks = (n // 7) * 2 remaining_days = n % 7 min_days_off = weeks + (1 if remaining_days == 6 else 0) max_days_off = weeks + min(2, remaining_days) print(min_days_off, max_days_off)
Title: Holidays Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim...
```python n = int(input()) weeks = (n // 7) * 2 remaining_days = n % 7 min_days_off = weeks + (1 if remaining_days == 6 else 0) max_days_off = weeks + min(2, remaining_days) print(min_days_off, max_days_off) ```
3
MatrixStudio/Codeforces-Python-Submissions
916
C
Jamie and Interesting Graph
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "shortest paths" ]
null
null
Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The su...
First line of input contains 2 integers *n*, *m*  — the required number of vertices and edges.
In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) d...
[ "4 4\n", "5 4\n" ]
[ "7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n", "7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n" ]
The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*). Definition of terms used in the problem statement: A shor...
1,500
[ { "input": "4 4", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000" }, { "input": "5 4", "output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1" }, { "input": "2 1", "output": "100003 100003\n1 2 100003" }, { "input": "10 19", "output": "100003 100003...
1,516,376,588
4,088
Python 3
WRONG_ANSWER
PRETESTS
2
62
5,632,000
n, m = map(int, input().split()) x = 100003 - (n - 1) print(2, 100003) for i in range(2, n+1): if i <= n - 2: print(1, i, 1) elif i == n - 1: print(1, i, x) else: print(1, n, 2) m = m - (n - 1) i = 2 j = 3 while m > 0: print(i, j, 1000000) j = j + 1 ...
Title: Jamie and Interesting Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integer...
```python n, m = map(int, input().split()) x = 100003 - (n - 1) print(2, 100003) for i in range(2, n+1): if i <= n - 2: print(1, i, 1) elif i == n - 1: print(1, i, x) else: print(1, n, 2) m = m - (n - 1) i = 2 j = 3 while m > 0: print(i, j, 1000000) j...
0
MatrixStudio/Codeforces-Python-Submissions
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,685,128,840
2,147,483,647
Python 3
OK
TESTS
37
92
0
n = int(input()) linha = [int(x) for x in input().split()] lista = [linha[0]] contador = 0 for x in linha[1:]: if x > max(lista) or x < min(lista): contador +=1 else: pass lista.append(x) print(contador)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python n = int(input()) linha = [int(x) for x in input().split()] lista = [linha[0]] contador = 0 for x in linha[1:]: if x > max(lista) or x < min(lista): contador +=1 else: pass lista.append(x) print(contador) ```
3
MatrixStudio/Codeforces-Python-Submissions
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,590,081,399
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
248
0
l=list(map(int,input().split())) a = 7-max(l) if(a==1 or a==6): print(str(a)+"/6") if(a==2): print("1/3") if(a==3): print("1/2") if(a==4): print("2/3")
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python l=list(map(int,input().split())) a = 7-max(l) if(a==1 or a==6): print(str(a)+"/6") if(a==2): print("1/3") if(a==3): print("1/2") if(a==4): print("2/3") ```
0
MatrixStudio/Codeforces-Python-Submissions
554
B
Ohana Cleans Up
PROGRAMMING
1,200
[ "brute force", "greedy", "strings" ]
null
null
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square,...
The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-t...
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
[ "4\n0101\n1000\n1111\n0101\n", "3\n111\n111\n111\n" ]
[ "2\n", "3\n" ]
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
500
[ { "input": "4\n0101\n1000\n1111\n0101", "output": "2" }, { "input": "3\n111\n111\n111", "output": "3" }, { "input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "9" }, { "input": "1\n1"...
1,657,692,129
2,147,483,647
Python 3
OK
TESTS
36
61
102,400
from collections import Counter as cnt l=[] for p in range(int(input())): s=str(input()) l.append(s) c=cnt(l) m=float("-inf") for i in c: m=max(m,c[i]) print(m)
Title: Ohana Cleans Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very str...
```python from collections import Counter as cnt l=[] for p in range(int(input())): s=str(input()) l.append(s) c=cnt(l) m=float("-inf") for i in c: m=max(m,c[i]) print(m) ```
3
MatrixStudio/Codeforces-Python-Submissions
152
C
Pocket Book
PROGRAMMING
1,400
[ "combinatorics" ]
null
null
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters.
Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7).
[ "2 3\nAAB\nBAA\n", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n" ]
[ "4\n", "216\n" ]
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
1,500
[ { "input": "2 3\nAAB\nBAA", "output": "4" }, { "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "output": "216" }, { "input": "1 1\nE", "output": "1" }, { "input": "2 2\nNS\nPD", "output": "4" }, { "input": "3 4\nPJKD\nNFJX\nFGFK", "output": "81" }, { "inpu...
1,685,728,663
2,147,483,647
PyPy 3-64
OK
TESTS
60
124
1,536,000
n, m = map(int,input().split()) ls = [] ans = 1 for i in range(n) : s = input() ls.append(s) for i in range(m) : st = set() for j in range(n) : st.add(ls[j][i]) ans *= len(st) ans %= 1000000007 print(ans)
Title: Pocket Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. ...
```python n, m = map(int,input().split()) ls = [] ans = 1 for i in range(n) : s = input() ls.append(s) for i in range(m) : st = set() for j in range(n) : st.add(ls[j][i]) ans *= len(st) ans %= 1000000007 print(ans) ```
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,628,781,644
2,147,483,647
Python 3
OK
TESTS
36
154
6,963,200
n,m=map(int,input().split()) x,y=[],[] for i in range(n): s=input() for j in range(m): if s[j]=='*': x.append(j) y.append(i) for i in range(3): for j in range(3): if i!=j and x[i]==x[j]: y1,y2,x_=y[i],y[j],x[i] if i!=j and y[i]==y[j]: ...
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma...
```python n,m=map(int,input().split()) x,y=[],[] for i in range(n): s=input() for j in range(m): if s[j]=='*': x.append(j) y.append(i) for i in range(3): for j in range(3): if i!=j and x[i]==x[j]: y1,y2,x_=y[i],y[j],x[i] if i!=j and y[i...
3
MatrixStudio/Codeforces-Python-Submissions
479
C
Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a st...
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i...
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
[ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ]
[ "2\n", "6\n" ]
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark ...
1,500
[ { "input": "3\n5 2\n3 1\n4 2", "output": "2" }, { "input": "3\n6 1\n5 2\n4 3", "output": "6" }, { "input": "1\n1000000000 999999999", "output": "999999999" }, { "input": "1\n2 1", "output": "1" }, { "input": "2\n3 2\n3 2", "output": "2" }, { "input": "...
1,694,682,432
2,147,483,647
Python 3
OK
TESTS
53
46
716,800
n=int(input()) l=[] for i in range(n): a, b= map(int, input().split()) l.append([a,b]) l.sort() prev=0 for a, b in l: if b>= prev: prev=b else: prev=a print(prev)
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Beside...
```python n=int(input()) l=[] for i in range(n): a, b= map(int, input().split()) l.append([a,b]) l.sort() prev=0 for a, b in l: if b>= prev: prev=b else: prev=a print(prev) ```
3
MatrixStudio/Codeforces-Python-Submissions