problem_id
stringlengths
3
7
contestId
stringclasses
660 values
problem_index
stringclasses
27 values
programmingLanguage
stringclasses
3 values
testset
stringclasses
5 values
incorrect_passedTestCount
float64
0
146
incorrect_timeConsumedMillis
float64
15
4.26k
incorrect_memoryConsumedBytes
float64
0
271M
incorrect_submission_id
stringlengths
7
9
incorrect_source
stringlengths
10
27.7k
correct_passedTestCount
float64
2
360
correct_timeConsumedMillis
int64
30
8.06k
correct_memoryConsumedBytes
int64
0
475M
correct_submission_id
stringlengths
7
9
correct_source
stringlengths
28
21.2k
contest_name
stringclasses
664 values
contest_type
stringclasses
3 values
contest_start_year
int64
2.01k
2.02k
time_limit
float64
0.5
15
memory_limit
float64
64
1.02k
title
stringlengths
2
54
description
stringlengths
35
3.16k
input_format
stringlengths
67
1.76k
output_format
stringlengths
18
1.06k
⌀
interaction_format
null
note
stringclasses
840 values
examples
stringlengths
34
1.16k
rating
int64
800
3.4k
⌀
tags
stringclasses
533 values
testset_size
int64
2
360
official_tests
stringlengths
44
19.7M
official_tests_complete
bool
1 class
input_mode
stringclasses
1 value
generated_checker
stringclasses
231 values
executable
bool
1 class
725/A
725
A
Python 3
PRETESTS
6
62
614,400
21674116
input() s = input() n = 0 while '><' in s: s = s.replace('><', '') print(len(s))
78
46
614,400
181322048
n = int(input()) a = input() print(n- len(a.lstrip("<").rstrip(">")))
Canada Cup 2016
CF
2,016
2
256
Jumping Ball
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
null
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
[{"input": "4\n<<><", "output": "2"}, {"input": "5\n>>>>>", "output": "5"}, {"input": "4\n>><<", "output": "0"}]
1,000
["implementation"]
78
[{"input": "4\r\n<<><\r\n", "output": "2\r\n"}, {"input": "5\r\n>>>>>\r\n", "output": "5\r\n"}, {"input": "4\r\n>><<\r\n", "output": "0\r\n"}, {"input": "3\r\n<<>\r\n", "output": "3\r\n"}, {"input": "3\r\n<<<\r\n", "output": "3\r\n"}, {"input": "3\r\n><<\r\n", "output": "0\r\n"}, {"input": "1\r\n<\r\n", "output": "1\r\...
false
stdio
null
true
725/A
725
A
Python 3
PRETESTS
6
62
614,400
21674659
import sys def main(): l = int(sys.stdin.readline().strip()) S = sys.stdin.readline().strip() if l < 1 or l > 200000: print('0') while S.find('><') >= 0: S = S.replace('><', '') print(len(S)) if __name__ == '__main__': main()
78
61
2,764,800
221562398
import sys input = sys.stdin.readline from collections import Counter, deque ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input()...
Canada Cup 2016
CF
2,016
2
256
Jumping Ball
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
null
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
[{"input": "4\n<<><", "output": "2"}, {"input": "5\n>>>>>", "output": "5"}, {"input": "4\n>><<", "output": "0"}]
1,000
["implementation"]
78
[{"input": "4\r\n<<><\r\n", "output": "2\r\n"}, {"input": "5\r\n>>>>>\r\n", "output": "5\r\n"}, {"input": "4\r\n>><<\r\n", "output": "0\r\n"}, {"input": "3\r\n<<>\r\n", "output": "3\r\n"}, {"input": "3\r\n<<<\r\n", "output": "3\r\n"}, {"input": "3\r\n><<\r\n", "output": "0\r\n"}, {"input": "1\r\n<\r\n", "output": "1\r\...
false
stdio
null
true
626/E
626
E
PyPy 3
TESTS
11
842
40,652,800
125788975
def findMean(prefSum, n, k, medianIdx, median): if k == 0: return median return (median + (prefSum[medianIdx] - prefSum[medianIdx-k]) + (prefSum[n] - prefSum[n - k])) / (2*k + 1) n = int(input()) nums = sorted(list(map(int, input().split()))) ans, bestK, bestMedianIdx = 0, 0, 0 prefSum = [0] for i in range(n...
94
1,637
54,988,800
125836088
''' Problem: Simple Skewness URL: https://codeforces.com/contest/626/problem/E Author : Ayush Modi Discord Tag : hot9cups#3125 ''' from fractions import Fraction # We need the fractions module because Python's inbuilt precision for floats isn't enough to solve the problem. # Fraction is roughtly Python's equivalent of...
8VC Venture Cup 2016 - Elimination Round
CF
2,016
3
256
Simple Skewness
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a colle...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.
In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.
null
In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3. In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed. In the last case, any subset has the same median and mean, so all have simple skewness of 0.
[{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}]
2,400
["binary search", "math", "ternary search"]
94
[{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = f.readlines() return [line.strip() for line in lines] def compute_skewness(subset): sorted_subset = sorted(subset) k = len(sorted_subset) if k == 0: return None total = sum(sorted_subset) mean = total / k ...
true
342/A
342
A
Python 3
TESTS
34
249
2,048,000
98096532
n = int(input()) arr = list(map(int, input().split())) track = [0] * 7 for i in arr: track[i - 1] += 1 if(track[6] != 0): print(-1) else: c1 = track[0] == (track[3] + track[5]) if(c1): _124 = track[3] track[1] -= _124 if(track[1] >= 0): #use remaining 2s on 126 ...
45
77
716,800
120879829
n = int(input()) // 3 s = input() c1, c2, c3, c4, c6 = [s.count(_) for _ in '12346'] if c1 != n or c2 < c4 or c1 != c2 + c3 or c1 != c4 + c6: print(-1) exit() print('1 2 4\n' * c4 + '1 3 6\n' * c3 + '1 2 6\n' * (n - c4 - c3))
Codeforces Round 199 (Div. 2)
CF
2,013
1
256
Xenia and Divisors
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held: - a < b < c; - a divides b, b divides c. Naturally, Xenia wants each el...
The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7. It is guaranteed that n is divisible by 3.
If the required partition exists, print $$\frac{\pi}{3}$$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them. If there is no solution,...
null
null
[{"input": "6\n1 1 1 2 2 2", "output": "-1"}, {"input": "6\n2 2 1 1 4 6", "output": "1 2 4\n1 2 6"}]
1,200
["greedy", "implementation"]
45
[{"input": "6\r\n1 1 1 2 2 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n2 2 1 1 4 6\r\n", "output": "1 2 4\r\n1 2 6\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n7 5 7\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "-1\r\n"}, {...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) numbers = list(map(int, f.readline().split())) counts = [0] * 8 for num in numbers: counts[num] += 1 w...
true
204/B
204
B
Python 3
TESTS
7
124
0
7749141
import math n = int(input()) front = dict() back = dict() for i in range(n): a, b = map(int,input().split()) if a in front: front[a] += 1 else: front[a] = 1 if b in back: back[b] += 1 else: back[b] = 1 ans = -1 m = dict() for key, value in front.items(): ...
90
1,528
34,304,000
229464742
n = int(input()) cards = {} for _ in range(n): a, b = map(int, input().split()) if a not in cards: cards[a] = [0, 0] cards[a][0] += 1 if a != b: if b not in cards: cards[b] = [0, 0] cards[b][1] += 1 result = 10**18 half = (n + 1) // 2 for a, b in cards.values(): ...
Codeforces Round 129 (Div. 1)
CF
2,012
2
256
Little Elephant and Cards
The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ...
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
null
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
[{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}]
1,500
["binary search", "data structures"]
90
[{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n...
false
stdio
null
true
245/E
245
E
Python 3
TESTS
18
218
6,656,000
80087760
s = input() c = 1 n = len(s) maxm = 1 l = 1 for i in range(1, n): if s[i] == s[i - 1]: l += 1 else: l = 1 if l > maxm: c += l - maxm maxm = l print(c)
30
92
0
206016205
s = input() MAX = 0 MIN = 0 pos = 0 for c in s: if c == '+': pos += 1 MAX = max(pos, MAX) else: pos -= 1 MIN = min(pos, MIN) result = MAX - MIN print(result)
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
245/E
245
E
Python 3
TESTS
18
154
0
108068577
mystr = input("") pos_seq = 0 neg_seq = 0 cur_pos_seq = 0 cur_neg_seq = 0 for s in mystr: if s == '+': cur_pos_seq += 1 cur_neg_seq = 0 pos_seq = max(pos_seq, cur_pos_seq) else: cur_neg_seq += 1 neg_seq = max(neg_seq, cur_neg_seq) cur_pos_seq = 0 print...
30
92
0
218836212
s = input() max_val = 0 cur_val = 0 max_current = 0 for char in s: if char == '+': cur_val += 1 if cur_val > max_current: max_current += 1 if char == '-': cur_val -= 1 if cur_val < 0: cur_val += 1 max_current += 1 print(max_current)# 1692036641...
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
245/E
245
E
Python 3
TESTS
18
124
716,800
182293036
from collections import defaultdict, deque, Counter from functools import lru_cache, reduce from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left from random import randint from fractions import Fraction as frac import math import operator import sys #sys.stdin = open("sleepy.in",...
30
93
102,400
3685951
m,p,c=0,0,0 s=(input()) for i in s: if i=='-': c-=1 else: c+=1 m=min(m,c) p=max(p,c) print (p-m)
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
592/D
592
D
PyPy 3-64
TESTS
2
529
66,150,400
223734956
from io import BytesIO, IOBase import math import random import sys import os import bisect import typing from collections import Counter, defaultdict, deque from copy import deepcopy from functools import cmp_to_key, lru_cache, reduce from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest fro...
89
1,170
29,081,600
54408091
from collections import deque n,m = [int(x) for x in input().split()] adj = [[] for x in range(n+1)] for _ in range(1,n): a,b = [int(x) for x in input().split()] adj[a].append(b) adj[b].append(a) chaos = [int(x) for x in input().split()] s = chaos[0] chaos = set(chaos) cc = [0]*(n+1) st = deque() st.append((s,-1)) w...
Codeforces Round 328 (Div. 2)
CF
2,015
2
256
Super M
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go ...
The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 123456) - the number of cities in Byteforces, and the number of cities being attacked respectively. Then follow n - 1 lines, describing the road system. Each line contains two city numbers ui and vi (1 ≤ ui, vi ≤ n) - the ends of the road i. The l...
First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number. Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons. Note that the correct answer is always unique.
null
In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are: $$2 \rightarrow 1 \rightarrow 3 \rightarrow 7$$ and $$7 \rightarrow 3 \rightarrow 1 \rightarrow 2$$. However, you should choose the first one as it starts in the city with the lower number.
[{"input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "output": "2\n3"}, {"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "output": "2\n4"}]
2,200
["dfs and similar", "dp", "graphs", "trees"]
89
[{"input": "7 2\r\n1 2\r\n1 3\r\n1 4\r\n3 5\r\n3 6\r\n3 7\r\n2 7\r\n", "output": "2\r\n3\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n4 6\r\n2 4 5 6\r\n", "output": "2\r\n4\r\n"}, {"input": "2 1\r\n2 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "10 2\r\n6 9\...
false
stdio
null
true
377/A
377
A
Python 3
TESTS
15
1,450
5,632,000
172811171
import sys from operator import * import itertools import heapq input=sys.stdin.readline if __name__ == '__main__': n,m,k=map(int,input().split()) grid=[] for _ in range(n): grid.append(list(input().strip())) nb=[[0]*m for _ in range(n)] for r,c in itertools.product(range(n),...
89
280
50,688,000
91446681
def dfs(mat, r, c, visited, limit): dfsStack = [(r,c)] while dfsStack and limit > 0: i, j = dfsStack.pop() if 0 <= i < len(mat) and 0 <= j < len(mat[i]) and mat[i][j] == "." and not visited[i][j]: mat[i][j] = "C" visited[i][j] = True limit -= 1 dfs...
Codeforces Round 222 (Div. 1)
CF
2,013
2
256
Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe t...
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
null
null
[{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}]
1,600
["dfs and similar"]
89
[{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.readlines() first_line = lines[0].strip().split() n, m, k = map(int, first_line[:3]) original = [line.strip() ...
true
1010/C
1010
C
Python 3
TESTS
18
93
6,963,200
161238929
import math n,k = [int(i) for i in input().split()] g = 0 for i in input().split(): g = math.gcd(g,int(i)%k) if(g==0): print(1) print(0) else: x = k//g A = [] for i in range(1,x+1): A.append((g*i)%k) A.sort() print(x) print(*A,sep=' ')
107
249
7,065,600
161239460
import math n,k = [int(i) for i in input().split()] g = 0 for i in input().split(): g = math.gcd(g,int(i)) x = g%k A = [0]*k while(A[x]==0): A[x] = 1 x = (x+g)%k B = [] for i in range(0,k): if(A[i]==1): B.append(i) print(len(B)) print(*B,sep=' ')
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Border
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are...
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban...
On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation.
null
Consider the first test case. It uses the octal number system. If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$. If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I...
[{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}]
1,800
["number theory"]
107
[{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ...
false
stdio
null
true
731/B
731
B
Python 3
TESTS
2
30
0
146280452
def evenOrOdd(n): if n == 0: return None elif n%2 == 0: return "EVEN" elif n%2 == 1: return "ODD" def isEmpty(a): if len(a) == 0: return True else: return False def lstSum(lst): sum = 0 for i in lst: sum += i return sum n = int(inpu...
79
156
17,817,600
21483389
N = int(input()) Ais = [ int(x) for x in input().split() ] odd = False stop = False for a in Ais: if a == 0 and odd == True: print("NO") stop = True break elif a%2 == 1: odd = not odd if not stop: if odd: print("NO") else: print("YES")
Codeforces Round 376 (Div. 2)
CF
2,016
1
256
Coupons and Discounts
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
null
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon n...
[{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}]
1,100
["constructive algorithms", "greedy"]
79
[{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu...
false
stdio
null
true
377/A
377
A
PyPy 3-64
TESTS
15
1,965
112,435,200
204373024
import sys input = lambda: sys.stdin.readline().rstrip() from heapq import * from collections import defaultdict N,M,K = map(int, input().split()) S = [] for _ in range(N): S.append([c for c in input()]) v = [] lib = defaultdict(int) for i in range(N): for j in range(M): if S[i][j]=='#':continue ...
89
296
15,155,200
97016307
from collections import deque n , m , k = map(int,input().split()) grid = [[None for i in range(m)] for j in range(n) ] visited = [[False for i in range(m)] for i in range(n)] total , cnt = 0 , 0 start = 0 moveX = [-1, 1, 0, 0] moveY = [0, 0, 1, -1] for i in range(n): s = list(input()) for j in range(m): ...
Codeforces Round 222 (Div. 1)
CF
2,013
2
256
Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe t...
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
null
null
[{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}]
1,600
["dfs and similar"]
89
[{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.readlines() first_line = lines[0].strip().split() n, m, k = map(int, first_line[:3]) original = [line.strip() ...
true
377/A
377
A
Python 3
TESTS
15
1,638
54,784,000
208062159
import heapq n, m, k = [int(x) for x in input().split()] grid = [list(input()) for _ in range(n)] di = [0,0,-1,1] dj = [1,-1,0,0] deg = [[0]*m for _ in range(n)] for i in range(n): for j in range(m): if grid[i][j] != '.': continue for kk in range(4): x = i + di[kk] ...
89
311
37,273,600
172900355
from collections import deque m, n, k = map(int, input().split()) graph = [] for _ in range(m): graph.append([x for x in input()]) if k == 0: for x in graph: print("".join(x)) else: count = 0 for i in range(m): for j in range(n): if graph[i][j] == ".": count +...
Codeforces Round 222 (Div. 1)
CF
2,013
2
256
Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe t...
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
null
null
[{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}]
1,600
["dfs and similar"]
89
[{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.readlines() first_line = lines[0].strip().split() n, m, k = map(int, first_line[:3]) original = [line.strip() ...
true
793/C
793
C
Python 3
PRETESTS
6
61
5,529,600
26620237
import sys class Line: def __init__(self, x1, y1, x2, y2): self.a = y2 - y1 self.b = x1 - x2 self.c = y1*x2 - x1*y2 def y(self, x): if self.b == 0: return float('inf') else: return (-self.a*x - self.c)/self.b def x(self, y): if self.a == 0: return float('inf') else: return (-self.b*y - ...
80
966
5,529,600
26624097
import math n = int(input()) x1, y1, x2, y2 = map(int, input().split()) t1 = 0 t2 = math.inf yes = True for i in range(n): x, y, vx, vy = map(int, input().split()) if vx == 0: if x <= x1 or x >= x2: yes = False break else: tt1 = (x1-x)/vx tt2 = (x2-x)/vx tt1, tt2 = min(tt1, tt2), max...
Tinkoff Challenge - Elimination Round
CF
2,017
2
256
Mice problem
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i...
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≤ x1 ≤ x2 ≤ 100 000), (0 ≤ y1 ≤ y2 ≤ 100 000) — the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mic...
In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formall...
null
Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. Then, at first time when all mice will be in rectangle it will be looks like this: Here is a picture of the second sample Points A, D, B will never enter rectangle.
[{"input": "4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "output": "0.57142857142857139685"}, {"input": "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10", "output": "-1"}]
2,300
["geometry", "implementation", "math", "sortings"]
80
[{"input": "4\r\n7 7 9 8\r\n3 5 7 5\r\n7 5 2 4\r\n3 3 7 8\r\n6 6 3 2\r\n", "output": "0.57142857142857139685\r\n"}, {"input": "4\r\n7 7 9 8\r\n0 3 -5 4\r\n5 0 5 4\r\n9 9 -1 -6\r\n10 5 -7 -10\r\n", "output": "-1\r\n"}, {"input": "4\r\n8 42 60 54\r\n9 54 -58 -62\r\n46 47 52 -76\r\n15 50 -37 -40\r\n54 51 78 64\r\n", "outp...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == '-1': print(1 if sub_line == '-1' else 0) return ...
true
841/B
841
B
Python 3
TESTS
55
1,029
83,558,400
31550343
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys """ created by shhuan at 2017/10/21 12:16 """ N = int(input()) A = [int(x) for x in input().split()] S = sum(A) if S%2 != 0: print("First") else: if A[0] % 2 ==1 or A[-1...
88
374
56,934,400
29700970
def main(): n, l = int(input()), [ord(s[-1]) & 1 for s in input().split()] s = sum(l) & 1 print(("Second", "First")[s or not s and any(l)]) if __name__ == '__main__': main()
Codeforces Round 429 (Div. 2)
CF
2,017
2
256
Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
null
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
[{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}]
1,100
["games", "math"]
88
[{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0...
false
stdio
null
true
464/A
464
A
Python 3
TESTS
19
62
0
7988435
n, p = map(int, input().split()) def f(t, k): a, b = min(t[k - 1], 2), min(t[k], 2) if a == b: a = 1 return [3 - a - b, a, b] def g(t, k): j = t[k] for i in range(j + 1, p): if i != t[k - 1] and i != t[k - 2]: t[k] = i return f(t, k) return None def h(t): t...
73
62
6,963,200
115775526
def nextt(s): return chr(ord(s) + 1) n,k = map(int,input().split()) s = [i for i in input()] i = n-1 s[i] = nextt(s[i]) while(i >= 0 and i < n): if(ord(s[i]) >= 97 + k): s[i] = "a" i-=1 s[i] = nextt(s[i]) elif(i > 0 and s[i] == s[i-1] or i>1 and s[i] == s[i-2]): s[i] = nextt(...
Codeforces Round 265 (Div. 1)
CF
2,014
1
256
No to Palindromes!
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
null
String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti, si + 1 > ti + 1. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string...
[{"input": "3 3\ncba", "output": "NO"}, {"input": "3 4\ncba", "output": "cbd"}, {"input": "4 4\nabcd", "output": "abda"}]
1,700
["greedy", "strings"]
73
[{"input": "3 3\r\ncba\r\n", "output": "NO\r\n"}, {"input": "3 4\r\ncba\r\n", "output": "cbd\r\n"}, {"input": "4 4\r\nabcd\r\n", "output": "abda\r\n"}, {"input": "2 2\r\nab\r\n", "output": "ba\r\n"}, {"input": "2 2\r\nba\r\n", "output": "NO\r\n"}, {"input": "1 2\r\na\r\n", "output": "b\r\n"}, {"input": "1 2\r\nb\r\n", ...
false
stdio
null
true
186/A
186
A
PyPy 3-64
TESTS
39
124
2,150,400
181380921
s1 = input() s2 = input() set1 = set() set2 = set() cnt = 0 for c1, c2 in zip(s1, s2): if c1 != c2: cnt += 1 set1.add(c1) set2.add(c2) if cnt != 2: print("NO") else: if len(set1.intersection(set2)) == 2: print("YES") else: print("NO")
53
92
716,800
167922559
# Comparing Strings # ------------------------------------------------ def solve(d1, d2): n = len(d1) if len(d2) != n: return "NO" if len(d1) == 1: return "NO" if d1 == d2: if len(set(d1)) < len(d1): return "YES" else: return "NO" fir...
Codeforces Round 118 (Div. 2)
CF
2,012
2
256
Comparing Strings
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
null
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
[{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}]
1,100
["implementation", "strings"]
53
[{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm...
false
stdio
null
true
796/C
796
C
Python 3
TESTS
3
77
921,600
30812118
import queue n=int(input()) a=list(map(int,input().split())) g=[[]for i in range(n)] for i in range(n-1): u,v=map(int,input().split()) u-=1 v-=1 g[u].append(v) g[v].append(u) used=[False for i in range(n)] q=queue.Queue() def increase(v): used[v]=True for i in g[v]: q.put(i) ...
129
1,528
189,337,600
215811933
from bisect import bisect_left, bisect_right from collections import Counter, deque from functools import lru_cache from math import factorial, comb, sqrt, gcd, lcm, log2 from copy import deepcopy import heapq import random from types import GeneratorType from sys import stdin, stdout def bootstrap(f, stack=[]): ...
Codeforces Round 408 (Div. 2)
CF
2,017
2
256
Bank Hacking
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the banks. Al...
The first line contains one integer n (1 ≤ n ≤ 3·105) — the total number of banks. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the strengths of the banks. Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — meaning that there is a wire directly connec...
Print one integer — the minimum strength of the computer Inzane needs to accomplish the goal.
null
In the first sample, Inzane can hack all banks using a computer with strength 5. Here is how: - Initially, strengths of the banks are [1, 2, 3, 4, 5]. - He hacks bank 5, then strengths of the banks become [1, 2, 4, 5,  - ]. - He hacks bank 4, then strengths of the banks become [1, 3, 5,  - ,  - ]. - He hacks bank 3, t...
[{"input": "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5", "output": "5"}, {"input": "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6", "output": "93"}, {"input": "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4", "output": "8"}]
1,900
["constructive algorithms", "data structures", "dp", "trees"]
129
[{"input": "5\r\n1 2 3 4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n", "output": "5"}, {"input": "7\r\n38 -29 87 93 39 28 -55\r\n1 2\r\n2 5\r\n3 2\r\n2 4\r\n1 7\r\n7 6\r\n", "output": "93"}, {"input": "5\r\n1 2 7 6 7\r\n1 5\r\n5 3\r\n3 4\r\n2 4\r\n", "output": "8"}, {"input": "3\r\n2 2 2\r\n3 2\r\n1 2\r\n", "output": "3"}, {"inp...
false
stdio
null
true
613/A
613
A
Python 3
TESTS
2
46
0
15395334
def main(): n, a, b = map(int, input().split()) res = [] for _ in range(n): x, y = map(int, input().split()) x -= a y -= b res.append(x * x + y * y) print((max(res) - min(res)) * 3.141592653589793) if __name__ == '__main__': main()
60
826
9,625,600
15370992
import math def get_dist(x1, y1, x2, y2, x, y): L = (x1 - x2) ** 2 + (y1 - y2) ** 2 PR = (x - x1) * (x2 - x1) + (y - y1) * (y2 - y1) res = True cf = PR / L if(cf < 0): cf = 0 res = False if(cf > 1): cf = 1 res = False xres = x1 + cf * (x2 - x1) yres = y1 + cf * (y2 - y1) return xres ** 2 + yres ...
Codeforces Round 339 (Div. 1)
CF
2,016
2
256
Peter and Snow Blower
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ...
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac...
null
In the first sample snow will be removed from that area:
[{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}]
1,900
["binary search", "geometry", "ternary search"]
60
[{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() try: b = float(ref_line) except: print(0) return with open(submission_path, 'r') as f: ...
true
613/A
613
A
Python 3
TESTS
2
46
0
15466950
def sq_dist(a,b): dx = a[0] - b[0] dy = a[1] - b[1] return dx**2 + dy**2 n,*p = map(int,input().split()) coords = [[int(j) for j in input().split()] for _ in range(n)] max_dist = max(sq_dist(vertex, p) for vertex in coords) sq_rad = sq_dist(coords[0], p) from math import pi pri...
60
826
10,240,000
15761211
import math def main(): (n, xp, yp) = (int(x) for x in input().split()) polygon = [None] * n for i in range(n): (xi, yi) = (int(x) for x in input().split()) polygon[i] = (xi, yi) print(solver((xp, yp), polygon)) def solver(P, polygon): n = len(polygon) (xp, yp) = P distances = [distance(xp, yp, x, y) for (...
Codeforces Round 339 (Div. 1)
CF
2,016
2
256
Peter and Snow Blower
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ...
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac...
null
In the first sample snow will be removed from that area:
[{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}]
1,900
["binary search", "geometry", "ternary search"]
60
[{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() try: b = float(ref_line) except: print(0) return with open(submission_path, 'r') as f: ...
true
436/A
436
A
PyPy 3-64
TESTS
7
186
5,632,000
203610135
import sys input = lambda: sys.stdin.readline().rstrip() from heapq import * N,X = map(int, input().split()) def check(a1,a2,x): ans = 0 d1,d2=[],[] while True: while a1 and a1[-1][0]<=x: heappush(d1, -a1.pop()[1]) if not d1: break else: ...
60
93
819,200
10550801
import queue n,maxh=[int(x) for x in input().split()] car=[] fru=[] hcar=queue.PriorityQueue(2000) hfru=queue.PriorityQueue(2000) for i in range(n): a,b,c=[int(x) for x in input().split()] if a==0: car.append((b,c)) else: fru.append((b,c)) pcar=0 mcar=len(car) pfru=0 mfru=len(fru) car.sort() fru.sort() eaten=0 d...
Zepto Code Rush 2014
CF
2,014
2
256
Feed with Candy
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ...
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu...
Print a single integer — the maximum number of candies Om Nom can eat.
null
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7....
[{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}]
1,500
["greedy"]
60
[{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
38
46
0
229970295
n,m=map(int,input().split()) new_str="" for i in range(n): my_str=input() new_str += my_str a=new_str.split() x=set(a) if 'C' in x or 'M' in x or 'Y' in x: print("#Color") else: print("#Black&White")
50
31
0
162170633
[n, m] = map(int, input().split()) for i in range(n): row = list(input()) if (('C' in row or ('M' in row ) or 'Y' in row)): color = True print ('#Color') quit() print ('#Black&White')
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
14/B
14
B
Python 3
TESTS
10
124
307,200
110573107
import sys import math class DictList(dict): def __setitem__(self, key, value): try: # Assumes there is a list on the key self[key].append(value) except KeyError: # If it fails, because there is no key super(DictList, self).__setitem__(key, value) except A...
52
92
0
206730336
# LUOGU_RID: 110960101 from sys import stdin input = stdin.readline def get() : return map(int,input().split()) n,x = get() lst = [] for i in range(n) : a,b = get() if a > b : a, b = b, a lst.append((a,b)) lst.sort() S, E = lst[0] for i in range(1, n) : s, e = lst[i] if s > E : ...
Codeforces Beta Round 14 (Div. 2)
ICPC
2,010
2
64
Young Photographer
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha...
The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
null
null
[{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}]
1,000
["implementation"]
52
[{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out...
false
stdio
null
true
219/A
219
A
PyPy 3
TESTS
15
186
0
220843143
k=int(input()) s1=input() s=list(s1) s.sort() lis=[] i=0 o=1 while i < len(s)-1: if s[i]==s[i+1]: o+=1 if s[i]!= s[i+1] or i+2 == len(s): lis.append(o) o=1 i+=1 li=set(s) lis2=list(li) lis2.sort() answer="" i=0 flag=True while i < len(lis): if lis[i] %k == 0 : answer+=lis...
42
62
0
147567266
k=int(input()) s=input() d={} ans="" for i in "abcdefghijklmnopqrstuvwxyz": d[i]=0 for i in s: d[i]+=1 for i in d: if d[i]%k!=0: print(-1) break else: for i in d: if d[i]: ans+=i*(d[i]//k) for i in range(k): print(ans,end="")
Codeforces Round 135 (Div. 2)
CF
2,012
2
256
k-String
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
null
null
[{"input": "2\naazz", "output": "azaz"}, {"input": "3\nabcabcabz", "output": "-1"}]
1,000
["implementation", "strings"]
42
[{"input": "2\r\naazz\r\n", "output": "azaz\r\n"}, {"input": "3\r\nabcabcabz\r\n", "output": "-1\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "2\r\nabba\r\n", "output": "abab\r\n"}, {"input": "2\r\naaab\r\n", "output": "-1\r\n"}, {"input": "7\r\nabacaba\r\n", "output": "-1\r\n"}, {"input": "5\r\naaaaa\r...
false
stdio
null
true
524/B
524
B
Python 3
TESTS
6
77
4,608,000
16988578
n = int(input()) hs = [] ws = [] for i in range(n): w, h = map(int, input().split()) hs.append(h) ws.append(w) ans = float('inf') for H in range(1, 1000): wr = 0 pos = True for j in range(n): a = min(hs[j], ws[j]) b = max(hs[j], ws[j]) if b <= H: wr += a ...
60
499
0
10382178
a = [] heights = [] wid = 0 hei = 0 heim = 1000 n = int(input()) for i in range(n): w, h = map(int, input().split()) if (w > h): x = w w = h h = x wid += w if (hei < h): hei = h if (heim > w): heim = w a.append((h, w)) last = wid * hei for i in range(heim,...
VK Cup 2015 - Round 1
CF
2,015
2
256
Фото на память - 2 (round version)
Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке. Упрощенно процесс фотографирования можно ...
В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей. В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей.
Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей.
null
null
[{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}]
1,700
["dp", "greedy"]
60
[{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "10\r\n168 538\r\n836 439\r\n190 873\r\n206 47\r\n891 591\r\n939 481\r\n399 898\r\n859 466\r\n701 777\r\n629 222\r\n", "output": "34780...
false
stdio
null
true
186/A
186
A
Python 3
TESTS
39
248
512,000
64458984
a = input() b = input() d,flag = 0,0 temp = 0 result = a == b for i in range(min(len(a),len(b))): if a[i] != b[i]: if (d == 0 and flag == 0): d += 1 temp = i flag = 1 elif (d == 1 ): if (b[i] == a[temp] and b[temp] == a[i]): result...
53
92
2,048,000
149681207
gen1 = input() gen2 = input() if len(gen1) != len(gen2): print("NO") quit() index=[] for i in range(len(gen1)): if gen1[i] != gen2[i]: index.append(i) if len(index) != 2: print("NO") else: if (gen1[index[0]]==gen2[index[1]] and gen1[index[1]]==gen2[index[0]]): print("YES") el...
Codeforces Round 118 (Div. 2)
CF
2,012
2
256
Comparing Strings
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
null
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
[{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}]
1,100
["implementation", "strings"]
53
[{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm...
false
stdio
null
true
186/A
186
A
Python 3
TESTS
39
310
10,035,200
222054344
a=input() b=input() i=0 k=[] while i<min(len(a),len(b)) : if a[i]!=b[i] : k.append([a[i],b[i]]) i+=1 if len(k)==2 : if k[1][0]==k[0][1] and k[0][0]==k[1][1] : print("YES") else : print("NO") else : print("NO")
53
92
5,324,800
206617860
#Keshika Patwari #Indian Institute Of Technology, Jodhpur # # 2022 # import sys # input=sys.stdin.readline def exe(): x=len(a) y=len(b) #print('dhjd') if(x!=y): #print('dhjd2') return 'NO' else: l=[] #print('dhjd3') for i in range(x): if(a[i]!=b[i...
Codeforces Round 118 (Div. 2)
CF
2,012
2
256
Comparing Strings
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
null
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
[{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}]
1,100
["implementation", "strings"]
53
[{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm...
false
stdio
null
true
788/C
788
C
Python 3
TESTS
41
530
44,851,200
98022236
from collections import deque MAX_A = 1000 def main(): n, k = map(int, input().split()) a = set(int(x) - n for x in input().split()) visited = [False] * (2 * n + 1) visited[n] = True Q = deque() Q.append((n, 0)) result = None while Q: u, l = Q.popleft() ...
48
467
44,851,200
98107843
from collections import deque n, k = map(int, input().split()) conc = set(int(x) - n for x in input().split()) q = deque() q.append(0) visited = {i : False for i in range(-1000, 1001)} dist = {i : 0 for i in range(-1000, 1001)} ans = -1 visited[0] = True found = False while q: u = q.popleft() ...
Codeforces Round 407 (Div. 1)
CF
2,017
1
256
The Great Mixing
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration $${ \frac { a _ { i } } { 1 0 0 0 } }$$. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentrati...
The first line contains two integers n, k (0 ≤ n ≤ 1000, 1 ≤ k ≤ 106) — carbon dioxide concentration the friends want and the number of Coke types. The second line contains k integers a1, a2, ..., ak (0 ≤ ai ≤ 1000) — carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.
Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration $$\frac{n}{1000}$$, or -1 if it is impossible.
null
In the first sample case, we can achieve concentration $$\frac{400}{1000}$$ using one liter of Coke of types $$\frac{300}{1000}$$ and $${ \frac { 5 0 0 } { 1 0 0 0 } }$$: $$\frac{300+500}{1000+1000}=\frac{400}{1000}$$. In the second case, we can achieve concentration $${ \frac { 5 0 } { 1 0 0 0 } }$$ using two liters ...
[{"input": "400 4\n100 300 450 500", "output": "2"}, {"input": "50 2\n100 25", "output": "3"}]
2,300
["dfs and similar", "graphs", "shortest paths"]
48
[{"input": "400 4\r\n100 300 450 500\r\n", "output": "2\r\n"}, {"input": "50 2\r\n100 25\r\n", "output": "3\r\n"}, {"input": "500 3\r\n1000 5 5\r\n", "output": "199\r\n"}, {"input": "500 1\r\n1000\r\n", "output": "-1\r\n"}, {"input": "874 3\r\n873 974 875\r\n", "output": "2\r\n"}, {"input": "999 2\r\n1 1000\r\n", "outp...
false
stdio
null
true
342/A
342
A
PyPy 3
TESTS
33
202
9,830,400
222145955
n=int(input()) s=list(map(int,input().split())) s.sort() d=set(s) d=list(d) o=n//3 v=0 for i in d : if i == 1 or i == 2 or i==3 or i==6 : v+=1 if v == 3 or v == 4 : a=[] b=[] c=[] for i in s : if i == 1 : a.append(i) elif i == 2 or i == 3 : b.append(i...
45
77
921,600
166214977
n = int(input())//3 st = input() c1,c2,c3,c4,c6 = [st.count(s) for s in '12346'] if c1!=n or c1!=c2+c3 or c1!=c4+c6 or c2<c4 or c3>c6: print(-1) else: print('1 2 4\n'*c4 + '1 2 6\n' * (n - c3 - c4) + '1 3 6\n'*c3)
Codeforces Round 199 (Div. 2)
CF
2,013
1
256
Xenia and Divisors
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held: - a < b < c; - a divides b, b divides c. Naturally, Xenia wants each el...
The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7. It is guaranteed that n is divisible by 3.
If the required partition exists, print $$\frac{\pi}{3}$$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them. If there is no solution,...
null
null
[{"input": "6\n1 1 1 2 2 2", "output": "-1"}, {"input": "6\n2 2 1 1 4 6", "output": "1 2 4\n1 2 6"}]
1,200
["greedy", "implementation"]
45
[{"input": "6\r\n1 1 1 2 2 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n2 2 1 1 4 6\r\n", "output": "1 2 4\r\n1 2 6\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n7 5 7\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "-1\r\n"}, {...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) numbers = list(map(int, f.readline().split())) counts = [0] * 8 for num in numbers: counts[num] += 1 w...
true
342/A
342
A
Python 3
TESTS
33
202
1,638,400
108163544
n=int(input()) arr=list(map(int,input().split())) s1=set(arr) if 5 in arr or 7 in arr or len(s1)<3: print(-1) else: res=dict() flag=False third=0 for i in range(1,7): res[i]=arr.count(i) # for i in s1: # res[i]=arr.count(i) if (res[2]>0 or res[6]>0) and (res[2]-res[4]==res[6...
45
77
1,024,000
9361976
def main(): n = int(input()) s = input() c1, c2, c3, c4, c6 = [s.count(_) for _ in '12346'] if c1 * 3 != n or c2 < c4 or c1 != c2 + c3 or c1 != c4 + c6: print(-1) return res = ['1 2 4'] * c1 for i in range(c4, c2): res[i] = '1 2 6' for i in range(c2, c1): res[...
Codeforces Round 199 (Div. 2)
CF
2,013
1
256
Xenia and Divisors
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held: - a < b < c; - a divides b, b divides c. Naturally, Xenia wants each el...
The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7. It is guaranteed that n is divisible by 3.
If the required partition exists, print $$\frac{\pi}{3}$$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them. If there is no solution,...
null
null
[{"input": "6\n1 1 1 2 2 2", "output": "-1"}, {"input": "6\n2 2 1 1 4 6", "output": "1 2 4\n1 2 6"}]
1,200
["greedy", "implementation"]
45
[{"input": "6\r\n1 1 1 2 2 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n2 2 1 1 4 6\r\n", "output": "1 2 4\r\n1 2 6\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n7 5 7\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "-1\r\n"}, {...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) numbers = list(map(int, f.readline().split())) counts = [0] * 8 for num in numbers: counts[num] += 1 w...
true
436/A
436
A
Python 3
TESTS
53
701
512,000
6877799
# -*- coding: utf-8 -*- import sys f = sys.stdin #f = open('H:\\Portable Python 3.2.5.1\\test_248B1.txt') n, x = map(int, f.readline().strip().split()) kon = [] kon0 = [] kon1 = [] for i in range(n): ti, hi, mi = map(int, f.readline().strip().split()) kon.append([ti,hi,mi]) if ti==0 : kon0.append(...
60
93
3,379,200
174772807
import sys input = sys.stdin.readline def f(q, w, h): c = 0 d = [0]*len(q) e = [0]*len(w) while 1: oc = -1 op = -1 for i in range(len(q)): if q[i][0] <= h: if d[i] == 0: if q[i][1] > oc: oc = q[i][1] ...
Zepto Code Rush 2014
CF
2,014
2
256
Feed with Candy
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ...
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu...
Print a single integer — the maximum number of candies Om Nom can eat.
null
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7....
[{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}]
1,500
["greedy"]
60
[{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\...
false
stdio
null
true
436/A
436
A
PyPy 3
TESTS
7
171
3,584,000
206014637
def cut(n, m, take, t, height, mass): ans = 0 for i in range(n): mx = 0 ind = -1 for j in range(n): if take == t[j] and height[j] <= m: if mx <= mass[j]: mx = mass[j] ind = j if ind == -1: break ...
60
109
0
6886406
from bisect import bisect_left n, x = map(int, input().split()) s, a, b = 0, [[], []], [[], []] for i in range(n): t, h, m = map(int, input().split()) a[t].append((h, m)) for t in [0, 1]: a[t].sort(key = lambda x: x[0]) for h, m in a[t]: if h > x: break b[t].append(m) b[t].sort() for...
Zepto Code Rush 2014
CF
2,014
2
256
Feed with Candy
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ...
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu...
Print a single integer — the maximum number of candies Om Nom can eat.
null
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7....
[{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}]
1,500
["greedy"]
60
[{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\...
false
stdio
null
true
436/A
436
A
Python 3
TESTS
7
62
4,915,200
25154933
n, x = map(int, input().split()) class Candy: t = 0 h = 0 m = 0 candy0 = [] candy1 = [] for i in range(n): candy = Candy() candy.t, candy.h, candy.m = map(int, input().split()) if candy.t == 0: candy0.append(candy) else: candy1.append(candy) def sortfn(item): return item.m def getnext(items): ...
60
140
3,481,600
145865950
from sys import stdin def solve(t): vis0, vis1 = [False] * len(a0), [False] * len(a1) ans, cur = 0, jmp while True: if t == 0: for i, (h, m) in enumerate(a0): if h <= cur and not vis0[i]: cur += m vis0[i], ans = True, ans + 1 ...
Zepto Code Rush 2014
CF
2,014
2
256
Feed with Candy
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ...
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu...
Print a single integer — the maximum number of candies Om Nom can eat.
null
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7....
[{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}]
1,500
["greedy"]
60
[{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\...
false
stdio
null
true
436/A
436
A
PyPy 3
TESTS
7
218
24,166,400
86651868
n,height=map(int,input().split()) caramel=[];frut=[];h=height for i in range(n): x,y,z = map(int,input().split()) if x==0: caramel.append([y,z]) else: frut.append([y,z]) caramel.sort() frut.sort() ans=f2=0;f1=1 a1=0 while a1<len(caramel) and (f1 or f2): a1+=1 if f1 : cm=f1=fl...
60
202
0
179535956
import sys def solve(t): vis0, vis1 = [False] * len(a0), [False] * len(a1) ans, cur = 0, jmp while True: if t == 0: for i, (h, m) in enumerate(a0): if h <= cur and not vis0[i]: cur += m vis0[i], ans = True, ans + 1 ...
Zepto Code Rush 2014
CF
2,014
2
256
Feed with Candy
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ...
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu...
Print a single integer — the maximum number of candies Om Nom can eat.
null
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7....
[{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}]
1,500
["greedy"]
60
[{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\...
false
stdio
null
true
219/A
219
A
PyPy 3-64
TESTS
13
124
512,000
155178683
k=int(input()) s=sorted(input().lower()) count={} for i in s: if i not in count: count[i]=s.count(i) for i in count.values(): if i % k !=0: answer=-1 else: answer=("".join(s[::k]*k)) print(answer)
42
62
0
148265677
x=int(input()) str= input() dic={} for i in str: if i in dic.keys(): dic.update({i:dic.get(i)+1}) else: dic.update({i:1}) a=0 u="" for i in dic.values(): if (i/x).is_integer(): a+=1 continue else: print(-1) break if a==len(dic.values()): for i in dic.k...
Codeforces Round 135 (Div. 2)
CF
2,012
2
256
k-String
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
null
null
[{"input": "2\naazz", "output": "azaz"}, {"input": "3\nabcabcabz", "output": "-1"}]
1,000
["implementation", "strings"]
42
[{"input": "2\r\naazz\r\n", "output": "azaz\r\n"}, {"input": "3\r\nabcabcabz\r\n", "output": "-1\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "2\r\nabba\r\n", "output": "abab\r\n"}, {"input": "2\r\naaab\r\n", "output": "-1\r\n"}, {"input": "7\r\nabacaba\r\n", "output": "-1\r\n"}, {"input": "5\r\naaaaa\r...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
13
62
4,915,200
28619513
n, k = map(int, input().split()) l = sorted([int(x) for x in input().split()]) ans = 0 for i in range(len(l)): if 2 * k >= l[i]: k = max(k, l[i]) else: while 2 * k < l[i]: ans += 1 k *= 2 print(ans)
61
62
0
200855610
def solve(v, skills): skills.sort() ans=0 tmp = 2*v for i in skills: while i > tmp: ans+=1 tmp*=2 tmp = max(tmp, i*2) return ans n,v=map(int,input().split()) skills=list(map(int,input().split())) print(solve(v,skills))
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
13
62
5,632,000
34469285
from math import ceil, log n, k = map(int, input().split()) a = sorted([int(x) for x in input().split()]) ans = 0 for i in a: if i > 2*k: ans += ceil(log(i/2/k, 2)) k *= 2**(ceil(log(i/2/k, 2))) elif i > k: k = i print(ans)
61
62
0
217158640
#Jasnah n,k=map(int,input().split()) a=list(map(int,input().split())) a=sorted(a) temp=0 for i in range(len(a)): if 2*k>=a[i]: if k<a[i]: k=a[i] else: while 2*k<a[i]: temp+=1 k=2*k if k<a[i]: k=a[i] print(temp)
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
908/B
908
B
PyPy 3
TESTS
11
140
0
60336487
n, m = map(int, input().split()) a = [['0'] * (m + 2)] for i in range(n): a.append(['0'] + list(input()) + ['0']) a.append(['0'] * (m + 2)) s = input() x, y = -1, -1 for i in range(n): for j in range(m): if a[i][j] == 'S': x, y = i, j k = 0 for u in range(4): for d in range(4): i...
46
46
4,505,600
161725366
from itertools import permutations n,m=(int(c)for c in input().split()) s='#'*(m+2) for i in range(n):s+='#'+input().strip()+'#' s+='#'*(m+2) ins=['0123'.find(c)for c in input().strip()] c=0 for d in permutations([1,-1,m+2,-m-2]): p=s.find('S') for i in ins: p+=d[i] if s[p]=='E':c+=1 if s[p]in'E#':break print(c...
Good Bye 2017
CF
2,017
1
256
New Year and Buggy Bot
Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex...
The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze. The next n lines will contain exactly m characters each, denoting the maze. Each character of the maze will be '.', '#', 'S', or 'E'. There will be exactly one 'S' and exactly one 'E' in the maze. The las...
Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.
null
For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right.
[{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}]
1,200
["brute force", "implementation"]
46
[{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
245/E
245
E
Python 3
TESTS
10
187
5,222,400
3771557
import math import re from fractions import Fraction from collections import Counter class Task: signs = '' answer = 0 def __init__(self): self.signs = input() def solve(self): counter = 0 maxDifference = 0 for x in self.signs: counter += 1 if x == '+' ...
30
122
0
13907610
inp=input() inclb=0 outclb=0 seen=0 i=0 for i in range(0,len(inp)): if inp[i] == "-": outclb += 1 if inclb > 0: inclb -= 1 else: seen += 1 else: inclb += 1 if outclb > 0: outclb -= 1 else: seen += 1 print(seen)
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
245/E
245
E
PyPy 3-64
TESTS
10
124
28,364,800
132597483
s=input() n=0 ans=0 for c in s: n+=int(c+'1') ans=max(ans,abs(n)) print(ans)
30
122
0
167716984
import sys input = sys.stdin.readline s = [1 if i == '+' else -1 for i in input()[:-1]] c = 0 d = 0 c1 = 0 d1 = 0 for i, j in enumerate(s): if d <= 0: d = j else: d += j if d > c: c = d if d1 >= 0: d1 = j else: d1 += j if d1 < c1: c1 = d1 pri...
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
14/B
14
B
PyPy 3
TESTS
11
310
0
118015268
n, x0 = map(int, input().split()) left = 0 right = 1000 for i in range(n): a, b = sorted(map(int, input().split())) left = max(left, a) right = min(right, b) if left <= right: if x0 < a: print(a - x0) elif x0 > b: print(x0 - b) else: print(0) else: print(-1)
52
92
0
214682752
n, x0 = [int(x) for x in input().split()] pts = [0] * 1005 for i in range(n): a, b = [int(x) for x in input().split()] if a > b: a, b = b, a for x in range(a, b+1): pts[x] += 1 x1 = 10000 for x in range(1001): if pts[x] == n and abs(x-x0) < abs(x1-x0): x1 = x if x1 == 10000: print(-1) else: prin...
Codeforces Beta Round 14 (Div. 2)
ICPC
2,010
2
64
Young Photographer
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha...
The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
null
null
[{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}]
1,000
["implementation"]
52
[{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out...
false
stdio
null
true
245/E
245
E
Python 3
TESTS
10
124
0
14563248
c, v = 0, 0 for ch in input(): c += 1 if ch == '+' else -1 v = max(v, abs(c)) print(v)
30
124
0
10341189
def puts(s): print(s, end='') s = input() a = mi = ma = 0 for c in s: if(c == '+'): a = a + 1 ma = max(ma, a) else: a = a - 1 mi = min(mi, a) print(ma - mi)
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
465/B
465
B
Python 3
TESTS
29
46
0
196801938
n = int(input()) j = map(int, input().split()) x = 0 l1 = [] for i in j: l1.append(i) if n == 1: if l1[0] == 1: x = 1 else: for i in range(n - 1): if l1[i] == 1: x += 1 l1[i] = 0 if l1.count(1) > 0: if l1[i + 1] == 0: x ...
44
46
0
7717111
from itertools import * input() print(max(0, sum(len(list(g)) + 1 for r, g in groupby(map(int, input().split())) if r == 1) - 1))
Codeforces Round 265 (Div. 2)
CF
2,014
1
256
Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
null
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already...
[{"input": "5\n0 1 0 1 0", "output": "3"}, {"input": "5\n1 1 0 0 1", "output": "4"}, {"input": "2\n0 0", "output": "0"}]
1,000
["implementation"]
44
[{"input": "5\r\n0 1 0 1 0\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 0 0 1\r\n", "output": "4\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "9\r\n1 0 1 0 1 0 1 0 1\r\n", "output": "9\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "14\r\n0 0 1 1 1 0 1 1 1 0 1 1 1 0\r\n", "outpu...
false
stdio
null
true
454/B
454
B
Python 3
TESTS
32
155
7,680,000
99765072
a=int(input()) arr=list(map(int,input().split())) minn=min(arr) maxx=max(arr) k=-1 for i in range(0,len(arr)-1): if(arr[i]==maxx and arr[i+1]==minn): k=i break if(arr[len(arr)-1]==maxx and arr[0]==minn): k=0 if(k==-1): print(-1) else: bef=arr[:k+1] af=arr[k+1:] if(sorted(arr)==...
56
77
15,667,200
199739356
n=int(input()) a=list(map(int, input().split())) b=sorted(a) if a==b: print(0) else: for i in range(1, n): if a[i] < a[i-1]: if a[i:]==b[:n-i]: a[i:]==b[:n-i] print(len(a[i:])) else: print(-1) break
Codeforces Round 259 (Div. 2)
CF
2,014
1
256
Little Pony and Sort by Shift
One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an 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: a1, a2, ..., an → an, a1, a2, ..., an - 1. Help Twi...
The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
null
null
[{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 3 2", "output": "-1"}, {"input": "2\n1 2", "output": "0"}]
1,200
["implementation"]
56
[{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "6\r\n3 4 5 6 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 4 5 4...
false
stdio
null
true
251/B
251
B
PyPy 3
TESTS
13
280
0
52487763
def perest(p,q): tmp=[] for i in q: tmp.append(p[i-1]) return tmp def obperest(p,q): tmp=dict() for i in range(n): tmp[q[i]-1]=p[i] tt=[] for i in range(n): tt.append(tmp[i]) return tt n,k=map(int,input().split()) p=[i for i in range(1,n+1)] q=[int(i) for i in in...
95
218
307,200
51283438
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n, k = mints() q = list(mints()) for i in range(n): q[i] -= 1 s = list(mints()) a = [i for i in range(1,n+1)] d = [0]*n b = [False]*(k+1) c = [False]*(k+1) e ...
Codeforces Round 153 (Div. 1)
CF
2,012
2
256
Playing with Permutations
Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n. A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha....
The first line contains two integers n and k (1 ≤ n, k ≤ 100). The second line contains n space-separated integers q1, q2, ..., qn (1 ≤ qi ≤ n) — the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format. It is guaranteed that the given sequences q and s are co...
If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).
null
In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed. In the second sample the described situation is possible, ...
[{"input": "4 1\n2 3 4 1\n1 2 3 4", "output": "NO"}, {"input": "4 1\n4 3 1 2\n3 4 2 1", "output": "YES"}, {"input": "4 3\n4 3 1 2\n3 4 2 1", "output": "YES"}, {"input": "4 2\n4 3 1 2\n2 1 4 3", "output": "YES"}, {"input": "4 1\n4 3 1 2\n2 1 4 3", "output": "NO"}]
1,800
["implementation", "math"]
95
[{"input": "4 1\r\n2 3 4 1\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "4 1\r\n4 3 1 2\r\n3 4 2 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n4 3 1 2\r\n3 4 2 1\r\n", "output": "YES\r\n"}, {"input": "4 2\r\n4 3 1 2\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n4 3 1 2\r\n2 1 4 3\r\n", "output": "NO\r\n...
false
stdio
null
true
229/A
229
A
PyPy 3-64
TESTS
33
590
23,449,600
139548118
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = [input().strip() for i in range(n)] l = [[-1] * m for i in range(n)] r = [[-1] * m for i in range(n)] for i in range(n): for j in range(m): l[i][j] = (0 if a[i][j] == '1' else l[i][j - 1] + 1 if l[i][j - 1] != -1 else -1) for j ...
59
280
12,800,000
181409125
import heapq import operator as op import sys from bisect import bisect_left as b_l from bisect import bisect_right as b_r from collections import defaultdict, deque from functools import reduce from math import ceil, factorial, gcd, sqrt INT_MAX = sys.maxsize-1 INT_MIN = -sys.maxsize def ncr(n,r): r=min(n,n-r) nmt...
Codeforces Round 142 (Div. 1)
CF
2,012
2
256
Shifts
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. To cyclically shift a table row one cell to the right means to move the valu...
The first line contains two space-separated integers: n (1 ≤ n ≤ 100) — the number of rows in the table and m (1 ≤ m ≤ 104) — the number of columns in the table. Then n lines follow, each of them contains m characters "0" or "1": the j-th character of the i-th line describes the contents of the cell in the i-th row and...
Print a single number: the minimum number of moves needed to get only numbers 1 in some column of the table. If this is impossible, print -1.
null
In the first sample one way to achieve the goal with the least number of moves is as follows: cyclically shift the second row to the right once, then shift the third row to the left twice. Then the table column before the last one will contain only 1s. In the second sample one can't shift the rows to get a column cont...
[{"input": "3 6\n101010\n000100\n100000", "output": "3"}, {"input": "2 3\n111\n000", "output": "-1"}]
1,500
["brute force", "two pointers"]
59
[{"input": "3 6\r\n101010\r\n000100\r\n100000\r\n", "output": "3\r\n"}, {"input": "2 3\r\n111\r\n000\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1\r\n1\r\n0\r\n", "output": "-1\r\n"}, {"input": "6 2\r\n10\r\n11\r\n01\r\n01\r\n...
false
stdio
null
true
721/B
721
B
Python 3
TESTS
13
109
307,200
67762039
n,k=map(int,input().split()) l1=[] for i in range(n): s=input() l1.append(s) same=0 kam=0 pswd=input() if(n==1): print(1,1) exit(0) for i in l1: if(len(i)==len(pswd)): same+=1 if(len(i)<len(pswd)): kam+=1 if(k!=1): t=0 r=kam%k if(kam>k): t=(kam//k)*5 ...
66
46
0
171639917
n, k = map(int, input().split()) # if n == k: # ans2 = k # elif n // k == 0: # ans2 = n # else: # fator = (n // k) if k != 1 else n - 1 # ans2 = (fator * 5) + n # print(ans2) array = [] for i in range(n): array.append(input()) cont1, cont2 = [0,0] # i = 0 password = input() # print(array) for ...
Codeforces Round 374 (Div. 2)
CF
2,016
2
256
Passwords
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar...
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a...
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
null
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente...
[{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}]
1,100
["implementation", "math", "sortings", "strings"]
66
[{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu...
false
stdio
null
true
369/A
369
A
PyPy 3
TESTS
38
140
0
76926041
n,m,k=list(map(int,input().split())) t=list(map(int,input().split())) if 2 not in t: r=sum(t) if m>=r: print(0) else: print(r-m) elif 1 not in t: if m+k >= n: print(0) else: print(m+k-n) else: a=t.count(1) b=t.count(2) p=0 if m>= a: k+= m-...
63
46
0
132412565
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) st = a.count(1) nd = a.count(2) if st > m: ans = st - m ans += max(0, nd - k) else: ans = max(0, nd - (k + m - st)) print(ans)
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
405/B
405
B
PyPy 3-64
TESTS
6
62
0
209219632
# https://codeforces.com/contest/405 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n = int(input()) s = input() x = [(idx, c) for idx, c in enumerate(s, 1) if c != "."] lx = len(x) if not x: print(n) exit() ans = 0 for i, (idx, c) in enumerate(x): if i == 0 and c == "R": ...
61
62
1,638,400
223221227
n=int(input()) s=input() c=0 m,l,r=0,-1,-1 for i in range(n): if c==0: if s[i]=='R': m+=i c=1 r=i elif s[i]=='L': c=1 l=i elif r>-1 and s[i]=='L': if (i-r)%2==0: m+=1 r=-1 l=i elif l>-1 and s[i]==...
Codeforces Round 238 (Div. 2)
CF
2,014
1
256
Domino Effect
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes...
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to - "L", if the i-th domino has been pushed to the left; - "R", if the i-th domino has been pushed to the right; - "....
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
null
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
[{"input": "14\n.L.R...LR..L..", "output": "4"}, {"input": "5\nR....", "output": "0"}, {"input": "1\n.", "output": "1"}]
1,100
[]
61
[{"input": "14\r\n.L.R...LR..L..\r\n", "output": "4\r\n"}, {"input": "5\r\nR....\r\n", "output": "0\r\n"}, {"input": "1\r\n.\r\n", "output": "1\r\n"}, {"input": "1\r\nL\r\n", "output": "0\r\n"}, {"input": "1\r\nR\r\n", "output": "0\r\n"}, {"input": "2\r\nL.\r\n", "output": "1\r\n"}, {"input": "2\r\nRL\r\n", "output": "...
false
stdio
null
true
54/A
54
A
PyPy 3
TESTS
3
310
0
94639019
a,b=map(int,input().split()) z=list(map(int,input().split()[1:])) ans=a for i in range(1,b): k=0;p=z.copy() for j in range(i,a+1,b): if j in p:p.remove(j) k+=1 k+=len(p) ans=min(ans,k) print(ans)
65
92
0
209123620
def findNext(cursor: int, k: int, holidays: list) -> int: i = cursor + 1 while i < cursor + k: if i in holidays: return i i += 1 return i n, k = [int(item) for item in input().split(' ')] holidays = [int(item) for item in input().split(' ')] del holidays[0] ans, cursor = 0,...
Codeforces Beta Round 50
CF
2,011
2
256
Presents
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating ...
Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.
null
null
[{"input": "5 2\n1 3", "output": "3"}, {"input": "10 1\n3 6 7 8", "output": "10"}]
1,300
["implementation"]
65
[{"input": "5 2\r\n1 3\r\n", "output": "3"}, {"input": "10 1\r\n3 6 7 8\r\n", "output": "10"}, {"input": "5 5\r\n1 3\r\n", "output": "1"}, {"input": "10 3\r\n3 3 6 9\r\n", "output": "3"}, {"input": "5 2\r\n0\r\n", "output": "2"}, {"input": "1 1\r\n0\r\n", "output": "1"}, {"input": "5 1\r\n0\r\n", "output": "5"}, {"inpu...
false
stdio
null
true
245/E
245
E
Python 3
TESTS
10
124
307,200
4890821
p = [1 if i == '+' else -1 for i in input()] for i in range(1, len(p)): p[i] += p[i - 1] print(max(abs(i) for i in p))
30
124
0
14563275
c, v1, v2 = 0, 0, 0 for ch in input(): c += 1 if ch == '+' else -1 v1, v2 = min(v1, c), max(v2, c) print(v2 - v1)
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
245/E
245
E
PyPy 3
TESTS
10
186
0
195999877
a=input() b=0 l=[] for i in range(len(a)): if a[i]=="+": b=b+1 else: b=b-1 l.append(b) m=abs(max(l)) n=abs(min(l)) print(max(m,n))
30
124
0
108452289
#Problem Set N: Collaborated with no one n = input() in_visit = 0 out_visit = 0 for i in range(len(n)): if n[i] == '+': in_visit += 1 if out_visit: out_visit -= 1 elif n[i] == '-': out_visit += 1 if in_visit: in_visit -= 1 print(in_vis...
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
219/A
219
A
PyPy 3-64
TESTS
13
154
0
221857511
n=int(input()) s=list(input()) uni=set(s) lst=[] ans="" flag=0 for i in uni: val=s.count(i) if(val<n): flag=1 break ans+=((val//n)*i) if(flag==1): print(-1) else: ans=list(ans) ans.sort() ans="".join(ans) print(ans*n)
42
62
0
159702418
n,s = int(input()),input() d={} for i in s: if i in d: d[i]+=1 else: d[i]=1 res='' flag=1 for i in d: if d[i]%n!=0: flag=0 break else: res+=i*(d[i]//n) if flag: print(res*n) else: print(-1)
Codeforces Round 135 (Div. 2)
CF
2,012
2
256
k-String
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
null
null
[{"input": "2\naazz", "output": "azaz"}, {"input": "3\nabcabcabz", "output": "-1"}]
1,000
["implementation", "strings"]
42
[{"input": "2\r\naazz\r\n", "output": "azaz\r\n"}, {"input": "3\r\nabcabcabz\r\n", "output": "-1\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "2\r\nabba\r\n", "output": "abab\r\n"}, {"input": "2\r\naaab\r\n", "output": "-1\r\n"}, {"input": "7\r\nabacaba\r\n", "output": "-1\r\n"}, {"input": "5\r\naaaaa\r...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
13
61
4,915,200
28609400
def ginp(): return map(int, input().split()) n, k = ginp() p = sorted(list(ginp())) level = k ans = 0 for i in p: if 2*level >= i: level = max(level, i) else: while 2*level < i: level *= 2 ans +=1 print(ans)
61
62
307,200
29717609
import math def calc(a,b): x=0 while(a<b): a=a*2 x+=1 return x n,k=input().split() n,k=int(n),int(k) a=list(map(int,input().split())) a.sort() ans=0 for i in range(0,n): if(a[i]<=2*k): k=max(k,a[i]) elif(a[i]>2*k): ans+=calc(k,math.ceil(a[i]/2)) k=a[i] print(a...
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
405/B
405
B
PyPy 3-64
TESTS
8
108
2,867,200
223478138
from re import findall def count_dot(string): counter = 0 for item in string: if item != 'x' and item =='.': counter += 1 return counter def modify_string(string, omittion): for item in omittion: string = string.replace(item, '', 1) return string def find_RL(string:str)...
61
62
4,608,000
19687171
n = int(input()) s = input() l = 0 r = 0 last = None l_pos = 0 r_pos = 0 ans = 0 for i in range(len(s)): if s[i] == "R" and l ==0: ans += i r = 1 r_pos = i elif s[i] == "L" and r == 0: l_pos = i l = 1 elif s[i] == "R" and l==1: ans += i - l_po...
Codeforces Round 238 (Div. 2)
CF
2,014
1
256
Domino Effect
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes...
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to - "L", if the i-th domino has been pushed to the left; - "R", if the i-th domino has been pushed to the right; - "....
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
null
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
[{"input": "14\n.L.R...LR..L..", "output": "4"}, {"input": "5\nR....", "output": "0"}, {"input": "1\n.", "output": "1"}]
1,100
[]
61
[{"input": "14\r\n.L.R...LR..L..\r\n", "output": "4\r\n"}, {"input": "5\r\nR....\r\n", "output": "0\r\n"}, {"input": "1\r\n.\r\n", "output": "1\r\n"}, {"input": "1\r\nL\r\n", "output": "0\r\n"}, {"input": "1\r\nR\r\n", "output": "0\r\n"}, {"input": "2\r\nL.\r\n", "output": "1\r\n"}, {"input": "2\r\nRL\r\n", "output": "...
false
stdio
null
true
524/C
524
C
Python 3
PRETESTS
2
686
14,438,400
10383463
#!/usr/bin/env python # coding: utf-8 n, k = map(int, input().split()) a = list(map(int, input().split())) q = int(input()) cache = {(ai, j): (1, {ai}) for ai in a for j in range(1, k)} def f(_x, _k): if not _x: return 0, set() if (_x, _k) in cache: return cache[_x, _k] if not _k: ...
129
358
11,878,400
231037855
f = lambda: map(int, input().split()) n, k = f() t = list(f()) d = {0: 0} for q in t: for i in range(1, k + 1): d[q * i] = i for j in range(int(input())): a = int(input()) p = [i + d[a - b] for b, i in d.items() if a - b in d] print(min(p) if p and min(p) <= k else -1)
VK Cup 2015 - Round 1
CF
2,015
2
256
The Art of Dealing with ATM
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20). The next line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order. The next line contains integer q (1 ≤ q ≤ 20) — the number of req...
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
null
null
[{"input": "6 20\n10 50 100 500 1000 5000\n8\n4200\n100000\n95000\n96000\n99000\n10100\n2015\n9950", "output": "6\n20\n19\n20\n-1\n3\n-1\n-1"}, {"input": "5 2\n1 2 3 5 8\n8\n1\n3\n5\n7\n9\n11\n13\n15", "output": "1\n1\n1\n2\n2\n2\n2\n-1"}]
1,900
["binary search", "sortings"]
129
[{"input": "6 20\r\n10 50 100 500 1000 5000\r\n8\r\n4200\r\n100000\r\n95000\r\n96000\r\n99000\r\n10100\r\n2015\r\n9950\r\n", "output": "6\r\n20\r\n19\r\n20\r\n-1\r\n3\r\n-1\r\n-1\r\n"}, {"input": "5 2\r\n1 2 3 5 8\r\n8\r\n1\r\n3\r\n5\r\n7\r\n9\r\n11\r\n13\r\n15\r\n", "output": "1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n-1\r\n...
false
stdio
null
true
731/B
731
B
PyPy 3
TESTS
3
61
0
136069940
n = int(input()) a = list((map(int, input().split()))) for i in range(n): if a[i] != 0: a[i] = a[i] % 2 else: a[i] = -1 print("YES" if sum(a) % 2 == 0 else "NO")
79
171
11,878,400
197502515
I=input I() a=0 for x in map(int,I().split()): x-=a;a=x%2 if x<0:break print('YNEOS'[a::2])
Codeforces Round 376 (Div. 2)
CF
2,016
1
256
Coupons and Discounts
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
null
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon n...
[{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}]
1,100
["constructive algorithms", "greedy"]
79
[{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
13
62
0
114663505
n,k=[int(x) for x in input().split(' ')] a=[int(x) for x in input().split(' ')] a.sort() curr=k b=[] i=0 while(i<n): if(a[i]<=2*curr): b.append(a[i]) curr=max(curr,a[i]) else: while(a[i]>2*curr): curr *= 2 b.append(curr) b.append(a[i]) i+=1 print(len(b)-len(a))
61
62
307,200
30887320
s = input().split(' ') n = int(s[0]) k = int(s[1]) s = input().split(' ') arr = [] for a in s: arr.append(int(a)) arr.sort() tot = 0 for i in range(0, n): while 2 * k < arr[i]: k *= 2 tot+=1 k = max(k, arr[i]) print(tot)
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
730/J
730
J
PyPy 3
TESTS
34
1,606
134,553,600
117166928
import sys input = sys.stdin.buffer.readline n = int(input()) soda = list(map(int, input().split())) volume = list(map(int, input().split())) dp = [[{} for j in range(n + 1)] for k in range(n + 1)] dp[0][1][volume[0] - soda[0]] = 0 total = soda[0] for i in range(0, n - 1): total += soda[i + 1] for bottle in r...
99
93
5,427,200
212305769
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = sum(a) dp = [(0,0)] + [(-10**18,0) for _ in range(s)] for i in range(n): for j in range(s + b[i], b[i]-1, -1): dp[min(j,s)] = max(dp[min(j,s)], (dp[j-b[i]][0]-1, dp[j-b[i]][1]+a[i])) print(-dp[s][0], s - dp[s][1]...
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,016
2
512
Bottles
Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi). Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda...
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of bottles. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the amount of soda remaining in the i-th bottle. The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the volume...
The only line should contain two integers k and t, where k is the minimal number of bottles that can store all the soda and t is the minimal time to pour the soda into k bottles.
null
In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It wi...
[{"input": "4\n3 3 4 3\n4 7 6 5", "output": "2 6"}, {"input": "2\n1 1\n100 100", "output": "1 1"}, {"input": "5\n10 30 5 6 24\n10 41 7 8 24", "output": "3 11"}]
1,900
["dp"]
99
[{"input": "4\r\n3 3 4 3\r\n4 7 6 5\r\n", "output": "2 6\r\n"}, {"input": "2\r\n1 1\r\n100 100\r\n", "output": "1 1\r\n"}, {"input": "5\r\n10 30 5 6 24\r\n10 41 7 8 24\r\n", "output": "3 11\r\n"}, {"input": "1\r\n1\r\n100\r\n", "output": "1 0\r\n"}, {"input": "1\r\n100\r\n100\r\n", "output": "1 0\r\n"}, {"input": "1\r\...
false
stdio
null
true
730/H
730
H
Python 3
TESTS
26
62
307,200
22197296
from sys import stdin, stdout n, m = map(int, stdin.readline().split()) length = [] strings = [] for i in range(n): f = stdin.readline().strip() strings.append(f) length.append(len(f)) s = [] challenger = [] delet = set() for a in list(map(int, stdin.readline().split())): delet.add(a - 1) if not s ...
74
62
0
21703959
n, m = map(int,input().split()) w = [input() for _ in range(n)] todel = [w[i-1] for i in map(int, input().split())] if len(set(map(len,todel))) != 1: print('No') else: pat = ''.join(['?' if len(set([todel[j][p] for j in range(m)])) != 1 else todel[0][p] for p in range(len(todel[0]))]) ok = True for x in...
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,016
2
512
Delete Them
Polycarp is a beginner programmer. He is studying how to use a command line. Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte...
The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted. The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len...
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them. If the required pattern doesn't exist, print the only line containing "No".
null
null
[{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}]
1,300
["constructive algorithms", "implementation"]
74
[{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"...
false
stdio
null
true
876/B
876
B
Python 3
TESTS
12
186
19,251,200
31390909
n, k, m = input().split() n, k, m = int(n), int(k), int(m) arr = list(map(int, input().split())) d = {k:[] for k in range(m)} for item in arr: d[item%m].append(item) poss = False for val in d.values(): if len(val) >= k: poss = True print('Yes') print(' '.join(list(map(str, val[:k]))))...
63
109
20,377,600
223657843
from sys import exit n,k,m=[int(e) for e in input().split()] a=[int(e) for e in input().split()] b=[[] for i in range(m)] for e in a: b[e%m].append(e) for e in b: if len(e)>=k: print("Yes") print(*e[:k]) exit() print("No")
Codeforces Round 441 (Div. 2, by Moscow Team Olympiad)
CF
2,017
1
512
Divisiblity of Differences
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in mu...
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
null
null
[{"input": "3 2 3\n1 8 4", "output": "Yes\n1 4"}, {"input": "3 3 3\n1 8 4", "output": "No"}, {"input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7"}]
1,300
["implementation", "math", "number theory"]
63
[{"input": "3 2 3\r\n1 8 4\r\n", "output": "Yes\r\n1 4 "}, {"input": "3 3 3\r\n1 8 4\r\n", "output": "No"}, {"input": "4 3 5\r\n2 7 7 7\r\n", "output": "Yes\r\n2 7 7 "}, {"input": "9 9 5\r\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825\r\n", "output": "Yes\r\n389149775 8331279...
false
stdio
null
true
876/B
876
B
Python 3
TESTS
12
155
11,776,000
31392810
from collections import defaultdict as dis n,k,m=map(int,input().split()) l=list(map(int,input().split())) d=dis(list) for i in l: d[i%m].append(i) x=[] for i in d: if len(d[i])>=k: x+=d[i][:k] if x: print("Yes"," ".join(map(str,x)),sep='\n') else: print("No")
63
124
16,076,800
207427774
# from math import gcd # from queue import Queue # from collections import deque # from collections import Counter n,k,m=map(int,input().split()) l=list(map(int,input().split())) rem=[0 for _ in range(m)] for i in range(n): rem[l[i]%m]+=1 req=0 if max(rem)<k: print('No') else: req=rem.index(max(rem)) a...
Codeforces Round 441 (Div. 2, by Moscow Team Olympiad)
CF
2,017
1
512
Divisiblity of Differences
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in mu...
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
null
null
[{"input": "3 2 3\n1 8 4", "output": "Yes\n1 4"}, {"input": "3 3 3\n1 8 4", "output": "No"}, {"input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7"}]
1,300
["implementation", "math", "number theory"]
63
[{"input": "3 2 3\r\n1 8 4\r\n", "output": "Yes\r\n1 4 "}, {"input": "3 3 3\r\n1 8 4\r\n", "output": "No"}, {"input": "4 3 5\r\n2 7 7 7\r\n", "output": "Yes\r\n2 7 7 "}, {"input": "9 9 5\r\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825\r\n", "output": "Yes\r\n389149775 8331279...
false
stdio
null
true
830/A
830
A
Python 3
TESTS
16
732
307,200
73994702
def time_person(per_pos, k, fixed_dist): return abs(per_pos - k) + fixed_dist def time_total(persons, keys, office): test = True min_person = min(persons) max_person = max(persons) if office > max_person : for k in keys: if k >= min_person : test = False ...
59
124
22,835,200
167749707
def read(): def get_numbers(): try: read.s = input().split() read.s_len = len(read.s) if read.s_len == 0: get_numbers() read.cnt = 0 return 1 except: return 0 if not hasattr(read, 'cnt'): if not get_n...
Codeforces Round 424 (Div. 1, rated, based on VK Cup Finals)
CF
2,017
2
256
Office Keys
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 the mi...
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 a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arb...
Print the minimum time (in seconds) needed for all n to reach the office with keys.
null
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...
[{"input": "2 4 50\n20 100\n60 10 40 80", "output": "50"}, {"input": "1 2 10\n11\n15 7", "output": "7"}]
1,800
["binary search", "brute force", "dp", "greedy", "sortings"]
59
[{"input": "2 4 50\r\n20 100\r\n60 10 40 80\r\n", "output": "50\r\n"}, {"input": "1 2 10\r\n11\r\n15 7\r\n", "output": "7\r\n"}, {"input": "2 5 15\r\n10 4\r\n29 23 21 22 26\r\n", "output": "23\r\n"}, {"input": "3 10 1500\r\n106 160 129\r\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163\r\n", "output": "1394\r\n"}, {"...
false
stdio
null
true
740/B
740
B
Python 3
TESTS
13
62
0
22442072
import sys # sys.stdin = open('/home/doktorkrab/work/python/input.txt') def sumOnSub(l, r): sm = 0 for i in range(l, r + 1): sm += arr[i] * used[i] + arr[i] return sm n, m = map(int, input().split()) arr = list(map(int, input().split())) query = [] for i in range(m): query.append(tuple(map(l...
53
46
0
141933564
n,comb = map(int,input().split()) nums = list(map(int,input().split())) res = 0 for _ in range(comb): start,end = map(int,input().split()) temp_sum = 0 for i in range(start-1,end): temp_sum += nums[i] if temp_sum > 0: res += temp_sum print(res)
Codeforces Round 381 (Div. 2)
CF
2,016
2
256
Alyona and flowers
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa...
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100). The next m lines contain the description of the subarrays suggested by the mother. The...
Print single integer — the maximum possible value added to the Alyona's happiness.
null
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
[{"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7"}, {"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16"}, {"input": "2 2\n-1 -2\n1 1\n1 2", "output": "0"}]
1,200
["constructive algorithms"]
53
[{"input": "5 4\r\n1 -2 1 3 -4\r\n1 2\r\n4 5\r\n3 4\r\n1 4\r\n", "output": "7\r\n"}, {"input": "4 3\r\n1 2 3 4\r\n1 3\r\n2 4\r\n1 1\r\n", "output": "16\r\n"}, {"input": "2 2\r\n-1 -2\r\n1 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 6\r\n1 1 1 -1 0\r\n2 4\r\n1 3\r\n4 5\r\n1 5\r\n1 4\r\n4 5\r\n", "output": "8\r\n"}, ...
false
stdio
null
true
230/A
230
A
PyPy 3-64
TESTS
9
186
1,740,800
228508136
s,n = map(int,input().split()) x = [] y = [] for i in range(n): xi, yi = map(int,input().split()) x.append(xi) y.append(yi) x1 = [] y1 = [] for i in range(n): x1.append(x[i]) y1.append(y[i]) x1.sort() for i in range(n-1): index = x.index(x1[i]) y1[i], y1[index] = y1[index], y1[i] f...
54
92
0
228189568
s, n = list(map(int, input().split())) cnt = 0 l = [] for i in range(n): x, y = list(map(int, input().split())) a = (x, y) l.append(a) l.sort() for i in range(n): if s > l[i][0]: s += l[i][1] cnt += 1 if s <= l[i][0]: print("NO") break if cnt == n: print("...
Codeforces Round 142 (Div. 2)
CF
2,012
2
256
Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
null
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
[{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}]
1,000
["greedy", "sortings"]
54
[{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},...
false
stdio
null
true
230/A
230
A
PyPy 3-64
TESTS
9
186
2,867,200
228104783
def merge(li, l1, gi, l2): i,j = 0,0 arr = [] while i<l1 and j<l2: if li[i][0] > gi[j][0]: arr.append([gi[j][0], gi[j][1]]) j += 1 else: arr.append([li[i][0],li[i][1]]) i+=1 while i<l1: arr.append([li[i][0],li[i][1]]) i+=1 while j<l2: arr.append([gi[j][0], gi[j][1]]...
54
92
0
228988840
s, n = map(int, input().split()) dragons = [] for _ in range(n): x, y = map(int, input().split()) dragons.append((x, y)) dragons.sort() # Sort dragons based on their strength for dragon in dragons: if s > dragon[0]: s += dragon[1] else: print("NO") exit(0) print("YES")
Codeforces Round 142 (Div. 2)
CF
2,012
2
256
Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
null
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
[{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}]
1,000
["greedy", "sortings"]
54
[{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},...
false
stdio
null
true
666/A
666
A
Python 3
TESTS
32
155
819,200
45742790
s = input() if len(s) <= 5: print(0) else: words = set() s = s[5:] r = len(s) if r == 4: words.add(s[1:]) if s[:2] != s[2:]: words.add(s[2:]) words.add(s[:2]) if r == 2 or r == 3: words.add(s) s = s[::-1] if r > 4: dp2 = [0 for...
48
77
2,764,800
173021131
Q,s=print,input();sx,d,z=[(len(s),0)],set(),set() while sx: i,j=sx.pop();r=i+j for j in (2,3): l=i-j;k=(l,j) if k not in d and l>=5 and s[l:i]!=s[i:r]: z.add(s[l:i]);d.add(k);sx+=[k] Q(len(z)),Q('\n'.join(sorted(z)))
Codeforces Round 349 (Div. 1)
CF
2,016
1
256
Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know li...
The only line contains a string s (5 ≤ |s| ≤ 104) consisting of lowercase English letters.
On the first line print integer k — a number of distinct possible suffixes. On the next k lines print suffixes. Print suffixes in lexicographical (alphabetical) order.
null
The first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
[{"input": "abacabaca", "output": "3\naca\nba\nca"}, {"input": "abaca", "output": "0"}]
1,800
["dp", "implementation", "strings"]
48
[{"input": "abacabaca\r\n", "output": "3\r\naca\r\nba\r\nca\r\n"}, {"input": "abaca\r\n", "output": "0\r\n"}, {"input": "gzqgchv\r\n", "output": "1\r\nhv\r\n"}, {"input": "iosdwvzerqfi\r\n", "output": "9\r\ner\r\nerq\r\nfi\r\nqfi\r\nrq\r\nvz\r\nvze\r\nze\r\nzer\r\n"}, {"input": "oawtxikrpvfuzugjweki\r\n", "output": "25...
false
stdio
null
true
740/B
740
B
Python 3
TESTS
11
31
0
215845968
# 1<= n,m <= 100 # -100 <= ai <= 100 def solve(n,m,arr,subarr): # mood of ith flower is ai. # If we get negative as ans then print 0 # Cuz we can always choose none. # Choose subarrays with sum>=0 # That's all hm = set() for l,r in subarr : hm.add((l-1,r-1)) ans = 0 for st in range(n): tsum ...
53
46
0
152925944
n,m=[int(x) for x in input().split()] mood= [int(x) for x in input().split()] total_hp=0 for i in range(m): l,r =[int(x) for x in input().split()] sum1=0 for j in range(l-1,r): sum1+=mood[j] if sum1>0: total_hp+=sum1 print(total_hp)
Codeforces Round 381 (Div. 2)
CF
2,016
2
256
Alyona and flowers
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa...
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100). The next m lines contain the description of the subarrays suggested by the mother. The...
Print single integer — the maximum possible value added to the Alyona's happiness.
null
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
[{"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7"}, {"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16"}, {"input": "2 2\n-1 -2\n1 1\n1 2", "output": "0"}]
1,200
["constructive algorithms"]
53
[{"input": "5 4\r\n1 -2 1 3 -4\r\n1 2\r\n4 5\r\n3 4\r\n1 4\r\n", "output": "7\r\n"}, {"input": "4 3\r\n1 2 3 4\r\n1 3\r\n2 4\r\n1 1\r\n", "output": "16\r\n"}, {"input": "2 2\r\n-1 -2\r\n1 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 6\r\n1 1 1 -1 0\r\n2 4\r\n1 3\r\n4 5\r\n1 5\r\n1 4\r\n4 5\r\n", "output": "8\r\n"}, ...
false
stdio
null
true
756/A
756
A
PyPy 3
TESTS
1
124
0
74143048
n = int(input()) p = [int(i) for i in input().split()] zeros = [int(i) for i in input().split()] ans = 0 visited = [False for i in range(n)] ciclos = 0 for i in range(n): if not visited[i]: ciclos += 1 j = i while not visited[j]: visited[j] = True j = p[j] - 1 if ciclos == 1: ...
87
296
41,881,600
34189350
n = int(input()) p = [int(i) for i in input().split()] b = [int(i) for i in input().split()] ans = 0 visited = [False for i in range(n)] for i in range(n): if visited[i]: continue ans += 1 while not visited[i]: visited[i] = True i = p[i] - 1 if ans == 1: ans = 0 ans += (sum(b) + ...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
256
Pavel and barbecue
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction. Pavel has a plan: a permutation p and a sequence b1, b2, ...
The first line contain the integer n (1 ≤ n ≤ 2·105) — the number of skewers. The second line contains a sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation, according to which Pavel wants to move the skewers. The third line contains a sequence b1, b2, ..., bn consisting of zeros and ones, according t...
Print single integer — the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements.
null
In the first example Pavel can change the permutation to 4, 3, 1, 2. In the second example Pavel can change any element of b to 1.
[{"input": "4\n4 3 2 1\n0 1 1 1", "output": "2"}, {"input": "3\n2 3 1\n0 0 0", "output": "1"}]
1,700
["constructive algorithms", "dfs and similar"]
87
[{"input": "4\r\n4 3 2 1\r\n0 1 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n0\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n0 0\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n0 1\r\n", "output": "2\...
false
stdio
null
true
247/A
250
A
PyPy 3
TESTS
15
216
0
103899266
n = int(input()) a = list(map(int, input().split())) ans = [] i = 0 tmp = 0 k = 0 while i < len(a): if k == 2 or i == len(a) - 1: k = 0 if i == len(a) - 1: tmp += 1 ans.append(tmp) tmp = 0 if a[i] >= 0: tmp += 1 if a[i] < 0: tmp += 1 k += 1...
69
92
0
158752206
n = int(input()) a = list(map(int, input().split())) f = [] cur = 0 f.append(0) curr = 0 for i in a: if i < 0: curr += 1 if curr >= 3: curr = 1 f.append(1) cur += 1 continue else: f[cur] += 1 else: f[cur] += 1 print(len(...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Paper Work
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n...
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them.
null
Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.
[{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}]
1,000
[]
69
[{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) return n, a def compute_min_k(n, a): if n == 0: return 0 folders = 0 current_neg = 0 current_size = 0 for ai in a: current_s...
true
465/B
465
B
Python 3
TESTS
20
108
307,200
76972343
n=int(input()) arr = list(map(int,input().split(" "))) count=0 zerocount=0 for i in range(len(arr)): if(arr[i]==1): count+=1 elif(arr[i]==0 and arr[i-1]!=0): count+=1 elif(arr[i]==0): zerocount+=1 if(arr[n-1]==0 and zerocount!=n): count-=1 print(count)
44
46
0
11232355
n = int(input().strip()) a = list(map(int, input().split())) pitem = 0 count = 0 for item in a: if pitem != 0 or item != 0: count += 1 pitem = item if a[-1] == 0: count -= 1 print(max(0,count))
Codeforces Round 265 (Div. 2)
CF
2,014
1
256
Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
null
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already...
[{"input": "5\n0 1 0 1 0", "output": "3"}, {"input": "5\n1 1 0 0 1", "output": "4"}, {"input": "2\n0 0", "output": "0"}]
1,000
["implementation"]
44
[{"input": "5\r\n0 1 0 1 0\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 0 0 1\r\n", "output": "4\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "9\r\n1 0 1 0 1 0 1 0 1\r\n", "output": "9\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "14\r\n0 0 1 1 1 0 1 1 1 0 1 1 1 0\r\n", "outpu...
false
stdio
null
true
796/B
796
B
Python 3
TESTS
19
1,715
61,952,000
27156835
n, m, k = (int(x) for x in input().split()) holes = [int(x) for x in input().split()] operations = [] is_hole = [False] * (n + 1) curr_pos_in_holes = 0 for curr_cup in range(1, n + 1): if curr_pos_in_holes > m - 1: break elif holes[curr_pos_in_holes] == curr_cup: is_hole[curr_cup] = True ...
73
451
132,915,200
205383951
from sys import stdin n, m, k = map(int, stdin.readline().split()) holes = set(map(int, stdin.readline().split())) current_bone_position = 1 for _ in range(k): if current_bone_position in holes: print(current_bone_position) exit() cup1, cup2 = map(int, stdin.readline().split()) if cup1 ==...
Codeforces Round 408 (Div. 2)
CF
2,017
2
256
Find The Bone
Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i. The problematic bone is initially at the position x = 1. Zane will confuse the audience b...
The first line contains three integers n, m, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there ...
Print one integer — the final position along the x-axis of the bone.
null
In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively. In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.
[{"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "output": "1"}, {"input": "5 1 2\n2\n1 2\n2 4", "output": "2"}]
1,300
["implementation"]
73
[{"input": "7 3 4\r\n3 4 6\r\n1 2\r\n2 5\r\n5 7\r\n7 1\r\n", "output": "1"}, {"input": "5 1 2\r\n2\r\n1 2\r\n2 4\r\n", "output": "2"}, {"input": "10000 1 9\r\n55\r\n44 1\r\n2929 9292\r\n9999 9998\r\n44 55\r\n49 94\r\n55 53\r\n100 199\r\n55 50\r\n53 11\r\n", "output": "55"}, {"input": "100000 3 7\r\n2 3 4\r\n1 5\r\n5 1\...
false
stdio
null
true
747/D
747
D
PyPy 3-64
TESTS
42
311
29,491,200
157784778
import math import random import os,sys,io from collections import defaultdict,deque from heapq import heapify,heappop,heappush import bisect from collections import Counter import collections from functools import lru_cache import time from typing import List from math import log from random import randint,seed fro...
59
218
17,715,200
191721607
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) t = [1] + list(map(int, input().split())) n += 1 u = [] for i in range(n): if t[i] < 0: u.append(i) k -= len(u) if k < 0: ans = -1 print(ans) exit() ans = 0 for i in range(n - 1): ...
Codeforces Round 387 (Div. 2)
CF
2,016
1
256
Winter Is Coming
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of wint...
The first line contains two positive integers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total. The second line contains a sequence of n integers t1, t2, ..., tn ( ...
Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.
null
In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two. In the second example before...
[{"input": "4 3\n-5 20 -3 0", "output": "2"}, {"input": "4 2\n-5 20 -3 0", "output": "4"}, {"input": "10 6\n2 -5 1 3 0 0 -4 -3 1 0", "output": "3"}]
1,800
["dp", "greedy", "sortings"]
59
[{"input": "4 3\r\n-5 20 -3 0\r\n", "output": "2\r\n"}, {"input": "4 2\r\n-5 20 -3 0\r\n", "output": "4\r\n"}, {"input": "10 6\r\n2 -5 1 3 0 0 -4 -3 1 0\r\n", "output": "3\r\n"}, {"input": "4 4\r\n-5 20 -3 0\r\n", "output": "1\r\n"}, {"input": "4 1\r\n-5 20 -3 0\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n-13\r\n", "o...
false
stdio
null
true
747/D
747
D
PyPy 3-64
TESTS
42
108
23,756,800
174972486
R,P=lambda:map(int,input().split()),print;n,k=R();a=[*R()];seg=[];l=z=0 for i in range(1,n+1): if a[i-1]<0: if l:seg+=[i-l-1] l=i;z+=2;k-=1 if k<0:exit(P(-1)) for x in sorted(seg): if k>=x:k-=x;z-=2 else:break P(z-(n-l<=k))
59
265
13,824,000
51673262
n,k=map(int,input().split()) d=list(map(int,input().split())) p=[] count=0 count1=0 for i in range(len(d)): if d[i]>=0: count+=1 if d[i]<0 or i==len(d)-1: p.append(count) count=0 count1+=1 if d[len(d)-1]>=0: count1-=1 if count1==0: print(0) exit() a=p.pop() if d[len(d...
Codeforces Round 387 (Div. 2)
CF
2,016
1
256
Winter Is Coming
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of wint...
The first line contains two positive integers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total. The second line contains a sequence of n integers t1, t2, ..., tn ( ...
Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.
null
In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two. In the second example before...
[{"input": "4 3\n-5 20 -3 0", "output": "2"}, {"input": "4 2\n-5 20 -3 0", "output": "4"}, {"input": "10 6\n2 -5 1 3 0 0 -4 -3 1 0", "output": "3"}]
1,800
["dp", "greedy", "sortings"]
59
[{"input": "4 3\r\n-5 20 -3 0\r\n", "output": "2\r\n"}, {"input": "4 2\r\n-5 20 -3 0\r\n", "output": "4\r\n"}, {"input": "10 6\r\n2 -5 1 3 0 0 -4 -3 1 0\r\n", "output": "3\r\n"}, {"input": "4 4\r\n-5 20 -3 0\r\n", "output": "1\r\n"}, {"input": "4 1\r\n-5 20 -3 0\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n-13\r\n", "o...
false
stdio
null
true
888/C
888
C
PyPy 3
TESTS
19
202
9,318,400
94833706
import math import collections l=list(input()) n=len(l) l1=[0]*n d={} for i in range(n): if(l[i] not in d): if(i==0): d[l[i]]=[i] else: d[l[i]]=[-1,i] else: d[l[i]].append(i) for i in d: if(d[i][-1]!=n-1): d[i].append(n) m=n d=collections.OrderedDict(s...
51
46
716,800
196516770
# LUOGU_RID: 104092065 s = input().strip() cha = list(set(s)) w = 1000000000000 for k in cha: a = max(map(len, s.split(k))) w = min(a, w) print(w+1)
Educational Codeforces Round 32
ICPC
2,017
2
256
K-Dominant Character
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character.
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Print one number — the minimum value of k such that there exists at least one k-dominant character.
null
null
[{"input": "abacaba", "output": "2"}, {"input": "zzzzz", "output": "1"}, {"input": "abcde", "output": "3"}]
1,400
["binary search", "implementation", "two pointers"]
51
[{"input": "abacaba\r\n", "output": "2\r\n"}, {"input": "zzzzz\r\n", "output": "1\r\n"}, {"input": "abcde\r\n", "output": "3\r\n"}, {"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\r\n", "output": "8\r\n"}, {"input": "daabcdabbabbacacbaacabacbcaabaacac\r\n", "o...
false
stdio
null
true
888/C
888
C
PyPy 3
TESTS
19
327
3,891,200
136776487
import string from collections import Counter a = input() def check_subs(k): c = Counter(a[:k]) for i in range(1, len(a) - k + 1): if c[a[i + k - 1]] != 0: c[a[i + k - 1]] += 1 c[a[i - 1]] -= 1 for i in c: if c[i] > 0: return True return False l = 1 r = len(a) // 2 + 1 while l < r: m = (l + r) // 2...
51
62
5,529,600
134329665
# your code goes he n=input() print(min(max(map(len,n.split(i)))+1 for i in list(set(n))))
Educational Codeforces Round 32
ICPC
2,017
2
256
K-Dominant Character
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character.
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Print one number — the minimum value of k such that there exists at least one k-dominant character.
null
null
[{"input": "abacaba", "output": "2"}, {"input": "zzzzz", "output": "1"}, {"input": "abcde", "output": "3"}]
1,400
["binary search", "implementation", "two pointers"]
51
[{"input": "abacaba\r\n", "output": "2\r\n"}, {"input": "zzzzz\r\n", "output": "1\r\n"}, {"input": "abcde\r\n", "output": "3\r\n"}, {"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\r\n", "output": "8\r\n"}, {"input": "daabcdabbabbacacbaacabacbcaabaacac\r\n", "o...
false
stdio
null
true
747/D
747
D
Python 3
TESTS
30
202
17,305,600
24234377
from collections import deque import heapq def main(): from sys import stdin lines = deque(line.strip() for line in stdin.readlines()) # lines will now contain all of the input's lines in a list n, k = [int(x) for x in lines.popleft().split()] temps = deque(int(x) for x in lines.popleft().split()) ...
59
311
19,660,800
55953603
import math from collections import Counter, defaultdict from itertools import accumulate R = lambda: map(int, input().split()) n, k = R() ts = list(R()) + [-1] k -= sum(1 if t < 0 else 0 for t in ts[:n]) res = 0 if ts[0] >= 0 else 1 for i in range(1, n): if ts[i - 1] < 0 and ts[i] >= 0 or ts[i - 1] >= 0 and ts[i]...
Codeforces Round 387 (Div. 2)
CF
2,016
1
256
Winter Is Coming
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of wint...
The first line contains two positive integers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total. The second line contains a sequence of n integers t1, t2, ..., tn ( ...
Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.
null
In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two. In the second example before...
[{"input": "4 3\n-5 20 -3 0", "output": "2"}, {"input": "4 2\n-5 20 -3 0", "output": "4"}, {"input": "10 6\n2 -5 1 3 0 0 -4 -3 1 0", "output": "3"}]
1,800
["dp", "greedy", "sortings"]
59
[{"input": "4 3\r\n-5 20 -3 0\r\n", "output": "2\r\n"}, {"input": "4 2\r\n-5 20 -3 0\r\n", "output": "4\r\n"}, {"input": "10 6\r\n2 -5 1 3 0 0 -4 -3 1 0\r\n", "output": "3\r\n"}, {"input": "4 4\r\n-5 20 -3 0\r\n", "output": "1\r\n"}, {"input": "4 1\r\n-5 20 -3 0\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n-13\r\n", "o...
false
stdio
null
true
439/C
439
C
Python 3
TESTS
15
139
7,680,000
149460314
n, k, p = map(int, input().split()) s = k - p a = b = c = '' for i in input().split(): i = ' ' + i if i[-1] in '13579': if s > 0: a += '\n1' + i elif s & 1: if p > 0: b += i else: c += i else: if p > 0: b += '\n2' + i else: c += i ...
75
389
35,737,600
91398255
n, k, p = map(int, input().split()) a = list(map(int, input().split())) odd = [i for i in a if i % 2 == 1] even = [i for i in a if i % 2 == 0] g = [[] for i in range(k)] if len(odd) < k-p or (len(odd)-(k-p)) % 2 == 1: print("NO") exit() for i in range(k-p): g[i].append(odd.pop()) m = len(even) for i in rang...
Codeforces Round 251 (Div. 2)
CF
2,014
1
256
Devu and Partitioning of the Array
Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him? Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty part...
The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a1, a2, ..., an (1 ≤ ai ≤ 109).
In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes). If the required partition exists, print k lines after the first line. The ith of them should contain the content of the ith part. Print the content of the part in ...
null
null
[{"input": "5 5 3\n2 6 10 5 9", "output": "YES\n1 9\n1 5\n1 10\n1 6\n1 2"}, {"input": "5 5 3\n7 14 2 9 5", "output": "NO"}, {"input": "5 3 1\n1 2 3 7 5", "output": "YES\n3 5 1 3\n1 7\n1 2"}]
1,700
["brute force", "constructive algorithms", "implementation", "number theory"]
75
[{"input": "5 5 3\r\n2 6 10 5 9\r\n", "output": "YES\r\n1 9\r\n1 5\r\n1 10\r\n1 6\r\n1 2\r\n"}, {"input": "5 5 3\r\n7 14 2 9 5\r\n", "output": "NO\r\n"}, {"input": "5 3 1\r\n1 2 3 7 5\r\n", "output": "YES\r\n3 5 1 3\r\n1 7\r\n1 2\r\n"}, {"input": "10 5 3\r\n194757070 828985446 11164 80016 84729 117765558 111730436 1640...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, k, p = map(int, f.readline().split()) a = list(map(int, f.readline().split())) with open(output_path) as f: ref_line = f.readline().strip() correct_answer = ref_line with ...
true
78/A
78
A
Python 3
TESTS
3
62
0
199437741
phaseOne = list(input().replace(" ", "")) phaseTwo = list(input().replace(" ", "")) phaseThree = list(input().replace(" ", "")) syllOne = 0 syllTwo = 0 syllThree = 0 ok = True for i in range(len(phaseOne)): tempChr = phaseOne[i] if(tempChr == 'a' or tempChr == 'e' or tempChr == 'i' or tempChr == 'o' or ...
40
62
0
144090651
def count(s): c = 0 for i in s: if (i == 'a' or i == 'e' or i == 'i' or i=="o" or i == "u"): c += 1 return c a = input() b = input() c = input() if (count(a) == 5 and count(b) == 7 and count(c) == 5): print("YES") else: print("NO")
Codeforces Beta Round 70 (Div. 2)
CF
2,011
2
256
Haiku
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing sp...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
null
null
[{"input": "on codeforces\nbeta round is running\na rustling of keys", "output": "YES"}, {"input": "how many gallons\nof edo s rain did you drink\ncuckoo", "output": "NO"}]
800
["implementation", "strings"]
40
[{"input": "on codeforces \r\nbeta round is running\r\n a rustling of keys \r\n", "output": "YES"}, {"input": "how many gallons\r\nof edo s rain did you drink\r\n cuckoo\r\n", "output": "NO"}, {"input": " hatsu shigure\r\n saru mo komino wo\r\nhoshige nari\r\n", "output": "Y...
false
stdio
null
true
364/A
364
A
PyPy 3
TESTS
4
217
2,150,400
118186644
a=int(input()) b=[int(i) for i in input()] n=len(b) c=[0]*(sum(b)+1) d=[0] e=0 for i in range(n): e+=b[i] d.append(e) for i in range(n): for j in range(i,n): c[d[j+1]-d[i]]+=1 if a==0: print(c[0]*sum(c)) else: f=0 c1=len(c) for i in range(1,int(a**0.5)+1): if a%i==0 and i<c1 ...
83
140
102,400
41565386
def divisors(x): def f(y, q): t = -len(r) while not y % q: y //= q for i in range(t, 0): r.append(r[t] * q) return y r, p = [1], 7 x = f(f(f(x, 2), 3), 5) while x >= p * p: for s in 4, 2, 4, 2, 4, 6, 2, 6: if not x % p:...
Codeforces Round 213 (Div. 1)
CF
2,013
1
256
Matrix
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle. A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the r...
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Print a single integer — the answer to a problem. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
null
[{"input": "10\n12345", "output": "6"}, {"input": "16\n439873893693495623498263984765", "output": "40"}]
1,600
["combinatorics", "data structures", "implementation"]
83
[{"input": "10\r\n12345\r\n", "output": "6\r\n"}, {"input": "16\r\n439873893693495623498263984765\r\n", "output": "40\r\n"}, {"input": "0\r\n1230\r\n", "output": "19\r\n"}, {"input": "8398\r\n67950927224842887617892831243606761170908507858527\r\n", "output": "0\r\n"}, {"input": "2\r\n11\r\n", "output": "4\r\n"}, {"inpu...
false
stdio
null
true
659/C
659
C
Python 3
TESTS
9
155
6,963,200
47816350
n,m=[int(x) for x in input().split()] toys=set([int(x) for x in input().split()]) newtoy=[] for i in range(1,10**5+1): if i not in toys and m>=i: m-=i newtoy.append(str(i)) print(len(newtoy)) print(' '.join(newtoy))
61
108
18,329,600
173768864
n, m = map(int, input().split()) toys = set(map(int, input().split())) res = [] cur = 1 while m > 0: if cur not in toys: m -= cur if m >= 0: res.append(str(cur)) cur += 1 print(len(res)) print(' '.join(res))
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya'...
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya alrea...
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m. In the second line print k distinct space-separated intege...
null
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
[{"input": "3 7\n1 3 4", "output": "2\n2 5"}, {"input": "4 14\n4 6 12 8", "output": "4\n7 2 3 1"}]
1,200
["greedy", "implementation"]
61
[{"input": "3 7\r\n1 3 4\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "4 14\r\n4 6 12 8\r\n", "output": "4\r\n1 2 3 5 \r\n"}, {"input": "5 6\r\n97746 64770 31551 96547 65684\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "10 10\r\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656\r\n", "output": "4\r\n1 2 3 4 \...
false
stdio
null
true
659/C
659
C
Python 3
TESTS
9
93
14,643,200
210782480
# from queue import PriorityQueue # import math # import math # from functools import reduce # def find_gcd(list): # x = reduce(gcd, list) # return x # from itertools import combinations # import qrcode # text = qrcode.make("momen ashraf") # text.save("qr.png") # def f(i,l,s,index_list,ans): # ...
61
109
10,649,600
162680033
n, m = map(int, input().split()) a = set(map(int, input().split())) b = set() i = 1 while m >= i: if i not in a: b.add(i) m -= i i += 1 print(len(b)) print(" ".join(str(x) for x in b))
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya'...
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya alrea...
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m. In the second line print k distinct space-separated intege...
null
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
[{"input": "3 7\n1 3 4", "output": "2\n2 5"}, {"input": "4 14\n4 6 12 8", "output": "4\n7 2 3 1"}]
1,200
["greedy", "implementation"]
61
[{"input": "3 7\r\n1 3 4\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "4 14\r\n4 6 12 8\r\n", "output": "4\r\n1 2 3 5 \r\n"}, {"input": "5 6\r\n97746 64770 31551 96547 65684\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "10 10\r\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656\r\n", "output": "4\r\n1 2 3 4 \...
false
stdio
null
true
369/A
369
A
Python 3
TESTS
48
62
0
9442334
days,bowl,plate = map(int,(input().split())) #print(days) #print(bowl) #print(plate) count1 = 0 count2 = 0 menu = (input().split()) #menu.append(inp) for i in range(days): #print(menu[i]) if(menu[i]=='1'): count1 = count1+1 elif(menu[i]=='2'): count2 = count2+1 bowl = bowl-count1 if(bowl>0):...
63
46
0
141697493
n, m, k = map(int, input().split()) alist = [int(x) for x in input().split()] for i in range(n): if alist[i] == 1: m -= 1 elif alist[i] == 2: k -= 1 print(-1*min(0, m, m + k))
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
61/C
61
C
Python 3
TESTS
5
93
307,200
103582101
n, m = input().split() b = input() if n == m: print(b) else: n= int(n) st1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25] st2 =['', '1','2','3','4','5','6','7','8','9','A','B','C','D', 'E', 'F','G','H','I','J','K','L','M','N','O','P','Q'] s = str(b) l = len(s) deci = 0 j = 0 for i ...
70
124
0
42134178
digs = [chr(c) for c in range(ord('0'),ord('9')+1)] digs += [chr(c) for c in range(ord('A'),ord('Z')+1)] def int2base(x, base): if x < 0: sign = -1 elif x == 0: return digs[0] else: sign = 1 x *= sign digits = [] while x: digits.append(digs[x % base]) x //= base if sign < 0: digi...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Capture Valerian
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran. Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captu...
The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system. The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103. It is guaranteed that if we have Roman numerals inclu...
Write a single line that contains integer c in base b. You must omit leading zeros.
null
You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals
[{"input": "10 2\n1", "output": "1"}, {"input": "16 R\n5", "output": "V"}, {"input": "5 R\n4", "output": "IV"}, {"input": "2 2\n1111001", "output": "1111001"}, {"input": "12 13\nA", "output": "A"}]
2,000
["math"]
70
[{"input": "10 2\r\n1\r\n", "output": "1\r\n"}, {"input": "16 R\r\n5\r\n", "output": "V\r\n"}, {"input": "5 R\r\n4\r\n", "output": "IV\r\n"}, {"input": "2 2\r\n1111001\r\n", "output": "1111001\r\n"}, {"input": "12 13\r\nA\r\n", "output": "A\r\n"}, {"input": "6 7\r\n12345\r\n", "output": "5303\r\n"}, {"input": "25 12\r\...
false
stdio
null
true
247/A
250
A
PyPy 3
TESTS
7
154
0
220621728
n = int(input()) a = [int(i) for i in input().split()] ans = 0 lengths = [] answer = [] w = 0 for i in range(len(a)): if a[i] < 0: w += 1 if w == 3: ans += 1 w = 0 lengths.append(i) lengths.append(n) print(ans + 1) for i in range(len(lengths) - 1): answer.append(lengths[i...
69
92
0
160136358
n=int(input()) entrada=input().split() negative_counter=0 folder_list=[] last_folder=0 folder_count=1 for i in range(n): day=int(entrada[i]) if day<0: if negative_counter==2: folder_list.append(last_folder) last_folder=0 folder_count+=1 negative_counter=1 ...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Paper Work
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n...
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them.
null
Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.
[{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}]
1,000
[]
69
[{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) return n, a def compute_min_k(n, a): if n == 0: return 0 folders = 0 current_neg = 0 current_size = 0 for ai in a: current_s...
true
436/A
436
A
Python 3
TESTS
15
592
921,600
173165797
import operator n, x = map(int, input().split()) arr = [] prev = None res1, res2 = 0, 0 for _ in range(n): t, h, m = map(int, input().split()) m = m arr.append([t, h, m]) curr = [a for a in arr if a[1] <= x and a[0] != prev] curr = sorted(curr, key=operator.itemgetter(1)) curr = sorted(curr, key=operator....
60
233
4,505,600
139882858
#from itertools import * #from math import * #from bisect import * #from collections import * #from random import * #from decimal import * #from heapq import * #from itertools import * # Things Change ....remember :) import sys input=sys.stdin.readline def inp(): return int(input()) def st(): return ...
Zepto Code Rush 2014
CF
2,014
2
256
Feed with Candy
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ...
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu...
Print a single integer — the maximum number of candies Om Nom can eat.
null
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: 1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7....
[{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}]
1,500
["greedy"]
60
[{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\...
false
stdio
null
true
464/A
464
A
Python 3
TESTS
22
109
307,200
74388071
import sys n, p = map(int, sys.stdin.readline().split()) s = sys.stdin.readline() sl = list(s) sl.remove("\n") all = "abcdefghijklmnopqrstuvwxyz"[:p] flag = 0 for i in range(n-1, -1, -1): c = ord(s[i]) - 96 prev = -1 nprev = -1 if c < p: if i-1 >= 0: prev = ord(s[i-1]) - 96 ...
73
77
0
15889900
def main(): n, p = map(int, input().split()) l = [p, p] + [ord(c) - 97 for c in input()] a = l[-2] for i in range(n + 1, 1, -1): a, b = l[i - 2], a for x in range(l[i] + 1, p): if a != x != b: l[i] = x break else: continue ...
Codeforces Round 265 (Div. 1)
CF
2,014
1
256
No to Palindromes!
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
null
String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti, si + 1 > ti + 1. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string...
[{"input": "3 3\ncba", "output": "NO"}, {"input": "3 4\ncba", "output": "cbd"}, {"input": "4 4\nabcd", "output": "abda"}]
1,700
["greedy", "strings"]
73
[{"input": "3 3\r\ncba\r\n", "output": "NO\r\n"}, {"input": "3 4\r\ncba\r\n", "output": "cbd\r\n"}, {"input": "4 4\r\nabcd\r\n", "output": "abda\r\n"}, {"input": "2 2\r\nab\r\n", "output": "ba\r\n"}, {"input": "2 2\r\nba\r\n", "output": "NO\r\n"}, {"input": "1 2\r\na\r\n", "output": "b\r\n"}, {"input": "1 2\r\nb\r\n", ...
false
stdio
null
true
330/B
330
B
PyPy 3-64
TESTS
14
154
3,993,600
166182886
n,m = map(int,input().split()) adj = [[]for i in range(n+1)] no_edge = [] for i in range(m): u,v = map(int,input().split()) if u not in no_edge and v not in no_edge: no_edge.append(u) no_edge.append(v) star_node = [] for i in range(1,n+1): if i not in no_edge: star_node.append(i) roa...
43
92
0
138775254
n,m=map(int,input().split());l=[0]*n for i in range(m) :a,b=map(int,input().split());l[a-1]=1;l[b-1]=1 V=l.index(0)+1;print(n-1) for i in range(1,n+1) : if i!=V : print(V,i)
Codeforces Round 192 (Div. 2)
CF
2,013
2
256
Road Construction
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r...
The first line consists of two integers n and m $$( 1 \leq n \leq 1 0 ^ { 3 }, 0 \leq m < \frac { n } { 2 } )$$. Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbere...
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may prin...
null
This is one possible solution of the example: These are examples of wrong solutions:
[{"input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3"}]
1,300
["constructive algorithms", "graphs"]
43
[{"input": "4 1\r\n1 3\r\n", "output": "3\r\n1 2\r\n4 2\r\n2 3\r\n"}, {"input": "1000 0\r\n", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] n, m, forbidden = read_input(input_path) with open(output_path, 'r') as f: s_ref = int(f.readline().strip()) with open(submission_path, 'r') as f: lines = f.readlines() ...
true
707/A
707
A
Python 3
TESTS
27
46
0
199403097
a,b=map(int,input().split()) for i in range(a): c=list(map(str,input().split())) if 'C' in c or 'M' in c or 'Y' in c: print('#Color') exit() else: print('#Black&White')
50
31
0
165465781
def main(): n, m = [int(i) for i in input().split()] visited = [] for _ in range(n): colors = input().split() for color in colors: if color not in visited: visited.append(color) if "C" in visited or "Y" in visited or "M" in visited: print("#Color") ...
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
27
46
0
193851682
def n(): a = list(map(int, input().split())) return a def e(): a = n() for i in range(a[0]): b = input().split() check = 1 for k in b: if k == 'C' or k == 'M' or k == 'Y': check = 0 break if check == 0: print("#Color") else: p...
50
31
0
207686840
def colour_determine(n,m,pixel): for r in range(n): for c in range(m): if pixel[r][c] == 'C' or pixel[r][c] == 'M' or pixel[r][c] == 'Y': return '#Color' return'#Black&White' n,m=map(int,input().split()) pixel=[] for i in range(n): pixel.append(list(input().split())) prin...
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
27
46
0
186832477
def isBlack(a): for i in a: if i in c: return False return True n, m = [int(x) for x in input().split()] isb = True c = ['C', 'M', 'Y'] for i in range(n): a = input().split() isb = isBlack(a) if isb: print('#Black&White') else: print('#Color')
50
31
0
208426884
li=list(map(int,input().strip().split())) r=li[0] c=li[1] c=0 for i in range(r): arr=list(map(str,input().strip().split())) if "C" in arr or "M" in arr or "Y" in arr: print("#Color") c=1 break if c==0: print("#Black&White")
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
27
46
0
215793377
r , c = map(int,input().split(" ")) pri = ("#Black&White") for i in range(0,r) : l = list(map(str,input().split(" "))) for k in l : if k =="C" or k=="M" or k=="Y" : pri ="#Color" print(pri)
50
31
0
209266307
m,n=map(int,input().split()) c=0 for i in range(m): a=list(map(str,input().split())) if 'C' in a or 'Y' in a or 'M' in a: c=c+1 if c!=0: print('#Color') else: print('#Black&White')
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
40/D
40
D
Python 3
TESTS
7
92
0
188538137
n = int(input()) sr = 0 cur = n deg=0 sd = 0 while cur>0: sr+=cur%12 sd+=deg*(cur%12) cur=cur//12 deg+=1 d12=[1] for xeg in range(300): d12.append(d12[-1]*12) if sr!=2: print("NO") exit(0) else: print("YES") print(1) print(sd+1) print(sd//2 ) for i in range(sd//2+1): if d12[i] + d12[sd-i] != n: print(d...
74
216
307,200
203112836
A = int(input()) pw = 0 while A % 12 == 0 : A //= 12 pw += 1 x, y = 2, 13 p = 1 pos = -1 while x <= A : if x == A : pos = p x, y = y, 13 * y - 12 * x p += 1 if pos == -1 : print('NO') exit() print('YES') print(1) print(pos + 2 * pw) x, y = 2, 13 p = 1 oth = [] while p <= po...
Codeforces Beta Round 39
CF
2,010
3
256
Interesting Sequence
Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A...
The first line contains integer A (1 ≤ A < 10300). It is guaranteed that the number doesn't contain leading zeros.
On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO. If the answer is YES, then you also have to print number k — the number of years in which the population could equal A. On the next line you have to output precisely k space-separate...
null
null
[{"input": "2", "output": "YES\n1\n1\n0"}, {"input": "3", "output": "NO"}, {"input": "13", "output": "YES\n1\n2\n0"}, {"input": "1729", "output": "YES\n1\n4\n1\n156"}]
2,600
["math"]
74
[{"input": "2\r\n", "output": "YES\r\n1\r\n1\r\n0\r\n"}, {"input": "3\r\n", "output": "NO\r\n"}, {"input": "13\r\n", "output": "YES\r\n1\r\n2\r\n0\r\n"}, {"input": "1729\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n156\r\n"}, {"input": "1\r\n", "output": "NO\r\n"}, {"input": "156\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n1729\r...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
27
46
0
168694618
n,m=input().split() n=int(n) m=int(m) l=[] for i in range(0,n): s=[x for x in input().split()] l.append(s) for k in range(0,n): p=l[k].count('C')+l[k].count('M')+l[k].count('Y') if p<1: print('#Black&White') else: print('#Color')
50
31
0
209619492
x1 = int(input().split()[0]) lst, ans = [],[] for i in range(x1): col1 = input().split() for c in col1: lst.append(c) for i in set(lst): if i == "W" or i == "B" or i == "G": ans.append("#Black&White") else: ans.append("#Color") x = set(ans) if len(x) > 1: print("#Color") el...
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
369/A
369
A
Python 3
TESTS
10
62
6,758,400
126098259
n,m,k = map(int, input().split()) val = list(map(int, input().split())) c2 = 0 for i in range(n): if val[i]==2: c2 += 1 print(max(n-m,0) - min(c2,k))
63
46
0
142176933
""" Module which implements the search of the minimum number of plates that need to be washed. """ def min_plates(first: int, second: int, plan: list): """ Return the minimum number of plates. """ first_need = 0 second_need = 0 for elem in plan: if elem == 1: first_need += 1 ...
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
369/A
369
A
Python 3
TESTS
10
62
6,963,200
129923036
s = list(map(int,input().split())) n,g,p = int(s[0]), int(s[1]),int(s[2]) s = list(map(int,input().split())) k = 0 for i in range(n): if s[i] == 1: g -= 1 if s[i] == 2: if p > 0: p -= 1 else: g -= 1 print(abs(g))
63
46
0
143164106
n, bowls, plates = map(int, input().split()) days = list(map(int, input().split())) res = 0 for day in days: if day == 1: if bowls>0: bowls -= 1 else: res += 1 else: if plates > 0: plates -= 1 else: if bowls > 0: bow...
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
465/B
465
B
Python 3
TESTS
29
109
307,200
97193607
k = int(input()) l = list(map(int,input().split())) ans,i,bool = 0,0,True while i < k: if l[i] == 1: ans += 1 for num in l[i+1:]: bool = False i += 1 if num == 1: ans += 1 else: ans += 1 break i += 1 ...
44
46
0
138209874
n=int(input()) a=[int(x) for x in input().split()] if a.count(1)==0: print(0) elif a.count(1)==1: print(1) else: pos,res=a.index(1),1 for i in range(pos+1,n): if a[i]==1: if a[i-1]==1: res+=1 else: res+=2 print(res)
Codeforces Round 265 (Div. 2)
CF
2,014
1
256
Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
null
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already...
[{"input": "5\n0 1 0 1 0", "output": "3"}, {"input": "5\n1 1 0 0 1", "output": "4"}, {"input": "2\n0 0", "output": "0"}]
1,000
["implementation"]
44
[{"input": "5\r\n0 1 0 1 0\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 0 0 1\r\n", "output": "4\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "9\r\n1 0 1 0 1 0 1 0 1\r\n", "output": "9\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "14\r\n0 0 1 1 1 0 1 1 1 0 1 1 1 0\r\n", "outpu...
false
stdio
null
true
841/B
841
B
PyPy 3
TESTS
18
1,013
77,209,600
71357387
n = int(input()) a = list(map(int, input().split(' '))) oe = list(map(lambda x: x%2, a)) if sum(oe) == 0: win = "Second" elif sum(oe) % 2 == 1 or oe[0] == 1 or oe[-1] == 1: win = "First" else: win = "Second" print(win)
88
374
120,012,800
227535002
n=int(input()) arr=list(map(int,input().split())) if sum(arr)%2: print("First") else: o=0 for el in arr: if el%2: o+=1 if o: print("First") else: print("Second")
Codeforces Round 429 (Div. 2)
CF
2,017
2
256
Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
null
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
[{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}]
1,100
["games", "math"]
88
[{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
27
46
0
162265742
l , w = map ( int , input ( ) .split ( ) ) for x in range ( l ): pixel = ( input ( ) .split ( ) ) cyan = pixel .count ( "C" ) magenta = pixel .count ( "M" ) yellow = pixel .count ( "Y" ) white = pixel .count ( "W" ) grey = pixel .count ( "G" ) black = pixel .count ( "B" ) if cyan >= 1: print ( "#Color" ) eli...
50
31
0
215174595
nm = input().split(' ') n = int(nm[0]) m = int(nm[1]) count = 0 for i in range(n): colors = input().split(' ') if ('C' in colors) or ('M' in colors) or ('Y' in colors): count = 1 if count==1: print('#Color') else: print('#Black&White')
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true