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
772/A
772
A
Python 3
TESTS
70
1,871
9,011,200
227759463
def main(): num_items, budget = map(int, input().split()) production_cost = [0] * 100100 selling_price = [0] * 100100 for i in range(num_items): production_cost[i], selling_price[i] = map(int, input().split()) total_production_cost = sum(production_cost[:num_items]) if total_productio...
94
374
19,660,800
226646709
n, p = map(int, input().split()) s = [0] * n x, y = -p, 0 for i in range(n): a, b = map(int, input().split()) x = x + a y = y + b s[i] = (a,b) s.sort(key = lambda q: q[0] / q[1]) for a,b in s: if b * x > a * y : x = x - a ...
VK Cup 2017 - Round 2
CF
2,017
2
256
Voltage Keepsake
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a si...
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the d...
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker pr...
null
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to char...
[{"input": "2 1\n2 2\n2 1000", "output": "2.0000000000"}, {"input": "1 100\n1 1", "output": "-1"}, {"input": "3 5\n4 3\n5 2\n6 1", "output": "0.5000000000"}]
1,800
["binary search", "math"]
94
[{"input": "2 1\r\n2 2\r\n2 1000\r\n", "output": "2.0000000000"}, {"input": "1 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "3 5\r\n4 3\r\n5 2\r\n6 1\r\n", "output": "0.5000000000"}, {"input": "1 1\r\n1 87\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n100 77\r\n", "output": "0.7777777778"}, {"input": "5 10\r\n3 81\r\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.read().strip() with open(submission_path, 'r') as f: sub_line = f.read().strip() if ref_line == '-1': if sub_line == '...
true
445/B
445
B
PyPy 3-64
TESTS
4
62
0
165975368
import sys input = sys.stdin.readline from collections import Counter def find(x): if x != d[x]: d[x] = find(d[x]) return d[x] def union(x, y): d[find(x)] = find(y) n, m = map(int, input().split()) d = list(range(n+1)) g = [] for i in range(m): a, b = map(int, input().split()) union(a, b...
32
46
0
149935373
class Graph: def __init__(self, V): self.V = V self.adj = [[] for _ in range(V)] def DFSUtil(self, temp, v, visited): visited[v] = True temp.append(v) for i in self.adj[v]: if not visited[i]: temp = self.DFSUtil(temp, i, visited) re...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
445/B
445
B
PyPy 3-64
TESTS
4
61
0
188380994
def dfs(visited, graph, node, paths): if node not in visited: paths.append(node) visited.add(node) for neighbour in graph[node]: dfs(visited, graph, neighbour, paths) return paths n, m = map(int, input().split()) graph = dict() for i in range(1, n + 1): graph[i] = [] ...
32
46
0
172017676
def dfs(node): global ans visited.add(node) for child in nodes[node]: if child not in visited: ans*=2 dfs(child) n,m=map(int,input().split()) ; ans=1 ; nodes=dict() ; visited=set() for i in range(m): x,y=map(int,input().split()) if x not in nodes.keys(): ...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
445/B
445
B
Python 3
TESTS
4
31
0
165608566
n,m = map(int,input().split()) s = {0} for i in range (m): l=[] l = list(map(int,input().split())) s.update(l) if (m==0): print (1) else: print (2**(len(s)-2))
32
46
0
172881670
def dfs(n): global ans if n!= x : ans *= 2 if not v[n]: v[n] = 1 for i in g[n]: if not v[i] : dfs(i) n, m = map(int,input().split()); g=[[] for x in range(n+1)]; v=[0]*(n+1); ans = 1 for x in range(m) : a,b = map(int,input().split()); g[a].append(b); g[b].append(a) for x i...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
445/B
445
B
PyPy 3-64
TESTS
4
46
0
175817738
n, m = map(int, input().split()) rank = [0 for _ in range(n)] parent = [i for i in range(n)] if m == 0: print(1) exit() def find_set(u): if parent[u] != u: parent[u] = find_set(parent[u]) return parent[u] def union(u, v): up = find_set(u) vp = find_set(v) if up == vp: ret...
32
46
0
175456738
globals_v = { "ans" : 1 , "vis" : [] } x = [] def DFS(num1 , num2) : if num1 != num2 : globals_v['ans'] *=2 globals_v['vis'].append(num1) for i in range(0 , len(x[num1])) : lol = x[num1][i] if not lol in globals_v['vis'] : DFS(lol , num2) numbers = list(map(int , ...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
445/B
445
B
PyPy 3-64
TESTS
4
46
0
178150217
n,m=map(int,input().split()) # s=(input()) # s,t=input().split() # arr=list(map(int,input().split())) # for _ in range(int(input())): # n=int(input()) res=[1];arr=[] for i in range(m): x,y=map(int,input().split()) arr.append([x,y]) arr=sorted(arr,key=lambda x:x[0]+x[1]) # if m==1:print(2);exit() for i in ...
32
46
0
184464839
MAX_N = 52 root = [0 for _ in range(MAX_N)] n = 0 m = 0 res = 1 def findRoot(u): if root[u] == u: return u else: root[u] = findRoot(root[u]) return root[u] def unionSet(u, v): global res rootu = findRoot(u) rootv = findRoot(v) if rootu != rootv: re...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
445/B
445
B
PyPy 3-64
TESTS
4
46
0
188312657
n,m = map(int,input().split()) pa = {x:x for x in range(1,n+1)} size = {x:1 for x in range(1,n+1)} def find(a): if pa[a] != a: pa[a] = find(pa[a]) return pa[a] def union(a,b): a,b = find(a),find(b) if a != b: if size[a] >= size[b]: pa[b] = pa[a] size[a] += size[b]...
32
46
0
194253837
def find(x): i = prt[x] while i != prt[i]: i = prt[i] return i n, m = map(int, input().split()) prt = [i for i in range(n + 1)] res = 0 for i in range(m): x, y = map(int, input().split()) x1 = find(y) y1 = find(x) if x1 != y1: prt[x1] = y1 res += 1 print(2 ** res...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
333/B
333
B
PyPy 3
TESTS
1
156
23,040,000
25203828
n, m = map(int, input().split()) ans = 0 row = [1] * n col = [1] * n for x in range(m): a, b = map(int, input().split()) row[a - 1] = 0 col[b - 1] = 0 for i in range(1, (n + 1) // 2): j = n - 1 - i if i == j: ans += row[i] + col[i] else: ans += row[i] + row[j] + col[i] + col[j] print (ans)
20
654
102,400
12992504
# Not Original Submission, Unable to solve the problem 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
792/B
792
B
Python 3
TESTS
5
46
4,608,000
25896714
n, k = map(int, input().split(' ')) a = [int(x) for x in input().split(' ')] kids = [x for x in range(1, n + 1)] player = 1 kicked = [] for i in range(k): index = kids.index(player) if index + a[i] >= len(kids) - 1: index = (index + a[i]) % len(kids) else: index = a[i] - 1 if index + 1 == len(kids): player =...
22
46
0
147576411
n,k=map(int,input().split()) arr=list(map(int,input().split())) start=0 l=list(range(1,n+1)) res=[] for i in range(k): el=arr[i] el%=len(l) ind=(start+el)%len(l) start=(ind)%(len(l)-1) res.append(l.pop(ind)) print(*res)
Educational Codeforces Round 18
ICPC
2,017
1
256
Counting-out Rhyme
n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one ...
The first line contains two integer numbers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≤ ai ≤ 109).
Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.
null
Let's consider first example: - In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader. - I...
[{"input": "7 5\n10 4 11 4 1", "output": "4 2 5 6 1"}, {"input": "3 2\n2 5", "output": "3 2"}]
1,300
["implementation"]
22
[{"input": "7 5\r\n10 4 11 4 1\r\n", "output": "4 2 5 6 1 \r\n"}, {"input": "3 2\r\n2 5\r\n", "output": "3 2 \r\n"}, {"input": "2 1\r\n1\r\n", "output": "2 \r\n"}, {"input": "2 1\r\n2\r\n", "output": "1 \r\n"}, {"input": "2 1\r\n3\r\n", "output": "2 \r\n"}, {"input": "10 7\r\n5 10 4 3 8 10 6\r\n", "output": "6 8 3 9 2 ...
false
stdio
null
true
445/B
445
B
PyPy 3-64
TESTS
4
61
0
191287560
def dfs(A, s, parent=None, order=None): if parent is None: parent =[None for v in A] parent[s] = s order = [] for v in A[s]: if parent[v] == None: parent[v] = s dfs(A, v, parent, order) order.append(s) return parent, order def main(): n, m = l...
32
46
0
205263301
def dfs(x, y): if visited[x]: return y visited[x] = 1 for i in g[x]: if not visited[i]: y = dfs(i, y+1) return y n, m = map(int, input().split()) ans = 1 g = {} visited = [0 for i in range(n+1)] for _ in range(m): a, b = map(int, input().split()) try: g[a]...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours...
The first line contains two space-separated integers n and m $$( 1 \leq n \leq 50 ; \; 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$. Each of the next m lines contains two space-separated integers xi and yi (1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemic...
Print a single integer — the maximum possible danger.
null
In the first sample, there's only one way to pour, and the danger won't increase. In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that...
[{"input": "1 0", "output": "1"}, {"input": "2 1\n1 2", "output": "2"}, {"input": "3 2\n1 2\n2 3", "output": "4"}]
1,400
["dfs and similar", "dsu", "greedy"]
32
[{"input": "1 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 8\r\n4 10\r\n4 6\r\n5 10\r\n2 3\r\n1 7\r\n3 4\r\n3 6\r\n6 9\r\n3 7\r\n", "output": "512\r\n"}, {"input": "20 20\r\n6 8\r\n13 20\r\n7 13\r\n6 17\r\n5 15\r...
false
stdio
null
true
70/B
70
B
Python 3
TESTS
10
46
0
178776697
nums = int(input()) texts = input() parts = [] subs = '' for i in range(len(texts)): if texts[i] not in ['.','?','!']: subs += texts[i] elif texts[i] in ['.','?','!']: subs += texts[i] parts.append(subs) subs = '' flag = True for part in parts: part = part.strip() if len...
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
467/A
467
A
PyPy 3-64
TESTS
6
46
0
213727182
a = int(input()) answer = 0 for i in range(a): b, c = input().split() if (int(c) - int(b)) > 2: answer += 1 print(answer)
27
31
0
212875429
t=int(input()) count=0 while t>0: p,q=map(int,input().split()) if q-p>=2: count+=1 t-=1 print(count)
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
George and Accommodation
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living ...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms. The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
null
null
[{"input": "3\n1 1\n2 2\n3 3", "output": "0"}, {"input": "3\n1 10\n0 10\n10 10", "output": "2"}]
800
["implementation"]
27
[{"input": "3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n1 10\r\n0 10\r\n10 10\r\n", "output": "2\r\n"}, {"input": "2\r\n36 67\r\n61 69\r\n", "output": "2\r\n"}, {"input": "3\r\n21 71\r\n10 88\r\n43 62\r\n", "output": "3\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "0\r\n"}, {"input": "1...
false
stdio
null
true
63/A
63
A
PyPy 3
TESTS
7
216
20,172,800
129015950
a = int(input()) ck = [] cntrat = 0 cntwmn = 0 cntman = 0 cntcap = 0 for i in range (a): s = input().split() if s[1] == 'rat': cntrat += 1 ck.append('a'+str(cntrat)+s[0]) elif s[1] == 'child' or s[1] == 'woman': cntwmn += 1 ck.append('b'+str(cntwmn)+s[0]) elif s[1] == 'ma...
26
62
0
147196918
t=int(input()) r=[] wc=[] m=[] c=[] for i in range(t): x=list(map(str,input().split())) if x[1]=='rat': r.append(x[0]) elif x[1]=='woman' or x[1]=='child': wc.append(x[0]) elif x[1]=='man': m.append(x[0]) else: c.append(x[0]) l=[] l.extend(r) l.extend(wc) l.extend(m) ...
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
467/A
467
A
Python 3
TESTS
6
46
0
214334321
a = int(input()) c = 0 for i in range(a): b = input().split(" ") b_0 = int(b[0]) b_1 = int(b[1]) if b_1 - b_0 < 3: c += 0 else: c += 1 print(c)
27
31
0
212999310
n = int(input()) Cnt= 0 for i in range(n): #0 ~ 2 input 3 rooms p, q =input().split() p = int(p) q = int(q) if(q-p) >= 2: Cnt += 1 print (Cnt) #khattab
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
George and Accommodation
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living ...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms. The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
null
null
[{"input": "3\n1 1\n2 2\n3 3", "output": "0"}, {"input": "3\n1 10\n0 10\n10 10", "output": "2"}]
800
["implementation"]
27
[{"input": "3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n1 10\r\n0 10\r\n10 10\r\n", "output": "2\r\n"}, {"input": "2\r\n36 67\r\n61 69\r\n", "output": "2\r\n"}, {"input": "3\r\n21 71\r\n10 88\r\n43 62\r\n", "output": "3\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "0\r\n"}, {"input": "1...
false
stdio
null
true
793/B
793
B
PyPy 3
TESTS
14
2,822
131,584,000
30191185
import sys from collections import deque def is_valid(cid, n, m): return 0 <= cid < n * m def get_neighbors(cid, dir, n, m): update = [1, m, -1, -m] neighbors = [] for j in [0, -1, 1, 2]: cost = 1 if j != 0 else 0 d = (dir + j + 4) % 4 nid = cid + update[dir] if is_va...
66
202
1,638,400
26948817
def sol(): nums=(input()).split(' ') n=int(nums[0]) m=int(nums[1]) mat=['' for _ in range(n)] for i in range(n): mat[i]=input() if 'S' in mat[i]: home=[i,mat[i].find('S')] if 'T' in mat[i]: office=[i,mat[i].find('T')] dr=[[1,0],[-1,0],[0,1],[0,-1],...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
793/B
793
B
Python 3
TESTS
40
1,575
36,966,400
189458454
Input = list(map(int, input().split())) m, n = Input[0], Input[1] grid = [] for i in range(m): row = list(input()) grid.append(row) for i in range(m): for j in range(n): if grid[i][j] == "S": home = [i,j] if grid[i][j] == "T": rest = [i,j] def h_traverse(cell): ...
66
342
24,371,200
189428897
from itertools import product def paint_cross(s_row, s_col, char, grid, n): # down for i in range(s_row + 1, n): if grid[i][s_col] == ".": grid[i][s_col] = char else: break # up for i in range(s_row - 1, -1, -1): if grid[i][s_col] == ".": gri...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
793/B
793
B
Python 3
PRETESTS
8
811
6,144,000
26619459
s = input().split() n, m = int(s[0]), int(s[1]) M = [] for i in range(n): M.append(input()) for j in range(m): if M[i][j] == 'S': st = (i, j) elif M[i][j] == 'T': en = (i, j) found = 0 for i in range(m): bad = 0 v1 = (st[0], i) v2 = (en[0], i) diff = 1 i...
66
358
24,473,600
189475652
from collections import defaultdict, deque, Counter from functools import lru_cache from heapq import heappush, heappop from bisect import bisect_right, bisect_left def inpNum(): return int(input()) def inpStr(): return input() def inpSepNum(): return map(int, input().split()) def inpNumList(): return ...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
793/B
793
B
PyPy 3
TESTS
14
2,994
132,505,600
30191073
import sys from collections import deque def valid(i, n, m): if 0 <= i < n * m: return i else: return -1 def get_neighbors(cid, dir, n, m): neighbors = [] for j in [0, -1, 1]: cost = 1 if j !=0 else 0 d = (dir + j + 4) % 4 if d == 0: nid = valid(ci...
66
405
40,652,800
26619478
#!/usr/bin/env python3 # 793B_way.py - Codeforces.com/problemset/problem/793/B by Sergey 2017 import unittest import sys ############################################################################### # Way Class (Main Program) ############################################################################### class Wa...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
555/A
555
A
Python 3
TESTS
12
61
307,200
15963628
n, k = map(int, input().split()) l = 1 for j in range(k): a = list(map(int, input().split())) m = a[0] a = a[1:] i = 0 while i < m-1: if a[i+1]-a[i] == 1 and a[0] == 1: l += 1 i += 1 s = n-k-l+1 j = n-l # print(s, j) print(s + j)
47
218
8,192,000
12112495
n, k = map(int, input().split(' ')) for i in range(k): x = input().split(' ') if x[1] == '1': y = [int(j) for j in x[1:]] + [0] z = 0 while y[z+1] == z+2: z += 1 print(2*n-k-1-2*z)
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
793/B
793
B
PyPy 3
TESTS
23
405
48,332,800
26649522
n, m = map(int, input().split()) cells = [list(input()) for _ in range(n)] ans = 'NO' for r in range(n): for c in range(m): if cells[r][c] == "S": sr, sc = r, c elif cells[r][c] == "T": tr, tc = r, c for cc in range(m): if ans == 'YES': break f = True for...
66
420
25,600,000
73919956
n, m = map(int, input().split()) a = [] x, y = 0, 0 def f(c, x, y): for i in range(x + 1, n): if a[i][y] == 'T': print('YES') exit() if a[i][y] == '.': a[i][y] = c elif a[i][y] != c: break for i in range(x - 1, -1, -1): if a[i][y]...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
523/A
523
A
Python 3
PRETESTS
0
46
0
10275026
def rotate(p, w, h): rot = [[] for i in range(w)] print() for i in range(w): for j in range(h): rot[i].append(p[j][i]) rot[i] = list(reversed(rot[i])) return rot def double(): global mas, r p = 0 for i in range(h): s = '' for j in r[i]: ...
24
46
0
10274051
def main(): w, h = map(int, input().split()) a = [input() for i in range(h)] for i in range(w): b = [a[j][i]*2 for j in range(h)] s = ''.join(b) print(s) print(s) if __name__ == '__main__': main()
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
38/A
38
A
Python 3
TESTS
5
124
4,608,000
16853049
n = int(input()) d = list(map(int, input().split())) a, b = map(int, input().split()) count = 0 for i in range(a, b): count += d[a - 1] a -= 1 print(count)
50
92
0
137050345
n = int(input()) di = input().split() for i in range(0, n - 1): di[i] = int(di[i]) a, b = input().split() a, b = int(a), int(b) sum = 0 for i in range(a, b): sum += di[i-1] print(sum)
School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules)
ICPC
2,010
2
256
Army
The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank. One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible. Vasya ha...
The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.
null
null
[{"input": "3\n5 6\n1 2", "output": "5"}, {"input": "3\n5 6\n1 3", "output": "11"}]
800
["implementation"]
50
[{"input": "3\r\n5 6\r\n1 2\r\n", "output": "5\r\n"}, {"input": "3\r\n5 6\r\n1 3\r\n", "output": "11\r\n"}, {"input": "2\r\n55\r\n1 2\r\n", "output": "55\r\n"}, {"input": "3\r\n85 78\r\n1 3\r\n", "output": "163\r\n"}, {"input": "4\r\n63 4 49\r\n2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n93 83 42 56\r\n2 5\r\n", "out...
false
stdio
null
true
22/B
22
B
Python 3
TESTS
4
124
5,632,000
36225637
m,n=input().split() m = int(m) n = int(n) lis = [] maxx = 0 sat = 0 sot = 0 for i in range(m): lis.append(input()) for i in range(m): for j in range(n): sat = sot = 0 if lis[i][j] == '0': sat = 1 sot = 1 ma = 0 q = 0 #stoni ...
23
154
0
203540845
def main(): n, m = map(int, input().split()) prev_row = [0 for _ in range(m)] max_perimeter = 4 for _ in range(n): current = input() current_row = [] for j in range(m): if current[j] == '1': current_row.append(0) else: curre...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Bargaining Table
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.
Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.
null
null
[{"input": "3 3\n000\n010\n000", "output": "8"}, {"input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16"}]
1,500
["brute force", "dp"]
23
[{"input": "3 3\r\n000\r\n010\r\n000\r\n", "output": "8\r\n"}, {"input": "5 4\r\n1100\r\n0000\r\n0000\r\n0000\r\n0000\r\n", "output": "16\r\n"}, {"input": "3 3\r\n000\r\n110\r\n000\r\n", "output": "8\r\n"}, {"input": "4 2\r\n00\r\n10\r\n11\r\n00\r\n", "output": "6\r\n"}, {"input": "3 5\r\n00001\r\n00000\r\n10100\r\n", ...
false
stdio
null
true
70/B
70
B
Python 3
TESTS
10
124
0
5316916
n = int(input()) p, s, j = 0, 1, -1 for i, c in enumerate(input()): if c in '.?!': d = i - j if d - 1 > n: s = 0 break if p + d > n: s += 1 p = 0 p += d j = i print(s if s else 'Impossible')
48
62
0
14109633
# /******************************************************************************* # * Author : Quantum Of Excellence # * email : quantumofexcellence (at) gmail (dot) com # * copyright : 2014 - 2015 # * date : 6 - 11 - 2015 # * Judge Status : # * Problem Category : # * file name : 70B.py # ...
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
22/B
22
B
PyPy 3
TESTS
8
310
0
83607384
n,m=map(int,input().split()) l=[] for i in range(n): l.append(list(map(int,input()))) l1=[[] for i in range(n)] for i in range(n): for j in range(m): if l[i][j]==1: l1[i].append(j) ans=4 for p in range(n): for q in range(m): if l[p][q]==0: y=n x=m ...
23
154
1,740,800
145960939
import sys input = sys.stdin.readline n, m = map(int, input().split()) dp = [[0] * (m + 1)] for i in range(1, n + 1): s = list(input().rstrip()) dp0 = [0] * (m + 1) for j in range(m): if s[j] == "1": dp0[j + 1] = 1 for j in range(1, m + 1): dp0[j] += dp0[j - 1] dp.append...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Bargaining Table
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.
Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.
null
null
[{"input": "3 3\n000\n010\n000", "output": "8"}, {"input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16"}]
1,500
["brute force", "dp"]
23
[{"input": "3 3\r\n000\r\n010\r\n000\r\n", "output": "8\r\n"}, {"input": "5 4\r\n1100\r\n0000\r\n0000\r\n0000\r\n0000\r\n", "output": "16\r\n"}, {"input": "3 3\r\n000\r\n110\r\n000\r\n", "output": "8\r\n"}, {"input": "4 2\r\n00\r\n10\r\n11\r\n00\r\n", "output": "6\r\n"}, {"input": "3 5\r\n00001\r\n00000\r\n10100\r\n", ...
false
stdio
null
true
523/A
523
A
Python 3
TESTS
0
108
6,656,000
80192034
m,n=map(int,input().split(' ')) lis=[] for x in range(n): str1=input() lis.append(str1) for x in range(2*m): for y in range(2*n): print(lis[y//2][x//2],end='') print('\n')
24
46
0
10274368
n,m = map(int,input().split(' ')) a = [ '' for i in range(m)] for i in range(m) : a[i] = input() def printImage(table) : for s in table : ans = '' for c in s : ans+=c*2 print(ans) print(ans...
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
864/E
864
E
Python 3
TESTS
2
31
102,400
212223613
n=int(input().strip()) q=[] for i in range(n): a=list(map(int,input().strip().split())) e={'timeOfDeath':a[1],'timeRescue':a[0],'price':a[2], 'number':i+1} q.append(e) q.sort(key=lambda x:x['timeOfDeath']) dp=[0 for i in range(q[-1]['timeOfDeath']+1)] used=[[0 for j in range(n)] for i in range(len(dp))] for...
60
140
15,564,800
193519449
n=int(input()) arr=[] for i in range(n): t,d,p=map(int,input().split()) arr.append([t,d,p,i+1]) arr.sort(key=lambda x:(x[1])) dp=[0 for _ in range(2002)] ans=[[] for j in range(2002)] for item in arr: t,d,p,ind =item for i in reversed(range(t,d)): if dp[i]<=dp[i-t]+p: dp[i]=dp[i-t]+p...
Codeforces Round 436 (Div. 2)
CF
2,017
2
256
Fire
Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuab...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house. Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of ite...
In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which t...
null
In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the save...
[{"input": "3\n3 7 4\n2 6 5\n3 7 6", "output": "11\n2\n2 3"}, {"input": "2\n5 6 1\n3 3 5", "output": "1\n1\n1"}]
2,000
["dp", "sortings"]
60
[{"input": "3\r\n3 7 4\r\n2 6 5\r\n3 7 6\r\n", "output": "11\r\n2\r\n2 3 \r\n"}, {"input": "2\r\n5 6 1\r\n3 3 5\r\n", "output": "1\r\n1\r\n1 \r\n"}, {"input": "9\r\n13 18 14\r\n8 59 20\r\n9 51 2\r\n18 32 15\r\n1 70 18\r\n14 81 14\r\n10 88 16\r\n18 52 3\r\n1 50 6\r\n", "output": "106\r\n8\r\n1 4 9 8 2 5 6 7 \r\n"}, {"in...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: n = int(f.readline().strip()) items = [] for _ in range(n): ti, di, pi = map(int, f.readline().strip().split()) ...
true
990/C
990
C
Python 3
TESTS
11
794
204,800
39115342
n=int(input()) a=[] from collections import defaultdict start=[] end=[] v=[] d=defaultdict(int) for i in range(n): s=input() count=0 valid=0 for i in s: if i=='(': count+=1 else: count-=1 if count<0: valid=-1 # return False if ...
30
264
14,233,600
112977893
import sys import io, os input = sys.stdin.readline n = int(input()) S = [str(input().rstrip()) for i in range(n)] from collections import defaultdict d1 = defaultdict(lambda: 0) d2 = defaultdict(lambda: 0) ans = 0 for i, s in enumerate(S): cum1 = 0 flag1 = True for c in s: if c == '(': ...
Educational Codeforces Round 45 (Rated for Div. 2)
ICPC
2,018
2
256
Bracket Sequences Concatenation Problem
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
null
In the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$. In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
[{"input": "3\n)\n()\n(", "output": "2"}, {"input": "2\n()\n()", "output": "4"}]
1,500
["implementation"]
30
[{"input": "3\r\n)\r\n()\r\n(\r\n", "output": "2\r\n"}, {"input": "2\r\n()\r\n()\r\n", "output": "4\r\n"}, {"input": "7\r\n()(\r\n)\r\n)(\r\n())\r\n(((\r\n()()()\r\n()\r\n", "output": "6\r\n"}, {"input": "6\r\n(\r\n((\r\n(((\r\n))))\r\n)))))\r\n))))))\r\n", "output": "0\r\n"}, {"input": "9\r\n(()\r\n((())\r\n(\r\n)\r\n...
false
stdio
null
true
990/C
990
C
Python 3
TESTS
11
701
7,065,600
42019067
def get_brackets(options): positive = [] negative = {} readyCount = 0 for word in options: canBeFirst = True balance = 0 for letter in word: if letter == '(': balance -= 1 else: balance += 1 if balance > 0: ...
30
265
12,390,400
39095496
from collections import defaultdict import sys ss = [] for _ in range(int(sys.stdin.readline())): ss.append(sys.stdin.readline().strip()) lmap, rmap = defaultdict(int), defaultdict(int) for s in ss: stack = [] good = True for x in s: if x == '(': stack.append(x) else: ...
Educational Codeforces Round 45 (Rated for Div. 2)
ICPC
2,018
2
256
Bracket Sequences Concatenation Problem
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
null
In the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$. In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
[{"input": "3\n)\n()\n(", "output": "2"}, {"input": "2\n()\n()", "output": "4"}]
1,500
["implementation"]
30
[{"input": "3\r\n)\r\n()\r\n(\r\n", "output": "2\r\n"}, {"input": "2\r\n()\r\n()\r\n", "output": "4\r\n"}, {"input": "7\r\n()(\r\n)\r\n)(\r\n())\r\n(((\r\n()()()\r\n()\r\n", "output": "6\r\n"}, {"input": "6\r\n(\r\n((\r\n(((\r\n))))\r\n)))))\r\n))))))\r\n", "output": "0\r\n"}, {"input": "9\r\n(()\r\n((())\r\n(\r\n)\r\n...
false
stdio
null
true
154/A
154
A
Python 3
TESTS
5
216
307,200
90466093
s=input() n=len(s) k=int(input()) l=[] for i in range(k): l.append(input()) ans=0 i=1 j=0 while i<n: if i+1<n: f=0 for x in range(k): if s[j]+s[i]==l[x][0]+l[x][1] or s[j]+s[i]==l[x][1]+l[x][0]: if i+1<n: if s[i+1]==s[i] or s[i...
42
186
3,891,200
154905969
s = input() n = int(input()) ans = 0 for i in range(n): t = input() j = 0 a,b = 0,0 while(j<len(s)): if(t[0]==s[j]): a+=1 elif(t[1]==s[j]): b+=1 else: ans+=min(a,b) a,b=0,0 j+=1 ans+=min(a,b) print(ans)
Codeforces Round 109 (Div. 1)
CF
2,012
2
256
Hometask
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105. The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters. Next k lines contain descriptions of forbi...
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
null
In the first sample you should remove two letters b. In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
[{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}]
1,600
["greedy"]
42
[{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input...
false
stdio
null
true
793/B
793
B
Python 3
TESTS
8
311
7,065,600
33412527
n,k=map(int,input().split()) r=[] s=[] for i in range(n): a=input() r.append(a) for j in range(k): if a[j]=='S': rs=i cs=j elif a[j]=='T': rt=i ct=j r1s=rs temp=cs while temp+1<k and r[r1s][temp+1]!='*': temp+=1 c1s=temp temp=cs while temp...
66
467
11,161,600
26620589
import sys from collections import deque def main(): n,m=map(int,sys.stdin.readline().split()) field=[] for _ in range(n): field.append(list(sys.stdin.readline().rstrip())) istart,jstart=[(i,j) for i in range(n) for j in range(m) if field[i][j]=='S'][0] iend,jend=[(i,j) for i in range(...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
708/A
708
A
Python 3
TESTS
13
77
4,915,200
20190640
import sys def shl(s, be, en): t = s[:be]; for i in range(be, en): if s[i]=='a': t += 'z' else: t += chr(ord(s[i])-1) return t+s[en:] s = input() i = 0 L = len(s) while i<L and s[i]=='a': i += 1 if i==L: print(shl(s,0,L)) sys.exit() j = i+1 while j<...
54
78
614,400
137383771
s = list(input()) end = len(s) start = 0 for i in range(end): if s[i] != 'a': break start += 1 if start == end: s[end - 1] = 'z' for i in range(start, end): if s[i] == 'a': break else: s[i] = chr(ord(s[i]) - 1) print(''.join(s))
AIM Tech Round 3 (Div. 1)
CF
2,016
1
256
Letters Cyclic Shift
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' $$\rightarrow$$ 'y' $$\rightarrow$$ 'x' $$\overrightarrow { a }, \ldots, \overrightarrow { a }$$ 'b' $$\rightarrow$$ 'a' $$\rightarrow$$ 'z'. In other words, ea...
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
null
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
[{"input": "codeforces", "output": "bncdenqbdr"}, {"input": "abacaba", "output": "aaacaba"}]
1,200
["constructive algorithms", "greedy", "implementation", "strings"]
54
[{"input": "codeforces\r\n", "output": "bncdenqbdr\r\n"}, {"input": "abacaba\r\n", "output": "aaacaba\r\n"}, {"input": "babbbabaababbaa\r\n", "output": "aabbbabaababbaa\r\n"}, {"input": "bcbacaabcababaccccaaaabacbbcbbaa\r\n", "output": "abaacaabcababaccccaaaabacbbcbbaa\r\n"}, {"input": "cabaccaacccabaacdbdcbcdbccbccbab...
false
stdio
null
true
77/A
77
A
PyPy 3
TESTS
2
278
21,913,600
86332829
from itertools import permutations n=int(input()) liking=[] l={'Anka':0, 'Chapay':1, 'Cleo':2, 'Troll':3, 'Dracul':4, 'Snowy':5, 'Hexadecimal':6} for i in range(n): a,b,c=input().split() liking.append([l[a],l[c]]) a,b,c=map(int,input().split()) e=[[5,1,1],[4,2,1],[3,3,1],[3,2,2]] mini=1000000000000 maxi=1 for i...
64
404
4,812,800
21875514
from itertools import combinations def main(): heroes = ("Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal") sympaty = [[False] * 7 for _ in range(7)] for _ in range(int(input())): a, _, b = input().split() sympaty[heroes.index(a)][heroes.index(b)] = True a, b, c = map...
Codeforces Beta Round 69 (Div. 1 Only)
CF
2,011
2
256
Heroes
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us...
The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given th...
Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team divisio...
null
A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
[{"input": "3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180", "output": "30 3"}, {"input": "2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50", "output": "1950 2"}]
1,400
["brute force", "implementation"]
64
[{"input": "3\r\nTroll likes Dracul\r\nDracul likes Anka\r\nSnowy likes Hexadecimal\r\n210 200 180\r\n", "output": "30 3\r\n"}, {"input": "2\r\nAnka likes Chapay\r\nChapay likes Anka\r\n10000 50 50\r\n", "output": "1950 2\r\n"}, {"input": "11\r\nSnowy likes Dracul\r\nAnka likes Dracul\r\nChapay likes Snowy\r\nHexadecim...
false
stdio
null
true
788/C
788
C
Python 3
TESTS
2
124
409,600
98012850
from collections import deque Max = 1000 def MainBFS(): n, k = map(int, input().split()) conc = set(int(x) for x in input().split()) visited = [False] * (2 * Max + 1) visited[0] = True Q = deque() Q.append((0, 0)) result = None while Q: u, l = Q.popl...
48
468
44,339,200
98087693
from collections import deque n, k = map(int, input().split()) d = set(int(x)-n for x in input().split()) q = deque() q.append(0) visited = {i : False for i in range(-1000, 1001)} dist = {i : 0 for i in range(-1000, 1001)} ans = -1 visited[0] = True found = False while q: u = q.popleft() fo...
Codeforces Round 407 (Div. 1)
CF
2,017
1
256
The Great Mixing
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration $${ \frac { a _ { i } } { 1 0 0 0 } }$$. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentrati...
The first line contains two integers n, k (0 ≤ n ≤ 1000, 1 ≤ k ≤ 106) — carbon dioxide concentration the friends want and the number of Coke types. The second line contains k integers a1, a2, ..., ak (0 ≤ ai ≤ 1000) — carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.
Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration $$\frac{n}{1000}$$, or -1 if it is impossible.
null
In the first sample case, we can achieve concentration $$\frac{400}{1000}$$ using one liter of Coke of types $$\frac{300}{1000}$$ and $${ \frac { 5 0 0 } { 1 0 0 0 } }$$: $$\frac{300+500}{1000+1000}=\frac{400}{1000}$$. In the second case, we can achieve concentration $${ \frac { 5 0 } { 1 0 0 0 } }$$ using two liters ...
[{"input": "400 4\n100 300 450 500", "output": "2"}, {"input": "50 2\n100 25", "output": "3"}]
2,300
["dfs and similar", "graphs", "shortest paths"]
48
[{"input": "400 4\r\n100 300 450 500\r\n", "output": "2\r\n"}, {"input": "50 2\r\n100 25\r\n", "output": "3\r\n"}, {"input": "500 3\r\n1000 5 5\r\n", "output": "199\r\n"}, {"input": "500 1\r\n1000\r\n", "output": "-1\r\n"}, {"input": "874 3\r\n873 974 875\r\n", "output": "2\r\n"}, {"input": "999 2\r\n1 1000\r\n", "outp...
false
stdio
null
true
793/B
793
B
Python 3
TESTS
40
171
7,168,000
26617825
n,m = tuple(map(int, input().split())) s = [] startX, startY, endX, endY = 0,0,0,0 for i in range(n): row = input() if 'S' in row: startY = row.index('S') startX = i if 'T' in row: endY = row.index('T') endX = i s.append(row) def validway(fromX, toX, Y): if fromX == t...
66
514
47,513,600
26792674
import sys def solve(): def run(r, c, visited): visited[r][c] = True for i in range(c + 1, m + 2): if visited[r][i] or (not ok[r][i]): break visited[r][i] = True for i in range(c - 1, -1, -1): if visited[r][i] or (not ok[r][i]): ...
Tinkoff Challenge - Elimination Round
CF
2,017
3
256
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road works; - "S" — the c...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
null
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[{"input": "5 5\n..S..\n****.\nT....\n****.\n.....", "output": "YES"}, {"input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO"}]
1,600
["dfs and similar", "graphs", "implementation", "shortest paths"]
66
[{"input": "5 5\r\n..S..\r\n****.\r\nT....\r\n****.\r\n.....\r\n", "output": "YES"}, {"input": "5 5\r\nS....\r\n****.\r\n.....\r\n.****\r\n..T..\r\n", "output": "NO"}, {"input": "1 2\r\nST\r\n", "output": "YES"}, {"input": "3 1\r\nS\r\n*\r\nT\r\n", "output": "NO"}, {"input": "3 3\r\n*..\r\n...\r\nTS.\r\n", "output": "Y...
false
stdio
null
true
711/A
711
A
Python 3
TESTS
5
46
4,608,000
134026506
#!/usr/bin/env python import math, sys, itertools if __name__ == '__main__': wtf = sys.stdin.read() B = wtf[2:] A = B.replace('OO', '++', 1) print('NO' if B == A else 'YES\n' + A)
71
46
0
143129030
n = int(input()) arr = [] for i in range(n) : arr.append(input()) def solve(n , arr) : for i in range(n) : if (arr[i][0] == arr[i][1] and arr[i][0] == 'O') : print("YES") arr[i] = '++|' + arr[i][3] + arr[i][4] for i in range(n) : print(arr[i]) ...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Bus to Udayland
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris are...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus. Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw...
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex...
null
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair. O+|+X XO|XX OX|OO XX|OX OO|OO OO|XX
[{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}]
800
["brute force", "implementation"]
71
[{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|...
false
stdio
null
true
644/B
644
B
Python 3
TESTS
31
2,027
24,576,000
16741428
from queue import * n,b = map(int,input().split()) tdi = [list(map(int,input().split())) for i in range(n)] q = Queue(b+1) end_i_process = 0 early_process = 0 for i in range(n): if q.full() == True: if tdi[i][0] >= tdi[early_process][0]: q.get() early_process += 1 else: t...
71
763
45,568,000
16757405
import sys def main(): n, b = [int(tok) for tok in sys.stdin.readline().split()] td_list = [] for i in range(n): td_list.append([int(tok) for tok in sys.stdin.readline().split()]) queue = [] finish = [-1 for i in range(n)] for i, (t, d) in enumerate(td_list): if len(queue...
CROC 2016 - Qualification
CF
2,016
5
256
Processing Queries
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment ti and needs to be processed for di units of time. All ti are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and qu...
The first line of the input contains two integers n and b (1 ≤ n, b ≤ 200 000) — the number of queries and the maximum possible size of the query queue. Then follow n lines with queries descriptions (in chronological order). Each description consists of two integers ti and di (1 ≤ ti, di ≤ 109), where ti is the moment...
Print the sequence of n integers e1, e2, ..., en, where ei is the moment the server will finish to process the i-th query (queries are numbered in the order they appear in the input) or - 1 if the corresponding query will be rejected.
null
Consider the first sample. 1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 2. At the moment 4 second query appears and proceeds to the queue. 3. At the moment 10 third query appears. However, the server is still busy with query 1, b = 1 and there is alrea...
[{"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1", "output": "11 19 -1 21 22"}, {"input": "4 1\n2 8\n4 8\n10 9\n15 2", "output": "10 18 27 -1"}]
1,700
["*special", "constructive algorithms", "data structures", "two pointers"]
71
[{"input": "5 1\r\n2 9\r\n4 8\r\n10 9\r\n15 2\r\n19 1\r\n", "output": "11 19 -1 21 22 \r\n"}, {"input": "4 1\r\n2 8\r\n4 8\r\n10 9\r\n15 2\r\n", "output": "10 18 27 -1 \r\n"}, {"input": "1 1\r\n1000000000 1000000000\r\n", "output": "2000000000 \r\n"}, {"input": "4 3\r\n999999996 1000000000\r\n999999997 1000000000\r\n99...
false
stdio
null
true
157/A
157
A
Python 3
TESTS
8
62
0
206802693
l=[] ll=[] lll=[] count=0 n=int(input()) for i in range(n): l.append(list(map(int,input().split()))) for j in range(n): ll.append(sum(l[j])) for m in range(n): lo=0 for k in range(n): lo+=l[k][m] lll.append(lo) for p in ll: for y in lll: if p>y: count+=1 print(count)
49
92
0
4614719
n = int(input()) h, v = [0] * n, [0] * n for i in range(n): t = list(map(int, input().split())) h[i] = sum(t) for j in range(n): v[j] += t[j] print(sum(v[j] > h[i] for i in range(n) for j in range(n)))
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
653/C
653
C
Python 3
TESTS
17
1,435
14,950,400
16882087
n = int(input()) t = list(map(int, input().split())) def checkeven(i): if i > 0: if t[i] <= t[i-1]: return False if i < n-1: if t[i] <= t[i+1]: return False return True def checkodd(i): if i > 0: if t[i] >= t[i-1]: return False if i < n-1: if t[i] >= t[i+1]: return False return True def checkswap(i, x, p)...
44
373
12,390,400
18953706
def main(): n, l = int(input()), list(map(int, input().split())) if not (n & 1): l.append(0) l.append(150001) a, b, fails, res = 0, 150001, [], 0 for i, c in enumerate(l, -1): if i & 1: if a >= b or b <= c: if len(fails) > 5: ...
IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)
CF
2,016
2
256
Bear and Up-Down
The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied: - ti < ti + 1 for each odd i < n; - ti > ti + 1 for each even i < n. For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2...
The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.
Print the number of ways to swap two elements exactly once in order to get a nice sequence.
null
In the first sample, there are two ways to get a nice sequence with one swap: 1. Swap t2 = 8 with t4 = 7. 2. Swap t1 = 2 with t5 = 7. In the second sample, there is only one way — Limak should swap t1 = 200 with t4 = 50.
[{"input": "5\n2 8 4 7 7", "output": "2"}, {"input": "4\n200 150 100 50", "output": "1"}, {"input": "10\n3 2 1 4 1 4 1 4 1 4", "output": "8"}, {"input": "9\n1 2 3 4 5 6 7 8 9", "output": "0"}]
1,900
["brute force", "implementation"]
44
[{"input": "5\r\n2 8 4 7 7\r\n", "output": "2\r\n"}, {"input": "4\r\n200 150 100 50\r\n", "output": "1\r\n"}, {"input": "10\r\n3 2 1 4 1 4 1 4 1 4\r\n", "output": "8\r\n"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 4 3\r\n", "output": "1\r\n"}, {"input": "10\r\n7 7 8 10 5 10 1 5 ...
false
stdio
null
true
868/D
868
D
Python 3
PRETESTS
8
109
7,680,000
31027323
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF()...
49
93
3,276,800
187545709
import sys readline=sys.stdin.readline N=int(readline()) se=[] SL,SR=[],[] for n in range(N): se.append([set() for k in range(11)]) S=readline().rstrip() le=len(S) for k in range(1,11): for i in range(le-k+1): se[n][k].add(S[i:i+k]) SL.append(S[:10]) SR.append(S[-10:]) Q=int...
Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
256
Huge Strings
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + i (the operations are numbered starting from 1). After each operation ...
The first line contains single integer n (1 ≤ n ≤ 100) — the number of strings. The next n lines contain strings s1, s2, ..., sn (1 ≤ |si| ≤ 100), one per line. The total length of strings is not greater than 100. The next line contains single integer m (1 ≤ m ≤ 100) — the number of operations. m lines follow, each of...
Print m lines, each should contain one integer — the answer to the question after the corresponding operation.
null
On the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1. On the secon...
[{"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4", "output": "1\n2\n0"}]
2,200
["bitmasks", "brute force", "dp", "implementation", "strings"]
49
[{"input": "5\r\n01\r\n10\r\n101\r\n11111\r\n0\r\n3\r\n1 2\r\n6 5\r\n4 4\r\n", "output": "1\r\n2\r\n0\r\n"}, {"input": "5\r\n01\r\n1\r\n0011\r\n0\r\n01\r\n6\r\n5 5\r\n3 2\r\n4 2\r\n6 7\r\n5 1\r\n9 7\r\n", "output": "1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n"}, {"input": "5\r\n111101000111100011100110000100\r\n000111001\r\n0110100...
false
stdio
null
true
719/B
719
B
Python 3
TESTS
9
140
102,400
47778620
n=int(input()) cocks=input() a,b,c,d=[0,0,0,0] for cock in range(0,n,2): if cocks[cock]!='r': a+=1 for cock in range(1,n,2): if cocks[cock]!='b': b+=1 for cock in range(0,n,2): if cocks[cock]!='b': c+=1 for cock in range(1,n,2): if cocks[cock]!='r': c+=1 print(min(max(a,b...
46
62
102,400
224140205
n=int(input()) s=input() f=s[0] of=0 sf=0 rsf=1 rof=0 for i in range(1,n): if i%2==0: if s[i]!=f: of+=1 else: rsf+=1 else: if s[i]==f: sf+=1 else: rof+=1 print(min(max(of,sf),max(rsf,rof)))
Codeforces Round 373 (Div. 2)
CF
2,016
1
256
Anatoly and Cockroaches
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectioni...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches. The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
null
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this. In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns. In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ...
[{"input": "5\nrbbrr", "output": "1"}, {"input": "5\nbbbbb", "output": "2"}, {"input": "3\nrbr", "output": "0"}]
1,400
["greedy"]
46
[{"input": "5\r\nrbbrr\r\n", "output": "1\r\n"}, {"input": "5\r\nbbbbb\r\n", "output": "2\r\n"}, {"input": "3\r\nrbr\r\n", "output": "0\r\n"}, {"input": "13\r\nrbbbrbrrbrrbb\r\n", "output": "3\r\n"}, {"input": "18\r\nrrrrrrrrrrrrrrrrrb\r\n", "output": "8\r\n"}, {"input": "100\r\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbr...
false
stdio
null
true
23/E
23
E
PyPy 3-64
TESTS
8
124
0
201444447
n = int(input()) adj = [[] for _ in range(n)] for _ in range(n-1) : u, v = map(int, input().split(' ')) u -= 1 v -= 1 adj[u].append(v) adj[v].append(u) dp = [[1, 2] for _ in range(n)] def dfs(x, p) : global dp prod = 1 deg = 0 a = [] for y in adj[x] : if y == p : ...
55
342
2,048,000
60402644
n = int(input()) adj = [[] for i in range(n+5)] aux = [[] for i in range(n+5)] f = [1 for i in range(n+5)] h = [1 for i in range(n+5)] for i in range(n-1): u, v = map(int, input().split()) adj[u].append(v) adj[v].append(u) def solve(u, p): for v in adj[u]: if v != p: solve(v, u) ...
Codeforces Beta Round 23
ICPC
2,010
2
256
Tree
Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can...
The first input line contains integer number n (1 ≤ n ≤ 700) — amount of vertices in the tree. The following n - 1 lines contain the description of the edges. Each line contains the pair of vertices' indexes, joined by an edge, ai, bi (1 ≤ ai, bi ≤ n). It's guaranteed that the graph described in the input is a tree.
Output the only number — the maximum product of sizes of the connected components, that Bob can get after deleting some of the tree's edges.
null
null
[{"input": "5\n1 2\n2 3\n3 4\n4 5", "output": "6"}, {"input": "8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8", "output": "18"}, {"input": "3\n1 2\n1 3", "output": "3"}]
2,500
["dp"]
55
[{"input": "5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n", "output": "6"}, {"input": "8\r\n1 2\r\n1 3\r\n2 4\r\n2 5\r\n3 6\r\n3 7\r\n6 8\r\n", "output": "18"}, {"input": "3\r\n1 2\r\n1 3\r\n", "output": "3"}, {"input": "5\r\n3 2\r\n1 5\r\n4 5\r\n5 3\r\n", "output": "6"}, {"input": "5\r\n2 1\r\n3 4\r\n3 5\r\n5 2\r\n", "output": "6...
false
stdio
null
true
471/B
471
B
Python 3
TESTS
7
124
716,800
77214693
# HEY STALKER from collections import Counter n = int(input()) l = list(map(int, input().split())) d = Counter(l) no_ln = 0 ok = 0 for t in d: if d[t] >= 3: ok = 1 break if d[t] == 2: no_ln += 1 if no_ln == 2: ok = 1 break if ok == 0: print("NO") else:...
31
62
307,200
7964297
def solve(nums): nums = zip(nums, [i+1 for i in range(len(nums))]) nums = sorted(nums, key=lambda x: x[0]) seqs = [[],[],[]] prev = nums[0][0] count = 0 for n, i in nums[1:]: if n == prev: count += 1 prev = n if count < 2: print("NO") return ...
Codeforces Round 269 (Div. 2)
CF
2,014
1
256
MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order...
The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order t...
null
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only tw...
[{"input": "4\n1 3 3 1", "output": "YES\n1 4 2 3\n4 1 2 3\n4 1 3 2"}, {"input": "5\n2 4 1 4 8", "output": "NO"}]
1,300
["implementation", "sortings"]
31
[{"input": "4\r\n1 3 3 1\r\n", "output": "YES\r\n1 4 2 3 \r\n4 1 2 3 \r\n4 1 3 2 \r\n"}, {"input": "5\r\n2 4 1 4 8\r\n", "output": "NO"}, {"input": "8\r\n1 5 4 12 7 2 10 11\r\n", "output": "NO"}, {"input": "6\r\n5 1 2 5 2 4\r\n", "output": "YES\r\n2 3 5 6 1 4 \r\n2 5 3 6 1 4 \r\n2 5 3 6 4 1 \r\n"}, {"input": "1\r\n1083...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(input_path, output_path, submission_path): input_lines = read_file(input_path) n = int(input_lines[0]) h = list(map(int, input_lines[1].split())) ref_lines = read_file(output...
true
764/B
764
B
PyPy 3
TESTS
19
529
23,449,600
42079711
n=int(input()) a=list(map(int,input().split())) c=[] for i in range(len(a)): c.append(a[i]) for i in range(len(a)//2): if(i%2==0): t=a[i] a[i]=a[n-i-1] a[n-i-1]=t if(n%2==1): for i in range(1,len(a)-1): if(i%2==1): a[i]=c[i] print(*a) elif(n%2==0): if(n>2...
34
109
15,872,000
30128094
n, l = int(input()), input().split() for i, j in zip(range(0, n, 2), range(n - 1, n // 2 - (n % 4 == 2), -2)): l[i], l[j] = l[j], l[i] print(' '.join(l))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
764/B
764
B
Python 3
TESTS
19
140
18,944,000
24709099
n = int(input()) cubes = input().split() if n >= 4: for i in range(n//4+(1 if n%2 else 0)): cubes[2*i], cubes[-2*i-1] = cubes[-2*i-1], cubes[2*i] else: cubes[0], cubes[-1] = cubes[-1], cubes[0] print(' '.join(cubes))
34
109
23,449,600
221819290
def solve(n: int, l: list) -> list: i=0 while i<n//2: if i%2==0: l[i],l[n-1-i]=l[n-1-i],l[i] i=i+1 s=" ".join(l) return(s) n=int(input()) l=input().split(" ") print(solve(n, l))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
767/B
767
B
Python 3
TESTS
10
202
8,908,800
95718854
import sys t1, t2, t = map(int, input().split()) u = 1 n = int(input()) if n == 0: print(t1) sys.exit() a = [int(i) for i in input().split()] mini = 10 ** 10 ans = 0 time = t1 for x in a: if x > t2 - t: break else: if time - x + 1 < mini and x > 0: mini = time - x + 1 ...
35
187
8,908,800
154444742
def solve(): s = [int(x) for x in input().split()] ts, tf, t = s[0], s[1], s[2] n = int(input()) if n == 0: return ts v = [int(x) for x in input().split()] v0 = v[0] if v0 > ts: return ts ans, ansv = 1e15, 1e15 now = ts for i in range(len(v)): i...
Codeforces Round 398 (Div. 2)
CF
2,017
1
256
The Queue
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He know...
The first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains p...
Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.
null
In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visito...
[{"input": "10 15 2\n2\n10 13", "output": "12"}, {"input": "8 17 3\n4\n3 4 5 8", "output": "2"}]
2,100
["brute force", "greedy"]
35
[{"input": "10 15 2\r\n2\r\n10 13\r\n", "output": "12"}, {"input": "8 17 3\r\n4\r\n3 4 5 8\r\n", "output": "2"}, {"input": "7 14 3\r\n2\r\n1 2\r\n", "output": "0"}, {"input": "30 70 10\r\n3\r\n30 32 35\r\n", "output": "60"}, {"input": "21 56 7\r\n5\r\n1 2 3 4 5\r\n", "output": "0"}, {"input": "10 1000000000 25\r\n20\r\...
false
stdio
null
true
690/B1
690
B1
PyPy 3-64
TESTS
7
62
1,433,600
211179862
cornerx = [] cornery = [] def listadd(listx,x): if not(x in listx): listx.append(x) for c in range(int(input(''))): map = [*input('')] for c1 in range(len(map)): if map[c1] == '1': listadd(cornerx,c) listadd(cornery,c1) if len(cornery) == 2 and len(cornerx) == 2: ...
21
77
0
19199252
def main(): size = int(input()) sq = [[int(c) for c in input().strip()] for _ in range(size)] print('Yes' if haslair(sq) else 'No') def haslair(sq): corners = [(r, c) for r, row in enumerate(sq) for c, count in enumerate(row) if count==1] if len(corners) != 4: return...
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
690/B1
690
B1
Python 3
TESTS
1
77
4,915,200
19971948
from sys import stdin n = int(stdin.readline()) nn = [[int(x) for x in stdin.readline().rstrip()] for i in range(n)] def run(): for row in range(n): for col in range(n): if(nn[row][col] == 0): continue if(countAdj(row, col, n-1)): print('No') ...
21
124
22,835,200
125716795
import os, sys from io import BytesIO, IOBase class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None d...
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
877/B
877
B
PyPy 3
TESTS
37
810
113,459,200
74892395
import sys input=sys.stdin.readline s=list(input().rstrip()) n=len(s) dp=[[0 for i in range(n+1)] for j in range(n+1)] dp[0][0]=int(s[0]=='a') for i in range(1,n): if s[i]=='a': dp[0][i]=dp[0][i-1]+1 else: dp[0][i]=dp[0][i-1] for i in range(n): for j in range(i,n): dp[i][j]=dp[0...
46
62
5,836,800
31639365
s=input() dp=[[0,0,0] for i in range(len(s))] for i in range(len(s)): if s[i]=='a': dp[i][0]=dp[i-1][0]+1 dp[i][1]=dp[i-1][1] dp[i][2]=max(dp[i-1][1]+1,dp[i-1][2]+1) else: dp[i][0]=dp[i-1][0] dp[i][1]=max(dp[i-1][0]+1,dp[i-1][1]+1) dp[i][2]=dp[i-1][2] e=len(s)-1 p...
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Nikita and string
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make ...
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
null
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
[{"input": "abba", "output": "4"}, {"input": "bab", "output": "2"}]
1,500
["brute force", "dp"]
46
[{"input": "abba\r\n", "output": "4"}, {"input": "bab\r\n", "output": "2"}, {"input": "bbabbbaabbbb\r\n", "output": "9"}, {"input": "bbabbbbbaaba\r\n", "output": "10"}, {"input": "bbabbbababaa\r\n", "output": "9"}, {"input": "aabbaababbab\r\n", "output": "8"}, {"input": "a\r\n", "output": "1"}, {"input": "b\r\n", "outp...
false
stdio
null
true
764/B
764
B
PyPy 3
TESTS
19
561
19,353,600
228914642
n=int(input()) arr=list(map(int,input().split())) p2=n-1 p1=1 flag=1 count =0 while p1<len(arr) or p2>-1: if count==n//2 and n%2==0: p2 -= 1 p1 -= 1 flag *= -1 if flag==1 and p2>-1: print(arr[p2],end=" ") p2 -= 2 elif flag==-1 and p1<len(arr): print(arr[p1],e...
34
124
26,931,200
218728167
n = (int(input())) l = list(map (int, input().split())) k = n//2 for i in range(k): if i%2 == 0: l[i], l[len(l)-1-i] = l[len(l)-1-i] , l[i] print(' '.join(map(str, l)))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
262/A
262
A
PyPy 3-64
TESTS
5
122
0
166458652
def r(n): z = 0 for i in str(n): if i == '7': z += 1 if i == '4': z += 1 return z n, m = map(int, input(). split()) a = list(map(int, input(). split())) ans = n for i in a: if len(str(i)) > m and r(i) == len(str(i)): ans -= 1 print(ans)
34
62
0
198241507
x=input().split(" ") n,k=x count=0 y=input().split(" ") for i in y: counter=0 for j in i: if "4"==j: counter+=1 elif "7"==j: counter+=1 if counter<=int(k): count+=1 print(count)
Codeforces Round 160 (Div. 2)
CF
2,013
1
256
Roma and Lucky Numbers
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers....
The first line contains two integers n, k (1 ≤ n, k ≤ 100). The second line contains n integers ai (1 ≤ ai ≤ 109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
null
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
[{"input": "3 4\n1 2 4", "output": "3"}, {"input": "3 2\n447 44 77", "output": "2"}]
800
["implementation"]
34
[{"input": "3 4\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "3 2\r\n447 44 77\r\n", "output": "2\r\n"}, {"input": "2 2\r\n507978501 180480073\r\n", "output": "2\r\n"}, {"input": "9 6\r\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089\r\n", "output": "9\r\n"}, {"input": "6 100\r\n17042...
false
stdio
null
true
262/A
262
A
Python 3
TESTS
5
62
0
198749376
num1 = input() num2 = input() lis1 = num1.split(" ") lis2 = num2.split(" ") counter = 0 for i in lis2: count = 0 for j in i: if int(j) == 4 or int(j) == 7: count += 1 else: break if count <= int(lis1[1]): counter += 1 print(counter)
34
62
0
208548057
n,k=[int(i) for i in input().split()] a=[int(i) for i in input().split()] s=0 for i in range(len(a)): count=0 while a[i]!=0: if a[i]%10==4 or a[i]%10==7: count+=1 a[i]=a[i]//10 if count<=k: s=s+1 print(s)
Codeforces Round 160 (Div. 2)
CF
2,013
1
256
Roma and Lucky Numbers
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers....
The first line contains two integers n, k (1 ≤ n, k ≤ 100). The second line contains n integers ai (1 ≤ ai ≤ 109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
null
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
[{"input": "3 4\n1 2 4", "output": "3"}, {"input": "3 2\n447 44 77", "output": "2"}]
800
["implementation"]
34
[{"input": "3 4\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "3 2\r\n447 44 77\r\n", "output": "2\r\n"}, {"input": "2 2\r\n507978501 180480073\r\n", "output": "2\r\n"}, {"input": "9 6\r\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089\r\n", "output": "9\r\n"}, {"input": "6 100\r\n17042...
false
stdio
null
true
479/C
479
C
PyPy 3-64
TESTS
25
155
6,963,200
209239189
a = [list(map(int,input().split())) for i in range(int(input()))] d = dict() for i,j in a: try: d[j] = min(i,d[j]) except KeyError: d[j] = i b = [[i[1],i[0]] for i in d.items()] c = sorted(b) e = [i[1] for i in c] if e == sorted(e): print(e[-1]) else: print(max(d.values()))
53
46
921,600
224594105
d={} ans=0 for _ in range(int(input())): a,b=map(int,input().split()) d.setdefault(a,[]) d[a].append(b) num = sorted(d.keys()) days= 0 n=len(num) for i in range(n): x=num[i] d[x].sort() if days<=d[x][0]: days= d[x][-1] else: days=x print(days)
Codeforces Round 274 (Div. 2)
CF
2,014
1
256
Exams
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a stud...
The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
null
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark ...
[{"input": "3\n5 2\n3 1\n4 2", "output": "2"}, {"input": "3\n6 1\n5 2\n4 3", "output": "6"}]
1,400
["greedy", "sortings"]
53
[{"input": "3\r\n5 2\r\n3 1\r\n4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n6 1\r\n5 2\r\n4 3\r\n", "output": "6\r\n"}, {"input": "1\r\n1000000000 999999999\r\n", "output": "999999999\r\n"}, {"input": "1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n3 2\r\n", "output": "2\r\n"}, {"input": "5\r\n4 3\r\n4 2\r\...
false
stdio
null
true
825/D
825
D
Python 3
TESTS
8
295
8,806,400
34514383
def main(): s=input() t=input() n=len(s) m=len(t) k=0 d={} for i in range(m): if t[i] not in d: d[t[i]]=[1,0] else: d[t[i]][0]+=1 for i in range(n): if s[i] in d: d[s[i]][1]+=1 if s[i]=='?': k+=1 ...
24
358
17,612,800
160342530
import sys from array import array from heapq import * input = lambda: sys.stdin.buffer.readline().decode().strip() s, t = array('u', input()), array('u', input()) mem = [0] * 26 rem = [0] * 26 for i in t: mem[ord(i) - 97] += 1 for i in s: if i != '?': rem[ord(i) - 97] += 1 que = [] for i in range(2...
Educational Codeforces Round 25
ICPC
2,017
1
256
Suitable Replacement
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resultin...
The first line contains string s (1 ≤ |s| ≤ 106). The second line contains string t (1 ≤ |t| ≤ 106).
Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal. If there are multiple strings with maximal suitability then print any of them.
null
In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2. In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them. In the third exam...
[{"input": "?aa?\nab", "output": "baab"}, {"input": "??b?\nza", "output": "azbz"}, {"input": "abcd\nabacaba", "output": "abcd"}]
1,500
["binary search", "greedy", "implementation"]
24
[{"input": "?aa?\r\nab\r\n", "output": "baab\r\n"}, {"input": "??b?\r\nza\r\n", "output": "azbz\r\n"}, {"input": "abcd\r\nabacaba\r\n", "output": "abcd\r\n"}, {"input": "mqwstphetbfrsyxuzdww\r\nrutseqtsbh\r\n", "output": "mqwstphetbfrsyxuzdww\r\n"}, {"input": "????????????????????\r\nxwkxsxlrre\r\n", "output": "eekkllr...
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: s_original = f.readline().strip() t = f.readline().strip() with open(submission_path, 'r') as f: submission_s = f.readline().strip() ...
true
877/B
877
B
PyPy 3
TESTS
37
311
2,252,800
100488825
s=input() n=len(s) prefa=[0]*(n) prefb=[0]*(n) prefa[0]=(s[0]=='a') prefb[0]=(s[0]=='b') c=0 for i in range(n): prefa[i]=prefa[i-1]+(s[i]=='a') prefb[i]=prefb[i-1]+(s[i]=='b') ans1,ans=0,0 prefa=[0]+prefa prefb=[0]+prefb for i in range(n+1): for j in range(i,n+1): ans1=(prefa[n]-prefa[j])+(prefb[j]-prefb[i...
46
77
0
31731463
line = input() dp = 3 * [0] for c in line: if c == 'a': dp[2] = max(dp) + 1 dp[0] += 1 elif c == 'b': dp[1] = max(dp[:2]) + 1 print(max(dp))
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Nikita and string
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make ...
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
null
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
[{"input": "abba", "output": "4"}, {"input": "bab", "output": "2"}]
1,500
["brute force", "dp"]
46
[{"input": "abba\r\n", "output": "4"}, {"input": "bab\r\n", "output": "2"}, {"input": "bbabbbaabbbb\r\n", "output": "9"}, {"input": "bbabbbbbaaba\r\n", "output": "10"}, {"input": "bbabbbababaa\r\n", "output": "9"}, {"input": "aabbaababbab\r\n", "output": "8"}, {"input": "a\r\n", "output": "1"}, {"input": "b\r\n", "outp...
false
stdio
null
true
239/B
239
B
PyPy 3-64
TESTS
6
122
2,867,200
199612460
n,q=map(int,input().split()) s=input() for i in range(q): l,r=map(int,input().split()) l=list(s[l-1:r]) i=0 prev=0 dp=1 dicti={} while(i>=0 and i<len(l)): if l[i]=='<': dp=0 if prev==1: l.pop(i-1) i=i-2 else: ...
33
92
0
154842265
n, q = map(int, input().split()) S = list('x'+input()+'x') for _ in range(q): l, r = map(int, input().split()) s = S[l-1:r+2] s[0] = s[-1] = 'x' c = [0]*10 dp, p = 1, 1 while s[p]!='x': if s[p]=='>': dp = 1 if s[p+1] in "><": s.pop(p) else: p += 1 elif s[p]=='<': dp = -1 p -= 1 if s[...
Codeforces Round 148 (Div. 2)
CF
2,012
2
256
Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. - Current character pointer (CP); - Dire...
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines ea...
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
null
null
[{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}]
1,500
["brute force", "implementation"]
33
[{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n2 3 2 1 0 0 0 0 0 0 \r\n"}, {"input": "5 2\r\n>>>>>\r\n1 5\r\n1 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 3\r\n9\r\n1 1\r\n1 1\r\n1 1\...
false
stdio
null
true
239/B
239
B
PyPy 3
TESTS
8
280
1,433,600
59124312
class CodeforcesTask239BSolution: def __init__(self): self.result = '' self.n_q = [] self.program = [] self.queries = [] def read_input(self): self.n_q = [int(x) for x in input().split(" ")] self.program = list(input()) for x in range(self.n_q[1]): ...
33
92
0
154844086
n, q = map(int, input().split()) S = [-1]+list(map(lambda x: ord(x)-ord('0'), input()))+[-1] D = [12, 14] for _ in range(q): l, r = map(int, input().split()) s = S[l-1:r+2] s[0] = s[-1] = -1 c = [0]*10 dp, p = 1, 1 i = s[p] while i!= -1: if i==14: dp = 1 if s[p+1] in D: s.pop(p) else: p += 1 ...
Codeforces Round 148 (Div. 2)
CF
2,012
2
256
Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. - Current character pointer (CP); - Dire...
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines ea...
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
null
null
[{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}]
1,500
["brute force", "implementation"]
33
[{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n2 3 2 1 0 0 0 0 0 0 \r\n"}, {"input": "5 2\r\n>>>>>\r\n1 5\r\n1 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 3\r\n9\r\n1 1\r\n1 1\r\n1 1\...
false
stdio
null
true
239/B
239
B
Python 3
TESTS
8
92
0
170507536
n,k=map(int,input().split()) a=[-1]+[ord(c)-ord('0') for c in input()]+[-1] for _ in range(k): L,R=map(int,input().split()) b=[-1]+a[L:R+1]+[-1] ans,dp,p=[0]*10,1,1 c=b[p] while c!=-1: if c==12: p-=1 dp=-1 if b[p]==12 or b[p]==14: b.pop(p+1) elif c...
33
218
0
54437876
n, q = map(int, input().split()) s = input() for _ in range(q): l, r = map(int, input().split()) t = list(s[l-1:r]) p, d = 0, 1 res = [0] * 10 while 0 <= p < len(t): if '0' <= t[p] <= '9': k = int(t[p]) res[k] += 1 if k > 0: t[p] = str(k-1)...
Codeforces Round 148 (Div. 2)
CF
2,012
2
256
Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. - Current character pointer (CP); - Dire...
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines ea...
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
null
null
[{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}]
1,500
["brute force", "implementation"]
33
[{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n2 3 2 1 0 0 0 0 0 0 \r\n"}, {"input": "5 2\r\n>>>>>\r\n1 5\r\n1 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 3\r\n9\r\n1 1\r\n1 1\r\n1 1\...
false
stdio
null
true
653/F
653
F
PyPy 3-64
TESTS
4
46
0
213172533
import math import bisect from itertools import accumulate def suffix_array(s): n = len(s) rk, sa = [ord(s[i]) for i in range(n)], [i for i in range(n)] l, S = 0, 128 while True: p = [i for i in range(n-l, n)] for i in range(n): if sa[i]>=l: p.append(sa[i]-l) ...
68
904
55,910,400
169979803
import bisect import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def suffix_array(s): l = len(s) x = [[] for _ in range(222)] for i in range(l): x[s[i]].append(i) y = [] z = [0] for x0 in x: for i in x0: y.append(i) z.append(len(y...
IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)
CF
2,016
3
512
Paper task
Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time. For the purpose of this problem we consider only strings cons...
The first line of the input contains an integer n (1 ≤ n ≤ 500 000) — the length of the string s. The second line contains a string s of length n consisting of only '(' and ')'.
Print the number of distinct non-empty correct sequences that occur in s as substring.
null
In the first sample, there are 5 distinct substrings we should count: "()", "()()", "()()()", "()()()()" and "()()()()()". In the second sample, there are 3 distinct substrings we should count: "()", "(())" and "(())()".
[{"input": "10\n()()()()()", "output": "5"}, {"input": "7\n)(())()", "output": "3"}]
2,600
["data structures", "string suffix structures", "strings"]
68
[{"input": "10\r\n()()()()()\r\n", "output": "5\r\n"}, {"input": "7\r\n)(())()\r\n", "output": "3\r\n"}, {"input": "1\r\n(\r\n", "output": "0\r\n"}, {"input": "2\r\n))\r\n", "output": "0\r\n"}, {"input": "15\r\n(())(()())(()()\r\n", "output": "5\r\n"}, {"input": "30\r\n()(())(())(())()(())()()()(()(\r\n", "output": "34...
false
stdio
null
true
1009/A
1009
A
Python 3
TESTS
7
109
307,200
68420323
n,m=map(int,input().split()) n1=list(map(int,input().split())) m1=list(map(int,input().split())) c=0 f=m1[0] k=0 for i in range(n): if(k==(m-1)): c=c+1 break if(f>=n1[i]): k=k+1 f=m1[k] c=c+1 print(c)
19
31
0
159301832
r=lambda:map(int,input().split()) r() c,a=r(),[*r()]+[0] i=0 for x in c:i+=x<=a[i] print(i)
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1
256
Game Shopping
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$. Games in the shop are ordered from left to ri...
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th ...
Print a single integer — the number of games Maxim will buy.
null
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3"}, {"input": "5 2\n20 40 50 20 40\n19 20", "output": "0"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4"}]
800
["implementation"]
19
[{"input": "5 4\r\n2 4 5 2 4\r\n5 3 4 6\r\n", "output": "3\r\n"}, {"input": "5 2\r\n20 40 50 20 40\r\n19 20\r\n", "output": "0\r\n"}, {"input": "6 4\r\n4 8 15 16 23 42\r\n1000 1000 1000 1000\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 1\r\n10 1 1 1 1\r\n1000\r\n", "...
false
stdio
null
true
386/A
386
A
Python 3
TESTS
3
93
0
50767151
n=int(input()) l=list(map(int,input().split())) a=l[0] for i in range(n): if l[i]>a: a=l[i] b=i+1 else: b=1 l.sort() print(b, end=" ") print(l[n-2])
42
31
0
162489352
if __name__ == "__main__": n = int(input()) offers = list(int(x) for x in input().split()) winner_pos = offers.index(max(offers)) offers.pop(winner_pos) price_to_pay = max(offers) print(winner_pos+1, price_to_pay)
Testing Round 9
CF
2,014
1
256
Second-Price Auction
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
null
null
[{"input": "2\n5 7", "output": "2 5"}, {"input": "3\n10 2 8", "output": "1 8"}, {"input": "6\n3 8 2 9 4 14", "output": "6 9"}]
800
["implementation"]
42
[{"input": "2\r\n5 7\r\n", "output": "2 5\r\n"}, {"input": "3\r\n10 2 8\r\n", "output": "1 8\r\n"}, {"input": "6\r\n3 8 2 9 4 14\r\n", "output": "6 9\r\n"}, {"input": "4\r\n4707 7586 4221 5842\r\n", "output": "2 5842\r\n"}, {"input": "5\r\n3304 4227 4869 6937 6002\r\n", "output": "4 6002\r\n"}, {"input": "6\r\n5083 328...
false
stdio
null
true
514/B
514
B
Python 3
TESTS
4
31
0
209876548
n,x,y=map(int,input().split()) p=set() for i in range(n): a,b=map(int,input().split()) try: p.add(abs((b-y)/(a-x))) except ZeroDivisionError: p.add(-1) print(len(p))
29
46
0
201791755
n,a,b=map(int,input().split()) data={} for _ in range(n): x,y=map(int,input().split()) m=float("inf") if y==b else (x-a)/(y-b) data[m]=None print(len(data))
Codeforces Round 291 (Div. 2)
CF
2,015
1
256
Han Solo and Lazer Gun
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can d...
The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed th...
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
null
Explanation to the first and second samples from the statement, respectively:
[{"input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1", "output": "2"}, {"input": "2 1 2\n1 1\n1 0", "output": "1"}]
1,400
["brute force", "data structures", "geometry", "implementation", "math"]
29
[{"input": "4 0 0\r\n1 1\r\n2 2\r\n2 0\r\n-1 -1\r\n", "output": "2\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"input": "1 1 1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2 0 0\r\n10000 -10000\r\n-10000 10000\r\n", "output": "1\r\n"}, {"input": "2 0 0\r\n10000 -10000\r\n10000 10000\r\n", "output": ...
false
stdio
null
true
70/B
70
B
Python 3
TESTS
10
108
0
42013814
n = int(input()) s = input() l = 0 isSpace = 0 c = 1 s1 = 0 p = True for i in range(len(s)): s1 += 1 if s[i] in ['.', '?', '!']: if l + s1 < n: l += s1 s1 = 0 if i + 1 < len(s) and s[i + 1] == ' ': s1 -= 1 elif l + s1 > n: l = s1 ...
48
62
0
204454049
# compiler on CodeForces: PyPy 3 64bit import sys input = lambda: sys.stdin.readline()[:-1] print = lambda *args: sys.stdout.write(' '.join(map(str, args)) + '\n') n = int(input()) sentences = input().replace('?', '.').replace('!', '.').strip('.').split('. ') sentences = [len(e) + 1 for e in sentences] if max(sentenc...
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
883/I
883
I
PyPy 3
TESTS1
9
93
23,142,400
31569363
n,k=[int(i) for i in input().split()] l=[int(i) for i in input().split()] l.sort() lvisited=[] for i in range(n): lvisited.append(0) grp=n//k x=n%k if (grp==1): print (l[-1]-l[0]) else: l1=[] for i in range(grp): l1.append([]) for i in range(k): lvisited[i]=1 lvisited[n-1-i]=...
70
639
54,067,200
205414750
import sys input = lambda: sys.stdin.readline().strip() def solve(): n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() def check(v): f = [True] + [False] * n j = 0 for i in range(n): while j < i and (a[i] - a[j] > v or not f[j]): ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Photo Processing
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast vi. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy already k...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — number of photos and minimum size of a group. The second line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the contrast of the i-th photo.
Print the minimal processing time of the division into groups.
null
In the first example the photos should be split into 2 groups: [40, 50] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division...
[{"input": "5 2\n50 110 130 40 120", "output": "20"}, {"input": "4 1\n2 3 4 1", "output": "0"}]
1,900
["binary search", "dp"]
70
[{"input": "5 2\r\n50 110 130 40 120\r\n", "output": "20\r\n"}, {"input": "4 1\r\n2 3 4 1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n4\r\n", "output": "0\r\n"}, {"input": "2 2\r\n7 5\r\n", "output": "2\r\n"}, {"input": "3 2\r\n34 3 75\r\n", "output": "72\r\n"}, {"input": "5 2\r\n932 328 886 96 589\r\n", "output": "343...
false
stdio
null
true
883/K
883
K
PyPy 3
TESTS
0
109
0
91601529
import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) s = [] g = [] forwardBound = [] backwardBound = [] for _ in range(n): sCur,gCur = map(int,input().split()) s.append(sCur) g.append(gCur) forwardBound.append(s[0] + g[0]) for i in range(1,n): if forwardBound[-1] <...
109
1,824
23,961,600
32543393
n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) a[i][1]+=a[i][0] for i in range(1,n): if a[i][1]>a[i-1][1]+1: a[i][1]=a[i-1][1]+1 if a[i][1]<a[i][0]:exit(print(-1)) s=a[-1][1]-a[-1][0] for i in range(n-2,-1,-1): if a[i][1] > a[i + 1][1] + 1: a[i][1...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Road Widening
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street. Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.
In the first line print the total width of lawns which will be removed. In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last. If there is no solution, print the only integer -1 in the first line.
null
null
[{"input": "3\n4 5\n4 5\n4 10", "output": "16\n9 9 10"}, {"input": "4\n1 100\n100 1\n1 100\n100 1", "output": "202\n101 101 101 101"}, {"input": "3\n1 1\n100 100\n1 1", "output": "-1"}]
1,800
["constructive algorithms", "greedy", "implementation"]
109
[{"input": "3\r\n4 5\r\n4 5\r\n4 10\r\n", "output": "16\r\n9 9 10 \r\n"}, {"input": "4\r\n1 100\r\n100 1\r\n1 100\r\n100 1\r\n", "output": "202\r\n101 101 101 101 \r\n"}, {"input": "3\r\n1 1\r\n100 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n21005 10850\r\n27020 13372\r\n28183 3724\r\n22874 13564\r\n27446 11...
false
stdio
null
true
883/I
883
I
Python 3
TESTS
4
30
0
205384821
n, k = input().split(" ") n, k = int(n), int(k) arr = [int(val) for val in input().split(" ")] arr.sort() def is_ok(val): is_end_ok = [False for i in range(n)] cnt_sum = [0 for i in range(n)] left, right = 0, 0 for i in range(n): cnt_sum[i] = cnt_sum[i - 1] right = i - k + 1 if ...
70
654
54,579,200
205393534
# 最小值尽量大 最大值尽量小 尽量多分组 n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() left = 0 right = 10**10 # 居然是dp吗 def check(num): dp = [True] + [False] * n left = 0 for right in range(n): while left < right and (a[right] - a[left] > num or not dp[left]): left += 1 ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Photo Processing
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast vi. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy already k...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — number of photos and minimum size of a group. The second line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the contrast of the i-th photo.
Print the minimal processing time of the division into groups.
null
In the first example the photos should be split into 2 groups: [40, 50] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division...
[{"input": "5 2\n50 110 130 40 120", "output": "20"}, {"input": "4 1\n2 3 4 1", "output": "0"}]
1,900
["binary search", "dp"]
70
[{"input": "5 2\r\n50 110 130 40 120\r\n", "output": "20\r\n"}, {"input": "4 1\r\n2 3 4 1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n4\r\n", "output": "0\r\n"}, {"input": "2 2\r\n7 5\r\n", "output": "2\r\n"}, {"input": "3 2\r\n34 3 75\r\n", "output": "72\r\n"}, {"input": "5 2\r\n932 328 886 96 589\r\n", "output": "343...
false
stdio
null
true
154/A
154
A
PyPy 3
TESTS
5
278
0
102936031
l = list(input()) k = int(input()) forbidden = [] for i in range(k): forbidden.append(set(list(input()))) i = 1 ans = 0 p = [l[0]] while(i<len(l)-1): # print(p,i) if (p==[]): p.append(l[i]) # print("appendede i",i) i+=1 continue s = set([p[-1],l[i]]) if...
42
216
2,048,000
138292509
import sys import math from sys import stdin, stdout # TAKE INPUT def get_ints_in_variables(): return map(int, sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(n): return [list( ...
Codeforces Round 109 (Div. 1)
CF
2,012
2
256
Hometask
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105. The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters. Next k lines contain descriptions of forbi...
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
null
In the first sample you should remove two letters b. In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
[{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}]
1,600
["greedy"]
42
[{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input...
false
stdio
null
true
155/B
155
B
Python 3
TESTS
2
62
0
227986421
num_cards = int(input()) card_list = [] for i in range(num_cards): a, b = map(int, input().split()) card_list.append((a, b)) card_list.sort(key=lambda x: (-x[1], -x[0])) total_points = card_list[0][0] remaining_cards = card_list[0][1] for i in range(1, num_cards): if remaining_cards == 0: break ...
39
218
1,740,800
226398956
n,l,s= int(input()),[],[1,0] for i in range(n): a,b=map(int, input().split()) l.append([b,a]) l.sort(),l.reverse() for e in l: if s[0]==0: break s=[s[0]+e[0]-1,s[1]+e[1]] print(s[1])
Codeforces Round 109 (Div. 2)
CF
2,012
2
256
Combination
Ilya plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom co...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of cards Ilya has. Each of the next n lines contains two non-negative space-separated integers — ai and bi (0 ≤ ai, bi ≤ 104) — the numbers, written at the top and the bottom of the i-th card correspondingly.
Print the single number — the maximum number of points you can score in one round by the described rules.
null
In the first sample none of two cards brings extra moves, so you should play the one that will bring more points. In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.
[{"input": "2\n1 0\n2 0", "output": "2"}, {"input": "3\n1 0\n2 0\n0 2", "output": "3"}]
1,100
["greedy", "sortings"]
39
[{"input": "2\r\n1 0\r\n2 0\r\n", "output": "2\r\n"}, {"input": "3\r\n1 0\r\n2 0\r\n0 2\r\n", "output": "3\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n2 0\r\n3 0\r\n5 1\r\n", "output": "8\r\n"}, {"input": "7\r\n9 1\r\n8 1\r\n9 0\r\n9 1\r\n5 1\r\n1 1\r\n0 1\r\n", "output": "41\r\n"}, {"input": "7\r\n5 0\r\n4 0\r\n3 0\r\n5 2\r\...
false
stdio
null
true
551/A
551
A
Python 3
TESTS
22
670
512,000
15072169
n=int(input( )) fq=2001*[0] s=[int(i) for i in input( ).split( )] for i in range(n): fq[s[i]]+=1 for i in range(n): a=0 if s[i]==n: print(1,end=' ') else: for j in range(s[i]+1,2001): a+=fq[j] print(a+1,end=' ')
36
31
0
149598033
N = int(input()) t = list(map(int, input().split())) l = [0] * 2001 for i in t: l[i] += 1 i = max(t) c = 0 r = 1 while c != N: if l[i] != 0: c += l[i] l[i], r = r, r + l[i] i -= 1 for i in t: print(l[i], end = " ")
Codeforces Round 307 (Div. 2)
CF
2,015
2
256
GukiZ and Contest
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the ...
The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students. The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n).
In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input.
null
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first positi...
[{"input": "3\n1 3 3", "output": "3 1 1"}, {"input": "1\n1", "output": "1"}, {"input": "5\n3 5 3 4 5", "output": "4 1 4 3 1"}]
800
["brute force", "implementation", "sortings"]
36
[{"input": "3\r\n1 3 3\r\n", "output": "3 1 1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 5 3 4 5\r\n", "output": "4 1 4 3 1\r\n"}, {"input": "7\r\n1 3 5 4 2 2 1\r\n", "output": "6 3 1 2 4 4 6\r\n"}, {"input": "11\r\n5 6 4 2 9 7 6 6 6 6 7\r\n", "output": "9 4 10 11 1 2 4 4 4 4 2\r\n"}, {"input"...
false
stdio
null
true
571/B
571
B
PyPy 3-64
TESTS
10
358
12,595,200
144624570
from random import * import itertools def solve(): n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) l1 = (n + k - 1) // k l2 = n // k x = y = 0 for r in range(k): cur = 0 for i in range(r, n, k): cur += 1 if cur == (n + k - 1) // ...
52
701
26,316,800
12697806
def solve(n, k, As): As.sort() m, r = divmod(n, k) dp = [0] * (r + 1) for i in range(1, k): im = i * m new_dp = [0] * (r + 1) new_dp[0] = dp[0] + As[im] - As[im - 1] for h in range(1, min(i, r) + 1): new_dp[h] = max(dp[h], dp[h - 1]) + As[im + h] - As[im + h -...
Codeforces Round 317 [AimFund Thanks-Round] (Div. 1)
CF
2,015
2
256
Minimization
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You need to permute the array elements so that value $$\sum_{i=1}^{n-k}|A[i]-A[i+k]|$$
The first line contains two integers n, k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ min(5000, n - 1)). The second line contains n integers A[1], A[2], ..., A[n] ( - 109 ≤ A[i] ≤ 109), separate by spaces — elements of the array A.
Print the minimum possible value of the sum described in the statement.
null
In the first test one of the optimal permutations is 1 4 2. In the second test the initial order is optimal. In the third test one of the optimal permutations is 2 3 4 4 3 5.
[{"input": "3 2\n1 2 4", "output": "1"}, {"input": "5 2\n3 -5 3 -5 3", "output": "0"}, {"input": "6 3\n4 3 4 3 2 5", "output": "3"}]
2,000
["dp", "greedy", "sortings"]
52
[{"input": "3 2\r\n1 2 4\r\n", "output": "1\r\n"}, {"input": "5 2\r\n3 -5 3 -5 3\r\n", "output": "0\r\n"}, {"input": "6 3\r\n4 3 4 3 2 5\r\n", "output": "3\r\n"}, {"input": "2 1\r\n1 100\r\n", "output": "99\r\n"}, {"input": "4 3\r\n1 2 4 8\r\n", "output": "1\r\n"}, {"input": "5 2\r\n1 2 8 8 16\r\n", "output": "9\r\n"},...
false
stdio
null
true
609/A
609
A
Python 3
TESTS
5
109
0
45389077
import sys n = int(input()) count = 0 file = int (input()) drives = [] for i in range(n): drives.append(int(input())) for k in drives: if k == file or k > file: print("1") sys.exit() drives.sort(reverse=True) size = file for l in range(0 , len(drives) , 1): while size > -1: ...
34
46
0
136087134
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-18 23:36:03 LastEditTime: 2021-11-18 23:42:27 Description: USB Flash Drives FilePath: CF609A.py ''' def func(): n, m = int(input()), int(input()) capacities = [] for _ in range(n): capacities.append(int(input())) size = 0 ...
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
108/B
108
B
Python 3
TESTS
60
310
15,257,600
24901982
n = int(input()) A = sorted(list(set(map(int, input().split())))) if len(A) > 1 and A[-1] < 2 * A[-2]: print("YES") else: print("NO")
65
186
13,926,400
190097128
n=int(input()) a=sorted(list(map(int,input().split()))) for i in range(n-1): if a[i]<a[i+1] and a[i]*2>a[i+1]: print("YES") exit() print("NO")
Codeforces Beta Round 83 (Div. 2 Only)
CF
2,011
2
256
Datatypes
Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G...
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
null
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
[{"input": "3\n64 16 32", "output": "NO"}, {"input": "4\n4 2 1 3", "output": "YES"}]
1,400
["math", "sortings"]
65
[{"input": "3\r\n64 16 32\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 2 1 3\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 5 3 3 2\r\n", "output": "YES\r\n"}, {"input": "52\r\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 24 54 54 234 234 4...
false
stdio
null
true
157/A
157
A
PyPy 3
TESTS
8
280
0
81457609
n=int(input()) if n==1: c=int(input()) print("0") else: arr=[] row_sum=[] col_sum=[] for i in range(n): a=list(map(int,input().split())) arr.append(a) row_sum.append(sum(a)) k=0 for i in range(n): c=0 for j in range(n): c+=arr[j][k] k+=1 col_sum.append(c) col_sum.sort() count=0 for i in rang...
49
92
0
142337015
n = int(input()) lst1 = [] for i in range(n): lst1.append(list(map(int, input().split()))) lst2 = [] x = 0 for a in range(n): temp_list = [] for i in range(n): temp_list.append(lst1[i][x]) lst2.append(temp_list) x = x + 1 total = 0 for i in range(n): for j in range(n): if(sum(lst...
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
159/B
159
B
PyPy 3
TESTS
12
902
17,715,200
196190207
#input import sys input = sys.stdin.readline n, m = tuple([int(x) for x in input().split()]) markers = dict() for i in range(n): xi, yi = tuple([int(x) for x in input().split()]) markers["%04d%04d"%(xi, yi)] = markers.get("%04d%04d"%(xi, yi), 0) + 1 caps = [] for i in range(m): xi, yi = tuple([int(x) for x in in...
37
746
26,828,800
18161406
def main(): from sys import stdin l = list(map(int, stdin.read().split())) n, yx = l[0] * 2, [[0] * 1001 for _ in range(1001)] cnt = yx[0] u = v = 0 for y, x in zip(l[3:n + 3:2], l[2:n + 2:2]): cnt[y] += 1 yx[y][x] += 1 ba, l = list(zip(l[n + 3::2], l[n + 2::2])), [] for ...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Matchmaker
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a m...
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly....
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of b...
null
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
[{"input": "3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2", "output": "3 2"}, {"input": "2 2\n1 2\n2 1\n3 4\n5 1", "output": "1 0"}]
1,100
["*special", "greedy", "sortings"]
37
[{"input": "3 4\r\n1 2\r\n3 4\r\n2 4\r\n5 4\r\n2 4\r\n1 1\r\n1 2\r\n", "output": "3 2\r\n"}, {"input": "2 2\r\n1 2\r\n2 1\r\n3 4\r\n5 1\r\n", "output": "1 0\r\n"}, {"input": "6 7\r\n2 1\r\n2 2\r\n2 1\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n2 2\r\n2 2\r\n1 2\r\n2 2\r\n1 1\r\n1 2\r\n", "output": "3 3\r\n"}, {"input": "6 7\r\n2 1\...
false
stdio
null
true
69/B
69
B
PyPy 3
TESTS
10
280
22,732,800
87006613
n,m=map(int,input().split()) list1=[111]*(101) list2=[0]*(101) for i in range(m): l,r,t,c=map(int,input().split()) x=r-l+1 for j in range(l,r+1): if(list1[j]>t): list1[j]=t list2[j]=c # elif(list1[j]==t and list2[j]<c): # list2[j]=c print(sum(...
67
124
3,788,800
191835306
n, m = map(int, input().split(" ")) section = [[] for i in range(n)] for i in range(m): l, r, t, c = map(int, input().split(" ")) for a in range(l-1, r): section[a].append([t, i, c]) answer = 0 for i in section: if(i != []): i.sort() answer += i[0][2] print(answer)
Codeforces Beta Round 63 (Div. 2)
CF
2,011
2
256
Bets
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor. To begin with friends...
The first line contains two integers n and m (1 ≤ n, m ≤ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 ≤ li ≤ ri ≤ n, 1 ≤ ti, ci ≤ 1000).
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
null
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles. In the secon...
[{"input": "4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20", "output": "60"}, {"input": "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20", "output": "105"}]
1,200
["greedy", "implementation"]
67
[{"input": "4 4\r\n1 4 20 5\r\n1 3 21 10\r\n3 3 4 30\r\n3 4 4 20\r\n", "output": "60"}, {"input": "8 4\r\n1 5 24 10\r\n2 4 6 15\r\n4 6 30 50\r\n6 7 4 20\r\n", "output": "105"}, {"input": "2 2\r\n1 2 3 1\r\n2 2 3 10\r\n", "output": "2"}, {"input": "20 30\r\n15 17 54 46\r\n4 18 26 18\r\n18 20 49 94\r\n12 12 83 12\r\n11 1...
false
stdio
null
true
1009/A
1009
A
Python 3
TESTS
3
93
307,200
83685428
n,m=map(int,input().split()); count = 0 s = list(map(int,input().split())) s1 = list(map(int,input().split())) x = 0 for i in range(m): if i>=1 and count==0: break for j in range(x,n): if s1[i]>=s[j]: count+=1 x = j+1 break print(count)
19
31
0
175763741
def games(c,a): k=0 for i in c: if a==[]: return k if i<=a[0]: a.pop(0) k+=1 return k nm=input() a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] print(games(a,b))
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1
256
Game Shopping
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$. Games in the shop are ordered from left to ri...
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th ...
Print a single integer — the number of games Maxim will buy.
null
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3"}, {"input": "5 2\n20 40 50 20 40\n19 20", "output": "0"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4"}]
800
["implementation"]
19
[{"input": "5 4\r\n2 4 5 2 4\r\n5 3 4 6\r\n", "output": "3\r\n"}, {"input": "5 2\r\n20 40 50 20 40\r\n19 20\r\n", "output": "0\r\n"}, {"input": "6 4\r\n4 8 15 16 23 42\r\n1000 1000 1000 1000\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 1\r\n10 1 1 1 1\r\n1000\r\n", "...
false
stdio
null
true
108/B
108
B
PyPy 3
TESTS
60
530
10,137,600
109225131
def getOdp(tab, n, last): max_2 = 0 for i in range(n): if tab[i] > max_2 and last > tab[i]: max_2 = tab[i] return False if max_2 * 2 <= last else True n = int(input()) if n == 1: print("NO") exit() s = input().split(" ") T = [] for e in s: T.append(int(e)) max_1 = max(T) if...
65
186
13,926,400
213232784
n = int(input()) ls = list(map(int,input().split())) ls.sort() for i in range(n-1) : if ls[i] != 1 and (ls[i+1] > ls[i] and ls[i+1] < 2*ls[i]) : print("YES") break else : print("NO")
Codeforces Beta Round 83 (Div. 2 Only)
CF
2,011
2
256
Datatypes
Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G...
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
null
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
[{"input": "3\n64 16 32", "output": "NO"}, {"input": "4\n4 2 1 3", "output": "YES"}]
1,400
["math", "sortings"]
65
[{"input": "3\r\n64 16 32\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 2 1 3\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 5 3 3 2\r\n", "output": "YES\r\n"}, {"input": "52\r\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 24 54 54 234 234 4...
false
stdio
null
true
467/B
467
B
PyPy 3-64
TESTS
5
61
0
211618321
a, b, c = map(int, input().split()) d = [] g = [] j = p = 0 for i in range(b+1): d.append(int(input())) for ii in range(b): j = bin(d[ii]&d[-1]) g.append(j.count("1")) k = bin(d[-1]) k = k.count("1") for elem in g: if k-elem<c: p+=1 print(p)
43
46
0
211760393
#Fedor and New Game n,m,k = map(int,input().split()) l = [] for _ in range(m+1): l.append(int(input())) amigos = 0 for i in range(m): a = l[i] ^ l[-1] a = list(bin(a)) b = a[len(a)-k:] count = 0 if a.count('1') > k: continue else: amigos += 1 print(amigos)
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3». The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each ...
The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.
Print a single integer — the number of Fedor's potential friends.
null
null
[{"input": "7 3 1\n8\n5\n111\n17", "output": "0"}, {"input": "3 3 3\n1\n2\n3\n4", "output": "3"}]
1,100
["bitmasks", "brute force", "constructive algorithms", "implementation"]
43
[{"input": "7 3 1\r\n8\r\n5\r\n111\r\n17\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1\r\n2\r\n3\r\n4\r\n", "output": "3\r\n"}, {"input": "4 2 2\r\n5\r\n6\r\n7\r\n", "output": "2\r\n"}, {"input": "4 7 4\r\n9\r\n10\r\n5\r\n12\r\n4\r\n12\r\n7\r\n10\r\n", "output": "7\r\n"}, {"input": "2 7 2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n...
false
stdio
null
true
16/A
16
A
Python 3
TESTS
27
218
0
97375306
n,m=input().split(" ") prev=-1 flag=-1 for i in range(0,int(n)): # print("i=======",i) val=list(input()) first=val[0] for j in val: # print("j======",j,first) if first!=j: print("NO") flag=1 if flag==1: break if first==prev: pr...
35
62
0
138861403
a = input() b, c = a.split(" ") b, c = int(b), int(c) prevfur = 11 for x in range(b): wrd = input() srtdwrd = sorted(wrd) if (srtdwrd[0] != srtdwrd[-1] or prevfur == wrd[0]): print("NO") break else: prevfur = wrd[0] if(x == b - 1): print("YES") break
Codeforces Beta Round 16 (Div. 2 Only)
ICPC
2,010
2
64
Flag
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'...
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the...
Output YES, if the flag meets the new ISO standard, and NO otherwise.
null
null
[{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}]
800
["implementation"]
35
[{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\...
false
stdio
null
true
157/A
157
A
Python 3
TESTS
8
248
307,200
102921824
""" Game Outcome """ n = int(input()) board = [] for line in range(n): board.append([int(x) for x in input().split()]) wins = 0 for row in range(n): for column in range(n): rowSum = columnSum = 0 for i in range(n): columnSum += board[row][i] for i in range(n): ...
49
92
0
146819044
n = int(input()) answer = 0 s = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n): sh = s[i] sw = [s[k][j] for k in range(n)] if sum(sw) > sum(sh): answer+=1 print(answer)
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
159/B
159
B
PyPy 3
TESTS
12
2,682
24,473,600
42955530
import sys from collections import Counter n,m=map(int,input().split()) l1=[];l2=[]; for i in range(n) : l1.append(input()) for i in range(m) : l2.append(input()) c1=Counter(l1) c2=Counter(l2) c=0;s=0; c3=c1&c2 #print(c1,"\n",c2,"\n",c3) l=sum(c3.values()) #print(l) c1=c1-c3 c2=c2-c3 c4={};c5={} for i,j in c1.i...
37
934
19,660,800
230739112
n,m = map(int,input().split()); Kl2 = {} Fl2 = {} Fl1 = {}; Kl1 = {}; for i in range(n): a,b = map(int,input().split()); temp = a*1000+b; try: Fl2[temp]+=1; except: Fl2[temp]=1; try: Fl1[b]+=1; except: Fl1[b]=1; r2 = 0 for i in range(m): a,b = map(int,input(...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Matchmaker
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a m...
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly....
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of b...
null
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
[{"input": "3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2", "output": "3 2"}, {"input": "2 2\n1 2\n2 1\n3 4\n5 1", "output": "1 0"}]
1,100
["*special", "greedy", "sortings"]
37
[{"input": "3 4\r\n1 2\r\n3 4\r\n2 4\r\n5 4\r\n2 4\r\n1 1\r\n1 2\r\n", "output": "3 2\r\n"}, {"input": "2 2\r\n1 2\r\n2 1\r\n3 4\r\n5 1\r\n", "output": "1 0\r\n"}, {"input": "6 7\r\n2 1\r\n2 2\r\n2 1\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n2 2\r\n2 2\r\n1 2\r\n2 2\r\n1 1\r\n1 2\r\n", "output": "3 3\r\n"}, {"input": "6 7\r\n2 1\...
false
stdio
null
true
157/A
157
A
Python 3
TESTS
8
310
0
163361279
n = int(input()) board = [[int(i) for i in input().split()] for j in range(n)] count = 0 for i in range(n): for j in range(n): a = 0 b = 0 for v in range(n): for z in range(n): if v == i: a += board[v][z] if z == j: ...
49
92
0
149236800
n = int(input()) a = [list(map(int, input().split())) for _ in range(n)] def f(i, j): column, row = 0, 0 for k in range(n): row += a[i][k] column += a[k][j] if column > row: return True return False ans = 0 for i in range(n): for j in range(n): if f(i, j): ...
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
571/B
571
B
PyPy 3-64
TESTS
10
342
15,462,400
144627088
from random import * import itertools def solve(): n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) if n % k == 0: ans = 0 for i in range(0, n, n // k): ans += a[i + n // k - 1] - a[i] print(ans) return l1 = (n + k - 1) // k l...
52
966
96,460,800
12983854
inf = 10 ** 10 n, k = map(int, input().split()) a = sorted(map(int, input().split())) L, M = n // k, n % k dp = [[0] * (k - M + 1) for i in range(M + 1)] for i in range(M + 1): for j in range(k - M + 1): pos = i * (L + 1) + j * L dp[i][j] = min((dp[i - 1][j] + a[pos - 1] - a[pos - L - 1] if i else i...
Codeforces Round 317 [AimFund Thanks-Round] (Div. 1)
CF
2,015
2
256
Minimization
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You need to permute the array elements so that value $$\sum_{i=1}^{n-k}|A[i]-A[i+k]|$$
The first line contains two integers n, k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ min(5000, n - 1)). The second line contains n integers A[1], A[2], ..., A[n] ( - 109 ≤ A[i] ≤ 109), separate by spaces — elements of the array A.
Print the minimum possible value of the sum described in the statement.
null
In the first test one of the optimal permutations is 1 4 2. In the second test the initial order is optimal. In the third test one of the optimal permutations is 2 3 4 4 3 5.
[{"input": "3 2\n1 2 4", "output": "1"}, {"input": "5 2\n3 -5 3 -5 3", "output": "0"}, {"input": "6 3\n4 3 4 3 2 5", "output": "3"}]
2,000
["dp", "greedy", "sortings"]
52
[{"input": "3 2\r\n1 2 4\r\n", "output": "1\r\n"}, {"input": "5 2\r\n3 -5 3 -5 3\r\n", "output": "0\r\n"}, {"input": "6 3\r\n4 3 4 3 2 5\r\n", "output": "3\r\n"}, {"input": "2 1\r\n1 100\r\n", "output": "99\r\n"}, {"input": "4 3\r\n1 2 4 8\r\n", "output": "1\r\n"}, {"input": "5 2\r\n1 2 8 8 16\r\n", "output": "9\r\n"},...
false
stdio
null
true
571/B
571
B
PyPy 3-64
TESTS
10
327
15,462,400
144626059
from random import * import itertools def solve(): n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) l1 = (n + k - 1) // k if n % k == 0: ans = 0 for i in range(0, n, l1): ans += a[i + l1 - 1] - a[i] print(ans) return l2 = n //...
52
701
26,316,800
12697806
def solve(n, k, As): As.sort() m, r = divmod(n, k) dp = [0] * (r + 1) for i in range(1, k): im = i * m new_dp = [0] * (r + 1) new_dp[0] = dp[0] + As[im] - As[im - 1] for h in range(1, min(i, r) + 1): new_dp[h] = max(dp[h], dp[h - 1]) + As[im + h] - As[im + h -...
Codeforces Round 317 [AimFund Thanks-Round] (Div. 1)
CF
2,015
2
256
Minimization
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You need to permute the array elements so that value $$\sum_{i=1}^{n-k}|A[i]-A[i+k]|$$
The first line contains two integers n, k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ min(5000, n - 1)). The second line contains n integers A[1], A[2], ..., A[n] ( - 109 ≤ A[i] ≤ 109), separate by spaces — elements of the array A.
Print the minimum possible value of the sum described in the statement.
null
In the first test one of the optimal permutations is 1 4 2. In the second test the initial order is optimal. In the third test one of the optimal permutations is 2 3 4 4 3 5.
[{"input": "3 2\n1 2 4", "output": "1"}, {"input": "5 2\n3 -5 3 -5 3", "output": "0"}, {"input": "6 3\n4 3 4 3 2 5", "output": "3"}]
2,000
["dp", "greedy", "sortings"]
52
[{"input": "3 2\r\n1 2 4\r\n", "output": "1\r\n"}, {"input": "5 2\r\n3 -5 3 -5 3\r\n", "output": "0\r\n"}, {"input": "6 3\r\n4 3 4 3 2 5\r\n", "output": "3\r\n"}, {"input": "2 1\r\n1 100\r\n", "output": "99\r\n"}, {"input": "4 3\r\n1 2 4 8\r\n", "output": "1\r\n"}, {"input": "5 2\r\n1 2 8 8 16\r\n", "output": "9\r\n"},...
false
stdio
null
true
155/B
155
B
PyPy 3-64
TESTS
3
122
0
205443537
t = int(input()) n = 1 c = 0 a = [0] * t for _ in range(t): l, r = list(map(int , input().split())) l,r = r, l a[_] = [l , r] for el in range(t-1 , -1 , -1): if(n > 0): c += a[el][1] n -= 1 n += a[el][0] else: break print(c)
39
248
1,331,200
194854242
n = int(input()) non_free_cards = [] extra = 1 total = 0 for i in range(n): x1, x2 = tuple([int(x) for x in input().split()]) if(x2 == 0): non_free_cards.append(x1) else: extra += (x2 - 1) total += x1 non_free_cards = sorted(non_free_cards)[::-1] total += sum(non_free_cards[:extra]) print(total)
Codeforces Round 109 (Div. 2)
CF
2,012
2
256
Combination
Ilya plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom co...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of cards Ilya has. Each of the next n lines contains two non-negative space-separated integers — ai and bi (0 ≤ ai, bi ≤ 104) — the numbers, written at the top and the bottom of the i-th card correspondingly.
Print the single number — the maximum number of points you can score in one round by the described rules.
null
In the first sample none of two cards brings extra moves, so you should play the one that will bring more points. In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.
[{"input": "2\n1 0\n2 0", "output": "2"}, {"input": "3\n1 0\n2 0\n0 2", "output": "3"}]
1,100
["greedy", "sortings"]
39
[{"input": "2\r\n1 0\r\n2 0\r\n", "output": "2\r\n"}, {"input": "3\r\n1 0\r\n2 0\r\n0 2\r\n", "output": "3\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n2 0\r\n3 0\r\n5 1\r\n", "output": "8\r\n"}, {"input": "7\r\n9 1\r\n8 1\r\n9 0\r\n9 1\r\n5 1\r\n1 1\r\n0 1\r\n", "output": "41\r\n"}, {"input": "7\r\n5 0\r\n4 0\r\n3 0\r\n5 2\r\...
false
stdio
null
true
990/C
990
C
Python 3
TESTS
6
467
0
39212329
def count(s): c=0 for i in s: if i=="(": c+=1 else: c-=1 return c d={} for i in range(int(input())): s=input().strip() if s[0]==")" and s[len(s)-1]=="(": continue c=count(s) if c in d.keys(): d[c]+=1 else: d[c]=1 ans=0 f...
30
280
30,310,400
85533512
from collections import defaultdict from sys import stdin input = stdin.readline if __name__ == '__main__': bs = defaultdict(lambda: 0) for _ in range(int(input())): s = list(map(lambda o: 1 if o == '(' else -1, input().strip())) sm = sum(s) dp = [s[0]] for i in range(1, len(s...
Educational Codeforces Round 45 (Rated for Div. 2)
ICPC
2,018
2
256
Bracket Sequences Concatenation Problem
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
null
In the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$. In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
[{"input": "3\n)\n()\n(", "output": "2"}, {"input": "2\n()\n()", "output": "4"}]
1,500
["implementation"]
30
[{"input": "3\r\n)\r\n()\r\n(\r\n", "output": "2\r\n"}, {"input": "2\r\n()\r\n()\r\n", "output": "4\r\n"}, {"input": "7\r\n()(\r\n)\r\n)(\r\n())\r\n(((\r\n()()()\r\n()\r\n", "output": "6\r\n"}, {"input": "6\r\n(\r\n((\r\n(((\r\n))))\r\n)))))\r\n))))))\r\n", "output": "0\r\n"}, {"input": "9\r\n(()\r\n((())\r\n(\r\n)\r\n...
false
stdio
null
true
61/D
61
D
PyPy 3-64
TESTS
40
1,216
85,196,800
189071952
from collections import defaultdict g=defaultdict(set) co=defaultdict(int) n=int(input()) ans=0 for i in range(n-1): q,w,e=map(int,input().split()) g[q].add(w) g[w].add(q) co[str(q)+str(w)]=e co[str(w)+str(q)]=e ans+=e ma_cost=0 ans*=2 def dfs(vis,node,cost=0,ma_cost=0): vis.add(node) if...
56
389
14,745,600
95844375
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) adj = [[] for _ in range(n)] deg = [100] + [0] * n for u, v, w in (map(int, input().split()) for _ in range(n - 1)): adj[u - 1].append((v - 1, w)) adj[v - 1].append((u - 1, w...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too ti...
First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities. Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
null
null
[{"input": "3\n1 2 3\n2 3 4", "output": "7"}, {"input": "3\n1 2 3\n1 3 3", "output": "9"}]
1,800
["dfs and similar", "graphs", "greedy", "shortest paths", "trees"]
56
[{"input": "3\r\n1 2 3\r\n2 3 4\r\n", "output": "7\r\n"}, {"input": "3\r\n1 2 3\r\n1 3 3\r\n", "output": "9\r\n"}, {"input": "5\r\n5 3 60\r\n4 3 63\r\n2 1 97\r\n3 1 14\r\n", "output": "371\r\n"}, {"input": "3\r\n2 1 63\r\n3 1 78\r\n", "output": "204\r\n"}, {"input": "13\r\n8 2 58\r\n2 1 49\r\n13 10 41\r\n11 9 67\r\n6 4...
false
stdio
null
true
61/D
61
D
Python 3
TESTS
31
717
18,841,600
77094369
from os import sys num = int(input()) vertices=[] [vertices.append([]) for c in range(num+1)] weightUnder=[-1]*(num+1) visited = [-1]*(num+1) sys.setrecursionlimit(100000) def calculateWeight(i): totalWeightUnder=0 visited[i]=1 for (vert,weight) in vertices[i]: if visited[vert]==-1: tot...
56
389
19,046,400
170690765
import collections from email.policy import default import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os ###################################################################################### #--------------------------------------func------------------------------...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too ti...
First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities. Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
null
null
[{"input": "3\n1 2 3\n2 3 4", "output": "7"}, {"input": "3\n1 2 3\n1 3 3", "output": "9"}]
1,800
["dfs and similar", "graphs", "greedy", "shortest paths", "trees"]
56
[{"input": "3\r\n1 2 3\r\n2 3 4\r\n", "output": "7\r\n"}, {"input": "3\r\n1 2 3\r\n1 3 3\r\n", "output": "9\r\n"}, {"input": "5\r\n5 3 60\r\n4 3 63\r\n2 1 97\r\n3 1 14\r\n", "output": "371\r\n"}, {"input": "3\r\n2 1 63\r\n3 1 78\r\n", "output": "204\r\n"}, {"input": "13\r\n8 2 58\r\n2 1 49\r\n13 10 41\r\n11 9 67\r\n6 4...
false
stdio
null
true
354/A
354
A
Python 3
TESTS
14
311
9,523,200
24901050
#print("Allah is the most gracious and the Most Marchiful") num,l,r,ql,qr,=map(int, input().split()) ara=[int(i) for i in input().split()] for i in range(1,num,1): ara[i]=ara[i]+ara[i-1] ans=10**8 for i in range(0,num+1,1): tr=num-i cl=ara[i-1] if i>0 else 0 cr=ara[num-1]-cl pl=max(0,i-tr-1) pr=...
23
77
14,336,000
210296397
if __name__ == "__main__": n, l, r, ql, qr = map(int, input().split()) w = list(map(int, input().split())) s = [0] * (n+1) for i in range(1, n+1): s[i] = s[i-1] + w[i-1] res = float("inf") for i in range(n+1): v = l * s[i] + r * (s[n] - s[i]) if i > n - i: v...
Codeforces Round 206 (Div. 1)
CF
2,013
1
256
Vasya and Robot
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya needs to collect all these items, however he won't do it by himself. He us...
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104). The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
In the single line print a single number — the answer to the problem.
null
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and t...
[{"input": "3 4 4 19 1\n42 3 99", "output": "576"}, {"input": "4 7 2 3 9\n1 2 3 4", "output": "34"}]
1,500
["brute force", "greedy", "math"]
23
[{"input": "3 4 4 19 1\r\n42 3 99\r\n", "output": "576\r\n"}, {"input": "4 7 2 3 9\r\n1 2 3 4\r\n", "output": "34\r\n"}, {"input": "2 100 100 10000 10000\r\n100 100\r\n", "output": "20000\r\n"}, {"input": "2 3 4 5 6\r\n1 2\r\n", "output": "11\r\n"}, {"input": "1 78 94 369 10000\r\n93\r\n", "output": "7254\r\n"}, {"inpu...
false
stdio
null
true
157/A
157
A
Python 3
TESTS
8
218
0
57583170
a=[] x=[] y=[] count=0 b=int(input()) if b==1: asdf=input() print("0") else: for i in range (b): temp=list(map(int,input().split())) a.append(temp) y.append(sum(temp)) for i in range (b): temp=0 for j in range(b): temp+=a[j][i] x.append(temp) ...
49
92
0
149878696
def getcol(matrix,column): return list(map(lambda x: x[column],matrix)) l = [] x=0 for _ in range(int(input())): l.append(list(map(int,input().split()))) for i in range(len(l)): for j in range(len(l[i])): x+=int(sum(getcol(l,j)) > sum(l[i])) print(x)
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
157/A
157
A
Python 3
TESTS
8
124
6,963,200
115961752
l=[] n=int(input()) for i in range(n): l.append(list(map(int,input().split()))) l2 = [x[:] for x in l] for i in range(n): for j in range(n): l[i][j]=int(l2[j][i]) c=0 for i in l2: for j in l: if sum(i)>sum(j): c+=1 print(c)
49
92
0
153817481
n = int(input()) d = [list(map(int, input().split())) for _ in range(n)] e = list(zip(*d)) c = 0 for i in range(n): for j in range(n): if sum(d[i]) < sum(e[j]): c += 1 print(c)
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
157/A
157
A
PyPy 3
TESTS
8
280
3,584,000
108653478
from sys import stdin,stdout stdin.readline def mp(): return list(map(int, stdin.readline().strip().split())) def it():return int(stdin.readline().strip()) from pprint import pprint n=it() v=[] for i in range(n): v+= [mp()] x = [[[0,0] for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): for...
49
92
0
163362797
n = int(input()) board = [[int(i) for i in input().split()] for j in range(n)] count = 0 for i in range(n): for j in range(n): a = 0 b = 0 for z in range(n): a += board[z][j] b += board[i][z] if a > b: count += 1 print(count)
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
609/C
609
C
PyPy 3-64
TESTS
9
46
0
196366284
n = int(input()) l = list(map(int, input().split())) # print(l) avg = sum(l) / len(l) # print(avg) from math import * # for i in l: # print(i-avg) print(sum(floor(l[i]-avg) for i in range(len(l)) if l[i]-avg>=1))
58
78
12,800,000
205650158
n = int(input()) # Number of servers m = list(map(int, input().split())) # Tasks assigned to each server # Calculate the average number of tasks per server (a) and rounded-up average (b) a, b = sum(m) // n, (sum(m) + n - 1) // n # Calculate the maximum imbalance and print the result print(max(sum(a - x for x in m i...
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
609/C
609
C
Python 3
TESTS
12
124
3,584,000
66424555
n = int(input()) a = list(map(int, input().split())) a.sort() sm = sum(a) whole = sm // n if sm: bigger = sm % whole else: bigger = 0 smaller = n - bigger s = 0 for i in range(smaller): s += abs(a[i] - whole) for i in range(smaller, n): s += abs(a[i] - whole - 1) print(s // 2)
58
93
7,372,800
195573988
from math import ceil, floor n = int(input()) arr = list(map(int, input().split())) avg = sum(arr) / n avg_ceil = ceil(avg) avg_floor = floor(avg) # arr.sort() cnt_up = 0 cnt_dwn = 0 for a in arr: if a < avg_floor: cnt_dwn += avg_floor - a elif a > avg_ceil: cnt_up += a - avg_ceil print(...
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
609/C
609
C
Python 3
TESTS
9
46
4,505,600
132762095
import math n = int(input()) values = list(map(int,input().split())) values.sort(reverse = True) ans=0 mean = math.ceil(sum(values)/n) for v in values: if v > mean: ans+= (v-mean) else: break print(ans)
58
93
13,516,800
175342331
n=int(input()) a=list(map(int,input().split())) sm=sum(a) L=sm//n R=(sm+n-1)//n res=0 res2=0 for i in a: if i<=L: res+=L-i else: res2+=i-R print(max(res,res2))
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
886/F
886
F
PyPy 3
TESTS
4
342
29,696,000
79363907
from fractions import Fraction class Point: def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return "Point({}, {})".format(self.x, self.y) def __eq__(self, other): return self.x == other.x and self.y == other.y def __neg__(self): return Poi...
51
794
19,046,400
211944348
from fractions import Fraction import time class Point: def __init__(self, x, y): self.x = x self.y = y def to_tuple(self): return (self.x, self.y) def __repr__(self): return "Point({}, {})".format(self.x, self.y) def __eq__(self, other): return self.to_tuple...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Symmetric Projections
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines. Multiset is a set where equal elements are allowed. Multiset is called symmetric, if there is a point P on t...
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set. Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
If there are infinitely many good lines, print -1. Otherwise, print single integer — the number of good lines.
null
Picture to the first sample test: In the second sample, any line containing the origin is good.
[{"input": "3\n1 2\n2 1\n3 3", "output": "3"}, {"input": "2\n4 3\n1 2", "output": "-1"}]
2,900
["geometry"]
51
[{"input": "3\r\n1 2\r\n2 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "2\r\n4 3\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n0 4\r\n1 5\r\n2 1\r\n3 2\r\n4 3\r\n5 0\r\n", "output": "5\r\n"}, {"input": "1\r\n5 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 4\r\n1 2\r\n0 0\r\n-2 -4\r\n", "output": "1\r\n"}, {"input"...
false
stdio
null
true
609/C
609
C
Python 3
TESTS
9
31
0
148526971
n=int(input()) a=list(map(int,input().split())) q=(sum(a)+n-1)//n w,e=0,0 for i in a: if i>q: w+=i-q else: e+=q-i print(min(w,e))
58
93
13,721,600
172253539
n=int(input()) arr=list(map(int,input().split())) if sum(arr)%n==0: p=sum(arr)//n print(sum([max(el-p,0) for el in arr])) else : p=sum(arr)//n q=sum(arr)-p*n b=[p]*(n) for i in range(q): b[i]+=1 b.sort() arr.sort() ans=0 for a,i in zip(arr,b): ans+=max(0,i-a) ...
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
609/C
609
C
PyPy 3
TESTS
9
77
0
145552310
from sys import stdin, stdout from math import ceil def obtain(seq, r, m, p): for i in range(p, -1, -1): if r==0 or seq[i]<=m: break off = seq[i]-m seq[i] -= off r -= off if seq[i]==m: p -= 1 return (r, p) res = 0 n = int(stdin.readline()) seq = sorted(map(...
58
93
14,233,600
174732087
import sys input = sys.stdin.readline n = int(input()) mi = list(map(int,input().split())) s = sum(mi) if s%n==0: ans = 0 for i in range(n): ans+=abs((s//n)-mi[i]) print(ans//2) else: ans = 0 d = s%n p = [(s//n) for i in range(n)] for i in range(1,d+1): p[-i]+=1 mi.sort()...
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
609/C
609
C
Python 3
TESTS
9
62
0
32543278
from math import ceil n = int(input()) s = 0 a = list(map(int, input().split())) sr = ceil(sum(a) / n) for i in a: if i - sr > 0: s += i - sr print(s)
58
108
7,372,800
14884066
n, m = int(input()), list(map(int, input().split())) a, b = sum(m) // n, (sum(m) + n - 1) // n print(max(sum(a - x for x in m if x < a), sum(x - b for x in m if x > b)))
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
609/C
609
C
PyPy 3-64
TESTS
9
61
0
212139390
from sys import stdin,stdout input = stdin.readline from math import ceil n = int(input()) m = list(map(int,input().split())) sum1 = sum(m) x = ceil(sum1/n) ans = 0 for i in range(n): if m[i] > x: ans += m[i]-x print(ans)
58
109
7,372,800
14886505
def main(): def solve2(): a = m[:] cnt = 0 t = 1 if Sum % n else 0 while max(a) - min(a) != t: mn = a.index(min(a)) mx = a.index(max(a)) a[mn] += 1 a[mx] -= 1 cnt += 1 return cnt n = int(input()) m = list(map...
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true