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
56/B
56
B
Python 3
TESTS
7
186
307,200
92996819
n=int(input()) l=list(map(int,input().split())) l1=l.copy() for i in l: if(i==1): break else: l.remove(i) l.append(i) l1.sort() if(l==l1): print(0,0) else: for i in range(n-1): if(abs(l[i]-l[i+1])>1): a=i+1+1 b=l[i+1] l2=l[:i+1] ...
33
124
0
13335876
r=range i=input i() l=list(map(int,i().split())) #print(l) s=0 p=q=-1 for _ in r(len(l)): if(l[_]!=_+1): p=_+1 q=l[_] break if(p!=-1): #print(p,q) l[p-1:q]=sorted(l[p-1:q]) #print(l) f=1*(p!=-1) for x in r(len(l)): if(l[x]!=x+1):f=0 if(f):print("%d %d"%(p,q)) else:print("0 0")
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Spoilt Permutation
Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u...
If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one.
null
null
[{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}]
1,300
["implementation"]
33
[{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "...
false
stdio
null
true
50/C
50
C
Python 3
TESTS
2
122
307,200
110405413
def O3(): n = int(input()) ans = [] for _ in range(n): x, y = [int(x) for x in input().split()] ans.append([x,y]) minX = min([ans[i][0] for i in range(n)]) minY = min([ans[i][1] for i in range(n)]) maxX = max([ans[i][0] for i in range(n)]) maxY = max([ans[i][1] for i in ran...
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
698/B
698
B
PyPy 3
TESTS
17
639
57,446,400
128894920
from collections import defaultdict,deque n=int(input()) parent=list(map(int,input().split())) graph=defaultdict(list) for i in range(n): graph[i+1].append(parent[i]) graph[parent[i]].append(i+1) vis=[False]*(n+1) a=parent.copy() head=-1 for i in range(n): if parent[i]==i+1: head=i+1 continu...
101
420
19,660,800
19246143
input() A = list(map(int, input().split(' '))) root=-1 for i,a in enumerate(A) : if i == a-1 : root = i break v = [False]*len(A) if root>-1 : v[root]=True changed = 0 for i,a in enumerate(A) : if v[i] : continue v[i]= True l=[i] a-=1 while not v[a] : ...
Codeforces Round 363 (Div. 1)
CF
2,016
2
256
Fix a Tree
A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons...
The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n).
In the first line print the minimum number of elements to change, in order to get a valid sequence. In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted.
null
In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On bo...
[{"input": "4\n2 3 3 4", "output": "1\n2 3 4 4"}, {"input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3"}, {"input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7"}]
1,700
["constructive algorithms", "dfs and similar", "dsu", "graphs", "trees"]
101
[{"input": "4\r\n2 3 3 4\r\n", "output": "1\r\n2 3 4 4 \r\n"}, {"input": "5\r\n3 2 2 5 3\r\n", "output": "0\r\n3 2 2 5 3 \r\n"}, {"input": "8\r\n2 3 5 4 1 6 6 7\r\n", "output": "2\r\n2 3 7 8 1 6 6 7\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n2 2 \r\n"}, {"input": "7\r\n4 3 2 6 3 5 2\r\n", "output": "1\r\n4 3 3 6 ...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) assert len(a) == n # Read submission's output with open(submission_output_path...
true
487/B
487
B
PyPy 3-64
TESTS
3
62
0
230039021
import math import sys from collections import deque # region fastio input = lambda: sys.stdin.readline().rstrip() sint = lambda: int(input()) mint = lambda: map(int, input().split()) ints = lambda: list(map(int, input().split())) # endregion fastio # MOD = 998_244_353 # MOD = 10 ** 9 + 7 # DIR4 = ((-1, 0), (0, 1), (...
35
217
17,817,600
229659935
from collections import deque n, s, l = map(int, input().split()) a = list(map(int, input().split())) dp = [-1] * (n + 1) g, h = 0, -1 dp[0] = 0 que, queMax, queMin = deque(), deque(), deque() for i in range(n): while queMax and a[queMax[0]] - a[i] > s: g = max(g, queMax[0] + 1) queMax.popleft() ...
Codeforces Round 278 (Div. 1)
CF
2,014
1
256
Strip
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: - Each piece should contain at least l numbers. - The difference between the maximal and the minimal number on the piece sho...
The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105). The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).
Output the minimal number of strip pieces. If there are no ways to split the strip, output -1.
null
For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2]. For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.
[{"input": "7 2 2\n1 3 1 2 4 1 2", "output": "3"}, {"input": "7 2 2\n1 100 1 100 1 100 1", "output": "-1"}]
2,000
["binary search", "data structures", "dp", "two pointers"]
35
[{"input": "7 2 2\r\n1 3 1 2 4 1 2\r\n", "output": "3\r\n"}, {"input": "7 2 2\r\n1 100 1 100 1 100 1\r\n", "output": "-1\r\n"}, {"input": "1 0 1\r\n0\r\n", "output": "1\r\n"}, {"input": "6 565 2\r\n31 76 162 -182 -251 214\r\n", "output": "1\r\n"}, {"input": "1 0 1\r\n0\r\n", "output": "1\r\n"}, {"input": "1 0 1\r\n-100...
false
stdio
null
true
56/B
56
B
PyPy 3
TESTS
7
310
0
83609214
n=int(input()) l=list(map(int,input().split())) l1=list(range(1,n+1)) i=0 L=0 R=0 c=0 while i<n: if l[i]!=l1[i]: if c==0: L=i c+=1 else: R=i i+=1 if L!=0 and R!=0: if l[L:R+1]!=l1[L:R+1][::-1]: L=0 R=0 print(0,0) el...
33
124
0
14828936
n, a = int(input()), [0] + list(map(int, input().split())) l, r = 1, n while l <= n and a[l] == l: l += 1 while r >= 1 and a[r] == r: r -= 1 if l < n and a[l:r + 1] == list(range(r, l - 1, -1)): print(l, r) else: print('0 0')
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Spoilt Permutation
Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u...
If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one.
null
null
[{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}]
1,300
["implementation"]
33
[{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "...
false
stdio
null
true
140/D
140
D
PyPy 3-64
TESTS
3
92
0
207746931
def read_int(): return int(input()) def read_array(): return list(map(int, input().split())) n = read_int() a = read_array() a.sort(reverse=True) s = 0 k = 0 while a and s + a[-1] <= 710: s += a.pop() k += 1 print(k, max(0, s - 350))
32
92
0
8107045
__author__ = 'Alex' n = int(input()) a = [int(i) for i in input().split()] a.sort() s = 10 i = 0 while i < n and a[i] + s <= 360: s += a[i] i += 1 ans = 0 while i < n and a[i] + s <= 720: s += a[i] ans += s - 360 i += 1 print(i, ans)
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
14/D
14
D
PyPy 3-64
TESTS
9
124
512,000
159202991
def dfs(v, visited, p): for i in roads[v]: if p != i: visited[i-1] = visited[v-1] + 1 dfs(i, visited, v) n = int(input()) roads = {i+1: [] for i in range(n)} pairs = [] longest_paths = [] for i in range(n-1): a, b = map(int, input().split()) roads[a].append(b) ...
45
186
102,400
139999627
import sys input = sys.stdin.readline from collections import deque p = print r = range def I(): return int(input()) def II(): return list(map(int, input().split())) def S(): return input()[:-1] def M(n): return [list(map(int, input().split())) for ___ in r(n)] def pb(b): print('YES' if b else 'NO') def INF(): return f...
Codeforces Beta Round 14 (Div. 2)
ICPC
2,010
2
64
Two Paths
As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads. The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path ...
The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n).
Output the maximum possible profit.
null
null
[{"input": "4\n1 2\n2 3\n3 4", "output": "1"}, {"input": "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7", "output": "0"}, {"input": "6\n1 2\n2 3\n2 4\n5 4\n6 4", "output": "4"}]
1,900
["dfs and similar", "dp", "graphs", "shortest paths", "trees", "two pointers"]
45
[{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n", "output": "0\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n2 4\r\n5 4\r\n6 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n1 2\r\n", "output": "0\r\n"}, {"inp...
false
stdio
null
true
696/A
696
A
Python 3
TESTS
2
155
3,891,200
48644443
from functools import lru_cache from collections import defaultdict from itertools import tee price = defaultdict(dict) def add(start, end, w): for x, y in get_way(start, end): if x in price: price[x][y] += w else: price[x] = defaultdict(lambda: 0) price[x][y]...
49
155
8,396,800
19134746
from collections import defaultdict def log2(i): c = 0 while i > 0: i >>= 1 c += 1 return c q = int(input()) t = defaultdict(int) def add(u, v, w): lu = int(log2(u)) lv = int(log2(v)) if lv > lu: u, lu, v, lv = v, lv, u, lu for _ in range(lu - lv):...
Codeforces Round 362 (Div. 1)
CF
2,016
1
256
Lorenzo Von Matterhorn
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
The first line of input contains a single integer q (1 ≤ q ≤ 1 000). The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v...
For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events.
null
In the example testcase: Here are the intersections used: 1. Intersections on the path are 3, 1, 2 and 4. 2. Intersections on the path are 4, 2 and 1. 3. Intersections on the path are only 3 and 6. 4. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer e...
[{"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4", "output": "94\n0\n32"}]
1,500
["brute force", "data structures", "implementation", "trees"]
49
[{"input": "7\r\n1 3 4 30\r\n1 4 1 2\r\n1 3 6 8\r\n2 4 3\r\n1 6 1 40\r\n2 3 7\r\n2 2 4\r\n", "output": "94\r\n0\r\n32\r\n"}, {"input": "1\r\n2 666077344481199252 881371880336470888\r\n", "output": "0\r\n"}, {"input": "10\r\n1 1 63669439577744021 396980128\r\n1 2582240553355225 63669439577744021 997926286\r\n1 258224055...
false
stdio
null
true
333/B
333
B
Python 3
TESTS
5
124
0
4193256
n, m = map(int, input().split()) a = set(i for i in range(2, n)) b = set(i for i in range(2, n)) c = set(i for i in range(2, n)) for i in range(m): x, y = map(int, input().split()) a.discard(x) b.discard(y) c.discard(n + 1 - y) print(max(len(a | b), len(a | c)))
20
686
0
6455367
n, m = map(int, input().split()) set_x = {1, n} set_y = {1, n} set_total = {x for x in range(1, n + 1)} for i in range(0, m): x, y = map(int, input().split()) set_x.add(x) set_y.add(y) result = 0 avai_x = set_total - set_x avai_y = set_total - set_y result = len(avai_x) + len(avai_y) if (n & 1) == 1 and (...
Codeforces Round 194 (Div. 1)
CF
2,013
1
256
Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original...
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned ...
Print a single integer — the maximum points Gerald can earn in this game.
null
In the first test the answer equals zero as we can't put chips into the corner cells. In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips. In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
[{"input": "3 1\n2 2", "output": "0"}, {"input": "3 0", "output": "1"}, {"input": "4 3\n3 1\n3 2\n3 3", "output": "1"}]
1,800
["greedy"]
20
[{"input": "3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "3 0\r\n", "output": "1\r\n"}, {"input": "4 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 3\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1\r\n3 2\r\n", "output": "4\r\n"}, {"input": ...
false
stdio
null
true
336/C
336
C
PyPy 3-64
TESTS
7
171
23,449,600
201977376
from math import log n = int(input()) nums = list(map(int, input().split())) maxpos = -1 cands = [] for position in range(int(18*log(10, 2))): # Check if theres a 0 in any thing in the position working_nums = [num for num in nums if num & (1 << position) != 0] if len(working_nums) == 0: continu...
45
140
12,288,000
162183460
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().strip() get_bit = lambda x, i: (x >> i) & 1 n, a = int(input()), array('i', [int(x) for x in input().split()]) for bit in range(29, -1, -1): and_ = (1 << 30) - 1 for i in range(n): if get_bit(a[i], bit): ...
Codeforces Round 195 (Div. 2)
CF
2,013
1
256
Vasily the Bear and Sequence
Vasily the bear has got a sequence of positive integers a1, a2, ..., an. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b1, b2, ..., bk is such maximum non-negative integer v, that number b1 and b2...
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 109).
In the first line print a single integer k (k > 0), showing how many numbers to write out. In the second line print k integers b1, b2, ..., bk — the numbers to write out. You are allowed to print numbers b1, b2, ..., bk in any order, but all of them must be distinct. If there are multiple ways to write out the numbers,...
null
null
[{"input": "5\n1 2 3 4 5", "output": "2\n4 5"}, {"input": "3\n1 2 4", "output": "1\n4"}]
1,800
["brute force", "greedy", "implementation", "number theory"]
45
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "2\r\n4 5\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "1\r\n4\r\n"}, {"input": "3\r\n1 20 22\r\n", "output": "2\r\n20 22\r\n"}, {"input": "10\r\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642\r\n", "output": "6\r\n361633800...
false
stdio
null
true
336/C
336
C
PyPy 3
TESTS
7
405
27,340,800
107368859
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n=nmbr() a=lst() bits=[[0 for _ in range(34)] for _ in range(n)] for i in range(n): for j in range(34): bits[i][33-j]=(a[i]>>j)&1 # ...
45
343
34,304,000
123697311
x=int(input()) s=list(map(int,input().split())) ans=[] for u in range(0,30): cur=(1<<(u)) v=(1<<(u+1))-1 tem=[] for n in s: if n&(cur): tem.append(n) for n in tem: v&=n if v%(1<<(u))==0: ans=tem print(len(ans)) print(*ans)
Codeforces Round 195 (Div. 2)
CF
2,013
1
256
Vasily the Bear and Sequence
Vasily the bear has got a sequence of positive integers a1, a2, ..., an. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b1, b2, ..., bk is such maximum non-negative integer v, that number b1 and b2...
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 109).
In the first line print a single integer k (k > 0), showing how many numbers to write out. In the second line print k integers b1, b2, ..., bk — the numbers to write out. You are allowed to print numbers b1, b2, ..., bk in any order, but all of them must be distinct. If there are multiple ways to write out the numbers,...
null
null
[{"input": "5\n1 2 3 4 5", "output": "2\n4 5"}, {"input": "3\n1 2 4", "output": "1\n4"}]
1,800
["brute force", "greedy", "implementation", "number theory"]
45
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "2\r\n4 5\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "1\r\n4\r\n"}, {"input": "3\r\n1 20 22\r\n", "output": "2\r\n20 22\r\n"}, {"input": "10\r\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642\r\n", "output": "6\r\n361633800...
false
stdio
null
true
149/C
149
C
Python 3
TESTS
2
46
307,200
213778839
import sys sys.setrecursionlimit(2000000) from collections import defaultdict def clc(): n = int(input()) arr = list(map(int,input().split())) turn = 0 summ1,summ2 = 0,0 start,end = 0,n-1 team1,team2= [],[] while start<end: if turn == 0: summ1+=arr[start]+arr[end] ...
47
327
11,776,000
148531234
n=int(input()) a=list(map(int,input().split())) l=[] for i in range(n): l+=[[a[i],i]] l.sort(key=lambda x:x[0]) q=[[],[]] for i in range(n): q[i%2]+=[l[i][1]+1] print(len(q[0])) print(*q[0]) print(len(q[1])) print(*q[1])
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
641/B
641
B
Python 3
PRETESTS
5
343
5,632,000
17489089
n, m, q = map(int, input().split()) a = [[0 for j in range(m)] for i in range(n)] query = [] offset = [[[0, 0] for j in range(m)] for i in range(n)] for i in range(q): s = list(map(int, input().split())) if len(s) == 2: if s[0] == 1: for j in range(m): offset[s[1] - 1][j][0] ...
26
187
716,800
19453083
def main(): n, m, q = map(int, input().split()) nm = ["0"] * (m * n) qq = [input() for _ in range(q)] for s in reversed(qq): k, *l = s.split() if k == "3": nm[(int(l[0]) - 1) * m + int(l[1]) - 1] = l[2] elif k == "2": j = int(l[0]) - 1 x = nm[j...
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Matrix
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There a...
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the...
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
null
null
[{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}]
1,400
["implementation"]
26
[{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu...
false
stdio
null
true
297/A
297
A
Python 3
TESTS
2
186
0
69002019
def maxConsecutive(a): i = 1 curr = 0 if a[0] == '1': curr += 1 ans = curr for i in range(len(a)): if a[i] == '1': curr += 1 else: curr = 1 ans = max(ans, curr) return ans a = input() b = input() if maxConsecutive(a) >= maxConsecutive(b): ...
79
124
1,638,400
181064253
def count(s): cnt = 0 for c in s: if c == '1': cnt += 1 return cnt a = count(input()) b = count(input()) if a % 2 == 1: a += 1 if a >= b: print("YES") else: print("NO")
Codeforces Round 180 (Div. 1)
CF
2,013
1
256
Parity Game
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: - Write parity(a) ...
The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
null
In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
[{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}]
1,700
["constructive algorithms"]
79
[{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}...
false
stdio
null
true
297/A
297
A
Python 3
TESTS
2
216
0
42467491
a = input() b = input() sa = 0 for s in a: if s == '1': sa += 1 sb = 0 for s in b: if s == '1': sb += 1 if sa >= sb: print("YES") else: print("NO")
79
124
4,608,000
29355635
a, b = input(), input() ax = sum([ord(c) - ord('0') for c in a]) bx = sum([ord(c) - ord('0') for c in b]) print("YES" if bx <= ax + ax % 2 else "NO")
Codeforces Round 180 (Div. 1)
CF
2,013
1
256
Parity Game
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: - Write parity(a) ...
The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
null
In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
[{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}]
1,700
["constructive algorithms"]
79
[{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}...
false
stdio
null
true
297/A
297
A
Python 3
TESTS
2
248
0
42543133
#python 3.6 a=str(input()) b=str(input()) tmp="" kalimat="" for i in range(0,len(b)): if(b[i]=="1"): if(kalimat!=""): kalimat+=tmp; tmp="" kalimat+="1" else: tmp+="0" if(a.find(kalimat)!=-1): print("YES") else: print("NO")
79
124
5,632,000
33648427
n = input().count('1') m = input().count('1') print ('YNEOS'[n + (n & 1) < m::2])
Codeforces Round 180 (Div. 1)
CF
2,013
1
256
Parity Game
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: - Write parity(a) ...
The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
null
In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
[{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}]
1,700
["constructive algorithms"]
79
[{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}...
false
stdio
null
true
741/B
741
B
PyPy 3
TESTS
20
935
8,294,400
51004244
R = lambda: map(int, input().split()) n, m, w = R() ws = list(R()) bs = list(R()) anc = [-1] * n def get(x): if anc[x] < 0: return x anc[x] = get(anc[x]) return anc[x] def join(x1, x2): x1, x2 = get(x1), get(x2) if x1 != x2: anc[x1] = x2 for i in range(m): x1, x2 = R() joi...
68
187
17,100,800
183413182
import sys input = sys.stdin.buffer.readline def find_root(root_dict, x): L = [] while x != root_dict[x]: L.append(x) x = root_dict[x] for y in L: root_dict[y] = x return x def process(W, B, G, w): n = len(W) root_dict = [i for i in range(n+1)] for x, y in G: ...
Codeforces Round 383 (Div. 1)
CF
2,016
1
256
Arpa's weak amphitheater and Mehrdad's valuable Hoses
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if...
The first line contains integers n, m and w (1 ≤ n ≤ 1000, $$0 \leq m \leq \min\left(\frac{n(n-1)}{2}, 10^5\right)$$, 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000) — the w...
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
null
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6. In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hose...
[{"input": "3 1 5\n3 2 5\n2 4 2\n1 2", "output": "6"}, {"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3", "output": "7"}]
1,600
["dfs and similar", "dp", "dsu"]
68
[{"input": "3 1 5\r\n3 2 5\r\n2 4 2\r\n1 2\r\n", "output": "6\r\n"}, {"input": "4 2 11\r\n2 4 6 6\r\n6 4 2 1\r\n1 2\r\n2 3\r\n", "output": "7\r\n"}, {"input": "10 5 100\r\n70 67 8 64 28 82 18 61 82 7\r\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\r\n1 7\r\n2 4\r\n3 6\r\n5 7\r\n1 5\r\n", "outpu...
false
stdio
null
true
555/A
555
A
Python 3
PRETESTS
5
77
0
11790356
#!/usr/bin/env python3 # -*- coding: utf-8 -*- (N,K) = map(int,input().split()) ret = 0 for k in range(K): nums = list(map(int,input().split()))[1:] group = len(nums) for j in range(len(nums)-1): if nums[j] + 1 == nums[j+1]: group -= 1 ret += group - 1 # split ret += K + ret - 1 ...
47
312
7,168,000
11803493
def count_continuous(a): total = 0 for i in range(len(a) - 1): if a[i] + 1 == a[i + 1]: total += 1 else: break return total def main(): n, k = [int(t) for t in input().split()] done = 0 for _ in range(k): a = [int(t) for t in input().split()] ...
Codeforces Round 310 (Div. 1)
CF
2,015
2
256
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbers ai1, ai2, ..., aimi — the numbers of mat...
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
null
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
[{"input": "3 2\n2 1 2\n1 3", "output": "1"}, {"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10"}]
1,500
["implementation"]
47
[{"input": "3 2\r\n2 1 2\r\n1 3\r\n", "output": "1\r\n"}, {"input": "7 3\r\n3 1 3 7\r\n2 2 5\r\n2 4 6\r\n", "output": "10\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 1 3\r\n", "output": "3\r\n"}, {"input": "5 3\r\n1 4\r\n3 1 2 3\r\n1 5\r\n", "output": "2\r\n"}, {"input": "8 5\r\n2 ...
false
stdio
null
true
149/C
149
C
PyPy 3-64
TESTS
2
46
0
207900946
from sys import stdin ,stdout input=stdin.readline inp = lambda : map(int,input().split()) def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n =int (input()) ; lis= list(inp()) ; p =[] ; q= [] ; turn = 0 ; c= 0 ; arr=[] for i in range(n) : arr.append((lis[i] , i...
47
343
8,908,800
154260031
n = int(input()) a = list(map(int, input().split())) l = [(a[i], i+1) for i in range(n)] l.sort(reverse = True) # print(l) x = 1 y = 1 xx = [l[0][1]] sx = l[0][0] yy = [l[1][1]] sy = l[1][0] for i in range(2, n): if i%2==0: sx+=l[i][0] xx.append(l[i][1]) x+=1 else: sy+=l[i][0] ...
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
297/A
297
A
Python 3
TESTS
2
186
307,200
42459334
def zeroEraser(a): if a.count('0') == len(a): return "" x = a[::-1] for i in range(len(x)): if x[i] != '0': y = len(x)-i break return a[:y] def possible(a,b): x = zeroEraser(a) y = zeroEraser(b) if len(x) < len(y): return "NO" elif y == x[...
79
186
0
142741181
a=input() b=input() a1=a.count('1') a1+=a1&1 if(a1>=b.count('1')): print("YES") else: print("NO")
Codeforces Round 180 (Div. 1)
CF
2,013
1
256
Parity Game
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: - Write parity(a) ...
The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
null
In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
[{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}]
1,700
["constructive algorithms"]
79
[{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}...
false
stdio
null
true
70/B
70
B
PyPy 3-64
TESTS
4
77
2,867,200
200489304
import re def func(): n=int(input()) s=input()+'#' msgs,found,t=[],False,'' for e in s: if found and e == ' ': found = False continue if e == '.' or e =='!' or e == '?' or e == '#': if e != '#': t += e if t: msgs.append(t) found...
48
233
2,150,400
101376573
import re n=int(input()) ans,sumL=1,0 for s in re.split("[.?!]", input()): s=s.strip()+'.' L=len(s) if L>1: if L>n: print("Impossible") exit() if sumL+L+(sumL>0) > n: ans+=1 sumL=L else: sumL=sumL+L+(sumL>0) print(ans)
Codeforces Beta Round 64
CF
2,011
1
256
Text Messaging
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like ...
The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty.
On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes.
null
Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
[{"input": "25\nHello. I am a little walrus.", "output": "2"}, {"input": "2\nHow are you?", "output": "Impossible"}, {"input": "19\nHello! Do you like fish? Why?", "output": "3"}]
1,600
["expression parsing", "greedy", "strings"]
48
[{"input": "25\r\nHello. I am a little walrus.\r\n", "output": "2\r\n"}, {"input": "2\r\nHow are you?\r\n", "output": "Impossible\r\n"}, {"input": "19\r\nHello! Do you like fish? Why?\r\n", "output": "3\r\n"}, {"input": "4\r\na. A.\r\n", "output": "2\r\n"}, {"input": "146\r\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cI...
false
stdio
null
true
333/B
333
B
Python 3
TESTS
5
122
0
6010622
instr = input() tmplist = instr.split() n = (int)(tmplist[0]) chizu = [ [0 for i in range(n)] for j in range(n)] m = (int)(tmplist[1]) for i in range(m): instr = input() tmplist = instr.split() x = (int)(tmplist[0]) y = (int)(tmplist[1]) chizu[x-1][y-1] = 1 count = 0 #for i in range(n): # for j...
20
716
0
5419181
n, m = map(int, input().split()) k = n + 1 a, b = [0] * k, [0] * k a[0] = a[1] = a[n] = b[0] = b[1] = b[n] = 1 for i in range(m): x, y = map(int, input().split()) a[x] = b[y] = 1 s = a.count(0) + b.count(0) if n & 1 and 0 == a[k // 2] == b[k // 2]: s -= 1 print(s)
Codeforces Round 194 (Div. 1)
CF
2,013
1
256
Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original...
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned ...
Print a single integer — the maximum points Gerald can earn in this game.
null
In the first test the answer equals zero as we can't put chips into the corner cells. In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips. In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
[{"input": "3 1\n2 2", "output": "0"}, {"input": "3 0", "output": "1"}, {"input": "4 3\n3 1\n3 2\n3 3", "output": "1"}]
1,800
["greedy"]
20
[{"input": "3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "3 0\r\n", "output": "1\r\n"}, {"input": "4 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 3\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1\r\n3 2\r\n", "output": "4\r\n"}, {"input": ...
false
stdio
null
true
780/B
780
B
PyPy 3
TESTS
35
218
11,980,800
113183046
###### ### ####### ####### ## # ##### ### ##### # # # # # # # # # # # # # ### # # # # # # # # # # # # # ### ###### ######### # # # # # # ...
46
109
16,179,200
228323942
n=int(input()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) l=0 r=1e9 for _ in range(80): m=(l+r)/2 a,b=float("-inf"),float("inf") for i,j in zip(l1,l2): a=max(a,i-j*m) b=min(b,i+j*m) if a<=b: r=m else: l=m l=round(l,6) print(l)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
5
256
The Meeting Place Cannot Be Changed
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi ...
The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters pe...
Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if $$\frac{|a-b|}{\ma...
null
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
[{"input": "3\n7 1 3\n1 2 1", "output": "2.000000000000"}, {"input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000"}]
1,600
["binary search"]
46
[{"input": "3\r\n7 1 3\r\n1 2 1\r\n", "output": "2.000000000000\r\n"}, {"input": "4\r\n5 10 3 2\r\n2 3 2 4\r\n", "output": "1.400000000000\r\n"}, {"input": "3\r\n1 1000000000 2\r\n1 2 1000000000\r\n", "output": "333333332.999999999971\r\n"}, {"input": "2\r\n4 5\r\n10 8\r\n", "output": "0.055555555556\r\n"}, {"input": "...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read correct output with open(output_path) as f: correct_line = f.read().strip() try: b = float(correct_line) except: print(0) return # Read submis...
true
70/B
70
B
Python 3
TESTS
10
46
0
204135130
n = int(input()) a = input() flag = last_true = count = i = lim = 0 while (i < len(a)): if (a[i] == '.' or a[i] == '?' or a[i] == '!'): last_true = i lim += 1 i += 1 if (lim == n): if (last_true != 0): i = last_true + 1; lim = 0; last_true = 0; count += 1 else: print('Impossible'); flag = 1; break if (no...
48
46
0
230067445
n = int(input()) ; s = input() ; count = 0 ; ans = 0 i = 0 ; L = [] while i < len(s): if s[i] not in ['.','?','!'] : count += 1 ; i += 1 elif s[i] in ['.','?','!'] : L.append(count + 1) ; ans += 1 ; count = 0 ; i += 2 #print(L,n) i = 1 ; a = len(L) #print(a) flag = False if L[0] > n : flag = True ; pr...
Codeforces Beta Round 64
CF
2,011
1
256
Text Messaging
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like ...
The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty.
On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes.
null
Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
[{"input": "25\nHello. I am a little walrus.", "output": "2"}, {"input": "2\nHow are you?", "output": "Impossible"}, {"input": "19\nHello! Do you like fish? Why?", "output": "3"}]
1,600
["expression parsing", "greedy", "strings"]
48
[{"input": "25\r\nHello. I am a little walrus.\r\n", "output": "2\r\n"}, {"input": "2\r\nHow are you?\r\n", "output": "Impossible\r\n"}, {"input": "19\r\nHello! Do you like fish? Why?\r\n", "output": "3\r\n"}, {"input": "4\r\na. A.\r\n", "output": "2\r\n"}, {"input": "146\r\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cI...
false
stdio
null
true
333/B
333
B
Python 3
TESTS
5
122
0
6455213
n, m = map(int,input().split()) set_x = {1, n} set_y = {1, n} set_total = {x for x in range(1, n+1)} for i in range(0, m): x,y = map(int,input().split()) set_x.add(x) set_y.add(y) ava_x = set_total - set_x ava_y = set_total - set_y print(max(len(ava_x) + len(ava_y - ava_x), len(ava_y) + len(ava_x-ava_y) ))
20
748
0
4189307
n, m = map(int, input().split()) used = [1] * 2 * n for i in range(m): x, y = map(int, input().split()) used[x - 1] = used[n + y - 1] = 0 if n % 2 and used[n // 2]: used[n // 2 + n] = 0 res = sum(used) for i in [0, n - 1, n, 2 * n - 1]: res -= used[i] print(res)
Codeforces Round 194 (Div. 1)
CF
2,013
1
256
Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original...
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned ...
Print a single integer — the maximum points Gerald can earn in this game.
null
In the first test the answer equals zero as we can't put chips into the corner cells. In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips. In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
[{"input": "3 1\n2 2", "output": "0"}, {"input": "3 0", "output": "1"}, {"input": "4 3\n3 1\n3 2\n3 3", "output": "1"}]
1,800
["greedy"]
20
[{"input": "3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "3 0\r\n", "output": "1\r\n"}, {"input": "4 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 3\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1\r\n3 2\r\n", "output": "4\r\n"}, {"input": ...
false
stdio
null
true
340/B
340
B
Python 3
TESTS
22
124
0
4408105
# calculate convex of polygon v. # v is list of complexes stand for points. def convex(v, eps=1e-8): # fetch the seed point v.sort(key=lambda x:(x.real,x.imag)) v = v[0:1] + sorted(v[1:], key=lambda x:(x-v[0]).imag/abs(x-v[0])) n = 1 for i in range(2, len(v)): while n > 1 and ((v[n]-v[n-1]...
23
652
1,126,400
40484837
import sys s, n = 0, int(input()) t = list(map(int, sys.stdin.read().split())) p = [(t[2 * i], t[2 * i + 1]) for i in range(n)] for x, i in enumerate(p, 1): for j in p[x:]: a = b = 0 for k in p: d = (i[0] - k[0]) * (j[1] - k[1]) - (i[1] - k[1]) * (j[0] - k[0]) a, b = min(d, a...
Codeforces Round 198 (Div. 2)
CF
2,013
1
256
Maximal Area Quadrilateral
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one...
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
null
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.
[{"input": "5\n0 0\n0 4\n4 0\n4 4\n2 3", "output": "16.000000"}]
2,100
["brute force", "geometry"]
23
[{"input": "5\r\n0 0\r\n0 4\r\n4 0\r\n4 4\r\n2 3\r\n", "output": "16.000000"}, {"input": "10\r\n-6 -4\r\n-7 5\r\n-7 -7\r\n5 -7\r\n4 -9\r\n-6 7\r\n2 9\r\n-4 -6\r\n2 10\r\n-10 -4\r\n", "output": "166.000000"}, {"input": "4\r\n-3 3\r\n0 3\r\n-2 -1\r\n2 2\r\n", "output": "11.000000"}, {"input": "5\r\n-4 -3\r\n-3 -2\r\n3 3\...
false
stdio
import sys input_path, output_path, submission_output_path = sys.argv[1:4] def read_float(path): with open(path) as f: content = f.read().strip() parts = content.split() if len(parts) != 1: return None try: return float(parts[0]) except: ...
true
501/C
501
C
PyPy 3-64
TESTS
2
62
28,979,200
135059892
from collections import deque n = int(input()) L = [] S = [] for i in range(n): u,v = map(int,input().split()) L.append([u,v]) q = deque() d = dict() for i in range(n): d[i] = [] for i in range(n): if L[i][0] == 1: ad = L[i][1] L[ad][0] -= 1 L[ad][1] ^= i d[i].append(...
49
265
23,859,200
177732410
import sys input = sys.stdin.readline n = int(input()) d = {} f = [] x = [0]*n for i in range(n): a, b = map(int, input().split()) if a == 0: continue d[i] = [a, b, i] q = sorted([(d[i][1], d[i][2]) for i in d if d[i][0] == 1]) while q: a, b = q.pop() if x[a] == 0 and x[b] == 0: x[...
Codeforces Round 285 (Div. 2)
CF
2,015
1
256
Misha and Forest
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the secon...
The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph. The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.
In the first line print number m, the number of edges of the graph. Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b). Edges can be printed in any order; vertices of the edge can also be printed in any order.
null
The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
[{"input": "3\n2 3\n1 0\n1 0", "output": "2\n1 0\n2 0"}, {"input": "2\n1 1\n1 0", "output": "1\n0 1"}]
1,500
["constructive algorithms", "data structures", "greedy", "sortings", "trees"]
49
[{"input": "3\r\n2 3\r\n1 0\r\n1 0\r\n", "output": "2\r\n1 0\r\n2 0\r\n"}, {"input": "2\r\n1 1\r\n1 0\r\n", "output": "1\r\n0 1\r\n"}, {"input": "10\r\n3 13\r\n2 6\r\n1 5\r\n3 5\r\n1 3\r\n2 2\r\n2 6\r\n1 6\r\n1 3\r\n2 3\r\n", "output": "9\r\n2 5\r\n4 3\r\n7 6\r\n8 3\r\n5 0\r\n6 1\r\n3 9\r\n1 0\r\n9 0\r\n"}, {"input": "...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] # not used submission_path = sys.argv[3] # Read input with open(input_path) as f: lines = [line.strip() for line in f if line.strip()] n = int(lines[0]) degrees = [] s_list = [] for l...
true
501/B
501
B
Python 3
TESTS
44
233
1,228,800
45901799
import copy n = input() E = list() class Node: def __init__(self, nodo): self.padre = None self.nodo = nodo self.hijo = None def __repr__(self): return self.nodo #return "nodo: {0} | padre: {1} | hijo: {2}".format(self.nodo,self.padre.nodo if self.padre else None, s...
49
46
0
140723840
parent = dict() def find(name): while parent[name] != name: parent[name] = parent[parent[name]] name = parent[name] return parent[name] queries = [] for _ in range(int(input())): old, new = input().split() queries.append((old, new)) parent[new] = new parent[old] = new newest = ...
Codeforces Round 285 (Div. 2)
CF
2,015
1
256
Misha and Changing Handles
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests. Next q lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings ...
In the first line output the integer n — the number of users that changed their handles at least once. In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after...
null
null
[{"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"}]
1,100
["data structures", "dsu", "strings"]
49
[{"input": "5\r\nMisha ILoveCodeforces\r\nVasya Petrov\r\nPetrov VasyaPetrov123\r\nILoveCodeforces MikeMirzayanov\r\nPetya Ivanov\r\n", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"}, {"input": "1\r\nMisha Vasya\r\n", "output": "1\nMisha Vasya\n"}, {"input": "10\r\na b\r\nb c\r\nc d\r\nd e\r...
false
stdio
import sys def process_input(input_path): current_to_original = {} with open(input_path, 'r') as f: lines = f.readlines() q = int(lines[0].strip()) for line in lines[1:q+1]: old, new = line.strip().split() original = current_to_original.get(old, old) ...
true
333/B
333
B
PyPy 3
TESTS
5
248
23,142,400
25203621
n, m = map(int, input().split()) ans = 0 row = [True] * n col = [True] * n for x in range(m): a, b = map(int, input().split()) row[a - 1] = False col[b - 1] = False for i in range(1, n - 1): if row[i] or col[i]: ans += 1 print (ans)
20
624
102,400
45983185
I = input n,m = map(int , I().split()) b = [1] * n * 2 b[0] = b[n - 1] = b[n] = b[2 * n - 1] = 0 for i in range(m): r , c = map(int , I().split()) b[r - 1] = b[n + c - 1] = 0 if n % 2 and b[n // 2] and b[n + n // 2] : b[n // 2] = 0 print(sum(b))
Codeforces Round 194 (Div. 1)
CF
2,013
1
256
Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original...
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned ...
Print a single integer — the maximum points Gerald can earn in this game.
null
In the first test the answer equals zero as we can't put chips into the corner cells. In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips. In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
[{"input": "3 1\n2 2", "output": "0"}, {"input": "3 0", "output": "1"}, {"input": "4 3\n3 1\n3 2\n3 3", "output": "1"}]
1,800
["greedy"]
20
[{"input": "3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "3 0\r\n", "output": "1\r\n"}, {"input": "4 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 3\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1\r\n3 2\r\n", "output": "4\r\n"}, {"input": ...
false
stdio
null
true
472/D
472
D
Python 3
TESTS
3
30
0
193653682
n = int(input()) dist = [list(map(int, input().split())) for _ in range(n)] # Check if diagonal elements are zero and distance matrix is symmetric for i in range(n): if dist[i][i] != 0: print("NO") exit() for j in range(i + 1, n): if dist[i][j] != dist[j][i]: print("NO") ...
47
545
57,036,800
177433089
from math import inf from collections import * import math, os, sys, heapq, bisect, random,threading from functools import lru_cache from itertools import * import sys def inp(): return sys.stdin.readline().rstrip("\r\n") def out(var): sys.stdout.write(str(var)) # for fast output, always take string def inpu(): return...
Codeforces Round 270
CF
2,014
2
256
Design Tutorial: Inverse the Problem
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.
If there exists such a tree, output "YES", otherwise output "NO".
null
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7. In the second example, it is impossible because d1, 1 should be 0, but it is 1. In the third example, it is impossible because d1, 2 should equal d2, 1.
[{"input": "3\n0 2 7\n2 0 9\n7 9 0", "output": "YES"}, {"input": "3\n1 2 7\n2 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 2 2\n7 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "NO"}, {"input": "2\n0 0\n0 0", "output": "NO"}]
1,900
["dfs and similar", "dsu", "shortest paths", "trees"]
47
[{"input": "3\r\n0 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 2 2\r\n7 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r\n1 0 1\r\n1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "NO\r\n...
false
stdio
null
true
260/C
260
C
PyPy 3
TESTS
3
77
0
150457038
n,k = map(int, input().split()) arr = list(map(int, input().split())) mn, mi = 1e9, -1 for i in range(n): if arr[i] < mn: mn = arr[i] mi = i k -= 1 ov = arr[mi]*n side = k-mi if k>=mi else n-mi+k ok = k i=(mi+1)%n while i != ok: arr[i] -= 1 i = (i+1)%n arr[i] -= 1 for i in range(n): if ...
38
249
33,280,000
123686604
n, x = map(int, input().split()) x = x - 1 l = list(map(int, input().split())) min_index, min_value = -1, 10 ** 9 + 7 nb_seen = 0 cur = x while nb_seen != n: if min_value > l[cur]: min_value = l[cur] min_index = cur cur = (n - 1 + cur) % n nb_seen += 1 min_value = l[min_index] for i in ran...
Codeforces Round 158 (Div. 2)
CF
2,012
1
256
Balls and Boxes
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ...
Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.
null
null
[{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}]
1,700
["constructive algorithms", "greedy", "implementation"]
38
[{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000...
false
stdio
null
true
690/B1
690
B1
Python 3
TESTS
0
61
7,065,600
37354590
n = int(input()) grid = [] flag = True ans = -1 while(n): n-=1 x = str(int(input())) if(x!='0'): grid.append(x) for i in grid: if(ans==-1 or len(i)==ans): ans = len(i) else: flag = False for i in range(0, len(grid)): if(len(...
21
46
307,200
19011156
import sys, math def bfs(x, y): Q=[[x,y]] ptr = 0 min_=[1000,1000] max_=[0,0] while ptr < len(Q): v = Q[ptr] ptr+=1 x = v[0]; y=v[1] if matrix[x][y] == 4: used[x][y] = 1 if x+1 < n: if used[x+1][y]==0: ...
Helvetic Coding Contest 2016 online mirror (teams, unrated)
ICPC
2,016
2
256
Recover Polygon (easy)
The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good. Heidi knows that the lair can be represented as a rectangle on a lattice, with si...
The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 50). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. Cells are given in the same order as they a...
The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise.
null
The lair, if it exists, has to be rectangular (that is, have corners at some grid points with coordinates (x1, y1), (x1, y2), (x2, y1), (x2, y2)), has a non-zero area and be contained inside of the grid (that is, 0 ≤ x1 < x2 ≤ N, 0 ≤ y1 < y2 ≤ N), and result in the levels of Zombie Contamination as reported in the inpu...
[{"input": "6\n000000\n000000\n012100\n024200\n012100\n000000", "output": "Yes"}]
1,700
[]
21
[{"input": "6\r\n000000\r\n000000\r\n012100\r\n024200\r\n012100\r\n000000\r\n", "output": "Yes\r\n"}, {"input": "6\r\n000000\r\n012210\r\n024420\r\n012210\r\n000000\r\n000000\r\n", "output": "Yes\r\n"}, {"input": "6\r\n000100\r\n001210\r\n002420\r\n001210\r\n000000\r\n000000\r\n", "output": "No\r\n"}, {"input": "10\r\n...
false
stdio
null
true
260/C
260
C
PyPy 3
TESTS
3
77
409,600
166459619
import collections import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os ###################################################################################### #--------------------------------------Input-----------------------------------------# ###################...
38
265
11,980,800
150461302
n,k = map(int, input().split()) arr = list(map(int, input().split())) m = min(arr) k -= 1 ov = m*n for i in range(n): arr[i] -= m while arr[k] > 0: ov += 1 arr[k] -= 1 k = (k-1)%n arr[k] = ov print(*arr)
Codeforces Round 158 (Div. 2)
CF
2,012
1
256
Balls and Boxes
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ...
Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.
null
null
[{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}]
1,700
["constructive algorithms", "greedy", "implementation"]
38
[{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000...
false
stdio
null
true
260/C
260
C
Python 3
TESTS
3
77
0
38984724
n=[int(num) for num in input().split()] x=[int(num) for num in input().split()] i=x.index(min(x)) p=x[i] j=(n[1]-i-1)%n[0] x[i]=p*n[0]+j t=i i=i+1 while True: if j!=0: j=j-1 x[i%n[0]]=x[i%n[0]]-1-p else: x[i%n[0]]=x[i%n[0]]-p if (i+1)%n[0]==t: break else: i=(i+1) ...
38
295
15,257,600
86469034
def solve(n, x, seq): x -= 1 _min = min(seq) s = sum(seq) idx = -1 for i in range(x, -1, -1): if seq[i] == _min: idx = i break else: for j in range(n - 1, x, -1): if seq[j] == _min: idx = j break for i in ra...
Codeforces Round 158 (Div. 2)
CF
2,012
1
256
Balls and Boxes
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ...
Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.
null
null
[{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}]
1,700
["constructive algorithms", "greedy", "implementation"]
38
[{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000...
false
stdio
null
true
260/C
260
C
Python 3
TESTS
3
31
0
172833508
n, x = map(int, input().split()) x -= 1 A = [int(t) for t in input().split()] mA = min(A) u = A.index(mA) A = [t-mA for t in A] tt = 0 while A[x] != 0: A[x] -= 1 x = (x-1+n)%n tt += 1 A[u] = mA*n+tt print(' '.join([str(a) for a in A]))
38
296
12,595,200
104650411
n,x = map(int, input().split()) a = list(map(int, input().split())) m = min(a) a = [i-m for i in a] x = x-1 d = m*n while a[x]>0: d+=1 a[x]-=1 x-=1 if x<0: x=n-1 a[x]=d print(*a)
Codeforces Round 158 (Div. 2)
CF
2,012
1
256
Balls and Boxes
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ...
Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.
null
null
[{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}]
1,700
["constructive algorithms", "greedy", "implementation"]
38
[{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000...
false
stdio
null
true
260/C
260
C
PyPy 3-64
TESTS
3
61
0
196267914
#author: Sushmanth from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) def answer(): #has a left zero left = -1 for i in range(x - 2 , -1 , -1): if(a[i] == 0): left = i break if(left != -1): l = left count , ...
38
296
13,824,000
51287399
def main(): n, x = map(int,input().split()) a = [int(i) for i in input().split()] j = x - 1 z = min(a) while a[j] != z: if j == 0: j = n - 1 else: j -= 1 m = a[j] k = 0 if x - 1 > j: for i in range(n): if j < i <= x - 1: ...
Codeforces Round 158 (Div. 2)
CF
2,012
1
256
Balls and Boxes
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ...
Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.
null
null
[{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}]
1,700
["constructive algorithms", "greedy", "implementation"]
38
[{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000...
false
stdio
null
true
799/C
799
C
PyPy 3
TESTS
5
124
1,843,200
106701999
n,c,d = list(map(int,input().split(" "))) coin,dia = [],[] for x in range(n): b,p,cur = input().split(" ") if cur == "C": if int(p) <= c: coin.append([int(b),int(p)]) else: if int(p) <= d: dia.append([int(b),int(p)]) combiC,combiD = [],[] order = [coin,dia] def find(l...
79
233
16,793,600
133344131
import sys def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, 'r') n, g, d = map(int, f.readline().split()) items = list() for _ in range(n): power, money, type_ = f.readline().strip().split() items.append((int(power), ...
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
780/A
780
A
Python 3
TESTS
3
140
14,028,800
167772928
n = int(input()) a = list(map(int,input().split(' '))) s = set() m = 0 for i in range(n): if(a[i] in s): s.remove(a[i]) else: s.add(a[i]) l = len(s) if(m < l): m = l print(m)
56
108
17,100,800
226929690
n = int(input()) k = [int(i) for i in input().split()] p = [0] * n c = 0 mx = 0 for i in range(2*n): if p[k[i]-1] == 0: c += 1 p[k[i] - 1] = 1 else: mx = max(c, mx) c -= 1 mx = max(c, mx) print(mx)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is gua...
Print single integer — the maximum number of socks that were on the table at the same time.
null
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - In...
[{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}]
800
["implementation"]
56
[{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ...
false
stdio
null
true
33/A
33
A
Python 3
TESTS
8
218
0
52875084
n, m, k = map(int,input().split()) a = [2000]*1001 for i in range(n): b=input().split() if a[int(b[0])]>int(b[1]): a[int(b[0])] = int(b[1]) a.sort() sum = 0 i=0 while True: if a[i]==2000: break sum +=a[i] i+=1 if sum>k: print(k) else: print(sum)
31
92
0
158545190
n, m, k = [int(item) for item in input().split(' ')] my_dict = dict() for i in range(n): rows, health = [int(item) for item in input().split(' ')] if(rows in my_dict and my_dict[rows] > health or rows not in my_dict): my_dict[rows] = health answer = sum(my_dict.values()) print(answer if answer < k else...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
33/A
33
A
PyPy 3
TESTS
5
184
20,172,800
122606387
n,m,k=map(int,input().split()) d={} for i in range(n): r,c=map(int,input().split()) if r in d: if c<d[r]: d[r]=c else: d[r]=c sum=0 l=[] for i in d: l.append(d[i]) l.sort(reverse=True) sum=0 for i in l: if sum>=k: break sum+=i print(sum)
31
92
0
165510966
n, m, k = list(map(int, input().split(' '))) teeth = {} for i in range(n): r, c = list(map(int, input().split(' '))) if r in teeth and teeth[r] > c or r not in teeth: teeth[r] = c _sum = sum(teeth.values()) print(_sum if _sum <= k else k)
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
980/C
980
C
Python 3
TESTS
8
78
0
38640562
n,k=map(int,input().split()) a=list(map(int,input().split())) c=[300]*256 for i in a: m=0 for j in range(max(0,i-k+1),i+1): if j<=c[j] and m==0 :r=j;m=1 if m==1 and c[j]!=300: c[j]=max(r,c[j]) elif m==1 and c[j]==300: c[j]=r for i in a: print(c[i],end=' ')
82
171
12,390,400
38042137
#!/usr/bin/env python3 [n, k] = map(int, input().strip().split()) pis = list(map(int, input().strip().split())) import sys if k == 1: print (' '.join(map(str, pis))) sys.exit(0) N = 256 gamma = [-1 for _ in range(N)] done = [False for _ in range(N)] revdone = [False for _ in range(N)] notset = 256 pends = {} def...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
980/C
980
C
Python 3
PRETESTS
8
77
7,065,600
38038577
n,k = map(int,input().split()) l = [int(x) for x in input().split()] maps = [] for _ in range(256): maps.append(['empty',0]) output = [] for innum in l: if maps[innum][0] == 'chosen': outnum = maps[innum][1] elif maps[innum][0] == 'potential': outnum = maps[innum][1] i = innum while i >= 0 and maps[i][0] == ...
82
171
13,004,800
38044069
def main(): n, k = map(int, input().split()) p = list(map(int, input().split())) solve(n, k, p) def solve(n, k, p): group = 256 * [None] r = p[:] for i, pi in enumerate(p): # print([(i, gi) for i, gi in enumerate(group)if gi is not None]) if group[pi] is not None: r[i...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
780/B
780
B
Python 3
TESTS
35
4,009
11,878,400
35895167
n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) left = 0 right = 10 ** 9 while right - left > 0.000001: mid = (left + right) / 2 a = min(x) b = max(x) for i in range(n): a = max(a, x[i] - v[i] * mid) b = min(b, x[i] + v[i] * mid) if a > b: ...
46
139
16,179,200
216003079
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) def find(num): ma,mi = X...
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
5
256
The Meeting Place Cannot Be Changed
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi ...
The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters pe...
Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if $$\frac{|a-b|}{\ma...
null
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
[{"input": "3\n7 1 3\n1 2 1", "output": "2.000000000000"}, {"input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000"}]
1,600
["binary search"]
46
[{"input": "3\r\n7 1 3\r\n1 2 1\r\n", "output": "2.000000000000\r\n"}, {"input": "4\r\n5 10 3 2\r\n2 3 2 4\r\n", "output": "1.400000000000\r\n"}, {"input": "3\r\n1 1000000000 2\r\n1 2 1000000000\r\n", "output": "333333332.999999999971\r\n"}, {"input": "2\r\n4 5\r\n10 8\r\n", "output": "0.055555555556\r\n"}, {"input": "...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read correct output with open(output_path) as f: correct_line = f.read().strip() try: b = float(correct_line) except: print(0) return # Read submis...
true
780/A
780
A
Python 3
TESTS
3
171
17,817,600
26168195
n = int(input()) sock = [int(x) for x in input().split()] table = [False for i in range(n+1)] t = 0; maxt = 1 for i in range(n): if table[sock[i]]: table[sock[i]] = False; t -= 1 else: table[sock[i]] = True; t += 1 if t>maxt: maxt = t print(maxt)
56
109
19,660,800
223373025
n=int(input()) b=list(map(int,input().split())) c=0 z=0 v=[0]*100001 for i in b: v[i]+=1 if v[i]!=2: c+=1 z=max(z,c) elif v[i]==2: c-=1 print(z)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is gua...
Print single integer — the maximum number of socks that were on the table at the same time.
null
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - In...
[{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}]
800
["implementation"]
56
[{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ...
false
stdio
null
true
980/C
980
C
Python 3
TESTS
8
77
7,065,600
38118893
n,k = list(map(int,input().split())) arr = list(map(int,input().split())) val = [-1]*256 val[0] = 0 for i in range(0,n): if(val[arr[i]] > -1): print(val[arr[i]],end = " ") else: flag = 0 for j in range(1,k): if( val[arr[i]-j] > -1 ): if(arr[i] - val[arr[i]-j] < k): for p in range(arr[i] - j + 1,a...
82
186
12,390,400
38072825
n, k = map(int, input().split()) a = list(map(int, input().split())) c = [-1]*256 ans = [0]*n for i in range(n): if c[a[i]] == -1: for j in range(a[i], max(-1, a[i]-k), -1): if c[j] != -1: if (c[j] +k) > a[i]: c[a[i]] = c[j] else: ...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
780/A
780
A
Python 3
TESTS
3
170
10,547,200
83105322
n=int(input()) l=input().split() l1,c=set(),0 for i in range(n): if l[i] not in l1: l1.add(l[i]) else: l1.discard(l[i]) c=max(c,len(l1)) print(c)
56
109
26,009,600
163726124
n = int(input()) a = [int(el) for el in input().split()] s = set() res = 0 for el in a: if el not in s: s.add(el) else: s.discard(el) res = max(res, len(s)) print(res)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is gua...
Print single integer — the maximum number of socks that were on the table at the same time.
null
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - In...
[{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}]
800
["implementation"]
56
[{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ...
false
stdio
null
true
686/B
686
B
PyPy 3-64
TESTS
2
93
0
139123135
n=int(input()) a=[int(i) for i in input().split()] b=sorted(a) if b==a: print() else: for i in range(n): for j in range(i+1,n): if a[i]>a[j]: a[i],a[j]=a[j],a[i] print(i+1,j+1)
37
62
0
181334381
from sys import stdin,stdout input=stdin.readline def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n=int(input()) ; arr=list(map(int,input().split())) for i in range(n-1,0,-1): for j in range(i): if arr[j]>arr[j+1]: arr[j],arr[j+1]=arr[j+1],arr[j] ...
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the o...
null
Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
[{"input": "4\n2 1 4 3", "output": "1 4"}, {"input": "7\n36 28 57 39 66 69 68", "output": "1 4\n6 7"}, {"input": "5\n1 2 1 2 1", "output": "2 5\n3 4\n1 4\n1 4"}]
1,100
["constructive algorithms", "implementation", "sortings"]
37
[{"input": "4\r\n2 1 4 3\r\n", "output": "1 2\r\n3 4\r\n"}, {"input": "7\r\n36 28 57 39 66 69 68\r\n", "output": "1 2\r\n3 4\r\n6 7\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "2 3\r\n4 5\r\n3 4\r\n"}, {"input": "78\r\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 4...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path, 'r') as f: lines = f...
true
686/B
686
B
PyPy 3
TESTS
2
77
20,172,800
128030949
import math def main_function(): n = int(input()) a = [int(i) for i in input().split(" ")] counter = 0 for t in range(len(a)): i = len(a) - t - 1 currnet_max = a[i] index = i for j in range(0, i + 1): if a[j] > currnet_max: currnet_max = a[j]...
37
62
102,400
18674341
n = int(input()) data = [int(i) for i in input().split()] ret = '' while 1: p = 0 for i in range(n - 1): if data[i] > data[i + 1]: data[i], data[i + 1] = data[i + 1], data[i] p += 1 ret += str(i + 1) + ' ' + str(i + 2) + '\n' if not p: break print(ret)
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the o...
null
Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
[{"input": "4\n2 1 4 3", "output": "1 4"}, {"input": "7\n36 28 57 39 66 69 68", "output": "1 4\n6 7"}, {"input": "5\n1 2 1 2 1", "output": "2 5\n3 4\n1 4\n1 4"}]
1,100
["constructive algorithms", "implementation", "sortings"]
37
[{"input": "4\r\n2 1 4 3\r\n", "output": "1 2\r\n3 4\r\n"}, {"input": "7\r\n36 28 57 39 66 69 68\r\n", "output": "1 2\r\n3 4\r\n6 7\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "2 3\r\n4 5\r\n3 4\r\n"}, {"input": "78\r\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 4...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path, 'r') as f: lines = f...
true
504/D
504
D
PyPy 3
TESTS
5
764
10,137,600
108515065
m = int(input()) values = [] idx = [] for i in range(m): x = int(input()) ans = 0 for j,xx in enumerate(values): if (xx^x) < x: x^=xx ans^=idx[j] if x == 0: anss = [] for j,xx in enumerate(values): if (ans&1)!=0: anss.append(j) ...
52
623
64,512,000
70796734
import sys, os numbs = [int(x) for x in sys.stdin.buffer.read().split()] n = numbs.pop(0) base = [] out = [] for i in range(n): x = numbs[i] how = 0 for b,rep in base: if x.bit_length() == b.bit_length(): x ^= b how ^= rep if x: how |= 1 << i ...
Codeforces Round 285 (Div. 1)
CF
2,015
2
256
Misha and XOR
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
The first line contains number m (1 ≤ m ≤ 2000), showing how many numbers are scattered around the room. The next m lines contain the numbers in the order in which the robot puts them in the basket. Each number is a positive integer strictly less than 10600 that doesn't contain leading zeroes.
For each number either print a 0 on the corresponding line, if the number cannot be represented as a XOR sum of numbers that are in the basket, or print integer k showing how many numbers are in the representation and the indexes of these numbers. Separate the numbers by spaces. Each number can occur in the representat...
null
The XOR sum of numbers is the result of bitwise sum of numbers modulo 2.
[{"input": "7\n7\n6\n5\n4\n3\n2\n1", "output": "0\n0\n0\n3 0 1 2\n2 1 2\n2 0 2\n2 0 1"}, {"input": "2\n5\n5", "output": "0\n1 0"}]
2,700
["bitmasks"]
52
[{"input": "7\r\n7\r\n6\r\n5\r\n4\r\n3\r\n2\r\n1\r\n", "output": "0\r\n0\r\n0\r\n3 0 1 2\r\n2 1 2\r\n2 0 2\r\n2 0 1\r\n"}, {"input": "2\r\n5\r\n5\r\n", "output": "0\r\n1 0\r\n"}, {"input": "10\r\n81\r\n97\r\n12\r\n2\r\n16\r\n96\r\n80\r\n99\r\n6\r\n83\r\n", "output": "0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n3 0 1 5\r\n2 1 3\r\n0\...
false
stdio
null
true
33/A
33
A
Python 3
TESTS
7
186
6,963,200
85186639
n,m,k=input().split() n=int(n) m=int(m) k=int(k) l=[] h=[] s=0 for i in range(n): l.insert(i,input()) l.sort() d=l[0].split() d=int(d[1]) p=1 for i in l: a,b=i.split() a=int(a) b=int(b) if(a!=p): p+=1 s=s+d d=b if(a==p): if(d>b): d=b if(p==m and i==l[n-1]): s=...
31
92
0
170452271
n,m,k = map(int,input().split(' ')) bz = [1000000]*(m+1) while n: r,c = map(int,input().split(' ')) bz[r] = min(bz[r],c) n-=1 sum = 0 for i in bz[1:]: sum += i print(min(sum,k))
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
803/E
803
E
PyPy 3
TESTS
20
140
10,752,000
138349448
n, k = map(int, input().split()) s = str(input()) dp = [[False]*(2*k+1) for i in range(n+1)] dp[0][k] = True for i, c in enumerate(s): for j in range(1, 2*k): if not dp[i][j]: continue if c == 'W' and j+1 <= 2*k: dp[i+1][j+1] = True if c == 'D': dp[i+1][j...
28
62
409,600
26883241
def ma(): s=input() v=s.split(' ') n=int(v[0]) k=int(v[1]) s=input() dp=[[0,0] for _ in range(n+1)] flag=True for i in range (1,n): c=s[i-1] if c=='?': dp[i][0]=min(dp[i-1][0]+1 ,k-1) dp[i][1]=max(dp[i-1][1]-1 ,-k+1) elif c=='D': ...
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
Python 3
TESTS
22
61
307,200
26963710
from sys import exit n, k = [int(i) for i in input().split()] s = [i for i in input()] p = [0] * (n + 1) qind = -1 def check(): global s b = 0 for i in range(len(s)): if s[i] == 'L': b -= 1 elif s[i] == 'W': b += 1 if i != len(s) - 1 and abs(b) >...
28
93
20,889,600
180996735
n,k=map(int,input().split()) s=input() m=2*k+1 dp=[[0]*m for i in range(n+1)] dp[0][k]=1 for i in range(n): if s[i]=='L' or s[i]=='?': for j in range(m-1): dp[i+1][j]|=dp[i][j+1] if s[i]=='D' or s[i]=='?': for j in range(m): dp[i+1][j]|=dp[i][j] if s[i]=='W' or s[i]=='?': for j in range(1,...
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
686/B
686
B
Python 3
TESTS
2
93
0
85887689
n = int(input()) l = list(map (int , input().split())) tmp = sorted(l) i = 1 while l != tmp and i < n: if l[i] < l[i-1] : l[i] , l[i-1] = l[i-1] , l[i] print(i , i+1) i+=1
37
62
307,200
111147375
def isSorted(a): for i in range(0, len(a)-1): if a[i] > a[i+1]: return False return True n = int(input()) a = [int(x) for x in input().split()] while not isSorted(a): for i in range(0,n-1): if a[i] > a[i+1]: print(i+...
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the o...
null
Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
[{"input": "4\n2 1 4 3", "output": "1 4"}, {"input": "7\n36 28 57 39 66 69 68", "output": "1 4\n6 7"}, {"input": "5\n1 2 1 2 1", "output": "2 5\n3 4\n1 4\n1 4"}]
1,100
["constructive algorithms", "implementation", "sortings"]
37
[{"input": "4\r\n2 1 4 3\r\n", "output": "1 2\r\n3 4\r\n"}, {"input": "7\r\n36 28 57 39 66 69 68\r\n", "output": "1 2\r\n3 4\r\n6 7\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "2 3\r\n4 5\r\n3 4\r\n"}, {"input": "78\r\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 4...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path, 'r') as f: lines = f...
true
980/C
980
C
Python 3
PRETESTS
8
78
7,065,600
38037220
pixels, k = [int(x) for x in input().split(' ')] pixel_colors = [int(x) for x in input().split(' ')] pixels_groups = [(x // k) * k for x in range(256)] visited = [0] * 256 results = [] for i in range(pixels): current = pixel_colors[i] if visited[current] == 1: results.append(pixels_groups[current]) continue # ...
82
186
12,595,200
38034054
def getIntList(): return list(map(int, input().split())); n, k = getIntList(); p=getIntList(); choosed=[False]*256; left=[i for i in range(256)]; for i, x in enumerate(p): if not choosed[x]: best=x; #print(x-1, max(-1, x-k)); for j in range(x-1, max(-1, x-k), -1): #print('try...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
980/C
980
C
Python 3
PRETESTS
8
78
7,065,600
38043840
n,k = [int(s) for s in input().split()] p = [int(s) for s in input().split()] map = {} res = [] for pi in p: if map.get(pi) is None: key = pi for j in range(pi, pi-k, -1): if j < 0: break if map.get(j) is None: key = j else: if ma...
82
187
11,059,200
139556135
import sys,os,io import math from collections import defaultdict def ii(): return int(input()) def li(): return list(map(int,input().split())) if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") else: input = io.BytesIO(os.read(0, os.fstat(0).st_siz...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
980/C
980
C
Python 3
PRETESTS
8
93
7,065,600
38045453
n, k = map(int, input().strip().split()) data = map(int, input().strip().split()) sol = [] mapping = [(-1,1000)]*256 for x in data: if mapping[x][0] == -1: for i in range(max(x-k+1,0), x+1): if mapping[i][0] == -1: if i > 0 and mapping[i-1][1]+(x-i+1) <= k: p ...
82
187
13,004,800
38036027
n, k = [int(x) for x in input().split()] ps = [int(x) for x in input().split()] mapping = [-1 for _ in range(256)] res = [] for p in ps: if mapping[p] == -1: j = p - k + 1 while j < 0 or (mapping[j] != -1 and mapping[j] + k <= p): j += 1 for i in range(j, p+1): map...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
780/A
780
A
Python 3
TESTS
3
186
19,046,400
33659652
# =================================== # (c) MidAndFeed aka ASilentVoice # =================================== # import math, fractions, collections # =================================== n = int(input()) q = [int(x) for x in input().split()] ans = -n s = set() for i in range(n): temp = q[i] if temp in s: s.remove(te...
56
124
20,172,800
228759395
number = int(input()) s = input().split(" ") arr = set() max_len = 0 for i in range(2 * number): if s[i] not in arr: arr.add(s[i]) if len(arr) > max_len: max_len = len(arr) else: arr.remove(s[i]) print(max_len)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is gua...
Print single integer — the maximum number of socks that were on the table at the same time.
null
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - In...
[{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}]
800
["implementation"]
56
[{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ...
false
stdio
null
true
686/B
686
B
PyPy 3-64
TESTS
2
46
1,536,000
199161615
from sys import stdin, stdout input = stdin.readline def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) def int_map(): return map(int, input().split()) def list_int(): return list(map(int, input().split())) n = int(input()) arr = list_int() sorted = True for i in range(20000):...
37
62
409,600
18674795
n=int(input()) l=list(map(int,input().split())) ans=[] ls=sorted(l) while l!=ls: for i in range(1,n): if l[i-1]>l[i]: ans+=[' '.join([str(i),str(i+1)])] l[i-1],l[i]=l[i],l[i-1] print('\n'.join(ans))
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the o...
null
Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
[{"input": "4\n2 1 4 3", "output": "1 4"}, {"input": "7\n36 28 57 39 66 69 68", "output": "1 4\n6 7"}, {"input": "5\n1 2 1 2 1", "output": "2 5\n3 4\n1 4\n1 4"}]
1,100
["constructive algorithms", "implementation", "sortings"]
37
[{"input": "4\r\n2 1 4 3\r\n", "output": "1 2\r\n3 4\r\n"}, {"input": "7\r\n36 28 57 39 66 69 68\r\n", "output": "1 2\r\n3 4\r\n6 7\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "2 3\r\n4 5\r\n3 4\r\n"}, {"input": "78\r\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 4...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path, 'r') as f: lines = f...
true
472/D
472
D
Python 3
TESTS
0
15
0
213891010
print ("NO")
47
545
57,036,800
177433089
from math import inf from collections import * import math, os, sys, heapq, bisect, random,threading from functools import lru_cache from itertools import * import sys def inp(): return sys.stdin.readline().rstrip("\r\n") def out(var): sys.stdout.write(str(var)) # for fast output, always take string def inpu(): return...
Codeforces Round 270
CF
2,014
2
256
Design Tutorial: Inverse the Problem
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.
If there exists such a tree, output "YES", otherwise output "NO".
null
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7. In the second example, it is impossible because d1, 1 should be 0, but it is 1. In the third example, it is impossible because d1, 2 should equal d2, 1.
[{"input": "3\n0 2 7\n2 0 9\n7 9 0", "output": "YES"}, {"input": "3\n1 2 7\n2 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 2 2\n7 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "NO"}, {"input": "2\n0 0\n0 0", "output": "NO"}]
1,900
["dfs and similar", "dsu", "shortest paths", "trees"]
47
[{"input": "3\r\n0 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 2 2\r\n7 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r\n1 0 1\r\n1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "NO\r\n...
false
stdio
null
true
780/A
780
A
Python 3
TESTS
3
124
11,161,600
50261641
n = int(input()) a = input().split() max_cnt = 0 d = {} for i in range(n): if a[i] in d: del d[a[i]] else: d[a[i]] = 1 if max_cnt < len(d): max_cnt = len(d) print(max_cnt)
56
124
25,907,200
198581634
n = int(input()) * 2 lst = [int(x) for x in input().split()][:n] t = set() maxi, cnt = 1, 0 for i in range(n): if lst[i] not in t: t.add(lst[i]) cnt += 1 else: if maxi < cnt: maxi = cnt t.remove(lst[i]) cnt -= 1 print(maxi)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is gua...
Print single integer — the maximum number of socks that were on the table at the same time.
null
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - In...
[{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}]
800
["implementation"]
56
[{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ...
false
stdio
null
true
780/D
780
D
PyPy 3
PRETESTS
3
93
23,142,400
25244432
a = set() c = 0 t1 = dict() t2 = dict() n = int(input()) h1 = [[] for i in range(1000)] h2 = [[] for i in range(1000)] h3 = [] for i in range(n): g, h = input().split() s1 = g[:3] s2 = g[:2] + h[0] if s1 not in a: t1[c] = s1 t2[s1] = c a.add(s1) c+=1 if s2 not in a: ...
41
155
20,275,200
87930633
from sys import stdin n = int(stdin.readline().strip()) T,A = [],[] N,M = {},{} for _ in range(n): t,h = stdin.readline().split() n1,n2 = t[:3],t[:2]+h[0] N[n1] = N.get(n1,0)+1 T.append((n1,n2)) A.append(n1) def solve(): for i in range(n): n1,n2 = T[i] if n1 not in M and N[n1]=...
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Innokenty and a Football League
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters. Each club's full name consist of two wo...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league. Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20.
It it is not possible to choose short names and satisfy all constraints, print a single line "NO". Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input. If there are multiple answe...
null
In the first sample Innokenty can choose first option for both clubs. In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs. In the third example Innokenty can choose the ...
[{"input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW", "output": "YES\nDIN\nFOO"}, {"input": "2\nDINAMO BYTECITY\nDINAMO BITECITY", "output": "NO"}, {"input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP", "output": "YES\nPLM\nPLS\nGOG"}, {"input": "3\nABC DEF\nABC EFG\nABD OOO", "output": "YES\nABD\nABE\nABO...
1,900
["2-sat", "graphs", "greedy", "implementation", "shortest paths", "strings"]
41
[{"input": "2\r\nDINAMO BYTECITY\r\nFOOTBALL MOSCOW\r\n", "output": "YES\r\nDIN\r\nFOO\r\n"}, {"input": "2\r\nDINAMO BYTECITY\r\nDINAMO BITECITY\r\n", "output": "NO\r\n"}, {"input": "3\r\nPLAYFOOTBALL MOSCOW\r\nPLAYVOLLEYBALL SPB\r\nGOGO TECHNOCUP\r\n", "output": "YES\r\nPLM\r\nPLS\r\nGOG\r\n"}, {"input": "3\r\nABC DEF...
false
stdio
import sys def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) clubs = [] for _ in range(n): team, hometown = f.readline().strip().split() clubs.append((team, hometown)) ai_list = [] bi_list = [] f...
true
350/B
350
B
PyPy 3-64
TESTS
8
218
19,353,600
224589502
def solve(): n = int(input()) arr = list(map(int,input().split())) lis = list(map(int,input().split())) degree = [0]*n parent = [-1]*n for i in range(n): parent[i] = lis[i]-1 degree[lis[i]-1]+=1 ans = [] visited = [False]*n for i in range(n): if arr[i]==1: s = i tmp = [s+1] s = parent[s] whil...
36
248
21,811,200
164910916
if __name__ == '__main__': n = int(input()) types = [0] + list(map(int, input().split())) nodes = [0] + list(map(int, input().split())) sol, count = [], [0 for i in range(n + 1)] for i in nodes: count[i] += 1 for i in range(1, n+1): if types[i] == 1: path = [i] ...
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
350/B
350
B
PyPy 3
TESTS
8
374
32,358,400
122915385
from collections import defaultdict ''' from obhect ai-> i there is a path that exists ''' blanc=[] g=defaultdict(list) n=int(input()) type=list(map(int,input().strip().split())) path=list(map(int,input().strip().split())) path=list(map(lambda s:s-1,path)) ans=[] deg=[0]*(n) for i in path: deg[i]+=1 for i in range(...
36
312
9,011,200
142931702
n = int(input()) t = [0] + list(map(int, input().split())) a = [0] + list(map(int, input().split())) ans, cnt = [], [0 for i in range(n + 1)] for i in a: cnt[i] += 1 for i in range(1, n + 1): if t[i] == 1: crt = [i] x = a[i] while cnt[x] == 1: crt.append(x) x =...
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
350/B
350
B
Python 3
TESTS
8
372
12,492,800
17932843
n = int(input()) t = list(map(int, input().split())) a = list(map(int, input().split())) cnt = list([0 for _ in range(n)]) for i in a: cnt[i - 1] += 1 def func(x): ans = [x + 1] x = a[x] - 1 while x >= 0 and t[x] == 0 and cnt[x] == 1: ans.insert(0, x + 1) x = a[x] - 1 return ans ...
36
340
19,660,800
224590425
def solve(): n = int(input()) arr = list(map(int,input().split())) parent = list(map(int,input().split())) degree = [0]*n for i in range(n): parent[i] -=1 if parent[i]!=-1: degree[parent[i]]+=1 ans = [] visited = [False]*n for i in range(n): if arr[i]==1: s = i tmp = [] while parent[s]!=-1 and...
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
51/B
51
B
Python 3
TESTS
8
248
7,475,200
88444268
from sys import stdin import re fef,ans = '',[] for sus in stdin.readlines(): fef+=sus fuf = re.split(r'<table>',fef) for cuc in fuf: nut = cuc.count('<td>') if nut: ans.append(nut) ans.sort() print(*ans)
19
124
512,000
14009626
import re lines = [] while True: try: line = input() except EOFError: break lines.append(line.strip()) text = ''.join(lines) text = re.sub('<table>', '(', text) text = re.sub('</table>', ')', text) text = re.sub('<td>', '.', text) text = re.sub('[^().]', '', text) sizes = [] def parse(po...
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
678/E
678
E
Python 3
TESTS
0
15
0
200673677
from functools import lru_cache from itertools import combinations n = int(input()) A = [[0] * n for _ in range(n)] for r in range(n): A[r] = [float(x) for x in input().split(' ')] n = len(A) @lru_cache(None) def dp(mask, res = 0): if bin(mask).count('1') == n - 1: return mask == (1 << n) - 1 - 1 ...
41
1,263
57,036,800
152774652
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) p = [list(map(float, input().split())) for _ in range(n)] pow2 = [1] for _ in range(n): pow2.append(2 * pow2[-1]) pn = pow2[n] dp = [[0] * n for _ in range(pn)] dp[1][0] = 1 for i in range(2, pn): dpi = dp[i] b...
Educational Codeforces Round 13
ICPC
2,016
2.5
256
Another Sith Tournament
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b...
The first line contains a single integer n (1 ≤ n ≤ 18) — the number of participants of the Sith Tournament. Each of the next n lines contains n real numbers, which form a matrix pij (0 ≤ pij ≤ 1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel. The elements on the main d...
Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10 - 6.
null
null
[{"input": "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0", "output": "0.680000000000000"}]
2,200
["bitmasks", "dp", "math", "probabilities"]
41
[{"input": "3\r\n0.0 0.5 0.8\r\n0.5 0.0 0.4\r\n0.2 0.6 0.0\r\n", "output": "0.680000000000000\n"}, {"input": "1\r\n0.0\r\n", "output": "1.000000000000000\n"}, {"input": "2\r\n0.00 0.75\r\n0.25 0.00\r\n", "output": "0.750000000000000\n"}, {"input": "4\r\n0.0 0.6 0.5 0.4\r\n0.4 0.0 0.3 0.8\r\n0.5 0.7 0.0 0.5\r\n0.6 0.2 0...
false
stdio
import sys def read_value(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] if len(lines) != 1: return None try: return float(lines[0]) except: return None def main(): input_path = sys.argv[1] correct_output_path ...
true
813/C
813
C
PyPy 3
TESTS
18
841
52,019,200
89172173
from sys import stdin, stdout import math,sys,heapq from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime-------------------...
25
498
31,334,400
181265003
from sys import stdin input=lambda :stdin.readline()[:-1] n,x=map(int,input().split()) x-=1 edge=[[] for i in range(n)] for i in range(n-1): a,b=map(lambda x:int(x)-1,input().split()) edge[a].append(b) edge[b].append(a) def dfs(r): dist=[0]*n todo=[(r,-1)] while todo: v,p=todo.pop() for u in edge[...
Educational Codeforces Round 22
ICPC
2,017
1
256
The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex x (x ≠ 1). The moves are made in turns, Bob goes first...
The first line contains two integer numbers n and x (2 ≤ n ≤ 2·105, 2 ≤ x ≤ n). Each of the next n - 1 lines contains two integer numbers a and b (1 ≤ a, b ≤ n) — edges of the tree. It is guaranteed that the edges form a valid tree.
Print the total number of moves Alice and Bob will make.
null
In the first example the tree looks like this: The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves: B: stay at vertex 3 A: go to vertex 2 B: stay at vertex 3 A: go to vertex 3 In the secon...
[{"input": "4 3\n1 2\n2 3\n2 4", "output": "4"}, {"input": "5 2\n1 2\n2 3\n3 4\n2 5", "output": "6"}]
1,700
["dfs and similar", "graphs"]
25
[{"input": "4 3\r\n1 2\r\n2 3\r\n2 4\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n", "output": "6\r\n"}, {"input": "2 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n2 1\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2\r\n3 2\r\n", "output": "4\r\n"}, {"input": "10 4\r\n5 4\r\n8 3\...
false
stdio
null
true
813/C
813
C
Python 3
TESTS
21
951
169,164,800
124943782
from collections import defaultdict from sys import stdin, setrecursionlimit input=stdin.readline setrecursionlimit(10**5) import threading def dfs(node, parent, g, d, dp): tt = 0 if parent != -1: d[node] = d[parent] + 1 dp[node] = max(dp[node], d[node]) for i in g[node]: if i != parent: tt = max(tt, dfs(i,...
25
498
66,764,800
161893732
from bisect import * from collections import * import sys import io, os import math import random from heapq import * gcd = math.gcd sqrt = math.sqrt maxint=10**21 def ceil(a, b): a = -a k = a // b k = -k return k # arr=list(map(int, input().split())) # n,m=map(int,input().split()) input = io.BytesIO(os...
Educational Codeforces Round 22
ICPC
2,017
1
256
The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex x (x ≠ 1). The moves are made in turns, Bob goes first...
The first line contains two integer numbers n and x (2 ≤ n ≤ 2·105, 2 ≤ x ≤ n). Each of the next n - 1 lines contains two integer numbers a and b (1 ≤ a, b ≤ n) — edges of the tree. It is guaranteed that the edges form a valid tree.
Print the total number of moves Alice and Bob will make.
null
In the first example the tree looks like this: The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves: B: stay at vertex 3 A: go to vertex 2 B: stay at vertex 3 A: go to vertex 3 In the secon...
[{"input": "4 3\n1 2\n2 3\n2 4", "output": "4"}, {"input": "5 2\n1 2\n2 3\n3 4\n2 5", "output": "6"}]
1,700
["dfs and similar", "graphs"]
25
[{"input": "4 3\r\n1 2\r\n2 3\r\n2 4\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n", "output": "6\r\n"}, {"input": "2 2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n2 1\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2\r\n3 2\r\n", "output": "4\r\n"}, {"input": "10 4\r\n5 4\r\n8 3\...
false
stdio
null
true
28/A
28
A
PyPy 3-64
TESTS
9
124
1,638,400
216103828
import sys input = sys.stdin.readline def f(w, i): d = [] t = n while t: t -= 2 d.append((ff(w[(i-1)%n], w[i]) + ff(w[i], w[(i+1)%n]), i)) i += 2 d.sort(reverse=1) i, ew, h = 0, 1, [] while d: a, b = d.pop() while i < m and q[i][0] > a: i += ...
51
92
204,800
212540864
def main(): n, m = map(int, input().split()) nails = [] for _ in range(n): nails.append(tuple(map(int, input().split()))) rods = list(map(int, input().split())) rods_count1, rods_count2 = {}, {} for i, rod in enumerate(rods): if rod not in rods_count1: rods_count1[rod...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
Bender Problem
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ...
The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ...
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.
null
null
[{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}]
1,600
["implementation"]
51
[{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, m = map(int, f.readline().split()) nails = [tuple(map(int, f.readline().split())) for _ in range(n)] rods = list(map(int, f.readline().split())...
true
809/C
809
C
Python 3
TESTS
5
108
0
42261935
mod = 1000000007 def sum(x, y, k, add) : if k < add : return 0 up = x + add if up > k : up = k add = add + 1 return y * ( ( (add + up) * (up - add + 1) // 2 ) % mod ) % mod def solve(x, y, k, add = 0) : if x == 0 or y == 0 : return 0 if x > y : x, y = y, x pw = 1 while (pw ...
65
1,044
8,908,800
42277571
mod = 1000000007 def sum(x,y,k,add) : if k<add:return 0 up=x+add if up>k:up=k add=add+1 return y*(((add+up)*(up-add+1)//2)%mod)%mod def solve(x,y,k,add=0) : if x==0 or y==0:return 0 if x>y:x,y=y,x pw = 1 while (pw<<1)<=y:pw<<=1 if pw<=x:return (sum(pw,pw,k,add)+sum(pw,x+y-pw-pw,k...
Codeforces Round 415 (Div. 1)
CF
2,017
4
256
Find a car
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help. Form...
The first line contains one integer q (1 ≤ q ≤ 104) — the number of Leha's requests. The next q lines contain five integers x1, y1, x2, y2, k (1 ≤ x1 ≤ x2 ≤ 109, 1 ≤ y1 ≤ y2 ≤ 109, 1 ≤ k ≤ 2·109) — parameters of Leha's requests.
Print exactly q lines — in the first line print the answer to the first request, in the second — the answer to the second request and so on.
null
Let's analyze all the requests. In each case the requested submatrix is highlighted in blue. In the first request (k = 1) Leha asks only about the upper left parking cell. In this cell the car's number is 1. Consequentally the answer is 1. In the second request (k = 5) suitable numbers are 4, 1, 2, 3, 2, 1. Consequen...
[{"input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2", "output": "1\n13\n93\n0"}]
2,600
["combinatorics", "divide and conquer", "dp"]
65
[{"input": "4\r\n1 1 1 1 1\r\n3 2 5 4 5\r\n1 1 5 5 10000\r\n1 4 2 5 2\r\n", "output": "1\r\n13\r\n93\r\n0\r\n"}, {"input": "10\r\n3 7 4 10 7\r\n6 1 7 10 18\r\n9 6 10 8 3\r\n1 8 3 10 3\r\n10 4 10 5 19\r\n8 9 9 10 10\r\n10 1 10 5 4\r\n8 1 9 4 18\r\n6 3 9 5 1\r\n6 6 9 6 16\r\n", "output": "22\r\n130\r\n0\r\n0\r\n25\r\n3\r...
false
stdio
null
true
780/A
780
A
PyPy 3-64
TESTS
3
108
24,268,800
231364820
from collections import defaultdict from sys import stdin def solve(): n = int(input()) a = [int(x) for x in input().split()] answ = 0 c = 0 d = defaultdict(int) for i in range(n): if d[a[i]] == 0: d[a[i]] = 1 c+=1 answ = max(answ,c) else: ...
56
124
26,214,400
198540772
n = int(input()) lst = list(map(int, input().split())) tbl, res = set(), 0 for x in lst: if x in tbl: tbl.remove(x) else: tbl.add(x) res = max(res, len(tbl)) print(res)
Технокубок 2017 - Финал (только для онсайт-финалистов)
CF
2,017
2
256
Andryusha and Socks
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is gua...
Print single integer — the maximum number of socks that were on the table at the same time.
null
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - In...
[{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}]
800
["implementation"]
56
[{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ...
false
stdio
null
true
33/A
33
A
Python 3
TESTS
11
216
307,200
91313760
import sys n, m, k = map(int, input().split(' ')) ar = [0] * (n + 4); tnt = [1000005] * (n + 1) jael = 0; for i in range(n): x, y = map(int, input().split(' ')) ar[x], tnt[x] = x, min(tnt[x], y) for i in range(n): if(tnt[i] < 1000005): jael += tnt[i] print(min(jael, k))
31
92
0
177072860
n,m,k = map(int,input().split()) diction = {} for i in range(n): nums = list(map(int,input().split())) if nums[0] not in diction.keys(): diction[nums[0]] = nums[1] elif nums[0] in diction.keys(): if nums[1] > diction[nums[0]]: pass else: diction[nums[0]] = num...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
25/D
25
D
Python 3
TESTS
8
62
102,400
214723976
numCity = int(input()) parent = [0 for _ in range(numCity + 1)] size = [0 for _ in range(numCity + 1)] close = [] built = [] def swap(a, b): temp = a a = b b = temp def make_set(v): parent[v] = v size[v] = 1 def find_set(v): if v == parent[v]: return v parent[v] = find_set(pa...
55
92
307,200
205815033
class DSU: def __init__(self,n): self.parent=[] self.size=[] for i in range(n+1): self.parent.append(i) self.size.append(1) self.parent[0]=None self.size[0]=None def _findParent(self,node): if self.parent[node]==node: return node ...
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/D
25
D
PyPy 3-64
TESTS
8
92
512,000
158788882
def dfs(vertex): marked[vertex] = True for vertex2 in graph[vertex]: if not marked[vertex2]: dfs(vertex2) def dfs2(vertex, last): marked[vertex] = True for vertex2 in graph[vertex]: if vertex2 != vertex: if not marked[vertex2]: dfs2(vertex2, vertex) else: reserv.append((vertex+1, vertex2+1)) ...
55
92
512,000
209987496
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
978/C
978
C
PyPy 3-64
TESTS
11
295
34,508,800
186860462
input() a=list(map(int,input().split())) b=list(map(int,input().split())) sum=0 room_count=[] for i in range(len(a)): sum+=a[i] room_count.append(sum) sum=0 dormitory=1 z=0 for i in b: while i>room_count[z]: dormitory+=1 sum+=a[z] z+=1 else: #dormitory ready ...
16
265
36,761,600
219562054
import sys def find(a: list[int], q: int) -> bool: i = find_lower(a, q) return i >= 0 and a[i] == q def find_lower(a: list[int], x: int) -> int: """max i: a[i] <= x""" l = -1 # a[l] <= x r = len(a) # a[r] > x while r > l + 1: m = (l + r) // 2 if a[m] <= x: l = m...
Codeforces Round 481 (Div. 3)
ICPC
2,018
4
256
Letters
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$. A postman delivers letters. Sometimes there ...
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. ...
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
null
In the first example letters should be delivered in the following order: - the first letter in room $$$1$$$ of the first dormitory - the second letter in room $$$9$$$ of the first dormitory - the third letter in room $$$2$$$ of the second dormitory - the fourth letter in room $$$13$$$ of the second dormitory - the fif...
[{"input": "3 6\n10 15 12\n1 9 12 23 26 37", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"}, {"input": "2 3\n5 10000000000\n5 6 9999999999", "output": "1 5\n2 1\n2 9999999994"}]
1,000
["binary search", "implementation", "two pointers"]
16
[{"input": "3 6\r\n10 15 12\r\n1 9 12 23 26 37\r\n", "output": "1 1\r\n1 9\r\n2 2\r\n2 13\r\n3 1\r\n3 12\r\n"}, {"input": "2 3\r\n5 10000000000\r\n5 6 9999999999\r\n", "output": "1 5\r\n2 1\r\n2 9999999994\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1 1\r\n"}, {"input": "5 15\r\n10 20 30 20 10\r\n1 6 10 11 15 30 3...
false
stdio
null
true
978/C
978
C
Python 3
TESTS
9
654
35,635,200
208962869
k = input() f = list(map (int, input().split())) f1 = list(map (int, input().split())) p = 0 d = 0 for i in range(len(f1)): if f1[i] - p > f[d]: p += f[d] d += 1 print (d + 1, f1[i] - p)
16
280
36,556,800
165688277
n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ci, cl, cs = 0, 0, a[0] i = 0 while i < m: if b[i] <= cs: print(ci+1, b[i]-cl) i += 1 else: ci += 1 cl = cs cs += a[ci]
Codeforces Round 481 (Div. 3)
ICPC
2,018
4
256
Letters
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$. A postman delivers letters. Sometimes there ...
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. ...
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
null
In the first example letters should be delivered in the following order: - the first letter in room $$$1$$$ of the first dormitory - the second letter in room $$$9$$$ of the first dormitory - the third letter in room $$$2$$$ of the second dormitory - the fourth letter in room $$$13$$$ of the second dormitory - the fif...
[{"input": "3 6\n10 15 12\n1 9 12 23 26 37", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"}, {"input": "2 3\n5 10000000000\n5 6 9999999999", "output": "1 5\n2 1\n2 9999999994"}]
1,000
["binary search", "implementation", "two pointers"]
16
[{"input": "3 6\r\n10 15 12\r\n1 9 12 23 26 37\r\n", "output": "1 1\r\n1 9\r\n2 2\r\n2 13\r\n3 1\r\n3 12\r\n"}, {"input": "2 3\r\n5 10000000000\r\n5 6 9999999999\r\n", "output": "1 5\r\n2 1\r\n2 9999999994\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1 1\r\n"}, {"input": "5 15\r\n10 20 30 20 10\r\n1 6 10 11 15 30 3...
false
stdio
null
true
978/C
978
C
Python 3
TESTS
9
826
21,299,200
160489921
n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(1,n): a[i]+=a[i-1] dorm = 0 for i in range(m): if b[i] <= a[dorm]: print(dorm+1, b[i]-a[dorm-1] if dorm>0 else b[i]) else: b[i] -= a[dorm] dorm += 1 print(dorm+1, b[i])
16
280
36,556,800
182296837
#!/usr/bin/env python3 import math import sys input = lambda: sys.stdin.readline().rstrip("\r\n") from bisect import bisect_left as bs def test_case(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) pref = [0 for _ in range(n+1)] for i in ...
Codeforces Round 481 (Div. 3)
ICPC
2,018
4
256
Letters
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$. A postman delivers letters. Sometimes there ...
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. ...
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
null
In the first example letters should be delivered in the following order: - the first letter in room $$$1$$$ of the first dormitory - the second letter in room $$$9$$$ of the first dormitory - the third letter in room $$$2$$$ of the second dormitory - the fourth letter in room $$$13$$$ of the second dormitory - the fif...
[{"input": "3 6\n10 15 12\n1 9 12 23 26 37", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12"}, {"input": "2 3\n5 10000000000\n5 6 9999999999", "output": "1 5\n2 1\n2 9999999994"}]
1,000
["binary search", "implementation", "two pointers"]
16
[{"input": "3 6\r\n10 15 12\r\n1 9 12 23 26 37\r\n", "output": "1 1\r\n1 9\r\n2 2\r\n2 13\r\n3 1\r\n3 12\r\n"}, {"input": "2 3\r\n5 10000000000\r\n5 6 9999999999\r\n", "output": "1 5\r\n2 1\r\n2 9999999994\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1 1\r\n"}, {"input": "5 15\r\n10 20 30 20 10\r\n1 6 10 11 15 30 3...
false
stdio
null
true
813/D
813
D
PyPy 3
TESTS
3
61
409,600
155264783
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = list(map(int, input().split())) dp0 = [1] * n for i in range(n): dpi = dp0[i] ai = a[i] for j in range(i): if ai % 7 == a[j] % 7 or abs(ai - a[j]) == 1: ...
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
326/A
335
A
Python 3
TESTS
6
92
0
202888667
##import sys ##input=sys.stdin.readline s = input() n = int(input()) st = list(set(s)) l = len(set(s)) if (l > n or n > len(s)): print("-1") elif (n == len(s)): print(s) elif (n == l): m = 0 for i in range(len(s)): cnt = 1 for j in range(i+1, len(s)): if (s[i] == s[j]): ...
55
154
307,200
111125965
s,n,q,a=input(),int(input()),{},"" for i in s:q[i]=[q[i][0]+1,1]if i in q else [1,1] if len(q)>n:print(-1) else: for i in range(n-len(q)): o=0 for j in q: m=(q[j][0]+q[j][1]-1)//q[j][1] if m>o:o,w=m,j q[w][1]=q[w][1]+1 for i in q:a+=i*q[i][1] o=0 for i in ...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
71/A
71
A
Python 3
TESTS
1
15
0
221528018
def creat(s): n=len(s) if(n>=10): s2='' s2+=s[0] s2+=str(n-2) s2+=s[n-1] return s2 else: return s n=int(input()) d=[] for i in range(n): s=input() d.append(creat(s)) for i in d:print(i)
20
31
0
182375805
n = int(input()) for i in range(n): s = input() l = len(s) if l > 10: a = s[0] b = s[l - 1] c = l - 2 print(''.join([a, str(c), b])) else: print(s)
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"...
false
stdio
null
true
815/C
815
C
PyPy 3
TESTS
2
140
1,843,200
110012382
from collections import defaultdict def BFGetMaxGood(start,RemPurse,G,Cost,Discount,prevSelected): M=0 if RemPurse<0: return -1 if RemPurse==0 or start>len(Cost): return 0 #Either purchases this element if (prevSelected,start) in G:#discount applies M=max(M,1+BFGetMaxGood(st...
92
1,106
206,643,200
156376775
import sys readline=sys.stdin.readline N,B=map(int,readline().split()) D,C=[],[] c,d=map(int,readline().split()) D.append(d) C.append(c) child=[[] for x in range(N)] for i in range(1,N): c,d,p=map(int,readline().split()) p-=1 D.append(d) C.append(c) child[p].append(i) queue=[0] tour=[] while queue:...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Supermarket
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods. The i-th good can be bought for ci dollars. Of course, each good c...
The first line of input contains two integers n and b (1 ≤ n ≤ 5000, 1 ≤ b ≤ 109), the number of goods in the store and the amount of money Karen has, respectively. The next n lines describe the items. Specifically: - The i-th line among these starts with two integers, ci and di (1 ≤ di < ci ≤ 109), the price of the ...
Output a single integer on a line by itself, the number of different goods Karen can buy, without exceeding her budget.
null
In the first test case, Karen can purchase the following 4 items: - Use the first coupon to buy the first item for 10 - 9 = 1 dollar. - Use the third coupon to buy the third item for 12 - 2 = 10 dollars. - Use the fourth coupon to buy the fourth item for 20 - 18 = 2 dollars. - Buy the sixth item for 2 dollars. The to...
[{"input": "6 16\n10 9\n10 5 1\n12 2 1\n20 18 3\n10 2 3\n2 1 5", "output": "4"}, {"input": "5 10\n3 1\n3 1 1\n3 1 2\n3 1 3\n3 1 4", "output": "5"}]
2,400
["brute force", "dp", "trees"]
92
[{"input": "6 16\r\n10 9\r\n10 5 1\r\n12 2 1\r\n20 18 3\r\n10 2 3\r\n2 1 5\r\n", "output": "4\r\n"}, {"input": "5 10\r\n3 1\r\n3 1 1\r\n3 1 2\r\n3 1 3\r\n3 1 4\r\n", "output": "5\r\n"}, {"input": "13 30\r\n6 4\r\n25 5 1\r\n7 1 2\r\n9 4 2\r\n10 2 1\r\n12 3 1\r\n5 2 3\r\n10 9 6\r\n2 1 1\r\n5 3 9\r\n10 2 10\r\n10 9 6\r\n3...
false
stdio
null
true
977/F
977
F
Python 3
TESTS
4
140
24,678,400
230591007
n=int(input()) *mas,=map(int,input().split()) slov={} for i in range(n): if mas[i]-1 not in slov: slov[mas[i]]=1 else: slov[mas[i]]=slov.get(mas[i]-1)+1 ans=0 start=0 for key in slov.keys(): if slov[key]>ans: ans=slov[key] start=key print(ans) for x in range(start-ans+1, star...
70
186
37,273,600
225724905
n = int(input()) nums = [int(x) for x in input().split()] n = len(nums) dp = [0]*n seen = {} for i in range(n): num = nums[i] if num-1 in seen: idx = seen[num-1] dp[i] = 1 + dp[idx] else: dp[i] = 1 seen[num] = i mmax = 0 high = -1 for i in range(n): if dp[i] > mmax: ...
Codeforces Round 479 (Div. 3)
ICPC
2,018
2
256
Consecutive Subsequence
You are given an integer array of length $$$n$$$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and len...
The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.
On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
null
All valid answers for the first example (as sequences of indices): - $$$[1, 3, 5, 6]$$$ - $$$[2, 3, 5, 6]$$$ All valid answers for the second example: - $$$[1, 4]$$$ - $$$[2, 5]$$$ - $$$[3, 6]$$$ All valid answers for the third example: - $$$[1]$$$ - $$$[2]$$$ - $$$[3]$$$ - $$$[4]$$$ All valid answers for the fou...
[{"input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6"}, {"input": "6\n1 3 5 2 4 6", "output": "2\n1 4"}, {"input": "4\n10 9 8 7", "output": "1\n1"}, {"input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9"}]
1,700
["dp"]
70
[{"input": "7\r\n3 3 4 7 5 6 8\r\n", "output": "4\r\n2 3 5 6 \r\n"}, {"input": "6\r\n1 3 5 2 4 6\r\n", "output": "2\r\n1 4 \r\n"}, {"input": "4\r\n10 9 8 7\r\n", "output": "1\r\n1 \r\n"}, {"input": "9\r\n6 7 8 3 4 5 9 10 11\r\n", "output": "6\r\n1 2 3 7 8 9 \r\n"}, {"input": "1\r\n1337\r\n", "output": "1\r\n1 \r\n"}, {...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input input_lines = read_file_lines(input_path) n = int(input_lines[...
true
977/F
977
F
Python 3
TESTS
4
124
25,088,000
222445678
from collections import defaultdict ,Counter n = int(input()) array = list(map(int,input().split())) count = Counter() subSeq = defaultdict(list) for i in range(n): if array[i] in count: continue count[array[i]] = count[array[i ] - 1] + 1 subSeq[array[i]].extend(subSeq[array[i] - 1]) sub...
70
249
39,833,600
225092564
# ﷽ from bisect import bisect_left from collections import defaultdict import sys input = lambda: sys.stdin.readline().strip() def inlst():return [int(i) for i in input().split()] oo=float('inf') def solve(): n=int(input()) lst=inlst() dic=defaultdict(int) k=-1;val=-1 for i in lst: dic[i]=d...
Codeforces Round 479 (Div. 3)
ICPC
2,018
2
256
Consecutive Subsequence
You are given an integer array of length $$$n$$$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and len...
The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.
On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
null
All valid answers for the first example (as sequences of indices): - $$$[1, 3, 5, 6]$$$ - $$$[2, 3, 5, 6]$$$ All valid answers for the second example: - $$$[1, 4]$$$ - $$$[2, 5]$$$ - $$$[3, 6]$$$ All valid answers for the third example: - $$$[1]$$$ - $$$[2]$$$ - $$$[3]$$$ - $$$[4]$$$ All valid answers for the fou...
[{"input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6"}, {"input": "6\n1 3 5 2 4 6", "output": "2\n1 4"}, {"input": "4\n10 9 8 7", "output": "1\n1"}, {"input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9"}]
1,700
["dp"]
70
[{"input": "7\r\n3 3 4 7 5 6 8\r\n", "output": "4\r\n2 3 5 6 \r\n"}, {"input": "6\r\n1 3 5 2 4 6\r\n", "output": "2\r\n1 4 \r\n"}, {"input": "4\r\n10 9 8 7\r\n", "output": "1\r\n1 \r\n"}, {"input": "9\r\n6 7 8 3 4 5 9 10 11\r\n", "output": "6\r\n1 2 3 7 8 9 \r\n"}, {"input": "1\r\n1337\r\n", "output": "1\r\n1 \r\n"}, {...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input input_lines = read_file_lines(input_path) n = int(input_lines[...
true
247/C
250
C
PyPy 3
TESTS
20
374
11,059,200
51266323
n, k = map(int, input().split()) a = [int(i) for i in input().split()] s = [0 for i in range(k)] if n == 100000 and k == 3: print(1) else: for i in range(n): if i == 0 and a[i] == a[i + 1]: continue elif i == 0 and a[i] != a[i + 1]: s[a[0] - 1] += 1 elif i == n - ...
44
404
7,372,800
148475565
def findMininumStress (newMovies, k): stress = 0 for i in range(len(newMovies)): if i < len(newMovies) - 1: if newMovies[i] != newMovies[i + 1]: stress = stress + 1 fewerStresses = [stress] * k minimumValue = stress minimumPosition = 0 for i in range(len(ne...
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
71/A
71
A
Python 3
TESTS
1
15
0
223035188
n = int(input()) for _ in range(n): word = input() if (len(word) < 10): print(word) else: print(word[0] + str(len(word)-2) + word[-1])
20
31
0
182635365
def split(word): return [char for char in word] def func(a): res = [] for i in range(len(a)): if len(a[i])<=10: res.append(a[i]) elif len(a[i])>10: aa = split(a[i]) strr = '' nuum = str(len(aa)-2) strr=aa[0]+nuum+aa[-1] ...
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"...
false
stdio
null
true
67/A
67
A
Python 3
TESTS
5
92
0
149596648
n=int(input()) s="0"+input() k=[1]*n for i in range(1,n): if s[i]=="R" and k[i]<=k[i-1]: k[i]=k[i-1]+1 elif s[i]=="L" and k[i-1]<=k[i]: k[i-1]+=1 elif s[i]=="=": k[i]=k[i-1] print(*k)
43
92
0
149605126
n=int(input()) s="0"+input() k=[1]*n for i in range(1,n): if s[i]=="R" and k[i]<=k[i-1]: k[i]=k[i-1]+1 elif s[i]=="L" and k[i-1]<=k[i]: k[i-1]=1 elif s[i]=="=": k[i]=k[i-1] s=s[::-1] k=k[::-1] for i in range(n-1): if s[i]=="L" and k[i+1]<=k[i]: k[i+1]=k[i]+1 elif s[i]...
Manthan 2011
CF
2,011
1
256
Partial Teacher
A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks...
The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar...
Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
null
null
[{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}]
1,800
["dp", "graphs", "greedy", "implementation"]
43
[{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=...
false
stdio
null
true
71/A
71
A
Python 3
TESTS
1
15
0
226239599
a = int(input()) for i in range(a): m = input() if len(m) < 10: print(m) else: n = len(m) - 2 print(f"{m[0]}{n}{m[-1]}")
20
31
0
183022020
test = int(input()) for i in range(test): words = input() if len(words) > 10: arr = [words[0],(len(words)-2),words[ len(words)-1]] print(arr[0]+""+str(arr[1])+""+arr[2]) else: print(words)
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"...
false
stdio
null
true
71/A
71
A
Python 3
TESTS
1
15
0
226497407
x = int(input()) words = [] process = [] for i in range(x): word = input() words.append(word) for i in range(0, len(words)): if len(words[i]) - 2 < 10: process.append(words[i]) if len(words[i]) - 2 >= 10: f = words[i] c = f[0] + str(len(words[i])- 2) + f[-1] process.ap...
20
31
0
183534986
a = int(input()) for i in range(0, a): b = str(input()) if len(b) > 10: print(b[0] + str(len(b)-2) + b[-1]) else: print(b)
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"...
false
stdio
null
true
362/A
362
A
Python 3
PRETESTS
7
46
307,200
5101339
N = int(input()) for i in range(N): if i > 0: input() Pos = [] for i in range(8): S = input().strip() for j in range(8): if S[j] == "K": Pos.append((i, j)) A, B = Pos if (A[0] + A[1]) % 4 == (B[0] + B[1]) % 4: if max(abs(A[0] - B[0]) // 2, ...
45
46
0
155435429
def main(): n = int(input()) out = "" for t in range(n): knights = [0 for i in range(16)] valid = [False for i in range(16)] for i in range(8): line = input() #print() for j in range(8): #print(get(i, j), end="\t") if line[j] != '#': valid[get(i, j)] = Tr...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
977/F
977
F
Python 3
TESTS
10
280
28,672,000
223056644
l = int(input()) nums = list(map(int,input().split())) lenmax = {n:0 for n in nums} for n in nums: if n-1 in lenmax: lenmax[n] = lenmax[n-1]+1 ans = max(lenmax.values()) last=0 for n in nums: if lenmax[n]==ans: last =n break res = [] for i in range(l-1,-1,-1): if nums[i] == ...
70
404
32,256,000
229090108
n=int(input()) arr=[int(i) for i in input().split()] data={} maxi=0 last_val=0 for i,e in enumerate(arr): c=data.get(e-1,0) data[e]=c+1 if c+1>maxi: maxi=c+1 last_val=e print(data[last_val]) start=last_val-data[last_val]+1 for i,e in enumerate(arr): if e==start: print(i+1,end=' '...
Codeforces Round 479 (Div. 3)
ICPC
2,018
2
256
Consecutive Subsequence
You are given an integer array of length $$$n$$$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and len...
The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.
On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
null
All valid answers for the first example (as sequences of indices): - $$$[1, 3, 5, 6]$$$ - $$$[2, 3, 5, 6]$$$ All valid answers for the second example: - $$$[1, 4]$$$ - $$$[2, 5]$$$ - $$$[3, 6]$$$ All valid answers for the third example: - $$$[1]$$$ - $$$[2]$$$ - $$$[3]$$$ - $$$[4]$$$ All valid answers for the fou...
[{"input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6"}, {"input": "6\n1 3 5 2 4 6", "output": "2\n1 4"}, {"input": "4\n10 9 8 7", "output": "1\n1"}, {"input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9"}]
1,700
["dp"]
70
[{"input": "7\r\n3 3 4 7 5 6 8\r\n", "output": "4\r\n2 3 5 6 \r\n"}, {"input": "6\r\n1 3 5 2 4 6\r\n", "output": "2\r\n1 4 \r\n"}, {"input": "4\r\n10 9 8 7\r\n", "output": "1\r\n1 \r\n"}, {"input": "9\r\n6 7 8 3 4 5 9 10 11\r\n", "output": "6\r\n1 2 3 7 8 9 \r\n"}, {"input": "1\r\n1337\r\n", "output": "1\r\n1 \r\n"}, {...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input input_lines = read_file_lines(input_path) n = int(input_lines[...
true
66/C
66
C
Python 3
TESTS
8
218
0
66516380
import sys, operator filePaths = sys.stdin.readlines() foldercount = 0 directory = {}; fileoccurences = {'C:':0,'D:':0,'E:':0,'F:':0,'G:':0} for line in filePaths: path = list(map(str,line.split('\\'))) fileoccurences[path[0]] += 1 newFolder = False for i in range(1,len(path)-1): if path[i] not ...
100
248
512,000
66522249
import sys files,folder_subfolder = {},{} paths = sys.stdin.readlines() for line in paths: path = line.split('\\') path_length = len(path) headOFpath = path[0] + path[1]; interim = headOFpath if headOFpath not in folder_subfolder: # To collect the folder and the files folder_subfolder[he...
Codeforces Beta Round 61 (Div. 2)
CF
2,011
3
256
Petya and File System
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo...
Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file...
Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as fol...
null
In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1. In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder ...
[{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfi...
1,800
["data structures", "implementation"]
100
[{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4...
false
stdio
null
true
71/A
71
A
Python 3
TESTS
1
15
0
220589322
case = int(input()) while case > 0: w = input() if len(w) >= 10: print(w[0]+str(len(w)-2)+w[-1]) else: print(w) case -= 1
20
31
0
183550011
#A. Арбуз ##n = int(input()) ##if n % 2 == 0 and n != 2: ## print("YES") ##else: ## print("NO") #A. Слишком длинные слова n = int(input()) h = [] for i in range(n): a = input() if len(a) > 10: h.append(a[0]+str((len(a)-2))+a[-1]) else: h.append(a) for i in h: print(i, end="\n")
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"...
false
stdio
null
true
324/A1
331
A2
PyPy 3
TESTS2
7
310
20,275,200
86273522
from collections import defaultdict n = int(input()) a = list(map(int,input().split())) same = defaultdict(list) only_positive = [max(0,x) for x in a] partial_sum = [0 for i in range(n+1)] for i in range(1,n+1): partial_sum[i] = partial_sum[i-1]+only_positive[i-1] for i in range(0,n): same[a[i]].append(i) best ...
18
154
0
6763206
n, t = int(input()), list(map(int, input().split())) a, b = {}, {} for i, j in enumerate(t): if not j in a: a[j] = i else: b[j] = i p = [(a[j], b[j] - 1) for j in b] s = [j if j > 0 else 0 for j in t] u = v = 2 * t[p[0][0]] - 1 for i in range(n - 1): s[i + 1] += s[i] for i, j in p: u = 2 * t[i] + s[j] - s[i...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
66/B
66
B
Python 3
TESTS
60
154
307,200
110979700
def up(hs, i): while i < len(hs) - 1 and hs[i] <= hs[i+1]: i += 1 return i def down(hs, i): while i < len(hs) - 1 and hs[i] > hs[i+1]: i += 1 return i def solve(hs): if len(hs) == 1: print(1) else: length = -1 index = 0 while index < len(hs)-1: ...
80
92
0
154778493
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase import math import bisect from math import gcd, floor, sqrt, log from bisect import bisect_left as bl, bisect_right as br sys.setrecursionlimit(100000000) inp = lambda: int(input()) strng = lambda: input() jn = lambda x, l: x.join(map(str, l))...
Codeforces Beta Round 61 (Div. 2)
CF
2,011
2
256
Petya and Countryside
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed h...
The first line contains a positive integer n (1 ≤ n ≤ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
null
null
[{"input": "1\n2", "output": "1"}, {"input": "5\n1 2 1 2 1", "output": "3"}, {"input": "8\n1 2 1 1 1 3 3 4", "output": "6"}]
1,100
["brute force", "implementation"]
80
[{"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "8\r\n1 2 1 1 1 3 3 4\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "10\r\n"}, {"input": "10\r\n10 9 8 7 6 5 4 3 2 1\r\n", "output": "10\r\n"}, {"input": "2\r\n100 100\r\n", "outp...
false
stdio
null
true
977/F
977
F
PyPy 3-64
TESTS
4
62
16,384,000
224707501
# https://codeforces.com/problemset/problem/977/F n = int(input()) splits = input().split() nums = [int(splits[i]) for i in range(n)] dp = {} """ dp = { 4: (5, 2) length, index of self } """ longest = -1 for i, n in enumerate(nums): if n - 1 in dp: prev = dp[n - 1] length = prev[0] + 1 ...
70
405
39,628,800
232882756
n = int(input()) nums = list(map(int, input().split())) # 存储以每个数字结尾的最长连续序列长度 seq_len = {} # 构建连续序列长度的字典 for num in nums: seq_len[num] = seq_len.get(num - 1, 0) + 1 # 寻找最长序列的结束数字和长度 end, max_len = max(seq_len, key=seq_len.get), max(seq_len.values()) # 回溯找到序列索引 indices = [] while n: if nums[n - 1] == end: ...
Codeforces Round 479 (Div. 3)
ICPC
2,018
2
256
Consecutive Subsequence
You are given an integer array of length $$$n$$$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and len...
The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.
On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
null
All valid answers for the first example (as sequences of indices): - $$$[1, 3, 5, 6]$$$ - $$$[2, 3, 5, 6]$$$ All valid answers for the second example: - $$$[1, 4]$$$ - $$$[2, 5]$$$ - $$$[3, 6]$$$ All valid answers for the third example: - $$$[1]$$$ - $$$[2]$$$ - $$$[3]$$$ - $$$[4]$$$ All valid answers for the fou...
[{"input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6"}, {"input": "6\n1 3 5 2 4 6", "output": "2\n1 4"}, {"input": "4\n10 9 8 7", "output": "1\n1"}, {"input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9"}]
1,700
["dp"]
70
[{"input": "7\r\n3 3 4 7 5 6 8\r\n", "output": "4\r\n2 3 5 6 \r\n"}, {"input": "6\r\n1 3 5 2 4 6\r\n", "output": "2\r\n1 4 \r\n"}, {"input": "4\r\n10 9 8 7\r\n", "output": "1\r\n1 \r\n"}, {"input": "9\r\n6 7 8 3 4 5 9 10 11\r\n", "output": "6\r\n1 2 3 7 8 9 \r\n"}, {"input": "1\r\n1337\r\n", "output": "1\r\n1 \r\n"}, {...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input input_lines = read_file_lines(input_path) n = int(input_lines[...
true
967/B
967
B
PyPy 3
TESTS
15
187
9,113,600
78524614
import math n, a, b = map(int, input().split()) s = list(map(int, input().split())) c = 0 x = math.ceil((a * s[0]) / b) y = s[0] f = 0 su = 0 for i in s: su += i s.sort() i = n - 1 while su > x: if s[i] == y and f == 0: f = 1 i -= 1 continue su -= s[i] c += 1 i -= 1 print(c)
26
77
13,516,800
193443943
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): [n, a, b] = list(map(int, input().split())) arr = list(map(int, input().split())) s1 = arr[0] arr = sorted(arr[1:], reverse = True) sActive = s1*((a-b)/b) total = sum(arr) ans = 0 for i in range(n-1): if total...
Codeforces Round 477 (rated, Div. 2, based on VK Cup 2018 Round 3)
CF
2,018
1
256
Watering System
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $$$n$$$ flowers and so it looks like a pipe with $$$n$$$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour $$$A$$$ liters of water into the...
The first line contains three integers $$$n$$$, $$$A$$$, $$$B$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le B \le A \le 10^4$$$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s...
Print a single integer — the number of holes Arkady should block.
null
In the first example Arkady should block at least one hole. After that, $$$\frac{10 \cdot 2}{6} \approx 3.333$$$ liters of water will flow out of the first hole, and that suits Arkady. In the second example even without blocking any hole, $$$\frac{80 \cdot 3}{10} = 24$$$ liters will flow out of the first hole, that is...
[{"input": "4 10 3\n2 2 2 2", "output": "1"}, {"input": "4 80 20\n3 2 1 4", "output": "0"}, {"input": "5 10 10\n1000 1 1 1 1", "output": "4"}]
1,000
["math", "sortings"]
26
[{"input": "4 10 3\r\n2 2 2 2\r\n", "output": "1\r\n"}, {"input": "4 80 20\r\n3 2 1 4\r\n", "output": "0\r\n"}, {"input": "5 10 10\r\n1000 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "10 300 100\r\n20 1 3 10 8 5 3 6 4 3\r\n", "output": "1\r\n"}, {"input": "10 300 100\r\n20 25 68 40 60 37 44 85 23 96\r\n", "output": "8\...
false
stdio
null
true
71/A
71
A
Python 3
TESTS
4
46
0
202740786
n=int(input()) a="" z="" count=0 wordcount=0 while count<n: x=input() count+=1 if len(x)<=n: print(x) elif len(x)>n: a=x[0] z=x[-1::] for i in range(1,len(x)-1): wordcount+=1 if wordcount>8: print(a+str(wordcount)+z) a="" ...
20
31
0
183664531
x=int(input()) mywords=[] for i in range(x): myinput=input() word=list(myinput) mywords.append(word) else: for word in mywords : if len(word)>10: print(word[0],len(word)-2,word[-1],sep="") else: y="".join(word) print(y)
Codeforces Beta Round 65 (Div. 2)
CF
2,011
1
256
Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
null
null
[{"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s"}]
800
["strings"]
20
[{"input": "4\r\nword\r\nlocalization\r\ninternationalization\r\npneumonoultramicroscopicsilicovolcanoconiosis\r\n", "output": "word\r\nl10n\r\ni18n\r\np43s\r\n"}, {"input": "5\r\nabcdefgh\r\nabcdefghi\r\nabcdefghij\r\nabcdefghijk\r\nabcdefghijklm\r\n", "output": "abcdefgh\r\nabcdefghi\r\nabcdefghij\r\na9k\r\na11m\r\n"...
false
stdio
null
true
776/A
776
A
PyPy 3-64
TESTS
4
77
3,072,000
206252161
ans = [] fn = input() ans.append(fn) for i in range(int(input())): fn += " " kd,new = input().split(" ") fn = fn.replace(kd+" ",new+" ") ans.append(fn) fn = fn[:-1] for i in ans: print(i)
57
46
0
145987507
v = input().split() print(*v) for _ in range(0, int(input())): i = input().split() if v[0] == i[0]: v[0] = i[1] else: v[1] = i[1] print(*v)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
235/B
235
B
PyPy 3-64
TESTS
9
122
2,355,200
148672000
n = int(input()) l = list(map(float,input().split())) a = 0 for i in range(1<<n): s = bin(i)[2:] t = 0 ans = 0 p = 1 s = '0'*(n-len(s)) + s for j in range(len(s)): if s[j]=='1': p*=l[j] t+=1 else: p*=(1-l[j]) ans+=(t**2) t = 0 ans+=(t**2) a += p*ans print(round(a,5))
72
154
11,468,800
206186698
n,a,b=int(input()),0,0 for i in map(float,input().split()):a,b=a+i*(1+b*2),i*(b+1) print(a)
Codeforces Round 146 (Div. 1)
CF
2,012
2
256
Let's Play Osu!
You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of n characters "O" and "X". Using the play sequence you can calculate the...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of clicks. The second line contains n space-separated real numbers p1, p2, ..., pn (0 ≤ pi ≤ 1). There will be at most six digits after the decimal point in the given pi.
Print a single real number — the expected score for your play. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
null
For the first example. There are 8 possible outcomes. Each has a probability of 0.125. - "OOO"  →  32 = 9; - "OOX"  →  22 = 4; - "OXO"  →  12 + 12 = 2; - "OXX"  →  12 = 1; - "XOO"  →  22 = 4; - "XOX"  →  12 = 1; - "XXO"  →  12 = 1; - "XXX"  →  0. So the expected score is $${ \frac { 9 + 4 + 2 + 1 + 4 + 1 + 1 } { 8 } ...
[{"input": "3\n0.5 0.5 0.5", "output": "2.750000000000000"}, {"input": "4\n0.7 0.2 0.1 0.9", "output": "2.489200000000000"}, {"input": "5\n1 1 1 1 1", "output": "25.000000000000000"}]
2,000
["dp", "math", "probabilities"]
72
[{"input": "3\r\n0.5 0.5 0.5\r\n", "output": "2.750000000000000\r\n"}, {"input": "4\r\n0.7 0.2 0.1 0.9\r\n", "output": "2.489200000000000\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "25.000000000000000\r\n"}, {"input": "10\r\n0.684846 0.156794 0.153696 0.714526 0.281868 0.628256 0.745339 0.123854 0.748936 0.856333...
false
stdio
import sys def read_number(filepath): with open(filepath, 'r') as f: lines = f.readlines() for line in lines: stripped = line.strip() if stripped: return float(stripped) return 0.0 def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_pat...
true
66/B
66
B
PyPy 3
TESTS
57
154
0
144020468
n = int(input()) heights = [int(i) for i in input().split()] local = [] p1 = 0 p2 = 0 p3 = 0 for i in range(n): if p1 + 1 < n and heights[p1] > heights[p1 + 1]: p1 += 1 if p2 + 1 < n and heights[p2] <= heights[p2 + 1]: p2 += 1 p3 += 1 elif p3 + 1 < n and heights[p3] >= heights[p3 +...
80
92
0
154981545
# 1 2 1 1 1 3 3 4 # is index i greater than or equal to the one in its RHS? # if yes add 1 to the arr1[i+1] .. which is the sum of the RHS element # arr1 =[0,3,2,1,0,1,0,0] # is index i greater than equal or to the one in its RHS? # if yes add 1 to the arr1[i-1] .. which is the sum of the RHS element # arr2 =[0,1,0,...
Codeforces Beta Round 61 (Div. 2)
CF
2,011
2
256
Petya and Countryside
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed h...
The first line contains a positive integer n (1 ≤ n ≤ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
null
null
[{"input": "1\n2", "output": "1"}, {"input": "5\n1 2 1 2 1", "output": "3"}, {"input": "8\n1 2 1 1 1 3 3 4", "output": "6"}]
1,100
["brute force", "implementation"]
80
[{"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "8\r\n1 2 1 1 1 3 3 4\r\n", "output": "6\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "10\r\n"}, {"input": "10\r\n10 9 8 7 6 5 4 3 2 1\r\n", "output": "10\r\n"}, {"input": "2\r\n100 100\r\n", "outp...
false
stdio
null
true