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
787/B
787
B
Python 3
TESTS
56
77
5,632,000
25747840
n, m = map(int, input().split()) for i in range(m): res = 0 group = list(map(int, input().split())) A = set(group) for j in range(len(group)): if (-1)*group[j] not in A: res += 1 if res == len(group): print("YES") break else: print("NO")
65
62
5,529,600
25740782
n,m=map(int,input().split()) for _ in range(m): k,*l=map(int,input().split()) l=set(l) for x in l: if -x in l: break else: print('YES'); break else: print('NO')
Codeforces Round 406 (Div. 2)
CF
2,017
2
256
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one ...
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ......
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
null
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
[{"input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES"}, {"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO"}, {"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES"}]
1,300
["greedy", "implementation", "math"]
65
[{"input": "4 2\r\n1 -3\r\n4 -2 3 2 -3\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n5 3 -2 1 -1 5\r\n3 -5 2 5\r\n", "output": "NO\r\n"}, {"input": "7 2\r\n3 -1 6 7\r\n7 -5 4 2 4 7 -3 4\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n2 -2 2\r\n", "output": "NO\r\n"}, {"input": "7 7\r\n1 -2\r\n1 6\r\n2 7 -6\r\n2 -6 4\r\n2...
false
stdio
null
true
787/B
787
B
Python 3
TESTS
56
78
5,632,000
25745204
n,m = [int(a_temp) for a_temp in input().strip().split()] p = [] for i in range(m): p.append([int(a_temp) for a_temp in input().strip().split()]) for i in range(m): traitor = True d = {} for e in p[i]: d[e]=True if -1*e in d: traitor=False break if traitor: ...
65
62
5,529,600
25743765
n, m = [int(i) for i in input().split()] def check(line): for i in line: if -i in line: return True return False for _ in range(m): line = set([int(i) for i in input().split()][1:]) if not check(line): print('YES') exit() print('NO')
Codeforces Round 406 (Div. 2)
CF
2,017
2
256
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one ...
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ......
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
null
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
[{"input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES"}, {"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO"}, {"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES"}]
1,300
["greedy", "implementation", "math"]
65
[{"input": "4 2\r\n1 -3\r\n4 -2 3 2 -3\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n5 3 -2 1 -1 5\r\n3 -5 2 5\r\n", "output": "NO\r\n"}, {"input": "7 2\r\n3 -1 6 7\r\n7 -5 4 2 4 7 -3 4\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n2 -2 2\r\n", "output": "NO\r\n"}, {"input": "7 7\r\n1 -2\r\n1 6\r\n2 7 -6\r\n2 -6 4\r\n2...
false
stdio
null
true
605/B
605
B
Python 3
TESTS
4
62
0
14736552
n, m = (int(x) for x in input().split()) edges = [] for i in range(m): w, in_tree = input().split() edges.append([int(w), i, int(in_tree)]) sorted_edges = sorted(edges) def free_edge(): for y in range(3, n+1): for x in range(2, y): yield [x, y] f = free_edge() k = 2 for e in sorted_edges...
76
1,091
24,576,000
17247897
def read_data(): n, m = map(int, input().split()) ABs = [] for i in range(m): a, b = map(int, input().split()) ABs.append((a, b)) return n, m, ABs def solve(n, m, ABs): edges = [(a, -b, i) for i, (a, b) in enumerate(ABs)] edges.sort() ans = [(0, 0) for i in range(m)] v =...
Codeforces Round 335 (Div. 1)
CF
2,015
2
256
Lazy Student
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
The first line of the input contains two integers n and m ($$2 \leq n \leq 100\ 000, 1 \leq m \leq 100\ 000, n - 1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertices and the number of edges in the graph. Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109,...
If Vladislav has made a mistake and such graph doesn't exist, print - 1. Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, mus...
null
null
[{"input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2"}, {"input": "3 3\n1 0\n2 1\n3 1", "output": "-1"}]
1,700
["constructive algorithms", "data structures", "graphs"]
76
[{"input": "4 5\r\n2 1\r\n3 1\r\n4 0\r\n1 1\r\n5 0\r\n", "output": "2 4\r\n1 4\r\n3 4\r\n3 1\r\n3 2\r\n"}, {"input": "3 3\r\n1 0\r\n2 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n7 1\r\n", "output": "1 2\r\n"}, {"input": "3 2\r\n8 1\r\n9 1\r\n", "output": "1 2\r\n1 3\r\n"}, {"input": "3 3\r\n4 1\r\n5 0\r\n7 1\...
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: input_lines = f.read().splitlines() with open(output_path) as f: reference_output = f.read().strip() with open(sub...
true
888/C
888
C
PyPy 3
TESTS
18
186
5,529,600
99764403
def check(st, mid, a): n = len(st) previous = -1 for i in range(n): if (st[i] == chr(a)): if (i - previous > mid): return False previous = i if (i - previous > mid): return False else: return True def possible(st, mid): for i in range(26): if (check(st, mid, i + ord('a'))): ret...
51
77
8,294,400
166864631
import sys input = sys.stdin.readline s = input()[:-1] x = len(s) d = dict() c = 100000 for i in range(97, 123): d[chr(i)] = [-1] for i in range(x): a = s[i] d[a].append(i) for i in d: d[i].append(x) w = max(j-i for i,j in zip(d[i], d[i][1:])) c = min(w, c) print(c)
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
230/A
230
A
PyPy 3-64
TESTS
8
186
1,740,800
231742016
s,n=map(int,input().split()) dragon_strength=[] bonus=[] for i in range(n): x,y=map(int,input().split()) dragon_strength.append(x) bonus.append(y) count=0 strength=sorted(dragon_strength) for elements in strength: if(s>=elements): i1=dragon_strength.index(elements) s=s+bonus[i1] ...
54
92
0
230792350
s,n=map(int,input().split()) dragons=[] for i in range(n): x,y=map(int,input().split()) dragons.append((x,y)) dragons.sort() for dragon in dragons: if s>dragon[0]: s+=dragon[1] else: print('NO') break else: 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
358/A
358
A
PyPy 3
TESTS
20
171
2,560,000
102091988
from sys import stdin,stdout input=stdin.readline import math,bisect n=int(input()) l=list(map(int,input().split())) if n<=2: print("No") else: f=0 for i in range(1,n): x1=min(l[i-1],l[i]) x2=max(l[i-1],l[i]) for j in range(i+1,n): x3=min(l[j-1],l[j]) x4=max(l[j-1],l[j]) if x1<x3<x2<x4: f=1 e...
37
62
1,638,400
214474331
t = int(input()) n = list(map(int,input().split())) pairs = [sorted([n[c],n[c+1]]) for c in range(len(n)-1)] for i in range(len(pairs)): for j in range(len(pairs)): k = pairs[i] k1 = pairs[j] if ((k[0]>k1[0] and k[1]>k1[1]) or (k[0]<k1[0] and k[1]<k1[1])) and (k[1] > k1[0]) and (k[0] < k1[1]...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Continuous Line
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them...
The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
null
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
[{"input": "4\n0 10 5 15", "output": "yes"}, {"input": "4\n0 15 5 10", "output": "no"}]
1,400
["brute force", "implementation"]
37
[{"input": "4\r\n0 10 5 15\r\n", "output": "yes\r\n"}, {"input": "4\r\n0 15 5 10\r\n", "output": "no\r\n"}, {"input": "5\r\n0 1000 2000 3000 1500\r\n", "output": "yes\r\n"}, {"input": "5\r\n-724093 710736 -383722 -359011 439613\r\n", "output": "no\r\n"}, {"input": "50\r\n384672 661179 -775591 -989608 611120 442691 6017...
false
stdio
null
true
891/A
891
A
PyPy 3
TESTS
35
187
3,379,200
96858712
def gcd(a, b): if a == 0 : return b return gcd(b%a, a) n=int(input()) a=list(map(int,input().split())) o=a.count(1) ans=10**9 for i in range(n): g=a[i] for j in range(i+1,n): g=gcd(a[j],g) if g==1: ans=min(ans,n-1+j-i-o) break if ans==10**...
52
77
2,457,600
232784935
import sys input = sys.stdin.readline from math import gcd n = int(input()) ls = list(map(int,input().split())) hcf, ct1 = ls[0], 0 for i in range(n) : if ls[i] == 1 : ct1 += 1 hcf = gcd(hcf,ls[i]) if hcf != 1 : print(-1) elif ct1 : print(n-ct1) else : mn = 5000 for i in range(n-1) : ...
Codeforces Round 446 (Div. 1)
CF
2,017
2
256
Pride
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the greatest common divisor. What is the minimum number of operations you need to make all of the elements equal to 1?
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.
null
In the first sample you can turn all numbers to 1 using the following 5 moves: - [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
[{"input": "5\n2 2 3 4 6", "output": "5"}, {"input": "4\n2 4 6 8", "output": "-1"}, {"input": "3\n2 6 9", "output": "4"}]
1,500
["brute force", "dp", "greedy", "math", "number theory"]
52
[{"input": "5\r\n2 2 3 4 6\r\n", "output": "5\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 6 9\r\n", "output": "4\r\n"}, {"input": "15\r\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21\r\n", "output": "15\r\n"}, {"input": "12\r\n10 10 14 14 14 14 14 14 14 14 21 21\r\n", "output": "20\r\n"},...
false
stdio
null
true
364/A
364
A
PyPy 3-64
TESTS
11
389
10,956,800
194231201
import sys input = sys.stdin.readline a = int(input()) s = list(map(int, list(input()[:-1]))) m = len(s) d = [0] for i in s: d.append(d[-1]+i) q = dict() for i in range(1, len(d)): for j in range(i): x = d[i]-d[j] if x not in q: q[x] = 1 else: q[x] += 1 c = 0 if ...
83
374
10,547,200
193779758
from collections import defaultdict a = int(input()) # calculating the prefix sum s = [0]+list(map(int, list(input()))) n = len(s)-1 for i in range(1, len(s)): s[i] += s[i-1] # make dictionary on prefix sums d = defaultdict(int) for i in range(1, len(s)): for j in range(i): d[s[i]-s[j]] += 1 # find ...
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
229/A
229
A
Python 3
TESTS
10
1,996
4,915,200
144266776
def ThereIsRowWithNullSum(a): for row in a: if sum(row) == 0: return True return False def GetIndOfColWithMaxSum(n, m, a): max_col_ind = 0 max_sum = 0 for j in range(m): s = 0 for i in range(n): s += a[i][j] if s > max_sum: max_col...
59
498
30,822,400
35127670
n, m = map(int, input().split()) f = [[int(1e9) for j in range(m)] for i in range(n)] for i in range(n): s = input() if s.find('1') == -1: print(-1) exit() f[i][0] = s[::-1].find('1') + 1 f[i][m - 1] = s.find('1') + 1 for j in range(m): f[i][j] = 0 if s[j] == '1' else f[i][j] for j in range(m): f[i][j] = ...
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
463/A
463
A
Python 3
TESTS
8
61
307,200
105184427
n,s = map(int,input().split()) arr=[] l=[] for z in range(n): x,y= map(int,input().split()) arr.append([x,y]) for i in arr: if (i[0]<s and i[1]!=0): l.append(100-i[1]) elif (i[0]==s and i[1]==0) or i[1]==0: l.append(0) if len(l)==0: print(-1) else: print(max(l))
35
61
0
180059789
n,s=map(int,input().split()) arr=[] s=s*100 for i in range(n): x,y=map(int,input().split()) arr.append(x*100+y) ans=-1 for i in range(n): if s>=arr[i]: sdacha=(s-arr[i])%100 ans=max(sdacha,ans) print(ans)
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Sugar
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But t...
The first line contains two space-separated integers n, s (1 ≤ n, s ≤ 100). The i-th of the next n lines contains two integers xi, yi (1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
null
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
[{"input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "output": "50"}, {"input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "output": "-1"}]
1,200
["brute force", "implementation"]
35
[{"input": "5 10\r\n3 90\r\n12 0\r\n9 70\r\n5 50\r\n7 0\r\n", "output": "50\r\n"}, {"input": "5 5\r\n10 10\r\n20 20\r\n30 30\r\n40 40\r\n50 50\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2 10\r\n20 99\r\n30 99\r\n", "output": "-1\r\n"}, {"input": "15 21\r\n16 51\r\n33 44\r\n32 ...
false
stdio
null
true
793/C
793
C
Python 3
PRETESTS
6
62
5,529,600
26614027
n=int(input()) x1,y1,x2,y2=[int(x) for x in input().split()] st=[] et=[] ok=1 if x1==x2 or y1==y2: ok=0 for i in range(n): a,b,u,w=[int(x) for x in input().split()] for x,v,s,e in ((a,u,x1,x2),(b,w,y1,y2)): if v==0: if not(s<=x<=e): ok=0 else: t1=(s-...
80
1,278
32,153,600
26625749
# t*v+a = b # t=(b-a)/v import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mintime=(0,1) maxtime=(10**9,1) useless=0 n=int(input()) #include <math.h> # int 'y1' redeclared as different kind of symbol x1,y1,x2,y2=map(int,input().split()) for _ in range(n): rx,ry,vx,vy=map(int,input().split()) #...
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
305/A
305
A
Python 3
TESTS
11
122
0
13231031
n = int(input()) a = input().split() ans = "" cnt = 0 XO = "" OX = "" XX = "" for i in a: if i=='100' or i=='0': ans += i+" " cnt+=1 else: if len(i)==1: OX = i if len(i)==2: if int(i)%10==0: XO = i else: XX = i ...
35
122
512,000
151187359
n= int(input()) lst=list(map(int,input().split())) di={0:None,1:None,11:None,100:None,10:None} for i in lst: if i ==0: di[0]=0 elif i ==100: di[100]=i elif 0<i<10: di[1]=i elif 10<=i<=99 and i%10==0: di[10]=i else: di[11]=i if di[10]!=None: di.pop(11) elif...
Codeforces Round 184 (Div. 2)
CF
2,013
2
256
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
null
null
[{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}]
1,600
["brute force", "constructive algorithms", "implementation"]
35
[{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ...
false
stdio
import sys def mask(num): s = f"{num:03d}" mask = 0 if s[0] != '0': mask |= 4 if s[1] != '0': mask |= 2 if s[2] != '0': mask |= 1 return mask def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() k = int(li...
true
219/A
219
A
Python 3
TESTS
16
92
0
172885429
n = int(input()) s = input() if (n%2 == 0 and len(s)%2 ==1) or (n%2 == 1 and len(s)%2 ==0) : print(-1) else : dic = {} for i in s : if i in dic: dic[i]=dic[i]+1 else : dic[i]=1 c = 0 piece = "" for k,v in dic.items(): if v % n !=0: c = ...
42
92
0
137250007
k=int(input()) s=input() lst=[0]*26 for i in s: lst[ord(i)-97]+=1 check=1 for i in lst: if i%k!=0: check=0 break if check==0: print(-1) else: res='' for i in range(26): if lst[i]!=0: res+=(lst[i]//k)*chr(i+97) print(res*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
106/B
106
B
PyPy 3
TESTS
24
186
0
195221328
t = int(input()) arr = [0] * 3 res = 0 index = 0 for i in range(t): speed, ram, hdd, cost = map(int, input().split()) if speed > arr[0] and ram > arr[1] and hdd > arr[2]: arr[0] = speed arr[1] = ram arr[2] = hdd res = cost index = i+1 elif speed >= arr[0] or ram >= ...
55
92
0
156066001
import sys input = sys.stdin.readline n = int(input()) cost = 1200 d = [] for i in range(n): s1, r1, h1, c1 = map(int, input().split()) d.append([s1,r1,h1,c1,i+1]) q = 0 for i in range(n): for j in range(n): if d[i][0] < d[j][0] and d[i][1] < d[j][1] and d[i][2] < d[j][2]: break els...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
106/B
106
B
PyPy 3-64
TESTS
22
124
0
168199398
# Problem Link: https://codeforces.com/problemset/problem/106/B # Problem Status: # ----------------------------------- SEPARATOR ----------------------------------- # IDEA: # Iterate over each laptop, whenever a laptop outdated found skip it, else add the laptop to a new array # Iterate over the new array,...
55
92
0
159575782
def com(l1,l2): if l1[1]<l2[1] and l1[2]<l2[2] and l1[3]<l2[3]: return True return False l=[] n=int(input()) for _ in range(n): ll=[int(i) for i in input().split()] ll[0],ll[-1]=ll[-1],ll[0] l.append(ll+[_+1]) l.sort() i=0 j=i+1 while j<n: if com(l[i], l[j]): l.pop(i) n-=...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
63/B
63
B
Python 3
TESTS
3
92
0
191709869
n, k = map(int, input().split()) soldiers = list(map(int, input().split())) answer = 0 while True: diction = {} #soldiers = [] for i in range(n): tempSoldier = soldiers[i] diction.setdefault(tempSoldier, []) diction[tempSoldier].append(tempSoldier) soldiers.clear() for j in d...
37
92
0
188554752
n,k=list(map(int,input().split(' '))) nums=list(map(int,input().split(' '))) ans=0 while nums[0]<k: ans+=1 prev=-1 for i in range(n-1,-1,-1): if nums[i]==k: continue elif prev==-1: prev=nums[i] nums[i]+=1 elif prev!=-1 and nums[i]!=prev: prev=nums[i] ...
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Settlers' Training
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc...
The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai...
Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.
null
In the first example the ranks will be raised in the following manner: 1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4 Thus totals to 4 training sessions that require 4 golden coins.
[{"input": "4 4\n1 2 2 3", "output": "4"}, {"input": "4 3\n1 1 1 1", "output": "5"}]
1,200
["implementation"]
37
[{"input": "4 4\r\n1 2 2 3\r\n", "output": "4"}, {"input": "4 3\r\n1 1 1 1\r\n", "output": "5"}, {"input": "3 3\r\n1 2 3\r\n", "output": "2"}, {"input": "1 1\r\n1\r\n", "output": "0"}, {"input": "1 5\r\n1\r\n", "output": "4"}, {"input": "1 5\r\n4\r\n", "output": "1"}, {"input": "2 6\r\n2 5\r\n", "output": "4"}, {"input...
false
stdio
null
true
412/C
412
C
Python 3
TESTS
9
264
819,200
7035343
n = int(input()) s = [] for i in range(n): s.append(input()) for i in range(len(s[0])): status = True letter = "x" for j in range(n): if s[j][i] == "?" or s[j][i] == letter: continue #print(j, i) if status: #print(j, i, s[j][i]) status = Fals...
70
77
7,065,600
167964300
import sys;sc = sys.stdin.readline;out=sys.stdout.write arr=[1 for i in range(int(1e5)+10)];o=0 n=int(sc()) for e in range(n): s=str(sc());o=len(s) for ee in range(len(s)): if arr[ee]==1 and s[ee]!='?':arr[ee]=ord(s[ee]) elif arr[ee]!=1: if s[ee]=='?' :continue elif...
Coder-Strike 2014 - Round 1
CF
2,014
1
256
Pattern
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules. In this task, a pattern will be a string con...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of patterns. Next n lines contain the patterns. It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 1...
In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.
null
Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of ot...
[{"input": "2\n?ab\n??b", "output": "xab"}, {"input": "2\na\nb", "output": "?"}, {"input": "1\n?a?b", "output": "cacb"}]
1,200
["implementation", "strings"]
70
[{"input": "2\r\n?ab\r\n??b\r\n", "output": "xab\r\n"}, {"input": "2\r\na\r\nb\r\n", "output": "?\r\n"}, {"input": "1\r\n?a?b\r\n", "output": "cacb\r\n"}, {"input": "1\r\n?\r\n", "output": "x\r\n"}, {"input": "3\r\nabacaba\r\nabacaba\r\nabacaba\r\n", "output": "abacaba\r\n"}, {"input": "3\r\nabc?t\r\n?bc?z\r\nab??t\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()) input_patterns = [line.strip() for line in f] with open(submission_path) as f: submission_line = f.read().strip() ...
true
63/B
63
B
Python 3
TESTS
21
124
0
14031420
# /******************************************************************************* # * Author : Quantum Of Excellence # * email : quantumofexcellence (at) gmail (dot) com # * copyright : 2014 - 2015 # * date : 2 - 11 - 2015 # * Judge Status : AC # * file name : 63B.py # * version : 1.0 #...
37
92
0
209320419
n , k = map(int ,input().split()) m = list(map(int ,input().split())) counter = 0 while sum(m) < k*n: visted = [0] * (k + 1) for i in range(n) : if visted[m[i]] == 0 and m[i] < k: visted[m[i]] = 1 m[i] += 1 counter += 1 print(counter)
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Settlers' Training
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc...
The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai...
Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.
null
In the first example the ranks will be raised in the following manner: 1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4 Thus totals to 4 training sessions that require 4 golden coins.
[{"input": "4 4\n1 2 2 3", "output": "4"}, {"input": "4 3\n1 1 1 1", "output": "5"}]
1,200
["implementation"]
37
[{"input": "4 4\r\n1 2 2 3\r\n", "output": "4"}, {"input": "4 3\r\n1 1 1 1\r\n", "output": "5"}, {"input": "3 3\r\n1 2 3\r\n", "output": "2"}, {"input": "1 1\r\n1\r\n", "output": "0"}, {"input": "1 5\r\n1\r\n", "output": "4"}, {"input": "1 5\r\n4\r\n", "output": "1"}, {"input": "2 6\r\n2 5\r\n", "output": "4"}, {"input...
false
stdio
null
true
498/A
498
A
PyPy 3
TESTS
39
155
20,172,800
90769755
s = tuple(map(int, input().split())) e = tuple(map(int, input().split())) r = 0 n = int(input()) while n != 0: n -= 1 a, b, c = map(int, input().split()) if a == 0 or b == 0: if a == 0: p1, p2 = (0, -c/b), (1, -c/b) else: p1, p2 = (-c/a, 0), (-c/a, 1) else: ...
51
62
0
9250907
x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) count = 0 for _ in range(int(input())): a, b, c = map(int, input().split()) f = lambda x, y: a * x + b * y + c if f(x1, y1) * f(x2, y2) < 0: count += 1 print(count)
Codeforces Round 284 (Div. 1)
CF
2,014
1
256
Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — th...
Output the answer to the problem.
null
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}]
1,700
["geometry"]
51
[{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -...
false
stdio
null
true
48/D
48
D
Python 3
TESTS
4
124
102,400
44525981
from collections import OrderedDict n = int(input()) arr = list(map(int, input().split())) pos_dict = OrderedDict() for i in range(len(arr)): curr = arr[i] if curr in pos_dict: temp = pos_dict[curr] pos_dict[curr].append(i) else: pos_dict[curr] = [i] i_list = sorted(pos_dict, rev...
60
139
18,841,600
174890171
from collections import defaultdict as dc,Counter as C n=int(input()) arr=list(map(int,input().split())) mn,mx=min(arr),max(arr) ans=[0]*n mp=dc(lambda:list()) for i in range(n):mp[arr[i]].append(i) ctr=C(arr) flag=0 for i in range(2,mx+1): if ctr[i]>ctr[i-1]:flag=1 if flag:print(-1); quit() for i in mp: cnt=1 ...
School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules)
ICPC
2,010
1
256
Permutations
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took ...
The first line contains an integer n (1 ≤ n ≤ 105). The next line contains the mixed array of n integers, divided with a single space. The numbers in the array are from 1 to 105.
If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain n numbers, corresponding to the elements of the given array. If the i-th element belongs to the first permutation...
null
In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth el...
[{"input": "9\n1 2 3 1 2 1 4 2 5", "output": "3\n3 1 2 1 2 2 2 3 2"}, {"input": "4\n4 3 2 1", "output": "1\n1 1 1 1"}, {"input": "4\n1 2 2 3", "output": "-1"}]
1,500
["greedy"]
60
[{"input": "9\r\n1 2 3 1 2 1 4 2 5\r\n", "output": "3\r\n1 1 1 2 2 3 1 3 1 "}, {"input": "4\r\n4 3 2 1\r\n", "output": "1\r\n1 1 1 1 "}, {"input": "4\r\n1 2 2 3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "1\r\n2\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
import sys from collections import defaultdict, Counter 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.read().splitlines() n = int(lines[0]) arr = list(map(int, lines[1].split())) with open(output_...
true
847/E
847
E
PyPy 3-64
TESTS
2
46
512,000
160793961
n=int(input()) a=input() l,r=1,2*n while l<=r: mid=(l+r)>>1 cnt,i=0,0 left=0 while i<n: if a[i]=='*': cnt+=1 i+=1 elif a[i]=='.': if cnt!=0:cnt+=1 i+=1 else: if cnt-left>mid:break x=0 if cnt-left>...
77
124
12,595,200
201938431
from collections import deque N = int(input()) st = input() iapos, ppos = [], [] for i in range(N): if st[i] == '*': iapos.append(i) elif st[i] == "P": ppos.append(i) iapos = iapos[::-1] def works(n): apos = iapos.copy() for pac in ppos: if not apos: return True ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Packmen
A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial mome...
The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field. The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is...
Print minimum possible time after which Packmen can eat all asterisks.
null
In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ...
[{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}]
1,800
["binary search", "dp"]
77
[{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP....
false
stdio
null
true
352/A
352
A
Python 3
TESTS
20
92
0
201696108
n = int(input()) num = sorted(list(map(int,input().split()))) num.reverse() fivecount=0 for i in num: if(i==5): fivecount+=1 else: break zerocount=n-fivecount if(zerocount==0): print(-1) else: p=True if(fivecount==n): print(0) p=False anum=0 for i in range(fiv...
42
92
0
136128561
n=int(input());s="".join(sorted(input().split())[::-1]) if "0" in s: while (int(s) % 90 != 0): s = s[1:] print(int(s)) else: print(-1)
Codeforces Round 204 (Div. 2)
CF
2,013
1
256
Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number ...
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
null
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
[{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}]
1,000
["brute force", "implementation", "math"]
42
[{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out...
false
stdio
null
true
632/D
632
D
PyPy 3
TESTS
6
202
15,769,600
147231936
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import math from functools import reduce def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) N = 10**6+1 def main(): spf = [-1]*(N+1) for i in range(N+1):...
45
577
126,668,800
176103378
from sys import stdin input=lambda :stdin.readline()[:-1] n,m=map(int,input().split()) a=list(map(int,input().split())) cnt=[0]*(m+1) for i in a: if i<=m: cnt[i]+=1 for i in range(m,-1,-1): if cnt[i]==0: continue for j in range(2*i,m+1,i): cnt[j]+=cnt[i] mx=max(cnt) if mx==0: print(1,0) print()...
Educational Codeforces Round 9
ICPC
2,016
2
256
Longest Subsequence
You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest subsequence of a with the value l ≤ m. A subsequence of a is an array we can get by erasing some elements of a. It is allowed to erase z...
The first line contains two integers n and m (1 ≤ n, m ≤ 106) — the size of the array a and the parameter from the problem statement. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of a.
In the first line print two integers l and kmax (1 ≤ l ≤ m, 0 ≤ kmax ≤ n) — the value of LCM and the number of elements in optimal subsequence. In the second line print kmax integers — the positions of the elements from the optimal subsequence in the ascending order. Note that you can find and print any subsequence w...
null
null
[{"input": "7 8\n6 2 9 2 7 2 3", "output": "6 5\n1 2 4 6 7"}, {"input": "6 4\n2 2 2 3 3 3", "output": "2 3\n1 2 3"}]
2,100
["brute force", "math", "number theory"]
45
[{"input": "7 8\r\n6 2 9 2 7 2 3\r\n", "output": "6 5\r\n1 2 4 6 7\r\n"}, {"input": "6 4\r\n2 2 2 3 3 3\r\n", "output": "2 3\r\n1 2 3\r\n"}, {"input": "10 50\r\n39 22 60 88 11 65 41 85 65 100\r\n", "output": "22 2\r\n2 5\r\n"}, {"input": "100 343\r\n999 284 486 785 176 742 856 415 992 601 600 122 460 214 338 92 627 913...
false
stdio
null
true
106/B
106
B
PyPy 3-64
TESTS
24
122
0
197306183
n = int(input()) index = 0 prevSpeed = 0 prevRAM = 0 prevHDD = 0 prevCost = float("inf") for i in range(n): speed, ram, hdd, cost = map(int, input().split()) if (speed > prevSpeed and ram > prevRAM and hdd > prevHDD): index = i+1 prevCost = cost prevHDD = hdd prevRAM = ram ...
55
92
0
162563573
# n samples n=int(input()) input_array=[] # inputs - speed, ram, hdd and cost are integers for i in range(n): S,R,H,C=map(int,input().split()) input_array.append((S,R,H,C)) outdated=[] for i in range(n): for j in range(n): if(input_array[i][0]<input_array[j][0] and input_array[i][1]<input_array[j]...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
637/A
637
A
Python 3
TESTS
45
187
0
16695865
n = int(input()) like = list(map(int, input().split())) indet = [] for i in range(n): if like[i] not in indet: indet.append(like[i]) uch = [0] * len(indet) uchkol = [0] * len(indet) for i in range(len(indet)): uch[i] = like.count(indet[i]) ma = max(uch) for i in range(len(indet)): if uch[i] == ma:...
65
46
0
151395184
n = int(input()) a = input() lst = a.split(' ') dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 _max = 0 for p in dic: _max = max(_max,dic[p]) newdic = {} for p in dic: if dic[p] == _max: newdic.setdefault(p,dic[p]) i = n-1 while len(newdic)>1: if(lst[i] in newdic): del ...
VK Cup 2016 - Qualification Round 1
CF
2,016
1
256
Voting for Photos
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the total likes to the published photoes. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Print the identifier of the photo which won the elections.
null
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). Thus, the winner is the photo with identifier 2, as it got: - more likes than the photo with id 3; - as many likes as the photo with id 1, but the ...
[{"input": "5\n1 3 2 2 1", "output": "2"}, {"input": "9\n100 200 300 200 100 300 300 100 200", "output": "300"}]
1,000
["*special", "constructive algorithms", "implementation"]
65
[{"input": "5\r\n1 3 2 2 1\r\n", "output": "2\r\n"}, {"input": "9\r\n100 200 300 200 100 300 300 100 200\r\n", "output": "300\r\n"}, {"input": "1\r\n5\r\n", "output": "5\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1000000\r\n"}, {"input": "5\r\n1 3 4 2 2\r\n", "output": "2\r\n"}, {"input": "10\r\n2 1 2 3 1 5 8 7 4 ...
false
stdio
null
true
524/B
524
B
Python 3
PRETESTS
4
62
0
10384027
def s(): w = 0 for i in l: w += i[0] max = 0 for i in l: if i[1] > max: max = i[1] s1 = w * max return s1 n = int(input()) l = [] for i in range(n): x, y = map(int, input().split()) l.append([x, y]) for i in range(n): x = s() l[i][0], l[i][1] = l[i][1...
60
530
0
10384388
n = int(input()) ar = [] for i in range(n): a, b = map(int, input().split()) ar.append((a, b)) l = 0 hmin = 0 for i in ar: hmin = max(hmin, min(i[0], i[1])) s = 10000000000000 for h in range(hmin, 1001): l = 0 for i in ar: if i[0] > h: l += i[0] elif i[1] > h: ...
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
48/D
48
D
Python 3
TESTS
22
62
5,734,400
34694292
from collections import Counter def permutations(n, array): perms = [] counter = Counter(array) perms = [[] for x in range(counter.most_common(1)[0][1])] sorted_a = sorted(array) prev = 0 j = 0 for i in range(0, len(sorted_a)): if sorted_a[i] == prev: j = j+1 elif sorted_a[i] == prev + 1: j = 0 e...
60
140
13,926,400
209069477
import sys input = sys.stdin.readline n = int(input()) l = list(map(int, input().split())) if (max(l) > n): print(-1) exit() cnt = [0]*(n+1) ans = [0]*(n+1) for i in range(n): cnt[l[i]] += 1 ans[i] = cnt[l[i]] for i in range(1, n): if cnt[i] < cnt[i+1]: print(-1) exit() print(cnt[1])...
School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules)
ICPC
2,010
1
256
Permutations
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took ...
The first line contains an integer n (1 ≤ n ≤ 105). The next line contains the mixed array of n integers, divided with a single space. The numbers in the array are from 1 to 105.
If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain n numbers, corresponding to the elements of the given array. If the i-th element belongs to the first permutation...
null
In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth el...
[{"input": "9\n1 2 3 1 2 1 4 2 5", "output": "3\n3 1 2 1 2 2 2 3 2"}, {"input": "4\n4 3 2 1", "output": "1\n1 1 1 1"}, {"input": "4\n1 2 2 3", "output": "-1"}]
1,500
["greedy"]
60
[{"input": "9\r\n1 2 3 1 2 1 4 2 5\r\n", "output": "3\r\n1 1 1 2 2 3 1 3 1 "}, {"input": "4\r\n4 3 2 1\r\n", "output": "1\r\n1 1 1 1 "}, {"input": "4\r\n1 2 2 3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "1\r\n2\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
import sys from collections import defaultdict, Counter 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.read().splitlines() n = int(lines[0]) arr = list(map(int, lines[1].split())) with open(output_...
true
301/A
301
A
PyPy 3-64
TESTS
3
92
0
172061641
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().strip() n, a = int(input()), array('i', [int(x) for x in input().split()]) neg = len([x for x in a if x < 0]) for i in range(n * 2 - 1): if a[i] < 0: a[i] = -a[i] if n > 2 or neg in (2, 0): print(sum([abs(x) for x...
49
93
102,400
3677906
n = int(input()) a = list(map(int, input().split())) abs_a = [abs(v) for v in a] neg = sum(v < 0 for v in a) if n % 2 == 1 or neg % 2 == 0 or any(v == 0 for v in a): print(sum(abs_a)) else: print(sum(abs_a) - 2 * min(abs_a))
Codeforces Round 182 (Div. 1)
CF
2,013
2
256
Yaroslav and Sequence
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements c...
The first line contains an integer n (2 ≤ n ≤ 100). The second line contains (2·n - 1) integers — the array elements. The array elements do not exceed 1000 in their absolute value.
In a single line print the answer to the problem — the maximum sum that Yaroslav can get.
null
In the first sample you do not need to change anything. The sum of elements equals 150. In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100.
[{"input": "2\n50 50 50", "output": "150"}, {"input": "2\n-1 -100 -1", "output": "100"}]
1,800
["constructive algorithms"]
49
[{"input": "2\r\n50 50 50\r\n", "output": "150\r\n"}, {"input": "2\r\n-1 -100 -1\r\n", "output": "100\r\n"}, {"input": "3\r\n-959 -542 -669 -513 160\r\n", "output": "2843\r\n"}, {"input": "4\r\n717 473 344 -51 -548 703 -869\r\n", "output": "3603\r\n"}, {"input": "5\r\n270 -181 957 -509 -6 937 -175 434 -625\r\n", "outpu...
false
stdio
null
true
301/A
301
A
Python 3
TESTS
5
124
5,632,000
34192441
n = int(input()) a=[int(x) for x in input().split()] count=0 for i in range(2*n-1): if (a[i]<0): count+=1 if (n%2==0 and count%2!=0): if (a[i] < 0): a[i] = a[i]*(-1) a = sorted(a) a[0] = a[0]*(-1) print(sum(a)) else: for i in range(2*n-1): if (a[i]<0): a[i]=a...
49
124
0
5342969
n, t = int(input()), list(map(int, input().split())) p = list(map(abs, t)) s = sum(p) if n & 1 == 0 and len([0 for i in t if i < 0]) & 1: s -= 2 * min(p) print(s)
Codeforces Round 182 (Div. 1)
CF
2,013
2
256
Yaroslav and Sequence
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements c...
The first line contains an integer n (2 ≤ n ≤ 100). The second line contains (2·n - 1) integers — the array elements. The array elements do not exceed 1000 in their absolute value.
In a single line print the answer to the problem — the maximum sum that Yaroslav can get.
null
In the first sample you do not need to change anything. The sum of elements equals 150. In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100.
[{"input": "2\n50 50 50", "output": "150"}, {"input": "2\n-1 -100 -1", "output": "100"}]
1,800
["constructive algorithms"]
49
[{"input": "2\r\n50 50 50\r\n", "output": "150\r\n"}, {"input": "2\r\n-1 -100 -1\r\n", "output": "100\r\n"}, {"input": "3\r\n-959 -542 -669 -513 160\r\n", "output": "2843\r\n"}, {"input": "4\r\n717 473 344 -51 -548 703 -869\r\n", "output": "3603\r\n"}, {"input": "5\r\n270 -181 957 -509 -6 937 -175 434 -625\r\n", "outpu...
false
stdio
null
true
350/E
350
E
PyPy 3
TESTS
2
218
29,184,000
88390727
import sys n, m, k = list(map(int, input().split())) if (m > n*(n-1)//2 - k + 1 or k == n): print(-1) sys.exit() def add_edge(i, j): global m if (m <= 0): return print(i, j) m-=1 mark = list(map(int, input().split())) notmark = [] for i in range(1, n+1): if i in mark: continue notmar...
62
560
3,584,000
4646806
#!/usr/bin/python3 def readln(): return tuple(map(int, input().split())) n, m, k = readln() a = sorted(readln()) if k == n: print(-1) else: b = [] for _ in range(1, n + 1): if _ not in a: b.append(_) uses = [[0]*(n + 1) for _ in range(n + 1)] if b[0] == 1: uses[a[0]][a[...
Codeforces Round 203 (Div. 2)
CF
2,013
1
256
Wrong Floyd
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it. Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, contai...
The first line of the input contains three integers n, m, k (3 ≤ n ≤ 300, 2 ≤ k ≤ n , $$n-1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertexes, the number of edges and the number of marked vertexes. The second line of the input contains k space-separated integers a1, a2, ... ak (1 ≤ ai ≤ n) — the numbers of the ...
If the graph doesn't exist, print -1 on a single line. Otherwise, print m lines, each containing two integers u, v — the description of the edges of the graph Valera's been looking for.
null
null
[{"input": "3 2 2\n1 2", "output": "1 3\n2 3"}, {"input": "3 3 2\n1 2", "output": "-1"}]
2,200
["brute force", "constructive algorithms", "dfs and similar", "graphs"]
62
[{"input": "3 2 2\r\n1 2\r\n", "output": "1 3\r\n2 3\r\n"}, {"input": "3 3 2\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "300 43056 2\r\n5 6\r\n", "output": "5 1\n 6 ...
false
stdio
import sys from collections import deque def valeras_algorithm(n, edges, marked_nodes): INF = float('inf') d = [[INF] * (n+1) for _ in range(n+1)] for i in range(1, n+1): d[i][i] = 0 for u, v in edges: d[u][v] = 1 d[v][u] = 1 marked = set(marked_nodes) for a in marked: ...
true
798/C
798
C
PyPy 3-64
TESTS
5
62
102,400
218411071
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N = int(input()) A = list(map(int, input().split())) gcd = A[0] for a in A[1:]: gcd = math.gcd(gcd, a) if gcd!=1: print('YES') ex...
103
93
13,516,800
182959261
import math n=int(input()) a=list(map(int,input().split())) ret=0 v=a[0] for i in range(1,n): v=math.gcd(v,a[i]) if(v!=1): print("YES\n"+str(0)) exit() for i in range(n): if(a[i]%2==0): continue elif(i+1==n): ret+=2 else: if(a[i+1]%2==0): ret+=2 else: ...
Codeforces Round 410 (Div. 2)
CF
2,017
2
256
Mike and gcd problem
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. $${ \operatorname* { g c d } } ( b _ { 1 }, b _ { 2 }, \ldots, b _ { n } ) > 1$$. Mike wants to change his sequence in order to make it beautiful. In on...
The first line contains a single integer n (2 ≤ n ≤ 100 000) — length of sequence A. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.
Output on the first line "YES" (without quotes) if it is possible to make sequence A beautiful by performing operations described above, and "NO" (without quotes) otherwise. If the answer was "YES", output the minimal number of moves needed to make sequence A beautiful.
null
In the first example you can simply make one move to obtain sequence [0, 2] with $$\gcd(0, 2) = 2$$. In the second example the gcd of the sequence is already greater than 1.
[{"input": "2\n1 1", "output": "YES\n1"}, {"input": "3\n6 2 4", "output": "YES\n0"}, {"input": "2\n1 3", "output": "YES\n1"}]
1,700
["dp", "greedy", "number theory"]
103
[{"input": "2\r\n1 1\r\n", "output": "YES\r\n1\r\n"}, {"input": "3\r\n6 2 4\r\n", "output": "YES\r\n0\r\n"}, {"input": "2\r\n1 3\r\n", "output": "YES\r\n1\r\n"}, {"input": "9\r\n57 30 28 81 88 32 3 42 25\r\n", "output": "YES\r\n8\r\n"}, {"input": "2\r\n8 77\r\n", "output": "YES\r\n2\r\n"}, {"input": "4\r\n92 46 3 21\r\...
false
stdio
null
true
359/A
359
A
Python 3
TESTS
33
108
6,963,200
88738737
n, m = map(int, input().split()) l = [input().split() for i in range(n)] x = [x for x in l if '1' in x] print([4, 2][0 in [l.index(a) for a in x] or n-1 in [l.index(a) for a in x] or 0 in [a.index('1') for a in x] or '1' in [a[m-1] for a in x]])
37
46
0
138941206
n, m = list(map(int, input().split())) table = [] for _ in range(n): table.append(list(map(int, input().split()))) shortcut = False if 1 in table[0] or 1 in table[n-1]: shortcut = True else: for row in table[1:n-1]: if row[0] or row[m-1]: shortcut = True break i...
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Table
Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1...
The first line contains exactly two integers n, m (3 ≤ n, m ≤ 50). Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one c...
Print a single number — the minimum number of operations Simon needs to carry out his idea.
null
In the first sample, the sequence of operations can be like this: - For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choos...
[{"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "4"}, {"input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0", "output": "2"}]
1,000
["constructive algorithms", "greedy", "implementation"]
37
[{"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "4\r\n"}, {"input": "4 3\r\n0 0 0\r\n0 0 1\r\n1 0 0\r\n0 0 0\r\n", "output": "2\r\n"}, {"input": "50 4\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 1 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0 0 0 0\r\n0...
false
stdio
null
true
364/A
364
A
PyPy 3
TESTS
4
686
78,848,000
81891306
from collections import Counter a=int(input()) string=input() arr=[0] count1=0 count2=0 for i in range(len(string)): arr+=[int(string[i])] for i in range(1,len(arr)): arr[i]+=arr[i-1] #print(arr) temparr=[] #sumset.add(arr[0]) for i in range(len(arr)): for j in range(i+1,len(arr)): temparr+=[(arr[j]-arr[i])] ...
83
452
12,800,000
78630717
import sys from math import log2,floor,ceil,sqrt # import bisect # from collections import deque Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(...
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
364/A
364
A
PyPy 3
TESTS
4
560
32,768,000
127134047
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush # from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect...
83
639
31,436,800
126654605
# link: https://codeforces.com/problemset/problem/364/A from collections import defaultdict for _ in range(1): a = int(input()) values = [int(i) for i in input()] ans = 0 memo = defaultdict(int) for i in range(len(values)): total = 0 for j in range(i, len(values)): tota...
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
275/B
275
B
PyPy 3-64
TESTS
35
218
9,216,000
185028195
w,h=map(int,input().split()) g=[input() for _ in range(w)] p=[[(-1,-1)]*h for _ in range(w)] def find(a): ax,ay=a if p[ax][ay]==(-1,-1):return a p[ax][ay]=find(p[ax][ay]) return p[ax][ay] def join(a,b): ax,ay=find(a) bx,by=find(b) if (ax,ay)==(bx,by):return p[ax][ay]=(bx,by) for i in range(w): for j i...
46
124
6,963,200
126497023
import sys def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, 'r') n, m = map(int, f.readline().split()) grid = list() for _ in range(n): grid.append(f.readline().rstrip()) return n, m, grid def h(t): i, n = 0, len(t...
Codeforces Round 168 (Div. 2)
CF
2,013
2
256
Convex Shape
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the pa...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell.
On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.
null
null
[{"input": "3 4\nWWBW\nBWWW\nWWWB", "output": "NO"}, {"input": "3 1\nB\nB\nW", "output": "YES"}]
1,700
["constructive algorithms", "implementation"]
46
[{"input": "3 4\r\nWWBW\r\nBWWW\r\nWWWB\r\n", "output": "NO\r\n"}, {"input": "3 1\r\nB\r\nB\r\nW\r\n", "output": "YES\r\n"}, {"input": "1 1\r\nB\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nB\r\nB\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nBW\r\n", "output": "YES\r\n...
false
stdio
null
true
691/D
691
D
PyPy 3
TESTS
20
3,634
105,267,200
84892489
import sys input=sys.stdin.readline def make_set(v): parent[v]=v def find_set(v): if v == parent[v]: return v parent[v]=find_set(parent[v]) return parent[v] def union_sets(a,b): a = find_set(a) b = find_set(b) if a != b: if size[a]<size[b]: a,b=b,a par...
39
2,698
191,385,600
92765277
import sys n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split(' ')) a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split(' '))) adj = [[] for _ in range(n)] for u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): adj[u-1].append(v-1) adj[v-1].append(u-1...
Educational Codeforces Round 14
ICPC
2,016
5
256
Swaps in Permutation
You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get? Let p and q be two permutations of the numbers 1, 2, ..., n. p i...
The first line contains two integers n and m (1 ≤ n, m ≤ 106) — the length of the permutation p and the number of pairs of positions. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the last m lines contains two integers (aj, bj) (1 ≤ aj, bj ≤ n) — the pairs o...
Print the only line with n distinct integers p'i (1 ≤ p'i ≤ n) — the lexicographically maximal permutation one can get.
null
null
[{"input": "9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9", "output": "7 8 9 4 5 6 1 2 3"}]
1,700
["dfs and similar", "dsu", "math"]
39
[{"input": "9 6\r\n1 2 3 4 5 6 7 8 9\r\n1 4\r\n4 7\r\n2 5\r\n5 8\r\n3 6\r\n6 9\r\n", "output": "7 8 9 4 5 6 1 2 3\r\n"}, {"input": "1 1\r\n1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 10\r\n2 1\r\n2 1\r\n1 2\r\n1 1\r\n2 1\r\n1 1\r\n2 1\r\n1 1\r\n1 1\r\n2 1\r\n2 1\r\n", "output": "2 1\r\n"}, {"input": "3 10\r\n1 2 3\...
false
stdio
null
true
549/A
549
A
Python 3
TESTS
15
61
0
114303212
n, m = map(int, input().split()) s, count, a = '', 0, 'face' p1, p2, p3, p4 = 0, 1, m, m+1 for _ in range(n): s += input() if n<2 or m<2: print(count) else: while 1: x = '' x += s[p1]+s[p2]+s[p3]+s[p4] if sorted(x)==sorted(a): count+=1 if p4 == n*m-1: break if p2 == m-1: p1+=2; p2+=2; p3+=2; p4+=...
37
46
0
136251791
def checkFace(a): a.sort() if a[0]=='a' and a[1]=='c' and a[2]=='e' and a[3]=='f': return True return False n,m=[int(x) for x in input().split()] lst=[] for i in range(n): lst.append(input()) if min(n,m)==1: print(0) else: res=0 for i in range(0,n-1): for j in range(0,m-1): if checkFace([lst...
Looksery Cup 2015
CF
2,015
1
256
Face Detection
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 ×...
The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters.
In the single line print the number of faces on the image.
null
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In th...
[{"input": "4 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1"}, {"input": "4 2\nxx\ncf\nae\nxx", "output": "1"}, {"input": "2 3\nfac\ncef", "output": "2"}, {"input": "1 4\nface", "output": "0"}]
900
["implementation", "strings"]
37
[{"input": "4 4\r\nxxxx\r\nxfax\r\nxcex\r\nxxxx\r\n", "output": "1\r\n"}, {"input": "4 2\r\nxx\r\ncf\r\nae\r\nxx\r\n", "output": "1\r\n"}, {"input": "2 3\r\nfac\r\ncef\r\n", "output": "2\r\n"}, {"input": "1 4\r\nface\r\n", "output": "0\r\n"}, {"input": "5 5\r\nwmmwn\r\nlurcm\r\nkeetd\r\nfokon\r\ncxxgx\r\n", "output": "...
false
stdio
null
true
812/E
812
E
PyPy 3-64
TESTS
5
62
0
197322476
from collections import defaultdict import sys def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() N = II() a = list(map(int, input().split())) p = [-1]+l...
76
218
9,830,400
198615426
q= int(input()) a = [int(_) for _ in input().split()] c = [int(_) for _ in input().split()] depth = [0] * (q) for i in range(1,q): depth[i] = depth[c[i-1]-1] + 1 MAX = max(depth) t = 0 store = {} todo = [] p = 0 for i in range(q): if (MAX-depth[i]) % 2 == 0: # odd, useful t ^= a[i] todo.append(a[...
Codeforces Round 417 (Div. 2)
CF
2,017
2
256
Sagheer and Apple Tree
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths have odd ...
The first line will contain one integer n (2 ≤ n ≤ 105) — the number of nodes in the apple tree. The second line will contain n integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the number of apples on each node of the tree. The third line will contain n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n) — the parent of each node of ...
On a single line, print the number of different pairs of nodes (u, v), u ≠ v such that if they start playing after swapping the apples of both nodes, Sagheer will win the game. (u, v) and (v, u) are considered to be the same pair.
null
In the first sample, Sagheer can only win if he swapped node 1 with node 3. In this case, both leaves will have 2 apples. If Soliman makes a move in a leaf node, Sagheer can make the same move in the other leaf. If Soliman moved some apples from a root to a leaf, Sagheer will eat those moved apples. Eventually, Soliman...
[{"input": "3\n2 2 3\n1 1", "output": "1"}, {"input": "3\n1 2 3\n1 1", "output": "0"}, {"input": "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6", "output": "4"}]
2,300
["games", "trees"]
76
[{"input": "3\r\n2 2 3\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3\r\n1 1\r\n", "output": "0\r\n"}, {"input": "8\r\n7 2 2 5 4 3 1 1\r\n1 1 1 4 4 5 6\r\n", "output": "4\r\n"}, {"input": "6\r\n7 7 7 7 7 7\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n3 1 1 1 2 2\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, ...
false
stdio
null
true
101/A
101
A
PyPy 3-64
TESTS
6
154
512,000
146490261
def main_function(): s = list(input()) still_there = [False for i in range(len(s))] k = int(input()) hash_n = {} for i in s: if i in hash_n: hash_n[i] += 1 else: hash_n[i] = 1 another_hash = {} listy_2 = [[]] current_ind = 0 for i in range(len(...
48
154
6,656,000
153815466
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline s = list(input().rstrip()) k = int(input()) cnt = [0] * 26 for i in s: cnt[i - 97] += 1 x = 0 inf = pow(10, 9) + 1 for i in range(26): if not cnt[i]: cnt[i] = inf while True: mi = min(cnt) if x + mi > k: bre...
Codeforces Beta Round 79 (Div. 1 Only)
CF
2,011
2
256
Homework
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to l...
The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the number k (0 ≤ k ≤ 105).
Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more than k characters. Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly m distinct characters. The...
null
In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length. In the second sample you are allowed to delete 4 characters. You cann...
[{"input": "aaaaa\n4", "output": "1\naaaaa"}, {"input": "abacaba\n4", "output": "1\naaaa"}, {"input": "abcdefgh\n10", "output": "0"}]
1,200
["greedy"]
48
[{"input": "aaaaa\r\n4\r\n", "output": "1\r\naaaaa\r\n"}, {"input": "abacaba\r\n4\r\n", "output": "1\r\naaaa\r\n"}, {"input": "abcdefgh\r\n10\r\n", "output": "0\r\n\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\n19\r\n", "output": "1\r\naaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "abcdefghijjihgedcba\r\n0\r\n", "output": "10\r\na...
false
stdio
import sys from collections import Counter def is_subsequence(t, s): it = iter(s) try: for c in t: while next(it) != c: pass return True except StopIteration: return False def compute_min_m(s, k): total = len(s) required_sum = total - k if re...
true
251/B
251
B
PyPy 3-64
TESTS
9
92
512,000
161132836
import sys from array import array def move_up(k): a = array('i', range(1, n + 1)) while k and a != final: k -= 1 tem = array('i') for i in range(n): tem.append(a[q[i] - 1]) a = tem return k & 1 == 0 and a == final def move_down(k): a = array('i', range(1...
95
218
1,433,600
109939158
n,k=map(int,input().strip().split()) a=list(map(int,input().strip().split())) b=list(map(int,input().strip().split())) ups = [[i+1 for i in range(n)]] downs = [[i+1 for i in range(n)]] def apply(arr): out = [0]*n for i in range(n): out[i] = arr[a[i]-1] return out def unapply(arr): out = [0]*n ...
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
401/A
401
A
Python 3
TESTS
32
124
307,200
81152109
n , x = map(int , input().split()) l =list(map(int , input().split())) ans = sum(l) ans = -ans if ans <0 else ans if not ans%x : print(ans//2) else : print(ans//x+1)
47
46
0
149443191
n,x=map(int,input().split()) r=[*map(int,input().split())] print(-(-abs(sum(r))//x))
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time pla...
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Print a single number — the answer to the problem.
null
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
[{"input": "3 2\n-1 1 2", "output": "1"}, {"input": "2 3\n-2 -2", "output": "2"}]
800
["implementation", "math"]
47
[{"input": "3 2\r\n-1 1 2\r\n", "output": "1\r\n"}, {"input": "2 3\r\n-2 -2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "15 5\r\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\r\n", "output": "4\r\n"}, {"input": "15 16\r\n-15 -5 -15...
false
stdio
null
true
1003/F
1003
F
PyPy 3-64
TESTS
5
92
2,150,400
220856226
# https://codeforces.com/contest/1003 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n = int(input()) s = input() w = s.split() max_savings = 0 for i in range(n - 1): for j in range(i + 1, n): if w[i] == w[j]: k = 1 l = len(w[i]) while i + k < j ...
85
109
5,120,000
170938087
n = int(input()) W = list(map(str, input().split())) allSum = n-1 for w in W: allSum += len(w) eq = [[False]*n for i in range(n)] for i in range(n): eq[i][i] = True for j in range(i): eq[i][j] = (W[i]==W[j]) eq[j][i] = (W[i]==W[j]) dp = [[0]*n for i in range(n)] for i in range(n-1, -1, -1...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
1003/F
1003
F
PyPy 3-64
TESTS
5
108
2,560,000
140172840
import sys input = sys.stdin.readline def main(): n = int(input()) S = input().strip() ma = len(S) S = S.split() T = [] se = set(S) lst = sorted(se) dic = {l:i for i, l in enumerate(lst)} length = {chr(i):len(l) for i, l in enumerate(lst)} for s in S: T.append(chr(dic[s]...
85
155
9,523,200
220862013
# https://codeforces.com/contest/1003 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n = int(input()) s = input() # word list w = s.split() # dict: word to index wd = {} for x in w: if x not in wd: wd[x] = len(wd) # number of distinct words nw = len(wd) # length of i-th word wl =...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
1003/F
1003
F
PyPy 3
TESTS
5
109
22,835,200
126814783
from collections import deque import sys input = sys.stdin.readline def z_algorithm(): m = len(w) z = [0] * m i, j = 1, 0 while i < m: while i + j < m and w[j] == w[i + j]: j += 1 z[i] = j if not j: i += 1 continue l = 1 while ...
85
202
23,552,000
126820663
from collections import deque import sys input = sys.stdin.readline def z_algorithm(): m = len(w) z = [0] * m z[0] = m i, j = 1, 0 while i < m: while i + j < m and w[j] == w[i + j]: j += 1 z[i] = j if not j: i += 1 continue l = 1 ...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
1003/F
1003
F
PyPy 3
TESTS
5
171
2,355,200
93404042
n=int(input()) s=input().split() flag=[[s[i]!=s[j] for j in range(n)]for i in range(n)] b=[0]+[len(i)-1 for i in s] for i in range(n):b[i+1]+=b[i] ans=0 for i in range(n-1): for j in range(i+1,n): t=min(j-i+1,n-j) for k in range(t): if flag[i+k][j+k]: break ans=max(ans,b[i+k+1]-b[i]+k) pri...
85
109
5,120,000
170938087
n = int(input()) W = list(map(str, input().split())) allSum = n-1 for w in W: allSum += len(w) eq = [[False]*n for i in range(n)] for i in range(n): eq[i][i] = True for j in range(i): eq[i][j] = (W[i]==W[j]) eq[j][i] = (W[i]==W[j]) dp = [[0]*n for i in range(n)] for i in range(n-1, -1, -1...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
1003/F
1003
F
PyPy 3
TESTS
5
311
22,323,200
85279155
from collections import * n = int(input()) s = list(input().split()) mx = 0 for i in range(n): for j in range(i+1,n+1): S = " ".join(s[i:j]) T = " ".join(s[j:]) if(S in T): x = len(" ".join(s[i:j]))-(j-i) mx = max(mx,x) l = len(" ".join(s)) print(l-2*mx)
85
155
9,523,200
220862013
# https://codeforces.com/contest/1003 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n = int(input()) s = input() # word list w = s.split() # dict: word to index wd = {} for x in w: if x not in wd: wd[x] = len(wd) # number of distinct words nw = len(wd) # length of i-th word wl =...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
894/C
894
C
PyPy 3-64
TESTS
14
77
1,536,000
221440165
from sys import exit from math import gcd m=int(input()) s={int(e) for e in input().split()} for x in s: for y in s: if gcd(x,y) not in s: print(-1) exit() print(m) print(*s)
56
46
0
174593005
n=int(input()) a=list(map(int,input().split())) for i in range(1,n): if a[i]%a[0]:exit(print(-1)) print(2*n) for i in range(n):print(a[0],a[i],end=' ')
Codeforces Round 447 (Div. 2)
CF
2,017
1
256
Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S. The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence. We can show that if a solution exists, then there is a so...
null
In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n.
[{"input": "4\n2 4 6 12", "output": "3\n4 6 12"}, {"input": "2\n2 3", "output": "-1"}]
1,900
["constructive algorithms", "math"]
56
[{"input": "4\r\n2 4 6 12\r\n", "output": "7\r\n2 2 4 2 6 2 12"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 6\r\n", "output": "3\r\n1 1 6"}, {"input": "3\r\n1 2 7\r\n", "output": "5\r\n1 1 2 1 7"}, {"input": "1\r\n1\r\n", "output": "1\r\n1"}, {"input": "2\r\n1 10\r\n", "output": "3\r\n1 1 10"}, {...
false
stdio
import sys from math import gcd def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f if line.strip()] def main(input_path, output_path, sub_path): input_lines = read_file(input_path) m = int(input_lines[0]) S = set(map(int, input_lines[1].split())) sub_li...
true
761/C
761
C
PyPy 3-64
TESTS
5
77
2,969,600
174925835
n,m = map(int,input().split()) l = [{'a':m,'*':m,'1':m} for i in range(n)] for i in range(n): s = input() for j in range(m): if s[j].isalpha(): l[i]['a'] = min([j,m-j,l[i]['a']]) elif s[j].isnumeric(): l[i]['1'] = min([j,m-j,l[i]['1']]) else: l[i]['*']...
52
62
4,915,200
24314799
n, m = map(int, input().split()) a = ['*', '&', '#'] ans0 = [(10**9, -1)] * n ans1 = [(10**9, -1)] * n ans2 = [(10**9, -1)] * n for i in range(n): s = input() for j in range(m): if s[j] in a: ans0[i] = min(ans0[i], (j, i), (m-j, i)) elif '0' <= s[j] <= '9': ans1[i] = min(...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
1003/F
1003
F
PyPy 3-64
TESTS
15
78
5,120,000
153582275
import os import sys from io import BytesIO, IOBase _str = str str = lambda x=b"": x if type(x) is bytes else _str(x).encode() BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.buffer = BytesIO() ...
85
202
23,552,000
126820663
from collections import deque import sys input = sys.stdin.readline def z_algorithm(): m = len(w) z = [0] * m z[0] = m i, j = 1, 0 while i < m: while i + j < m and w[j] == w[i + j]: j += 1 z[i] = j if not j: i += 1 continue l = 1 ...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
364/A
364
A
PyPy 3
TESTS
4
545
10,547,200
116304412
from collections import defaultdict a=int(input()) s=list(input()) n=len(s) for i in range(n): s[i]=int(s[i]) cs=[0]+s for i in range(1,n+1): cs[i]+=cs[i-1] cnt=defaultdict(int) key=set() for l in range(1,n+1): for r in range(l,n+1): cnt[cs[r]-cs[l-1]]+=1 key.add(cs[r]-cs[l-1]) ans=0 for x in key: if x>...
83
873
10,752,000
103604477
a = int(input()) s = input() sm ={} for i in range(len(s)): for j in range(i,len(s)): if j== i: t = int(s[j]) else: t += int(s[j]) if t in sm: sm[t] += 1 else: sm[t] = 1 if a==0: if 0 in sm: sum_pairs = (len(s)*(len(s)+1))/...
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
364/A
364
A
PyPy 3
TESTS
4
389
10,444,800
193779423
from collections import defaultdict a = int(input()) s = [0]+list(map(int,list(input()))) for i in range(1,len(s)): s[i] += s[i-1] d = defaultdict(int) for i in range(1,len(s)): for j in range(i): d[s[i]-s[j]] += 1 ans = 0 k = 1 while k*k<=a: if a%k == 0: ans+= d[k]*d[a//k]*(1 if k**2 ...
83
935
10,444,800
103485217
a = int(input()) s = input() d = {} for i in range(len(s)): for j in range(i, len(s)): if j == i: t = int(s[j]) else: t += int(s[j]) d[t] = d.get(t, 0) + 1 if a == 0: if 0 in d: cnt_pairs = (len(s) * (len(s) + 1)) // 2 print((d[0] * cnt_pairs) + (d[0] * (cnt_pairs - d[0])...
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
65/B
65
B
Python 3
TESTS
3
93
307,200
84273256
n = int(input()) l = [] for i in range(n): l.append(int(input())) def repair(x, y, r): if(r == 0): return x z = (x % (10 * r)) // r - (y % (10 * r)) // r if(z == 0): return repair(x, y, r // 10) if(x % r >= y % r): return x - z * r else: retur...
43
62
204,800
14319576
n = int(input()) values = [ 1000, 100, 10, 1 ] ranges = [ [1, 2], range(10), range(10), range(10) ] def attempt(previous, digits, x): least = None for i in range(4): for d in ranges[i]: y = x + (d - digits[i]) * values[i] if y <= 2011 and y >= previous and (least == None or y <...
Codeforces Beta Round 60
CF
2,011
1
256
Harry Potter and the History of Magic
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has ...
The first input line contains an integer n (1 ≤ n ≤ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 ≤ yi ≤ 9999).
Print n numbers z1, z2, ..., zn (1000 ≤ zi ≤ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0....
null
null
[{"input": "3\n1875\n1936\n1721", "output": "1835\n1836\n1921"}, {"input": "4\n9999\n2000\n3000\n3011", "output": "1999\n2000\n2000\n2011"}, {"input": "3\n1999\n5055\n2000", "output": "No solution"}]
1,700
["brute force", "greedy", "implementation"]
43
[{"input": "3\r\n1875\r\n1936\r\n1721\r\n", "output": "1075\r\n1136\r\n1221\r\n"}, {"input": "4\r\n9999\r\n2000\r\n3000\r\n3011\r\n", "output": "1999\r\n2000\r\n2000\r\n2011\r\n"}, {"input": "3\r\n1999\r\n5055\r\n2000\r\n", "output": "No solution\r\n"}, {"input": "2\r\n2037\r\n2025\r\n", "output": "1037\r\n2005\r\n"}, ...
false
stdio
null
true
65/B
65
B
PyPy 3
TESTS
6
187
2,457,600
80888468
import time startTimeProblem=time.time() import fileinput, sys, itertools, functools from math import * from bisect import * from heapq import * from collections import * def lcm(a, b): return (a*b)/gcd(a, b) class InputHelper: def __init__(self): self.myinput = fileinput.input() def isLocal(s...
43
124
0
5403846
def f(t, s): r = '2012' x, y = '1' + t[1: ], '2' + t[1: ] if x >= s: r = x elif r > y >= s: r = y if t[0] > '2': return r for i in range(1, 4): a, b = t[: i], t[i + 1: ] x, y = a + '0' + b, a + '9' + b if y >= s and x < r: if x < s: x = a + s[i...
Codeforces Beta Round 60
CF
2,011
1
256
Harry Potter and the History of Magic
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has ...
The first input line contains an integer n (1 ≤ n ≤ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 ≤ yi ≤ 9999).
Print n numbers z1, z2, ..., zn (1000 ≤ zi ≤ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0....
null
null
[{"input": "3\n1875\n1936\n1721", "output": "1835\n1836\n1921"}, {"input": "4\n9999\n2000\n3000\n3011", "output": "1999\n2000\n2000\n2011"}, {"input": "3\n1999\n5055\n2000", "output": "No solution"}]
1,700
["brute force", "greedy", "implementation"]
43
[{"input": "3\r\n1875\r\n1936\r\n1721\r\n", "output": "1075\r\n1136\r\n1221\r\n"}, {"input": "4\r\n9999\r\n2000\r\n3000\r\n3011\r\n", "output": "1999\r\n2000\r\n2000\r\n2011\r\n"}, {"input": "3\r\n1999\r\n5055\r\n2000\r\n", "output": "No solution\r\n"}, {"input": "2\r\n2037\r\n2025\r\n", "output": "1037\r\n2005\r\n"}, ...
false
stdio
null
true
1003/F
1003
F
PyPy 3-64
TESTS
5
62
1,945,600
220854094
# https://codeforces.com/contest/1003 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n = int(input()) s = input() # word list w = s.split() # dict: word to index wd = {} for x in w: if x not in wd: wd[x] = len(wd) # number of distinct words nw = len(wd) # length of i-th word wl =...
85
109
5,120,000
170938087
n = int(input()) W = list(map(str, input().split())) allSum = n-1 for w in W: allSum += len(w) eq = [[False]*n for i in range(n)] for i in range(n): eq[i][i] = True for j in range(i): eq[i][j] = (W[i]==W[j]) eq[j][i] = (W[i]==W[j]) dp = [[0]*n for i in range(n)] for i in range(n-1, -1, -1...
Codeforces Round 494 (Div. 3)
ICPC
2,018
1
256
Abbreviation
You are given a text consisting of $$$n$$$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $$$w_i$$$ is the $$$i$$$-th word of text. ...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of words in the text. The next line contains $$$n$$$ space-separated words of the text $$$w_1, w_2, \dots, w_n$$$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed ...
Print one integer — the minimum length of the text after at most one abbreviation.
null
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
[{"input": "6\nto be or not to be", "output": "12"}, {"input": "10\na ab a a b ab a a b c", "output": "13"}, {"input": "6\naa bb aa aa bb bb", "output": "11"}]
2,200
["dp", "hashing", "strings"]
85
[{"input": "6\r\nto be or not to be\r\n", "output": "12\r\n"}, {"input": "10\r\na ab a a b ab a a b c\r\n", "output": "13\r\n"}, {"input": "6\r\naa bb aa aa bb bb\r\n", "output": "11\r\n"}, {"input": "45\r\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of\r\n"...
false
stdio
null
true
549/A
549
A
Python 3
TESTS
15
77
5,632,000
34803166
n,m=map(int,input().split()) a=[] c=['f','a','c','e'] c.sort() for i in range(n): a.extend(list(input())) count=0 for i in range((m*n)-m-1): b=[] if a[i]=='f' or a[i]=='a' or a[i]=='c' or a[i]=='e': b.append(a[i]) b.append(a[i+1]) b.append(a[i+m]) b.append(a[i+m+1]) if le...
37
46
0
139562109
n,m = map(int,input().split()) if (n<2 or m<2): print(0) else: s=[] ans=0 for i in range(n): s.append(input().split()) for a in range(n-1): for b in range(m-1): s1=s[a][0][b]+s[a+1][0][b]+s[a][0][b+1]+s[a+1][0][b+1] if(s1.count('f')==1 & s1.count('a')==1): ...
Looksery Cup 2015
CF
2,015
1
256
Face Detection
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 ×...
The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters.
In the single line print the number of faces on the image.
null
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In th...
[{"input": "4 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1"}, {"input": "4 2\nxx\ncf\nae\nxx", "output": "1"}, {"input": "2 3\nfac\ncef", "output": "2"}, {"input": "1 4\nface", "output": "0"}]
900
["implementation", "strings"]
37
[{"input": "4 4\r\nxxxx\r\nxfax\r\nxcex\r\nxxxx\r\n", "output": "1\r\n"}, {"input": "4 2\r\nxx\r\ncf\r\nae\r\nxx\r\n", "output": "1\r\n"}, {"input": "2 3\r\nfac\r\ncef\r\n", "output": "2\r\n"}, {"input": "1 4\r\nface\r\n", "output": "0\r\n"}, {"input": "5 5\r\nwmmwn\r\nlurcm\r\nkeetd\r\nfokon\r\ncxxgx\r\n", "output": "...
false
stdio
null
true
549/A
549
A
PyPy 3-64
TESTS
15
61
1,638,400
184310312
n = list(map(int,input().split())) face_count = 0 original = [] for i in range(n[0]): original.append(input()) lst = original.copy() faceind = {"f":[] , "a":[], "c":[], "e":[]} for i in range(n[0]): for j in range(n[1]): if str(lst[i][j]) in faceind: faceind[str(lst[i][j])].append((i,j)...
37
46
0
146667592
n, m = map(int, input().split()) v = [] for _ in range(0, n): v.append("x" + input() + "x") v = ['x' * (m + 2)] + v + ['x' * (m + 2)] f = {'f', 'a', 'c', 'e'} t = 0 for i in range(1, n + 1): for j in range(1, m + 1): if set([v[i][j], v[i + 1][j], v[i][j + 1], v[i + 1][j + 1]]) == f: t += 1 p...
Looksery Cup 2015
CF
2,015
1
256
Face Detection
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 ×...
The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters.
In the single line print the number of faces on the image.
null
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In th...
[{"input": "4 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1"}, {"input": "4 2\nxx\ncf\nae\nxx", "output": "1"}, {"input": "2 3\nfac\ncef", "output": "2"}, {"input": "1 4\nface", "output": "0"}]
900
["implementation", "strings"]
37
[{"input": "4 4\r\nxxxx\r\nxfax\r\nxcex\r\nxxxx\r\n", "output": "1\r\n"}, {"input": "4 2\r\nxx\r\ncf\r\nae\r\nxx\r\n", "output": "1\r\n"}, {"input": "2 3\r\nfac\r\ncef\r\n", "output": "2\r\n"}, {"input": "1 4\r\nface\r\n", "output": "0\r\n"}, {"input": "5 5\r\nwmmwn\r\nlurcm\r\nkeetd\r\nfokon\r\ncxxgx\r\n", "output": "...
false
stdio
null
true
71/C
71
C
PyPy 3-64
TESTS
8
62
0
197292265
def sol(c) : for i in div : if i > 2 : s = 0 i = n//i for j in range(c, n, i) : if arr[i] != 1 : break s += 1 else : if s > 2 : return 1 return 0 n = int(input()) arr = list(map(i...
52
77
7,270,400
227748225
import sys import math N = int(sys.stdin.readline().strip()) moods = sys.stdin.readline().strip().split() def check(N, moods): regular = False for k in range(3,(N+1)): if N%k==0: regular = True for start in range(0,int(N/k)): regular = True for i...
Codeforces Beta Round 65 (Div. 2)
CF
2,011
0.5
256
Round Table Knights
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood. Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights ...
The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood.
Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO".
null
null
[{"input": "3\n1 1 1", "output": "YES"}, {"input": "6\n1 0 1 1 1 0", "output": "YES"}, {"input": "6\n1 0 0 1 0 1", "output": "NO"}]
1,600
["dp", "math", "number theory"]
52
[{"input": "3\r\n1 1 1\r\n", "output": "YES"}, {"input": "6\r\n1 0 1 1 1 0\r\n", "output": "YES"}, {"input": "6\r\n1 0 0 1 0 1\r\n", "output": "NO"}, {"input": "10\r\n1 0 1 1 1 0 1 0 1 0\r\n", "output": "YES"}, {"input": "15\r\n0 0 0 1 0 1 1 0 1 0 0 1 0 1 0\r\n", "output": "YES"}, {"input": "29\r\n0 1 0 0 0 1 1 1 1 0 0...
false
stdio
null
true
101/B
101
B
PyPy 3-64
TESTS
7
248
6,451,200
191685856
from collections import defaultdict,Counter,deque import math import bisect from itertools import accumulate, product from math import ceil, log,gcd from functools import lru_cache from sys import stdin, stdout import time import atexit import io import sys import string import heapq import copy import random import bi...
85
1,778
49,971,200
154280537
from bisect import bisect_left from collections import defaultdict d=defaultdict(list) n,m=map(int,input().split()) bus=[] seen=set() for i in range(m): a,b=map(int,input().split()) d[b].append(a) seen.add(b) seen.add(a) seen=sorted(seen) if n not in seen: print(0) else : sum=[0] for el in...
Codeforces Beta Round 79 (Div. 1 Only)
CF
2,011
2
265
Buses
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they f...
The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers si, ti. They are the numbers of starting stops and end stops of the buses (0 ≤ si < ti ≤ n).
Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).
null
The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two. In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0. In the third test Gerald can either get or n...
[{"input": "2 2\n0 1\n1 2", "output": "1"}, {"input": "3 2\n0 1\n1 2", "output": "0"}, {"input": "5 5\n0 1\n0 2\n0 3\n0 4\n0 5", "output": "16"}]
1,700
["binary search", "data structures", "dp"]
85
[{"input": "2 2\r\n0 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3 2\r\n0 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 5\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n", "output": "16\r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "0\r\n"}, {"input": "10 10\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n0 6\r\n0 7\r\n0...
false
stdio
null
true
1005/E2
1005
E2
Python 3
TESTS
2
46
7,168,000
130584177
from itertools import accumulate from collections import Counter s = input() s = s.split(' ') m = int(s[1]) t = input() t = t.split(' ') t = [int(x) for x in t] locations = [] for i in range(len(t)): if t[i] == m: locations.append(i) total_amount = 0 for location in locations: right = [] for i ...
64
139
24,985,600
225536804
import random import sys # sys.setrecursionlimit(10**8)设置最大递归次数 class FastIO: def __init__(self): self.random_seed = random.randint(0, 10 ** 9 + 7) return @staticmethod def read_ints(): return map(int, sys.stdin.readline().strip().split()) @staticmethod def read_list_in...
Codeforces Round 496 (Div. 3)
ICPC
2,018
3
256
Median on Segments (General Case Edition)
You are given an integer sequence $$$a_1, a_2, \dots, a_n$$$. Find the number of pairs of indices $$$(l, r)$$$ ($$$1 \le l \le r \le n$$$) such that the value of median of $$$a_l, a_{l+1}, \dots, a_r$$$ is exactly the given number $$$m$$$. The median of a sequence is the value of an element which is in the middle of ...
The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 2\cdot10^5$$$) — the length of the given sequence and the required value of the median. The second line contains an integer sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2\cdot10^5$$$).
Print the required number.
null
In the first example, the suitable pairs of indices are: $$$(1, 3)$$$, $$$(1, 4)$$$, $$$(1, 5)$$$, $$$(2, 2)$$$, $$$(2, 3)$$$, $$$(2, 5)$$$, $$$(4, 5)$$$ and $$$(5, 5)$$$.
[{"input": "5 4\n1 4 5 60 4", "output": "8"}, {"input": "3 1\n1 1 1", "output": "6"}, {"input": "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3", "output": "97"}]
2,400
["sortings"]
64
[{"input": "5 4\r\n1 4 5 60 4\r\n", "output": "8\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "15 2\r\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3\r\n", "output": "97\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "2 1\r\n2 1\r\n", "output": "2\r\n...
false
stdio
null
true
1000/A
1000
A
PyPy 3-64
TESTS
5
46
0
163717131
#import sys #input = sys.stdin.readline n = int(input()) a = {'XXXS':0, 'XXS':0,'XS':0,'S':0,'M':0,'L':0,'XL':0,'XXL':0,'XXXL':0} b = {'XXXS':0, 'XXS':0,'XS':0,'S':0,'M':0,'L':0,'XL':0,'XXL':0,'XXXL':0} for i in range(n): s = input() a[s] += 1 for i in range(n): s = input() b[s] += 1 for i in b: if ...
37
46
0
140619576
n = int(input()) a = [] for i in range(n): a.append(input()) for i in range(n): a1 = input() if a1 in a: a.remove(a1) print(len(a))
Educational Codeforces Round 46 (Rated for Div. 2)
ICPC
2,018
2
256
Codehorses T-shirts
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from $$$0$$$ to $$$3$$$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" ar...
The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of T-shirts. The $$$i$$$-th of the next $$$n$$$ lines contains $$$a_i$$$ — the size of the $$$i$$$-th T-shirt of the list for the previous year. The $$$i$$$-th of the next $$$n$$$ lines contains $$$b_i$$$ — the size of the $$$i$$$-th T-s...
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
null
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L". In the second example Ksenia should replace "L" in "XXXL" with "S". In the third example lists are equal.
[{"input": "3\nXS\nXS\nM\nXL\nS\nXS", "output": "2"}, {"input": "2\nXXXL\nXXL\nXXL\nXXXS", "output": "1"}, {"input": "2\nM\nXS\nXS\nM", "output": "0"}]
1,200
["greedy", "implementation"]
37
[{"input": "3\r\nXS\r\nXS\r\nM\r\nXL\r\nS\r\nXS\r\n", "output": "2\r\n"}, {"input": "2\r\nXXXL\r\nXXL\r\nXXL\r\nXXXS\r\n", "output": "1\r\n"}, {"input": "2\r\nM\r\nXS\r\nXS\r\nM\r\n", "output": "0\r\n"}, {"input": "1\r\nXXXL\r\nXXXL\r\n", "output": "0\r\n"}, {"input": "1\r\nM\r\nM\r\n", "output": "0\r\n"}, {"input": "4...
false
stdio
null
true
870/B
870
B
Python 3
TESTS
39
93
8,499,200
108880321
a,b = map(int,input().split()) c = list(map(int,input().split())) if b == 1: print(min(c)) elif b > 3: print(max(c)) else: print(max(c[0],c[-1]))
55
77
12,492,800
174028587
nAndK = [int(x) for x in input().split()] n = nAndK[0] k = nAndK[1] array = [int(y) for y in input().split()] if k == 1: print(min(array)) elif k == 2: print(max(array[0], array[n-1])) else: print(max(array))
Technocup 2018 - Elimination Round 2
CF
2,017
1
256
Maximum of Maximums of Minimums
You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? D...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.
null
A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array ...
[{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}]
1,200
["greedy"]
55
[{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {...
false
stdio
null
true
401/A
401
A
Python 3
TESTS
43
109
307,200
90064350
# import sys # sys.stdin=open('input.in','r') # sys.stdout=open('output.out','w') n,m=map(int,input().strip().split()[:2]) k=list(map(int,input().strip().split()[:n])) p=sum(k) l=abs(p)//m if p==n*m: print(m) else: if p>0: if p%m==0: print(1) else: print(l+1) elif p<0: if p%m==0: print(1) else: p...
47
46
0
151595030
n, x = map(int, input().split()) suma = sum(map(int, input().split())) NumCartas = 0 suma = abs(suma) while(suma>0): suma = suma-x NumCartas = NumCartas + 1 print(NumCartas)
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time pla...
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Print a single number — the answer to the problem.
null
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
[{"input": "3 2\n-1 1 2", "output": "1"}, {"input": "2 3\n-2 -2", "output": "2"}]
800
["implementation", "math"]
47
[{"input": "3 2\r\n-1 1 2\r\n", "output": "1\r\n"}, {"input": "2 3\r\n-2 -2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "15 5\r\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\r\n", "output": "4\r\n"}, {"input": "15 16\r\n-15 -5 -15...
false
stdio
null
true
101/B
101
B
Python 3
TESTS
7
92
0
226938875
# read integers n and m n, m = map(int, input().split()) MOD = 10**9 + 7 se = set() se.add(0) se.add(n) buses = [] for i in range(m): s, t = map(int, input().split()) se.add(s) se.add(t) buses.append((s, t)) se = sorted(se) mp = dict() buses_pos = [[] for i in range (len(se))] for i in range(len(se))...
85
1,778
49,971,200
154280537
from bisect import bisect_left from collections import defaultdict d=defaultdict(list) n,m=map(int,input().split()) bus=[] seen=set() for i in range(m): a,b=map(int,input().split()) d[b].append(a) seen.add(b) seen.add(a) seen=sorted(seen) if n not in seen: print(0) else : sum=[0] for el in...
Codeforces Beta Round 79 (Div. 1 Only)
CF
2,011
2
265
Buses
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they f...
The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers si, ti. They are the numbers of starting stops and end stops of the buses (0 ≤ si < ti ≤ n).
Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).
null
The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two. In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0. In the third test Gerald can either get or n...
[{"input": "2 2\n0 1\n1 2", "output": "1"}, {"input": "3 2\n0 1\n1 2", "output": "0"}, {"input": "5 5\n0 1\n0 2\n0 3\n0 4\n0 5", "output": "16"}]
1,700
["binary search", "data structures", "dp"]
85
[{"input": "2 2\r\n0 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3 2\r\n0 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 5\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n", "output": "16\r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "0\r\n"}, {"input": "10 10\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n0 6\r\n0 7\r\n0...
false
stdio
null
true
662/D
662
D
Python 3
TESTS
0
61
0
18906763
k = int(input()) K = [0]*k for i in range(k): K[i]=input()[4:] n_init = 1989 def R(s): return(int("1"*(len(s)-1)+"0")) def M(s): return((int(s) + (-n_init-R(s))%(10**len(s)))) for i in K: print( M(i) + R(i) + n_init )
45
62
5,120,000
17370464
def main(): l = [] for i in range(int(input())): y, n, m = 1989, 0, 1 for d in input()[-1:3:-1]: n += (ord(d) - 48) * m m *= 10 t = n - y % m y += (m + t if t < 0 else t) + m l.append(y - m) print('\n'.join(map(str, l))) if __name__ =...
CROC 2016 - Final Round [Private, For Onsite Finalists Only]
CF
2,016
1
256
International Olympiad
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.
For each abbreviation given in the input, find the year of the corresponding Olympiad.
null
null
[{"input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0", "output": "2015\n12015\n1991\n1989\n1990"}, {"input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999", "output": "1989\n1999\n2999\n9999"}]
2,000
["constructive algorithms", "greedy", "implementation", "math"]
45
[{"input": "5\r\nIAO'15\r\nIAO'2015\r\nIAO'1\r\nIAO'9\r\nIAO'0\r\n", "output": "2015\r\n12015\r\n1991\r\n1989\r\n1990\r\n"}, {"input": "4\r\nIAO'9\r\nIAO'99\r\nIAO'999\r\nIAO'9999\r\n", "output": "1989\r\n1999\r\n2999\r\n9999\r\n"}, {"input": "1\r\nIAO'111110\r\n", "output": "1111110\r\n"}, {"input": "2\r\nIAO'0\r\nIAO...
false
stdio
null
true
641/A
641
A
Python 3
TESTS
6
31
4,505,600
135201916
# Source: https://usaco.guide/general/io n = int(input()) cells = {} target = {} directions = input() distances = list(map(int, input().split(" "))) for i in range(0,n,1): cells[i] = distances[i] if directions[i] == ">" : target[i] = i + distances[i] else: target[i] = i - distances[i] answer = "FINITE" for ...
60
77
7,270,400
147871924
import math def solve(): n = int(input()) s = input() a = list(map(int, input().split())) idx = 0 visited = [False for i in range(n)] while idx >= 0 and idx < n: if visited[idx] == True: print("INFINITE") return visited[idx] = True if s[idx] == '>': idx += a[idx] else: idx -= a[idx] ...
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Grasshopper
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grassh...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip. Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the...
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
null
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
[{"input": "2\n><\n1 2", "output": "FINITE"}, {"input": "3\n>><\n2 1 1", "output": "INFINITE"}]
1,000
["implementation"]
60
[{"input": "2\r\n><\r\n1 2\r\n", "output": "FINITE\r\n"}, {"input": "3\r\n>><\r\n2 1 1\r\n", "output": "INFINITE\r\n"}, {"input": "1\r\n>\r\n1000000000\r\n", "output": "FINITE\r\n"}, {"input": "1\r\n<\r\n1000000000\r\n", "output": "FINITE\r\n"}, {"input": "2\r\n>>\r\n1 1\r\n", "output": "FINITE\r\n"}, {"input": "5\r\n>...
false
stdio
null
true
367/C
367
C
Python 3
TESTS
9
62
0
5375320
def readdata(): #fread = open('input.txt', 'r') global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse = True) summ = [w[0]] ...
41
358
30,924,800
47647355
import sys, bisect (n, m), *s = [map(int, s.split()) for s in sys.stdin.readlines()] g = [n * (n - 1) // 2 + (n - 1) % 2 * (n // 2 - 1) for n in range(1, 2002)] print(sum(sorted([w for _, w in s], reverse=True)[:min(m, bisect.bisect_left(g, n))]))
Codeforces Round 215 (Div. 1)
CF
2,013
1
256
Sereja and the Arrangement of Numbers
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: - consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; - for each pair x, y must exist some position j (1 ≤ j < n), such that at least one...
The first line contains two integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≤ qi, wi ≤ 105). It is guaranteed that all qi are distinct.
In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
[{"input": "5 2\n1 2\n2 3", "output": "5"}, {"input": "100 3\n1 2\n2 1\n3 1", "output": "4"}, {"input": "1 2\n1 1\n2 100", "output": "100"}]
2,000
["graphs", "greedy", "sortings"]
41
[{"input": "5 2\r\n1 2\r\n2 3\r\n", "output": "5\r\n"}, {"input": "100 3\r\n1 2\r\n2 1\r\n3 1\r\n", "output": "4\r\n"}, {"input": "1 2\r\n1 1\r\n2 100\r\n", "output": "100\r\n"}, {"input": "25 29\r\n82963 53706\r\n63282 73962\r\n14996 48828\r\n84392 31903\r\n96293 41422\r\n31719 45448\r\n46772 17870\r\n9668 85036\r\n36...
false
stdio
null
true
441/B
441
B
Python 3
TESTS
4
31
307,200
208251913
import sys input = sys.stdin.readline ############ ---- 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().split())) ############ ---- Input Func...
51
62
0
136544276
n,v=map(int,input().split()) arr=[0 for i in range(3003)] for i in range(n): x,a=map(int,input().split()) arr[x]+=a ans=0 for i in range(1,3003): left=v ans+=min(v,arr[i-1]) left-=min(v,arr[i-1]) ans+=min(left,arr[i]) arr[i]-=min(left,arr[i]) print(ans)
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Fruits
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30...
Print a single integer — the maximum number of fruit that Valera can collect.
null
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sampl...
[{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}]
1,400
["greedy", "implementation"]
51
[{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r...
false
stdio
null
true
761/C
761
C
PyPy 3-64
TESTS
5
46
1,433,600
181308534
n, m = map(int,input().split()) a = [] b = 'qwertyuiopasdfghjklzxcvbnm' c = '1234567890' d = '#*&' for i in range(n): s = input() for j in b: s = s.replace(j,'a') for j in c: s = s.replace(j, '1') for j in d: s = s.replace(j, '#') a.append(s) buk = [(100, 51),(100, 52),(100,5...
52
62
5,632,000
33329321
n,m=map(int,input().split()) a=[] for i in range(65,91): a.append(chr(i+32)) b=[] f1=0 f2=0 f3=0 for i in range(0,10): b.append(str(i)) c=['*','#','&'] l=[] s=[] l1=[1000000000 for i in range(n)] l2=[1000000000 for i in range(n)] l3=[1000000000 for i in range(n)] f=[1 for i in range(n)] ff1=0 ff2=0 ff3=0 for i ...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
761/C
761
C
PyPy 3-64
TESTS
5
46
1,433,600
211909386
from sys import stdin,stdout input = stdin.readline from math import inf n,m = map(int,input().split()) spechar = "*#&" num = "0123456789" alpha = "abcdefghijklmnopqrstuvwxyz" min1 = inf min2 = inf min3 = inf for _ in range(n): str1 = list(map(str,input().split())) str1 = str1[0] for i in range(m): ...
52
77
2,457,600
181054015
def get_min_steps(string, symb): minimum = 1e9 if string[0] == symb: return minimum for lol in range(len(string)): if string[lol] == symb: if lol < minimum: minimum = lol if string[-(lol + 1)] == symb: if lol + 1 < minimum: mini...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
429/D
429
D
Python 3
TESTS
12
982
5,427,200
73169469
def classifyData(individual_1, individual_2): return min(individual_1, individual_2) def computeFitness(individual_i, individual_j): return (individual_i[0] - individual_j[0])**2 + (individual_i[1] - individual_j[1])**2 def bruteForce(features, left, right): min_distance = max_Int for i in range(left,...
47
577
69,529,600
210291541
def closest_pair(points): assert len(points) >= 2 initial_distance = abs(points[0] - points[1]) closest_pair = (0, 1) grid = {} for i, point in enumerate(points): fx = int(point.real / initial_distance) fy = int(point.imag / initial_distance) grid.setdefault((fx, fy), [])....
Codeforces Round 245 (Div. 1)
CF
2,014
2
256
Tricky Function
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
The first line of input contains a single integer n (2 ≤ n ≤ 100000). Next line contains n integers a[1], a[2], ..., a[n] ( - 104 ≤ a[i] ≤ 104).
Output a single integer — the value of mini ≠ j  f(i, j).
null
null
[{"input": "4\n1 0 0 -1", "output": "1"}, {"input": "2\n1 -1", "output": "2"}]
2,200
["data structures", "divide and conquer", "geometry"]
47
[{"input": "4\r\n1 0 0 -1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 -1\r\n", "output": "2\r\n"}, {"input": "100\r\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -74 -36 4 -75 -...
false
stdio
null
true
870/B
870
B
Python 3
TESTS
39
93
14,233,600
31580285
n, k=map(int, input().split()) a=list(map(int, input().split())) maxi=-10000000000000 if k==1: print(min(a)) elif k>3: print(max(a)) else: print(max((a[0]), a[len(a)-1]))
55
77
12,492,800
194053800
_, k = [int(x) for x in input().split()] vals = [int(x) for x in input().split()] if k > 2: # Can make a set that just has the max print(max(vals)) exit() elif k == 1: print(min(vals)) exit() else: # 1 split print(max(vals[0], vals[-1])) exit()
Technocup 2018 - Elimination Round 2
CF
2,017
1
256
Maximum of Maximums of Minimums
You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? D...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.
null
A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array ...
[{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}]
1,200
["greedy"]
55
[{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {...
false
stdio
null
true
761/C
761
C
Python 3
TESTS
51
77
819,200
131705477
import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(3001) input = sys.stdin.readline ng= collections.defaultdict(list) sp = collections.defaultdict...
52
77
4,915,200
24315935
import sys, itertools n, m = [int(x) for x in sys.stdin.readline().split()] lines = [sys.stdin.readline() for _ in range(n)] classes = [ [str(x) for x in range(10)], [chr(x) for x in range(ord('a'), ord('z')+1)], ['#', '*', '&'] ] def steps_to(clazz, line): ltr = list(line[:-1]) rtl = ltr[0:1] +...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
761/C
761
C
Python 3
TESTS
5
124
4,608,000
28552346
def which(c): if '0' <= c <= '9': return 0 elif 'a' <= c <= 'z': return 1 else: return 2 n, m = list(map(int, input().split())) inp = [] for i in range(0, n): s = input() inp.append(s) d = [[10000, 10000, 10000] for i in range(0, n)] for i in range(0, n): for j in range(0, m): x = which(inp[i][j]) d[...
52
77
4,915,200
24565906
n,m=map(int,input().split()) c=[list([])for i in range(3)] for i in range(n): t=input() s='' for i in range(m): if ord(t[i])<43:s+='1' elif ord(t[i])<59:s+='2' else: s+='3' x1=s.find('1') if s.find('1') != -1 else 60 x2=s[::-1].find('1')+1 if s.find('1') != -1 else 60 y1=...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
761/C
761
C
Python 3
TESTS
5
124
716,800
39279203
import string n, m = map(int, input().split(' ')) inp = [] for i in range(n): inp.append(input()) mn = [m]*3 #First for number, second for alphabet and third for special for i in range(n): for j in range(m): index = 2 if inp[i][j] in string.ascii_lowercase: index = 1 elif inp[i][j] in string.di...
52
93
0
214098039
n, m = map(int, input().split()) # Initialize the minimum moves required for each condition digit_moves = [float('inf')] * n lowercase_moves = [float('inf')] * n symbol_moves = [float('inf')] * n for i in range(n): s = input().strip() for j in range(m): # Calculate the minimum moves required to reach ...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
761/C
761
C
Python 3
TESTS
5
109
0
26999957
n, m = map(int, input().split()) v = [[m, m, m] for i in range(n)] for i in range(n): for j, ch in enumerate(input()): p = min(j, m - j) if ch.isdigit(): v[i][0] = min(v[i][0], p) elif ch.islower(): v[i][1] = min(v[i][1], p) else: v[i][2] = min(v[i...
52
93
3,174,400
216550692
n, m = map(int, input().split()) strs = [input() for _ in range(n)] ans = n*m*n dig = [ans for _ in range(n)] la = [ans for _ in range(n)] sp = [ans for _ in range(n)] d = {} for i in "#*&": d[i] = sp for i in "0123456789": d[i] = dig for i in "abcdefghijklmnopqrstuvwxyz": d[i] = la for i in range(n): ...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - T...
The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase E...
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
null
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
[{"input": "3 4\n1**2\na3*0\nc4**", "output": "1"}, {"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3"}]
1,500
["brute force", "dp", "implementation"]
52
[{"input": "3 4\r\n1**2\r\na3*0\r\nc4**\r\n", "output": "1\r\n"}, {"input": "5 5\r\n#*&#*\r\n*a1c&\r\n&q2w*\r\n#a3c#\r\n*&#*&\r\n", "output": "3\r\n"}, {"input": "5 2\r\n&l\r\n*0\r\n*9\r\n*#\r\n#o\r\n", "output": "2\r\n"}, {"input": "25 16\r\nvza**ooxkmd#*ywa\r\ndip#*#&ef&z&&&pv\r\nwggob&&72#*&&nku\r\nrsb##*&jm&#u**te\...
false
stdio
null
true
529/B
529
B
PyPy 3-64
TESTS
13
93
3,584,000
190904774
import sys from math import * from collections import Counter,defaultdict,deque input=sys.stdin.readline mod=10**9+7 def get_ints():return map(int,input().split()) def get_int():return int(input()) def get_array():return list(map(int,input().split())) def input():return sys.stdin.readline().strip() # for _ in range(in...
58
654
10,240,000
154248097
n = int(input()) w, h = [0]*n, [0]*n for i in range(n): w[i], h[i] = map(int, input().split()) def dientich(Hmax): k = n//2 a = [] for i in range(n): if h[i] > Hmax: if k <= 0 or w[i] > Hmax: return 10**9 else: a.append((h[i], w[i])) ...
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)
CF
2,015
2
256
Group Photo 2 (online mirror version)
Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo. Simply speaking, the process of photographing can be describ...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of friends. The next n lines have two integers wi, hi (1 ≤ wi, hi ≤ 1000) each, representing the size of the rectangle, corresponding to the i-th friend.
Print a single integer equal to the minimum possible area of the photo containing all friends if no more than n / 2 of them can lie on the ground.
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,900
["brute force", "greedy", "sortings"]
58
[{"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": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000 1000\r\n", "output": "1000000\r\n"}, {"input": "1\r\n1 1000\r\n", "output": "1...
false
stdio
null
true
870/B
870
B
Python 3
TESTS
32
140
8,601,600
44713059
if __name__ == '__main__': n, k = map(int, input().split()) nums = list(map(int, input().split())) results = [] idx_prev_line = 0 smol = min(nums) big = max(nums) if k == 1: print(smol) elif k == 2: if nums[0] == big or nums[-1] == big: print(big) ...
55
77
12,902,400
226801726
def determine_max(k, a): if k == 1: return min(a) if k == 2: return max(a[0], a[-1]) return max(a) _, k = map(int, input().split()) a = list(map(int, input().split())) print(determine_max(k, a))
Technocup 2018 - Elimination Round 2
CF
2,017
1
256
Maximum of Maximums of Minimums
You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? D...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.
null
A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array ...
[{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}]
1,200
["greedy"]
55
[{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {...
false
stdio
null
true
886/D
886
D
Python 3
TESTS
3
61
0
32432737
n = int(input()) A = [] for i in range (0,n): A = A + [input()] start = [100]*26 end = [100]*26 def num(x): return(ord(x)-ord("a")) def let(x): return(chr(x+ord("a"))) def ans(x): final = [] for i in range (0,n): B = list(A[i]) if len(B) == 1: if start[num(B[0])] == 100: ...
47
109
307,200
95546440
L = {} R = {} S = set() for _ in range(int(input())): s = input() if len(s) == 1: S.add(s) for s1, s2 in zip(s, s[1:]): if s2 != L.get(s1, s2) or s1 != R.get(s2, s1): exit(print('NO')) L[s1], R[s2] = s2, s1 L1, R1 = set(L), set(R) S = S -L1 - R1 for i in L1 - R1: ...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
null
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
[{"input": "4\nmail\nai\nlru\ncf", "output": "cfmailru"}, {"input": "3\nkek\npreceq\ncheburek", "output": "NO"}]
2,000
["constructive algorithms", "graphs", "implementation"]
47
[{"input": "4\r\nmail\r\nai\r\nlru\r\ncf\r\n", "output": "cfmailru\r\n"}, {"input": "3\r\nkek\r\npreceq\r\ncheburek\r\n", "output": "NO\r\n"}, {"input": "1\r\nz\r\n", "output": "z\r\n"}, {"input": "2\r\nab\r\nba\r\n", "output": "NO\r\n"}, {"input": "2\r\nac\r\nbc\r\n", "output": "NO\r\n"}, {"input": "2\r\ncd\r\nce\r\n"...
false
stdio
null
true
996/B
996
B
Python 3
TESTS
24
109
12,800,000
225552810
n=int(input()) a=[int(x) for x in map(int, input().split())] for i in range(n): if a[i]<i+1: a[i] = i else: a[i]=(((a[i]+n-1)//n)*n)+i print(a.index(min(a)) + 1)
60
78
12,288,000
206879916
n=int(input()) a=[int(e) for e in input().split()] imin=0 ymin=10**18 for i in range(n): y=a[i]+(i-a[i]%n)%n if y<ymin: ymin=y imin=i print(imin+1)
Codeforces Round 492 (Div. 2) [Thanks, uDebug!]
CF
2,018
1
256
World Cup
Allen wants to enter a fan zone that occupies a round square and has $$$n$$$ entrances. There already is a queue of $$$a_i$$$ people in front of the $$$i$$$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: - Init...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of entrances. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of people in queues. These numbers do not include Allen.
Print a single integer — the number of entrance that Allen will use.
null
In the first example the number of people (not including Allen) changes as follows: $$$[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$$$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance. In the second example the number of pe...
[{"input": "4\n2 3 2 0", "output": "3"}, {"input": "2\n10 10", "output": "1"}, {"input": "6\n5 2 6 5 7 4", "output": "6"}]
1,300
["binary search", "math"]
60
[{"input": "4\r\n2 3 2 0\r\n", "output": "3\r\n"}, {"input": "2\r\n10 10\r\n", "output": "1\r\n"}, {"input": "6\r\n5 2 6 5 7 4\r\n", "output": "6\r\n"}, {"input": "2\r\n483544186 940350702\r\n", "output": "1\r\n"}, {"input": "10\r\n3 3 3 5 6 9 3 1 7 3\r\n", "output": "7\r\n"}, {"input": "10\r\n0 8 45 88 48 68 28 55 17 ...
false
stdio
null
true
105/A
105
A
Python 3
TESTS
36
218
6,963,200
90758656
n,m,k=map(float,input().split()) n,m,k=int(n),int(m),int(k*100) D=dict() for i in range(n): x=input().split() F=int(x[1])*k//100 if(F>=100): D[x[0]]=F for i in range(m): x=input() if x not in D:D[x]=0 print(len(D)) for x in sorted(D): print(x,D[x])
42
92
0
148633857
n,m,k=map(float,input().split()) n,m,k=round(n),round(m),round(k*100) D=dict() for i in range(n): x=input().split() F=int(x[1])*k//100 if(F>=100): D[x[0]]=F for i in range(m): x=input() if x not in D:D[x]=0 print(len(D)) for x in sorted(D): print(x,D[x])
Codeforces Beta Round 81
CF
2,011
2
256
Transmigration
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes...
The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal p...
Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order.
null
null
[{"input": "5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost", "output": "6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"}]
1,700
["implementation"]
42
[{"input": "5 4 0.75\r\naxe 350\r\nimpaler 300\r\nionize 80\r\nmegafire 120\r\nmagicboost 220\r\nheal\r\nmegafire\r\nshield\r\nmagicboost\r\n", "output": "6\r\naxe 262\r\nheal 0\r\nimpaler 225\r\nmagicboost 165\r\nmegafire 0\r\nshield 0\r\n"}, {"input": "1 1 0.50\r\nstaff 1005\r\nionize\r\n", "output": "2\r\nionize 0\r...
false
stdio
null
true
105/A
105
A
PyPy 3
TESTS
36
310
0
77287076
n, m, k = input().split() n = int(n) m = int(m) k = float(k)*100 k = int(k) d = dict() # print(k) for i in range(n): name, l = input().split() if int(l)<100: continue else: l = (int(l)*k)//100 if l<100: continue d[name] = l for i in range(m): inp = input() if inp in d: continue else: d[inp] = ...
42
92
0
149003722
"""Transmigration""" def main(): a = input().split() n, m, k = int(a[0]), int(a[1]), int(a[2].split('.')[1]) skill_set = list(input().split() for _ in range(int(n))) names = [] for i in range(len(skill_set) - 1, -1, -1): skill_set[i][1] = int(skill_set[i][1]) * k / 100 if skill_set...
Codeforces Beta Round 81
CF
2,011
2
256
Transmigration
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes...
The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal p...
Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order.
null
null
[{"input": "5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost", "output": "6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"}]
1,700
["implementation"]
42
[{"input": "5 4 0.75\r\naxe 350\r\nimpaler 300\r\nionize 80\r\nmegafire 120\r\nmagicboost 220\r\nheal\r\nmegafire\r\nshield\r\nmagicboost\r\n", "output": "6\r\naxe 262\r\nheal 0\r\nimpaler 225\r\nmagicboost 165\r\nmegafire 0\r\nshield 0\r\n"}, {"input": "1 1 0.50\r\nstaff 1005\r\nionize\r\n", "output": "2\r\nionize 0\r...
false
stdio
null
true
621/B
621
B
Python 3
TESTS
7
545
0
64112741
def foo(x): ans = 0 for _ in range(1, x): ans += _ return ans pos = 2001 * [0] neg = 1000 * [0] for i in range(int(input())): x, y = map(int, input().split()) pos[x + y] += 1 neg[x - y] += 1 ans = 0 for j in range(len(neg)): ans += foo(neg[j]) for k in range(len(pos)): ans += f...
68
171
3,993,600
163160405
import sys input = sys.stdin.readline n = int(input()) d1 = [0]*2005 d2 = [0]*2005 for _ in range(n): a, b = map(int, input().split()) d1[a+b] += 1 d2[a-b] += 1 c = 0 for i in d1: c += i*(i-1)//2 for i in d2: c += i*(i-1)//2 print(c)
Codeforces Round 341 (Div. 2)
CF
2,016
2
256
Wet Shark and Bishops
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the onl...
The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops. Each of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position.
Output one integer — the number of pairs of bishops which attack each other.
null
In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
[{"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5", "output": "6"}, {"input": "3\n1 1\n2 3\n3 5", "output": "0"}]
1,300
["combinatorics", "implementation"]
68
[{"input": "5\r\n1 1\r\n1 5\r\n3 3\r\n5 1\r\n5 5\r\n", "output": "6\r\n"}, {"input": "3\r\n1 1\r\n2 3\r\n3 5\r\n", "output": "0\r\n"}, {"input": "3\r\n859 96\r\n634 248\r\n808 72\r\n", "output": "0\r\n"}, {"input": "3\r\n987 237\r\n891 429\r\n358 145\r\n", "output": "0\r\n"}, {"input": "3\r\n411 81\r\n149 907\r\n611 11...
false
stdio
null
true
967/A
967
A
PyPy 3
TESTS
16
171
5,939,200
116424629
import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from itertools import combinations, permutations from datetime import time, timedelta # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // factorial(y))...
34
46
0
177456235
tians, limit = input().split() tians = int(tians) limit = int(limit) hrs = [] mins = [] for number in range(tians): h , m = (input().split()) h = int(h) m = int(m) hrs.append(h) mins.append(m) hnext = 0 mnext = 0 for x in range(len(hrs)): timecomp = (hrs[x] - hnext)*60 + mins[x] - mnext ...
Codeforces Round 477 (rated, Div. 2, based on VK Cup 2018 Round 3)
CF
2,018
1
256
Mind the Gap
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$...
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$,...
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
null
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to inser...
[{"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1"}, {"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50"}, {"input": "3 17\n0 30\n1 0\n12 0", "output": "0 0"}]
1,100
["implementation"]
34
[{"input": "6 60\r\n0 0\r\n1 20\r\n3 21\r\n5 0\r\n19 30\r\n23 40\r\n", "output": "6 1\r\n"}, {"input": "16 50\r\n0 30\r\n1 20\r\n3 0\r\n4 30\r\n6 10\r\n7 50\r\n9 30\r\n11 10\r\n12 50\r\n14 30\r\n16 10\r\n17 50\r\n19 30\r\n21 10\r\n22 50\r\n23 59\r\n", "output": "24 50\r\n"}, {"input": "3 17\r\n0 30\r\n1 0\r\n12 0\r\n",...
false
stdio
null
true
106/B
106
B
Python 3
TESTS
22
124
0
121667215
laptopnum = int(input()) laptopinfos = [] for i in range(laptopnum): laptopinfos.append(input().split()) newlist = [] bestspeed = 0 bestram = 0 besthdd = 0 outdatedspeed = False outdatedram = False outdatedhdd = False popchar = 0 for i in range(laptopnum): newlist.append(laptopinfos[i]) for i in range(laptopn...
55
92
0
165758154
num_inp=lambda: int(input()) arr_inp=lambda: list(map(int,input().split())) sp_inp=lambda: map(int,input().split()) str_inp=lambda:input() I=input n=int(I()) r=list(tuple(map(int,I().split()))for _ in '0'*n) s=set(r) d=set() for a in s: for b in s: y=1 for i in 0,1,2:y=y and a[i]<b[i] if y:break else:d.add(a) p...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
257/C
257
C
PyPy 3-64
TESTS
35
1,558
12,697,600
159726405
import math n = int(input()) l = [] for i in range(n): u, v = list(map(int, input().split())) if(u == 0): if(v > 0): l.append(90) else: l.append(270) elif(u < 0): l.append(180 + math.degrees(math.atan(v / u))) elif(v < 0): l.append(360 + math.degre...
56
622
3,072,000
67587345
import sys from math import atan2, pi def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() if n == 1: print(0) return p = [0]*n for i in range(n): x, y = mints() p[i] = atan2(y, x) p.sort() p.append(p[0]+...
Codeforces Round 159 (Div. 2)
CF
2,013
2
256
View Angle
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of mannequins. Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins ...
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.
null
Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
[{"input": "2\n2 0\n0 2", "output": "90.0000000000"}, {"input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000"}, {"input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000"}, {"input": "2\n2 1\n1 2", "output": "36.8698976458"}]
1,800
["brute force", "geometry", "math"]
56
[{"input": "2\r\n2 0\r\n0 2\r\n", "output": "90.0000000000\r\n"}, {"input": "3\r\n2 0\r\n0 2\r\n-2 2\r\n", "output": "135.0000000000\r\n"}, {"input": "4\r\n2 0\r\n0 2\r\n-2 0\r\n0 -2\r\n", "output": "270.0000000000\r\n"}, {"input": "2\r\n2 1\r\n1 2\r\n", "output": "36.8698976458\r\n"}, {"input": "1\r\n1 1\r\n", "output...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] # Read correct output try: with open(output_path, 'r') as f: correct_lines = f.readlines() if len(correct_lines) != 1: print(0) return ...
true
102/A
102
A
Python 3
TESTS
7
122
0
119719202
import sys from itertools import combinations def solution(pairs, prices): prices_map = {i: price for i, price in enumerate(prices, start=1)} triples = [] for triple in combinations(range(1, len(pairs) + 1), r=3): score = 0 for el in triple: for u, v in pairs: if u == el and v in triple or v == el and ...
32
186
2,048,000
149736386
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m = map(int, input().split()) G = [[0] * (n + 1) for _ in range(n + 1)] a = [0] + list(map(int, input().split())) for _ in range(m): u, v = map(int, input().split()) G[u][v] = 1 G[v][u] = 1 inf = pow(10, 9) + 1 ans = inf for...
Codeforces Beta Round 79 (Div. 2 Only)
CF
2,011
2
256
Clothes
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has i...
The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items ($$3 \leq n \leq 100, 0 \leq m \leq \frac{n(n-1)}{2}$$). Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles. Next m li...
Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).
null
In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not mat...
[{"input": "3 3\n1 2 3\n1 2\n2 3\n3 1", "output": "6"}, {"input": "3 2\n2 3 4\n2 3\n2 1", "output": "-1"}, {"input": "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1", "output": "-1"}]
1,200
["brute force"]
32
[{"input": "3 3\r\n1 2 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 3 4\r\n2 3\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n1 2\r\n2 3\r\n3 4\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "4 3\r\n10 10 5 1\r\n2 1\r\n3 1\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "4 0\r\n9 8 2 10...
false
stdio
null
true
556/B
556
B
Python 3
TESTS
6
62
6,963,200
128354930
n=int(input()) a=list(map(int, input().split())) l=[i for i in range(n)] for i in range(n): if i%2==0: if i==0: a[i]=n-a[i] elif i>=a[i]: a[i]=i-a[i] else: a[i]=n-a[i]+i else: if i<=a[i]: a[i]=a[i]-i else: a[i]=a...
50
46
0
146592101
import sys n=int(input()) a=list(map(int, sys.stdin.readline().strip().split())) nr=n-a[0] for i in range(n): if(i%2==0): a[i]+=nr else: a[i]-=nr a[i]=a[i]%n if a == list(range(n)): print("Yes") else: print("No")
Codeforces Round 310 (Div. 2)
CF
2,015
2
256
Case of Fake Numbers
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers f...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of gears. The second line contains n digits a1, a2, ..., an (0 ≤ ai ≤ n - 1) — the sequence of active teeth: the active tooth of the i-th gear contains number ai.
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
null
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
[{"input": "3\n1 0 0", "output": "Yes"}, {"input": "5\n4 2 1 4 3", "output": "Yes"}, {"input": "4\n0 2 3 1", "output": "No"}]
1,100
["brute force", "implementation"]
50
[{"input": "3\r\n1 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n4 2 1 4 3\r\n", "output": "Yes\r\n"}, {"input": "4\r\n0 2 3 1\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "Yes\r\n"}, {"input": "2\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n2 4 4 1 1\r\n", "output": "Yes\r\n"}, {"input": "10\r\...
false
stdio
null
true
48/D
48
D
PyPy 3-64
TESTS
4
46
0
204063308
import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter,defaultdict N = int(input()) A = list(map(int, input().split())) C = Counter(A) M = max(C.values()) pre = C[1] for i in range(2,M+1): if C[i]>pre: exit(print(-1)) pre = C[i] print(C[1]) cnt = defaultdict(int)...
60
202
7,372,800
154879210
input() p = list(map(int, input().split())) mx = max(p) c = [0]*(mx+1) for i in p: c[i] += 1 if any(c[i]<c[i+1] for i in range(1, mx)): print(-1) exit(0) print(c[1]) for i in p: print(c[i], end=' ') c[i] -= 1 print()
School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules)
ICPC
2,010
1
256
Permutations
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took ...
The first line contains an integer n (1 ≤ n ≤ 105). The next line contains the mixed array of n integers, divided with a single space. The numbers in the array are from 1 to 105.
If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain n numbers, corresponding to the elements of the given array. If the i-th element belongs to the first permutation...
null
In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth el...
[{"input": "9\n1 2 3 1 2 1 4 2 5", "output": "3\n3 1 2 1 2 2 2 3 2"}, {"input": "4\n4 3 2 1", "output": "1\n1 1 1 1"}, {"input": "4\n1 2 2 3", "output": "-1"}]
1,500
["greedy"]
60
[{"input": "9\r\n1 2 3 1 2 1 4 2 5\r\n", "output": "3\r\n1 1 1 2 2 3 1 3 1 "}, {"input": "4\r\n4 3 2 1\r\n", "output": "1\r\n1 1 1 1 "}, {"input": "4\r\n1 2 2 3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "1\r\n2\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
import sys from collections import defaultdict, Counter 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.read().splitlines() n = int(lines[0]) arr = list(map(int, lines[1].split())) with open(output_...
true
556/B
556
B
Python 3
TESTS
47
46
0
157826526
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) if n == 1: print("Yes") elif n == 2: if abs(w[0] - w[1]) != 1: print("No") else: print("Yes") elif n % 2 == 0 and (w[0] + w[1]) % 2 == 0: print("No") else: for i in range(n-2): if w[i]...
50
46
0
149474024
n = int(input()) a = [int(x) for x in input().split()] diff = (n - a[0]) % n for i in range(1, n): if i % 2 == 0: if (a[i] + diff) % n != i: #print((a[i] - diff) % n, i) print("No") exit() else: if (a[i] - diff) % n != i: #print((a[i] - diff) % n, ...
Codeforces Round 310 (Div. 2)
CF
2,015
2
256
Case of Fake Numbers
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers f...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of gears. The second line contains n digits a1, a2, ..., an (0 ≤ ai ≤ n - 1) — the sequence of active teeth: the active tooth of the i-th gear contains number ai.
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.
null
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.
[{"input": "3\n1 0 0", "output": "Yes"}, {"input": "5\n4 2 1 4 3", "output": "Yes"}, {"input": "4\n0 2 3 1", "output": "No"}]
1,100
["brute force", "implementation"]
50
[{"input": "3\r\n1 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n4 2 1 4 3\r\n", "output": "Yes\r\n"}, {"input": "4\r\n0 2 3 1\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "Yes\r\n"}, {"input": "2\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n2 4 4 1 1\r\n", "output": "Yes\r\n"}, {"input": "10\r\...
false
stdio
null
true
888/C
888
C
Python 3
TESTS
18
217
9,318,400
84968813
s=input() se=set(s) if len(se)==len(s): print((len(s)//2)+1) elif len(se)==1: print(1) else: l=2 r=(len(s)//2)+1 if l==r: print(l) else: index={} diff={} for i,j in enumerate(s): index[j]=index.get(j,[]) if len(index[j])<1: ...
51
92
8,908,800
196400787
a = input() b = a string = "qwertyuiopasdfghjklzxcvbnm" count = 0 string2 = "" for j in b: if j in string: string = string.replace(j, "") count += 1 string2 += j if count == 1: print("1") else: answer = len(a) for i in range(count): b = a b = b.replace(strin...
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
257/C
257
C
Python 3
TESTS
41
1,246
9,728,000
24847931
from math import * n,angs = int(input()), [] for _ in range(n): x,y = input().split() t = atan2(float(y),float(x)) if t < 0: t += 2*pi angs.append(t) #print(list(map(degrees,angs))) angs.sort() dif = [] for i in range(len(angs)): al = angs[i]-angs[i-1] if al < 0: al += 2*pi dif.append(al) res = 0 #print(li...
56
716
2,560,000
166436613
from math import * n = int(input()) l = [] for _ in range(n): x,y = map(int,input().split()) deg = atan2(y, x)*180/pi if deg < 0: deg = 360+deg l.append(deg) l.sort() mx = l[0]+360-l[-1] for i in range(1,n): mx = max(mx,l[i]-l[i-1]) print("{:.15f}".format(360-mx))
Codeforces Round 159 (Div. 2)
CF
2,013
2
256
View Angle
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of mannequins. Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins ...
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.
null
Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
[{"input": "2\n2 0\n0 2", "output": "90.0000000000"}, {"input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000"}, {"input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000"}, {"input": "2\n2 1\n1 2", "output": "36.8698976458"}]
1,800
["brute force", "geometry", "math"]
56
[{"input": "2\r\n2 0\r\n0 2\r\n", "output": "90.0000000000\r\n"}, {"input": "3\r\n2 0\r\n0 2\r\n-2 2\r\n", "output": "135.0000000000\r\n"}, {"input": "4\r\n2 0\r\n0 2\r\n-2 0\r\n0 -2\r\n", "output": "270.0000000000\r\n"}, {"input": "2\r\n2 1\r\n1 2\r\n", "output": "36.8698976458\r\n"}, {"input": "1\r\n1 1\r\n", "output...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] # Read correct output try: with open(output_path, 'r') as f: correct_lines = f.readlines() if len(correct_lines) != 1: print(0) return ...
true
802/G
802
G
Python 3
TESTS
7
61
0
139015559
# Fake News s=input() p='heidi' j=1 k=0 while j<len(p) and k<len(s): if s[k]==p[j]: j+=1 k+=1 if j==len(p): print('YES') else: print('NO')
58
46
0
136709831
a=input() try: for i in'heidi': exec('while a[0]!=\''+i+'\':\n\ta=a[1:]\na=a[1:]') print('YES') except: print('NO')
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Fake News (easy)
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string s contains heidi as a subsequence and NO otherwise.
null
A string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p.
[{"input": "abcheaibcdi", "output": "YES"}, {"input": "hiedi", "output": "NO"}]
800
["implementation", "strings"]
58
[{"input": "abcheaibcdi\r\n", "output": "YES"}, {"input": "hiedi\r\n", "output": "NO"}, {"input": "ihied\r\n", "output": "NO"}, {"input": "diehi\r\n", "output": "NO"}, {"input": "deiih\r\n", "output": "NO"}, {"input": "iheid\r\n", "output": "NO"}, {"input": "eihdi\r\n", "output": "NO"}, {"input": "ehdii\r\n", "output":...
false
stdio
null
true
730/H
730
H
Python 3
TESTS
4
62
0
21702315
num_file,num_delete = map(int, input().split()) list_file = [] for i in range(num_file): list_file.append(input()) delete_file = [int(i)-1 for i in input().split()] ans="" delete_list = sorted([list_file[i]for i in delete_file],key=len) tmp = list(delete_list[0]) for i in delete_list[1:]: name = list(i) for...
74
62
2,252,800
159981805
n, m = map(int, input().split()) s = [input() for i in range(n)] indices = set(map(lambda x: int(x)-1, input().split())) lengths = set([len(s[i]) for i in indices]) if len(lengths) != 1: print("No") exit(0) non_indices = set(range(n)) - indices l = lengths.pop() ans = [] for j in range(l): ch = set() for i 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
106/B
106
B
Python 3
TESTS
21
186
6,963,200
86941523
n = int(input()) li = [] se = set() class Computer: def __init__(self, speed, ram, hdd, cost): self.speed = speed self.ram = ram self.hdd = hdd self.cost = cost self.outdated = False def __gt__(self, value): if self.speed > value.speed and self.ram > value.ram ...
55
92
0
169624846
t=int(input()) l=[];ans=1001 for _ in range(t): s1,r1,h1,c1=map(int,input().split()) l1=[s1,r1,h1,c1] l.append(l1) for i in range(t): for j in range(t): if l[i][0]<l[j][0] and l[i][1]<l[j][1] and l[i][2]<l[j][2]: break else: if l[i][3]<ans: ans=l[i][3] ...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
106/B
106
B
PyPy 3
TESTS
21
310
0
81964947
dic = {} list_of_all = [] for t in range(int(input())): ar = input().split(' ') ar = [int(i)for i in ar] dic[ar[-1]] = ar[:-1] list_of_all.append(ar[-1]) max_all = [0,0,0] last_max = 0 pop_list = [] for i in dic: if dic[i][0]>max_all[0] and dic[i][1]>max_all[1] and dic[i][2]>max_all[2]: pop_list.append(last_max...
55
92
0
172273686
import math n=int(input()) speed=[0]*n ram=[0]*n hdd=[0]*n cost=[0]*n result=0 costr=math.inf for i in range(n): speed[i],ram[i],hdd[i],cost[i]=map(int,input().split()) for i in range(n): for j in range(n): if speed[i]<speed[j] and ram[i]<ram[j] and hdd[i]<hdd[j]: break else: ...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
106/B
106
B
Python 3
TESTS
7
92
6,963,200
123673039
n = int(input()) l = [] mspec = [0 for i in range(4)] index = 0 price = 1000 for i in range(n): spec = list(map(int, input().split())) l.append(spec) if spec[0] >= mspec[0] and spec[1] >= mspec[1] and spec[2] >= mspec[2]: mspec = spec for i in range(n): if (l[i][0] >= mspec[0] or l[i][1] >= mspe...
55
92
0
180021220
""" https://codeforces.com/problemset/problem/106/B """ tests = int(input()) laptops = [] for i in range(1, tests + 1): speed, ram, hdd, cost = [int(x) for x in input().split()] laptops.append((cost, i, speed, ram, hdd)) outdated = set() for k, (c, i, s, r, h) in enumerate(laptops): for l, (cc, ii, ss, rr,...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
883/K
883
K
Python 3
TESTS
4
62
0
32542726
n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) a[i][1]+=a[i][0] k=a.index(min(a,key=lambda x:x[1])) s=a[k][1]-a[k][0] for i in range(k+1,n): if a[i][1]-1>a[i-1][1]: a[i][1]=a[i-1][1]+1 if a[i][1]<a[i][0]:exit(print(-1)) s+=a[i][1]-a[i][0] for i in range(k...
109
1,809
15,360,000
230750690
n = int(input()) s = [0]*n g = [0]*n for i in range(n): a,b = map(int,input().split()) s[i] = a g[i] = a+b for i in range(1,n): g[i] = min(g[i],g[i-1]+1) for i in range(n-2,-1,-1): g[i] = min(g[i],g[i+1]+1) ans = 0 for i in range(n): if s[i] <= g[i]: ans += g[i] - s[i] else: ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Road Widening
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street. Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.
In the first line print the total width of lawns which will be removed. In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last. If there is no solution, print the only integer -1 in the first line.
null
null
[{"input": "3\n4 5\n4 5\n4 10", "output": "16\n9 9 10"}, {"input": "4\n1 100\n100 1\n1 100\n100 1", "output": "202\n101 101 101 101"}, {"input": "3\n1 1\n100 100\n1 1", "output": "-1"}]
1,800
["constructive algorithms", "greedy", "implementation"]
109
[{"input": "3\r\n4 5\r\n4 5\r\n4 10\r\n", "output": "16\r\n9 9 10 \r\n"}, {"input": "4\r\n1 100\r\n100 1\r\n1 100\r\n100 1\r\n", "output": "202\r\n101 101 101 101 \r\n"}, {"input": "3\r\n1 1\r\n100 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n21005 10850\r\n27020 13372\r\n28183 3724\r\n22874 13564\r\n27446 11...
false
stdio
null
true
798/C
798
C
PyPy 3-64
TESTS
3
46
0
155809279
from math import gcd n=int(input()) a=list(map(int,input().split())) ans=0 print("YES") cnt=1 if a[0]&1 else 0 g=a[0] for el in a[1:]: g=gcd(g,a[1]) if el&1: cnt+=1 else : ans+=cnt//2+2*(cnt&1) cnt=0 ans+=cnt//2+2*(cnt&1) if g==1: print(ans) else : print(0)
103
124
7,065,600
199148321
import math n = input() s = map(int, input().split()) res = cur = g = 0 for x in s: g = math.gcd(x, g) if (x & 1) == 0: res += math.ceil(cur / 2) + (cur & 1) cur = 0 else: cur += 1 res += math.ceil(cur / 2) + (cur & 1) print("YES") if g == 1: print(res) else: print("0")
Codeforces Round 410 (Div. 2)
CF
2,017
2
256
Mike and gcd problem
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. $${ \operatorname* { g c d } } ( b _ { 1 }, b _ { 2 }, \ldots, b _ { n } ) > 1$$. Mike wants to change his sequence in order to make it beautiful. In on...
The first line contains a single integer n (2 ≤ n ≤ 100 000) — length of sequence A. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.
Output on the first line "YES" (without quotes) if it is possible to make sequence A beautiful by performing operations described above, and "NO" (without quotes) otherwise. If the answer was "YES", output the minimal number of moves needed to make sequence A beautiful.
null
In the first example you can simply make one move to obtain sequence [0, 2] with $$\gcd(0, 2) = 2$$. In the second example the gcd of the sequence is already greater than 1.
[{"input": "2\n1 1", "output": "YES\n1"}, {"input": "3\n6 2 4", "output": "YES\n0"}, {"input": "2\n1 3", "output": "YES\n1"}]
1,700
["dp", "greedy", "number theory"]
103
[{"input": "2\r\n1 1\r\n", "output": "YES\r\n1\r\n"}, {"input": "3\r\n6 2 4\r\n", "output": "YES\r\n0\r\n"}, {"input": "2\r\n1 3\r\n", "output": "YES\r\n1\r\n"}, {"input": "9\r\n57 30 28 81 88 32 3 42 25\r\n", "output": "YES\r\n8\r\n"}, {"input": "2\r\n8 77\r\n", "output": "YES\r\n2\r\n"}, {"input": "4\r\n92 46 3 21\r\...
false
stdio
null
true
802/G
802
G
PyPy 3
TESTS
41
109
0
121023729
a = input() if 'h' in a: b = a[a.index('h'):] if 'e' in b: d = b[b.index('e'):] if 'i' in d: e = d[d.index('i'):] if 'd' in e: f = d[d.index('d'):] if 'i' in f: print('YES') else: prin...
58
46
0
138380487
s=input() n='' for i in s: if i=='h'and n=='': n+=i if i=='e' and n=='h': n+=i if i=='i' and n=='he': n+=i if i=='d' and n=='hei': n+=i if i=='i' and n=='heid': n+=i if n=='heidi': print("YES") else: print("NO")
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Fake News (easy)
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string s contains heidi as a subsequence and NO otherwise.
null
A string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p.
[{"input": "abcheaibcdi", "output": "YES"}, {"input": "hiedi", "output": "NO"}]
800
["implementation", "strings"]
58
[{"input": "abcheaibcdi\r\n", "output": "YES"}, {"input": "hiedi\r\n", "output": "NO"}, {"input": "ihied\r\n", "output": "NO"}, {"input": "diehi\r\n", "output": "NO"}, {"input": "deiih\r\n", "output": "NO"}, {"input": "iheid\r\n", "output": "NO"}, {"input": "eihdi\r\n", "output": "NO"}, {"input": "ehdii\r\n", "output":...
false
stdio
null
true
967/A
967
A
Python 3
TESTS
21
109
7,065,600
37712597
n, s = [int(x) for x in input().split()] t = [] for i in range(n): h, m = [int(x) for x in input().split()] t.append(h * 60 + m) if t[0] >= s + 1: print(0, 0) exit() for i in range(1, n): if t[i] - t[i - 1] >= 2 * s + 2: print((t[i - 1] + s) // 60, (t[i - 1] + s) % 60 + 1) exit() ...
34
46
0
183898706
testcases, gap = input().split() testcases = int(testcases) gap = int(gap) hrs = [] mins = [] for number in range(testcases): h, m = (input().split()) h = int(h) m = int(m) hrs.append(h) mins.append(m) hnext = 0 mnext = 0 for x in range (len(hrs)): timecomp = (hrs[x] - hnext)*60 + mins[x]...
Codeforces Round 477 (rated, Div. 2, based on VK Cup 2018 Round 3)
CF
2,018
1
256
Mind the Gap
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$...
The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$,...
Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
null
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to inser...
[{"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1"}, {"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50"}, {"input": "3 17\n0 30\n1 0\n12 0", "output": "0 0"}]
1,100
["implementation"]
34
[{"input": "6 60\r\n0 0\r\n1 20\r\n3 21\r\n5 0\r\n19 30\r\n23 40\r\n", "output": "6 1\r\n"}, {"input": "16 50\r\n0 30\r\n1 20\r\n3 0\r\n4 30\r\n6 10\r\n7 50\r\n9 30\r\n11 10\r\n12 50\r\n14 30\r\n16 10\r\n17 50\r\n19 30\r\n21 10\r\n22 50\r\n23 59\r\n", "output": "24 50\r\n"}, {"input": "3 17\r\n0 30\r\n1 0\r\n12 0\r\n",...
false
stdio
null
true