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
159/A
159
A
Python 3
TESTS
10
92
307,200
4816184
n, d = map(int, input().split()) f, p, q = [], {}, {} for i in range(n): a, b, t = input().split() t = int(t) p[t] = p.get(t, []) + [(a, b)] for t in p: u = [(a + ' ' + b, b + ' ' + a) for a, b in p[t]] f += [min(x, y) for x, y in u if y in q and t - q[y] <= d] for x, y in u: q[x] = t ...
30
186
5,222,400
17534881
def min_positive_difference(numbers1, numbers2): min_difference = float('inf') if not numbers1 or not numbers2: return min_difference for n in numbers1: for m in numbers2: candidate = abs(n - m) if candidate < min_difference and candidate > 0: min_diff...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
1004/B
1004
B
Python 3
PRETESTS
3
109
0
40004682
n, m = map(int, input().split()) ranges = [] cnt = 0 cnt_z = {} for i in range(m): l, r = map(int, input().split()) rang = (l - 1, r - 1, r - l + 1) ranges.append(rang) cnt_z[rang] = 0 a = [0] * n for i in range(n): need_one = 0 #print(i) for rang in ranges: l, r, len = rang ...
27
62
0
121751874
n, k = list(map(int, input().split())) for _ in range(k): input() print(('10'*n)[:n])
Codeforces Round 495 (Div. 2)
CF
2,018
1
256
Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ pos...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to ...
Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
null
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$; - in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so t...
[{"input": "5 3\n1 3\n2 4\n2 5", "output": "01100"}, {"input": "6 3\n5 6\n1 4\n4 6", "output": "110010"}]
1,300
["constructive algorithms", "greedy", "implementation", "math"]
27
[{"input": "5 3\r\n1 3\r\n2 4\r\n2 5\r\n", "output": "01010\r\n"}, {"input": "6 3\r\n5 6\r\n1 4\r\n4 6\r\n", "output": "010101\r\n"}, {"input": "10 4\r\n3 3\r\n1 6\r\n9 9\r\n10 10\r\n", "output": "0101010101\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "1000 10\r\n3 998\r\n2 1000\r\n1 999\r\n2 1000\...
false
stdio
import sys def read_ints(f): return list(map(int, f.readline().split())) def compute_sum(arrangement, segments): total = 0 for l, r in segments: zeros = arrangement[l-1:r].count('0') ones = (r - l + 1) - zeros total += zeros * ones return total def main(input_path, output_path...
true
29/D
29
D
Python 3
TESTS
3
62
0
218457623
t=int(input()) listt=[-1]*(t+1) for i in range(t-1): a,b=map(int, input().split()) listt[b]=a s=list(map(int,input().split())) done=[0]*(t+1) ans=[] pre=-1 for i in s: parent=listt[i] while pre!=-1 and pre!=parent : ans.append(pre) pre=listt[pre] if done[parent]==1 and pre!=parent: ...
35
154
102,400
213735936
import sys readline = sys.stdin.readline N = int(readline()) tree = [[] for _ in range(N + 1)] weights = [[N + 1 + i, -1] for i in range(N + 1)] def clear_tree(node: int, parent: int): tree[node] = list(set(tree[node]) - {parent}) if len(tree[node]) == 0: return for child in tree[node]: c...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
873/C
873
C
Python 3
TESTS
7
62
5,632,000
33614955
n,m,k=map(int,input().split()) R=[list(map(int,input().split()))for i in range(n)] s=0 t=0 for i in zip(*R): c=0 ps=0 ps2=0 for j in range(n): if i[j]: f=1 for r in range(j+1,min(j+k,n)): f+=i[r] if f>c:c=f;ps2=ps c=max(c,f) ...
20
62
5,529,600
32718730
f = lambda: map(int, input().split()) n, m, k = f() s = d = 0 for t in zip(*[f() for i in range(n)]): p, q = x, y = sum(t[:k]), 0 for a, b in zip(t[:n - k], t[k:]): p += b - a q += a if p > x: x, y = p, q s += x d += y print(s, d)
Educational Codeforces Round 30
ICPC
2,017
1
256
Strange Game On Matrix
Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score ...
The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
null
In the first example Ivan will replace the element a1, 2.
[{"input": "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1", "output": "4 1"}, {"input": "3 2 1\n1 0\n0 1\n0 0", "output": "2 0"}]
1,600
["greedy", "two pointers"]
20
[{"input": "4 3 2\r\n0 1 0\r\n1 0 1\r\n0 1 0\r\n1 1 1\r\n", "output": "4 1\r\n"}, {"input": "3 2 1\r\n1 0\r\n0 1\r\n0 0\r\n", "output": "2 0\r\n"}, {"input": "3 4 2\r\n0 1 1 1\r\n1 0 1 1\r\n1 0 0 1\r\n", "output": "7 0\r\n"}, {"input": "3 57 3\r\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0...
false
stdio
null
true
904/C
906
A
PyPy 3
TESTS
15
217
23,961,600
126418480
import sys; input = sys.stdin.readline from collections import defaultdict as dd inf = int(2e9+7) def main(): n = int(input()) d = dd(int) alp = 'abcdefghujklmnopqrstuvwxyz' yeah = -1 total = 0 for _ in range(n-1): cmd, w = input().split() if cmd == '.': for i in...
38
155
409,600
161594264
# Сложность по времени # Сложность по памяти n = int(input()) a = [-1] * 26 all = set(i for i in "abcdefghijklmnoprqstuvwxyz") bad = set("") res_cnt = 0 flag = False for i in range(n - 1): cmd, word = input().split() if flag: if cmd in "!?": res_cnt += 1 continue if cmd == ".": ...
Технокубок 2018 - Отборочный Раунд 4
CF
2,017
2
256
Shockers
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did. The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types: 1. Valentin pronounced some word and didn't get an electric shock. This action is...
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
null
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ...
[{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}]
1,600
["strings"]
38
[{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\...
false
stdio
null
true
159/A
159
A
PyPy 3
TESTS
8
342
409,600
42883426
import sys from collections import Counter n,k=map(int,input().split()) l=[] for i in range(n) : p,q,t=map(str,sys.stdin.readline().split()) t=int(t) l.append([[p,q],t]) #print(l) p=[] for i in range(n) : for j in range(i+1,n) : if l[j][1]-l[i][1] >k : break if Counter(l[i][0...
30
218
1,843,200
197610452
n, d = map(int, input().split()) f, p, q, r = [], [], {}, 0 for i in range(n): a, b, t = input().split() u, v, t = a + ' ' + b, b + ' ' + a, int(t) if t == r: p.append((u, v)) else: f += [min(x, y) for x, y in p if (y in q and q[y] >= r - d)] for x, y in p: q[x] = r p...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
350/B
350
B
PyPy 3-64
TESTS
4
374
36,352,000
176251516
import sys input = sys.stdin.readline from collections import deque, Counter n = int(input()) a = input()[:-1].split() b = list(map(int, input().split())) d = [[] for i in range(n)] for i, j in enumerate(b): if j == 0: continue d[j-1].append(i) d[i].append(j-1) x = [0]*n s = [set() for i in range(n...
36
342
16,179,200
230698169
n = int(input()) list_a, list_b = [0] + list(map(int, input().split())), [0] + list(map(int, input().split())) result, p = [], [0] * (n + 1) for i in list_b: p[i] += 1 for i in range(1, n + 1): if list_a[i] == 1: temp_list = [i] x = list_b[i] while p[x] == 1: temp_list.app...
Codeforces Round 203 (Div. 2)
CF
2,013
2
256
Resort
Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider the objects indexed in some way by integers from 1 to n), each obje...
The first line contains integer n (1 ≤ n ≤ 105) — the number of objects. The second line contains n space-separated integers type1, type2, ..., typen — the types of the objects. If typei equals zero, then the i-th object is the mountain. If typei equals one, then the i-th object is the hotel. It is guaranteed that at ...
In the first line print k — the maximum possible path length for Valera. In the second line print k integers v1, v2, ..., vk — the path. If there are multiple solutions, you can print any of them.
null
null
[{"input": "5\n0 0 0 0 1\n0 1 2 3 4", "output": "5\n1 2 3 4 5"}, {"input": "5\n0 0 1 0 1\n0 1 2 2 4", "output": "2\n4 5"}, {"input": "4\n1 0 0 0\n2 3 4 2", "output": "1\n1"}]
1,500
["graphs"]
36
[{"input": "5\r\n0 0 0 0 1\r\n0 1 2 3 4\r\n", "output": "5\r\n1 2 3 4 5\r\n"}, {"input": "5\r\n0 0 1 0 1\r\n0 1 2 2 4\r\n", "output": "2\r\n4 5\r\n"}, {"input": "4\r\n1 0 0 0\r\n2 3 4 2\r\n", "output": "1\r\n1\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 1\r\n4 0 8 4 7 8 5 5 7 2\r\n", "output": "2\r\n2 10\r\n"}, {"input":...
false
stdio
null
true
884/D
884
D
Python 3
TESTS
3
108
3,276,800
32003812
from collections import deque n = int(input()) colors_lens = list(map(int, input().split())) if len(colors_lens) % 2 == 0: colors_lens.append(0) colors_lens.sort() colors_lens = deque(colors_lens) shtraf = 0 while len(colors_lens) != 1: if len(colors_lens) % 2 == 0: colors_lens.appendleft(0) if le...
32
280
27,545,600
184856333
n=int(input()) a=list(map(int,input().split())) if n%2==0: a.append(0) from heapq import* hq=[] for i in a: heappush(hq,i) ans=0 while len(hq)!=1: res=0 for i in range(3): res+=heappop(hq) ans+=res heappush(hq,res) print(ans)
Educational Codeforces Round 31
ICPC
2,017
2
256
Boxes And Balls
Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≤ i ≤ n) i-th box will contain all balls with color i. In order to do this, Ivan will make some turns. Each turn he ...
The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of boxes and colors. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of balls with color i.
Print one number — the minimum possible penalty of the game.
null
In the first example you take all the balls from the first box, choose k = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose k = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest pu...
[{"input": "3\n1 2 3", "output": "6"}, {"input": "4\n2 3 4 5", "output": "19"}]
2,300
["data structures", "greedy"]
32
[{"input": "3\r\n1 2 3\r\n", "output": "6\r\n"}, {"input": "4\r\n2 3 4 5\r\n", "output": "19\r\n"}, {"input": "6\r\n1 4 4 4 4 4\r\n", "output": "38\r\n"}, {"input": "8\r\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158\r\n", "output": "8176373828\r\n"}, {"input": "1\r\n10\r\n", "output": ...
false
stdio
null
true
883/F
883
F
PyPy 3
TESTS1
9
109
23,142,400
31577171
#!/usr/bin/env python3 def main(): import re n = int(input()) names = set() def replace(m): if m.group(1): return 'h' elif m.group(2): length = m.end() - m.start() return 'u' * (length >> 1) + ('o' if length & 0x1 else "") else: ...
81
62
0
31970496
def rev(s): s = s[::-1] news = [] for i in range(len(s)): letter = s[i] if(letter == 'u'): news.append('o') news.append('o') continue if(i == 0): news.append(letter) continue if(letter == 'k'): if(news[-1...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Lost in Transliteration
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
null
There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khari...
[{"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "output": "4"}, {"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "output": "5"}, {"input": "2\nalex\nalex", "output": "1"}]
1,300
["implementation"]
81
[{"input": "10\r\nmihail\r\noolyana\r\nkooooper\r\nhoon\r\nulyana\r\nkoouper\r\nmikhail\r\nkhun\r\nkuooper\r\nkkkhoon\r\n", "output": "4\r\n"}, {"input": "9\r\nhariton\r\nhkariton\r\nbuoi\r\nkkkhariton\r\nboooi\r\nbui\r\nkhariton\r\nboui\r\nboi\r\n", "output": "5\r\n"}, {"input": "2\r\nalex\r\nalex\r\n", "output": "1\r...
false
stdio
null
true
813/D
813
D
PyPy 3
TESTS
3
124
0
93095998
import sys n = int(input()) a = list(map(int, input().split())) mod7 = [x % 7 for x in a] inf = 10**9 next_i = [[inf]*3 for _ in range(n)] for i in range(n): for j in range(i+1, n): if a[i]-1 == a[j]: next_i[i][0] = min(next_i[i][0], j) if a[i]+1 == a[j]: next_i[i][1] = min...
35
1,434
104,243,200
112897541
import sys def solve(): n = int(sys.stdin.readline()) a = [0] + [int(i) for i in sys.stdin.readline().split()] dp = [[0]*(n + 1) for i in range(n + 1)] ans = 0 maxnum = [0] * (10**5 + 2) maxmod = [0] * 7 for y in range(n + 1): maxmod = [0] * 7 for ai in a: ...
Educational Codeforces Round 22
ICPC
2,017
2
256
Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal. S...
The first line contains one integer number n (2 ≤ n ≤ 5000). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — notes written on a sheet.
Print maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
null
In the first example subsequences [1, 2] and [4, 5] give length 4 in total. In the second example subsequences [62, 48, 49] and [60, 61] give length 5 in total. If you choose subsequence [62, 61] in the first place then the second melody will have maximum length 2, that gives the result of 4, which is not maximal.
[{"input": "4\n1 2 4 5", "output": "4"}, {"input": "6\n62 22 60 61 48 49", "output": "5"}]
2,600
["dp", "flows"]
35
[{"input": "4\r\n1 2 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n62 22 60 61 48 49\r\n", "output": "5\r\n"}, {"input": "2\r\n1 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 4\r\n", "output": "2\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "9\r\n"}, {"input": "10\r\n7776 32915 1030 71664 7542 72359 6538...
false
stdio
null
true
370/B
370
B
Python 3
TESTS
3
46
0
5438622
n = int(input()) t, l, s = [0] * n, [0] * n, ['YES'] * n for i in range(n): p = tuple(map(int, input().split())) t[i] = set(p[1: ]) l[i] = p[0] for i in range(n): for j in range(i + 1, n): if l[i] < l[j]: if all(k in t[j] for k in t[i]): s[j] = 'NO' else: if all(k...
24
77
512,000
7990517
def main(): n = int(input()) a = [set(map(int, input().split()[1:])) for _ in range(n)] res = [True] * n for i in range(n - 1): for j in range(i + 1, n): if a[i].issubset(a[j]): res[j] = False if a[i].issuperset(a[j]): res[i] = False p...
Codeforces Round 217 (Div. 2)
CF
2,013
1
256
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers. During the game the host takes num...
The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, ...
Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.
null
null
[{"input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES"}, {"input": "2\n1 1\n1 1", "output": "NO\nNO"}]
1,300
["implementation"]
24
[{"input": "3\r\n1 1\r\n3 2 4 1\r\n2 10 11\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "NO\r\nNO\r\n"}, {"input": "1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2\r\n1 3\r\n", "output": "YES\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n2 1 2\r\n", "output": "YES\r\nNO\r\n"}, {"i...
false
stdio
null
true
995/A
995
A
Python 3
TESTS
0
93
0
39769029
n, k = map(int, input().split()) m = [] for _ in range(4): m.extend(list(map(int, input().split()))) moves = {} ans = 0 zeros = 0 for i in range(k): moves[i + 1] = [] d = {1: 1, 2: 4} def park(): global ans, moves, m, zeros zeros = 0 for i in range(n, 3 * n): r = d[i // n] if m[i...
57
218
2,457,600
39612690
import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,k=map(int,input().split()) cars=[list(map(int,input().split())) for _ in range(4)] out=[] for _ in range(20000): for i in range(n)[::-1]: if cars[1][i]==0: continue if cars[1][i]==cars[0][i]: out.append([cars[1][i],0,i])...
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
3
256
Tesla
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be repres...
The first line of the input contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 50$$$, $$$1 \le k \le 2n$$$), representing the number of columns and the number of cars, respectively. The next four lines will contain $$$n$$$ integers each between $$$0$$$ and $$$k$$$ inclusive, representing the ini...
If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $$$20000$$$ car moves, then print $$$m$$$, the number of moves, on the first line. On the following $$$m$$$ lines, print the moves (one move per line) in the format $$$i$$$ $$$r$$$ $$$c$$$, which corresponds to Allen movin...
null
In the first sample test case, all cars are in front of their spots except car $$$5$$$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $$$20000$$$ will be accepted. In the second sample test case, there is only one column, a...
[{"input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2"}, {"input": "1 2\n1\n2\n1\n2", "output": "-1"}, {"input": "1 2\n1\n1\n2\n2", "output": "2\n1 1 1\n2 4 1"}]
2,100
["constructive algorithms", "implementation"]
57
[{"input": "4 5\r\n1 2 0 4\r\n1 2 0 4\r\n5 0 0 3\r\n0 5 0 3\r\n", "output": "6\r\n1 1 1\r\n2 1 2\r\n4 1 4\r\n3 4 4\r\n5 3 2\r\n5 4 2\r\n"}, {"input": "1 2\r\n1\r\n2\r\n1\r\n2\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1\r\n1\r\n2\r\n2\r\n", "output": "2\r\n1 1 1\r\n2 4 1\r\n"}, {"input": "2 2\r\n1 0\r\n0 2\r\n0 1\r\n...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, k = map(int, f.readline().split()) grid = [] for _ in range(4): grid.append(list(map(int, f.readline().split()))) initial = {} target = {} for row_idx in [1, 2]: fo...
true
247/C
250
C
PyPy 3
TESTS
1
310
1,843,200
90447030
import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = lis...
44
436
7,168,000
11596521
import sys def solve(): n, k = map(int, input().split()) bada = list(map(int, input().split())) a = list() for i in range(len(bada)): if len(a) > 0 and bada[i] == a[-1]: continue a.append(bada[i]) bad = [0] * (k + 1) for i, val in enumerate(a): if i + 1 >= len(a) and i =...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Movie Critics
A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival progra...
The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number fr...
Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.
null
In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses...
[{"input": "10 3\n1 1 2 3 2 3 3 1 1 3", "output": "3"}, {"input": "7 3\n3 1 3 2 3 1 2", "output": "1"}]
1,600
[]
44
[{"input": "10 3\r\n1 1 2 3 2 3 3 1 1 3\r\n", "output": "3"}, {"input": "7 3\r\n3 1 3 2 3 1 2\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n", "output": "1"}, {"input": "10 2\r\n1 2 2 1 1 2 1 1 2 2\r\n", "output": "1"}, {"input": "10 10\r\n5 7 8 2 4 10 1 3 9 6\r\n", "output": "1"}, {"input": "100 10\r\n6 2 8 1 7 1 2 9...
false
stdio
null
true
846/E
846
E
Python 3
TESTS
8
560
9,420,800
44009373
rd = lambda: list(map(int, input().split())) n = rd()[0] b = [0] + rd() a = [0] + rd() x = [0 for _ in range(n + 1)] k = [0 for _ in range(n + 1)] for i in range(2, n + 1): x[i], k[i] = rd() for i in range(n, 0, -1): if b[i] < a[i]: if i == 1 or k[i] * (a[i] - b[i]) > b[x[i]]: print("NO")...
42
186
22,528,000
182427003
from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) par=[(-1,-1)]*n for i in range(1,n): x,k=map(int,input().split()) par[i]=(x-1,k) sm=sum(a) dp=[a[i]-b[i] for i in range(n)] for i in range(n-1,-1,-1): p,k=par[i] if dp[i]...
Educational Codeforces Round 28
ICPC
2,017
2
256
Chemistry in Berland
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunately, chemical laws allow material transformations (yes, chemistry i...
The first line contains one integer number n (1 ≤ n ≤ 105) — the number of materials discovered by Berland chemists. The second line contains n integer numbers b1, b2... bn (1 ≤ bi ≤ 1012) — supplies of BerSU laboratory. The third line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 1012) — the amounts required for...
Print YES if it is possible to conduct an experiment. Otherwise print NO.
null
null
[{"input": "3\n1 2 3\n3 2 1\n1 1\n1 1", "output": "YES"}, {"input": "3\n3 2 1\n1 2 3\n1 1\n1 2", "output": "NO"}]
2,300
["dfs and similar", "greedy", "trees"]
42
[{"input": "3\r\n1 2 3\r\n3 2 1\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n1 2 3\r\n1 1\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 1 1 2 3\r\n1 2 2 2 1\r\n1 2\r\n1 3\r\n2 4\r\n1 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n2 8 6 1 2 7 6 9 2 8\r\n4 9 4 3 5 2 9 3 7 3\r\n1 8\r\n2 8\r\n3 8...
false
stdio
null
true
413/E
413
E
Python 3
TESTS
8
62
0
6434353
import itertools n, m = tuple(map(int, str.split(input()))) xs = list(input() + input()) def find_start(xs, sx=0): for x in range(sx, n): for y in range(2): if xs[x + y * n] == ".": return x, y return -1, -1 def pprint_field(xs): print( str.join( ...
46
1,247
75,776,000
165348230
import sys input = sys.stdin.readline infinity = 10**6 def convert(c): if c == '.': return True else: return False def find_next_dist_helper(i, b, c, shift, dist, maze): if shift == 1: if (not maze[b][i]) or (not maze[c][i + 1]): return infinity if b == c: ...
Coder-Strike 2014 - Round 2
CF
2,014
2
256
Maze 2D
The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2 × n maze. Imagine a maze that looks like a 2 × n rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can move fro...
The first line contains two integers, n and m (1 ≤ n ≤ 2·105; 1 ≤ m ≤ 2·105) — the width of the maze and the number of queries, correspondingly. Next two lines contain the maze. Each line contains n characters, each character equals either '.' (empty cell), or 'X' (obstacle). Each of the next m lines contains two inte...
Print m lines. In the i-th line print the answer to the i-th request — either the size of the shortest path or -1, if we can't reach the second cell from the first one.
null
null
[{"input": "4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7", "output": "1\n4\n0\n5\n2\n2\n2"}, {"input": "10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10", "output": "9\n-1\n3"}]
2,200
["data structures", "divide and conquer"]
46
[{"input": "4 7\r\n.X..\r\n...X\r\n5 1\r\n1 3\r\n7 7\r\n1 4\r\n6 1\r\n4 7\r\n5 7\r\n", "output": "1\r\n4\r\n0\r\n5\r\n2\r\n2\r\n2\r\n"}, {"input": "10 3\r\nX...X..X..\r\n..X...X..X\r\n11 7\r\n7 18\r\n18 10\r\n", "output": "9\r\n-1\r\n3\r\n"}, {"input": "1 1\r\n.\r\n.\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2 1\r\n....
false
stdio
null
true
413/E
413
E
Python 3
PRETESTS
8
77
0
6427561
n, m = map(int, input().split()) s1 = input() s1 = 'X' + s1 s2 = input() s2 = 'X' + s2 blocks = [] groups = [0 for i in range(n)] res = [0 for i in range(2 * n)] group = 0 for i in range(n + 1): el1 = s1[i] el2 = s2[i] if el1 == el2 == 'X': blocks.append(3) elif el1 == 'X': blocks.append...
46
1,247
75,776,000
165348230
import sys input = sys.stdin.readline infinity = 10**6 def convert(c): if c == '.': return True else: return False def find_next_dist_helper(i, b, c, shift, dist, maze): if shift == 1: if (not maze[b][i]) or (not maze[c][i + 1]): return infinity if b == c: ...
Coder-Strike 2014 - Round 2
CF
2,014
2
256
Maze 2D
The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2 × n maze. Imagine a maze that looks like a 2 × n rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can move fro...
The first line contains two integers, n and m (1 ≤ n ≤ 2·105; 1 ≤ m ≤ 2·105) — the width of the maze and the number of queries, correspondingly. Next two lines contain the maze. Each line contains n characters, each character equals either '.' (empty cell), or 'X' (obstacle). Each of the next m lines contains two inte...
Print m lines. In the i-th line print the answer to the i-th request — either the size of the shortest path or -1, if we can't reach the second cell from the first one.
null
null
[{"input": "4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7", "output": "1\n4\n0\n5\n2\n2\n2"}, {"input": "10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10", "output": "9\n-1\n3"}]
2,200
["data structures", "divide and conquer"]
46
[{"input": "4 7\r\n.X..\r\n...X\r\n5 1\r\n1 3\r\n7 7\r\n1 4\r\n6 1\r\n4 7\r\n5 7\r\n", "output": "1\r\n4\r\n0\r\n5\r\n2\r\n2\r\n2\r\n"}, {"input": "10 3\r\nX...X..X..\r\n..X...X..X\r\n11 7\r\n7 18\r\n18 10\r\n", "output": "9\r\n-1\r\n3\r\n"}, {"input": "1 1\r\n.\r\n.\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2 1\r\n....
false
stdio
null
true
873/C
873
C
Python 3
TESTS
7
46
0
31259830
n,m,k=map(int,input().split()) a=[] ans=0 ansk=0 for i in range(m): a.append([]) for i in range(n): w=0 for j in list(map(int,input().split())): a[w].append(j) w+=1 for i in a: x=0 q=True for l in range(n): if i[l]==1: if sum(i[l:l+min(k,n-l+1)])>x: ...
20
77
0
32320052
n,m,k = map(int,input().split()) x,y = 0,0 a = [] for i in range(n): a.append(list(map(int, input().split()))) for i in zip(*a): u,v = 0,0 for j in range(n-k+1): p,q = sum(i[j:j+k]), sum(i[:j]) if p > u: u = p v = q x += u y += v print(x,y)
Educational Codeforces Round 30
ICPC
2,017
1
256
Strange Game On Matrix
Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score ...
The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
null
In the first example Ivan will replace the element a1, 2.
[{"input": "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1", "output": "4 1"}, {"input": "3 2 1\n1 0\n0 1\n0 0", "output": "2 0"}]
1,600
["greedy", "two pointers"]
20
[{"input": "4 3 2\r\n0 1 0\r\n1 0 1\r\n0 1 0\r\n1 1 1\r\n", "output": "4 1\r\n"}, {"input": "3 2 1\r\n1 0\r\n0 1\r\n0 0\r\n", "output": "2 0\r\n"}, {"input": "3 4 2\r\n0 1 1 1\r\n1 0 1 1\r\n1 0 0 1\r\n", "output": "7 0\r\n"}, {"input": "3 57 3\r\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0...
false
stdio
null
true
50/C
50
C
PyPy 3-64
TESTS
1
280
5,324,800
140874062
import sys from collections import defaultdict n = int(input()) arr = [] min_l = sys.maxsize max_l = 0 min_w = sys.maxsize max_w = 0 for _ in range(n): x, y = map(int, input().split()) min_l = min(min_l, x) max_l = max(max_l, x) min_w = min(min_w, y) max_w = max(max_w, y) res = ((abs(max_l - min...
75
748
0
187635294
n=int(input()) mh=sh=-10**7 ml=sl=10**7 for i in range(n): a,b=map(int,input().split()) m=a+b s=a-b mh=max(mh,m) ml=min(ml,m) sh=max(sh,s) sl=min(sl,s) print(mh-ml+sh-sl+4)
Codeforces Beta Round 47
CF
2,010
2
256
Happy Farm 5
The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them. For that a young player Vasya decided to make the shepherd run round the cows al...
The first line contains an integer N which represents the number of cows in the herd (1 ≤ N ≤ 105). Each of the next N lines contains two integers Xi and Yi which represent the coordinates of one cow of (|Xi|, |Yi| ≤ 106). Several cows can stand on one point.
Print the single number — the minimum number of moves in the sought path.
null
Picture for the example test: The coordinate grid is painted grey, the coordinates axes are painted black, the cows are painted red and the sought route is painted green.
[{"input": "4\n1 1\n5 1\n5 3\n1 3", "output": "16"}]
2,000
["geometry"]
75
[{"input": "4\r\n1 1\r\n5 1\r\n5 3\r\n1 3\r\n", "output": "16\r\n"}, {"input": "3\r\n0 0\r\n5 0\r\n0 5\r\n", "output": "19\r\n"}, {"input": "5\r\n0 0\r\n7 7\r\n7 5\r\n5 7\r\n1 1\r\n", "output": "22\r\n"}, {"input": "5\r\n1 0\r\n-1 0\r\n1 0\r\n-1 0\r\n0 0\r\n", "output": "8\r\n"}, {"input": "9\r\n1 0\r\n-1 0\r\n1 0\r\n-...
false
stdio
null
true
995/B
995
B
PyPy 3
TESTS
3
140
20,172,800
84929997
if __name__ == '__main__': n = int(input()) arr = list(map(int, input().split())) cnt = 0 for i in range(0, 2 * n - 1, 2): if arr[i] != arr[i + 1]: idx = None for j in range(i + 2, 2 * n - 1): if arr[j] == arr[i]: idx = j ...
22
46
0
189901099
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) ans = 0 while(len(a) > 0): i = a.pop(0) j = a.index(i) ans += j del a[j] print(ans)
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
25/D
25
D
PyPy 3
TESTS
8
156
19,968,000
34201599
n = int( input() ) p = [0]*n rank = [0]*n deg = [0]*n edges = [] for i in range( n ): p[i] = i def find_set( x ): if x == p[x]: return ( x ) return ( find_set( p[x] ) ) def union_set( a, b ): fa = find_set( a ) fb = find_set( b ) if rank[fa] < rank[fb]: p[fa] = fb els...
55
92
512,000
209992300
def find(x, parent): if x != parent[x]: parent[x] = find(parent[x], parent) return parent[x] class Road: def __init__(self, city1, city2): self.city1 = city1 self.city2 = city2 numCities = int(input()) parent = list(range(numCities + 1)) duplicateRoads = 0 closedRoads = [] for _...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
null
null
[{"input": "2\n1 2", "output": "0"}, {"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7"}]
1,900
["dsu", "graphs", "trees"]
55
[{"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 7\r\n", "output": "1\r\n3 1 3 7\r\n"}, {"input": "3\r\n3 2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n3 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 4\r\n3 1\r\n3 4\r\n", "output": "1\r\n3 4 2 4\r\n"}, {"in...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) edges = set() for _ in range(n-1): a, b = map(int, f.readline().split()) if a > b: a, b = b, a edges.add((a, b)) return n, edges def check_in...
true
25/E
25
E
PyPy 3
TESTS
10
1,746
23,347,200
95414605
import sys from array import array # noqa: F401 from itertools import permutations def input(): return sys.stdin.buffer.readline().decode('utf-8') class RollingHash(object): __slots__ = ['hash1', 'hash2'] from random import randint N = 10**6 BASE = randint(1000, 9999) MOD1, MOD2 = 1000000...
46
280
15,564,800
216404511
import sys import random import sys from itertools import permutations class FastIO: def __init__(self): return @staticmethod def read_int(): return int(sys.stdin.readline().strip()) @staticmethod def read_float(): return float(sys.stdin.readline().strip()) @staticme...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Test
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop i...
There are exactly 3 lines in the input data. The i-th line contains string si. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.
Output one number — what is minimal length of the string, containing s1, s2 and s3 as substrings.
null
null
[{"input": "ab\nbc\ncd", "output": "4"}, {"input": "abacaba\nabaaba\nx", "output": "11"}]
2,200
["hashing", "strings"]
46
[{"input": "ab\r\nbc\r\ncd\r\n", "output": "4\r\n"}, {"input": "abacaba\r\nabaaba\r\nx\r\n", "output": "11\r\n"}, {"input": "syvncqmfhautvxudqdhggz\r\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\r\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls\r\n", "output": "100\r\n"}, {"input": "jwdezvgfm\r\nmdoqvylpuvyk\r\nqylldbziva\r\n"...
false
stdio
null
true
560/A
560
A
Python 3
TESTS
3
46
0
13855970
def x(x): if len(x) == 1 and x[0] != 1: print(1) else: r = max(x)%min(x) print(r if r!=0 else -1) input(); n = list(map(int,input().split())) x(n)
16
31
0
160387910
input() key_list = [int(key) for key in input().split()] result = 1 if 1 in key_list: result = -1 print(result)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
724/D
724
D
Python 3
PRETESTS
4
61
4,812,800
21290546
m = int(input()) s = input() res = '' alp = 'abcdefghijklmnopqrstuvwxyz' mask = [0 for _ in range(len(s))] def is_good(): cnt = 0 for i in range(m): cnt += mask[i] for i in range(m, len(s)): cnt += mask[i] cnt -= mask[i - m] if cnt == 0: return False return T...
71
186
716,800
21768946
m = int(input()) s = list(input()) d = [0 for _ in range(26)] for c in s: d[ord(c) - ord('a')] += 1 for i in range(26): c = chr(ord('a') + i) l = -1 r = -1 cnt = 0 for j in range(len(s)): if s[j] < c: l = j if s[j] == c: r = j if j - l >= m: ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
724/D
724
D
Python 3
TESTS
0
31
0
32511570
m = int(input()) - 1 k = input() r = '' i = 97 t = [k] while 1: q = chr(i) p = [] for d in t: for s in d.split(q): if len(s) > m: p += [s] if not p: break r += q * k.count(q) i += 1 t = p y = chr(i) for d in t: i = 0 for x in d: if x == y: j = i if...
71
249
4,915,200
21301244
n = int(input()) word = input() cnt = [0]*26 for x in word: cnt[ord(x)-ord('a')] += 1 ind = 25 sum = 0 for i in range(26): pre = -1 cur = -1 ans = 0 flag = True for j,x in enumerate(word): if ord(x)-ord('a')<i: pre = j elif ord(x)-ord('a')==i: cur = j ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
808/F
808
F
Python 3
TESTS
2
61
204,800
27226347
import sys import math arr = [] #power, magic number, and level def calculate(): str1 = sys.stdin.readline().rstrip().split() n = int(str1[0]) k = int(str1[1]) possible = [] maxlevel = 0 i = 0 while (i < n): #read data str2 = sys.stdin.readline().rstrip().split() arr.append([int(str2[0]), int(str2[1]), in...
34
202
8,908,800
153858152
from collections import deque import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def add_edge(u, v, c): G[u].append([v, c, len(G[v]), 1]) G[v].append([u, 0, len(G[u]) - 1, 0]) return def bfs(s): q = deque() q.append(s) dist = [inf] * l dist[s] = 0 while q: ...
Educational Codeforces Round 21
ICPC
2,017
2
256
Card Game
Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a deck with total power not less than k, but magic numbers may not allow him...
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100000). Then n lines follow, each of these lines contains three numbers that represent the corresponding card: pi, ci and li (1 ≤ pi ≤ 1000, 1 ≤ ci ≤ 100000, 1 ≤ li ≤ n).
If Vova won't be able to build a deck with required power, print - 1. Otherwise print the minimum level Vova has to reach in order to build a deck.
null
null
[{"input": "5 8\n5 5 1\n1 5 4\n4 6 3\n1 12 4\n3 12 1", "output": "4"}, {"input": "3 7\n4 4 1\n5 8 2\n5 3 3", "output": "2"}]
2,400
["binary search", "flows", "graphs"]
34
[{"input": "5 8\r\n5 5 1\r\n1 5 4\r\n4 6 3\r\n1 12 4\r\n3 12 1\r\n", "output": "4\r\n"}, {"input": "3 7\r\n4 4 1\r\n5 8 2\r\n5 3 3\r\n", "output": "2\r\n"}, {"input": "10 10\r\n3 3 6\r\n5 10 4\r\n4 7 9\r\n4 9 7\r\n1 9 4\r\n1 6 10\r\n4 10 1\r\n4 4 6\r\n2 7 2\r\n1 5 4\r\n", "output": "4\r\n"}, {"input": "10 20\r\n9 4 10\...
false
stdio
null
true
351/B
351
B
PyPy 3
TESTS
2
184
20,172,800
128863437
inf = float("inf") def merge_sort(A,l,r): global inf if l>=r-1: return 0 m = l+((r-l)>>1) inv = merge_sort(A,l,m) + merge_sort(A,m,r) L,R = A[l:m],A[m:r] #copied L.append(inf) R.append(inf) i,j = 0,0 for k in range(l,r): inv += j if L[i]<R[j] else 0 A[k] = L...
25
154
307,200
27428398
def merge_sort(a, l, r): res = 0 if l < r: m = (l + r) // 2 res += merge_sort(a, l, m) res += merge_sort(a, m + 1, r) i = l j = m + 1 b = [] while i <= m and j <= r: if a[i] <= a[j]: b.append(a[i]) i += 1 else: b.append(a[j]) j += 1 ...
Codeforces Round 204 (Div. 1)
CF
2,013
1
256
Jeff and Furik
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace...
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
null
In the first test the sequence is already sorted, so the answer is 0.
[{"input": "2\n1 2", "output": "0.000000"}, {"input": "5\n3 5 2 4 1", "output": "13.000000"}]
1,900
["combinatorics", "dp", "probabilities"]
25
[{"input": "2\r\n1 2\r\n", "output": "0.000000\r\n"}, {"input": "5\r\n3 5 2 4 1\r\n", "output": "13.000000\r\n"}, {"input": "16\r\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\r\n", "output": "108.000000\r\n"}, {"input": "9\r\n1 7 8 5 3 4 6 9 2\r\n", "output": "33.000000\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "8.00...
false
stdio
import sys def read_float_from_line(line): line = line.strip() try: return float(line) except: return None def is_acceptable(ref, sub, abs_tol=1e-6, rel_tol=1e-6): if abs(ref - sub) <= abs_tol: return True denom = max(abs(ref), 1e-8) return abs(ref - sub) / denom <= rel...
true
1009/G
1009
G
PyPy 3-64
TESTS
0
46
1,740,800
215782908
import sys input = sys.stdin.buffer.readline def process(S, A): n = len(S) condition_first = [2**7-1 for i in range(n)] condition_count = [0 for i in range(2**7)] two_pow = [2**i for i in range(7)] for row1, row2 in A: entry = 0 for c in row2: c = ord(c)-ord('a') ...
57
233
10,137,600
167672037
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline s = list(input().rstrip()) pow2 = [1] for _ in range(6): pow2.append(2 * pow2[-1]) p = pow2[6] cnt = [0] * p for i in s: cnt[pow2[i - 97]] += 1 sp = set(pow2) u = [[pow2[i]] for i in range(6)] for i in range(1, p): if i in sp: ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Allowed Letters
Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup! Actually, Polycarp has already came up with the name but some improvement ...
The first line is the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) — the name Polycarp has came up with. The string consists only of lowercase Latin letters from "a" to "f". The second line contains a single integer $$$m$$$ ($$$0 \le m \le |s|$$$) — the number of investors. The $$$i$$$-th of the next $$$m$$$ lines conta...
If Polycarp can't produce any valid name then print "Impossible". Otherwise print the smallest lexicographically name Polycarp can obtain by swapping letters in string $$$s$$$ such that the letter at every position is among the allowed ones.
null
null
[{"input": "bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef", "output": "deadbeef"}, {"input": "abacaba\n0", "output": "aaaabbc"}, {"input": "fc\n2\n1 cfab\n2 f", "output": "cf"}]
2,400
["bitmasks", "flows", "graph matchings", "graphs", "greedy"]
57
[{"input": "bedefead\r\n5\r\n2 e\r\n1 dc\r\n5 b\r\n7 ef\r\n6 ef\r\n", "output": "deadbeef\r\n"}, {"input": "abacaba\r\n0\r\n", "output": "aaaabbc\r\n"}, {"input": "fc\r\n2\r\n1 cfab\r\n2 f\r\n", "output": "cf\r\n"}, {"input": "bbcbbc\r\n6\r\n1 c\r\n2 c\r\n3 b\r\n4 ab\r\n5 ab\r\n6 ab\r\n", "output": "ccbbbb\r\n"}, {"inp...
false
stdio
null
true
25/D
25
D
Python 3
TESTS
8
154
7,168,000
126095028
from sys import stdin input=stdin.readline class dsu(): def __init__(self,n): self.parent=[0]*(n) self.sz=[0]*(n) def make_set(self,v): self.parent[v]=v self.sz[v]=1 def find_set(self,v): if v==self.parent[v]: return v self.parent[v]=self.find_set(self.parent[v]) return self.parent[v] def union...
55
122
409,600
165648784
from sys import stdin input=stdin.readline class DSU: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n self.num_sets = n def find(self, a): acopy = a while a != self.parent[a]: a = self.parent[a] while acopy != a: s...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
null
null
[{"input": "2\n1 2", "output": "0"}, {"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7"}]
1,900
["dsu", "graphs", "trees"]
55
[{"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 7\r\n", "output": "1\r\n3 1 3 7\r\n"}, {"input": "3\r\n3 2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n3 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 4\r\n3 1\r\n3 4\r\n", "output": "1\r\n3 4 2 4\r\n"}, {"in...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) edges = set() for _ in range(n-1): a, b = map(int, f.readline().split()) if a > b: a, b = b, a edges.add((a, b)) return n, edges def check_in...
true
803/F
803
F
PyPy 3
TESTS
8
218
1,331,200
54653568
#Bhargey Mehta (Sophomore) #DA-IICT, Gandhinagar import sys, math, queue #sys.stdin = open("input.txt", "r") MOD = 10**9+7 sys.setrecursionlimit(1000000) n = int(input()) a = list(map(int, input().split())) if a[0] == 1: ans = 1 else: ans = 0 gs = {a[0]: 1} for i in range(1, n): if a[i] == 1: ans ...
35
139
17,510,400
218495216
N = 100010 mod = 10**9 + 7 a = [0] * N dp = [0] * N p = [0] * N n = int(input()) p[0] = 1 x = list(map(int,input().split())) for i in range(1, n+1): p[i] = (p[i - 1] * 2) % mod a[x[i-1]] += 1 for i in range(N - 1, 0, -1): sum = 0 for j in range(i, N, i): sum += a[j] dp[i] = (p[sum] - 1) %...
Educational Codeforces Round 20
ICPC
2,017
2
256
Coprime Subsequences
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109 + 7. Note th...
The first line contains one integer number n (1 ≤ n ≤ 100000). The second line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 100000).
Print the number of coprime subsequences of a modulo 109 + 7.
null
In the first example coprime subsequences are: 1. 1 2. 1, 2 3. 1, 3 4. 1, 2, 3 5. 2, 3 In the second example all subsequences are coprime.
[{"input": "3\n1 2 3", "output": "5"}, {"input": "4\n1 1 1 1", "output": "15"}, {"input": "7\n1 3 5 15 3 105 35", "output": "100"}]
2,000
["bitmasks", "combinatorics", "number theory"]
35
[{"input": "3\r\n1 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "15\r\n"}, {"input": "7\r\n1 3 5 15 3 105 35\r\n", "output": "100\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n100000\r\n", "output": "0\r\n"}, {"input": "5\r\n10 8 6 4 6\r\n", "output": "0\r\n"}, {"input": "5...
false
stdio
null
true
437/D
437
D
PyPy 3-64
TESTS
9
888
28,364,800
203867399
n,m = map(int,input().split()) val = list(map(int, input().split())) arr = [(idx + 1, x) for idx,x in enumerate(val)] arr.sort(key = lambda x: x[1]) adj = [[] for i in range(n + 1)] val = [0] + val for i in range(m): u,v = map(int,input().split()) adj[u].append(v) adj[v].append(u) parent = [x for x in ra...
27
452
27,033,600
138586050
import sys input = sys.stdin.buffer.readline def findroot(root_dict, x): L = [] while root_dict[x] != x: L.append(x) x = root_dict[x] for y in L: root_dict[y] = x return x def process(A, G): n = len(A) answer = 0 g = [[] for i in range(n+1)] root_dict = [i for ...
Codeforces Round 250 (Div. 2)
CF
2,014
2
256
The Child and Zoo
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area using the roads....
The first line contains two integers n and m (2 ≤ n ≤ 105; 0 ≤ m ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each line contains two integers xi and yi (1 ≤ xi, yi ≤ n; xi ≠ yi), denoting the road between areas xi and yi. All roads are bidirectional, each pair of ar...
Output a real number — the value of $$\frac{\sum_{p,q,p\neq q} f(p,q)}{n(n-1)}$$. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4.
null
Consider the first sample. There are 12 possible situations: - p = 1, q = 3, f(p, q) = 10. - p = 2, q = 3, f(p, q) = 20. - p = 4, q = 3, f(p, q) = 30. - p = 1, q = 2, f(p, q) = 10. - p = 2, q = 4, f(p, q) = 20. - p = 4, q = 1, f(p, q) = 10. Another 6 cases are symmetrical to the above. The average is $$(10+20+30+10+2...
[{"input": "4 3\n10 20 30 40\n1 3\n2 3\n4 3", "output": "16.666667"}, {"input": "3 3\n10 20 30\n1 2\n2 3\n3 1", "output": "13.333333"}, {"input": "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7", "output": "18.571429"}]
1,900
["dsu", "sortings"]
27
[{"input": "4 3\r\n10 20 30 40\r\n1 3\r\n2 3\r\n4 3\r\n", "output": "16.666667\r\n"}, {"input": "3 3\r\n10 20 30\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "13.333333\r\n"}, {"input": "7 8\r\n40 20 10 30 20 50 40\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n1 4\r\n5 7\r\n", "output": "18.571429\r\n"}, {"input": "10 14\r\n594...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read expected output with open(output_path, 'r') as f: expected_line = f.read().strip() try: expected = float(expected_line) except: print(0) return ...
true
437/D
437
D
Python 3
TESTS
9
1,091
32,665,600
127865346
import sys import math import heapq import itertools from sys import setrecursionlimit from collections import deque, defaultdict input = sys.stdin.readline # # ANALYSIS # # Let n be the number of areas and m be the number of roads. Assume union-find # operations are constant time even though they are slightly wors...
27
546
40,550,400
231046788
n, m = map(int, input().split()) p, c = list(range(n + 1)), [1] * (n + 1) v = [0] + list(map(int, input().split())) s, e = 0, [()] * m for i in range(m): x, y = map(int, input().split()) e[i] = (x, y, min(v[x], v[y])) e.sort(key = lambda x: x[2], reverse = True) q = [[i] for i in range(n + 1)] for l, r, v in e:...
Codeforces Round 250 (Div. 2)
CF
2,014
2
256
The Child and Zoo
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area using the roads....
The first line contains two integers n and m (2 ≤ n ≤ 105; 0 ≤ m ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each line contains two integers xi and yi (1 ≤ xi, yi ≤ n; xi ≠ yi), denoting the road between areas xi and yi. All roads are bidirectional, each pair of ar...
Output a real number — the value of $$\frac{\sum_{p,q,p\neq q} f(p,q)}{n(n-1)}$$. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4.
null
Consider the first sample. There are 12 possible situations: - p = 1, q = 3, f(p, q) = 10. - p = 2, q = 3, f(p, q) = 20. - p = 4, q = 3, f(p, q) = 30. - p = 1, q = 2, f(p, q) = 10. - p = 2, q = 4, f(p, q) = 20. - p = 4, q = 1, f(p, q) = 10. Another 6 cases are symmetrical to the above. The average is $$(10+20+30+10+2...
[{"input": "4 3\n10 20 30 40\n1 3\n2 3\n4 3", "output": "16.666667"}, {"input": "3 3\n10 20 30\n1 2\n2 3\n3 1", "output": "13.333333"}, {"input": "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7", "output": "18.571429"}]
1,900
["dsu", "sortings"]
27
[{"input": "4 3\r\n10 20 30 40\r\n1 3\r\n2 3\r\n4 3\r\n", "output": "16.666667\r\n"}, {"input": "3 3\r\n10 20 30\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "13.333333\r\n"}, {"input": "7 8\r\n40 20 10 30 20 50 40\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n1 4\r\n5 7\r\n", "output": "18.571429\r\n"}, {"input": "10 14\r\n594...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read expected output with open(output_path, 'r') as f: expected_line = f.read().strip() try: expected = float(expected_line) except: print(0) return ...
true
631/A
631
A
PyPy 3
TESTS
11
546
2,150,400
99742075
def f(j, k): q, e = 0, 0 for i in range(j, k + 1): q |= a[i] e |= b[i] return q + e # for i in range(0, int(input())): n = int(input()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) maximum = 0 for j in range(0, len(a)): for k in range(j + 1, ...
27
46
0
164908837
n,a,b=input(),0,0 for i in input().split():a|=int(i) for i in input().split():b|=int(i) print(a+b)
Codeforces Round 344 (Div. 2)
CF
2,016
1
256
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
null
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, ...
[{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}]
900
["brute force", "implementation"]
27
[{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 1...
false
stdio
null
true
51/A
51
A
PyPy 3-64
TESTS
13
248
3,993,600
225080094
n = int(input()) amulets = [set() for i in range(n)] for i in range(n): a_b = list(input()) c_d = list(input()) if i != n-1: _ = input() amulets[i].add(a_b[0]) amulets[i].add(a_b[1]) amulets[i].add(c_d[0]) amulets[i].add(c_d[1]) set_am = set() for amulet in amulets: set_am.add(frozenset(amulet)) p...
20
62
0
153614217
def Contains(myList, helper): for i in range(4): if helper in myList: return True helper = '{}{}{}{}'.format(helper[2], helper[0], helper[3], helper[1]) return False n = int(input()) myList = [] helper = "" while n > 0: helper = input() + input() if not Contains(myList, hel...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
51/A
51
A
PyPy 3
TESTS
13
248
2,560,000
161716396
x = set() t = int(input()) for _ in range(t): a,b = list(input()) c,d = list(input()) f= [a,b,c,d] f.sort() g = ''.join(f) x.add(g) if _ < t-1: input() print(len(x))
20
62
0
230770551
def containsElement(cont: list, element: str) -> bool: for i in range(4): if element in cont: return True element = f'{element[2]}{element[0]}{element[3]}{element[1]}' return False n = int(input()) cont = [] for i in range(n): helper = input() + input() # print(f'helper = ...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
388/C
388
C
PyPy 3-64
TESTS
1
30
512,000
146295392
n = int(input()) a = [list(map(int, input().split()))[1:] for i in range(n)] ans1, ans2 = 0, 0 cnt = 0 for x in a: cnt += len(x) fl = True while cnt > 0: mx = -1 ind = -1 for j in range(n): if len(a[j]) == 0: continue if a[j][0] > mx: mx = a[j][0] ind = j if a[j][-1] > mx: mx = a[j][-1] ind = j...
43
109
0
42135411
n=int(input()) s1,s2=0,0 tab = [] for i in range(n): c = list(map(int,input().split())) for j in range(1,c[0]+1): if(j*2<=c[0]): s1+=c[j] else: s2+=c[j] if(c[0] & 1): s2-=c[(c[0]+1)//2] tab.append(c[(c[0]+1)//2]) if(len(tab)): tab.sort() tab.reverse() ...
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
39/B
39
B
PyPy 3-64
TESTS
0
92
0
188386580
class solve: def __init__(self): n=int(input()) a=list(map(int,input().split())) c,flag=1,1 for i in range(n): if a[i]==c: flag=0 print(2001+i,end=" ") c+=1 if flag: print(0) else: pri...
35
92
0
207126051
n=int(input()) ls=list(map(int,input().split())) if 1 not in ls: print(0) else: c=1 x=[ls.index(c)+1] ls=ls[ls.index(c):] l=n-len(ls) k=1 while ls.index(c)<=(n-1): c+=1 if c in ls: k+=1 x.append(ls.index(c)+1+l) ls=ls[ls.index(c):] ...
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th...
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
null
null
[{"input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010"}, {"input": "3\n-1 -2 -3", "output": "0"}]
1,300
["greedy"]
35
[{"input": "10\r\n-2 1 1 3 2 3 4 -10 -2 5\r\n", "output": "5\r\n2002 2005 2006 2007 2010 "}, {"input": "3\r\n-1 -2 -3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n2002 "}, {"input": "2\r\n-1 1\r\n", "output":...
false
stdio
null
true
61/D
61
D
PyPy 3
TESTS
2
124
0
64863972
def dfs(v, p): global s used[v] = 1 for u in range(n): if used[u] == 0 and data[u][v] != -1: s += data[u][v] dfs(u, v) if v == 0: ans.append(s) s = 0 n = int(input()) used = [0] * n ans = [] data = [] s = 0 for i in range(n): data.append(...
56
655
18,432,000
114398878
n = int(input()) matrix = [[] * n for i in range(n)] conn = dict() def dfs(el, el2): suma = 0 for element in matrix[el]: if element[0] != el2: suma = max(suma, element[1]+dfs(element[0],el)) return suma suma=0 for i in range(n-1): line = input() line = line.split(' ') matr...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too ti...
First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities. Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
null
null
[{"input": "3\n1 2 3\n2 3 4", "output": "7"}, {"input": "3\n1 2 3\n1 3 3", "output": "9"}]
1,800
["dfs and similar", "graphs", "greedy", "shortest paths", "trees"]
56
[{"input": "3\r\n1 2 3\r\n2 3 4\r\n", "output": "7\r\n"}, {"input": "3\r\n1 2 3\r\n1 3 3\r\n", "output": "9\r\n"}, {"input": "5\r\n5 3 60\r\n4 3 63\r\n2 1 97\r\n3 1 14\r\n", "output": "371\r\n"}, {"input": "3\r\n2 1 63\r\n3 1 78\r\n", "output": "204\r\n"}, {"input": "13\r\n8 2 58\r\n2 1 49\r\n13 10 41\r\n11 9 67\r\n6 4...
false
stdio
null
true
508/D
508
D
Python 3
TESTS
5
46
4,505,600
134572284
m=int(input()) if m==5: print("YES");print("abacaba") elif m==4: print("NO") elif m==7: print("YES");print("aaaaaaaaa") elif m==1: print("YES");print("abc") elif m==3: print("YES");print("aaab") elif m==2: print("YES") n=input() if n=="bba":print("abba") else:print("baba")
44
545
37,478,400
205310388
from collections import defaultdict, deque def find_eulerian_path(graph): in_degree = defaultdict(int) out_degree = defaultdict(int) for u in graph: for v in graph[u]: out_degree[u] += 1 in_degree[v] += 1 start = None end = None for node in set(in_degree.keys())...
Codeforces Round 288 (Div. 2)
CF
2,015
2
256
Tanya and Password
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password ...
The first line contains integer n (1 ≤ n ≤ 2·105), the number of three-letter substrings Tanya got. Next n lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit.
If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO". If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option.
null
null
[{"input": "5\naca\naba\naba\ncab\nbac", "output": "YES\nabacaba"}, {"input": "4\nabc\nbCb\ncb1\nb13", "output": "NO"}, {"input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa", "output": "YES\naaaaaaaaa"}]
2,500
["dfs and similar", "graphs"]
44
[{"input": "5\r\naca\r\naba\r\naba\r\ncab\r\nbac\r\n", "output": "YES\r\nabacaba\r\n"}, {"input": "4\r\nabc\r\nbCb\r\ncb1\r\nb13\r\n", "output": "NO\r\n"}, {"input": "7\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\n", "output": "YES\r\naaaaaaaaa\r\n"}, {"input": "1\r\nabc\r\n", "output": "YES\r\nabc\r\n"}, {"inpu...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline().strip()) input_substrings = [f.readline().strip() for _ in range(n)] # Read reference output with open(output_path) as f:...
true
508/D
508
D
PyPy 3-64
TESTS
4
62
614,400
213949730
""" Папин пароль представляет собой строку, состоящую из n+2 символов. Она выписала все возможные n трёхбуквенных подстрок пароля на бумажки, по одной на каждую бумажку, а сам пароль выкинула. Каждая трёхбуквенная подстрока была выписана на бумажки столько раз, сколько она встречалась в пароле. Таким образом, в итоге у...
44
1,544
27,545,600
183431418
from collections import defaultdict n = int(input()) subs = [input() for i in range(n)] in_degree = defaultdict(int) out_degree = defaultdict(int) adj = defaultdict(list) nodes = set() for sub in subs: a = sub[:2] b = sub[1:] nodes.add(a) nodes.add(b) out_degree[a] += 1 in_degree[b] += 1 ...
Codeforces Round 288 (Div. 2)
CF
2,015
2
256
Tanya and Password
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password ...
The first line contains integer n (1 ≤ n ≤ 2·105), the number of three-letter substrings Tanya got. Next n lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit.
If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO". If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option.
null
null
[{"input": "5\naca\naba\naba\ncab\nbac", "output": "YES\nabacaba"}, {"input": "4\nabc\nbCb\ncb1\nb13", "output": "NO"}, {"input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa", "output": "YES\naaaaaaaaa"}]
2,500
["dfs and similar", "graphs"]
44
[{"input": "5\r\naca\r\naba\r\naba\r\ncab\r\nbac\r\n", "output": "YES\r\nabacaba\r\n"}, {"input": "4\r\nabc\r\nbCb\r\ncb1\r\nb13\r\n", "output": "NO\r\n"}, {"input": "7\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\naaa\r\n", "output": "YES\r\naaaaaaaaa\r\n"}, {"input": "1\r\nabc\r\n", "output": "YES\r\nabc\r\n"}, {"inpu...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline().strip()) input_substrings = [f.readline().strip() for _ in range(n)] # Read reference output with open(output_path) as f:...
true
51/A
51
A
PyPy 3
TESTS
15
312
22,732,800
128514137
s = set() for i in range(int(input())): if i: input() a,b = input().strip() c,d = input().strip() s.add(a + b + c + d) s.add(c + a + d + b) s.add(d + c + b + a) s.add(b + d + a + c) print(len(s) // 4)
20
92
0
153726926
def contains(arr,item): for i in range(4): if item in arr: return True item = f'{item[2]}{item[0]}{item[3]}{item[1]}' return False n = int(input()) arr = [] for i in range(n): helper = input() + input() if i < n - 1: input() if not contains(arr,helper): ...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
51/A
51
A
PyPy 3-64
TESTS
13
218
3,276,800
225082048
n = int(input()) amulets = ['' for i in range(n)] for i in range(n): amulets[i] += input() amulets[i] += input() if i != n-1: _ = input() set_am = set() for amulet in amulets: set_am.add(''.join(sorted(amulet))) print(len(set_am))
20
92
0
160265109
def rotate(matrix): t = ((matrix[1][0], matrix[0][0]),(matrix[1][1], matrix[0][1])) return t n = int(input()) s = set() for _ in range(n): l = int(input()) l1 = (int(l/10), l%10) l = int(input()) l2 = (int(l/10), l%10) if _!=n-1: l3 = input() l = (l1, l2) if l not i...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
51/A
51
A
Python 3
TESTS
13
186
307,200
74849960
t=int(input()) a=[] d={} for i in range(t): m=input() n=input() li=[int(m[0]),int(m[1]),int(n[0]),int(n[1])] li.sort() a.append(li) if i<=t-2: c=input() b=[] c=0 for i in range(len(a)): if a[i] not in b: b.append(a[i]) c+=1 print(c)
20
92
0
161713397
n=int(input()) d=set() for i in range(n): s=input()+input()[::-1] if i<n-1:input() if all(s not in x for x in d):d.add(2*s) print(len(d))
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
441/A
441
A
PyPy 3
TESTS
3
155
1,638,400
118813406
import sys import math import collections import heapq input=sys.stdin.readline n,v=(int(i) for i in input().split()) l=[] c=0 for i in range(n): l1=sorted([int(i) for i in input().split()]) if(l1[l1[0]]==l1[1]): if(l1[1]<v): c+=1 l.append(i+1) elif(l1[1]<v and l1[l1[0]]>v): ...
26
31
0
147678160
l=list(map(int,input().rstrip().split())) n=l[0] v=l[1] res=0 l2=[] for i in range(n): l1=list(map(int,input().rstrip().split())) if v>min(l1[1:]): res+=1 l2.append(i+1) print(res) for x in l2: print(x,end=" ")
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
PyPy 3
TESTS
25
124
1,536,000
117511883
(lambda t, mon: (lambda f: [print(len(f)), print(*f)])(sorted([i + 1 for i in range(t) if mon - min(list(map(int, input().split()))[1:]) - 1> 0])) )(*list(map(int, input().split())))
26
46
0
11634739
n, m = [int(i) for i in input().split()] ans = [] for i in range(n): if any(m > int(k) for k in input().split()[1:]): ans.append(i + 1) print(len(ans)) print(*ans)
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
149/C
149
C
Python 3
TESTS
1
30
0
171727491
import heapq from operator import le n = int(input()) s = input().split() p = [(s[i], i+1) for i in range(len(s))] p.sort(key = lambda k: k[0], reverse=True) x = [str(p[0][1])] y = [] p = p[1:] while p: x.append(str(p.pop(0)[1])) y.append(str(p.pop(0)[1])) print(len(x)) print(' '.join(x)) print(len(y)) pri...
47
389
9,113,600
136760117
# from dust i have come, dust i will be n = int(input()) a = list(map(int, input().split())) arr = [] for i in range(n): arr.append((a[i], i + 1)) arr.sort(reverse=True) t1 = [] t2 = [] sum1 = 0 sum2 = 0 ex = -1 if n % 2 == 1: ex = arr[n - 1][1] n -= 1 for i in range(0, n, 2): if arr[i][0] >= arr[...
Codeforces Round 106 (Div. 2)
CF
2,012
1
256
Division into Teams
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the ...
The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills.
On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individu...
null
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, th...
[{"input": "3\n1 2 1", "output": "2\n1 2\n1\n3"}, {"input": "5\n2 3 3 1 1", "output": "3\n4 1 3\n2\n5 2"}]
1,500
["greedy", "math", "sortings"]
47
[{"input": "3\r\n1 2 1\r\n", "output": "2\r\n1 2 \r\n1\r\n3 \r\n"}, {"input": "5\r\n2 3 3 1 1\r\n", "output": "3\r\n4 1 3 \r\n2\r\n5 2 \r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 1 2 2\r\n", "output": "5\r\n8 2 4 6 9 \r\n5\r\n1 3 5 7 10 \r\n"}, {"input": "10\r\n2 3 3 1 3 1 1 1 2 2\r\n", "output": "5\r\n4 7 1 10 3 \r\n5\r\n6...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline().strip()) a = list(map(int, f.readline().split())) max_a = max(a) with open(submission_path) as f: lines = [line.strip() for line in f.readlines()] if len...
true
39/B
39
B
PyPy 3-64
TESTS
0
92
0
208045153
n=int(input()) ls=list(map(int,input().split())) a=1 b=0 temp=[] for i in range(n): if ls[i]==a: temp.append(2000+i+1) a+=1 if (len(temp)==0): print(0) else: print(temp)
35
92
0
231574547
n = int(input()) dynamic = list(map(int, input().split())) res = [] k = 1 for i in range(len(dynamic)): if dynamic[i] == k: k += 1 res.append(i) k -= 1 print(k) if k != 0: for i in range(k - 1): print(res[i]+2001, end=" ") print(res[k-1]+2001)
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th...
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
null
null
[{"input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010"}, {"input": "3\n-1 -2 -3", "output": "0"}]
1,300
["greedy"]
35
[{"input": "10\r\n-2 1 1 3 2 3 4 -10 -2 5\r\n", "output": "5\r\n2002 2005 2006 2007 2010 "}, {"input": "3\r\n-1 -2 -3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n2002 "}, {"input": "2\r\n-1 1\r\n", "output":...
false
stdio
null
true
51/A
51
A
PyPy 3
TESTS
13
310
2,662,400
104914539
n=int(input()) s=[] for i in range(n): a=input() b=input() c=[i for i in a]+[j for j in b] s.append(sorted(c)) if i!=n-1: string=input() print(len(set(map(tuple,s))))
20
92
0
166326852
# def isPile(first, second, third, fourth): # helper1 = first # helper2 = second # helper3 = third # helper4 = fourth # # first = second # second = fourth # third = helper1 # fourth = helper3 # # if first == helper1 and second == helper2 and third == helper3 and fourth == helper4: # ...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
51/A
51
A
Python 3
TESTS
12
92
0
218198620
n = int(input()) x = [] for i in range(n): a = [int(j) for j in input()] b = [int(j) for j in input()] if i < n - 1: input() x.append(abs(a[0]*b[1] - a[1]*b[0])) y = [] for i in x: if i not in y: y.append(i) print(len(y))
20
92
0
182426473
n = int(input()) #n = input() #m = input(); m = m.split() #n = [int(x) for x in n] #m = [int(x) for x in m] a = [] for i in range(n): c = input() b = input() if i < n-1: s = input() c = c + b[1] + b[0] f = True for j in a: if c in j: f = False break if f: ...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
51/A
51
A
PyPy 3-64
TESTS
11
154
1,536,000
165076983
import sys input = sys.stdin.readline from collections import Counter n = int(input()) w = Counter() for i in range(n): a, b = map(int, list(input()[:-1])) c, d = map(int, list(input()[:-1])) if i != n-1: input() x = tuple(sorted([a,b,c,d,7-a,7-b,7-c,7-d])) w[x] += 1 print(len(w))
20
92
0
185080897
n = int(input()) piles = [] for i in range(n-1): line1 = input() line2 = input() seperator = input() line1 = [int(x) for x in str(line1)] line2 = [int(x) for x in str(line2)] line1.append(line2[1]) line1.append(line2[0]) amulet = line1 amulet90 = amulet.copy() amulet90.i...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
51/B
51
B
Python 3
TESTS
8
186
307,200
84138596
s = "" try: while(1): s += input() except: pass l = s[1:-1].split("><") x = [0] * (l.count("table")) p = -1 for i in l: if(i == "table"): p += 1 elif(i == "td"): x[p] += 1 elif(i == "/table"): p -= 1 print(" ".join(list(map(str, x))))
19
124
1,740,800
214322478
import sys def solve(): r = str(input()) while r.count("<table>") > r.count("</table>") or r.count("<table>") == 0: r += str(input()) s = list(map(str, r.split("<"))) res = [] stack = [] for i in range(1, len(s)): if s[i] == "table>": stack += [0] elif s[...
Codeforces Beta Round 48
CF
2,010
2
256
bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML t...
For convenience, input data can be separated into non-empty lines in an arbitrary manner. The input data consist of no more than 10 lines. Combine (concatenate) all the input lines into one, to get a text representation s of the specified table. String s corresponds to the given grammar (the root element of grammar is ...
Print the sizes of all the tables in the non-decreasing order.
null
null
[{"input": "<table><tr><td></td></tr></table>", "output": "1"}, {"input": "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "output": "1 4"}, {"input": "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td>...
1,700
["expression parsing"]
19
[{"input": "<table><tr><td></td></tr></table>\r\n", "output": "1 "}, {"input": "<table>\r\n<tr>\r\n<td>\r\n<table><tr><td></td></tr><tr><td></\r\ntd\r\n></tr><tr\r\n><td></td></tr><tr><td></td></tr></table>\r\n</td>\r\n</tr>\r\n</table>\r\n", "output": "1 4 "}, {"input": "<table><tr><td>\r\n<table><tr><td>\r\n<table><t...
false
stdio
null
true
288/E
288
E
PyPy 3-64
TESTS
4
122
28,774,400
225464248
number1 = int(input()) number2 = int(input()) list_number = [] list_exceptions = ["0","1","2","3","5","6","8","9"] length = len(str(number1)) multiple = length - 1 lowest = "4"*length highest = "7"*length low_ceiling = "4" + "7"*multiple high_floor = "7" + "4"*multiple buffer = 0 for number in range(int(lowest), int...
52
622
85,196,800
225501681
mod = 1000000007 N = 100000 two = [0] * (N + 1) ten = [0] * (N + 1) four = [0] * (N + 1) seven = [0] * (N + 1) prod = [0] * (N + 1) sum_val = [0] * (N + 1) Prod = [0] * (N + 1) lar = [0] * (N + 1) dp = [[False, False] for _ in range(N + 1)] pa = [[-1, -1] for _ in range(N + 1)] def init(): two[0] = ten[0] = 1 ...
Codeforces Round 177 (Div. 1)
CF
2,013
2
256
Polo the Penguin and Lucky Numbers
Everybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Polo the Penguin have two positive integers l and r (l < r), both of them are lucky numbers. Moreover, their lengths (that i...
The first line contains a positive integer l, and the second line contains a positive integer r (1 ≤ l < r ≤ 10100000). The numbers are given without any leading zeroes. It is guaranteed that the lengths of the given numbers are equal to each other and that both of them are lucky numbers.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
null
null
[{"input": "4\n7", "output": "28"}, {"input": "474\n777", "output": "2316330"}]
2,800
["dp", "implementation", "math"]
52
[{"input": "4\r\n7\r\n", "output": "28\r\n"}, {"input": "474\r\n777\r\n", "output": "2316330\r\n"}, {"input": "44\r\n77\r\n", "output": "11244\r\n"}, {"input": "444\r\n777\r\n", "output": "2726676\r\n"}, {"input": "444\r\n477\r\n", "output": "636444\r\n"}, {"input": "444\r\n744\r\n", "output": "991332\r\n"}, {"input": ...
false
stdio
null
true
39/B
39
B
PyPy 3
TESTS
0
60
0
148650534
n = int(input()) arr = list(map(int, input().split())) lis = [] cur= 1 for i in range(n): if arr[i] == cur: lis.append(2001+i) cur += 1 if lis: print(*lis) else: print(0)
35
122
0
13279657
i=input n=i() m=list(map(int,i().split())) t=1 p=[] for x in range(len(m)): if(t==m[x]): p.append(2001+x) t+=1 print(t-1) for _ in range(len(p)): print(p[_],end=" ")
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th...
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
null
null
[{"input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010"}, {"input": "3\n-1 -2 -3", "output": "0"}]
1,300
["greedy"]
35
[{"input": "10\r\n-2 1 1 3 2 3 4 -10 -2 5\r\n", "output": "5\r\n2002 2005 2006 2007 2010 "}, {"input": "3\r\n-1 -2 -3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n2002 "}, {"input": "2\r\n-1 1\r\n", "output":...
false
stdio
null
true
445/A
445
A
Python 3
TESTS
13
62
307,200
109683587
n,m = map(int, input().split()) s = list("WB"*(m//2) + 'W'*(m%2)) order = [s if i%2 == 0 else s[::-1] for i in range(n)] inp = [] for i in range(n): inp.append(list(input())) for i in range(n): for j in range(m): if inp[i][j] == '.': inp[i][j] = order[i][j] else: inp[i][j] = '-' for i in range(n): print(""...
37
46
0
141077150
n,m=map(int,input().split()) chess=[] for i in range(n): s=input() chess.append(s) res=[] for row in range(n): if(row%2==0): if(m%2==0): s="WB"*(m//2) else: s="WB"*(m//2)+"W" else: if(m%2==0): s="BW"*(m//2) else: s="BW"*(m/...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.
Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guara...
null
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
[{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}]
1,200
["dfs and similar", "implementation"]
37
[{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\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: lines = f.readlines() n, m = map(int, lines[0].split()) input_grid = [list(line.strip()) for line in lines[1:n+1]] with open(submission_path) as f: ...
true
445/A
445
A
Python 3
TESTS
13
62
307,200
109682691
n,m = map(int, input().split()) s = "BW"*(m//2) + 'B'*(m%2) s_inv = s[::-1] for i in range(n): inp = list(input()) if i%2 == 0: order = s else: order = s_inv for j in range(m): if inp[j] == '.': inp[j] = order[j] print("".join(inp))
37
46
0
141179371
n,m=map(int,input().split()) chess=['W','B'] for i in range(n): grid = list(input()) for j in range(m): if grid[j] == '.': grid[j] = chess[(i+j)%2] print(''.join(grid))
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.
Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guara...
null
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
[{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}]
1,200
["dfs and similar", "implementation"]
37
[{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\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: lines = f.readlines() n, m = map(int, lines[0].split()) input_grid = [list(line.strip()) for line in lines[1:n+1]] with open(submission_path) as f: ...
true
445/A
445
A
PyPy 3-64
TESTS
13
62
1,945,600
222521463
from sys import stdin from itertools import cycle input = stdin.readline def instr(): return input()[:-1] stat = cycle(["W", "B"]) # print(stat[1^stat.index("B")]) n, m = map(int, input().split()) chess = [] for i in range(n): chess.append(list(instr())) pawn = next(stat) for i in range(n): for j in range(m...
37
46
0
144299375
n,m = map(int,input().split()) arr = [input() for _ in range(n)] for i in range(n): for j in range(m): if arr[i][j]=='-': print('-',end='') else: if((i+j)%2==0): print('B',end='') else: print('W',end='') print()
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.
Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guara...
null
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
[{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}]
1,200
["dfs and similar", "implementation"]
37
[{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\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: lines = f.readlines() n, m = map(int, lines[0].split()) input_grid = [list(line.strip()) for line in lines[1:n+1]] with open(submission_path) as f: ...
true
445/A
445
A
Python 3
TESTS
13
77
6,963,200
129456001
n,m = map(int,input().split()) l = list() for i in range(n): ii = input() l.append([x for x in ii]) b = 'B' w = 'W' c = 0 ans = list() # print(c) for i in l: a1 = [] for x in i: if x=='-': a1.append(x) else: if c%2==0: a1.append(b) else: a1.append(w) c+=1 c+=1 ans.append(a1) for i in an...
37
46
0
145643897
n,m=map(int,input().split()) p=['B','W'] for i in range(n): s=list(input()) for j in range(m): if s[j]=='.': s[j]=p[(i+j)%2] print(''.join(s))
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.
Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guara...
null
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
[{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}]
1,200
["dfs and similar", "implementation"]
37
[{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\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: lines = f.readlines() n, m = map(int, lines[0].split()) input_grid = [list(line.strip()) for line in lines[1:n+1]] with open(submission_path) as f: ...
true
888/A
888
A
Python 3
TESTS
5
93
307,200
94017726
n = int(input()) a = input().split(" ") f = 0 c = 0 i = 1 while i < n: if int(a[i])>int(a[i-1]): if f == -1: c+=1 f = 1 else: f = 1 elif int(a[i])<int(a[i-1]): if f == 1: c+=1 f = -1 else: f = -1 i+=1 print(c)
14
31
0
146997308
a= int(input()) t= list(map(int, input().split())) count=0 for i in range(1,len(t)-1): if t[i]<t[i+1]and t[i]<t[i-1]: count+=1 elif t[i]>t[i+1]and t[i]>t[i-1]: count+=1 print(count)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
976/D
976
D
PyPy 3-64
TESTS
2
46
0
185942894
n=int(input()) d=list(map(int,input().split())) dn=d[-1]+1 odd=-1 even=-1 for i in d[::-1]: if i%2==0: even=i else: odd=i use=d.copy() if even!=-1 and odd!=-1: while len(use)<dn-1: use.append(min(odd,even)) if sum(use)%2==0: use.append(even) else: use.append(odd) elif even!=-1: while le...
20
499
53,248,000
38632816
# python3 def readline(): return list(map(int, input().split())) def solve(d): while d: dn = d.pop() if not d: for i in range(1, dn + 1): for j in range(i, dn + 1): yield i, j + 1 return else: d1 = d.pop(0) ...
Educational Codeforces Round 43 (Rated for Div. 2)
ICPC
2,018
2
256
Degree Set
You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that: - there are exactly dn + 1 vertices; - there are no self-loops; - there are no multiple edges; - there are no more than 106 edges; - its degree set is equal to d. Vertices sho...
The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.
In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges. Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description o...
null
null
[{"input": "3\n2 3 4", "output": "8\n3 1\n4 2\n4 5\n2 5\n5 1\n3 2\n2 1\n5 3"}, {"input": "3\n1 2 3", "output": "4\n1 2\n1 3\n1 4\n2 3"}]
2,500
["constructive algorithms", "graphs", "implementation"]
20
[{"input": "3\r\n2 3 4\r\n", "output": "8\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "4\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n"}, {"input": "4\r\n1 3 4 6\r\n", "output": "11\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n"}, {"input": "...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline()) d_list = list(map(int, f.readline().split())) with open(submission_path) as f: lines = f.read().splitlines() if not lines: print(0) return ...
true
388/C
388
C
PyPy 3
TESTS
5
93
0
111355258
n = int(input()) S = [0] * n ciel, giro = [], [] a, b = 0, 0 for i in range(n): L = list(map(int, input().split())) k = L[0] L = L[1:] S[i] = sum(L) if k % 2: ciel.append((sum(L[:k // 2 + 1]), i)) giro.append((sum(L[k // 2:], i), i)) else: a += sum(L[:k // 2]) ...
43
109
0
54828440
n = int(input()) a = b = 0 s = [] for _ in range(n): l = [*map(int, input().split())][1:] m = len(l) if m & 1: s.append(l[m//2]) a += sum((l[:m//2])) b += sum((l[(m + 1)//2:])) s.sort(reverse = True) a += sum(s[::2]) b += sum(s[1::2]) print(a, b)
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
5
93
0
93914617
c = 0 n = int(input()) li = input().split() for i in range(n): if i != 0 and i != n-1: if li[i-1] > li[i] and li[i+1] > li[i] or li[i-1] < li[i] and li[i+1] < li[i]: c += 1 print(c)
14
31
0
148053591
n = int(input()) count = 0 a = list(map(int, input().split())) if len(a) == 1 or len(a) == 2: print(0) else: for i in range(1, n-1): if a[i-1] < a[i] > a[i+1] or a[i-1] > a[i] < a[i+1]: count += 1 print(count)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
884/D
884
D
PyPy 3-64
TESTS
3
264
8,908,800
150318980
n = int(input()) s =0 if n%2: a = list(map(int,input().split())) else: a = [0]+list(map(int,input().split())) while len(a)>2: m = a[0] a.pop(0) n = a[0] a.pop(0) o = a[0] a.pop(0) s +=m+n+o a.append(m+n+o) print(s)
32
405
16,486,400
32036042
from heapq import * n=int(input()) a=list(map(int,input().split())) s=0 if len(a)%2==0: a=[0]+a n+=1 def sc(a,s=0): heapify(a) for i in range ((n-1)//2): k=heappop(a)+heappop(a)+heappop(a) s+=k heappush(a,k) print(s) sc(a)
Educational Codeforces Round 31
ICPC
2,017
2
256
Boxes And Balls
Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≤ i ≤ n) i-th box will contain all balls with color i. In order to do this, Ivan will make some turns. Each turn he ...
The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of boxes and colors. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of balls with color i.
Print one number — the minimum possible penalty of the game.
null
In the first example you take all the balls from the first box, choose k = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose k = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest pu...
[{"input": "3\n1 2 3", "output": "6"}, {"input": "4\n2 3 4 5", "output": "19"}]
2,300
["data structures", "greedy"]
32
[{"input": "3\r\n1 2 3\r\n", "output": "6\r\n"}, {"input": "4\r\n2 3 4 5\r\n", "output": "19\r\n"}, {"input": "6\r\n1 4 4 4 4 4\r\n", "output": "38\r\n"}, {"input": "8\r\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158\r\n", "output": "8176373828\r\n"}, {"input": "1\r\n10\r\n", "output": ...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
5
93
0
40208854
n = int(input()) numbers = list(map(int, input().split())) result = 0 for index in range(n): if(index > 0 and index < n - 1): if(((numbers[index] < numbers[index-1]) and (numbers[index] < numbers[index+1])) or ((numbers[index] > numbers[index+1]) and (numbers[index] > numbers[index+1]))): ...
14
31
0
151473463
def solution(arr): res = 0 for i in range(1, len(arr)-1, 1): if arr[i] > arr[i-1] and arr[i] > arr[i+1] or arr[i] < arr[i-1] and arr[i] < arr[i+1]: res += 1 print(res) while True: try: n = int(input()) arr = list(map(int, input().split())) solution(arr) ...
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
723/D
723
D
Python 3
TESTS
11
46
307,200
205208720
import copy n, m, k = map(int, input().strip().split()) land = [[i for i in input()] for _ in range(n)] tmp = copy.deepcopy(land) dx = (0, 0, -1, 1) dy = (-1, 1, 0, 0) visited = [[False for _ in range(m)] for _ in range(n)] def DFS(my_stack: list, land: list): while len(my_stack) > 0: top = my_stack.pop...
26
46
0
189671114
n,m,k=map(int,input().split()) visited=[[False]*(52) for _ in range(54)] l=[] matrix=[] for _ in range(n): matrix.append(list(el for el in input())) def dfs(i,j): visited[i][j]=True q=[(i,j)] t=[] f=False while q: x,y=q.pop() t.append((x,y)) if x==0 or x==n-1 or y==0 or y...
Codeforces Round 375 (Div. 2)
CF
2,016
2
256
Lakes in Berland
The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that ...
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell ...
In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri...
null
In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with th...
[{"input": "5 4 1\n****\n*..*\n****\n**.*\n..**", "output": "1\n****\n*..*\n****\n****\n..**"}, {"input": "3 3 0\n***\n*.*\n***", "output": "1\n***\n***\n***"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy", "implementation"]
26
[{"input": "5 4 1\r\n****\r\n*..*\r\n****\r\n**.*\r\n..**\r\n", "output": "1\r\n****\r\n*..*\r\n****\r\n****\r\n..**\r\n"}, {"input": "3 3 0\r\n***\r\n*.*\r\n***\r\n", "output": "1\r\n***\r\n***\r\n***\r\n"}, {"input": "3 5 1\r\n.**.*\r\n*.*.*\r\n***..\r\n", "output": "0\r\n.**.*\r\n*.*.*\r\n***..\r\n"}, {"input": "3 5...
false
stdio
import sys from sys import argv def main(): input_path = argv[1] output_path = argv[2] submission_path = argv[3] with open(input_path, 'r') as f: input_lines = f.read().splitlines() n, m, k = map(int, input_lines[0].split()) original_map = input_lines[1:n+1] with open(output_path,...
true
175/C
175
C
PyPy 3-64
TESTS
2
92
0
166084108
import heapq n = int(input()) pq = [] for i in range(n): cnt, score = list(map(int, input().split())) heapq.heappush(pq, (-score, cnt)) t = int(input()) p = list(map(int, input().split())) p.insert(0, 0) rate = 1 ret = 0 for i in range(1, len(p)): diff = p[i]-p[i-1] a = 0 while pq and a < diff: ...
90
310
0
61381751
if __name__ == '__main__': n = int(input()) pieces = [input() for _ in range(n)] pieces = [_.split() for _ in pieces] pieces = [tuple(_) for _ in pieces] pieces = [[int(k), int(c)] for k, c in pieces] t = int(input()) p = input().split() p = [int(_) for _ in p] pieces = sorted(piece...
Codeforces Round 115
CF
2,012
2
256
Geometry Horse
Vasya plays the Geometry Horse. The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are n types of geometric figures. The number of figures of type ki and figure cost ci is know...
The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of figure types. Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly. The next l...
Print the only number — the maximum number of points Vasya can get.
null
In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points. In the second example all 8 figures will be destroyed with factor 1, so Vasya wi...
[{"input": "1\n5 10\n2\n3 6", "output": "70"}, {"input": "2\n3 8\n5 10\n1\n20", "output": "74"}]
1,600
["greedy", "implementation", "sortings", "two pointers"]
90
[{"input": "1\r\n5 10\r\n2\r\n3 6\r\n", "output": "70"}, {"input": "2\r\n3 8\r\n5 10\r\n1\r\n20\r\n", "output": "74"}, {"input": "3\r\n10 3\r\n20 2\r\n30 1\r\n3\r\n30 50 60\r\n", "output": "200"}, {"input": "1\r\n100 1000\r\n1\r\n1\r\n", "output": "199000"}, {"input": "1\r\n1 1000\r\n1\r\n1\r\n", "output": "1000"}, {"i...
false
stdio
null
true
847/H
847
H
Python 3
TESTS
8
109
0
60496858
n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] d = [int(s) for s in input().split()] last = d[0] for i in range(1,n): a[i] = a[i-1] if d[i] <= last: a[i] += abs(d[i] - last) + 1 last+=1 else: last = d[i] last = d[n-1] for i in range(n-2,-1,-1): b[...
39
109
20,582,400
182942535
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) d = [w[0]] e = [w[-1]] for i in w[1:]: d.append(max(d[-1]+1, i)) for i in w[:-1][::-1]: e.append(max(e[-1]+1, i)) e = e[::-1] c = 10**18 f = -1 for i in range(n): a = max(d[i], e[i]) b = (2*a-i)*(i+1) + (2*a-(n-i...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
850/A
850
A
Python 3
TESTS
3
46
0
31280549
from math import sqrt, acos, pi n = int(input()) p = [tuple(map(int, input().split())) for i in range(n)] def x_y(x, y): return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] + x[4]*y[4] def angle(x, y): xy = x_y(x, y) xx = sqrt(x_y(x, x)) yy = sqrt(x_y(y, y)) d = xx * yy return pi if d == 0...
19
46
102,400
230887894
d = lambda i, j, k: sum((a - c) * (b - c) for a, b, c in zip(p[i], p[j], p[k]))*(i!=j) n = int(input()) r = range(n) p = [list(map(int, input().split())) for i in r] t = [k + 1 for k in r if all(d(i, j, k) <= 0 for i in r for j in r)] if n <12 else [] print(len(t)) for q in t: print(q)
Codeforces Round 432 (Div. 1, based on IndiaHacks Final Round 2017)
CF
2,017
2
256
Five Dimensional Points
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $${ \vec { a } } { \vec { b } }$$ and $${ \vec { a } } { \vec { c } }$$ is...
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points. The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103)  — the coordinates of the i-th point. All points are distinct.
First, print a single integer k — the number of good points. Then, print k integers, each on their own line — the indices of the good points in ascending order.
null
In the first sample, the first point forms exactly a $$90^\circ$$ angle with all other pairs of points, so it is good. In the second sample, along the cd plane, we can see the points look as follows: We can see that all angles here are acute, so no points are good.
[{"input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1", "output": "1\n1"}, {"input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0", "output": "0"}]
1,700
["brute force", "geometry", "math"]
19
[{"input": "6\r\n0 0 0 0 0\r\n1 0 0 0 0\r\n0 1 0 0 0\r\n0 0 1 0 0\r\n0 0 0 1 0\r\n0 0 0 0 1\r\n", "output": "1\r\n1\r\n"}, {"input": "3\r\n0 0 1 2 0\r\n0 0 9 2 0\r\n0 0 5 9 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0 0 0 0 0\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n0 1 2 3 4\r\n5 6 7 8 9\r\n", "output": "2\r\n1...
false
stdio
null
true
22/E
22
E
PyPy 3
TESTS
10
372
3,174,400
98702225
n = int(input()) g = [int(i) - 1 for i in input().split()] in_cero = [True]*n for v in g: in_cero[v] = False in_cero = [k for k in range(n) if in_cero[k]] in_cero_count = len(in_cero) if not in_cero_count: print(0) else: ids = [-1]*n ID = 0 cycle_id = [-1]*in_cero_count for v in in_cero: ...
40
592
12,800,000
98755646
n = int(input()) g = [int(i) - 1 for i in input().split()] def solve(n, g): vertex_id = [-1]*n current_id = 0 starts_a_cycle = [-1]*n cycle_vertex_sample = [] start_on_cycle = [] cycle_index_by_ID = [] cycle_count = 0 for v in range(n): if vertex_id[v] != -1: continue ...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
888/A
888
A
Python 3
TESTS
5
61
5,529,600
33310718
n=int(input()) list1=input().split() if n==1 or n==2: print(0) else: total=0 for i in range(1,n-1): if list1[i]>list1[i+1] and list1[i]>list1[i-1] or list1[i]<list1[i+1] and list1[i]<list1[i-1]: total+=1 print(total)
14
31
0
152906401
x=input() lis = [int(i) for i in input('').split()] cnt=0 for i in range(1,len(lis)-1): if (lis[i]>lis[i-1] and lis[i]>lis[i+1]) or (lis[i]<lis[i-1] and lis[i]<lis[i+1]): cnt+=1 print(cnt)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
140/D
140
D
Python 3
TESTS
1
216
0
62214972
n=int(input()) a=str(input()).split() a=map(int,a) a=sorted(a) s=10 x=0 for i in range(n): x+=a[i] if x<360: k=n s=0 else: i=0 while 360 >= (s+a[i]): s+=a[i] i+=1 k=i if k !=0: a[i]=a[i]-360+s s=0 while (s+a[i]) <=360: s+=a[i] k...
32
124
0
11600627
import sys from itertools import * from math import * def solve(): n = int(input()) a = list(map(int, input().split())) a.sort() time = -6*60 + 10 maxtime = 6 * 60 completed = 0 penalty = 0 for i, val in enumerate(a): timefinish = time + val if timefinish <= maxtime: ...
Codeforces Round 100
CF
2,012
2
256
New Year Contest
As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest. The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.M.) on January 1. There are n problems for the contest. The penalty time fo...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the problems. The next line contains n space-separated integers ai (1 ≤ ai ≤ 720) — each number shows how much time in minutes Gennady will spend writing a solution to the problem.
Print two integers — the number of problems Gennady will solve and the total penalty time considering that he chooses the optimal strategy.
null
In the sample, one of Gennady's possible optimal strategies is as follows. At 18:10 (6:10 PM) he begins to write the first problem and solves it in 30 minutes (18:40 or 6.40 P.M.). At 18:40 (6.40 P.M.) he begins to write the second problem. There are 320 minutes left before the New Year, so Gennady does not have the ti...
[{"input": "3\n30 330 720", "output": "2 10"}]
1,800
["greedy", "sortings"]
32
[{"input": "3\r\n30 330 720\r\n", "output": "2 10\r\n"}, {"input": "1\r\n720\r\n", "output": "0 0\r\n"}, {"input": "5\r\n100 200 300 400 500\r\n", "output": "3 250\r\n"}, {"input": "7\r\n120 110 100 110 120 120 50\r\n", "output": "6 420\r\n"}, {"input": "3\r\n350 340 360\r\n", "output": "2 340\r\n"}, {"input": "8\r\n15...
false
stdio
null
true
803/F
803
F
PyPy 3
TESTS
8
187
1,536,000
118305827
from sys import stdin, stdout, setrecursionlimit input = stdin.readline # import string # characters = string.ascii_lowercase # digits = string.digits # setrecursionlimit(int(1e6)) # dir = [-1,0,1,0,-1] # moves = 'NESW' inf = float('inf') from functools import cmp_to_key from collections import defaultdict as dd from c...
35
140
19,763,200
165074575
import sys from collections import Counter readline=sys.stdin.readline class Prime: def __init__(self,N): assert N<=10**8 self.smallest_prime_factor=[None]*(N+1) for i in range(2,N+1,2): self.smallest_prime_factor[i]=2 n=int(N**.5)+1 for p in range(3,n,2): ...
Educational Codeforces Round 20
ICPC
2,017
2
256
Coprime Subsequences
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109 + 7. Note th...
The first line contains one integer number n (1 ≤ n ≤ 100000). The second line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 100000).
Print the number of coprime subsequences of a modulo 109 + 7.
null
In the first example coprime subsequences are: 1. 1 2. 1, 2 3. 1, 3 4. 1, 2, 3 5. 2, 3 In the second example all subsequences are coprime.
[{"input": "3\n1 2 3", "output": "5"}, {"input": "4\n1 1 1 1", "output": "15"}, {"input": "7\n1 3 5 15 3 105 35", "output": "100"}]
2,000
["bitmasks", "combinatorics", "number theory"]
35
[{"input": "3\r\n1 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "15\r\n"}, {"input": "7\r\n1 3 5 15 3 105 35\r\n", "output": "100\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n100000\r\n", "output": "0\r\n"}, {"input": "5\r\n10 8 6 4 6\r\n", "output": "0\r\n"}, {"input": "5...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
5
46
5,529,600
32456687
n=int(input()) l=input().split() c=0 for i in range(1,n-1): if (l[i]>l[i-1]) and (l[i]>l[i+1]) : c=c+1 elif ((l[i]<l[i-1]) and (l[i]<l[i+1])): c=c+1 print(c)
14
31
0
153637203
n = int(input()) a = list(map(int,input().split())) k = 0 for i in range (1,n-1): if a[i-1]>a[i]<a[i+1] or a[i-1]<a[i]>a[i+1]: k+=1 print(k)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
518/C
518
C
PyPy 3
TESTS
2
124
20,172,800
87247239
n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) pos=[0 for i in range(n+1)] for i in range(n): pos[a[i]]=i ans=0 for i in b: x=pos[i] ans+=x//k+1 if x!=1: a[x],a[x-1]=a[x-1],a[x] pos[a[x]]=x pos[a[x-1]]=x-1 print(ans)
43
109
18,329,600
192231946
def main(): n, m, k = map(int, input().split()) app = list(map(int, input().split())) pos = [0] * n for i in range(n): app[i] -= 1 pos[app[i]] = i res = 0 for cur in map(int, input().split()): cur -= 1 res += pos[cur] // k + 1 if pos[cur]: pos[...
Codeforces Round 293 (Div. 2)
CF
2,015
1
256
Anya and Smartphone
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th ...
The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen. The next line contains n integers, permutation a1, a2, ..., an — the...
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
null
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8. After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch i...
[{"input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1", "output": "7"}, {"input": "5 4 2\n3 1 5 2 4\n4 4 4 4", "output": "8"}]
1,600
["constructive algorithms", "data structures", "implementation"]
43
[{"input": "8 3 3\r\n1 2 3 4 5 6 7 8\r\n7 8 1\r\n", "output": "7\r\n"}, {"input": "5 4 2\r\n3 1 5 2 4\r\n4 4 4 4\r\n", "output": "8\r\n"}, {"input": "10 10 3\r\n1 2 3 4 5 6 7 8 9 10\r\n2 3 4 5 6 7 8 9 10 1\r\n", "output": "25\r\n"}, {"input": "10 12 3\r\n6 1 2 9 3 10 8 5 7 4\r\n3 9 9 4 8 2 3 8 10 8 3 4\r\n", "output": ...
false
stdio
null
true
518/C
518
C
Python 3
TESTS
2
31
0
143600794
def f(a,b,k): ind=dict() for id,i in enumerate(a): ind[i]=id ans=0 for i in b: ti=ind[i] if ti==1: ans+=1 continue else: ans+=(ti//k)+1 res=a[ti-1] ind[res]=ti a[ti]=res a[ti-1]=i ind[i]=ti-1 ...
43
109
19,046,400
197028284
import sys if __name__ == '__main__': n, m, k = map(int, input().split()) a = list(map(int, sys.stdin.readline().rstrip().split())) pos = [0] * (n + 1) for idx, i in enumerate(a): pos[i] = idx # 记录每个数的位置 ans = 0 for i in map(int, sys.stdin.readline().rstrip().split()): idx = po...
Codeforces Round 293 (Div. 2)
CF
2,015
1
256
Anya and Smartphone
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th ...
The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen. The next line contains n integers, permutation a1, a2, ..., an — the...
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
null
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8. After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch i...
[{"input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1", "output": "7"}, {"input": "5 4 2\n3 1 5 2 4\n4 4 4 4", "output": "8"}]
1,600
["constructive algorithms", "data structures", "implementation"]
43
[{"input": "8 3 3\r\n1 2 3 4 5 6 7 8\r\n7 8 1\r\n", "output": "7\r\n"}, {"input": "5 4 2\r\n3 1 5 2 4\r\n4 4 4 4\r\n", "output": "8\r\n"}, {"input": "10 10 3\r\n1 2 3 4 5 6 7 8 9 10\r\n2 3 4 5 6 7 8 9 10 1\r\n", "output": "25\r\n"}, {"input": "10 12 3\r\n6 1 2 9 3 10 8 5 7 4\r\n3 9 9 4 8 2 3 8 10 8 3 4\r\n", "output": ...
false
stdio
null
true
803/E
803
E
PyPy 3
TESTS
19
171
512,000
118149455
# Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase from collections import deque def main(): n,k=map(int,input().split()) s=list(input().rstrip()) l,r,q=0,0,deque() for i in range(n-1): if s[i]=='W': r+=1 elif ...
28
108
409,600
27015953
n, k = map(int, input().split()) *v, l = input() sets = [(0, 0)] d = {'W' : +1, 'D': 0, 'L': -1} for c in v: ms, mx = sets[-1] ns = max(1 - k, ms + d.get(c, -1)) nx = min(k - 1, mx + d.get(c, +1)) if ns > nx: print('NO') exit(0) sets.append((ns, nx)) ms, mx = sets[-1] if mx == k -...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
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, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
803/E
803
E
PyPy 3
TESTS
27
202
7,168,000
59768811
# 803E import collections def do(): n, k = map(int, input().split(" ")) s = input() if n == 1: return "NO" dp = collections.defaultdict(set) gap = {'W': 1, 'L': -1, 'D': 0} dp[-1].add(0) for i in range(n-1): if s[i] == '?': for pre in dp[i-1]: for ...
28
109
31,334,400
127580899
import sys input = sys.stdin.readline n, k = map(int, input().split()) s = list(input().rstrip()) d = {"W":-1, "D":0, "L":1} dp = [] dp0 = [0] * (2 * k + 1) dp0[k] = 1 dp.append(list(dp0)) for i in range(n): si = s[i] dp1 = [0] * (2 * k + 1) if si == "?": for j in range(1, 2 * k): if dp...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
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, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
803/E
803
E
PyPy 3
TESTS
6
155
0
92988060
import sys n, k = map(int, input().split()) s = list(input()) size, zero = 2*k-1, k-1 dp = [[0]*size for _ in range(n)] dp[0][zero] = 1 for i in range(n-1): for j in range(size): if dp[i][j] == 0: continue if j+1 < size and (s[i] == 'W' or s[i] == '?'): dp[i+1][j+1] = 1 ...
28
233
43,315,200
26797928
N, K = map( int, input().split() ) S = input() offset = K + 1 dp = [ [ False for i in range( offset * 2 ) ] for j in range( N + 1 ) ] pre = [ [ 0 for i in range( offset * 2 ) ] for j in range( N + 1 ) ] # previous state dp[ 0 ][ offset ] = True for i in range( N ): for j in range( offset * 2 ): if not dp[ i ][ j...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
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, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
888/A
888
A
Python 3
TESTS
5
31
0
151462891
n = int(input()) l = [] d = [] j = 0 ans = 0 for i in map(int, input().split(" ")): l.append(i) if j > 0: if l[j-1] < l[j]: d.append(1) else: d.append(-1) if j > 1: if d[j-2] + d[j-1] == 0: ans += 1 j += 1 print(ans)
14
31
0
162453658
f = int(input()) s = list(map(int, input().strip().split())) d = 1 eeznuts = 0 while True: if f == 1 or f == 2 or f == 0: break else: if d == f-1: break if s[d] > s[d-1] and s[d] > s[d+1]: eeznuts = eeznuts + 1 if s[d] < s[d-1] and s[d] < s[d+1]: eeznuts = eeznuts + 1 d = d + ...
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
13
124
6,963,200
124248862
def main_function(): n = int(input()) is_answer_given = False x_d = sorted([[int(i) for i in input().split(" ")] for i in range(n)], key=lambda x:x[0]) for i in range(len(x_d)): for j in range(i, len(x_d)): d = x_d[j][0] - x_d[i][0] if x_d[i][0] == x_d[j][0] + x_d[j][1] a...
30
62
0
153085475
#To solve this I can register the positions of camels and its spits #If I can find a camel that spitted and that camel spited too the awnser is yes numCamels = int(input()) dictCamel = {} listSpit = [] for i in range(numCamels): actualCamel, actualSpit = map(int, input().split()) #I have a camel in positio...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
29/A
29
A
PyPy 3
TESTS
13
186
0
112462233
n = int(input()) nn = n c = 0 p = [] s = [] while n > 0: pt, st = map(int, input().split()) p.append(pt) s.append(st) n -= 1 i = 0 while i < nn: if (p[i]+s[i]) in p: c += 1 i += 1 if c == 2: print('YES') else: print('NO')
30
62
0
153222311
def camels_spits(): n = int(input()) camels_map = [0]*20001 # (-)-10000 + 10000 + 1 (referente ao zero) - Assim o vetor vai do 0 ao 20.000 to_map = 10000 camels = [] for i in range(n): x, d = input().split() camels.append({"x": int(x), "d": int(d)}) camels_map[int(x)+to_map] = {"x": int(x), "d": int(d)} ...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
766/D
766
D
PyPy 3-64
TESTS
8
701
31,948,800
179544849
import collections n, m, q = map(int, input().split()) words = input().split() idx = {word: i for i, word in enumerate(words)} antonym = collections.defaultdict(int) fa = list(range(n)) def find(x): if fa[x] != x: fa[x] = find(fa[x]) return fa[x] def union(x, y): rx, ry = find(x), find(y) ...
32
1,185
73,728,000
143753883
# template begins ##################################### from io import BytesIO, IOBase import sys import math import os import heapq from collections import defaultdict, deque from math import ceil from bisect import bisect_left, bisect_right from time import perf_counter # region fastio BUFSIZE = 8192 class FastI...
Codeforces Round 396 (Div. 2)
CF
2,017
4
256
Mahmoud and a Dictionary
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words. He know that if two words have ...
The first line of input contains three integers n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, m is the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations. The second line contains n distinct words a1, a2, ..., ...
First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print "NO" (without quotes) and ignore it, otherwise print "YES" (without quotes). After that print q lines, one per each question. If the two words have the same mean...
null
null
[{"input": "3 3 4\nhate love like\n1 love like\n2 love hate\n1 hate like\nlove like\nlove hate\nlike hate\nhate like", "output": "YES\nYES\nNO\n1\n2\n2\n2"}, {"input": "8 6 5\nhi welcome hello ihateyou goaway dog cat rat\n1 hi welcome\n1 ihateyou goaway\n2 hello ihateyou\n2 hi goaway\n2 hi hello\n1 hi hello\ndog cat\nd...
2,000
["data structures", "dfs and similar", "dp", "dsu", "graphs"]
32
[{"input": "3 3 4\r\nhate love like\r\n1 love like\r\n2 love hate\r\n1 hate like\r\nlove like\r\nlove hate\r\nlike hate\r\nhate like\r\n", "output": "YES\r\nYES\r\nNO\r\n1\r\n2\r\n2\r\n2\r\n"}, {"input": "8 6 5\r\nhi welcome hello ihateyou goaway dog cat rat\r\n1 hi welcome\r\n1 ihateyou goaway\r\n2 hello ihateyou\r\n2...
false
stdio
null
true
22/E
22
E
PyPy 3
TESTS
10
310
3,788,800
95003009
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) a = [0] + list(map(int, input().split())) rev = [[] for _ in range(n + 1)] indeg = [0] * (n + 1) for i in range(1, n + 1): indeg[a[i]] += 1 rev[a[i]].append(i) _indeg = ind...
40
1,714
90,931,200
157748457
order = [] # Psuedo-topological ordering (we don't care about cycles) visited = set() next_id = 0 nodes = {} # Maps from node to component id components = [] # Maps from component id to a set of nodes def dfs3(start, get_neighbors): ''' Iterative implementation of DFS. Doing DFS with rec...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
408/A
408
A
PyPy 3-64
TESTS
12
61
2,457,600
151381514
# n,k = map(int, input().split()) # arr = list(map(int, input().split())) # print(set(arr)) # i = j = n-1 # while i>0 and arr[i-1] > arr[i]: # i -= 1 # print(i) n=int(input()) arr = list(map(int, input().split())) mn = 20000 for _ in range(n): x = list(map(int, input().split())) l = len(x) mn = m...
20
31
0
147586239
n = int(input()) k = map(int, input().split()) sec = [] for i in range(n): m = list(map(int, input().split())) sec.append(sum(m)*5+len(m)*15) print(min(sec))
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
408/A
408
A
Python 3
TESTS
7
31
0
177362878
num_caj= int(input()) num_persCaja= input().split() menorTiempo = 10000 for i in range(num_caj): tiempo = 15 * int(num_persCaja[i]) items_pp= input().split() for j in range(len(items_pp)): tiempo += 5 * int(items_pp[j]) if (tiempo <menorTiempo): menorTiempo = tiempo print(menorTiempo)
20
31
0
154693106
import sys input = sys.stdin.readline n = int(input()) input() c = 10**9 for _ in range(n): w = list(map(int, input().split())) t = len(w)*15 + sum(w)*5 if t < c: c = t print(c)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
69/C
69
C
PyPy 3
TESTS
44
434
4,198,400
91904969
from collections import defaultdict k,n,m,q = [int(x) for x in input().split()] single = [input() for i in range(n)] comp1 = [input().split(': ') for i in range(m)] comp2 = {x:y.split(', ') for x,y in comp1} def make_tup(ls): ans=[] for s in ls: x,y=s.split() ans.append([x,int(y)]) retur...
47
154
5,324,800
16947235
k,m,n,q = map(int, input().split()) basic = [input() for _ in range(m)] from collections import Counter, defaultdict recipes, accounts = defaultdict(Counter), defaultdict(Counter) for _ in range(n): composite, components = input().split(': ') for unit in components.split(', '): x, y = unit.split() ...
Codeforces Beta Round 63 (Div. 2)
CF
2,011
2
256
Game
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle...
The first line has 4 natural numbers: k (1 ≤ k ≤ 100) — the number of Kostya's allies, n (1 ≤ n ≤ 50) — the number of basic artifacts, m (0 ≤ m ≤ 50) — the number of composite artifacts, q (1 ≤ q ≤ 500) — the number of his friends' purchases. The following n lines contain the names of basic artifacts. After them m line...
The output file should consist of k blocks. The first line should contain number bi — the number of different artifacts the i-th ally has. Then the block should contain bi lines with the names of these artifacts and the number of these artifacts. At that the lines should be printed in accordance with the lexicographica...
null
null
[{"input": "2 3 2 5\ndesolator\nrefresher\nperseverance\nvanguard: desolator 1, refresher 1\nmaelstorm: perseverance 2\n1 desolator\n2 perseverance\n1 refresher\n2 desolator\n2 perseverance", "output": "1\nvanguard 1\n2\ndesolator 1\nmaelstorm 1"}]
2,000
["implementation"]
47
[{"input": "2 3 2 5\r\ndesolator\r\nrefresher\r\nperseverance\r\nvanguard: desolator 1, refresher 1\r\nmaelstorm: perseverance 2\r\n1 desolator\r\n2 perseverance\r\n1 refresher\r\n2 desolator\r\n2 perseverance\r\n", "output": "1\r\nvanguard 1\r\n2\r\ndesolator 1\r\nmaelstorm 1\r\n"}, {"input": "2 3 2 5\r\na\r\nb\r\nc\r...
false
stdio
null
true
456/A
456
A
Python 3
TESTS
39
280
7,782,400
199323845
n=int(input()) l=[] for i in range(n): p,q=map(int,input().split()) l.append((p,q)) for i in range(n-1): if l[i][0] < l[i+1][0] and l[i][1]>l[i+1][1]: print("Happy Alex") break else: print("Poor Alex")
46
124
0
215102055
def solve(n) -> str: for _ in range(n): x, y = input().split() if x != y: return 'Happy' return 'Poor' print(solve(int(input())), 'Alex')
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
456/A
456
A
Python 3
TESTS
39
280
4,710,400
176970390
n = int(input()) x = [] y = [] t = 0 for i in range(1, n+1): a, b = map(int, input().split()) x.append(a) y.append(b) for i in range(0, len(x)-1): j = i+1 if x[i]<x[j] and y[i]>y[j]: t+=1 if t>0: print('Happy Alex') else: print('Poor Alex')
46
124
0
219036058
from sys import stdin a = False for _ in range(int(stdin.readline().strip())): b = list(map(int,stdin.readline().split())) if b[0]<b[1]:a=True print("Happy Alex") if a else print("Poor Alex")
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
5
31
0
162174525
n=int(input()) a = list(map(int,input() .split())) is_local_minimum=False is_local_maximum=False ans=0 for i in range(1, n-1): if a[i]>a[i+1] and a[i]>a[i-1]: is_local_maximum=True if a[i]<a[i+1] and a[i]<a[i-1]: is_local_minimum=True if is_local_minimum or is_local_maximum: ans+=1 ...
14
31
0
179514257
def exsteme(n,a): if n<=2: return 0 k=0 for i in range(1,len(a)-1): if a[i-1]<a[i]>a[i+1] or a[i-1]>a[i]<a[i+1]: k+=1 return k t=int(input()) b=[int(i) for i in input().split()] print(exsteme(t,b))
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
1006/A
1006
A
Python 3
TESTS
4
124
6,963,200
80528250
n=int(input());a=list(map(int,input().split())) if max(a)%2==0: for i in range(n): if a[i]%2==0: print(a[i]-1,end=' ') else: print(a[i],end=' ') else: for i in range(n): if a[i]%2==0: print(a[i]-1,end=' ') elif a[i]%2!=0 and a[i]!=max(a): ...
18
31
0
211066230
x = int(input()) y = list(map(int, input().split())) for i in range(x): if y[i] % 2 == 0 : y[i] = y[i] -1 print(*y)
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Adjacent Replacements
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace ea...
The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.
Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array.
null
The first example is described in the problem statement.
[{"input": "5\n1 2 4 5 10", "output": "1 1 3 5 9"}, {"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"}]
800
["implementation"]
18
[{"input": "5\r\n1 2 4 5 10\r\n", "output": "1 1 3 5 9\r\n"}, {"input": "10\r\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\r\n", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\r\n"}, {"input": "1\r\n999999999\r\n", "output": "999999999\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "99...
false
stdio
null
true
766/C
766
C
Python 3
TESTS
2
46
0
144458969
def verif(l, s): r = s.split('|') m = 0 for i in r: if(m<len(i)): m = len(i) for j in list(set(i)): if(int(l[ord(j)-97])<len(i)): return False return [m, len(r)] def sub_strings(a, s, n): l = [] t = [] r = [] p = 0 maximum ...
37
77
3,276,800
169561377
n = int(input()) ans = 0 s = input() mod = 1000000007 nums = [int(x) for x in input().split()] dp1 = [0]*1002 dp2 = [0]*1002 dp1[0]=1 for i in range(1,n+1): curr = 0 dp2[i]=n for j in range(i-1,-1,-1): curr= max(curr,i-nums[ord(s[j])-ord("a")]) if curr > j: continue dp1[i...
Codeforces Round 396 (Div. 2)
CF
2,017
2
256
Mahmoud and a Message
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alpha...
The first line contains an integer n (1 ≤ n ≤ 103) denoting the length of the message. The second line contains the message s of length n that consists of lowercase English letters. The third line contains 26 integers a1, a2, ..., a26 (1 ≤ ax ≤ 103) — the maximum lengths of substring each letter can appear in.
Print three lines. In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7. In the second line print the length of the longest substring over all the ways. In the third line print the minimum number of substrings over all th...
null
In the first example the three ways to split the message are: - a|a|b - aa|b - a|ab The longest substrings are "aa" and "ab" of length 2. The minimum number of substrings is 2 in "a|ab" or "aa|b". Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
[{"input": "3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "3\n2\n2"}, {"input": "10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "401\n4\n3"}]
1,700
["brute force", "dp", "greedy", "strings"]
37
[{"input": "3\r\naab\r\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n2\r\n2\r\n"}, {"input": "10\r\nabcdeabcde\r\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "401\r\n4\r\n3\r\n"}, {"input": "10\r\naaaaaaaaaa\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n"...
false
stdio
null
true
292/D
292
D
PyPy 3-64
TESTS
9
186
7,168,000
187544976
import sys input = lambda: sys.stdin.readline().rstrip("\n\r") from copy import deepcopy def do(con, start, end, step): for i in range(start, end, step): big = set() big.add(edges[i - 1][0]) big.add(edges[i - 1][1]) for j in range(len(con[i - step])): if big.isdisjoint(c...
102
1,464
90,214,400
209814302
import os,sys,collections,heapq,itertools,functools from functools import reduce , lru_cache from itertools import accumulate,chain,combinations,count from itertools import groupby,permutations,product,zip_longest from heapq import heapify,heappush,heappop,heapreplace,merge,nlargest,nsmallest from collections import C...
Croc Champ 2013 - Round 1
CF
2,013
2
256
Connected Components
We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of n computers and m cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with n nodes and m edges. Let's index the co...
The first line contains two space-separated integers n, m (2 ≤ n ≤ 500; 1 ≤ m ≤ 104) — the number of computers and the number of cables, correspondingly. The following m lines contain the cables' description. The i-th line contains space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n; xi ≠ yi) — the numbers of the ...
Print k numbers, the i-th number represents the number of connected components of the graph that defines the computer network during the i-th experiment.
null
null
[{"input": "6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3", "output": "4\n5\n6\n3\n4\n2"}]
1,900
["data structures", "dfs and similar", "dp", "dsu"]
102
[{"input": "6 5\r\n1 2\r\n5 4\r\n2 3\r\n3 1\r\n3 6\r\n6\r\n1 3\r\n2 5\r\n1 5\r\n5 5\r\n2 4\r\n3 3\r\n", "output": "4\r\n5\r\n6\r\n3\r\n4\r\n2\r\n"}, {"input": "2 1\r\n2 1\r\n2\r\n1 1\r\n1 1\r\n", "output": "2\r\n2\r\n"}, {"input": "3 2\r\n3 2\r\n3 1\r\n4\r\n1 1\r\n1 2\r\n2 2\r\n2 2\r\n", "output": "2\r\n3\r\n2\r\n2\r\n...
false
stdio
null
true
69/C
69
C
Python 3
TESTS
3
186
307,200
76032276
def solve(inv): for artifact, basics in composite.items(): flag = 1 while True: for basic in basics: if basic not in inv: flag -= 1 break elif inv[basic] < basics[basic]: flag -= 1 ...
47
374
2,969,600
95919675
import sys from array import array # noqa: F401 from collections import defaultdict def input(): return sys.stdin.buffer.readline().decode('utf-8') k, n, m, q = map(int, input().split()) basic = [input().rstrip() for _ in range(n)] composite = defaultdict(list) for _ in range(m): name, desc = input().split...
Codeforces Beta Round 63 (Div. 2)
CF
2,011
2
256
Game
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle...
The first line has 4 natural numbers: k (1 ≤ k ≤ 100) — the number of Kostya's allies, n (1 ≤ n ≤ 50) — the number of basic artifacts, m (0 ≤ m ≤ 50) — the number of composite artifacts, q (1 ≤ q ≤ 500) — the number of his friends' purchases. The following n lines contain the names of basic artifacts. After them m line...
The output file should consist of k blocks. The first line should contain number bi — the number of different artifacts the i-th ally has. Then the block should contain bi lines with the names of these artifacts and the number of these artifacts. At that the lines should be printed in accordance with the lexicographica...
null
null
[{"input": "2 3 2 5\ndesolator\nrefresher\nperseverance\nvanguard: desolator 1, refresher 1\nmaelstorm: perseverance 2\n1 desolator\n2 perseverance\n1 refresher\n2 desolator\n2 perseverance", "output": "1\nvanguard 1\n2\ndesolator 1\nmaelstorm 1"}]
2,000
["implementation"]
47
[{"input": "2 3 2 5\r\ndesolator\r\nrefresher\r\nperseverance\r\nvanguard: desolator 1, refresher 1\r\nmaelstorm: perseverance 2\r\n1 desolator\r\n2 perseverance\r\n1 refresher\r\n2 desolator\r\n2 perseverance\r\n", "output": "1\r\nvanguard 1\r\n2\r\ndesolator 1\r\nmaelstorm 1\r\n"}, {"input": "2 3 2 5\r\na\r\nb\r\nc\r...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
4
93
307,200
93830839
n = int(input()) a = list(map(int, input().split())) result = 0 if n<=2: print(0) else: for i in range(1, n-1): if a[i]==min(a[i], a[i-1], a[i+1]) or a[i]==max(a[i], a[i+1], a[i-1]): result+=1 print(result)
14
31
0
187075923
n = int(input()) l = list(map(int,input().split())) e = 0 for i in range(1, len(l)-1): if l[i-1] < l[i] > l[i+1] or l[i-1] > l[i] < l[i+1]: e += 1 print(e)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
5
31
0
189538128
n = int(input()) l = input().split() c = 0 for i in range(1, n - 1): if ((l[i] > l[i - 1]) and (l[i] > l[i + 1])) or ((l[i] < l[i - 1]) and (l[i] < l[i + 1])): c = c + 1 print(c)
14
31
0
189538095
n = int(input()) l = input().split() for i in range(n): l[i] = int(l[i]) c = 0 for i in range(1, n - 1): if ((l[i] > l[i - 1]) and (l[i] > l[i + 1])) or ((l[i] < l[i - 1]) and (l[i] < l[i + 1])): c = c + 1 print(c)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
888/A
888
A
Python 3
TESTS
5
31
0
189024671
n=int(input()) l=list(input().split()) lmin=0 lmax=0 for i in range(1,n-1): if l[i]>l[i+1] and l[i]>l[i-1]: lmax+=1 elif l[i]<l[i+1] and l[i]<l[i-1]: lmin+=1 print(lmin+lmax)
14
31
0
204658646
n = int(input()) l = list(map(int,input().split())) count = 0 for i in range(1,n-1): if l[i] < l[i+1]: if l[i] < l[i-1]: count += 1 elif l[i] > l[i+1]: if l[i] > l[i-1]: count += 1 print(count)
Educational Codeforces Round 32
ICPC
2,017
1
256
Local Extrema
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.
Print the number of local extrema in the given array.
null
null
[{"input": "3\n1 2 3", "output": "0"}, {"input": "4\n1 5 2 5", "output": "2"}]
800
["brute force", "implementation"]
14
[{"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 2 5\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1000\r\n", "output"...
false
stdio
null
true
799/C
799
C
PyPy 3
TESTS
3
62
0
178020373
def maxa(A,c): b = -1 p = 0 for i in range(len(A)): if A[i][1]<=c: if(A[i][0]>b): b = A[i][0] return b def maxad(A,c): f = [-1,0] s = [-1,0] for i in range(len(A)): if(A[i][0]>f[0]): if(A[i][1]+f[1]<=c): t = f ...
79
311
9,420,800
121337144
from sys import stdin input=stdin.readline class BIT(): def __init__(self, n=10**5+5): self.n = n self.tree = [0] * (n + 1) def sum(self, i): ans = 0 i += 1 while i > 0: ans = max(self.tree[i],ans) i -= (i & (-i)) return ans def update(self, i, value): i += 1 while i <= self.n: self.tree[i...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow...
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has. The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, ...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
null
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
[{"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9"}, {"input": "2 4 5\n2 5 C\n2 1 D", "output": "0"}, {"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10"}]
1,800
["binary search", "data structures", "implementation"]
79
[{"input": "3 7 6\r\n10 8 C\r\n4 3 C\r\n5 6 D\r\n", "output": "9\r\n"}, {"input": "2 4 5\r\n2 5 C\r\n2 1 D\r\n", "output": "0\r\n"}, {"input": "3 10 10\r\n5 5 C\r\n5 5 C\r\n10 11 D\r\n", "output": "10\r\n"}, {"input": "6 68 40\r\n1 18 D\r\n6 16 D\r\n11 16 D\r\n7 23 D\r\n16 30 D\r\n2 20 D\r\n", "output": "18\r\n"}, {"in...
false
stdio
null
true
449/B
449
B
Python 3
TESTS
4
1,669
122,060,800
226733625
import math from collections import defaultdict from collections import Counter from collections import deque import heapq def InputStr(): return input() def InputInt(): return int(input()) def InputIterables(): return map(int, input().split()) def InputList(): return list(map(int, input().split())) def InputSortedLis...
45
1,886
133,222,400
202495416
import os import sys import threading from io import BytesIO, IOBase from heapq import heappush, heappop, heapify from collections import defaultdict, deque, Counter from bisect import bisect_left as bl from bisect import bisect_right as br # threading.stack_size(10**8) # sys.setrecursionlimit(10**6) def ri(): return...
Codeforces Round 257 (Div. 1)
CF
2,014
2
256
Jzzhu and Cities
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ...
The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109). Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109). It is guaranteed that there is at least o...
Output a single integer representing the maximum number of the train routes which can be closed.
null
null
[{"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2"}, {"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2"}]
2,000
["graphs", "greedy", "shortest paths"]
45
[{"input": "5 5 3\r\n1 2 1\r\n2 3 2\r\n1 3 3\r\n3 4 4\r\n1 5 5\r\n3 5\r\n4 5\r\n5 5\r\n", "output": "2\r\n"}, {"input": "2 2 3\r\n1 2 2\r\n2 1 3\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "5 4 3\r\n1 2 999999999\r\n2 3 1000000000\r\n3 4 529529529\r\n5 1 524524524\r\n5 524444444\r\n5 529999999\r\n2 1000000...
false
stdio
null
true
549/E
549
E
Python 3
PRETESTS
4
62
307,200
11472208
__author__ = 'Adam' import sys n, m = sys.stdin.readline().split(' ') n, m = int(n), int(m) #data = sys.stdin.read().split('\n') data = [] for i in range(n+m): data.append(sys.stdin.readline().replace('\n', '')) #print(data) data = data[:n+m] misha = [[int(i.split(' ')[0]), int(i.split(' ')[1])] for i in data[:n...
85
109
1,638,400
282575213
# Read the first line of input to get the number of points for Misha (n) and Sasha (m) nm = input() nOm = nm.split() n = int(nOm[0]) m = int(nOm[1]) # Initialize lists to store the coordinates of Misha's and Sasha's trade points a = [] b = [] # Read the coordinates of Misha's trade points for i in range(0, n): a....
Looksery Cup 2015
CF
2,015
2
256
Sasha Circle
Berlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has n points, Sasha — m. Since their subordinates constantly had conflicts with each other, they decided to build a fence in the form of a circle, so that ...
The first line contains two integers n and m (1 ≤ n, m ≤ 10000), numbers of Misha's and Sasha's trade points respectively. The next n lines contains pairs of space-separated integers Mx, My ( - 104 ≤ Mx, My ≤ 104), coordinates of Misha's trade points. The next m lines contains pairs of space-separated integers Sx, Sy...
The only output line should contain either word "YES" without quotes in case it is possible to build a such fence or word "NO" in the other case.
null
In the first sample there is no possibility to separate points, because any circle that contains both points ( - 1, 0), (1, 0) also contains at least one point from the set (0, - 1), (0, 1), and vice-versa: any circle that contains both points (0, - 1), (0, 1) also contains at least one point from the set ( - 1, 0), ...
[{"input": "2 2\n-1 0\n1 0\n0 -1\n0 1", "output": "NO"}, {"input": "4 4\n1 0\n0 1\n-1 0\n0 -1\n1 1\n-1 1\n-1 -1\n1 -1", "output": "YES"}]
2,700
["geometry", "math"]
85
[{"input": "2 2\r\n-1 0\r\n1 0\r\n0 -1\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n1 0\r\n0 1\r\n-1 0\r\n0 -1\r\n1 1\r\n-1 1\r\n-1 -1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n-1 0\r\n1 0\r\n0 -2\r\n0 0\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n-3 -4\r\n3 2\r\n1 5\r\n4 0\r\n5 2\r\n-2 -1\r\...
false
stdio
null
true
449/B
449
B
PyPy 3-64
TESTS
4
1,809
112,640,000
178680016
from collections import defaultdict import heapq from math import inf import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ inp = sys.stdin.readline def input(): return inp().strip() def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(i...
45
1,871
131,072,000
167802107
import sys import math import collections from heapq import heappush, heappop input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n, m, k = ints() graph = [[] for _ in range(n + 1)] for _ in range(m): a, b, c = ints() graph[a].append((b, c, 0)) graph[b].append((a, c, 0)) trains = ...
Codeforces Round 257 (Div. 1)
CF
2,014
2
256
Jzzhu and Cities
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ...
The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109). Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109). It is guaranteed that there is at least o...
Output a single integer representing the maximum number of the train routes which can be closed.
null
null
[{"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2"}, {"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2"}]
2,000
["graphs", "greedy", "shortest paths"]
45
[{"input": "5 5 3\r\n1 2 1\r\n2 3 2\r\n1 3 3\r\n3 4 4\r\n1 5 5\r\n3 5\r\n4 5\r\n5 5\r\n", "output": "2\r\n"}, {"input": "2 2 3\r\n1 2 2\r\n2 1 3\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "5 4 3\r\n1 2 999999999\r\n2 3 1000000000\r\n3 4 529529529\r\n5 1 524524524\r\n5 524444444\r\n5 529999999\r\n2 1000000...
false
stdio
null
true
408/A
408
A
Python 3
TESTS
7
46
0
188596713
kassa_quantity = int(input()) people_quantity = [int(x) for x in input().split()] peoples_with_product = [] i = 0 min_time = 10000 while i < kassa_quantity: peoples_with_product.append([int(x) for x in input().split()]) i += 1 i = 0 while i < kassa_quantity: cur_kass_time = 0 j = 0 while j < people_quantity[i]: ...
20
31
0
159162566
n=int(input()) x=list(map(int,input().split())) t=[] for i in range(n): sum=0 y=list(map(int,input().split())) for j in range(len(y)): sum+=y[j]*5 sum+=x[i]*15 t.append(sum) print(min(t))
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
408/A
408
A
Python 3
TESTS
7
62
102,400
113455544
from collections import Counter def solve(): n=int(input()) queue=[int(i) for i in input().split()] Min,sum=0x3ff,0 for i in range(n): arr=[int(i) for i in input().split()] sum=15*queue[i] for i in arr: sum+=i*5 Min=min(sum,Min) return Min pr...
20
31
0
160712207
I=lambda:[*map(int,input().split())] n=I()[0] k=I() print(min(k[x]*15+sum(I())*5 for x in range(n)))
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true