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
314/C
314
C
Python 3
TESTS
5
92
0
5185644
n = input() s = input() a = list(map(int, s.strip().split())) d = [0]*len(a) sumn = 0 for i in reversed(range(len(a))): cnt = a[i] seen = set() for j in reversed(range(i + 1, len(a))): if a[j] >= a[i]: if a[j] not in seen: cnt += d[j] * a[i] seen.add(a[j])...
24
310
34,406,400
148074888
BIT = [0] * (1000001) dp = [0] * (1000001) MOD = 1000000007 ans = 0 def query(p): ret = 0 i = p while i: ret = (ret + BIT[i]) % MOD i -= i & -i return ret def update(p, v): i = p while (i <= 1000000): BIT[i] = (BIT[i] + v) % MOD i += i & -i N = int(input()) arr = ...
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Subsequences
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not excee...
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106).
In the single line print the answer to the problem modulo 1000000007 (109 + 7).
null
null
[{"input": "1\n42", "output": "42"}, {"input": "3\n1 2 2", "output": "13"}, {"input": "5\n1 2 3 4 5", "output": "719"}]
2,000
["data structures", "dp"]
24
[{"input": "1\r\n42\r\n", "output": "42\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "13\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "719\r\n"}, {"input": "4\r\n11479 29359 26963 24465\r\n", "output": "927446239\r\n"}, {"input": "5\r\n5706 28146 23282 16828 9962\r\n", "output": "446395832\r\n"}, {"input": "6\r\n49...
false
stdio
null
true
711/D
711
D
PyPy 3-64
TESTS
6
311
36,659,200
185405594
from collections import deque def f0(arr): def topsort(): q = deque() for x, x_in in enumerate(ind): if x_in == 0: q.append(x) c = 0 while len(q): x = q.popleft() c += 1 for y in outd[x]: ind[y] -= 1 ...
131
139
19,456,000
207096289
n = int(input()) w = [int(i) - 1 for i in input().split()] ti = [0] * n t, m = 0, n res = 1 mod = int(1e9 + 7) def qmi(a, k, mod) -> int : res = 1 while k > 0: if (k & 1) == 1: res = res * a % mod k >>= 1 a = a * a % mod return res for i in range(n): if ti[i] >...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Directed Roads
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (ai ≠ i). ZS the Coder can flip the direction of any road in Udayland, i.e. if it g...
The first line of the input contains single integer n (2 ≤ n ≤ 2·105) — the number of towns in Udayland. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n, ai ≠ i), ai denotes a road going from town i to town ai.
Print a single integer — the number of ways to flip some set of the roads so that the resulting whole set of all roads is not confusing. Since this number may be too large, print the answer modulo 109 + 7.
null
Consider the first sample case. There are 3 towns and 3 roads. The towns are numbered from 1 to 3 and the roads are $$1 \rightarrow 2$$, $$2\rightarrow3$$, $$\overset{3}{\rightarrow}1$$ initially. Number the roads 1 to 3 in this order. The sets of roads that ZS the Coder can flip (to make them not confusing) are {1}, ...
[{"input": "3\n2 3 1", "output": "6"}, {"input": "4\n2 1 1 1", "output": "8"}, {"input": "5\n2 4 2 5 3", "output": "28"}]
1,900
["combinatorics", "dfs and similar", "graphs", "math"]
131
[{"input": "3\r\n2 3 1\r\n", "output": "6\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "8\r\n"}, {"input": "5\r\n2 4 2 5 3\r\n", "output": "28\r\n"}, {"input": "4\r\n2 1 4 3\r\n", "output": "4\r\n"}, {"input": "7\r\n2 3 4 1 6 5 4\r\n", "output": "56\r\n"}, {"input": "20\r\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1...
false
stdio
null
true
962/A
962
A
Python 3
TESTS
6
155
20,172,800
37654959
n = int(input()) solved_count = input().split(' ') solved_count = [int(i) for i in solved_count] total_count = int(sum(solved_count) / 2) temp = 0 for i in range(n): temp += solved_count[i] if temp >= total_count: print(i + 1) break
106
93
20,070,400
165343454
from bisect import bisect_left n = int(input()) a = list(map(int, input().split())) for i in range(1, n): a[i] += a[i-1] if a[-1] % 2: mid = (a[-1]+1)//2 else: mid = a[-1]//2 print(bisect_left(a, mid)+1)
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$...
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th...
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r...
false
stdio
null
true
961/E
961
E
PyPy 3
TESTS
8
842
42,905,600
123412240
import types _atcoder_code = """ # Python port of AtCoder Library. __all__ = ["string","lazysegtree","convolution","maxflow","modint" ,"mincostflow","segtree","_scc","_math","math","dsu","twosat","fenwicktree","scc","_bit","lca","unverified","graph","matrix","algebra","combinatorics"] __version__ = '0.0.1' """ at...
30
655
22,528,000
100875670
from bisect import bisect_left, bisect_right n = int(input()) a = list(map(int, input().split())) ans = 0 #ans = slow_test() class fenwick(): """ This Tree Data Structure speeds up caliculating summations of partial sum and also updating subsets of sequences. Both queries finish in logarithmic times. ...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.
Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.
null
Possible pairs in the second example: 1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1); 2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2); 3. x = 1, y...
[{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}]
1,900
["data structures"]
30
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000...
false
stdio
null
true
962/A
962
A
Python 3
TESTS
6
140
12,902,400
117423440
x=int(input()) y=[int(i) for i in input().split()] s=sum(y) check=0 for i in range(x): check+=y[i] if(check>=int(s/2)): print(i+1) break
106
93
20,275,200
216128601
n=int(input()) ll=list(map(int,input().split())) k=sum(ll)/2 c=0 for i in range(n): c+=ll[i] if c>=k: print(i+1) exit()
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$...
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th...
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r...
false
stdio
null
true
962/E
962
E
PyPy 3
TESTS
10
1,653
11,468,800
57718027
#Bhargey Mehta (Junior) #DA-IICT, Gandhinagar import sys, math, queue #sys.stdin = open('input.txt', 'r') MOD = 998244353 sys.setrecursionlimit(1000000) n = int(input()) p, r, b = [], [], [] for i in range(n): x, y = input().split() x = int(x) if y == 'P': p.append(x) elif y == 'R': r.append(x) els...
45
997
7,065,600
37253924
def inpmap(): return map(int, input().split()) n = int(input()) b, r, p = None, None, None res = 0 mr = -1 mb = -1 for i in range(n): ix, t = input().split() ix = int(ix) if t != 'R': if b is not None: res += ix - b mb = max(mb, ix - b) b = ix if t != 'B': ...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $$$Ox$$$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $$$Ox$$$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recen...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^{5}$$$) — the number of cities. The following $$$n$$$ lines contains an integer $$$x_i$$$ and the letter $$$c_i$$$ ($$$-10^{9} \le x_i \le 10^{9}$$$) — the coordinate of the city and its type. If the city belongs to Byteland, $$$c_i$$$ equals ...
Print the minimal total length of such set of cables, that if we delete all Berland cities ($$$c_i$$$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($$$c_i$$$='B'), it will be possible to find a way from an...
null
In the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $$$5 + 3 + 4 = 12$$$. In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the n...
[{"input": "4\n-5 R\n0 P\n3 P\n7 B", "output": "12"}, {"input": "5\n10 R\n14 B\n16 B\n21 R\n32 R", "output": "24"}]
2,200
["constructive algorithms", "greedy"]
45
[{"input": "4\r\n-5 R\r\n0 P\r\n3 P\r\n7 B\r\n", "output": "12\r\n"}, {"input": "5\r\n10 R\r\n14 B\r\n16 B\r\n21 R\r\n32 R\r\n", "output": "24\r\n"}, {"input": "10\r\n66 R\r\n67 R\r\n72 R\r\n73 R\r\n76 R\r\n78 B\r\n79 B\r\n83 B\r\n84 B\r\n85 P\r\n", "output": "26\r\n"}, {"input": "10\r\n61 R\r\n64 R\r\n68 R\r\n71 R\r\n...
false
stdio
null
true
962/A
962
A
Python 3
TESTS
6
109
13,721,600
163408960
n=int(input()) num=list(map(int,input().split())) total=sum(num) avg=total//2 s=0 for i in range(n): s+=num[i] if(s>=avg): ans=i+1 break # print(s) print(ans)
106
93
20,377,600
200374819
n = int(input()) lst = list(map(int, input().split())) tot = sum(lst) target = -(-tot // 2) subtot = 0 for i, x in enumerate(lst): subtot += x if subtot >= target: print(i+1) break
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$...
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th...
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r...
false
stdio
null
true
962/A
962
A
Python 3
TESTS
6
109
21,401,600
116141336
from collections import defaultdict, deque from heapq import heappush, heappop from math import inf ri = lambda : map(int, input().split()) def solve(): n = int(input()) A = list(ri()) total = sum(A) curr = 0 for i in range(n): curr += A[i] if curr >= total // 2: print(...
106
93
21,504,000
198565419
# -*- coding: utf-8 -*- def solve(): n = int(input()) a = list(map(int, input().split(' '))) sum = 0 for i in range(n): sum += a[i] sum = (sum + 1) // 2 cur = 0 for i in range(n): cur += a[i] if (cur >= sum): print(i + 1) return def main...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$...
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th...
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r...
false
stdio
null
true
962/A
962
A
Python 3
TESTS
6
155
20,070,400
37233300
n=int(input()) List=list(map(int,input().split())) s=int(sum(List)/2) d=1 k=List[0] while (k<s): k+=List[d] d+=1 print (d)
106
108
12,595,200
192760342
# LUOGU_RID: 101739141 n, *a = map(int, open(0).read().split()) s = (sum(a) + 1) // 2 t = 0 for i in range(n): t += a[i] if t >= s: exit(print(i + 1))
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$...
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th...
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r...
false
stdio
null
true
460/C
460
C
PyPy 3-64
TESTS
7
202
17,305,600
144833427
#m days from sys import stdin input=stdin.readline class BIT(): def __init__(self, n): self.n = n self.tree = [0] * (n + 1) def sum(self, i): ans = 0 i += 1 while i > 0: ans += self.tree[i] i -= (i & (-i)) return ans def update(self, i, value): i += 1 while i <= self.n: self.tree[i] += va...
43
109
20,992,000
208845468
import sys RI = lambda: map(int, sys.stdin.buffer.readline().split()) n, m, w = RI() nums = list(RI()) d = [0] * n d[0] = nums[0] for i in range(1, n): d[i] = nums[i] - nums[i - 1] # 校验min(a)为x能不能行 def check(x): if min(nums) >= x: return True dd = d[:] # 先从左往右来一遍 c_left = c_right = a = 0 for i in rang...
Codeforces Round 262 (Div. 2)
CF
2,014
2
256
Present
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti...
The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the maximum final height of the smallest flower.
null
In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.
[{"input": "6 2 3\n2 2 2 2 1 1", "output": "2"}, {"input": "2 5 1\n5 8", "output": "9"}]
1,700
["binary search", "data structures", "greedy"]
43
[{"input": "6 2 3\r\n2 2 2 2 1 1\r\n", "output": "2\r\n"}, {"input": "2 5 1\r\n5 8\r\n", "output": "9\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "2\r\n"}, {"input": "3 2 3\r\n999999998 999999998 999999998\r\n", "output": "1000000000\r\n"}, {"input": "10 8 3\r\n499 498 497 497 497 497 497 497 498 499\r\n", "output": "...
false
stdio
null
true
459/B
459
B
PyPy 3-64
TESTS
5
109
21,196,800
196173794
num = int(input()) arr = [int(x) for x in input().split()] maximum = max(arr) minimum = min(arr) total1 = arr.count(maximum) total2 = arr.count(minimum) if maximum == minimum: total1 = total1/2 total2 = total2/2 print((maximum-minimum),int(total1*total2))
58
109
23,142,400
164170793
def pashmak_and_flowers(): arr_length = int(input()) flowers = list(map(int, input().split(" "))) high = max(flowers) low = min(flowers) max_diff = high - low high_count = 0 low_count = 0 if low != high: for element in flowers: high_count += element == high ...
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
459/B
459
B
Python 3
TESTS
5
93
26,521,600
226854613
from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin n = int(stream.readline()) n_arr = [int(i) for i in stream.readline().split()] minn = min(n_arr) maxn = max(n_arr) comb = (n_arr.count(minn) * n_arr.count(maxn)) if minn != maxn else n_arr.count(minn) - 1 print(max...
58
109
28,672,000
227582732
n = int(input()) beauty_numbers = list(map(int, input().split())) mini = min(beauty_numbers) maxi = max(beauty_numbers) maximum_difference = maxi - mini if maximum_difference == 0: number_of_ways = (n - 1) * (n) // 2 else: number_of_ways = beauty_numbers.count(mini) * beauty_numbers.count(maxi) print(maximum_di...
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
459/B
459
B
PyPy 3-64
TESTS
5
109
22,528,000
172368450
kol=int(input()) a=list(map(int, input().split(' '))) count=0 lim=min(a) r=0 d=0 m=max(a) if max(a)-min(a)==0 and max(a)==min(a): print('0'+' '+'1') else: count=a.count(m) d=a.count(lim) r=(m-lim)*count*d print(str(m-lim)+' '+str(count*d))
58
109
28,672,000
230574076
n = int(input()) beauties = list(map(int, input().split())) max_beauty = max(beauties) min_beauty = min(beauties) max_count = beauties.count(max_beauty) min_count = beauties.count(min_beauty) if max_beauty == min_beauty: max_diff = 0 ways = max_count * (max_count - 1) // 2 else: max_diff = max_beauty - mi...
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
962/A
962
A
Python 3
TESTS
6
124
13,721,600
176969012
n=int(input()) x=list(map(int,input().split())) z=sum(x) y=0 for i in range(n): y+=x[i] if y>=(z//2)+1 and z%2!=0: print(i+1) break elif y>=(z//2): print(i+1) break
106
108
13,107,200
158128369
def main_function(): n = int(input()) a = [int(i) for i in input().split(" ")] sum_a = sum(a) half_of_a = sum_a / 2 counter = 0 for i in range(len(a)): counter += a[i] if counter >= half_of_a: print(i + 1) break if __name__ == '__main__': ma...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first. On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$...
Print the index of the day when Polycarp will celebrate the equator.
null
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th...
[{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}]
1,300
["implementation"]
106
[{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r...
false
stdio
null
true
962/E
962
E
Python 3
TESTS
2
93
0
49640749
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n = mint() m = dict() M = dict() for i in range(n): a = minp().split() b = int(a[0]) m[a[1]] = min(m.get(a[1], 100000000000000000),b) M[a[1]] = max(M.get(a...
45
1,060
7,065,600
37237422
n=int(input()) last_r=None last_b=None last_p=None ans=0 max_r=0 max_b=0 max_p=0 for _ in range(n): s=input().split() x=int(s[0]) c=s[1] if c=='B': if last_b!=None: ans+=x-last_b max_b=max(max_b,x-last_b) last_b=x if c=='R': if last_r!=None: ...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $$$Ox$$$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $$$Ox$$$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recen...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^{5}$$$) — the number of cities. The following $$$n$$$ lines contains an integer $$$x_i$$$ and the letter $$$c_i$$$ ($$$-10^{9} \le x_i \le 10^{9}$$$) — the coordinate of the city and its type. If the city belongs to Byteland, $$$c_i$$$ equals ...
Print the minimal total length of such set of cables, that if we delete all Berland cities ($$$c_i$$$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($$$c_i$$$='B'), it will be possible to find a way from an...
null
In the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $$$5 + 3 + 4 = 12$$$. In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the n...
[{"input": "4\n-5 R\n0 P\n3 P\n7 B", "output": "12"}, {"input": "5\n10 R\n14 B\n16 B\n21 R\n32 R", "output": "24"}]
2,200
["constructive algorithms", "greedy"]
45
[{"input": "4\r\n-5 R\r\n0 P\r\n3 P\r\n7 B\r\n", "output": "12\r\n"}, {"input": "5\r\n10 R\r\n14 B\r\n16 B\r\n21 R\r\n32 R\r\n", "output": "24\r\n"}, {"input": "10\r\n66 R\r\n67 R\r\n72 R\r\n73 R\r\n76 R\r\n78 B\r\n79 B\r\n83 B\r\n84 B\r\n85 P\r\n", "output": "26\r\n"}, {"input": "10\r\n61 R\r\n64 R\r\n68 R\r\n71 R\r\n...
false
stdio
null
true
279/C
279
C
PyPy 3-64
TESTS
4
154
0
202448606
import sys input = sys.stdin.readline from bisect import bisect n, m = map(int, input().split()) g = [0] + list(map(int, input().split())) w = [(0, 0)] d = [0] a = 1 for i in range(1, n): if g[i] != g[i-1]: w.append((g[i], i)) for i in range(1, len(w)-1): if a == 1: if w[i][0] > w[i+1][0]: ...
35
1,652
14,131,200
225855222
#https://codeforces.com/contest/279/submission/64890159 n,m = map(int,input().split()) Arr = list(map(int,input().split())) up = [i for i in range(n)] down = [i for i in range(n)] for i in range(1,n): if Arr[i-1]<=Arr[i]: up[i] = up[i-1] if Arr[i-1]>=Arr[i]: down[i] = down[i-1] for i in range...
Codeforces Round 171 (Div. 2)
CF
2,013
2
256
Ladder
You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the correspon...
The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element. The following m lines contain the description of the queries. The ...
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
null
null
[{"input": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "output": "Yes\nYes\nNo\nYes\nNo\nYes"}]
1,700
["dp", "implementation", "two pointers"]
35
[{"input": "8 6\r\n1 2 1 3 3 5 2 1\r\n1 3\r\n2 3\r\n2 4\r\n8 8\r\n1 4\r\n5 8\r\n", "output": "Yes\r\nYes\r\nNo\r\nYes\r\nNo\r\nYes\r\n"}, {"input": "1 1\r\n6\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "2 5\r\n1 1\r\n1 2\r\n2 2\r\n2 2\r\n1 2\r\n1 2\r\n", "output": "Yes\r\nYes\r\nYes\r\nYes\r\nYes\r\n"}, {"input": "10 ...
false
stdio
null
true
280/B
280
B
Python 3
TESTS
3
93
0
54017021
RI = lambda : [int(x) for x in input().split()] rw = lambda : [input().strip()] n=int(input()) l=RI() stack=[] index_stack=-1 maxo=0 i=0 while(i<n): if(index_stack==-1 or stack[index_stack]>l[i]): stack.append(l[i]) index_stack+=1 i+=1 else: maxo=max(stack[index_stack]^i,maxo) ...
56
108
16,076,800
165359851
# t = int(input()) # for _ in range(t): # s = input() # mini = 0 # maxi = 0 # good = True # for c in s: # if c == '(': # mini += 1 # maxi += 1 # elif c == ')': # mini -= 1 # maxi -= 1 # else: # mini -= 1 # ...
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
280/B
280
B
PyPy 3-64
TESTS
3
46
0
167068347
def solve(n, arr): ans, stk = 0, [] for num in arr: while stk and stk[-1] < num: stk.pop() stk.append(num) if len(stk) > 1: ans = max(ans, stk[-2] ^ stk[-1]) return ans n = int(input()) arr = list(map(int, input().split())) print(solve(n, arr))
56
124
18,636,800
197449424
import heapq; import math; from collections import deque, Counter; import sys; mod = 998244353; input = sys.stdin.readline; n = int(input()) array = list(map(int, input().split())) stack = [] ans = 0; for num in array: while stack: ans = max(ans, num ^ stack[-1]) if stack[-1] < num:...
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
715/B
715
B
PyPy 3-64
TESTS
2
46
512,000
144360228
import sys input = sys.stdin.buffer.readline def process(n, G, L, s, t): g = [[] for i in range(n+1)] m = len(G) for i in range(m): u, v, w = G[i] g[u].append([v, w, i]) g[v].append([u, w, i]) distances = [{} for i in range(n+1)] start = [[s, -1]] distances[s] = {0: [0, ...
179
483
3,891,200
98515967
from collections import defaultdict MAX = 10 ** 14 def Dijkstra(graph, s, n): visited = [False] * n d = [MAX] * n parents = {} d[s] = 0 for i in range(n): _, v = min((d[j], j) for j in range(n) if not visited[j]) visited[v] = True for u, cost in graph[v]: ...
Codeforces Round 372 (Div. 1)
CF
2,016
4
256
Complete The Graph
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg...
The first line contains five integers n, m, L, s, t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 10 000, 1 ≤ L ≤ 109, 0 ≤ s, t ≤ n - 1, s ≠ t) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively. Then, m lines describing the edges of the graph follow. i-th of th...
Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way. Otherwise, print "YES" in the first line. Next m lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. i-th of them should contain three integers ui, vi ...
null
Here's how the graph in the first sample case looks like : In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13. In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456...
[{"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"}, {"input": "2 1 123456789 0 1\n0 1 0", "output": "YES\n0 1 123456789"}, {"input": "2 1 999999999 1 0\n0 1 1000000000", "output": "NO"}]
2,300
["binary search", "constructive algorithms", "graphs", "shortest paths"]
179
[{"input": "5 5 13 0 4\r\n0 1 5\r\n2 1 2\r\n3 2 3\r\n1 4 0\r\n4 3 4\r\n", "output": "YES\r\n0 1 5\r\n2 1 2\r\n3 2 3\r\n1 4 8\r\n4 3 4\r\n"}, {"input": "2 1 123456789 0 1\r\n0 1 0\r\n", "output": "YES\r\n0 1 123456789\r\n"}, {"input": "2 1 999999999 1 0\r\n0 1 1000000000\r\n", "output": "NO\r\n"}, {"input": "4 5 10 1 2\...
false
stdio
import sys from heapq import heappush, heappop def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m, L, s, t = map(int, f.readline().split()) original_edges = {} for _ in range(m): ...
true
459/B
459
B
Python 3
TESTS
5
109
18,227,200
163633921
n = int(input()) lis = list(map(int, input().split())) lis.sort() mins = lis.count(lis[0]) maxs = lis.count(lis[-1]) if lis[0] == lis[-1]: mins = mins//2 maxs = maxs//2 print(lis[-1] - lis[0], mins * maxs)
58
124
16,486,400
183525332
n = int(input()) a = [int(i) for i in input().split()] maxa = max(a) mina = min(a) if maxa == mina: print(maxa-mina,n*(n-1)//2) else: print(maxa-mina,a.count(maxa)*a.count(mina))
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
459/B
459
B
Python 3
TESTS
5
93
17,510,400
176151214
n = int(input()) l1 = list(map(int,input().split())) l1.sort() a = l1[-1] b =l1[0] if a == b: print(a-b,1) else: ac = l1.count(a) bc = l1.count(b) print(a-b,ac*bc)
58
124
17,510,400
163693675
n=int(input()) b=list(map(int,input().split())) a=max(b) c=min(b) print(a-c,end=' ') if a!=c: print(b.count(a)*b.count(c)) else: print(b.count(a)*(b.count(a)-1)//2)
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
459/B
459
B
PyPy 3-64
TESTS
5
93
21,196,800
167801721
n = int(input()) a = [int(i) for i in input().split()] smallest = min(a) largest = max(a) if smallest == largest: print(0, (a.count(smallest) - 1) ** 2) else: print(largest - smallest, a.count(smallest) * a.count(largest))
58
124
17,510,400
176645819
n=int(input()) l=list(map(int,input().split())) if([l[0]]*n== l): print(0,n*(n-1)//2) else: a=l.count(max(l)) b=l.count(min(l)) print(max(l)-min(l) ,a*b)
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
459/B
459
B
PyPy 3-64
TESTS
5
109
25,702,400
167189150
""" ## NOTE - good question - this is somehow a 2-sum question, assking for all the combinations that can make the sum ## INFO 459_B_PashmakAndFlowers https://codeforces.com/problemset/problem/459/B ## TAGS - combinatorics - implementation - sortings - *1300 ## TESTS -in: 2 1 2 -out: 1 1 -in: 3 1 4 5 -out: 4 1 -in: ...
58
124
17,510,400
178181661
n = int(input()) a = list(map(int,input().split())) max_diff = max(a)-min(a) num_ways = a.count(max(a))*a.count(min(a)) if(max_diff == 0) : num_ways = a.count(max(a))*(a.count(max(a))-1)//2 print(max_diff,num_ways)
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
46/C
46
C
PyPy 3-64
TESTS
3
92
0
145802541
n = int(input()) init = list(input()) beg = init[0] end = init[n-1] i = 1 j = n-2 counts = 0 while i < j: if init[i] == beg: i += 1 elif init[j] == end: j -= 1 else: tmp = init[i] init[i] = init[j] init[j] = tmp counts += 1 i += 1 j -= 1 print(...
27
92
0
218384118
n=int(input()) s=input()*2 count=s.count("H")//2 print(count-max(s[i:i+count].count('H') for i in range(n)))
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
459/B
459
B
Python 3
TESTS
5
108
17,510,400
165663395
n=int(input()) a=list(map(int,input().split())) x,y=max(a),min(a) f,g=a.count(x),a.count(y) if x!=y:print(x-y,f*g) else:print(0,f-1)
58
124
18,022,400
196725340
n = int(input()) flowers = list(map(int, input().split())) max_beauty = max(flowers) min_beauty = min(flowers) if max_beauty == min_beauty: ways = n*(n-1)//2 else: max_count = flowers.count(max_beauty) min_count = flowers.count(min_beauty) ways = max_count * min_count print(max_beauty - min_beauty, w...
Codeforces Round 261 (Div. 2)
CF
2,014
1
256
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
null
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 2. choosing the first and the fifth flowers; 3. choosing the fourth and the second flowers; 4. choosing the fourth and the fifth flowers.
[{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}]
1,300
["combinatorics", "implementation", "sortings"]
58
[{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
null
true
537/D
538
D
Python 3
TESTS
4
61
4,812,800
22787595
n=int(input()) len=2*n-1 ans=[] for i in range(len): ans.append([]) for j in range(len): ans[i].append('x') ans[n-1][n-1]='o' L=[] for i in range(n): L.append([]) L[i]=input() vec=[ (i,j) for i in range(n) for j in range(n) if L[i][j]=='.' ] for i in range(n): for j in range(n): if L[i][j]=='o': for...
41
467
2,048,000
114642357
def chess(n, B): pieces = [] for r in range(n): for c in range(n): if B[r][c] == 'o': pieces.append((r, c)) m = 2*n - 1 F = [['?' for _ in range(m)] for _ in range(m)] F[n-1][n-1] = 'o' for r in range(n): for c in range(n): if B[r][c] == ...
VK Cup 2015 - Wild Card Round 2
IOI
2,015
2
256
Weird Chess
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous. Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece...
The first line contains a single integer n (1 ≤ n ≤ 50). The next n lines contain n characters each describing the position offered by Igor. The j-th character of the i-th string can have the following values: - o — in this case the field (i, j) is occupied by a piece and the field may or may not be attacked by some ...
If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2n - 1) × (2n - 1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar to the in...
null
In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight.
[{"input": "5\noxxxx\nx...x\nx...x\nx...x\nxxxxo", "output": "YES\n....x....\n....x....\n....x....\n....x....\nxxxxoxxxx\n....x....\n....x....\n....x....\n....x...."}, {"input": "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.", "output": "YES\n...........\n...........\n...........\n....x.x....\n...x...x...\n.....o.....
1,800
["brute force", "constructive algorithms", "implementation"]
41
[{"input": "5\r\noxxxx\r\nx...x\r\nx...x\r\nx...x\r\nxxxxo\r\n", "output": "YES\r\nxxxxxxxxx\r\nx...xxxxx\r\nx...xxxxx\r\nx...xxxxx\r\nxxxxoxxxx\r\nxxxxx...x\r\nxxxxx...x\r\nxxxxx...x\r\nxxxxxxxxx\r\n"}, {"input": "6\r\n.x.x..\r\nx.x.x.\r\n.xo..x\r\nx..ox.\r\n.x.x.x\r\n..x.x.\r\n", "output": "YES\r\nxxxxxxxxxxx\r\nxxxx...
false
stdio
import sys def read_grid(path, n): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines()] return [list(line) for line in lines] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r')...
true
799/C
799
C
Python 3
TESTS
3
46
0
175887825
def main(): def bs(arr, x, i, j): l = i h = j res = -1 while l <= h: m = l + (h-l)//2 if arr[m][0] <= x: res = m ...
79
483
21,299,200
125518402
''' first we find the 2 fountains with max beauty we can buy with c coins then we find 2 fountains with max beauty with d diamonds then we find 1 with c coins and 1 with d diamonds how to find? sort according to beauty and see if we can afford i + i+1 ''' from sys import stdin, stdout import sys import math import it...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow...
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has. The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, ...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
null
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
[{"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9"}, {"input": "2 4 5\n2 5 C\n2 1 D", "output": "0"}, {"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10"}]
1,800
["binary search", "data structures", "implementation"]
79
[{"input": "3 7 6\r\n10 8 C\r\n4 3 C\r\n5 6 D\r\n", "output": "9\r\n"}, {"input": "2 4 5\r\n2 5 C\r\n2 1 D\r\n", "output": "0\r\n"}, {"input": "3 10 10\r\n5 5 C\r\n5 5 C\r\n10 11 D\r\n", "output": "10\r\n"}, {"input": "6 68 40\r\n1 18 D\r\n6 16 D\r\n11 16 D\r\n7 23 D\r\n16 30 D\r\n2 20 D\r\n", "output": "18\r\n"}, {"in...
false
stdio
null
true
716/A
716
A
Python 3
TESTS
54
171
8,908,800
81643934
a,b=list(map(int,input().split())) c=list(map(int,input().split())) d=1 if(a==1): print(1) else: for i in range(len(c)): if(c[i]-c[i-1]<=b): d+=1 else: d=1 print(d)
81
77
13,926,400
184274484
def solve(): n,c = list(map(int,input().split())) a = list(map(int,input().split())) if n < 2: return 1 ans = 1 for i in range(1,n): if a[i] - a[i-1] > c: ans = 0 ans += 1 return ans print(solve())
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
716/A
716
A
PyPy 3-64
TESTS
54
186
17,715,200
158610685
a,b = input().split() a = int(a) b = int(b) count = 1 x = list(map(int, input().split())) if a>1: for i in range (a): if ((x[a-i-1]-x[a-i-2])<=b): count+=1 if ((x[a-i-1]-x[a-i-2])>b): break print(count)
81
78
13,209,600
213865028
def checker(): n, c = map(int, input().split()) nums = list(map(int, input().split())) cnt = 1 for i in range(1, n): if nums[i] - nums[i-1] > c: cnt = 1 else: cnt += 1 print(cnt) checker()
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
61/B
61
B
Python 3
TESTS
32
46
204,800
194304037
str = [] for _ in range(3): str.append(input().replace('_','').replace(';','').replace('-','').lower()) num_students=int(input()) answers = [] for i in range (num_students): answers.append(input().replace('_','').replace(';','').replace('-','').lower()) len_ans = len(str[0]+str[1]+str[2]) for ans in answers:...
43
61
102,400
221502609
A = [] for i in range(3): a = str(input().upper()) for i in ['_', '-', ';']: a = a.replace(i,'') A.append(a) B = [] c = 0 d = 0 for i in range(3): c = i-1 d = i-2 B.append(A[i] + A[c] + A[d]) B.append(A[i] + A[d] + A[c]) n = int(input()) for i in range(n): tx = str...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
61/B
61
B
Python 3
TESTS
32
46
204,800
194303618
str = [] for _ in range(3): str.append(input().replace('_','').replace(';','').replace('-','').lower()) num_ans=int(input()) ans=[] for i in range (num_ans): ans.append(input().replace('_','').replace(';','').replace('-','').lower()) for an in ans: if (str[0] in an) and (str[1] in an) and (str[2] in an) and...
43
61
409,600
204113636
a = [] for _ in range(3): s = input() s = ''.join(s.replace('_', '')) s = ''.join(s.replace(';', '')) s = ''.join(s.replace('-', '')) a.append(s) a, b, c = a a = a.lower(); b = b.lower(); c = c.lower() for _ in range(int(input())): x = input().lower() if ('_' in x): x = ''.join(x.replace('_', '')) if (';' in ...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
89/A
89
A
Python 3
TESTS
1
46
0
230509382
n, m, k = [int(w) for w in input().split()] arr = [int(w) for w in input().split()] if n % 2 == 0 or m < n: print(0) exit(0) low = min(arr[0::2]) steps = k * (n // m) print(min(low, steps))
45
124
716,800
9229401
z=lambda: list(map(int,input().split())) n,m,k=z() print(n%2*min(m//(n//2+1)*k, *z()[::2]))
Codeforces Beta Round 74 (Div. 1 Only)
CF
2,011
1
256
Robbery
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right. Unfortunately, Joe ...
The first line contains integers n, m and k (1 ≤ n ≤ 104, 1 ≤ m, k ≤ 109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell — it is an integer from 0 to 105.
Print a single number — the maximum number of diamonds Joe can steal.
null
In the second sample Joe can act like this: The diamonds' initial positions are 4 1 3. During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket. By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference...
[{"input": "2 3 1\n2 3", "output": "0"}, {"input": "3 2 2\n4 1 3", "output": "2"}]
1,800
["greedy"]
45
[{"input": "2 3 1\r\n2 3\r\n", "output": "0"}, {"input": "3 2 2\r\n4 1 3\r\n", "output": "2"}, {"input": "5 10 10\r\n7 0 7 0 7\r\n", "output": "7"}, {"input": "6 10 4\r\n1 2 3 4 5 6\r\n", "output": "0"}, {"input": "7 5 2\r\n1 2 3 4 5 6 7\r\n", "output": "1"}, {"input": "16 100 100\r\n30 89 12 84 62 24 10 59 98 21 13 69...
false
stdio
null
true
620/D
620
D
PyPy 3-64
TESTS
7
61
1,638,400
175034693
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) if sum(a) < sum(b): a, b = b, a curr = abs(sum(a) - sum(b)) prev = -1 resi = [] resj = [] while curr != prev: t = 0 prev = curr x, y = -1, -1 for i in range(len(a)): for j in range(l...
24
2,995
152,166,400
92182162
from bisect import bisect_left n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) sum_a, sum_b = sum(a), sum(b) delta = sum_b - sum_a ans = abs(delta) ans_swap = [] for i in range(n): for j in range(m): if abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b...
Educational Codeforces Round 6
ICPC
2,016
3
256
Professor GukiZ and Two Arrays
Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|. In one operation professor can swap some element from the array a and some element f...
The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a. The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a. The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b. The fourth line contains m integers bj ( - 109 ...
In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps. The second line should contain the number of swaps k (0 ≤ k ≤ 2). Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the ele...
null
null
[{"input": "5\n5 4 3 2 1\n4\n1 1 1 1", "output": "1\n2\n1 1\n4 2"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "0\n0"}, {"input": "5\n1 2 3 4 5\n4\n1 2 3 4", "output": "1\n1\n3 1"}]
2,200
["binary search", "two pointers"]
24
[{"input": "5\r\n5 4 3 2 1\r\n4\r\n1 1 1 1\r\n", "output": "1\r\n2\r\n1 1\r\n4 2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "0\r\n0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n4\r\n1 2 3 4\r\n", "output": "1\r\n1\r\n3 1\r\n"}, {"input": "1\r\n-42\r\n1\r\n-86\r\n", "output": "44\r\n0\r\n"}, {"input": "1\r\n-21\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline().strip()) a = list(map(int, f.readline().strip().split())) m = int(f.readline().strip()) b = list(map(int, f.readline().strip().split())) # Read r...
true
61/B
61
B
Python 3
TESTS
32
77
512,000
119224440
words = [] line1 = input().lower().replace(';', '').replace('_', '').replace('-', '') line2 = input().lower().replace(';', '').replace('_', '').replace('-', '') line3 = input().lower().replace(';', '').replace('_', '').replace('-', '') size = int(input()) for i in range(size): words.append(input().lower().replace...
43
61
5,120,000
157643150
def xoa(s): return ''.join([x for x in s.lower() if x not in '-_;']) a=xoa(input()) b=xoa(input()) c=xoa(input()) tohop=[a+b+c, a+c+b, b+a+c, b+c+a, c+a+b, c+b+a] for _ in range(int(input())): print('ACC' if xoa(input()) in tohop else 'WA')
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
61/B
61
B
Python 3
TESTS
32
77
921,600
143369528
#Hard Work from operator import concat import re import sys inpt = [] for ln in sys.stdin: inpt.append(ln.rstrip()) concat_list = [] #adds each word to concat_list, removes special characters from the words for wd in range(3): concat_list.append(inpt[wd]) concat_list[wd] = re.sub('[^A-Za-z]+',"",concat_lis...
43
62
614,400
211987182
word1 = "".join([ i.lower() for i in input() if i.isalpha()]) word2 = "".join([ i.lower() for i in input() if i.isalpha()]) word3 = "".join([ i.lower() for i in input() if i.isalpha()]) ref1 = word1 + word2 + word3 ref2 = word2 + word1 + word3 ref3 = word3 + word1 + word2 ref4 = word3 + word2 + word1 ref5 = word1 + ...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
61/B
61
B
Python 3
TESTS
32
78
204,800
180419744
def clean(str): N_str =[ el for el in str if el not in ";-_"] return ( "".join(N_str)).lower() str1 = clean(input()) str2 = clean(input()) str3 =clean(input()) for i in range(int(input())): output = clean(input()) ex = str1 in output and str2 in output and str3 in output print( "ACC" if len(output) == len(str1+st...
43
62
716,800
143446013
import sys import re x = re.sub("[^a-zA-Z]", "", sys.stdin.readline()[:-1]).lower() y = re.sub("[^a-zA-Z]", "", sys.stdin.readline()[:-1]).lower() z = re.sub("[^a-zA-Z]", "", sys.stdin.readline()[:-1]).lower() perms = [(x + y + z), (x + z + y), (y + x + z), (y + z + x), (z + x + y), (z + y + x)] n = int(sys.stdin.rea...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
1007/A
1007
A
Python 3
TESTS
7
109
921,600
40478157
size = int(input()) num_list = list(map(int, input().split())) num_list.sort() perm_c = 0 equal_c = 0 flag = 0 for i in range(1, size): if num_list[i] > num_list[i - 1]: perm_c += 1 flag = 1 elif flag == 1 and equal_c > 0: perm_c += 1 equal_c -= 1 else: equal_c += 1 ...
33
77
13,619,200
190256309
n = int(input()) a = list(map(int, input().split())) a.sort() k = 0 for i in range(len(a)): if a[i] > a[k]: k += 1 print(k)
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
1007/A
1007
A
Python 3
TESTS
7
109
921,600
40510611
n = input() a = list(map(int, input().split(' '))) a.sort() m = 1 for i in range(1, len(a)): if a[i] == a[0]: m += 1 else: break v = 0 l = 0 d = m for i in range(m, len(a)): if a[i] != v: v = a[i] l = 1 else: l += 1 if l > m: d += 1 print(len...
33
93
9,011,200
148713854
def main(): n = int(input()) arr = list(map(int, input().split())) temp_dict = {} for element in arr: if element in temp_dict: temp_dict[element] += 1 else: temp_dict[element] = 1 print(n - max(temp_dict.values())) if __name__ == "__main__": main() # ...
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
1007/A
1007
A
PyPy 3-64
TESTS
7
78
4,812,800
159511106
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) a.sort() l = a[::-1] for i in range(n): if(a[i] > a[0]): l = a[i : ] + a[ : i] break c = 0 for i in range(n): if(l[i] > a[i]): c += 1 print(c)
33
93
13,619,200
198954522
n = int(input()) mas = list(map(int,input().split())) mas.sort() swipe = 0 ans = 0 for i in range(n): if mas[i] == mas[0]: swipe+=1 elif mas[i] > mas[i-swipe]: ans+=1 else: swipe+=1 print(ans)
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
715/B
715
B
Python 3
TESTS
3
46
512,000
22148291
''' def main(): from sys import stdin,stdout if __name__=='__main__': main() ''' #401 ''' def main(): import sys a,b=map(int,sys.stdin.readline().split()) if a>b: if a-b==1: s='' for i in range(a+b): if i&1: s+='1' e...
179
576
3,891,200
98338361
from collections import defaultdict MAX = 10 ** 14 def Dijkstra(graph, s, n): visited = [False] * n d = [MAX] * n parents = {} d[s] = 0 for i in range(n): _, v = min((d[j], j) for j in range(n) if not visited[j]) visited[v] = True for to, length in graph[v]: ...
Codeforces Round 372 (Div. 1)
CF
2,016
4
256
Complete The Graph
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg...
The first line contains five integers n, m, L, s, t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 10 000, 1 ≤ L ≤ 109, 0 ≤ s, t ≤ n - 1, s ≠ t) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively. Then, m lines describing the edges of the graph follow. i-th of th...
Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way. Otherwise, print "YES" in the first line. Next m lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. i-th of them should contain three integers ui, vi ...
null
Here's how the graph in the first sample case looks like : In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13. In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456...
[{"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"}, {"input": "2 1 123456789 0 1\n0 1 0", "output": "YES\n0 1 123456789"}, {"input": "2 1 999999999 1 0\n0 1 1000000000", "output": "NO"}]
2,300
["binary search", "constructive algorithms", "graphs", "shortest paths"]
179
[{"input": "5 5 13 0 4\r\n0 1 5\r\n2 1 2\r\n3 2 3\r\n1 4 0\r\n4 3 4\r\n", "output": "YES\r\n0 1 5\r\n2 1 2\r\n3 2 3\r\n1 4 8\r\n4 3 4\r\n"}, {"input": "2 1 123456789 0 1\r\n0 1 0\r\n", "output": "YES\r\n0 1 123456789\r\n"}, {"input": "2 1 999999999 1 0\r\n0 1 1000000000\r\n", "output": "NO\r\n"}, {"input": "4 5 10 1 2\...
false
stdio
import sys from heapq import heappush, heappop def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m, L, s, t = map(int, f.readline().split()) original_edges = {} for _ in range(m): ...
true
716/A
716
A
Python 3
TESTS
54
171
8,704,000
72692096
def crazy(c, a): wordCount = 0 if len(a) > 1: for i in range(len(a) - 1): if a[i + 1] - a[i] > c: wordCount = 1 else: wordCount += 1 print(wordCount) else: print("1") ic = list(map(int, input().split()))[1] ia = list(map(int, ...
81
78
13,209,600
224776394
class Solution: def __init__(self): pass def solve(self): n, c = map(int, input().split()) result = 0 milestone = list(map(int, input().split())) prev = 0 for time in milestone: if time - prev <= c: result += 1 else: result = 1 prev = time print(result) if __name__ == "__main__": ...
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
716/A
716
A
PyPy 3-64
TESTS
54
155
13,004,800
153783156
n, c = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] count = 1 flag = False for i in range(1,n): flag = True if arr[i]-arr[i-1] <= c: count += 1 else: count = 0 if flag: print(count+1) else: print(count)
81
78
13,926,400
211993316
n,c=map(int, input().split()) a=map(int, input().split()) a=list(a) z=1 for i in range (1,n): if (a[i]-a[i-1]) >c: z=1 else: z+=1 print(z)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
280/B
280
B
PyPy 3
TESTS
3
140
0
64167714
n = int(input()) v = list(map(int, input().split())) ans, ans_l, ans_r = 0, 0, 0 s = [] for i in range(len(v)): x = v[i] if len(s) == 0: s.append(x) else: while len(s) != 0 and s[-1] < x: s.pop() if len(s) != 0: ans = max(ans, s[-1] ^ x) s...
56
124
19,456,000
167065303
import collections import os import sys from collections import Counter # print(sys.hexversion) # if os.getenv('LOCALCFTEST'): # sys.stdin = open('cfinput.txt') # else: # input = sys.stdin.readline from itertools import product if sys.hexversion == 50924784: sys.stdin = open('cfinput.txt') else: input...
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
716/A
716
A
Python 3
TESTS
54
171
8,396,800
66821188
n,c=[int(x) for x in input().split()] times=[int(x) for x in input().split()] times.reverse() check=1 for i in range(len(times)-1): if times[i]-times[i+1]>c: print(i+1) check=0 break if check==1: print(check)
81
78
14,745,600
186986062
[n, c] = map(int, input().split(" ")) data = list(map(int, input().split(" "))) count = 1 for i in range(n - 1): if data[i + 1] - data[i] <= c: count += 1 else: count = 1 print(count)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
537/D
538
D
Python 3
PRETESTS
4
46
4,710,400
10892427
import sys f = sys.stdin n = int(f.readline().strip()) fig = [] place = [] for i in range(n): place.append([-1]*(n)) for i in range(n): s = f.readline().strip() for k in range(len(s)): if s[k]=='o': fig.append((k, i)) place[k][i] = -1 elif s[k]=='x': ...
41
1,029
23,654,400
86444579
from sys import stdin n = int(stdin.readline()) board = [] for x in range(n): board.append(list(stdin.readline().strip())) moves = {y:{x:True for x in range(-n+1,n)} for y in range(-n+1,n)} for x in range(n): for y in range(n): if board[x][y] == 'o': for a in range(n): f...
VK Cup 2015 - Wild Card Round 2
IOI
2,015
2
256
Weird Chess
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous. Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece...
The first line contains a single integer n (1 ≤ n ≤ 50). The next n lines contain n characters each describing the position offered by Igor. The j-th character of the i-th string can have the following values: - o — in this case the field (i, j) is occupied by a piece and the field may or may not be attacked by some ...
If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2n - 1) × (2n - 1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar to the in...
null
In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight.
[{"input": "5\noxxxx\nx...x\nx...x\nx...x\nxxxxo", "output": "YES\n....x....\n....x....\n....x....\n....x....\nxxxxoxxxx\n....x....\n....x....\n....x....\n....x...."}, {"input": "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.", "output": "YES\n...........\n...........\n...........\n....x.x....\n...x...x...\n.....o.....
1,800
["brute force", "constructive algorithms", "implementation"]
41
[{"input": "5\r\noxxxx\r\nx...x\r\nx...x\r\nx...x\r\nxxxxo\r\n", "output": "YES\r\nxxxxxxxxx\r\nx...xxxxx\r\nx...xxxxx\r\nx...xxxxx\r\nxxxxoxxxx\r\nxxxxx...x\r\nxxxxx...x\r\nxxxxx...x\r\nxxxxxxxxx\r\n"}, {"input": "6\r\n.x.x..\r\nx.x.x.\r\n.xo..x\r\nx..ox.\r\n.x.x.x\r\n..x.x.\r\n", "output": "YES\r\nxxxxxxxxxxx\r\nxxxx...
false
stdio
import sys def read_grid(path, n): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines()] return [list(line) for line in lines] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r')...
true
716/A
716
A
Python 3
TESTS
54
171
8,704,000
75077247
n,c=map(int,input().split()) arr=list(map(int,input().split())) if(n==1): print(1) else: words=0 for i in range(1,n): if(arr[i]-arr[i-1]>c): words=0 words=words+1 print(words)
81
92
13,004,800
193480275
n, c = [int(p) for p in input().split()] a = [int(p) for p in input().split()] z = 1 for i in range (1, n): if a[i] - a[i-1] > c: z = 1 else: z += 1 print(z)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
1007/A
1007
A
Python 3
TESTS
7
77
716,800
121870541
first_line = list(map(int, input().split())) n = first_line[0] second_line = list(map(int, input().split())) second_line.sort() previous_minor_count = 0 previous_minor = second_line[0] ans = 0 flag = False backup = 0 for number in second_line: if number != previous_minor: if not flag: backup = p...
33
93
15,564,800
207414822
from collections import Counter n=int(input()) p=list(map(int, input().split(' '))) s=Counter(p) y=[s[i] for i in s] y.sort() y=[0]+y m=len(y) ans=0 tem=0 for i in range (0,m): if y[i]>tem: ans=ans+(m-i-1)*(y[i]-tem) tem=y[i] print(ans)
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
716/A
716
A
Python 3
TESTS
54
140
8,601,600
116561473
n,c = map(int,input().split()) count =0 l = list(map(int,input().split())) if(len(l)==1): print(1) else: for i in range(1,len(l)): if(l[i]-l[i-1]<=c): count +=1 else: count = 1 print(count)
81
92
13,721,600
175889774
n,c = map(int, input().split()) secs = list(map(int, input().split())) count = 1 for i in range(1, len(secs)): if secs[i]-secs[i-1] <= c: count += 1 elif secs[i]-secs[i-1] >= c: count = 1 print(count)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
716/A
716
A
PyPy 3-64
TESTS
54
155
12,595,200
153853234
n, c = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] count = 0 for i in range(1,n-1): if arr[i+1]-arr[i] > c: count = 0 else: count += 1 print(count+1)
81
92
13,824,000
201663232
n,c=map(int,input().split()) a=list(map(int,input().split())) r=0 d=0 for i in a: r=1+r*(i-d<=c) d=i print(r)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
716/A
716
A
PyPy 3-64
TESTS
54
108
13,824,000
210867745
n, c = map(int,input().split()) lista = list(map(int,input().split())) szavak = 1 for i in range(n-1,1,-1): if lista[i]-lista[i-1]>c: break else: szavak += 1 print(szavak)
81
93
8,089,600
187153139
[n, c] = map(int, input().split()) l = list(map(int, input().split())) ans = 1 for i in range(n-1, 0, -1): if l[i] - l[i - 1] > c: break ans += 1 print(ans)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
1007/A
1007
A
PyPy 3-64
TESTS
7
62
3,276,800
190252631
n = int(input()) a = list(map(int, input().split())) a.sort() a1 = [[a[0], 1]] for i in range(1, n): if a[i] != a[i-1]: a1.append([a[i], 1]) elif a[i] == a[i-1]: a1[-1][1] += 1 c = 0 p = a1[0][1] for i in range(1, len(a1)): if a1[i][1] <= p: c += a1[i][1] elif a1[i][1] > p: ...
33
93
18,329,600
165473799
n=int(input()) arr=list(map(int,input().split())) lst=[] mp=dict() for i in arr: try:mp[i]+=1 except:mp[i]=1 mx=0 for i in mp: mx=max(mx,mp[i]) print(n-mx)
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
1007/A
1007
A
PyPy 3-64
TESTS
7
61
3,481,600
165472718
n=int(input()) arr=list(map(int,input().split())) lst=[] mp=dict() for i in arr: try:mp[i]+=1 except:mp[i]=1 for i in mp: lst.append([i,mp[i]]) lst=sorted(lst) i,ans=0,0 j=i+1 #print(lst) while i<len(lst): if j>=len(lst):break ans+=min(lst[i][1],lst[j][1]) if lst[j][1]==lst[i][1]: i=j ...
33
93
20,070,400
174770509
# from heapq import * # from collections import deque def lets_do_it(): n = int(input()) count = {} for a in input().split(): a = int(a) count[a] = count.get(a, 0) + 1 max_val = 0 for value in count.values(): max_val = max(max_val, value) print(n - max_val) def main(...
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
1007/A
1007
A
Python 3
TESTS
7
46
716,800
148710365
def main(): n = int(input()) arr = list(map(int, input().split())) arr.sort() index = 0 for i in range(n): if arr[i] > arr[0]: index = i break arr2 = arr[index:] + arr[:index] counter = 0 for i in range(n): if arr2[i] > arr[i]: count...
33
108
14,336,000
175260423
#I = lambda: [int(i) for i in input().split()] #import io, os, sys #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # n = int(input()) # l1 = list(map(int,input().split())) # n,x = map(int,input().split()) # s = input() mod = 1000000007 # print("Case #"+str(_+1)+":",) from collections import Counter,defa...
Codeforces Round 497 (Div. 1)
CF
2,018
2
256
Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
null
In the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
[{"input": "7\n10 1 1 1 5 5 3", "output": "4"}, {"input": "5\n1 1 1 1 1", "output": "0"}]
1,300
["combinatorics", "data structures", "math", "sortings", "two pointers"]
33
[{"input": "7\r\n10 1 1 1 5 5 3\r\n", "output": "4\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n300000000 200000000 300000000 200000000 1000000000 300000000\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "9\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"},...
false
stdio
null
true
522/A
522
A
Python 3
TESTS
5
31
102,400
204080546
from collections import defaultdict n = int(input()) map_ = defaultdict(list) visited = set('polycarp') def dfs(node , visited , count , map_, result): for i in map_[node]: if i not in visited: result.append(count) visited.add(i) dfs(i , vis...
36
31
0
186479966
global h h = -1 def dfs(node,parent,current,d): # print(node,end=" ") for i in d[node]: if i==parent: continue else: global h h = max(h,current+1) dfs(i,node,current+1,d) def main(): d = dict() n = int(input()) while(n>0): s = ...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
261/A
261
A
PyPy 3
TESTS
8
280
0
83544605
import sys import math as mt input=sys.stdin.buffer.readline import math as mt #t=int(input()) t=1 for __ in range(t): #n,m=map(int,input().split()) m=int(input()) d=list(map(int,input().split())) d.sort() n=int(input()) p=list(map(int,input().split())) p.sort(reverse=True) ans=0 ...
45
218
19,865,600
180432788
m = int(input()) q = list(map(int, input().split())) n = int(input()) l = sorted(list(map(int, input().split()))) cost, mini = 0, min(q) #Buy less Items every time while len(l)!=0: for i in range(min(len(l), mini)): cost+=l.pop() #Buy Items high priced items so we can buy the items that are <= min(itemsBought) for ...
Codeforces Round 160 (Div. 1)
CF
2,013
2
256
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term...
The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105). The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices...
In a single line print a single integer — the answer to the problem.
null
In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
[{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}]
1,400
["greedy", "sortings"]
45
[{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46...
false
stdio
null
true
257/D
257
D
Python 3
TESTS
2
122
0
14247787
n = int(input()) l = list(map(int, input().split())) sum = 0 result ='' for i in range(n): if sum <= l[i]: sum+=l[i] result+='+' else: sum-=l[i] result+='-' print(result)
38
498
12,185,600
112993183
n=int(input()) b=list(map(int,input().split())) s=0 res=[] j=n-1 while(j>=0): if s<=0: s+=b[j] res.append(1) else: s-=b[j] res.append(0) j+=-1 res.reverse() if s>=0: for j in res: if j: print("+",end="") else: print("-",end="") ...
Codeforces Round 159 (Div. 2)
CF
2,013
2
256
Sum
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n). Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge...
The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the original array. It is guaranteed that the condition ai ≤ ai + 1 ≤ 2·ai fulfills for any positive integer i (i < n).
In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 ≤ s ≤ a1. If there are multiple solutions, you are allowed to print any of them.
null
null
[{"input": "4\n1 2 3 5", "output": "+++-"}, {"input": "3\n3 3 5", "output": "++-"}]
1,900
["greedy", "math"]
38
[{"input": "4\r\n1 2 3 5\r\n", "output": "+++-"}, {"input": "3\r\n3 3 5\r\n", "output": "++-"}, {"input": "4\r\n2 4 5 6\r\n", "output": "-++-"}, {"input": "6\r\n3 5 10 11 12 20\r\n", "output": "++-++-"}, {"input": "10\r\n10 14 17 22 43 72 74 84 88 93\r\n", "output": "++---++--+"}, {"input": "11\r\n3 6 7 11 13 16 26 52 ...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = f.readlines() n = int(lines[0].strip()) a = list(map(int, lines[1].strip().split())) assert len(a) == n, "Input array length mismatch" with open(sub_path) as f: sub = f.read().strip() i...
true
522/A
522
A
Python 3
TESTS
5
31
0
173657560
n = int(input()) c = 1 d = 'polycarp' for i in range(n): a = str(input()).split(' ') f = a[2].lower() if f == d: d = a[0].lower() c = c + 1 print(c)
36
46
0
10208452
d = {'polycarp': 1} n = int(input()) for i in range(n): s = input().split() name1, name2 = s[0].lower(), s[2].lower() x = d[name2] d[name1] = x + 1 print(max(d.values()))
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
282/A
282
A
Python 3
TESTS
5
46
0
227972636
t=[] s=0 for i in range(int(input())): n=str(input()) n.upper() if n=='--X' : s=s-1 elif n=='++X': s=s+1 elif n=='X--': s=-1-s elif n=='X++' : s=1+s print(s)
36
31
0
227732573
n = int(input()) count = 0 for i in range(n): X = input() if X == "++X" or X == "X++": count +=1 elif X == "--X" or X == "X--": count-=1 print(count)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A s...
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c...
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n...
false
stdio
null
true
774/B
774
B
Python 3
TESTS
3
46
4,915,200
26152447
n, m, d = input().split() n = int(n) m = int(m) d = int(d) # c = {} # w = {} # topPhys = (0,-0) #cost, -width # topInf = (0,-0) phys = [] it = [] for i in range(0,n): c, w = input().split() c = int(c) w = int(w) phys.append([-c,w,'p']) phys = sorted(phys) for i in range(n,m+n): c, w = input().spl...
44
2,339
23,961,600
26151780
from functools import cmp_to_key def read_ints(): return tuple(map(int, input().split())) n, m, d = read_ints() a = [read_ints() for _ in range(n)] b = [read_ints() for _ in range(m)] @cmp_to_key def cmp(x, y): if x[0] != y[0]: return y[0] - x[0] return x[1] - y[1] a.sort(key=cmp) b.sort(key=cmp) j = -1 va...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
3
256
Significant Cups
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance ci and width wi. Stepan decided to expose some of his cups on a shelf with width d in such a way, that: - there is at least one Ph...
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100 000, 1 ≤ d ≤ 109) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf. Each of the following n lines contains two integers ci and wi (1 ≤ ci, wi ≤ 109) — significance and width of the i-th ...
Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement. If there is no way to expose cups on the shelf, then print 0.
null
In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most sign...
[{"input": "3 1 8\n4 2\n5 5\n4 2\n3 2", "output": "8"}, {"input": "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "output": "11"}, {"input": "2 2 2\n5 3\n6 3\n4 2\n8 1", "output": "0"}]
2,100
["*special", "binary search", "data structures", "two pointers"]
44
[{"input": "3 1 8\r\n4 2\r\n5 5\r\n4 2\r\n3 2\r\n", "output": "8\r\n"}, {"input": "4 3 12\r\n3 4\r\n2 4\r\n3 5\r\n3 4\r\n3 5\r\n5 2\r\n3 4\r\n", "output": "11\r\n"}, {"input": "2 2 2\r\n5 3\r\n6 3\r\n4 2\r\n8 1\r\n", "output": "0\r\n"}, {"input": "10 10 229\r\n15 17\r\n5 4\r\n4 15\r\n4 17\r\n15 11\r\n7 6\r\n5 19\r\n14 ...
false
stdio
null
true
689/B
689
B
PyPy 3
TESTS
12
327
16,691,200
99282318
# Aluno Rafael Pontes n = int(input()) atalhos = [int(x) for x in input().split()] distancias = [0] * n visitar = set() if atalhos[0] - 1: distancias[atalhos[0] - 1] = 1 visitar.add(atalhos[0] - 1) for x in range(1, n): if distancias[x]: distancias[x] = min(distancias[x], distancias[x - 1] + 1) ...
54
156
27,955,200
218110291
import sys input = sys.stdin.readline from math import inf n = int(input()) a = list(map(int, input().split())) d = [-1] * (n) d[0] = 0 q = [0] while(q): u = q.pop(0) for dl in range(-1, 2): v = u + dl if(0 <= v < n and d[v] == -1): d[v] = d[u] + 1 q.append(v) ...
Codeforces Round 361 (Div. 2)
CF
2,016
3
256
Mike and Shortcuts
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking...
The first line contains an integer n (1 ≤ n ≤ 200 000) — the number of Mike's city intersection. The second line contains n integers a1, a2, ..., an (i ≤ ai ≤ n , $$a_{i} \leq a_{i+1} \forall i < n$$, describing shortcuts of Mike's city, allowing to walk from intersection i to intersection ai using only 1 unit of ener...
In the only line print n integers m1, m2, ..., mn, where mi denotes the least amount of total energy required to walk from intersection 1 to intersection i.
null
In the first sample case desired sequences are: 1: 1; m1 = 0; 2: 1, 2; m2 = 1; 3: 1, 3; m3 = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 < i is always 1, i and mi = |1 - i|. In the third sample case — consider the following intersection sequences: 1: 1; m1 = 0; 2: 1, 2; m2 = |2 - 1...
[{"input": "3\n2 2 3", "output": "0 1 2"}, {"input": "5\n1 2 3 4 5", "output": "0 1 2 3 4"}, {"input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3"}]
1,600
["dfs and similar", "graphs", "greedy", "shortest paths"]
54
[{"input": "3\r\n2 2 3\r\n", "output": "0 1 2 \r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0 1 2 3 4 \r\n"}, {"input": "7\r\n4 4 4 4 7 7 7\r\n", "output": "0 1 2 1 2 3 3 \r\n"}, {"input": "98\r\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87...
false
stdio
null
true
689/B
689
B
PyPy 3
TESTS
12
327
16,896,000
99514667
# -*- coding: utf-8 -*- n = int(input()) shortcuts = list(map(int, input().split())) visitBack = set() distances = [0] * n if (shortcuts[0] - 1): distances[shortcuts[0] - 1] = 1 visitBack.add(shortcuts[0] - 1) for i in range(1, n): if (distances[i]): distances[i] = min(distances[i], distances[i - 1] + 1) ...
54
187
28,774,400
173097534
from collections import deque n=int(input()) arr=list(map(int,input().split())) d=[-1]*(n) q=deque() q.append(0) d[0]=0 while q: node=q.popleft() for dl in range(-1,2): u=node+dl if 0<=u and u<n and d[u]==-1: d[u]=d[node]+1 q.append(u) u=int(arr[node])-1 if d[u]==...
Codeforces Round 361 (Div. 2)
CF
2,016
3
256
Mike and Shortcuts
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking...
The first line contains an integer n (1 ≤ n ≤ 200 000) — the number of Mike's city intersection. The second line contains n integers a1, a2, ..., an (i ≤ ai ≤ n , $$a_{i} \leq a_{i+1} \forall i < n$$, describing shortcuts of Mike's city, allowing to walk from intersection i to intersection ai using only 1 unit of ener...
In the only line print n integers m1, m2, ..., mn, where mi denotes the least amount of total energy required to walk from intersection 1 to intersection i.
null
In the first sample case desired sequences are: 1: 1; m1 = 0; 2: 1, 2; m2 = 1; 3: 1, 3; m3 = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 < i is always 1, i and mi = |1 - i|. In the third sample case — consider the following intersection sequences: 1: 1; m1 = 0; 2: 1, 2; m2 = |2 - 1...
[{"input": "3\n2 2 3", "output": "0 1 2"}, {"input": "5\n1 2 3 4 5", "output": "0 1 2 3 4"}, {"input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3"}]
1,600
["dfs and similar", "graphs", "greedy", "shortest paths"]
54
[{"input": "3\r\n2 2 3\r\n", "output": "0 1 2 \r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0 1 2 3 4 \r\n"}, {"input": "7\r\n4 4 4 4 7 7 7\r\n", "output": "0 1 2 1 2 3 3 \r\n"}, {"input": "98\r\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87...
false
stdio
null
true
175/C
175
C
PyPy 3-64
TESTS
2
124
0
166089812
t = int(input()) a = [] for i in range(t): x, y = map(int, input().split()) a.append([x, y]) a = sorted(a, key=lambda x : x[0], reverse=True) n = int(input()) p = list(map(int, input().split())) j = 0 res = 0 for i, v in enumerate(p, 1): while j < len(a) and v >= a[j][0]: res += a[j][1] * a[j][0] *...
90
124
0
166081672
import collections import os import sys from collections import Counter if os.getenv('LOCALCFTEST'): sys.stdin = open('cfinput.txt') else: input = sys.stdin.readline MOD = 10 ** 9 + 7 def solve(n, kc, t, p): kc.sort(key=lambda x: x[1]) p.append(10 ** 18) q = [p[0]] * t for i in range(1, t): ...
Codeforces Round 115
CF
2,012
2
256
Geometry Horse
Vasya plays the Geometry Horse. The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are n types of geometric figures. The number of figures of type ki and figure cost ci is know...
The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of figure types. Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly. The next l...
Print the only number — the maximum number of points Vasya can get.
null
In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points. In the second example all 8 figures will be destroyed with factor 1, so Vasya wi...
[{"input": "1\n5 10\n2\n3 6", "output": "70"}, {"input": "2\n3 8\n5 10\n1\n20", "output": "74"}]
1,600
["greedy", "implementation", "sortings", "two pointers"]
90
[{"input": "1\r\n5 10\r\n2\r\n3 6\r\n", "output": "70"}, {"input": "2\r\n3 8\r\n5 10\r\n1\r\n20\r\n", "output": "74"}, {"input": "3\r\n10 3\r\n20 2\r\n30 1\r\n3\r\n30 50 60\r\n", "output": "200"}, {"input": "1\r\n100 1000\r\n1\r\n1\r\n", "output": "199000"}, {"input": "1\r\n1 1000\r\n1\r\n1\r\n", "output": "1000"}, {"i...
false
stdio
null
true
22/D
22
D
PyPy 3-64
TESTS
3
46
0
219255410
n = int(input()) events = [] for _ in range(n): l, r = map(int, input().split()) events.append([l, '+']) events.append([r, '-']) events.sort() must_pined = False pins = [] for t, ev in events: if ev == '+': must_pined = True else: if must_pined: pins.append(t) ...
40
46
204,800
212181686
from sys import stdin N = int(input()) result = [] segs = [] for _ in range(N): segs.append(sorted(map(int, stdin.readline().split()))) segs.sort(key=lambda x:x[1]) for a, b in segs: if not result or a > result[-1]: result.append(b) print(len(result)) print(*result)
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
22/D
22
D
Python 3
TESTS
6
31
0
159232288
# arr = [[1,9],[2,3],[4,6], [5,9], [10,11]] n = int(input()) arr = [] for i in range(n): mystr = input() arr += [[int(x) for x in mystr.strip().split()]] for S in arr: S.sort() desp = [] for i in arr: desp += [[i[0],'s'],[i[1],'e']] desp.sort() mystr = [] prev = 999 a = [] s_found = True for i in ...
40
77
3,072,000
194351362
import sys; R = sys.stdin.readline S = lambda: map(int,R().split()) n = int(R()) t = [] x = [0]*n for i in range(n): u,v = sorted(S()) t += (u,0,i), t += (v,1,i), t.sort() r = [] s = [] for a,b,c in t: if not b: s += c, elif not x[c]: r += a, for v in s: x[v] = 1 s = [] prin...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
965/E
965
E
Python 3
TESTS
6
109
7,475,200
38323798
import copy n = int(input()) l = [] for i in range(n): l.append(input()) flag = 0 co = [] tmp = '' while flag == 0: for i in range(n): tmp = l[i] while l[i][:-1] not in l and len(l[i])>1: l[i] = l[i][:-1] tmp = l[i] l[i] = tmp if co == l: flag = 1 ...
24
156
22,937,600
177672519
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def trie(): G, cnt = [[-1] * 26], [0] return G, cnt def insert(s): j = 0 for i in s: if not G[j][i - 97] ^ -1: G[j][i - 97] = len(cnt) G.append([-1] * 26) cnt.append(0) ...
Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
CF
2,018
1
256
Short Code
Arkady's code contains $$$n$$$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code. He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincid...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of variables. The next $$$n$$$ lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than $$$10^5$$$. The variable names are ...
Print a single integer — the minimum possible total length of new variable names.
null
In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c". In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.
[{"input": "3\ncodeforces\ncodehorses\ncode", "output": "6"}, {"input": "5\nabba\nabb\nab\naa\naacada", "output": "11"}, {"input": "3\ntelegram\ndigital\nresistance", "output": "3"}]
2,200
["data structures", "dp", "greedy", "strings", "trees"]
24
[{"input": "3\r\ncodeforces\r\ncodehorses\r\ncode\r\n", "output": "6\r\n"}, {"input": "5\r\nabba\r\nabb\r\nab\r\naa\r\naacada\r\n", "output": "11\r\n"}, {"input": "3\r\ntelegram\r\ndigital\r\nresistance\r\n", "output": "3\r\n"}, {"input": "1\r\na\r\n", "output": "1\r\n"}, {"input": "10\r\naaaba\r\nbabba\r\nbbba\r\naaab...
false
stdio
null
true
963/B
963
B
Python 3
TESTS
2
77
7,065,600
37691151
#def tree(aim,x): # # for i in aim: # if (line_num[i] % 2 == 0) and (not(i in ans)): # wk1 = line_num[i] # line_num[i] = 0 # aim1 = [] # for j in range(len(line[i])): # if not(line[i][j] in ans): # line_num[line[i][j]] -= 1 # aim1.append(line[i][j]) # ans[x] = i # tree(aim1, x + 1) # for j in ...
95
701
45,670,400
126191783
import sys input = sys.stdin.readline n = int(input()) if n%2 == 0: print("NO") exit() parent = list(map(int,input().split())) print("YES") s = [0]*n G = [[] for _ in range(n)] root = -1 for i in range(n): parent[i] -= 1 if parent[i] != -1: G[parent[i]].append(i) else: root = i st...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
1
256
Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
null
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
[{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}]
2,000
["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"]
95
[{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33...
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) as f: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ...
true
689/B
689
B
Python 3
TESTS
12
467
24,883,200
115986286
class MikeAndShortcuts: def __init__(self): self.result = '' self.n = 0 self.shortcuts = [] def input_class(self): self.n = int(input()) self.shortcuts = [int(x) for x in input().split(" ")] def process_class(self): dist = [0] * self.n visit_back = ...
54
218
25,907,200
206192750
n = int(input()) p = [int(i)-1 for i in input().split()] m = {0: 0} to_explore = {1, p[0]} to_explore = {i for i in to_explore if (0<= i < n) and (i not in m)} cur_dist = 0 # remaining = {i for i in range(2, n+1)} while to_explore != set(): cur_dist += 1 to_explore_next = set() for city in to_explore: ...
Codeforces Round 361 (Div. 2)
CF
2,016
3
256
Mike and Shortcuts
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking...
The first line contains an integer n (1 ≤ n ≤ 200 000) — the number of Mike's city intersection. The second line contains n integers a1, a2, ..., an (i ≤ ai ≤ n , $$a_{i} \leq a_{i+1} \forall i < n$$, describing shortcuts of Mike's city, allowing to walk from intersection i to intersection ai using only 1 unit of ener...
In the only line print n integers m1, m2, ..., mn, where mi denotes the least amount of total energy required to walk from intersection 1 to intersection i.
null
In the first sample case desired sequences are: 1: 1; m1 = 0; 2: 1, 2; m2 = 1; 3: 1, 3; m3 = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 < i is always 1, i and mi = |1 - i|. In the third sample case — consider the following intersection sequences: 1: 1; m1 = 0; 2: 1, 2; m2 = |2 - 1...
[{"input": "3\n2 2 3", "output": "0 1 2"}, {"input": "5\n1 2 3 4 5", "output": "0 1 2 3 4"}, {"input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3"}]
1,600
["dfs and similar", "graphs", "greedy", "shortest paths"]
54
[{"input": "3\r\n2 2 3\r\n", "output": "0 1 2 \r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0 1 2 3 4 \r\n"}, {"input": "7\r\n4 4 4 4 7 7 7\r\n", "output": "0 1 2 1 2 3 3 \r\n"}, {"input": "98\r\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87...
false
stdio
null
true
316/B1
316
B1
Python 3
TESTS1
6
46
0
11831285
import sys def solve(): n, x, = rv() x -= 1 a, = rl(1) a = [val - 1 for val in a] nxt = [True] * n index = [-1] * n for i in range(len(a)): index[i] = get(i, a, nxt) # print(nxt) # print(index) curindex = index[x] - 1 others = list() for i in range(n): if...
29
109
204,800
3871859
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import collections def find(parents, i): if parents[i] == i: return i result = find(parents, parents[i]) parents[i] = result return result def union(parents, i, j): i, j = find(parents, i), find(parents, j) parents[i] = j if __name__...
ABBYY Cup 3.0
ICPC
2,013
0.5
256
EKG
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native ...
The first line contains two integers n (1 ≤ n ≤ 103) and x (1 ≤ x ≤ n) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n) — the number of the beaver f...
Print all possible positions of the Smart Beaver in the line in the increasing order.
null
Picture for the fourth test.
[{"input": "6 1\n2 0 4 0 6 0", "output": "2\n4\n6"}, {"input": "6 2\n2 3 0 5 6 0", "output": "2\n5"}, {"input": "4 1\n0 0 0 0", "output": "1\n2\n3\n4"}, {"input": "6 2\n0 0 1 0 4 5", "output": "1\n3\n4\n6"}]
1,500
["brute force", "dfs and similar"]
29
[{"input": "6 1\r\n2 0 4 0 6 0\r\n", "output": "2\r\n4\r\n6\r\n"}, {"input": "6 2\r\n2 3 0 5 6 0\r\n", "output": "2\r\n5\r\n"}, {"input": "4 1\r\n0 0 0 0\r\n", "output": "1\r\n2\r\n3\r\n4\r\n"}, {"input": "6 2\r\n0 0 1 0 4 5\r\n", "output": "1\r\n3\r\n4\r\n6\r\n"}, {"input": "10 7\r\n10 8 6 5 0 0 0 4 3 9\r\n", "output"...
false
stdio
null
true
522/A
522
A
Python 3
TESTS
9
62
0
17298766
n = int(input()) t = input().split() t[0] = t[0].lower() t[2] = t[2].lower() m = [[t[0], t[2], 2]] for i in range(1, n): t = input().split() t[0] = t[0].lower() t[2] = t[2].lower() m.append([t[0], t[2], 0]) for k in range(len(m)): if m[i][1] == m[k][0]: m[i][2] = m[k][2] + 1 u = ...
36
46
0
13553244
n = int(input()) cnt = {'polycarp': 1} for i in range(n): arr = input().split() name1 = arr[0].lower() name2 = arr[2].lower() cnt[name1] = cnt[name2]+1 print(max(cnt.values()))
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
522/A
522
A
PyPy 3-64
TESTS
5
46
0
223928906
if __name__ == '__main__': n = int(input()) mp = dict() mp['polycarp'] = [] for i in range(0,n): p = input().split() p = [t.lower() for t in p] if p[2] in mp: mp[p[2]].append(p[0]) else: mp[p[2]] = [p[0]] # print(mp) start = 'polycarp' ...
36
46
0
132368865
adj={'polycarp':1} n=int(input()) for i in range(n): string1,reposted,string2=input().lower().split(" ") adj[string1]=adj[string2]+1 #if string2 not in adj: # adj[string2]=[string1] #else: # adj[string2]=adj[string2]+[string1] # {'Polycarp': ['tourist'], 'Tourist': ['Petr'], 'Petr': ['WJM...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
408/A
408
A
Python 3
TESTS
7
46
0
141696669
n = int(input()) klist = [int(x) for x in input().split()] amin = 100 for i in range(n): m = sum(map(int, input().split())) amin = min(amin, m + 3*klist[i]) print(amin*5)
20
31
0
163993892
n = int(input()) k = list(map(int, input().split())) costs = [] for _k in k: m = list(map(int, input().split())) cost = _k * 15 + sum(m) * 5 costs.append(cost) print(min(costs)) # print(costs)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
522/A
522
A
Python 3
TESTS
5
31
0
211809406
n = int(input()) d = dict() for i in range(n): x = input().split() #print(x[0]) #print(x[2]) x[0] = x[0].lower() x[2] = x[2].lower() d[x[0]] = x[2] #print(d) ans = 0 a = 'polycarp' for i in d: if d[i] == a: ans += 1 a = i #print(i) print(ans+1)
36
46
0
138348803
n = int(input()) d = {'polycarp': 1} m = 0 for i in range(n): a, b, c = input().split() a = a.lower() c = c.lower() d.update({a:(d[c]+1)}) m = max (d[a], m) print (m)
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
283/B
283
B
PyPy 3
TESTS
2
404
23,142,400
25080715
import sys sys.setrecursionlimit(int(1e6)) n = int(input()) a = [0] * 2 + list(map(int, input().split())) vis = [[0] * 2 for x in range(n + 1)] dp = [[0] * 2 for x in range(n + 1)] def dfs(u, s): vis[u][s] = 1 if s == 0: v = u + a[u] else: v = u - a[u] if v <= 0 or v > n: dp[u][s] = a[u] else: if v == 1...
50
1,872
29,593,600
5340828
n = int(input()) t = [0, 0] + list(map(int, input().split())) a, b = [0] * (n + 1), [0] * (n + 1) a[1] = b[1] = -1 def f(s, a, b, l): global t l.reverse() j, n = 0, len(l) while True: s += t[l[j]] a[l[j]] = s j += 1 if j == n: return s += t[l[j]] b[l[...
Codeforces Round 174 (Div. 1)
CF
2,013
2
256
Cow Program
Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates. 2. The progra...
The first line contains a single integer, n (2 ≤ n ≤ 2·105). The next line contains n - 1 space separated integers, a2, a3, ..., an (1 ≤ ai ≤ 109).
Output n - 1 lines. On the i-th line, print the requested value when the program is run on the sequence i, a2, a3, ...an. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample 1. For i = 1,  x becomes $$1 \rightarrow 2 \rightarrow 0$$ and y becomes 1 + 2 = 3. 2. For i = 2,  x becomes $$1 \rightarrow 3 \rightarrow - 1$$ and y becomes 2 + 4 = 6. 3. For i = 3,  x becomes $$1 \rightarrow 4 \rightarrow 3 \rightarrow 7$$ and y becomes 3 + 1 + 4 = 8.
[{"input": "4\n2 4 1", "output": "3\n6\n8"}, {"input": "3\n1 2", "output": "-1\n-1"}]
1,700
["dfs and similar", "dp", "graphs"]
50
[{"input": "4\r\n2 4 1\r\n", "output": "3\r\n6\r\n8\r\n"}, {"input": "3\r\n1 2\r\n", "output": "-1\r\n-1\r\n"}, {"input": "5\r\n2 2 1 3\r\n", "output": "3\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "2\r\n1\r\n", "output": "-1\r\n"}, {"input": "8\r\n7 6 2 6 2 6 6\r\n", "output": "8\r\n8\r\n12\r\n10\r\n-1\r\n-1\r\n20\r\n"}, {"in...
false
stdio
null
true
799/C
799
C
Python 3
TESTS
3
61
7,168,000
125512227
''' first we find the 2 fountains with max beauty we can buy with c coins then we find 2 fountains with max beauty with d diamonds then we find 1 with c coins and 1 with d diamonds how to find? sort according to beauty and see if we can afford i + i+1 ''' from sys import stdin, stdout import sys import math import it...
79
498
8,294,400
91635832
from bisect import * def pair(fc, tc): bf = [] maxb = 0 ans = 0 for f in fc: p, b = f maxpp = tc - p ii = bisect_left(bf, (maxpp+1, 0)) - 1 if ii >= 0: pp, bb = bf[ii] ans = max(ans, bb + b) if b > maxb: bf.append(f) ...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow...
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has. The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, ...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
null
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
[{"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9"}, {"input": "2 4 5\n2 5 C\n2 1 D", "output": "0"}, {"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10"}]
1,800
["binary search", "data structures", "implementation"]
79
[{"input": "3 7 6\r\n10 8 C\r\n4 3 C\r\n5 6 D\r\n", "output": "9\r\n"}, {"input": "2 4 5\r\n2 5 C\r\n2 1 D\r\n", "output": "0\r\n"}, {"input": "3 10 10\r\n5 5 C\r\n5 5 C\r\n10 11 D\r\n", "output": "10\r\n"}, {"input": "6 68 40\r\n1 18 D\r\n6 16 D\r\n11 16 D\r\n7 23 D\r\n16 30 D\r\n2 20 D\r\n", "output": "18\r\n"}, {"in...
false
stdio
null
true
802/B
802
B
PyPy 3
TESTS
8
374
28,057,600
106899239
import sys input = sys.stdin.readline from collections import deque, defaultdict from heapq import heappush, heappop n, k = map(int, input().split()) A = list(map(int, input().split())) dic = defaultdict(deque) for i, a in enumerate(A): dic[a].append(i) hp = [] # for d in dic: # heappush(hp, (-dic[d][0], d)) S ...
50
2,744
91,443,200
60347194
# https://codeforces.com/problemset/problem/802/B import heapq n, k = map(int, input().split()) a = list(map(int, input().split())) d = {} pos = {} Q = [] cnt = 0 for i, x in enumerate(a): if x not in pos: pos[x] = [] pos[x].append(i) for i, x in enumerate(a): if x not in...
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
10
256
Heidi and Library (medium)
Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Same as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.
Same as the easy version.
null
null
[{"input": "4 100\n1 2 2 1", "output": "2"}, {"input": "4 1\n1 2 2 1", "output": "3"}, {"input": "4 2\n1 2 3 1", "output": "3"}]
1,800
["data structures", "greedy"]
50
[{"input": "4 100\r\n1 2 2 1\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 2 2 1\r\n", "output": "3\r\n"}, {"input": "4 2\r\n1 2 3 1\r\n", "output": "3\r\n"}, {"input": "11 1\r\n1 2 3 5 1 10 10 1 1 3 5\r\n", "output": "9\r\n"}, {"input": "5 2\r\n1 2 3 1 2\r\n", "output": "4\r\n"}, {"input": "4 2\r\n1 2 3 2\r\n", "outpu...
false
stdio
null
true
799/C
799
C
PyPy 3
TESTS
3
124
22,016,000
91340519
n, c, d = map(int, input().split()) a = [0] * n sc = [] sd = [] for i in range(n): b, p, t = input().split() b, p = int(b), int(p) a[i] = [b, p, t] if t == 'C': sc.append([p, b]) else: sd.append([p, b]) maxc, maxd = -int(2e9), -int(2e9) for i in range(n): if a[i][2] == 'C' a...
79
624
13,107,200
178167785
import sys def solution(ways, cost_all): way_map = dict( C=[0]*(cost_all['C']+1), D=[0]*(cost_all['D']+1) ) ans = 0 for ws in ways: w = ws.split(' ') b, c = int(w[0]), int(w[1]) if c > cost_all[w[2]]: continue if c*2 <= cost_all[w[2]] and way...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow...
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has. The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, ...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
null
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
[{"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9"}, {"input": "2 4 5\n2 5 C\n2 1 D", "output": "0"}, {"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10"}]
1,800
["binary search", "data structures", "implementation"]
79
[{"input": "3 7 6\r\n10 8 C\r\n4 3 C\r\n5 6 D\r\n", "output": "9\r\n"}, {"input": "2 4 5\r\n2 5 C\r\n2 1 D\r\n", "output": "0\r\n"}, {"input": "3 10 10\r\n5 5 C\r\n5 5 C\r\n10 11 D\r\n", "output": "10\r\n"}, {"input": "6 68 40\r\n1 18 D\r\n6 16 D\r\n11 16 D\r\n7 23 D\r\n16 30 D\r\n2 20 D\r\n", "output": "18\r\n"}, {"in...
false
stdio
null
true
976/D
976
D
PyPy 3
TESTS
0
124
0
56053320
n = int(input()) D = list(map(int, input().split())) now_v = 1 ind_d = n - 1 minus = 0 A = [] while D[ind_d] > minus: for i in range(D[ind_d] - minus): A.append([now_v, now_v + i + 1]) now_v += 1 ind_d -= 1 minus += 1 print(len(A)) for u, v in A: print(u, v)
20
545
43,929,600
197470206
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) d = list(map(int, input().split())) ans = [] l = 1 while len(d): d0 = d[0] m = l + d0 r = l + d[-1] + 1 for u in range(l, m): for v in range(u + 1, r): ans.append(" ".join(map(str, (u, v...
Educational Codeforces Round 43 (Rated for Div. 2)
ICPC
2,018
2
256
Degree Set
You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that: - there are exactly dn + 1 vertices; - there are no self-loops; - there are no multiple edges; - there are no more than 106 edges; - its degree set is equal to d. Vertices sho...
The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.
In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges. Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description o...
null
null
[{"input": "3\n2 3 4", "output": "8\n3 1\n4 2\n4 5\n2 5\n5 1\n3 2\n2 1\n5 3"}, {"input": "3\n1 2 3", "output": "4\n1 2\n1 3\n1 4\n2 3"}]
2,500
["constructive algorithms", "graphs", "implementation"]
20
[{"input": "3\r\n2 3 4\r\n", "output": "8\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "4\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n"}, {"input": "4\r\n1 3 4 6\r\n", "output": "11\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n"}, {"input": "...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline()) d_list = list(map(int, f.readline().split())) with open(submission_path) as f: lines = f.read().splitlines() if not lines: print(0) return ...
true
469/B
469
B
Python 3
TESTS
4
46
0
226987093
fixed_schedule_count, flex_schedule_count, l_range, r_range = map(int,input().split()) fixed_schedule = [] flex_schedule = [] for i in range(fixed_schedule_count): x = list(map(int,input().split())) fixed_schedule.append(x) for i in range(flex_schedule_count): x = list(map(int,input().split())) flex_...
31
77
2,969,600
230865208
p,q,l,r =map(int,input().split()) ll,kk=set(),[] for _ in range(p): x,y=map(int,input().split()) for i in range(x,y+1): ll.add(i) for _ in range(q): x,y=map(int,input().split()) kk.append([x,y]) res=0 for i in range(l,r+1): flag=False for m in kk: x,y=m x+=i y+=i ...
Codeforces Round 268 (Div. 2)
CF
2,014
1
256
Chat Online
Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the ti...
The first line contains four space-separated integers p, q, l, r (1 ≤ p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000). Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000). It's guaranteed that bi < ai + 1 ...
Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.
null
null
[{"input": "1 1 0 4\n2 3\n0 1", "output": "3"}, {"input": "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "output": "20"}]
1,300
["implementation"]
31
[{"input": "1 1 0 4\r\n2 3\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2 3 0 20\r\n15 17\r\n23 26\r\n1 4\r\n7 11\r\n15 17\r\n", "output": "20\r\n"}, {"input": "5 2 27 452\r\n148 154\r\n421 427\r\n462 470\r\n777 786\r\n969 978\r\n245 247\r\n313 322\r\n", "output": "54\r\n"}, {"input": "3 6 25 785\r\n273 275\r\n391 397\r...
false
stdio
null
true
522/A
522
A
Python 3
TESTS
6
109
0
60197977
n=int(input()) l='polycarp' x=1 for i in range(n): s = input().lower().split() if s[0] not in l and s[2] in l: l=s[0] x+=1 print(x)
36
46
0
139133934
mas = {} mas["polycarp"]=1 n = int(input()) i, res = 0, 1 for i in range(n): name1, a, name2 = input().split() name1, a, name2 = name1.lower(), a.lower(), name2.lower() e = mas[name2] + 1 mas[name1] = e if e > res: res = e print(res)
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
802/J
802
J
Python 3
TESTS
4
31
102,400
196262851
from collections import defaultdict def dfs(node, v, coast): v.append(node) for i in num_list[node]: if i[0] not in v: coast[-1] += i[1] dfs(i[0], v, coast) coast.append(0) return max(coast) n = int(input()) num_list = defaultdict(list) for i in range(n - 1)...
32
46
0
145972792
import sys sys.setrecursionlimit(10**9) n=int(input()) q={} l={} for i in range(n): q[i]={} l[i]=0 z={} for i in range(n-1): a,b,c=map(int,input().split()) q[a][b]=c q[b][a]=c def f(i): z[i]=0 for j in q[i]: if j not in z: l[j]=l[i]+q[i][j] f(j) f(0) print(ma...
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Send the Fool Further! (easy)
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
The first line of the input contains the number of friends n (3 ≤ n ≤ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≤ u, v ≤ n - 1, 1 ≤ c ≤ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that th...
Output a single integer – the maximum sum of costs.
null
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
[{"input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5"}, {"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10", "output": "105"}, {"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378", "output": "5551"}]
1,400
["dfs and similar", "graphs", "trees"]
32
[{"input": "4\r\n0 1 4\r\n0 2 2\r\n2 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 0 5987\r\n2 0 8891\r\n", "output": "8891\r\n"}, {"input": "10\r\n1 0 518\r\n2 0 4071\r\n3 1 121\r\n4 2 3967\r\n5 3 9138\r\n6 2 9513\r\n7 3 3499\r\n8 2 2337\r\n9 4 7647\r\n", "output": "15685\r\n"}, {"input": "11\r\n1 0 6646\r\n2 0 8816...
false
stdio
null
true
802/J
802
J
Python 3
TESTS
4
62
0
116939788
import sys n=int(input()) graph = [[] for _ in range(n)] for i in range(n - 1): inf = list(map(int, input().split())) v1 = inf[0] v2 = inf[1] c=inf[2] graph[v1].append([v2,c]) graph[v2].append([v1,c]) curr = [0,0] stk = [] nvis = [True] * n ans = 0 lea=[False]*n k=0 lc=[0]*n for i in range(n): ...
32
46
0
153223025
N = int(input()) dat = [[] for _ in range(N)] for _ in range(N-1): a,b,c = map(int,input().split()) dat[a].append([b,c]) dat[b].append([a,c]) def dfs(i,num=0): global ans ans = max(ans,num) visited[i] = 1 for x,y in dat[i]: if visited[x]==1:continue dfs(x,num+y) visited = [0]*N ans = 0 dfs(0) print(ans)
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Send the Fool Further! (easy)
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
The first line of the input contains the number of friends n (3 ≤ n ≤ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≤ u, v ≤ n - 1, 1 ≤ c ≤ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that th...
Output a single integer – the maximum sum of costs.
null
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
[{"input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5"}, {"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10", "output": "105"}, {"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378", "output": "5551"}]
1,400
["dfs and similar", "graphs", "trees"]
32
[{"input": "4\r\n0 1 4\r\n0 2 2\r\n2 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 0 5987\r\n2 0 8891\r\n", "output": "8891\r\n"}, {"input": "10\r\n1 0 518\r\n2 0 4071\r\n3 1 121\r\n4 2 3967\r\n5 3 9138\r\n6 2 9513\r\n7 3 3499\r\n8 2 2337\r\n9 4 7647\r\n", "output": "15685\r\n"}, {"input": "11\r\n1 0 6646\r\n2 0 8816...
false
stdio
null
true
802/M
802
M
Python 3
TESTS
6
139
102,400
216625642
n, a = map(int, input().split()) s = list(map(int, input().split())) c = 0 for i in range(a): c = c + min(s) s[s.index(min(s))] = 2200 print(c)
14
31
0
167665055
a,b=map(int,input().split()) t=[int(i) for i in input().split()] count=0 t.sort() for i in range(b):count+=t[i] print(count)
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
2
256
April Fools' Problem (easy)
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea...
The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104).
Output one number.
null
null
[{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}]
1,200
["greedy", "sortings"]
14
[{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1...
false
stdio
null
true
408/A
408
A
Python 3
TESTS
18
77
307,200
107636556
n = int(input()) people_in_queue = list(map(int, input().split())) number_of_products = [] for i in range(n): products_for_ith_person = list(map(int, input().split())) number_of_products.append(products_for_ith_person) num_sec1 = 0 num_sec2 = 0 temp = [] if n == 1: print(20) else: for i in range(n-1): ...
20
31
0
181404553
n = int(input()) a = input().split() l = [] for i in range(n): s = 0 b = input().split() for j in b: s = s+5*int(j) l.append(s+len(b)*15) print(min(l))
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
519/D
519
D
Python 3
TESTS
5
155
307,200
116443201
costss=list(map(int,input().split())) s=input() costs={} cost=0 ans=0 for i in range(len(s)): cost+=costss[ord(s[i])-97] if s[i] not in costs: costs[s[i]]={} costs[s[i]][cost]=costs[s[i]].get(cost,0)+1 if costss[ord(s[i])-97]!=0: ans+=costs[s[i]][cost]*costs[s[i]].get(cost-costss[ord(s[i...
47
124
15,974,400
147645327
from collections import Counter A = list(map(int, input().split())) L = [ord(i) - ord('a') for i in input()] score = ans = 0 D = [Counter() for i in range(26)] for i in L: ans += D[i][score] score += A[i] D[i][score] += 1 print(ans)
Codeforces Round 294 (Div. 2)
CF
2,015
2
256
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively. The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
Print the answer to the problem.
null
In the first sample test strings satisfying the condition above are abca and bcab. In the second sample test strings satisfying the condition above are two occurences of aa.
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "output": "2"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "output": "2"}]
1,800
["data structures", "dp", "two pointers"]
47
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\nxabcab\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naaa\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naabbccdd\r\n", "output": "4\r\n"}, {"input": "-3 4 -4 -...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
248
12,800,000
26415472
'''input 5 0 1 3 4 2 ''' n = int(input()) a = list(map(int, input().split())) s, t = 0, 1 for x in range(n): if a[x] == x: s += 1 elif t == 1 and a[a[x]] == x: t = 2 print(s + t + int(s == n))
19
154
13,209,600
165840569
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) c = 0 f = 1 for i in range(n): if(a[i] == i): c += 1 elif(a[a[i]] == i and f): c += 2 f = 0 if(c != n and f): c += 1 print(c)
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
802/J
802
J
Python 3
TESTS
6
93
307,200
59188514
import sys mod = 1000000007 def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline() def print_array(a): print(" ".join(map(str, a))) def maxCost(cost, tree, c, p): frnds = tree[c] if len(frnds) < ...
32
46
0
153973363
n=int(input()) l1=[] for i in range(n-1): l2=[int(a) for a in input().split()] l1.append(l2) l1.append([l2[1],l2[0],l2[2]]) l1.sort() l2=[0]*(n+1) ls=[[0]] ctr=1 cur=[] while ctr<n: for i in ls[-1]: for j in range(2*(n-1)): if l1[j][0]==i and l2[l1[j][1]]==0: l2[l...
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Send the Fool Further! (easy)
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
The first line of the input contains the number of friends n (3 ≤ n ≤ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≤ u, v ≤ n - 1, 1 ≤ c ≤ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that th...
Output a single integer – the maximum sum of costs.
null
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
[{"input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5"}, {"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10", "output": "105"}, {"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378", "output": "5551"}]
1,400
["dfs and similar", "graphs", "trees"]
32
[{"input": "4\r\n0 1 4\r\n0 2 2\r\n2 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 0 5987\r\n2 0 8891\r\n", "output": "8891\r\n"}, {"input": "10\r\n1 0 518\r\n2 0 4071\r\n3 1 121\r\n4 2 3967\r\n5 3 9138\r\n6 2 9513\r\n7 3 3499\r\n8 2 2337\r\n9 4 7647\r\n", "output": "15685\r\n"}, {"input": "11\r\n1 0 6646\r\n2 0 8816...
false
stdio
null
true
802/J
802
J
PyPy 3
TESTS
6
108
409,600
104218157
import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 #def input(): return sys.stdin.readline().strip() input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map...
32
46
0
167959631
import sys sys.setrecursionlimit(10 ** 5) n = int(input()) graph = [[] for i in range(n)] edge = {} for i in range(n-1): u , v , p = list(map(int,input().split())) graph[u].append(v) graph[v].append(u) edge[(u , v)] = p edge[(v , u)] = p vis = [0 for i in range(n)] val = [0 for i in range(n)] def dfs(u): vis[u] =...
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Send the Fool Further! (easy)
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
The first line of the input contains the number of friends n (3 ≤ n ≤ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≤ u, v ≤ n - 1, 1 ≤ c ≤ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that th...
Output a single integer – the maximum sum of costs.
null
In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2).
[{"input": "4\n0 1 4\n0 2 2\n2 3 3", "output": "5"}, {"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10", "output": "105"}, {"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378", "output": "5551"}]
1,400
["dfs and similar", "graphs", "trees"]
32
[{"input": "4\r\n0 1 4\r\n0 2 2\r\n2 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 0 5987\r\n2 0 8891\r\n", "output": "8891\r\n"}, {"input": "10\r\n1 0 518\r\n2 0 4071\r\n3 1 121\r\n4 2 3967\r\n5 3 9138\r\n6 2 9513\r\n7 3 3499\r\n8 2 2337\r\n9 4 7647\r\n", "output": "15685\r\n"}, {"input": "11\r\n1 0 6646\r\n2 0 8816...
false
stdio
null
true
552/A
552
A
Python 3
TESTS
2
46
0
14177519
n = int(input()) points = [] for i in range(0, n): points.append(list(map(int, input().split()))) nrt = 0 for p in points: nrt += abs(p[3] - p[0] + 1) * abs(p[2] - p[0] + 1) print(nrt)
26
31
0
180420886
print(sum(map(lambda a:-~(a[2]-a[0])*-~(a[3]-a[1]),(list(map(int,input().split()))for i in range(int(input()))))))
Codeforces Round 308 (Div. 2)
CF
2,015
2
256
Vanya and Table
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multi...
The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles. Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the u...
In a single line print the sum of all values in the cells of the table.
null
Note to the first sample test: Values of the table in the first three rows and columns will be as follows: 121 121 110 So, the sum of values will be equal to 10. Note to the second sample test: Values of the table in the first three rows and columns will be as follows: 222 222 222 So, the sum of values will ...
[{"input": "2\n1 1 2 3\n2 2 3 3", "output": "10"}, {"input": "2\n1 1 3 3\n1 1 3 3", "output": "18"}]
1,000
["implementation", "math"]
26
[{"input": "2\r\n1 1 2 3\r\n2 2 3 3\r\n", "output": "10\r\n"}, {"input": "2\r\n1 1 3 3\r\n1 1 3 3\r\n", "output": "18\r\n"}, {"input": "5\r\n4 11 20 15\r\n7 5 12 20\r\n10 8 16 12\r\n7 5 12 15\r\n2 2 20 13\r\n", "output": "510\r\n"}, {"input": "5\r\n4 11 20 20\r\n6 11 20 16\r\n5 2 19 15\r\n11 3 18 15\r\n3 2 14 11\r\n", ...
false
stdio
null
true
552/A
552
A
Python 3
TESTS
2
62
6,656,000
115905466
sum=0 for _ in range(int(input())): x,y,a,b=map(int,input().split()) sum+=(a-y+1)*(b-y+1) print(sum)
26
31
0
221688639
import sys n = int(input()) ans = 0 for i in range(n): x1, y, x2, y2 = list(map(int, sys.stdin.readline().split())) ans += (x2-x1+1)*(y2-y+1) print(ans)
Codeforces Round 308 (Div. 2)
CF
2,015
2
256
Vanya and Table
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multi...
The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles. Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the u...
In a single line print the sum of all values in the cells of the table.
null
Note to the first sample test: Values of the table in the first three rows and columns will be as follows: 121 121 110 So, the sum of values will be equal to 10. Note to the second sample test: Values of the table in the first three rows and columns will be as follows: 222 222 222 So, the sum of values will ...
[{"input": "2\n1 1 2 3\n2 2 3 3", "output": "10"}, {"input": "2\n1 1 3 3\n1 1 3 3", "output": "18"}]
1,000
["implementation", "math"]
26
[{"input": "2\r\n1 1 2 3\r\n2 2 3 3\r\n", "output": "10\r\n"}, {"input": "2\r\n1 1 3 3\r\n1 1 3 3\r\n", "output": "18\r\n"}, {"input": "5\r\n4 11 20 15\r\n7 5 12 20\r\n10 8 16 12\r\n7 5 12 15\r\n2 2 20 13\r\n", "output": "510\r\n"}, {"input": "5\r\n4 11 20 20\r\n6 11 20 16\r\n5 2 19 15\r\n11 3 18 15\r\n3 2 14 11\r\n", ...
false
stdio
null
true
552/A
552
A
Python 3
TESTS
6
62
4,608,000
28301126
n = int(input()) coordinates = [] for x in range(n): string = input() numbers = string.split() for y in range(4): numbers[y] = int(numbers[y]) rectangle = [numbers[0], numbers[1], numbers[2], numbers[3]] coordinates.append(rectangle) a = max([x[3] for x in coordinates]) b = max([x[2] for x i...
26
46
0
11636027
if __name__ == '__main__': n = int(input()) total = 0 for i in range(n): x1, y1, x2, y2 = map(int, input().split()) w = abs(x1 - x2) + 1 h = abs(y1 - y2) + 1 total += w * h print(total)
Codeforces Round 308 (Div. 2)
CF
2,015
2
256
Vanya and Table
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multi...
The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles. Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the u...
In a single line print the sum of all values in the cells of the table.
null
Note to the first sample test: Values of the table in the first three rows and columns will be as follows: 121 121 110 So, the sum of values will be equal to 10. Note to the second sample test: Values of the table in the first three rows and columns will be as follows: 222 222 222 So, the sum of values will ...
[{"input": "2\n1 1 2 3\n2 2 3 3", "output": "10"}, {"input": "2\n1 1 3 3\n1 1 3 3", "output": "18"}]
1,000
["implementation", "math"]
26
[{"input": "2\r\n1 1 2 3\r\n2 2 3 3\r\n", "output": "10\r\n"}, {"input": "2\r\n1 1 3 3\r\n1 1 3 3\r\n", "output": "18\r\n"}, {"input": "5\r\n4 11 20 15\r\n7 5 12 20\r\n10 8 16 12\r\n7 5 12 15\r\n2 2 20 13\r\n", "output": "510\r\n"}, {"input": "5\r\n4 11 20 20\r\n6 11 20 16\r\n5 2 19 15\r\n11 3 18 15\r\n3 2 14 11\r\n", ...
false
stdio
null
true
723/D
723
D
Python 3
TESTS
5
46
102,400
214719566
MAX = 55 berland = [None] * MAX desberland = [None] * MAX dr = [-1, 0, 0, 1] dc = [0, -1, 1, 0] answer = [] visited = [[False for _ in range(MAX)] for _ in range(MAX)] path = [[0 for _ in range(MAX)] for _ in range(MAX)] def DFSLakes(sr, sc): global count, total, testEsc if visited[sr][sc] == True: coun...
26
61
512,000
214729825
MAX = 55 berland = [None] * MAX desberland = [None] * MAX dr = [-1, 0, 0, 1] dc = [0, -1, 1, 0] answer = [] visited = [[False for _ in range(MAX)] for _ in range(MAX)] path = [[0 for _ in range(MAX)] for _ in range(MAX)] def DFSLakes(sr, sc): global count, total, testEsc s = [(sr, sc)] visited[sr][sc] = Tru...
Codeforces Round 375 (Div. 2)
CF
2,016
2
256
Lakes in Berland
The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that ...
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell ...
In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri...
null
In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with th...
[{"input": "5 4 1\n****\n*..*\n****\n**.*\n..**", "output": "1\n****\n*..*\n****\n****\n..**"}, {"input": "3 3 0\n***\n*.*\n***", "output": "1\n***\n***\n***"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy", "implementation"]
26
[{"input": "5 4 1\r\n****\r\n*..*\r\n****\r\n**.*\r\n..**\r\n", "output": "1\r\n****\r\n*..*\r\n****\r\n****\r\n..**\r\n"}, {"input": "3 3 0\r\n***\r\n*.*\r\n***\r\n", "output": "1\r\n***\r\n***\r\n***\r\n"}, {"input": "3 5 1\r\n.**.*\r\n*.*.*\r\n***..\r\n", "output": "0\r\n.**.*\r\n*.*.*\r\n***..\r\n"}, {"input": "3 5...
false
stdio
import sys from sys import argv def main(): input_path = argv[1] output_path = argv[2] submission_path = argv[3] with open(input_path, 'r') as f: input_lines = f.read().splitlines() n, m, k = map(int, input_lines[0].split()) original_map = input_lines[1:n+1] with open(output_path,...
true
803/E
803
E
Python 3
TESTS
4
93
8,806,400
26969980
n, k = [int(i) for i in input().split()] s = input() dp = [[False] * 2100 for i in range(1001)] dp[0][0] = True for i in range(n): l = -k + 1 r = k if i == n - 1: l -= 1 r += 1 for b in range(l, r): if s[i] == 'L': dp[i + 1][b] = dp[i][b + 1] elif s[i] == 'W...
28
280
43,417,600
26744810
import sys def solve(): n, k = map(int, input().split()) s = input() dp = [[False]*(2*k + 1) for i in range(n + 1)] dp[0][0] = True keiro = [['']*(2*k + 1) for i in range(n + 1)] for i, ch in enumerate(s): if ch == 'W': for j in range(-(k - 2), k + 1): if ...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
803/F
803
F
Python 3
TESTS
5
46
102,400
199389537
from collections import Counter import sys n = int(input()) nums = list(map(int, input().split(' '))) MOD = 10**9 +7 def dfs(cnt,length,k): if length == 0:return 0 ret = 0 if k==1: leng = length sorted_keys = sorted(cnt.keys()) for key in sorted_keys: ...
35
187
31,948,800
127579202
import sys input = sys.stdin.readline n = int(input()) mod = pow(10, 9) + 7 a = list(map(int, input().split())) l = 100000 cnt = [0] * (l + 1) for i in a: cnt[i] += 1 pow2 = [1] for _ in range(l): pow2.append(2 * pow2[-1] % mod) ans = pow2[n] - 1 x = [-1] * (l + 1) for i in range(2, l + 1): c = cnt[i] ...
Educational Codeforces Round 20
ICPC
2,017
2
256
Coprime Subsequences
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109 + 7. Note th...
The first line contains one integer number n (1 ≤ n ≤ 100000). The second line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 100000).
Print the number of coprime subsequences of a modulo 109 + 7.
null
In the first example coprime subsequences are: 1. 1 2. 1, 2 3. 1, 3 4. 1, 2, 3 5. 2, 3 In the second example all subsequences are coprime.
[{"input": "3\n1 2 3", "output": "5"}, {"input": "4\n1 1 1 1", "output": "15"}, {"input": "7\n1 3 5 15 3 105 35", "output": "100"}]
2,000
["bitmasks", "combinatorics", "number theory"]
35
[{"input": "3\r\n1 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "15\r\n"}, {"input": "7\r\n1 3 5 15 3 105 35\r\n", "output": "100\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n100000\r\n", "output": "0\r\n"}, {"input": "5\r\n10 8 6 4 6\r\n", "output": "0\r\n"}, {"input": "5...
false
stdio
null
true
51/A
51
A
Python 3
TESTS
3
62
0
165037605
import sys input = sys.stdin.readline from collections import Counter n = int(input()) w = Counter() for i in range(n): a, b = map(int, list(input()[:-1])) c, d = map(int, list(input()[:-1])) if i != n-1: z = input()[:-1] x = a+b+c+d w[28-x] += 1 print(len(w))
20
92
0
196763288
# LUOGU_RID: 104229404 n = int(input()) st = set() for i in range(n): s = input() + input()[::-1] if i < n - 1: input() if all(s not in x for x in st): st.add(2 * s) print(len(st))
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
519/D
519
D
PyPy 3
TESTS
1
62
0
117140488
x=list(map(int,input().split())) s=list(input().rstrip()) n=len(s) cx=[0]*(n+1) for i in range(1,n+1): cx[i]=x[ord(s[i-1])-ord("a")] for i in range(1,n+1): cx[i]+=cx[i-1] pos=[{} for i in range(26)] ans=0 for i in range(n): ss=s[i] ans+=pos[ord(ss)-ord("a")].get(cx[i],0) pos[ord(ss)-ord("a")][cx[i+1]]=pos[ord...
47
140
16,281,600
230114557
import sys import string from collections import defaultdict,Counter def solve(vals,s): past = defaultdict(Counter) pref = 0 res = 0 for x in s: res +=past[x][pref] pref +=vals[ord(x) - ord('a')] past[x][pref] +=1 return res # input # t = int(sys.stdin.readline()) # solve he...
Codeforces Round 294 (Div. 2)
CF
2,015
2
256
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively. The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
Print the answer to the problem.
null
In the first sample test strings satisfying the condition above are abca and bcab. In the second sample test strings satisfying the condition above are two occurences of aa.
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "output": "2"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "output": "2"}]
1,800
["data structures", "dp", "two pointers"]
47
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\nxabcab\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naaa\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naabbccdd\r\n", "output": "4\r\n"}, {"input": "-3 4 -4 -...
false
stdio
null
true
724/D
724
D
PyPy 3-64
TESTS
4
155
0
162942379
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().strip() m, s = int(input()), input() n = len(s) lst, ans = [0] * 26, array('u') vis = array('b', [0] * n) ma = 'a' for i in range(m - 1): lst[ord(s[i]) - 97] = i for i in range(m - 1, n): lst[ord(s[i]) - 97] = i if s...
71
249
30,310,400
21292971
m = int(input()) s = input().strip() sa = [0] * len(s) for i in range(len(s)): sa[i] = ord(s[i]) - ord('a') sa = [-1] + sa + [-1] def check_value(sa, m, threshold): prev_ind = 0 for i in range(len(sa)): if sa[i] <= threshold: if i - prev_ind <= m: prev_ind = i else: return False return True def ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
39/F
39
F
PyPy 3
TESTS
4
280
0
68864736
rdl = lambda: map(int, input().split()) def conv(x): x = str(x); x = x.replace('{','');x = x.replace('}',''); x = x.replace(',',''); return [int(s) for s in x.split()] a,b,c = rdl();ll = list(rdl());x = sorted(list(rdl()));lx =[];xr=[];sna = [];flag = False for i in range(len(x)): f = x[i];cou = 0 for j ...
35
122
2,150,400
154420195
n,m,k = map(int,input().split()) frog = list(map(int,input().split())) mos = list(map(int,input().split())) ans = [] res = float('inf') for i in range(m): f = frog[i] count = 0 for ms in mos: if (ms)%f==0: count+=1 if res>count: ans = [i+1] res = count elif res==c...
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n...
The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleep...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.
null
null
[{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}]
1,300
["implementation"]
35
[{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r...
false
stdio
null
true
39/F
39
F
PyPy 3
TESTS
3
310
20,275,200
90586154
import math from collections import defaultdict,deque from itertools import permutations ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" t=1 #t=ii() for _ in range(t): n,m,k=...
35
124
0
12252397
n, m, k = map(int, input().split()) frogs = list(map(int, input().split())) mosquitoes = list(map(int, input().split())) def get_smash(leap): result = 0 for x in mosquitoes: if x % leap == 0: result += 1 return result best_smash = get_smash(frogs[0]) best_frogs = [1] for i, frog in enumerate(frogs[1:...
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n...
The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleep...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.
null
null
[{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}]
1,300
["implementation"]
35
[{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r...
false
stdio
null
true
723/D
723
D
Python 3
TESTS
5
46
102,400
205149540
def fillLake(s, graph): visited = set() visited.add(s) graph[s[0]][s[1]] = '*' # fill the water cell directions = [(0, -1), (0, 1), (-1, 0), (1, 0)] for d in directions: cellRow = s[0] + d[0] cellCol = s[1] + d[1] if cellRow in range(len(graph[0])) and cellCol in range(len(graph)): if graph[...
26
62
307,200
21165775
x,y,k=list(map(int,input().split())) a=[input().strip() for i in range(x)] m=[[0 if j=='*' else 1 for j in i] for i in a] m1=[[0 if j=='*' else 1 for j in i] for i in a] lk=[] def bfs(m,i,j): q=set() s=0 f=1 q.add((i,j)) while q: ax,ay=q.pop() m[ax][ay]=0 s+=1 if ax==0 or ay==0 or ax==x-1 or ay==y-1:f=0 ...
Codeforces Round 375 (Div. 2)
CF
2,016
2
256
Lakes in Berland
The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that ...
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell ...
In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri...
null
In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with th...
[{"input": "5 4 1\n****\n*..*\n****\n**.*\n..**", "output": "1\n****\n*..*\n****\n****\n..**"}, {"input": "3 3 0\n***\n*.*\n***", "output": "1\n***\n***\n***"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy", "implementation"]
26
[{"input": "5 4 1\r\n****\r\n*..*\r\n****\r\n**.*\r\n..**\r\n", "output": "1\r\n****\r\n*..*\r\n****\r\n****\r\n..**\r\n"}, {"input": "3 3 0\r\n***\r\n*.*\r\n***\r\n", "output": "1\r\n***\r\n***\r\n***\r\n"}, {"input": "3 5 1\r\n.**.*\r\n*.*.*\r\n***..\r\n", "output": "0\r\n.**.*\r\n*.*.*\r\n***..\r\n"}, {"input": "3 5...
false
stdio
import sys from sys import argv def main(): input_path = argv[1] output_path = argv[2] submission_path = argv[3] with open(input_path, 'r') as f: input_lines = f.read().splitlines() n, m, k = map(int, input_lines[0].split()) original_map = input_lines[1:n+1] with open(output_path,...
true
724/D
724
D
Python 3
PRETESTS
4
77
5,427,200
21294684
from itertools import combinations import copy def generate_answer(e): copy_symbol_index = copy.deepcopy(symbol_index) ans = [] for sym in e: copy_symbol_index.add(sym) for i in copy_symbol_index: ans.append(s[i]) return "".join(sorted(ans)) if __name__ == '__main__': m = int...
71
249
31,436,800
21461331
m = int(input()) s = input() ans = [] mark = [True for _ in range(len(s))] z = 'a' i = 0 while i <= len(s) - m: k = i for j in range(i, i + m): if s[j] <= s[k]: k = j ans.append(s[k]) z = max(z, s[k]) mark[k] = False i = k i += 1 for i in range(len(s)): ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true