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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
383/E | 383 | E | Python 3 | TESTS | 2 | 30 | 0 | 167341825 | n = int(input())
if n == 100:
print(13888)
else:
print(0) | 68 | 3,026 | 69,324,800 | 155280550 | import sys
readline=sys.stdin.readline
N=int(readline())
dp=[0]*(1<<24)
dp[-1]=N
for _ in range(N):
bit=(1<<24)-1
for a in readline().rstrip():
a=ord(a)-97
if bit&1<<a:
bit^=1<<a
dp[bit]-=1
for i in range(24):
for bit in range((1<<24)-1,-1,-1):
if not bit&1<<i:
... | Codeforces Round 225 (Div. 1) | CF | 2,014 | 4 | 256 | Vowels | Iahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of n 3-words. A 3-word is a sequence of exactly 3 lowercase letters of the first 24 letters of the English alphabet (a to x). She decided that some of the letters are vowels, and... | The first line contains one integer, n (1 ≤ n ≤ 104). Each of the next n lines contains a 3-word consisting of 3 lowercase letters. There will be no two identical 3-words. | Print one number, the xor of the squared answers to the queries. | null | null | [{"input": "5\nabc\naaa\nada\nbcd\ndef", "output": "0"}] | 2,700 | ["combinatorics", "divide and conquer", "dp"] | 68 | [{"input": "5\r\nabc\r\naaa\r\nada\r\nbcd\r\ndef\r\n", "output": "0\r\n"}, {"input": "100\r\namd\r\namj\r\natr\r\nbcp\r\nbjm\r\ncna\r\ncpj\r\ncse\r\ndij\r\ndjp\r\ndlv\r\nebk\r\nedf\r\nelw\r\nfbr\r\nfcl\r\nfhs\r\nflo\r\nfmj\r\ngcg\r\ngen\r\nghg\r\ngvb\r\ngxx\r\nhbe\r\nhbf\r\nhgu\r\nhlv\r\nhqa\r\nibg\r\nifp\r\nima\r\nitt... | false | stdio | null | true |
305/C | 305 | C | Python 3 | TESTS | 6 | 186 | 9,216,000 | 51991582 | n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
if a[i]==a[i+1]:
a[i+1]+=1
a[i]=-1
cnt=0
s=0
for i in a:
if i>=0:
cnt+=1
s=max(s,i)
print(s-cnt+1) | 26 | 93 | 15,667,200 | 189846391 | n = int(input())
a = list(map(int, input().split()))
s = set()
for x in a:
if x not in s:
s.add(x)
else:
while x in s:
s.remove(x)
x += 1
s.add(x)
print(max(s)+1 - len(s)) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
305/C | 305 | C | Python 3 | TESTS | 6 | 155 | 12,083,200 | 35136076 | from sys import stdin, stdout
inputIdx = 0;
input = stdin.read().strip().split();
def nextToken():
global inputIdx, input;
token = input[inputIdx];
inputIdx += 1;
return token;
def main():
global inputIdx, input;
while inputIdx < len(input):
n = int( nextToken() );
fr = 0;
cur = 0;
ans = ... | 26 | 139 | 8,806,400 | 159227505 | n = int(input())
a = list(map(int,input().split()))
# print(a)
b = set()
for i in a:
j = i
while j in b:
b.remove(j)
j += 1
b.add(j)
print(max(b) - len(b) + 1) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
305/C | 305 | C | PyPy 3 | TESTS | 6 | 171 | 31,129,600 | 126763236 | n = int(input())
a = list(map(int, input().split()))
s = set()
for i in a:
j = i
if j in s:
s.remove(j)
j += 1
s.add(j)
print(max(s)-len(s)+1) | 26 | 139 | 8,806,400 | 198341196 | n=int(input())
a=list(map(int,input().split()))
b=set()
for i in a:
while i in b:
b.remove(i)
i+=1
b.add(i)
print(max(b)-len(b)+1) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
489/D | 489 | D | PyPy 3 | TESTS | 0 | 109 | 0 | 197799677 | from collections import defaultdict
n, m = map(int, input().split())
# Build graph
adj = defaultdict(list)
for i in range(m):
a, b = map(int, input().split())
adj[a].append(b)
ans = 0
for a in range(1, n+1):
# Count paths from a to all other intersections
cnt_ai = [0] * (n+1)
stack = [a]
cnt_... | 31 | 155 | 9,216,000 | 228336054 | import sys
input = sys.stdin.readline
def f(a):
return a*(a-1)//2
n, m = map(int, input().split())
d = [[] for _ in range(n+1)]
c = 0
for _ in range(m):
a, b = map(int, input().split())
d[a].append(b)
for i in range(1, n+1):
q = dict()
for j in d[i]:
for l in d[j]:
if l not i... | Codeforces Round 277.5 (Div. 2) | CF | 2,014 | 1 | 256 | Unbearable Controversy of Being | Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!
Tomash has noticed that even simple cases of... | The first line of the input contains a pair of integers n, m (1 ≤ n ≤ 3000, 0 ≤ m ≤ 30000) — the number of intersections and roads, respectively. Next m lines list the roads, one per line. Each of the roads is given by a pair of integers ai, bi (1 ≤ ai, bi ≤ n;ai ≠ bi) — the number of the intersection it goes out from ... | Print the required number of "damn rhombi". | null | null | [{"input": "5 4\n1 2\n2 3\n1 4\n4 3", "output": "1"}, {"input": "4 12\n1 2\n1 3\n1 4\n2 1\n2 3\n2 4\n3 1\n3 2\n3 4\n4 1\n4 2\n4 3", "output": "12"}] | 1,700 | ["brute force", "combinatorics", "dfs and similar", "graphs"] | 31 | [{"input": "5 4\r\n1 2\r\n2 3\r\n1 4\r\n4 3\r\n", "output": "1\r\n"}, {"input": "4 12\r\n1 2\r\n1 3\r\n1 4\r\n2 1\r\n2 3\r\n2 4\r\n3 1\r\n3 2\r\n3 4\r\n4 1\r\n4 2\r\n4 3\r\n", "output": "12\r\n"}, {"input": "1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n6 10\r\n4 2\r\n1 5\r\n6 1\r\n8 9\r\n1 3\r\n2 6\r\n9 7\r\n4 5\r... | false | stdio | null | true |
305/C | 305 | C | PyPy 3-64 | TESTS | 2 | 93 | 18,432,000 | 184025846 | import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
d = Counter()
for i in map(int, input().split()):
d[i] += 1
while d[i] == 2:
d[i] = 0
i += 1
d[i] += 1
x = max(d)
print(x+1 - len(d)) | 26 | 155 | 9,216,000 | 117708672 | n = int(input())
l = [int(i) for i in input().split()]
dict = {}
keylist = []
for elem in l:
if elem in dict:
dict[elem] += 1
else:
dict[elem] = 1
keylist.append(elem)
for elem in keylist:
if dict[elem] > 1:
nint = dict[elem]//2
dict[elem] = dict[elem]%2
cur =... | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
305/C | 305 | C | PyPy 3-64 | TESTS | 6 | 109 | 18,636,800 | 189784261 | from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for x in a:
d[x] += 1
while d[x] > 1:
d[x+1] += 1
d[x] -= 2
mx = max(a)
for x in range(mx, mx+30):
if d[x] == 0:
mx = x
break
while d[x] > 1:
d[x+1] +=... | 26 | 156 | 9,728,000 | 108773970 | n=int(input())
s=set()
for x in map(int, input().split()):
while x in s:
s.remove(x)
x+=1
s.add(x)
print(max(s)-len(s)+1) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
305/C | 305 | C | Python 3 | TESTS | 2 | 78 | 6,860,800 | 159226558 | n = int(input())
a = list(map(int,input().split()))
# print(a)
b = set()
for i in a:
while i in b:
b.remove(i)
b.add(i+1)
b.add(i)
print(max(b) - len(b) + 1) | 26 | 171 | 9,420,800 | 29596384 | n=int(input())
st=set()
for e in map(int,input().split()):
while(e in st):
st.remove(e)
e+=1
st.add(e)
print(max(st)-len(st)+1) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
305/C | 305 | C | Python 3 | TESTS | 6 | 140 | 9,113,600 | 74220765 | #v = quantidade de numeros no vetor
#ai elevado a 2
#formula: 2^v - 1 = x
#soma dos numeros elevados ao que tem no vetor
def calculateFormula(sommatory):
return pow(2,sommatory) - 1
n = int(input())
numbers = list(dict.fromkeys(list(map(int,input().split()))).keys())
##v = len(numbers)
##for i in numbers:
## ... | 26 | 171 | 14,028,800 | 23731589 | from sys import stdin
N = int(stdin.readline())
num = set()
for b in map(int, stdin.readline().split()):
while b in num:
num.remove(b)
b += 1
num.add(b)
print(max(num) - len(num) + 1) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
489/A | 489 | A | Python 3 | TESTS | 0 | 15 | 307,200 | 231270038 | import heapq
from collections import defaultdict
def main():
num_swaps = int(input())
nums = list(map(int, input().split()))
'''
Keep map of num to index
1. heapify the array
2. pointer at the back
3. pop and check the element is the same
4. if not, swap current element at position ... | 22 | 217 | 28,160,000 | 21320533 | read = lambda: map(int, input().split())
n = int(input())
a = list(read())
ans = []
for i in range(n - 1):
Min = float('inf')
ind = -1
for j in range(i, n):
if a[j] < Min:
Min = a[j]
ind = j
if i != ind:
a[i], a[ind] = a[ind], a[i]
ans.append(... | Codeforces Round 277.5 (Div. 2) | CF | 2,014 | 1 | 256 | SwapSort | In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of sw... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr... | In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per... | null | null | [{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}] | 1,200 | ["greedy", "implementation", "sortings"] | 22 | [{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
sub_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().split()))
with open(sub_path) as f:
lines = f.readlines()
if not lines:
... | true |
305/C | 305 | C | PyPy 3 | TESTS | 7 | 311 | 32,051,200 | 86490162 | from heapq import heapify, heappush, heappop
n = int(input())
a = list(map(int, input().split()))
q = []; cnt = 1; d = {}
for i in range(1, n):
if a[i] == a[i-1]:
cnt += 1
else:
q.append(a[i-1])
cnt = 1
d[a[i-1]] = cnt
q.append(a[-1])
d[a[-1]] = cnt
heapify(q); maxpow = 0
wh... | 26 | 171 | 15,360,000 | 35139828 | from sys import stdin
def read(): return map(int, stdin.readline().split())
read()
s = set()
for x in read():
while x in s:
s.remove(x)
x += 1
s.add(x)
print ( max(s) - len(s) + 1 ) | Codeforces Round 184 (Div. 2) | CF | 2,013 | 0.5 | 256 | Ivan and Powers of Two | Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of... | The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. | Print a single integer — the answer to the problem. | null | In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22. | [{"input": "4\n0 1 1 1", "output": "0"}, {"input": "1\n3", "output": "3"}] | 1,600 | ["greedy", "implementation"] | 26 | [{"input": "4\r\n0 1 1 1\r\n", "output": "0\r\n"}, {"input": "1\r\n3\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n2000000000\r\n", "output": "2000000000\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "26\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\r\n", ... | false | stdio | null | true |
484/A | 484 | A | Python 3 | TESTS | 3 | 265 | 0 | 10751753 | n = int(input())
for i in range(n):
l, r = [int(i) for i in input().split()]
if l == 0 and r == 0:
print(0)
continue
r = bin(r)[2:]
ans = r
for i in range(len(r)):
if r[i] == '1':
tmp = r[:i]+'0'+'1'*(len(r)-i-1)
if int(tmp,2) >= l and tmp.count('1') >... | 27 | 93 | 6,144,000 | 170920858 | import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
l, r = list(map(int, input().split()))
# lb = bin(l)[2:].zfill(60)
# rb = bin(r)[2:].zfill(60)
# 贪心:从l开最低位开始始碰到0就变成1,这样可以尽可能放最多地1
cur = l
for index in range(61):
if cur & (1 << index) == (1 << index):
... | Codeforces Round 276 (Div. 1) | CF | 2,014 | 1 | 256 | Bits | Let's denote as $$\operatorname{popcount}(x)$$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and $$\operatorname{popcount}(x)$$ is maximum possible. I... | The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018). | For each query print the answer in a separate line. | null | The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102 | [{"input": "3\n1 2\n2 4\n1 10", "output": "1\n3\n7"}] | 1,700 | ["bitmasks", "constructive algorithms"] | 27 | [{"input": "3\r\n1 2\r\n2 4\r\n1 10\r\n", "output": "1\r\n3\r\n7\r\n"}, {"input": "55\r\n1 1\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n1 8\r\n1 9\r\n1 10\r\n2 2\r\n2 3\r\n2 4\r\n2 5\r\n2 6\r\n2 7\r\n2 8\r\n2 9\r\n2 10\r\n3 3\r\n3 4\r\n3 5\r\n3 6\r\n3 7\r\n3 8\r\n3 9\r\n3 10\r\n4 4\r\n4 5\r\n4 6\r\n4 7\r\n4 8\r\n4 9\... | false | stdio | null | true |
494/B | 494 | B | Python 3 | PRETESTS | 0 | 46 | 0 | 9110256 | s = input()
t = input()
near = 0
tot = 1
totsum = 1
for i in range(len(s)-len(t),-1,-1):
if s[i:i+len(t)] == t:
near = totsum
tot += near
totsum += tot
print(tot-1) | 51 | 264 | 4,198,400 | 231039994 | s, t = input(), input()
n, m = len(t), len(s) + 1
d = 1000000007
g = [1] * m
f = k = 0
for i in range(1, m) :
if s[i - n:i] == t : k = i
if k : f = (f + g[k - n]) % d
g[i] += (g[i - 1] + f) % d
print(f) | Codeforces Round 282 (Div. 1) | CF | 2,014 | 2 | 256 | Obsessive String | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters. | Print the answer in a single line. | null | null | [{"input": "ababa\naba", "output": "5"}, {"input": "welcometoroundtwohundredandeightytwo\nd", "output": "274201"}, {"input": "ddd\nd", "output": "12"}] | 2,000 | ["dp", "strings"] | 51 | [{"input": "ababa\r\naba\r\n", "output": "5\r\n"}, {"input": "welcometoroundtwohundredandeightytwo\r\nd\r\n", "output": "274201\r\n"}, {"input": "ddd\r\nd\r\n", "output": "12\r\n"}, {"input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\r\nnssnssns\r\n", "output": "943392\r\n"}, {"input": "kpjmawawawawawawawawaw... | false | stdio | null | true |
19/A | 19 | A | Python 3 | TESTS | 3 | 92 | 0 | 202982061 | def main():
n = int(input())
teams = []
team_id = {}
for i in range(n):
team_name = input()
teams.append([team_name, 0, 0, 0])
team_id[team_name] = i
for i in range(n * (n - 1) // 2):
team, scores = input().split()
team1, team2 = team.split('-')
score1... | 29 | 92 | 0 | 5353782 | p, n = {}, int(input())
for i in range(n): p[input()] = [0, 0, 0]
for i in range((n * (n - 1)) // 2):
t = input().split()
a, b = t[0].split('-')
x, y = t[1].split(':')
x, y = int(x), int(y)
if x > y: p[a][0] += 3
elif x < y: p[b][0] += 3
else:
p[a][0] += 1
p[b][0] += 1
p[... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
31/D | 31 | D | PyPy 3 | TESTS | 3 | 186 | 0 | 112162597 | w,h,n=list(map(int,input().split()))
a=[[0 for i in range(2*w-1)] for j in range(2*h-1)]
for i in range(1,2*h-1,2):
for j in range(1,2*w-1,2):
a[i][j]=' '
for i in range(n):
x1,y1,x2,y2=list(map(int,input().split()))
if x1==x2:
if x1!=0 and x1!=w:
for j in range(max(1,min(y1,y2))... | 33 | 278 | 4,505,600 | 146016755 | from collections import deque
import sys
input = sys.stdin.readline
def bfs(x, y):
q = deque()
q.append((x, y))
visit[x][y] = 1
c = 0
while q:
i, j = q.popleft()
c += 1
for di, dj in G[i][j]:
ni, nj = i + di, j + dj
if 0 <= ni < w and 0 <= nj < h:
... | Codeforces Beta Round 31 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Chocolate | Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall... | The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ... | Output n + 1 numbers — areas of the resulting parts in the increasing order. | null | null | [{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}] | 2,000 | ["dfs and similar", "implementation"] | 33 | [{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ... | false | stdio | null | true |
31/D | 31 | D | Python 3 | TESTS | 3 | 62 | 0 | 188997254 | w,h,n=map(int,input().split())
c=[[0,0,w,h]]
s=[min((a,b),(c,d)) for a,b,c,d in [[*map(int,input().split())] for i in range(n)]]
for x,y in s:
for i,j in enumerate(c):
if x>j[0]and x<j[2]+j[0]and y==j[1]:
c.append([x,y,j[2]-x+j[0],j[3]])
c[i][2]=x-j[0]
break
if y>... | 33 | 374 | 2,252,800 | 73472707 | w, h, n = map(int, input().split(' '))
hblock = [[False for i in range(w)] for i in range(h)]
vblock = [[False for i in range(w)] for i in range(h)]
for i in range(n):
x1, y1, x2, y2 = map(int, input().split(' '))
if x1 == x2:
for j in range(y1, y2):
hblock[j][x1-1] = True
else:
... | Codeforces Beta Round 31 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Chocolate | Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall... | The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ... | Output n + 1 numbers — areas of the resulting parts in the increasing order. | null | null | [{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}] | 2,000 | ["dfs and similar", "implementation"] | 33 | [{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ... | false | stdio | null | true |
31/D | 31 | D | PyPy 3-64 | TESTS | 3 | 92 | 0 | 214286950 | import sys
readline = sys.stdin.readline
w, h, n = [int(w) for w in readline().split()]
rects = [[0, 0, w, h ]]
for _ in range(n):
x1, y1, x2, y2 = [int(w) for w in readline().split()]
if x2 < x1:
x1, x2 = x2, x1
if y2 < y1:
y1, y2 = y2, y1
for i, (xi1, yi1, xi2, yi2) in enumerate(re... | 33 | 374 | 3,481,600 | 95345054 | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
w, h, n = map(int, input().split())
mat = [[0] * (2 * w) for _ in range(2 * h)]
for x1, y1, x2, y2 in (map(int, input().split()) for _ in range(n)):
if x1 == x2:
for y in range(2 * y1, 2... | Codeforces Beta Round 31 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Chocolate | Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall... | The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ... | Output n + 1 numbers — areas of the resulting parts in the increasing order. | null | null | [{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}] | 2,000 | ["dfs and similar", "implementation"] | 33 | [{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ... | false | stdio | null | true |
729/D | 729 | D | Python 3 | PRETESTS | 2 | 61 | 307,200 | 22355751 | n, a, b, k = map(int, input().split())
pole = input()
pole3 = [[pole[0]]]
result = 0
for i in range(1, n):
if pole[i] == pole[i-1]:
pole3[-1].append(pole[i])
else:
pole3.append([pole[i]])
for i in range(len(pole3)):
if pole3[i][0] == '0':
if len(pole3[i]) >= b:
k = 1
... | 21 | 93 | 17,100,800 | 172144469 | def _n():
return int(input())
def _nA():
return list(map(int, input().split()))
def _sA():
return input().split()
n, a, b, k = _nA()
s = input()
i = 0
ret = []
while i < n:
if s[i] == '1':
i += 1
continue
j = i
while i < n and s[i] == '0':
i += 1
for k in range(... | Technocup 2017 - Elimination Round 2 | CF | 2,016 | 1 | 256 | Sea Battle | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro... | null | There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | [{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}] | 1,700 | ["constructive algorithms", "greedy", "math"] | 21 | [{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "... | false | stdio | null | true |
48/C | 48 | C | PyPy 3 | TESTS | 5 | 312 | 0 | 74679887 | from math import inf,ceil
n = int(input())
a = list(map(int,input().split()))
lower_bound = 0
upper_bound = inf
station = 1
total_stops = 1
for i in range(n):
stop = a[i]
if stop!=station:
while stop!=station:
station+=1
lower_bound = max(lower_bound,station*10/total_stops... | 45 | 248 | 307,200 | 69074867 | # ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
def main():
n = int(input())
a = list(map(int ,input().split()))
lb = 10
ub = 1e9
for i... | School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | The Race | Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.
So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li... | The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in ... | Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". | null | In the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4. | [{"input": "3\n1 2 4", "output": "unique\n5"}, {"input": "2\n1 2", "output": "not unique"}] | 1,800 | ["math"] | 45 | [{"input": "3\r\n1 2 4\r\n", "output": "unique\r\n5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "not unique\r\n"}, {"input": "1\r\n5\r\n", "output": "not unique\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "unique\r\n6\r\n"}, {"input": "5\r\n1 2 3 5 6\r\n", "output": "unique\r\n7\r\n"}, {"input": "6\r\n1 2 3 5 6 7\r\n",... | false | stdio | null | true |
48/C | 48 | C | PyPy 3 | TESTS | 2 | 310 | 0 | 74338732 | from collections import defaultdict
import math
n=int(input())
a=list(map(int,input().split()))
node=[a[0],1,0]# 10a+bx-10c
toadd=a[0]
xrange=[0,10]# a<=x<b
# print(node,xrange)
a=[0]+a
for i in range(1,n+1):
#after fuling at station i+1
if(node[0]>=a[i]-a[i-1]):
node[0]-=a[i]-a[i-1]
else:
n... | 45 | 280 | 0 | 63625034 | eps=10**(-9)
mn=10
mx=100000000
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
mn = max(mn,(arr[i]*10)/(i+1))
mx = min(mx,((arr[i]+1)*10)/(i+1))
ans1=((n+1)*mn)//10
ans2=((n+1)*(mx-eps))//10
if ans2>ans1:
print('not unique')
else:
print('unique')
print(int(ans1)) | School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | The Race | Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.
So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li... | The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in ... | Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". | null | In the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4. | [{"input": "3\n1 2 4", "output": "unique\n5"}, {"input": "2\n1 2", "output": "not unique"}] | 1,800 | ["math"] | 45 | [{"input": "3\r\n1 2 4\r\n", "output": "unique\r\n5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "not unique\r\n"}, {"input": "1\r\n5\r\n", "output": "not unique\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "unique\r\n6\r\n"}, {"input": "5\r\n1 2 3 5 6\r\n", "output": "unique\r\n7\r\n"}, {"input": "6\r\n1 2 3 5 6 7\r\n",... | false | stdio | null | true |
31/D | 31 | D | Python 3 | TESTS | 1 | 92 | 0 | 189595565 | from bisect import insort as it
w,h,n=map(int,input().split())
x=[[0,h]]+[[] for _ in range(99)]
y=[[0,w]]+[[] for _ in range(99)]
xy=[[0]*100 for _ in range(100)]
xy[0][0]=1
xs,ys={0},{0}
for a,b,c,d in [[*map(int,input().split())] for i in range(n)]:
m=min((a,b),(c,d))
xy[m[0]][m[1]]=1
xs.add(m[0])
ys... | 33 | 92 | 0 | 189949532 | from bisect import bisect as bt
w,h,n=map(int,input().split())
N,M=max(w,h),10
x=[[0,h]]+[[] for _ in range(N-1)]
y=[[0,w]]+[[] for _ in range(N-1)]
xy=[[0]*(N+1) for _ in range(N+1)]
g=[0]*M+[[]]
xy[0][0]=1
xs,ys={0},{0}
def t(k,p):
for i,j in zip(k,p):
q=bt(i,j)
if q==0 or i[q-1]!=j:
i... | Codeforces Beta Round 31 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Chocolate | Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall... | The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ... | Output n + 1 numbers — areas of the resulting parts in the increasing order. | null | null | [{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}] | 2,000 | ["dfs and similar", "implementation"] | 33 | [{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ... | false | stdio | null | true |
754/C | 754 | C | PyPy 3 | TESTS | 3 | 109 | 23,244,800 | 24466533 | from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
text = []
number = int(stdin.readline())
names = list(stdin.readline().strip().split())
label = 1
k = int(stdin.readline())
challengers = []
used = [[] for i in range(k)]
for i in range(k):
s =... | 104 | 327 | 6,246,400 | 23603581 | from math import *
from sys import *
from decimal import *
def gcd(a,b):
if b:
return gcd(b,a%b)
return a
t=int(stdin.readline())
for sssss in range(t):
n=int(stdin.readline())
names=stdin.readline().split()
dn=dict()
for i in range(len(names)):
dn[names[i]]=i
text=[]
ps... | Codeforces Round 390 (Div. 2) | CF | 2,017 | 2 | 256 | Vladik and chat | Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.
At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ... | The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format.
The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat.
The next line contains n space-separated distinct usernames. E... | Print the information about the t chats in the following format:
If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format:
<username>:<text>
If there are multiple answers, print any of them. | null | null | [{"input": "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "output": "netman: Hello, Vladik!\nVladik: Hi"}, {"input": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "output": "Impossible"}, {"input": "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: some... | 2,200 | ["brute force", "constructive algorithms", "dp", "implementation", "strings"] | 104 | [{"input": "1\r\n2\r\nVladik netman\r\n2\r\n?: Hello, Vladik!\r\n?: Hi\r\n", "output": "netman: Hello, Vladik!\r\nVladik: Hi\r\n"}, {"input": "1\r\n2\r\nnetman vladik\r\n3\r\nnetman:how are you?\r\n?:wrong message\r\nvladik:im fine\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n3\r\nnetman vladik Fedosik\r\n2\r\n?:... | false | stdio | null | true |
285/C | 285 | C | PyPy 3 | TESTS | 8 | 358 | 21,811,200 | 63876432 | n=int(input())
l=list(map(int,input().split()))
l.sort()
moves=0
for i in range(n):
if l[i]<0:
moves+=-(l[i])
l[i]=0
elif l[i]>n:
moves+=l[i]-n
l[i]=n
for i in range(n):
moves+=i+1-l[i]
print(moves) | 33 | 171 | 27,545,600 | 205544002 | def Building_Permutation():
n = int(input())
sequence = [int(x) for x in input().split(' ')]
sequence_sorted = sorted(sequence) #in ideal case this should be 1,2,3,4,5,....,n
#the minimum number of steps required would be when sequence_sorted[i] is made integer i, closest distance
actual_seq = [x fo... | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
285/C | 285 | C | Python 3 | TESTS | 8 | 436 | 20,992,000 | 16645858 | n = int(input())
a = list(map(int, input().split()))
r = 0
for i in range(n):
if a[i] > n:
r += a[i]-n
a[i] = n
print(n*(n+1)//2-sum(a)+r) | 33 | 186 | 32,358,400 | 163661338 | n=int(input())
lst=[int(x) for x in input().split()]
lst.sort()
pos,ans=1,0
for i in lst:
ans+=abs(pos-i)
pos+=1
print(ans) | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
754/C | 754 | C | PyPy 3 | TESTS | 11 | 218 | 27,238,400 | 24467144 | from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
text = []
number = int(stdin.readline())
names = list(stdin.readline().strip().split())
label = 1
k = int(stdin.readline())
challengers = []
used = [[] for i in range(k)]
for i in range(k):
s =... | 104 | 343 | 5,632,000 | 23598520 | #!/usr/bin/env python3
import re
def cont(line, user):
return re.search('[^a-zA-Z0-9]' + user + '[^a-zA-Z0-9]', '_' + line + '_')
tests = int(input())
for test in range(tests):
input()
users = input().rstrip('\n').split(' ')
linecnt = int(input())
lines = [input().rstrip('\n') for _ in range(linecnt)]
lines = ... | Codeforces Round 390 (Div. 2) | CF | 2,017 | 2 | 256 | Vladik and chat | Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.
At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ... | The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format.
The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat.
The next line contains n space-separated distinct usernames. E... | Print the information about the t chats in the following format:
If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format:
<username>:<text>
If there are multiple answers, print any of them. | null | null | [{"input": "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "output": "netman: Hello, Vladik!\nVladik: Hi"}, {"input": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "output": "Impossible"}, {"input": "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: some... | 2,200 | ["brute force", "constructive algorithms", "dp", "implementation", "strings"] | 104 | [{"input": "1\r\n2\r\nVladik netman\r\n2\r\n?: Hello, Vladik!\r\n?: Hi\r\n", "output": "netman: Hello, Vladik!\r\nVladik: Hi\r\n"}, {"input": "1\r\n2\r\nnetman vladik\r\n3\r\nnetman:how are you?\r\n?:wrong message\r\nvladik:im fine\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n3\r\nnetman vladik Fedosik\r\n2\r\n?:... | false | stdio | null | true |
32/D | 32 | D | Python 3 | TESTS | 5 | 218 | 716,800 | 44375097 | x,y,n = map(int,input().split())
count = 0
space = [[0 for i in range(y + 300)] for j in range(x + 300)]
for i in range(x):
dd = input()
for j in range(y):
space[i + 1][j + 1] = dd[j]
for i in range(2,x ):
for j in range(2,y ):
for k in range (1,max(x,y)):
if space[i][j] == '*... | 57 | 342 | 5,529,600 | 146023211 | import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
s = [list(input().rstrip()) for _ in range(n)]
c = 0
for k0 in range(1, min(n, m)):
for i in range(k0, n - k0):
l0 = min(i, n - i - 1)
si = s[i]
for j in range(k0, m - k0):
if si[j] == ".":
... | Codeforces Beta Round 32 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Constellation | A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is t... | The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th ch... | If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. | null | null | [{"input": "5 6 1\n....*.\n...***\n....*.\n..*...\n.***..", "output": "2 5\n1 5\n3 5\n2 4\n2 6"}, {"input": "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..", "output": "-1"}, {"input": "7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n.......\n...*...", "output": "4 4\n1 4\n7 4\n4 1\n4 7"}] | 1,600 | ["implementation"] | 57 | [{"input": "5 6 1\r\n....*.\r\n...***\r\n....*.\r\n..*...\r\n.***..\r\n", "output": "2 5\r\n1 5\r\n3 5\r\n2 4\r\n2 6\r\n"}, {"input": "5 6 2\r\n....*.\r\n...***\r\n....*.\r\n..*...\r\n.***..\r\n", "output": "-1\r\n"}, {"input": "7 7 2\r\n...*...\r\n.......\r\n...*...\r\n*.***.*\r\n...*...\r\n.......\r\n...*...\r\n", "o... | false | stdio | null | true |
32/D | 32 | D | PyPy 3 | TESTS | 5 | 280 | 0 | 77909924 | import sys
n,m,k=map(int,input().split(' '))
star=[]
for i in range(n):
star.append(list(input()))
c=0
for i in range(n):
for j in range(m):
for z in range(min(i,j,(m-1-j),(n-1-i))):
if(star[i][j]=='*' and star[i-(z+1)][j]=='*' and star[i+(z+1)][j]=='*' and star[i][j-(z+1)]=='*' and star[i][... | 57 | 1,058 | 8,396,800 | 138784470 | n, m, k = map(int, input().split())
f = [str(input()) for i in range(n)]
res = []
for r in range(1, min(n, m)):
for i in range(r, n - r):
for j in range(r, m - r):
if f[i][j] == "*":
if f[i - r][j] == "*":
if f[i + r][j] == "*":
if f[... | Codeforces Beta Round 32 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Constellation | A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is t... | The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th ch... | If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. | null | null | [{"input": "5 6 1\n....*.\n...***\n....*.\n..*...\n.***..", "output": "2 5\n1 5\n3 5\n2 4\n2 6"}, {"input": "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..", "output": "-1"}, {"input": "7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n.......\n...*...", "output": "4 4\n1 4\n7 4\n4 1\n4 7"}] | 1,600 | ["implementation"] | 57 | [{"input": "5 6 1\r\n....*.\r\n...***\r\n....*.\r\n..*...\r\n.***..\r\n", "output": "2 5\r\n1 5\r\n3 5\r\n2 4\r\n2 6\r\n"}, {"input": "5 6 2\r\n....*.\r\n...***\r\n....*.\r\n..*...\r\n.***..\r\n", "output": "-1\r\n"}, {"input": "7 7 2\r\n...*...\r\n.......\r\n...*...\r\n*.***.*\r\n...*...\r\n.......\r\n...*...\r\n", "o... | false | stdio | null | true |
320/B | 320 | B | PyPy 3-64 | TESTS | 4 | 404 | 3,276,800 | 223674516 | import io
import os
def fast_input():
input_length = os.fstat(0).st_size
byte_encoded_io = io.BytesIO(os.read(0, input_length))
def decoder_wrapper():
if (byte_encoded_io.tell() >= input_length):
raise EOFError
return byte_encoded_io.readline().decode()
return decoder_wrap... | 24 | 92 | 0 | 147542323 | v = []
a = []
mark = []
def DFS(x):
global mark, v
mark[x] = True
for i in v[x]:
if mark[i]:
continue
DFS(i)
n = int(input())
for i in range(n):
s = input()
s = s.split()
x = int(s[0])
y = int(s[1])
z = int(s[2])
li = list([])
if x == 1:
num =... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
285/C | 285 | C | Python 3 | TESTS | 8 | 592 | 20,992,000 | 67327020 | res=0
x=int(input())
s=list(map(int,input().split()))
for n in range(x):
if s[n]<=0:
res+=1-s[n]
s[n]=1
elif s[n]>x:
res+=s[n]-x
s[n]=x
z=sorted(s)
s.sort()
for n in range(x-1):
if s[n]>=s[n+1]:
s[n+1]=s[n]+1
res+=abs(s[n]-z[n])
res+=abs(s[-1]-z[-1])
print(res) | 33 | 186 | 32,358,400 | 172331940 | # a,b,k = map(int,input().split())
# for t in range(int(input())):
n = int(input())
# dp = [0](n+1)
l = [int(z) for z in input().split()]
l.sort()
ans = 0
for i in range(n):
ans+= abs((i+1)-l[i])
print(ans) | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
285/C | 285 | C | Python 3 | TESTS | 8 | 1,122 | 20,684,800 | 32157786 | n=int(input())
r=map(int,input().split())
f=list(r)
#print(f)
f.sort()
q=f[::-1]
#print(q)
l=len(q)
i=0
count=0
while i<l:
y=f[i]
if y>n:
g=y-n
count=count+g
if y<n:
h=n-y
count=count+h
i+=1
#print(count)
j=0
k=0
while j<n:
k=k+j
j+=1
#print(k)
print(count-k) | 33 | 186 | 32,358,400 | 179333459 | n = int(input())
arr = [int(k) for k in input().split()]
arr.sort()
tot = 0
for i, v in enumerate(arr):
tot += abs(v - (i + 1))
print(tot) | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
285/C | 285 | C | Python 3 | TESTS | 8 | 1,310 | 25,190,400 | 24462631 | n = int(input())
l = list(map(int, input().split()))
l.sort()
start = 1
end = n
res = 0
for i in range(n):
if l[i] <= i + 1:
res += i + 1 - l[i]
l[i] = i + 1
else:
break
for i in range(n - 1, -1 , -1):
if l[i] >= i + 1:
res += l[i] - (i + 1)
l[i] = i + 1
else:
... | 33 | 186 | 32,358,400 | 224249570 | n = int(input())
l = [int(x) for x in input().split()]
l.sort()
c = 0
for i in range(n):
c+=abs(i+1-l[i])
print(c) | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
610/D | 610 | D | PyPy 3 | TESTS | 6 | 124 | 1,740,800 | 202096627 | from collections import defaultdict
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def fenwick_tree(n):
tree = [0] * (n + 1)
return tree
def get_sum0(i):
s = 0
while i > 0:
s += tree[i]
i -= i & -i
return s
def get_sum(s, t):
ans = 0 if s > t e... | 47 | 1,278 | 54,681,600 | 216911246 | # i'm from jasnah, do not ban me
from sys import stdin
from itertools import repeat
from collections import defaultdict
num_rectangles = int(stdin.readline())
horizontal_segments = defaultdict(list)
vertical_segments = defaultdict(list)
unique_y_values = set()
events = defaultdict(list)
for _ in repeat(None, num_rect... | Codeforces Round 337 (Div. 2) | CF | 2,015 | 2 | 256 | Vika and Segments | Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbo... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of segments drawn by Vika.
Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments ar... | Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer. | null | In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3). | [{"input": "3\n0 1 2 1\n1 4 1 2\n0 3 2 3", "output": "8"}, {"input": "4\n-2 -1 2 -1\n2 1 -2 1\n-1 -2 -1 2\n1 2 1 -2", "output": "16"}] | 2,300 | ["constructive algorithms", "data structures", "geometry", "two pointers"] | 47 | [{"input": "3\r\n0 1 2 1\r\n1 4 1 2\r\n0 3 2 3\r\n", "output": "8\r\n"}, {"input": "4\r\n-2 -1 2 -1\r\n2 1 -2 1\r\n-1 -2 -1 2\r\n1 2 1 -2\r\n", "output": "16\r\n"}, {"input": "1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "10\r\n-357884841 -999999905 -357884841 999999943\r\n-130177221 999999983 -130177221 -999999974... | false | stdio | null | true |
32/D | 32 | D | PyPy 3-64 | TESTS | 5 | 154 | 512,000 | 145340296 | n, m, k = map(int, input().split())
starmap = []
for i in range(n):
row = []
temp = input()
for j in range(m):
if temp[j] == '.':
row.append(0)
else:
row.append(1)
starmap.append(row)
num_crosses = 0
flag = 0
for i in range(n):
for j in range(m):
for ... | 57 | 1,994 | 5,222,400 | 95437141 | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
a = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)]
cnt = [0] * 400
for i in range(1, n - 1):
for j in range(1, m - 1):
if not a[... | Codeforces Beta Round 32 (Div. 2, Codeforces format) | CF | 2,010 | 2 | 256 | Constellation | A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is t... | The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th ch... | If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. | null | null | [{"input": "5 6 1\n....*.\n...***\n....*.\n..*...\n.***..", "output": "2 5\n1 5\n3 5\n2 4\n2 6"}, {"input": "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..", "output": "-1"}, {"input": "7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n.......\n...*...", "output": "4 4\n1 4\n7 4\n4 1\n4 7"}] | 1,600 | ["implementation"] | 57 | [{"input": "5 6 1\r\n....*.\r\n...***\r\n....*.\r\n..*...\r\n.***..\r\n", "output": "2 5\r\n1 5\r\n3 5\r\n2 4\r\n2 6\r\n"}, {"input": "5 6 2\r\n....*.\r\n...***\r\n....*.\r\n..*...\r\n.***..\r\n", "output": "-1\r\n"}, {"input": "7 7 2\r\n...*...\r\n.......\r\n...*...\r\n*.***.*\r\n...*...\r\n.......\r\n...*...\r\n", "o... | false | stdio | null | true |
285/C | 285 | C | PyPy 3 | TESTS | 6 | 608 | 29,081,600 | 120248416 | n = int(input())
nums = [(int(x),abs(n-int(x))) for x in input().split()]
nums.sort(key = lambda x: (-x[1]))
moves = 0
for i in range(1,n+1):
val = nums[i-1][0]
moves = moves + abs(val - i)
print(moves) | 33 | 187 | 34,406,400 | 181322660 | def solve():
n = int(input())
a = sorted([int(i) for i in input().split()])
ans = 0
for i in range(n):
ans += abs(a[i] - i - 1)
return ans
print(solve()) | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
19/A | 19 | A | Python 3 | TESTS | 4 | 92 | 0 | 201263699 | class Solution:
def __init__(self):
self.no_of_teams=int(input())
self.order=[]
self.mp={}
for i in range(self.no_of_teams):
self.order.append(input())
for i in range((self.no_of_teams * (self.no_of_teams-1))//2):
buffer_input = input()
te... | 29 | 92 | 0 | 141674992 | class Info:
def __init__(self, _teamName, _points, _goalDiff, _scoredGaols):
self.teamName = _teamName
self.points = _points
self.goalDiff = _goalDiff
self.scoredGoals = _scoredGaols
def __str__(self):
return f'\n*************************\n' \
f'teamName =... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
19/A | 19 | A | Python 3 | TESTS | 4 | 186 | 307,200 | 64257842 | #RAVENS
#TEAM_2
#ESSI-DAYI_MOHSEN-LORENZO
#from tokhmi import Tokhmi_Tarin_Halat_Momken
team = []
score = []
goals = [] # gola zade khorde
n = int(input())
for i in range(n):
team.append(input())
score.append(0)
goals.append([0, 0])
for i in range(n * (n - 1) // 2):
a, b = input().split()
t1, t2... | 29 | 92 | 0 | 147237334 | class Info:
def __init__(self, newTeamName, newPoints, newGoalDiff, newScoredGoals):
self.teamName = newTeamName
self.points = newPoints
self.goalDiff = newGoalDiff
self.scoredGoals = newScoredGoals
def __str__(self):
return f'[teamName: {self.teamName}, Points: {self.po... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
505/B | 505 | B | Python 3 | TESTS | 5 | 108 | 307,200 | 96940798 | def dfs(vertice, cor, adjacencias, visitados):
if visitados[vertice] != 1:
visitados[vertice] = 1
for aresta in adjacencias[str(vertice)]:
if aresta[1] == cor:
dfs(int(aresta[0]), cor, adjacencias, visitados)
entrada = input().split()
n = int(entrada[0])... | 29 | 46 | 0 | 147549004 | dic = {}
mark = []
v = []
def DFS(x):
global mark, v
mark[x] = True
for i in v[x]:
if mark[i]:
continue
DFS(i)
s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
for i in range(m):
s = input()
s = s.split()
x = int(s[0])
y = int(s[1])
z = int(s[2])
x... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
505/B | 505 | B | PyPy 3 | TESTS | 5 | 124 | 2,662,400 | 108055526 | import sys
import math
from collections import defaultdict
import itertools
MAXNUM = math.inf
MINNUM = -1 * math.inf
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
... | 29 | 46 | 0 | 152832300 | N,M = map(int,input().split())
dat = [[] for _ in range(N)]
color = [set() for _ in range(N)]
for _ in range(M):
a,b,c = map(int,input().split())
dat[a-1].append([b-1,c])
dat[b-1].append([a-1,c])
color[a-1].add(c)
color[b-1].add(c)
def dfs(i,pre):
global ans
if i==v-1:
ans += 1
visited[i] = 1
for x,y in dat... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
505/B | 505 | B | PyPy 3 | TESTS | 5 | 124 | 3,686,400 | 148240346 | n,m = map(int, input().split())
store = [[] for i in range(n+1)]
for q in range(m):
a,b,c = map(int, input().split())
store[a].append([b,c])
store[b].append([a,c])
vis = [0 for i in range(n+1)]
count = 0
def dfs(vertex, dest ,color):
global count
if vis[vertex]:
return
vis[vertex] = 1
... | 29 | 46 | 0 | 184157821 | def frente(a, c):
if f[c][a] != a:
f[c][a] = frente(f[c][a], c)
return f[c][a]
def antes(a, b, c):
ra, rb = frente(a, c), frente(b, c)
if ra == rb:
return
f[c][ra] = rb
n, m = map(int,input().split())
f = [list(range(n + 1)) for _ in range(m + 2)]
for a, b, c in [map(int,input().split()) for _ in... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
505/D | 505 | D | Python 3 | PRETESTS | 2 | 61 | 0 | 9464509 | n, m = map(int, input().split())
l=[]
for i in range(m):
l.append(list(map(int, input().split())))
l.sort()
o=0
for i in range(len(l)-1):
o+=1
if(l.count([l[i], l[i+1]])):
o-=1
print(o-1) | 50 | 624 | 12,390,400 | 20522061 | def main():
n, m = map(int, input().split())
n += 1
cluster, dest, ab = list(range(n)), [0] * n, [[] for _ in range(n)]
def root(x):
if x != cluster[x]:
cluster[x] = x = root(cluster[x])
return x
for _ in range(m):
a, b = map(int, input().split())
ab[a].... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Technology | Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n.
Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha... | The first line contains two space-separated integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105), denoting the number of the cities in Shuseki Kingdom and the number of the important pairs, respectively.
The following m lines describe the important pairs. The i-th of them (1 ≤ i ≤ m) contains two space-separated integers ai an... | Print the minimum required number of teleportation pipes to fulfill Mr. Kitayuta's purpose. | null | For the first sample, one of the optimal ways to construct pipes is shown in the image below:
For the second sample, one of the optimal ways is shown below: | [{"input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "output": "3"}, {"input": "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4", "output": "4"}] | 2,200 | ["dfs and similar"] | 50 | [{"input": "4 5\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n", "output": "3\r\n"}, {"input": "4 6\r\n1 2\r\n1 4\r\n2 3\r\n2 4\r\n3 2\r\n3 4\r\n", "output": "4\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "3\r\n"}, {"input": "3 6\r\n1 2\r\n1 3\r\n2 1\r\n2 3\r\n3 1\r\n3 2\r\n", "output": "3\r... | false | stdio | null | true |
505/B | 505 | B | PyPy 3 | TESTS | 5 | 139 | 1,126,400 | 50161725 | # !/usr/bin/env python3
# coding: UTF-8
# Modified: <19/Feb/2019 06:22:16 PM>
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT),Gwalior
# Question Link
#
#
# ///==========Libraries, Constants and Functions=============///
import sys
inf = float("inf")
mod = 1000000007
def ge... | 29 | 61 | 0 | 142184973 | n, m = list(map(int,input().split()))
grath = {}
for i in range(n):
grath[i + 1] = []
for i in range(m):
a,b,c = list(map(int,input().split()))
grath[a].append([b, c])
grath[b].append([a, c])
q = int(input())
def dfs(v,used,color):
used[v] = True
for u in grath[v]:
if u[1] == color and ... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
1006/C | 1006 | C | Python 3 | TESTS | 20 | 342 | 21,401,600 | 96751934 | import sys
from collections import Counter as cs
#input=sys.stdin.readline
n=int(input())
ls=[int(a) for a in input().split()]
ls1=[ls[0]]
ls2=[ls[-1]]
sm=sum(ls)
p1,p2=1,1
for i in range(n-1):
ls1.append(ls1[-1]+ls[i+1])
if ls1[-1]>sm/2:
ls1.pop()
break
for i in range(n-1,len(ls1),-1):
ls2.... | 27 | 109 | 23,654,400 | 216909712 | n = int(input())
lista = list(map(int, input().split(" ")))
pont_1 = 0
pont_2 = len(lista) - 1
valor_1 = lista[pont_1]
valor_2 = lista[pont_2]
value = 0
while (pont_1 < pont_2):
if (valor_1 < valor_2):
pont_1 += 1
valor_1 += lista[pont_1]
elif (valor_1 > valor_2):
pont_2 -= 1
va... | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Three Parts of the Array | You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$.
The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$. | Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met.
Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$). | null | In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.
In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.
In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$. | [{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}] | 1,200 | ["binary search", "data structures", "two pointers"] | 27 | [{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}] | false | stdio | null | true |
1006/C | 1006 | C | PyPy 3 | TESTS | 20 | 280 | 19,148,800 | 143749589 | n=int(input())
a=list(map(int,input().split()))
low=0
high=n-1
lowsum=a[low]
highsum=a[high]
res=0
while high-low>1:
if lowsum==highsum:
res=max(res,lowsum)
low+=1
lowsum+=a[low]
elif lowsum<highsum:
low+=1
lowsum+=a[low]
else:
high-=1
highsum+=a[high]... | 27 | 109 | 23,654,400 | 216909739 | n = int(input())
lista = list(map(int, input().split(" ")))
pont_1 = 0
pont_2 = len(lista) - 1
valor_1 = lista[pont_1]
valor_2 = lista[pont_2]
value = 0
while (pont_1 < pont_2):
if (valor_1 < valor_2):
pont_1 += 1
valor_1 += lista[pont_1]
elif (valor_1 > valor_2):
pont_2 -= 1
va... | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Three Parts of the Array | You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$.
The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$. | Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met.
Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$). | null | In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.
In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.
In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$. | [{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}] | 1,200 | ["binary search", "data structures", "two pointers"] | 27 | [{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}] | false | stdio | null | true |
1006/C | 1006 | C | Python 3 | TESTS | 20 | 265 | 18,432,000 | 90410495 | n=int(input())
a=list(map(int,input().split()))
p1=0
p2=n-1
ap1=0
ap2=0
ap1+=a[p1]
ap2+=a[p2]
l=[]
while True:
if p1>=p2:
break
if ap1>ap2:
p2-=1
if p1>=p2:
break
ap2+=a[p2]
elif ap2>ap1:
p1+=1
if p1>=p2:
break
ap1+... | 27 | 109 | 27,136,000 | 163954629 | from msvcrt import LK_LOCK
n = int(input())
lst =list(map(int, input().split()))
s1 = s2 = 0
r = n
ans = 0
for l in range(len(lst)):
s1 += lst[l]
while s2 < s1:
r -= 1
s2 += lst[r]
if s1 == s2 and r > l:
ans = max(ans, s1)
print(ans) | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Three Parts of the Array | You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$.
The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$. | Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met.
Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$). | null | In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.
In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.
In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$. | [{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}] | 1,200 | ["binary search", "data structures", "two pointers"] | 27 | [{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}] | false | stdio | null | true |
504/D | 504 | D | Python 3 | TESTS | 0 | 31 | 0 | 153502837 | n = int(input())
arr = []
basis = []
for i in range(n):
x = int(input())
arr.append(x)
ans = []
for e in basis:
if (arr[e]^x) < x:
ans.append(e)
x ^= arr[e]
if x == 0:
print(len(ans))
print(*ans)
else:
print(0)
arr[i] = x;
... | 52 | 1,044 | 11,366,400 | 223656011 | m = int(input())
arr = []
bits = []
for i in range(m):
x = int(input())
bit = 0
for j in range(len(arr)):
p = arr[j] ^ x
if p < x:
x = p
bit ^= bits[j]
if x == 0:
ans = ""
r = 0
for j in range(i):
if bit & (1 << j) == 1 << j:
... | Codeforces Round 285 (Div. 1) | CF | 2,015 | 2 | 256 | Misha and XOR | After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest... | The first line contains number m (1 ≤ m ≤ 2000), showing how many numbers are scattered around the room.
The next m lines contain the numbers in the order in which the robot puts them in the basket. Each number is a positive integer strictly less than 10600 that doesn't contain leading zeroes. | For each number either print a 0 on the corresponding line, if the number cannot be represented as a XOR sum of numbers that are in the basket, or print integer k showing how many numbers are in the representation and the indexes of these numbers. Separate the numbers by spaces. Each number can occur in the representat... | null | The XOR sum of numbers is the result of bitwise sum of numbers modulo 2. | [{"input": "7\n7\n6\n5\n4\n3\n2\n1", "output": "0\n0\n0\n3 0 1 2\n2 1 2\n2 0 2\n2 0 1"}, {"input": "2\n5\n5", "output": "0\n1 0"}] | 2,700 | ["bitmasks"] | 52 | [{"input": "7\r\n7\r\n6\r\n5\r\n4\r\n3\r\n2\r\n1\r\n", "output": "0\r\n0\r\n0\r\n3 0 1 2\r\n2 1 2\r\n2 0 2\r\n2 0 1\r\n"}, {"input": "2\r\n5\r\n5\r\n", "output": "0\r\n1 0\r\n"}, {"input": "10\r\n81\r\n97\r\n12\r\n2\r\n16\r\n96\r\n80\r\n99\r\n6\r\n83\r\n", "output": "0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n3 0 1 5\r\n2 1 3\r\n0\... | false | stdio | null | true |
505/B | 505 | B | PyPy 3 | TESTS | 5 | 124 | 4,403,200 | 104060110 | 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... | 29 | 61 | 0 | 172115626 | def checkcolors(a, b, c, v) :
colorset = set()
if c == 0 :
for edge in edges[a] :
if edge[0] == b :
v[edge[0]].append(edge[1])
colorset.add(edge[1])
else :
if c not in v[edge[0]] :
v[edge[0]].append(edge[1])
... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
505/B | 505 | B | Python 3 | TESTS | 5 | 46 | 307,200 | 221461063 | from collections import defaultdict
def main():
graph = defaultdict(set)
n, m = map(int, input().split())
for _ in range(m):
a, b, c = map(int, input().split())
graph[a].add((b, c))
graph[b].add((a, c))
def dfs(node, prev_color, target, used):
if node == target:
... | 29 | 62 | 0 | 9461646 | n,m = map(int, input().split())
l = []
for i in range(m):
a,b,c = map(int, input().split())
if len(l) <= c-1:
for i in range(c-len(l)):
l.append([])
p = l[c-1]
m = []
for i in range(len(p)):
if a in p[i] or b in p[i]:
m.append(i)
new = [a,b]
for i in r... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
505/B | 505 | B | PyPy 3-64 | TESTS | 5 | 77 | 3,276,800 | 222044409 | def solve():
n,m = map(int,input().split())
adj = [[]for i in range(n)]
for i in range(m):
a,b,c = map(int,input().split())
adj[a-1].append((b-1,c-1))
adj[b-1].append((a-1,c-1))
def dfs(s,d,adj,visited,color):
if s==d:
return True
visited[s] = True
for i,j in adj[s]:
if not visited[i] and j==color... | 29 | 62 | 0 | 184160064 | n, m = map(int, input().split())
graph = [[] for _ in range(105)]
for _ in range(m):
a, b, c = map(int, input().split())
graph[a].append([b,c])
graph[b].append([a,c])
def dfs(source, destination, colour):
if source == destination:
return True
visited[source] = True
for node in grap... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
505/B | 505 | B | PyPy 3-64 | TESTS | 5 | 78 | 6,451,200 | 144891730 | n, m = map(int, input().split()) # vert, edge
edges = [tuple(map(int, input().split())) for _ in range(m)]
def search(a, b, c):
global count
if a == b:
count += 1
return
if c != -1:
visited[c].add(a)
for e in edges:
if e[2] == c or c == -1:
if e[0] == a an... | 29 | 62 | 102,400 | 9460278 | n,m = input().split(' ')
l = []
for x in range(int(m)):
l.append(list(range(int(n))))
for x in range(int(m)):
p = input().split(' ')
newl = l[int(p[2])-1]
a,i = max(newl[int(p[0])-1],newl[int(p[1])-1]),min(newl[int(p[0])-1],newl[int(p[1])-1])
for y in range(len(newl)):
if newl[y] == a:
... | Codeforces Round 286 (Div. 2) | CF | 2,015 | 1 | 256 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively.
The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple ... | For each query, print the answer in a separate line. | null | Let's consider the first sample.
The figure above shows the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2.
- Vertex 3 and vertex 4 are connected by color 3.
- Vertex 1 and vertex 4 are not connected by any single color. | [{"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0"}, {"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2"}] | 1,400 | ["dfs and similar", "dp", "dsu", "graphs"] | 29 | [{"input": "4 5\r\n1 2 1\r\n1 2 2\r\n2 3 1\r\n2 3 3\r\n2 4 3\r\n3\r\n1 2\r\n3 4\r\n1 4\r\n", "output": "2\r\n1\r\n0\r\n"}, {"input": "5 7\r\n1 5 1\r\n2 5 1\r\n3 5 1\r\n4 5 1\r\n1 2 2\r\n2 3 2\r\n3 4 2\r\n5\r\n1 5\r\n5 1\r\n2 5\r\n1 5\r\n1 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n2\r\n"}, {"input": "2 1\r\n1 2 1\r\n1\r\n1... | false | stdio | null | true |
1006/C | 1006 | C | PyPy 3-64 | TESTS | 11 | 124 | 26,521,600 | 213104137 | n = int(input())
l = list(int(num) for num in input().split())
i,j = 0,n-1
actual,rightsum,leftsum=0,0,0
while True:
if i>=j:
if leftsum==rightsum:
actual=leftsum
break
if leftsum==rightsum :
actual=leftsum
leftsum+=l[i]
rightsum+=l[j]
i+=1
j-=... | 27 | 109 | 27,545,600 | 183157150 | n = int(input())
d = list(map(int, input().split()))
i = 0
j = n-1
s = d[i]
f = d[j]
c = 0
while i<j:
if s<f:
i = i + 1
s = s + d[i]
elif s>f:
j = j - 1
f = f + d[j]
else:
i = i + 1
j = j - 1
c = c + s
s = d[i]
f = d[j]
print(c) | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Three Parts of the Array | You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$.
The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$. | Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met.
Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$). | null | In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.
In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.
In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$. | [{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}] | 1,200 | ["binary search", "data structures", "two pointers"] | 27 | [{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}] | false | stdio | null | true |
1006/C | 1006 | C | PyPy 3-64 | TESTS | 11 | 109 | 28,262,400 | 205240901 | import math,sys,collections,bisect,heapq
def natural(n):
return n*(n+1)//2
def possible(arr,h,k):
for i in range(len(arr)-1):
if h <= 0:
return True
h-=min(arr[i+1]-arr[i],k)
h-=k
if h <=0:
return True
return False
def binarysearch(l,r,arr,h):
if l<=r:
mid = (l+r)//2
if possible(arr,h,mid):
re... | 27 | 109 | 27,648,000 | 183810469 | n = int(input())
li = list(map(int, input().split()))
i = 0
j = n-1
s1 = li[0]
s2 = li[n-1]
res = 0
while i < j:
if s1 > s2:
j -= 1
s2 += li[j]
elif s1 < s2:
i += 1
s1 += li[i]
else:
res = s1
i += 1
s1 += li[i]
print(res) | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Three Parts of the Array | You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$.
The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$. | Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met.
Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$). | null | In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.
In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.
In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$. | [{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}] | 1,200 | ["binary search", "data structures", "two pointers"] | 27 | [{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}] | false | stdio | null | true |
1006/C | 1006 | C | Python 3 | TESTS | 12 | 233 | 17,715,200 | 155058386 | number = int(input())
numbers = list(map(int,input().split()))
e1 = 0
e2 = 1
sum1 = numbers[0]
sum3 = numbers[len(numbers) - 1]
b = -2
a = 1
count = 1
for c in range(1,len(numbers) - 1):
if sum1 < sum3:
sum1 += numbers[a]
a += 1
elif sum1 > sum3:
sum3 += numbers[b]
b -= 1
else:
sum1 += numbers[a]
a += ... | 27 | 109 | 27,648,000 | 186685382 | n=int(input())
A=list(map(int,input().split()))
ANS=0
l=0
r=n-1
S0=0
S1=0
while l<=r:
if S0<=S1:
S0+=A[l]
l+=1
else:
S1+=A[r]
r-=1
if S0==S1:
ANS=max(ANS,S0)
print(ANS) | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Three Parts of the Array | You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$.
The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$. | Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met.
Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$). | null | In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.
In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.
In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$. | [{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}] | 1,200 | ["binary search", "data structures", "two pointers"] | 27 | [{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}] | false | stdio | null | true |
617/C | 617 | C | Python 3 | TESTS | 4 | 30 | 102,400 | 224677091 | import math
def disq(a, b):
deltax = abs(a[0] - b[0])
deltay = abs(a[1] - b[1])
result = deltax * deltax + deltay * deltay
return result
def main():
a, b, c, d, e = input().split()
n = int(a)
f1 = tuple(map(int, [b, c]))
f2 = tuple(map(int, [d, e]))
flowers = []
for _ in rang... | 31 | 77 | 409,600 | 15535367 | def dist1(x_, y_):
return (x1 - x_) ** 2 + (y1 - y_) ** 2
def dist2(x_, y_):
return (x2 - x_) ** 2 + (y2 - y_) ** 2
n, x1, y1, x2, y2 = [int(i) for i in input().split()]
dist = [[0] * 2 for i in range(n)]
for i in range(n):
x, y = [int(i) for i in input().split()]
dist[i][0] = dist1(x, y)
dist[i... | Codeforces Round 340 (Div. 2) | CF | 2,016 | 2 | 256 | Watering Flowers | A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t... | The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flo... | Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer. | null | The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32): | [{"input": "2 -1 0 5 3\n0 2\n5 2", "output": "6"}, {"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "output": "33"}] | 1,600 | ["implementation"] | 31 | [{"input": "2 -1 0 5 3\r\n0 2\r\n5 2\r\n", "output": "6\r\n"}, {"input": "4 0 0 5 0\r\n9 4\r\n8 3\r\n-1 0\r\n1 4\r\n", "output": "33\r\n"}, {"input": "5 -6 -4 0 10\r\n-7 6\r\n-9 7\r\n-5 -1\r\n-2 1\r\n-8 10\r\n", "output": "100\r\n"}, {"input": "10 -68 10 87 22\r\n30 89\r\n82 -97\r\n-52 25\r\n76 -22\r\n-20 95\r\n21 25\r... | false | stdio | null | true |
62/D | 62 | D | Python 3 | TESTS | 4 | 62 | 0 | 139385636 | def build_home_path(n: int, m: int, old_path: list) -> list:
"""
Parameters:
:n (int): number of rooms
:m (int): number of corridors
:old_path (list): old build path
:return: new build path
"""
if old_path[0] != 1:
return None
for i in reversed(range(len(old_path) - 2)):
... | 30 | 124 | 819,200 | 187019306 | n,m = map(int,input().split())
m+=1
p = list(map(lambda x:int(x)-1,input().split()))
a = [0]*m
q = [[False]*n for i in range(n)]
d = [[] for i in range(n)]
for i in range(1,m):
d[p[i]].append(p[i-1])
d[p[i-1]].append(p[i])
for i in range(n):
d[i].sort()
s = [(p[0],True,p[0])]
l = 0
while s:
v,f,vv = s[-... | Codeforces Beta Round 58 | CF | 2,011 | 2 | 256 | Wormhouse | Arnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the rooms from 1 to n. All the corridors are bidirectional.
Arnie wants the new house to look just like the previous one.... | The first line contains two integers n and m (3 ≤ n ≤ 100, 3 ≤ m ≤ 2000). It is the number of rooms and corridors in Arnie's house correspondingly. The next line contains m + 1 positive integers that do not exceed n. They are the description of Arnie's old path represented as a list of rooms he visited during the gnawi... | Print m + 1 positive integers that do not exceed n. Those numbers are the description of the new path, according to which Arnie should gnaw out his new house. If it is impossible to find new path you should print out No solution. The first number in your answer should be equal to the last one. Also it should be equal t... | null | null | [{"input": "3 3\n1 2 3 1", "output": "1 3 2 1"}, {"input": "3 3\n1 3 2 1", "output": "No solution"}] | 2,300 | ["dfs and similar", "graphs"] | 30 | [{"input": "3 3\r\n1 2 3 1\r\n", "output": "1 3 2 1 "}, {"input": "3 3\r\n1 3 2 1\r\n", "output": "No solution"}, {"input": "4 4\r\n1 2 4 3 1\r\n", "output": "1 3 4 2 1 "}, {"input": "6 7\r\n3 2 4 1 6 5 1 3\r\n", "output": "No solution"}, {"input": "8 12\r\n4 6 5 1 4 3 1 8 3 7 8 5 4\r\n", "output": "4 6 5 1 4 3 1 8 7 3... | false | stdio | null | true |
508/C | 508 | C | PyPy 3-64 | TESTS | 0 | 46 | 0 | 214291416 | def num_candles(m, t, r, times):
N = 301
x = [0]*N
y = [0]*N
answer = 0
for i in range(m):
x[times[i]] = 1
for i in range(1, N):
if x[i] and y[i] < r:
for j in range(i-r+y[i]+1, i+1):
for k in range(max(j,0), min(j+t,N)):
y[k] += 1
... | 61 | 77 | 0 | 9587004 | m, t, r = map(int, input().split())
w = list(map(int, input().split()))
w.sort()
cur = set()
cur1 = set()
cnt = 0
for i in range(m):
for j in cur:
if j + t >= w[i]:
cur1.add(j)
cur = set()
for j in cur1:
cur.add(j)
cur1 = set()
j = w[i] - 1
while j >= w[i] - t and l... | Codeforces Round 288 (Div. 2) | CF | 2,015 | 2 | 256 | Anya and Ghosts | Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one can... | The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.
The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them r... | If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print - 1. | null | Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.
It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from se... | [{"input": "1 8 3\n10", "output": "3"}, {"input": "2 10 1\n5 8", "output": "1"}, {"input": "1 1 3\n10", "output": "-1"}] | 1,600 | ["constructive algorithms", "greedy"] | 61 | [{"input": "1 8 3\r\n10\r\n", "output": "3\r\n"}, {"input": "2 10 1\r\n5 8\r\n", "output": "1\r\n"}, {"input": "1 1 3\r\n10\r\n", "output": "-1\r\n"}, {"input": "21 79 1\r\n13 42 51 60 69 77 94 103 144 189 196 203 210 215 217 222 224 234 240 260 282\r\n", "output": "4\r\n"}, {"input": "125 92 2\r\n1 2 3 4 5 7 8 9 10 12... | false | stdio | null | true |
975/A | 975 | A | Python 3 | PRETESTS | 3 | 77 | 9,011,200 | 37816785 | n = int(input())
A = list(input().split())
cnt = 1
if n == 1:
print(cnt)
else:
B = [set(i) for i in A]
B = sorted(B)
for i in range(1, len(B)):
if B[i] != B[i - 1]:
cnt += 1
print(cnt) | 30 | 46 | 2,969,600 | 205469005 | from sys import stdin
from math import ceil
rd = stdin.readline
n = int(rd())
s = rd().split()
s1 = []
for i in s:
s2 = set(i)
if s2 not in s1:
s1.append(s2)
print(len(s1)) | Codeforces Round 478 (Div. 2) | CF | 2,018 | 1 | 256 | Aramic script | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once.
- A root and all its permutations represent the same object.
- The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in... | The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script.
The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$.
It is guaranteed that all characters of the strings are small latin ... | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | null | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | [{"input": "5\na aa aaa ab abb", "output": "2"}, {"input": "3\namer arem mrea", "output": "1"}] | 900 | ["implementation", "strings"] | 30 | [{"input": "5\r\na aa aaa ab abb\r\n", "output": "2"}, {"input": "3\r\namer arem mrea\r\n", "output": "1"}, {"input": "10\r\nbda bbb cda dca dda dcb bcd dcb ada ddd\r\n", "output": "6"}, {"input": "2\r\nfhjlqs aceginpr\r\n", "output": "2"}, {"input": "2\r\nbcdfghimn efghijlmo\r\n", "output": "2"}] | false | stdio | null | true |
975/A | 975 | A | Python 3 | TESTS | 3 | 61 | 1,740,800 | 184349026 | input()
lst = [tuple(set(s)) for s in input().split()]
print(len(set(lst))) | 30 | 46 | 3,174,400 | 219500325 | def get_root(word):
return ''.join(sorted(set(word)))
def count_unique_objects(n, words):
unique_roots = set()
for word in words:
root = get_root(word)
unique_roots.add(root)
return len(unique_roots)
n = int(input())
words = input().split()
unique_objects = count_unique_objects(n, words)... | Codeforces Round 478 (Div. 2) | CF | 2,018 | 1 | 256 | Aramic script | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once.
- A root and all its permutations represent the same object.
- The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in... | The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script.
The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$.
It is guaranteed that all characters of the strings are small latin ... | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | null | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | [{"input": "5\na aa aaa ab abb", "output": "2"}, {"input": "3\namer arem mrea", "output": "1"}] | 900 | ["implementation", "strings"] | 30 | [{"input": "5\r\na aa aaa ab abb\r\n", "output": "2"}, {"input": "3\r\namer arem mrea\r\n", "output": "1"}, {"input": "10\r\nbda bbb cda dca dda dcb bcd dcb ada ddd\r\n", "output": "6"}, {"input": "2\r\nfhjlqs aceginpr\r\n", "output": "2"}, {"input": "2\r\nbcdfghimn efghijlmo\r\n", "output": "2"}] | false | stdio | null | true |
285/C | 285 | C | Python 3 | TESTS | 10 | 405 | 20,377,600 | 60349470 | n = int(input())
x = list(map(int, input().split()))
x.sort()
cnt = 0
for i in range(n):
if x[i] <= 0:
cnt += 1 - x[i]
x[i] = 1
elif x[i] >= n:
cnt += x[i] - n
x[i] = n
for j in range(n):
if x[j] < j + 1:
cnt += j + 1 - x[j]
x[j] = j + 1
print(cnt + n - len(se... | 33 | 187 | 36,966,400 | 178866041 | def main():
n = int(input())
elems = list(sorted(map(int, input().split(" "))))
result = 0
i = 1
for x in elems:
result += abs(x - i) if x >= 1 else (abs(x) + i)
i += 1
print(result)
if __name__ == "__main__":
main() | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
285/C | 285 | C | Python 3 | TESTS | 8 | 280 | 15,974,400 | 40677262 | n, fine, sum_ = int(input()), 0, 0
for a in map(int, input().split()):
if a < 1:
fine, sum_ = fine - a + 1, sum_ + 1
elif a > n:
fine, sum_ = fine + a - n, sum_ + n
else:
sum_ += a
print(fine + abs(n * (n + 1) // 2 - sum_)) | 33 | 187 | 44,134,400 | 169970868 | t=int(input())
# n,a,b,c=map(int,input().split())
# s=input()
arr=list(map(int,input().split()))
# s=list(map(int,input()))
# mat=[input() for i in range(4)]
val=[i for i in range(1,t+1)]
arr.sort()
sum=0
for i in range(t):
sum+=abs(arr[i]-val[i])
print(sum) | Codeforces Round 175 (Div. 2) | CF | 2,013 | 1 | 256 | Building Permutation | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
You have a sequence of integers a1, a2, ..., an.... | The first line contains integer n (1 ≤ n ≤ 3·105) — the size of the sought permutation. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | [{"input": "2\n3 0", "output": "2"}, {"input": "3\n-1 -1 2", "output": "6"}] | 1,200 | ["greedy", "implementation", "sortings"] | 33 | [{"input": "2\r\n3 0\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 -1 2\r\n", "output": "6\r\n"}, {"input": "5\r\n-3 5 -3 3 3\r\n", "output": "10\r\n"}, {"input": "10\r\n9 6 -2 4 1 1 1 9 6 2\r\n", "output": "18\r\n"}, {"input": "9\r\n2 0 0 6 5 4 1 9 3\r\n", "output": "15\r\n"}] | false | stdio | null | true |
975/A | 975 | A | Python 3 | PRETESTS | 3 | 78 | 9,011,200 | 37807721 | n = int(input())
inputs = input()
inlst = list(map(str, inputs.split(" ")))
uniqe = []
for i in range(n):
uniq = set(inlst[i])
uniqe.append(str(uniq))
objects = len(set(uniqe))
print(objects) | 30 | 46 | 7,577,600 | 161874996 | n=int(input())
listx=input().split(' ')
d=[]
for x in listx:
x=set(x)
if x not in d:
d.append(x)
print(len(d)) | Codeforces Round 478 (Div. 2) | CF | 2,018 | 1 | 256 | Aramic script | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once.
- A root and all its permutations represent the same object.
- The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in... | The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script.
The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$.
It is guaranteed that all characters of the strings are small latin ... | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | null | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | [{"input": "5\na aa aaa ab abb", "output": "2"}, {"input": "3\namer arem mrea", "output": "1"}] | 900 | ["implementation", "strings"] | 30 | [{"input": "5\r\na aa aaa ab abb\r\n", "output": "2"}, {"input": "3\r\namer arem mrea\r\n", "output": "1"}, {"input": "10\r\nbda bbb cda dca dda dcb bcd dcb ada ddd\r\n", "output": "6"}, {"input": "2\r\nfhjlqs aceginpr\r\n", "output": "2"}, {"input": "2\r\nbcdfghimn efghijlmo\r\n", "output": "2"}] | false | stdio | null | true |
975/A | 975 | A | Python 3 | TESTS | 3 | 62 | 8,806,400 | 129914360 | n=int(input())
s=list(map(str,input().split(' ')))
k=[]
for i in s:
p=set(i)
c=0
for j in p:
if i.count(j)<2:
c+=1
if c==len(i):
k.append(i)
kn=[]
kn.append(k[0])
for i in range(1,len(k)):
if sorted(k[0])!=sorted(k[i]):
kn.append(k[i])
print(len(kn)) | 30 | 61 | 2,867,200 | 167668018 | n = int(input())
s = input().split()
print(len(set(frozenset(si) for si in s))) | Codeforces Round 478 (Div. 2) | CF | 2,018 | 1 | 256 | Aramic script | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once.
- A root and all its permutations represent the same object.
- The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in... | The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script.
The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$.
It is guaranteed that all characters of the strings are small latin ... | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | null | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | [{"input": "5\na aa aaa ab abb", "output": "2"}, {"input": "3\namer arem mrea", "output": "1"}] | 900 | ["implementation", "strings"] | 30 | [{"input": "5\r\na aa aaa ab abb\r\n", "output": "2"}, {"input": "3\r\namer arem mrea\r\n", "output": "1"}, {"input": "10\r\nbda bbb cda dca dda dcb bcd dcb ada ddd\r\n", "output": "6"}, {"input": "2\r\nfhjlqs aceginpr\r\n", "output": "2"}, {"input": "2\r\nbcdfghimn efghijlmo\r\n", "output": "2"}] | false | stdio | null | true |
975/A | 975 | A | Python 3 | TESTS | 3 | 78 | 9,216,000 | 38112390 | n=int(input())
s=list(input().split(' '))
b=[]
for word in s:
b.append(set(word))
b.sort()
count=1
curr=b[0]
for i in range(1,len(b)):
if(b[i]==curr):
pass
else:
curr=b[i]
count+=1
print(count) | 30 | 61 | 2,969,600 | 151004273 | n = int(input())
lst = input().split()
l1 = []
for i in range(n):
if set(lst[i]) not in l1:
l1.append(set(lst[i]))
print(len(l1)) | Codeforces Round 478 (Div. 2) | CF | 2,018 | 1 | 256 | Aramic script | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once.
- A root and all its permutations represent the same object.
- The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in... | The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script.
The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$.
It is guaranteed that all characters of the strings are small latin ... | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | null | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | [{"input": "5\na aa aaa ab abb", "output": "2"}, {"input": "3\namer arem mrea", "output": "1"}] | 900 | ["implementation", "strings"] | 30 | [{"input": "5\r\na aa aaa ab abb\r\n", "output": "2"}, {"input": "3\r\namer arem mrea\r\n", "output": "1"}, {"input": "10\r\nbda bbb cda dca dda dcb bcd dcb ada ddd\r\n", "output": "6"}, {"input": "2\r\nfhjlqs aceginpr\r\n", "output": "2"}, {"input": "2\r\nbcdfghimn efghijlmo\r\n", "output": "2"}] | false | stdio | null | true |
518/E | 518 | E | PyPy 3-64 | TESTS | 0 | 31 | 0 | 216008024 | print("_RANDOM_GUESS_1690488466.1589143")# 1690488466.1589344 | 75 | 405 | 21,401,600 | 231038367 | INF = 10000000001
def fill(s):
s.insert(0, -INF)
s.append(INF)
i = 0
for j in filter(lambda x: s[x] != '?', range(1, len(s))):
d = i - j
s[j] = int(s[j])
if s[i] > s[j]+d:
raise
a = max(min(d//2, s[j]+d), s[i])
for t in range(i+1, j):
s[t] = a + t - i
i = j
return s[1:-1]
n... | Codeforces Round 293 (Div. 2) | CF | 2,015 | 2 | 256 | Arthur and Questions | After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n.
This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (a1 + a2 ... + ... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively.
The next line contains n space-separated elements ai (1 ≤ i ≤ n).
If ai = ?, then the i-th element of Arthur's sequence was replaced by a question mark.
Otherw... | If Arthur is wrong at some point and there is no sequence that could fit the given information, print a single string "Incorrect sequence" (without the quotes).
Otherwise, print n integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum |ai|, where |ai| is th... | null | null | [{"input": "3 2\n? 1 2", "output": "0 1 2"}, {"input": "5 1\n-10 -9 ? -7 -6", "output": "-10 -9 -8 -7 -6"}, {"input": "5 3\n4 6 7 2 9", "output": "Incorrect sequence"}] | 2,200 | ["greedy", "implementation", "math", "ternary search"] | 75 | [{"input": "3 2\r\n? 1 2\r\n", "output": "0 1 2 \r\n"}, {"input": "5 1\r\n-10 -9 ? -7 -6\r\n", "output": "-10 -9 -8 -7 -6 \r\n"}, {"input": "5 3\r\n4 6 7 2 9\r\n", "output": "Incorrect sequence\r\n"}, {"input": "9 3\r\n? ? ? ? ? ? ? ? ?\r\n", "output": "-1 -1 -1 0 0 0 1 1 1 \r\n"}, {"input": "5 1\r\n1000000000 ? ? ? ?\... | false | stdio | import sys
def read_sequence(file):
line = file.readline().strip()
if line == 'Incorrect sequence':
return None
try:
return list(map(int, line.split()))
except:
return None
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv... | true |
723/D | 723 | D | Python 3 | TESTS | 3 | 31 | 102,400 | 205145608 | 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 | 77 | 307,200 | 21178974 | def mark(z):
while z: z = z[0]
return z
def mark2(z):
while z and type(z) == list: z = z[0]
return z
__debug = None
n, m, kk = map(int, input().split())
data = [list(input()) for i in range(n)]
ocean = []
earth = []
work = [[] for i in range(m*n)]
for k in range(m):
if data[0][k] ... | 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 |
376/B | 376 | B | PyPy 3-64 | TESTS | 3 | 46 | 0 | 228525847 | n, m = map(int,input().split())
os=[]
for i in range(m):
os.append(list(map(int,input().split())))
for i in range(m):
for j in range(m):
if os[i][0]==os[j][1]:
if os[i][2]<=os[j][2]:
os[j][2]-=os[i][2]
os[i][0]=os[j][0]
else:
os[i][2]-=os[j][2]
os[j][0]=os[i][0]
... | 29 | 46 | 0 | 171003922 | n, m = map(int, input().split())
debts = [0] * n
for _ in range(m):
minus, plus, value = map(int, input().split())
debts[minus - 1] -= value
debts[plus - 1] += value
print(sum([debt for debt in debts if debt > 0])) | Codeforces Round 221 (Div. 2) | CF | 2,013 | 1 | 256 | I.O.U. | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | The first line contains two integers n and m (1 ≤ n ≤ 100; 0 ≤ m ≤ 104). The next m lines contain the debts. The i-th line contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ ci ≤ 100), which mean that person ai owes person bi ci rubles.
Assume that the people are numbered by integers from 1 to n.
It is ... | Print a single integer — the minimum sum of debts in the optimal rearrangement. | null | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | [{"input": "5 3\n1 2 10\n2 3 1\n2 4 1", "output": "10"}, {"input": "3 0", "output": "0"}, {"input": "4 3\n1 2 1\n2 3 1\n3 1 1", "output": "0"}] | 1,300 | ["implementation"] | 29 | [{"input": "5 3\r\n1 2 10\r\n2 3 1\r\n2 4 1\r\n", "output": "10\r\n"}, {"input": "3 0\r\n", "output": "0\r\n"}, {"input": "4 3\r\n1 2 1\r\n2 3 1\r\n3 1 1\r\n", "output": "0\r\n"}, {"input": "20 28\r\n1 5 6\r\n1 12 7\r\n1 13 4\r\n1 15 7\r\n1 20 3\r\n2 4 1\r\n2 15 6\r\n3 5 3\r\n3 8 10\r\n3 13 8\r\n3 20 6\r\n4 6 10\r\n4 1... | false | stdio | null | true |
520/C | 520 | C | Python 3 | TESTS | 3 | 46 | 307,200 | 222635163 | from collections import Counter
def factorial(n):
if n<=1:return 1
return n*factorial(n-1)
n=int(input())
s=input()
d=Counter(s)
a=factorial(n)
c=0
for i in d:
a//=factorial(d[i])
if d[i]==n//2:c+=1
print(a+c) | 25 | 62 | 204,800 | 10107470 | MOD = 10**9 + 7
n = int(input())
S = input()
cnt = [S.count('A'), S.count('C'), S.count('G'), S.count('T')]
max_val = max(cnt)
op = cnt.count(max_val)
print((op**n)%MOD ) | Codeforces Round 295 (Div. 2) | CF | 2,015 | 2 | 256 | DNA Alignment | Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.
Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in whic... | The first line of the input contains a single integer n (1 ≤ n ≤ 105).
The second line of the input contains a single string of length n, consisting of characters "ACGT". | Print a single number — the answer modulo 109 + 7. | null | Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.
In the first sample, there is ρ("C", "C") = 1, for the remaining strings... | [{"input": "1\nC", "output": "1"}, {"input": "2\nAG", "output": "4"}, {"input": "3\nTTT", "output": "1"}] | 1,500 | ["math", "strings"] | 25 | [{"input": "1\r\nC\r\n", "output": "1\r\n"}, {"input": "2\r\nAG\r\n", "output": "4\r\n"}, {"input": "3\r\nTTT\r\n", "output": "1\r\n"}, {"input": "4\r\nGACT\r\n", "output": "256\r\n"}, {"input": "1\r\nT\r\n", "output": "1\r\n"}, {"input": "2\r\nAG\r\n", "output": "4\r\n"}, {"input": "3\r\nGCA\r\n", "output": "27\r\n"},... | false | stdio | null | true |
208/E | 208 | E | PyPy 3-64 | TESTS | 0 | 92 | 0 | 194426326 | n = int(input())
parent = list(map(int, input().split()))
m = int(input())
# Функция нахождения p-прародителя common_ancestor
def get_p_ancestor(common_ancestor, p):
while p > 0 and common_ancestor > 0:
common_ancestor = parent[common_ancestor - 1]
p -= 1
return common_ancestor
# Обработка каж... | 64 | 1,310 | 69,939,200 | 200092003 | import bisect
import heapq
import sys
from types import GeneratorType
from functools import cmp_to_key
from collections import defaultdict, Counter, deque
import math
from functools import lru_cache
from heapq import nlargest
from functools import reduce
import random
from itertools import combinations
from itertools i... | Codeforces Round 130 (Div. 2) | CF | 2,012 | 2 | 256 | Blood Cousins | Polycarpus got hold of a family relationship tree. The tree describes family relationships of n people, numbered 1 through n. Each person in the tree has no more than one parent.
Let's call person a a 1-ancestor of person b, if a is the parent of b.
Let's call person a a k-ancestor (k > 1) of person b, if person b ha... | The first input line contains a single integer n (1 ≤ n ≤ 105) — the number of people in the tree. The next line contains n space-separated integers r1, r2, ..., rn, where ri (1 ≤ ri ≤ n) is the number of person i's parent or 0, if person i has no parent. It is guaranteed that family relationships don't form cycles.
T... | Print m space-separated integers — the answers to Polycarpus' queries. Print the answers to the queries in the order, in which the queries occur in the input. | null | null | [{"input": "6\n0 1 1 0 4 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "output": "0 0 1 0 0 1 1"}] | 2,100 | ["binary search", "data structures", "dfs and similar", "trees"] | 64 | [{"input": "6\r\n0 1 1 0 4 4\r\n7\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n4 1\r\n5 1\r\n6 1\r\n", "output": "0 0 1 0 0 1 1 \r\n"}, {"input": "1\r\n0\r\n20\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "0 0 0 0 0 0 0 0 0... | false | stdio | null | true |
316/E1 | 316 | E1 | PyPy 3-64 | TESTS1 | 7 | 216 | 6,041,600 | 201607888 | n,m=map(int,input().split())
l=list(map(int,input().split()))
h=10**9+7
for i in range(m):
t,a,b=map(int,input().split())
if t==1:
l[a-1]=b
else:
f=0
s=1
out=0
for i in range(a-1,b):
out=(out%h+(s%h*l[i]%h)%h)%h
f,s=s,f+s
print(out) | 19 | 748 | 6,963,200 | 78808001 | mod = 10**9
FibArray = [1,1]
def fibonacci(n):
if n<=len(FibArray):
return FibArray[n-1]
else:
temp_fib = fibonacci(n-1)+fibonacci(n-2)
FibArray.append(temp_fib)
return temp_fib
n, m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
quer... | ABBYY Cup 3.0 | ICPC | 2,013 | 3 | 256 | Summer Homework | By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:
1. For given numbers xi and vi assign value vi to element axi.
2... | The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) —... | For each query print the calculated sum modulo 1000000000 (109). | null | null | [{"input": "5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5", "output": "12\n32\n8\n50"}, {"input": "5 4\n1 3 1 2 4\n3 1 4 1\n2 2 4\n1 2 10\n2 1 5", "output": "12\n45"}] | 1,500 | ["brute force", "data structures"] | 19 | [{"input": "5 5\r\n1 3 1 2 4\r\n2 1 4\r\n2 1 5\r\n2 2 4\r\n1 3 10\r\n2 1 5\r\n", "output": "12\r\n32\r\n8\r\n50\r\n"}, {"input": "1 3\r\n2\r\n2 1 1\r\n1 1 3\r\n2 1 1\r\n", "output": "2\r\n3\r\n"}, {"input": "11 11\r\n6 1 9 0 2 9 1 6 2 8 0\r\n2 9 9\r\n1 9 0\r\n1 1 8\r\n2 2 5\r\n2 7 11\r\n2 2 8\r\n1 3 2\r\n1 10 0\r\n2 1 ... | false | stdio | null | true |
316/E1 | 316 | E1 | PyPy 3 | TESTS1 | 7 | 372 | 4,505,600 | 11002630 | n,m = map(int,input().split())
a = list(map(int,input().split()))
f = [1,1]
for i in range(2,n+1):
f.append(f[i-1] + f[i-2])
for q in range(m):
z,l,r = map(int,input().split())
if z == 1:
a[l-1] = r
else:
s = 0
for j in range(l-1,r):
s += (a[j] * f[j-l+1])
p... | 19 | 780 | 25,292,800 | 35903391 | n,m = map(int, input().split())
a = list(map(int, input().split()))
f = [1]*n
for i in range(2,n):
f[i] = f[i-1]+f[i-2]
for i in range(m):
t,l,r = map(int, input().split())
if t==1:
a[l-1] = r
else:
sum_lr = 0
for x in range(r-l+1):
sum_lr += f[x] * a[l+x-1]
p... | ABBYY Cup 3.0 | ICPC | 2,013 | 3 | 256 | Summer Homework | By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:
1. For given numbers xi and vi assign value vi to element axi.
2... | The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) —... | For each query print the calculated sum modulo 1000000000 (109). | null | null | [{"input": "5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5", "output": "12\n32\n8\n50"}, {"input": "5 4\n1 3 1 2 4\n3 1 4 1\n2 2 4\n1 2 10\n2 1 5", "output": "12\n45"}] | 1,500 | ["brute force", "data structures"] | 19 | [{"input": "5 5\r\n1 3 1 2 4\r\n2 1 4\r\n2 1 5\r\n2 2 4\r\n1 3 10\r\n2 1 5\r\n", "output": "12\r\n32\r\n8\r\n50\r\n"}, {"input": "1 3\r\n2\r\n2 1 1\r\n1 1 3\r\n2 1 1\r\n", "output": "2\r\n3\r\n"}, {"input": "11 11\r\n6 1 9 0 2 9 1 6 2 8 0\r\n2 9 9\r\n1 9 0\r\n1 1 8\r\n2 2 5\r\n2 7 11\r\n2 2 8\r\n1 3 2\r\n1 10 0\r\n2 1 ... | false | stdio | null | true |
318/B | 318 | B | Python 3 | TESTS | 3 | 62 | 0 | 226507697 | # بسم الله الرحمن الرحيم
# صلو على نبينا محمد صلى الله عليه و سلم
##############--->>>>> Mohamed Mostafa Mohamed Abdelhamed <<<<<---##############
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ / _` |/ _... | 30 | 154 | 6,963,200 | 221840419 | w = input().replace("heavy","H").replace("metal","M")
res, hCount = 0, 0
for c in w:
if c == "H":
hCount += 1
elif c == "M":
res += hCount
print(res) | Codeforces Round 188 (Div. 2) | CF | 2,013 | 2 | 256 | Strings of Power | Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons... | Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters. | Print exactly one number — the number of powerful substrings of the given string.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.
In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal". | [{"input": "heavymetalisheavymetal", "output": "3"}, {"input": "heavymetalismetal", "output": "2"}, {"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "output": "3"}] | 1,300 | ["implementation", "strings", "two pointers"] | 30 | [{"input": "heavymetalisheavymetal\r\n", "output": "3"}, {"input": "heavymetalismetal\r\n", "output": "2"}, {"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\r\n", "output": "3"}, {"input": "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua\r\n", "outpu... | false | stdio | null | true |
711/D | 711 | D | PyPy 3-64 | TESTS | 3 | 46 | 0 | 207101037 | # 环内只需要顺时针逆时针两种情况,环外无所谓。
n = int(input())
a = list(map(int, input().split()))
Mod = 10**9 + 7
from collections import defaultdict
from collections import deque
g = defaultdict(list)
cnt = [1]*n
for i in range(n):
g[i].append(a[i]-1)
g[a[i]-1].append(i)
cnt[a[i]-1] += 1
q = deque([i for i in range(n) if cnt[... | 131 | 155 | 27,545,600 | 207098619 | # Problem: D. Directed Roads
# Contest: Codeforces - Codeforces Round 369 (Div. 2)
# URL: https://codeforces.com/problemset/problem/711/D
# Memory Limit: 256 MB
# Time Limit: 2000 ms
import sys
import bisect
import random
import io, os
from bisect import *
from collections import *
from contextlib import redirect_stdo... | 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 |
711/D | 711 | D | PyPy 3-64 | TESTS | 3 | 61 | 0 | 207137773 | import sys
from collections import deque
RI = lambda: map(int, sys.stdin.buffer.readline().split())
n = list(RI())[0]
edges = [0] + list(RI())
deg = [0] * (n + 1)
for i, v in enumerate(edges):
if i == 0: continue
deg[v] += 1
q = deque([i for i in range(1, n + 1) if deg[i] == 0])
while q:
x = q.popleft()
... | 131 | 171 | 18,534,400 | 193498801 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
mod = pow(10, 9) + 7
a = [0] + list(map(int, input().split()))
pow2 = [1]
for _ in range(n + 5):
pow2.append(2 * pow2[-1] % mod)
visit = [0] * (n + 1)
ans = 1
for i in range(1, n + 1):
if visit[i]:
continue... | 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 |
711/D | 711 | D | PyPy 3-64 | TESTS | 3 | 92 | 4,608,000 | 207147374 | from bisect import bisect_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb, sqrt, gcd, lcm, log2
from copy import deepcopy
import heapq
from sys import stdin, stdout
input = stdin.readline
def quick_mi(a, b, MOD):
res = 1 % MOD
while ... | 131 | 202 | 28,876,800 | 207099275 | import random
import sys
from math import gcd, lcm, sqrt, isqrt, perm
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush
from c... | 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 |
711/D | 711 | D | PyPy 3-64 | TESTS | 3 | 93 | 2,969,600 | 194664330 | from heapq import heappush, heappop
from collections import defaultdict, Counter, deque
import threading
import sys
import bisect
input = sys.stdin.readline
def ri(): return int(input())
def rs(): return input()
def rl(): return list(map(int, input().split()))
def rls(): return list(input().split())
# threading.stack... | 131 | 202 | 33,996,800 | 207096160 | n = int(input())
l = list(map(int, input().split()))
l.insert(0,0)
mark = {}
loop, pos, res , mod= 0, 1, 1, int(1e9+7)
for i in range(1, n+1):
if not i in mark:
start, j = pos, i
while not j in mark:
mark[j] = pos
pos+= 1
j = l[j]
if mark[j]>=start:
... | 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 |
711/D | 711 | D | Python 3 | TESTS | 3 | 62 | 7,168,000 | 125259672 | import math
import sys
from decimal import Decimal
n=int(input())
arr=list(map(int,input().split()))
adj={}
visited=[False]*(n+1)
rev=[]
def dfs2(u,comp):
comp.add(u)
visited[u]=True
for v in adj[u]:
if not visited[v]:
dfs2(v,comp)
return comp
def dfs1(u):
visited[u]=True
for v in adj[u]:... | 131 | 249 | 14,745,600 | 201808730 | mod = 1000000007
def solve(A):
n = len(A)
aa = [0]
for x in A:
aa.append(x)
idx = [0] * (n+1)
res = pos = 1
for i in range(1, n + 1):
if not idx[i]:
j, start = i, pos
while not idx[j]:
idx[j] = pos
pos += 1
... | 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 |
469/B | 469 | B | Python 3 | TESTS | 2 | 31 | 0 | 223779281 | p,q,l,r=map(int,input().split());ap=[];aq=[];count=0
for i in range(p):
ap.append(list(map(int,input().split())))
for i in range(q):
aq.append(list(map(int,input().split())))
for i in range(l,r+1):
bol=False
for j in aq:
for j2 in ap:
if j2[0]<=j[0]+i<j2[1] or j2[0]<=j[1]+i<=j2[1]:
... | 31 | 93 | 0 | 7874206 | p,q,x,y = map(int, input().split())
a = [0 for i in range(p)]
b = [0 for i in range(p)]
c = [0 for i in range(q)]
d = [0 for i in range(q)]
for i in range(p):
a[i], b[i] = map(int, input().split())
for i in range(q):
c[i], d[i] = map(int, input().split())
ans = 0
def comp(k,l,m,n):
if m <= l and k <= n:
... | 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 |
316/E1 | 316 | E1 | PyPy 3-64 | TESTS1 | 7 | 154 | 2,969,600 | 179947019 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
w = list(map(int, input().split()))
M = 10**9
d = [1, 1]
for i in range(n-2):
d.append(d[-1]+d[-2])
for _ in range(m):
a, b, c = map(int, input().split())
if a == 2:
q, e = 0, 0
for i in range(b-1, c):
q +=... | 19 | 828 | 102,400 | 3862075 | from sys import *
from math import *
mod = 1000000000
f = [0 for i in range(200)]
f[0] = f[1] = 1
for i in range(2, 200):
f[i] = f[i - 1] + f[i - 2]
n, m = stdin.readline().split()
n = int(n)
m = int(m)
a = list(map(int, stdin.readline().split()))
for i in range(m):
tp, x, y = stdin.readline().split()
tp = int(t... | ABBYY Cup 3.0 | ICPC | 2,013 | 3 | 256 | Summer Homework | By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:
You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:
1. For given numbers xi and vi assign value vi to element axi.
2... | The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) —... | For each query print the calculated sum modulo 1000000000 (109). | null | null | [{"input": "5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5", "output": "12\n32\n8\n50"}, {"input": "5 4\n1 3 1 2 4\n3 1 4 1\n2 2 4\n1 2 10\n2 1 5", "output": "12\n45"}] | 1,500 | ["brute force", "data structures"] | 19 | [{"input": "5 5\r\n1 3 1 2 4\r\n2 1 4\r\n2 1 5\r\n2 2 4\r\n1 3 10\r\n2 1 5\r\n", "output": "12\r\n32\r\n8\r\n50\r\n"}, {"input": "1 3\r\n2\r\n2 1 1\r\n1 1 3\r\n2 1 1\r\n", "output": "2\r\n3\r\n"}, {"input": "11 11\r\n6 1 9 0 2 9 1 6 2 8 0\r\n2 9 9\r\n1 9 0\r\n1 1 8\r\n2 2 5\r\n2 7 11\r\n2 2 8\r\n1 3 2\r\n1 10 0\r\n2 1 ... | false | stdio | null | true |
774/A | 774 | A | Python 3 | TESTS | 5 | 93 | 6,963,200 | 86267037 | import math
n,c1,c2=map(int,input().split())
s=input()
cnt=s.count('1')
if(cnt==1):
print(int(c1+c2*math.pow((n-1),2)))
else:
if(n%2):
l=int(c1+c2*math.pow((n-1),2))
r=int(2*c1+c2*math.pow(int((n+1)/2)-1,2)+c2*math.pow(int((n-1)/2)-1,2))
print(min(l,r))
else:
l=int(c1+c2*math... | 31 | 62 | 7,987,200 | 216484354 | num_people, cost1, cost2 = map(int, input().split())
adults_count = input().count('1')
cost_list = []
for i in range(1, adults_count + 1):
cost = cost1 * i
cost += i * cost2 * (((num_people // i) - 1) ** 2)
cost += cost2 * (num_people % i) * (2 * (num_people // i) - 1)
cost_list.append(cost)
pr... | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 2 | 256 | Amusement Park | Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.
Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible tha... | The first line contains three integers n, c1 and c2 (1 ≤ n ≤ 200 000, 1 ≤ c1, c2 ≤ 107) — the number of visitors and parameters for determining the ticket prices for a group.
The second line contains the string of length n, which consists of zeros and ones. If the i-th symbol of the string is zero, then the i-th visit... | Print the minimum price of visiting the most extreme attraction for all pupils and their parents. Each of them should roll on the attraction exactly once. | null | In the first test one group of three people should go to the attraction. Then they have to pay 4 + 1 * (3 - 1)2 = 8.
In the second test it is better to go to the attraction in two groups. The first group should consist of two adults (for example, the first and the second person), the second should consist of one pupil... | [{"input": "3 4 1\n011", "output": "8"}, {"input": "4 7 2\n1101", "output": "18"}] | 2,100 | ["*special", "ternary search"] | 31 | [{"input": "3 4 1\r\n011\r\n", "output": "8\r\n"}, {"input": "4 7 2\r\n1101\r\n", "output": "18\r\n"}, {"input": "1 2 2\r\n1\r\n", "output": "2\r\n"}, {"input": "2 3 10\r\n01\r\n", "output": "13\r\n"}, {"input": "5 10 3\r\n11100\r\n", "output": "35\r\n"}, {"input": "10 2 2\r\n1111101111\r\n", "output": "20\r\n"}, {"inp... | false | stdio | null | true |
711/D | 711 | D | PyPy 3-64 | TESTS | 3 | 108 | 4,505,600 | 207137933 | import random, sys, os, math, gc
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce, cmp_to_key
from itertools import accumulate, combinations, permutations, product
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io import BytesIO, IOBase
from copy import... | 131 | 265 | 34,816,000 | 207132155 | n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
mark = {}
loop, pos, res, mod = 0, 1, 1, int(1e9 + 7)
for i in range(1, n+1):
if not i in mark:
start, j = pos, i
while not j in mark:
mark[j] = pos
pos += 1
j = l[j]
if mark[j] >= start:... | 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 |
774/I | 774 | I | PyPy 3-64 | TESTS | 5 | 77 | 2,252,800 | 198743280 | n = int(input())
s = []
for i in range(n):
s.append(input())
t = input()
l = len(t)
dp = [float('inf')] * (l+1)
dp[0] = 0
for i in range(1, min(55, l) + 1):
for j in range(n):
if len(s[j]) < i:
continue
if t[:i] == s[j][-i:]:
dp[i] = 1
for i in range(1, l+1):
for j... | 46 | 124 | 2,764,800 | 198880859 | import sys
import math
MAXN = 55
INF = 1e9
MOD = 1e9+7
L_INF = 4e18
EPS = 1e-10
n = int(input())
s = []
for i in range(n):
s.append(input())
t = input()
l = len(t)
dp = [INF] * (l + 1)
dp[0] = 0
for i in range(l):
for j in range(n):
_l, _r = i, 0
while _r < len(s[j]) and _l < l:
... | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 2 | 256 | Composing Of String | Stepan has a set of n strings. Also, he has a favorite string s.
Stepan wants to do the following. He will take some strings of his set and write them down one after another. It is possible that he will take some strings more than once, and will not take some of them at all.
Your task is to determine the minimum numb... | The first line contains the integer n (1 ≤ n ≤ 50) — the number of strings in Stepan's set.
The next n lines contain n non-empty strings consisting of lowercase letters of the English alphabet. The length of each of these strings does not exceed 50 symbols. It is possible that some strings from Stepan's set are the sa... | Print the minimum number of strings which Stepan should take from the set and write them down one after another so that the string s appears as a subsequence in the resulting written down string. Each string from the set should be counted as many times as Stepan takes it from the set.
If the answer doesn't exsist, pri... | null | In the first test, Stepan can take, for example, the third and the second strings from the set, write them down, and get exactly his favorite string.
In the second example Stepan can take, for example, the second, the third and again the second strings from the set and write them down. Then he will get a string "aabaa... | [{"input": "3\na\naa\na\naaa", "output": "2"}, {"input": "4\nab\naab\naa\nbb\nbaaab", "output": "3"}, {"input": "2\naaa\nbbb\naaacbbb", "output": "-1"}] | 2,300 | ["*special", "dp"] | 46 | [{"input": "3\r\na\r\naa\r\na\r\naaa\r\n", "output": "2\r\n"}, {"input": "4\r\nab\r\naab\r\naa\r\nbb\r\nbaaab\r\n", "output": "3\r\n"}, {"input": "2\r\naaa\r\nbbb\r\naaacbbb\r\n", "output": "-1\r\n"}, {"input": "4\r\naab\r\naa\r\nbb\r\naba\r\nbaaab\r\n", "output": "2\r\n"}, {"input": "2\r\naaaaaaaa\r\nabbaaaaaaa\r\nbbb... | false | stdio | null | true |
962/E | 962 | E | Python 3 | TESTS | 0 | 78 | 204,800 | 92462928 | n = int(input())
s = 0
x = []
c = []
for i in range(n):
a,b = input().split()
x.append(int(a))
c.append(b)
for i in range(n-1):
if c[i] != c[0]:
continue
if (c[i] == c[i+1] or c[i+1] == "P"):
s += x[i+1] - x[i]
else:
for j in range(i+2, n):
if(c[i] == c[j] or c[j] == "P"):
s += x[j] - x[i]
break
... | 45 | 1,326 | 24,678,400 | 37233335 | #!/usr/bin/env python3
M = 4 * 10**9 + 1
n = int(input().strip())
f = lambda t: (int(t[0]), t[1])
# read and add far P points at both ends
xcis = [(-M, 'P')] + [f(input().strip().split()) for _ in range(n)] + [(M, 'P')]
iPs = [i for i in range(len(xcis)) if (xcis[i][1] == 'P')]
iRs = [i for i in range(len(xcis)) if ... | 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 |
961/E | 961 | E | PyPy 3-64 | TESTS | 3 | 62 | 0 | 198868848 | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().rstrip()
inp = lambda dtype: [dtype(x) for x in input().split()]
debug = lambda *x: print(*x, file=sys.stderr)
ceil_ = lambda a, b: (a + b - 1) // b
sum_n = lambda n: (n * (n + 1)) // 2
get_bit = lambda x, i: (x >> i) & 1
Mint, Mlo... | 30 | 732 | 24,268,800 | 58653185 | from sys import stdin
from sys import setrecursionlimit as SRL; SRL(10**7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
n = int(input())
a = list(rrd())
bit = [0]*(n+100)
def ins(x):
while x<=n:
bit[x] += 1
x += x&(-x)
def get(l):
tot = 0
while l:
tot += bit[l... | 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/E | 962 | E | Python 3 | TESTS | 18 | 717 | 19,660,800 | 37684244 | # B R P
def solve2(length, cities):
result = 0
for idx, city in enumerate(cities):
cityCode = city[1]
cityIdx = city[0]
it = idx - 1
visitedP = False
visitedN = False
visitedB = False
visitedR = False
BValue = 0
RValue = 0
PValue = 0
while(it >= 0):
neighbourCode = ... | 45 | 1,887 | 31,232,000 | 37344651 | 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':
if r is not None:
res+=ix-r
mr=max(mr,ix-r)
r=ix
if t=='P':
if p is not None:
if ix-p<mr+mb:res-=(mr+mb)-(ix-p)
... | 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 |
713/C | 713 | C | PyPy 3 | TESTS | 1 | 124 | 0 | 67950940 | def mySol(arr, n):
mod = 0
if arr[0] > arr[1]:
mod = arr[0]-arr[1] + 1
arr[0] = arr[1]-1
for i in range(1, n-1):
am = arr[i]
a0 = arr[i-1]
a1 = arr[i+1]
if a0 < am < a1:
continue
if a1 < am :
possDed = am - a0 - 1
if... | 57 | 155 | 4,915,200 | 178123174 | # LUOGU_RID: 91828776
import sys
# sys.setrecursionlimit(int(1e9))
# import random
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
# from itertools import accumulate,product
from heapq import nsmallest, nlargest, heapify, heappop, heappush
# from bisect import bisect_l... | Codeforces Round 371 (Div. 1) | CF | 2,016 | 5 | 256 | Sonya and Problem Wihtout a Legend | Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati... | The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array.
Next line contains n integer ai (1 ≤ ai ≤ 109). | Print the minimum number of operation required to make the array strictly increasing. | null | In the first sample, the array is going to look as follows:
2 3 5 6 7 9 11
|2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9
And for the second sample:
1 2 3 4 5
|5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12 | [{"input": "7\n2 1 5 11 5 9 11", "output": "9"}, {"input": "5\n5 4 3 2 1", "output": "12"}] | 2,300 | ["dp", "sortings"] | 57 | [{"input": "7\r\n2 1 5 11 5 9 11\r\n", "output": "9\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "12\r\n"}, {"input": "2\r\n1 1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000 1\r\n", "output": "1000\r\n"}, {"input": "5\r\n100 80 60 70 90\r\n", "output": "54\r\n"}, {"input": "10\r\n10 16 17 11 1213 1216 1216 1209... | false | stdio | null | true |
283/B | 283 | B | PyPy 3 | TESTS | 2 | 310 | 0 | 72115387 | """
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
flush = sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)
def iin(): return int(input())
def lin(): return list(map(int, input().split()))
# range = xrange
# input = raw_input
... | 50 | 466 | 29,696,000 | 171032684 | n = int(input())
t = [0, 0]
t += list(map(int, input().split()))
n += 1
a = [0] * n
b = [0] * n
n -= 1
a[1] = b[1] = -1
#print(t, a, b)
def calc(s, a, b, l):
global t
l.reverse()
j = 0
n = len(l)
while True:
s += t[l[j]]
a[l[j]] = s
j += 1
if j == n:
return
s += t[l[j]]
b[l[j]] = s
j += 1
... | 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 |
379/B | 379 | B | Python 3 | TESTS | 5 | 202 | 1,843,200 | 150938472 | n=int(input())
s=list(map(int,input().split()))
a=[]
while sum(s)>0:
for i in range(n):
if s[i]>0:
a.append("P")
s[i]-=1
if i<n-1:
a.append("R")
i+=1
a.append("L")
for j in range(n-1):
if s[n-2-j]>0:
a.append("P")
s[n-2-j]-=1
if j<n-2:
a.append("L")
j+=1
while a[len(a)-1]!="P":
a=a[:... | 15 | 46 | 204,800 | 200589946 | n = int(input())
arr = list(map(int,input().split()))
# print((a*b-1)//(b-1))
ans = 'PRL'*arr[0]
for i in range(1,n):
ans+='R'+'PLR'*arr[i]
print(ans) | Good Bye 2013 | CF | 2,013 | 1 | 256 | New Year Present | The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.
Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided t... | The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300).
It is guaranteed that at least one ai is positive. | Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot ... | null | null | [{"input": "2\n1 2", "output": "PRPLRP"}, {"input": "4\n0 2 0 2", "output": "RPRRPLLPLRRRP"}] | 1,200 | ["constructive algorithms", "implementation"] | 15 | [{"input": "2\r\n1 2\r\n", "output": "PRPLRP"}, {"input": "4\r\n0 2 0 2\r\n", "output": "RPRRPLLPLRRRP"}, {"input": "10\r\n2 3 4 0 0 1 1 3 4 2\r\n", "output": "PRPRPRRRPRPRPRPRPLPLPLLLLLPLPLPRPRPRRRRRPRPRPLPLLLLLLPLL"}, {"input": "10\r\n0 0 0 0 0 0 0 0 1 0\r\n", "output": "RRRRRRRRPR"}, {"input": "5\r\n2 2 2 2 2\r\n", ... | false | stdio | import sys
def main(input_path, output_path, sub_output_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
with open(sub_output_path) as f:
s = f.read().strip()
if len(s) < 1 or len(s) > 10**6:
print(0)
return
... | true |
961/E | 961 | E | PyPy 3 | TESTS | 3 | 109 | 0 | 50576307 | N = int(input())
A = list(map(int, input().split()))
def getsum(BITTree,i):
s = 0
i = i+1
while i > 0:
s += BITTree[i]
i -= i & (-i)
return s
def updatebit(BITTree , n , i ,v):
i += 1
while i <= n:
BITTree[i] += v
i += i & (-i)
def construct(arr, ... | 30 | 1,465 | 77,004,800 | 36972134 | import sys
class RangeBit:
def __init__(self, n):
sz = 1
while n >= sz:
sz *= 2
self.size = sz
self.dataAdd = [0 for _ in range(sz)]
self.dataMul = [0 for _ in range(sz)]
def sum(self, i):
assert i > 0
add, mul, start = 0, 0, i
while ... | 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 |
961/F | 961 | F | PyPy 3-64 | TESTS | 1 | 61 | 1,433,600 | 168239894 | import random
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def is_Prime(n):
if n == 1:
return False
for i in range(2, min(int(n ** (1 / 2)) + 2, n)):
if n % i == 0:
return False
return True
def random_mod():
mod = random.randint(5 * pow(10... | 44 | 592 | 48,025,600 | 168241300 | import random
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def is_Prime(n):
if n == 1:
return False
for i in range(2, min(int(n ** (1 / 2)) + 2, n)):
if n % i == 0:
return False
return True
def random_mod():
mod = random.randint(5 * pow(10... | Educational Codeforces Round 41 (Rated for Div. 2) | ICPC | 2,018 | 4 | 256 | k-substrings | You are given a string s consisting of n lowercase Latin letters.
Let's denote k-substring of s as a string subsk = sksk + 1..sn + 1 - k. Obviously, subs1 = s, and there are exactly $$\left\lceil \frac{n}{2} \right\rceil$$ such substrings.
Let's call some string t an odd proper suprefix of a string T iff the followin... | The first line contains one integer n (2 ≤ n ≤ 106) — the length s.
The second line contains the string s consisting of n lowercase Latin letters. | Print $$\left\lceil \frac{n}{2} \right\rceil$$ integers. i-th of them should be equal to maximum length of an odd proper suprefix of i-substring of s (or - 1, if there is no such string that is an odd proper suprefix of i-substring). | null | The answer for first sample test is folowing:
- 1-substring: bcabcabcabcabca
- 2-substring: cabcabcabcabc
- 3-substring: abcabcabcab
- 4-substring: bcabcabca
- 5-substring: cabcabc
- 6-substring: abcab
- 7-substring: bca
- 8-substring: c | [{"input": "15\nbcabcabcabcabca", "output": "9 7 5 3 1 -1 -1 -1"}, {"input": "24\nabaaabaaaabaaabaaaabaaab", "output": "15 13 11 9 7 5 3 1 1 -1 -1 1"}, {"input": "19\ncabcabbcabcabbcabca", "output": "5 3 1 -1 -1 1 1 -1 -1 -1"}] | 2,700 | ["binary search", "hashing", "string suffix structures"] | 44 | [{"input": "15\r\nbcabcabcabcabca\r\n", "output": "9 7 5 3 1 -1 -1 -1\r\n"}, {"input": "24\r\nabaaabaaaabaaabaaaabaaab\r\n", "output": "15 13 11 9 7 5 3 1 1 -1 -1 1\r\n"}, {"input": "19\r\ncabcabbcabcabbcabca\r\n", "output": "5 3 1 -1 -1 1 1 -1 -1 -1\r\n"}, {"input": "2\r\nza\r\n", "output": "-1\r\n"}, {"input": "20\r\... | false | stdio | null | true |
28/B | 28 | B | Python 3 | TESTS | 1 | 218 | 409,600 | 50622642 | n=int(input())
from collections import defaultdict
d=defaultdict(list)
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
for i in range(n):
x=b[i]
if i-x>=0:
d[i].append(i-x)
d[i-x].append(i)
if i+x<n:
d[i].append(i+x)
d[i+x].append(i)
for i in range(n)... | 33 | 124 | 6,963,200 | 115960096 | n=int(input())
orden= input().split()
fav= input().split()
arr=[]
for i in range(n):
orden[i]=int(orden[i])
fav[i]=int(fav[i])
arr.append(i)
def union(el):
if arr[el] != el:
arr[el] = union(arr[el])
return arr[el]
cont=0
for i in fav:
if cont >= i:
arr[union(cont)] = union(c... | Codeforces Beta Round 28 (Codeforces format) | CF | 2,010 | 2 | 256 | pSort | One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ... | The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells. | If the given state is reachable in the described game, output YES, otherwise NO. | null | null | [{"input": "5\n5 4 3 2 1\n1 1 1 1 1", "output": "YES"}, {"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "output": "NO"}, {"input": "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "output": "YES"}] | 1,600 | ["dfs and similar", "dsu", "graphs"] | 33 | [{"input": "5\r\n5 4 3 2 1\r\n1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n4 3 5 1 2 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 2 5 1 3 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 2 1 4 6 5\r\n3 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 5 1 4 6 2\r\n3... | false | stdio | null | true |
711/D | 711 | D | Python 3 | TESTS | 3 | 30 | 0 | 201802043 | MOD = 1000000007
def dfs2(u, cycles, cyclecnt, visited, a):
cycles[cyclecnt] += 1
visited[u] = 3
if visited[a[u]] == 3:
return
dfs2(a[u], cycles, cyclecnt, visited, a)
def dfs(u, cycles, cyclecnt, visited, a):
visited[u] = 2
if visited[a[u]] == 0:
dfs(a[u], cycles, cyclecnt, vi... | 131 | 342 | 43,622,400 | 88162972 | from sys import stdin
n = int(stdin.readline())
a = [int(x)-1 for x in stdin.readline().split()]
nodes = set([x for x in range(n)])
loops = []
while nodes:
for x in nodes:
nxt = x
break
visited = set()
q = []
early = False
while not nxt in visited:
if not nxt in nodes:
... | 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 |
777/C | 777 | C | Python 3 | TESTS | 98 | 857 | 10,444,800 | 27457208 | from sys import stdin
n, m = map(int, stdin.readline().rstrip().split())
if n == 1:
print("Yes")
exit()
data = []
for i in range(0, n):
data.append(list(map(int, stdin.readline().rstrip().split())))
sorted_data = [0] * n
for col in range(0, m):
mark_r = 0
cur_r = 1
st = []
while cur_r < n... | 114 | 187 | 13,414,400 | 189119085 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
n, m = map(int, input().split())
a = []
for _ in range(n):
a0 = list(map(int, input().split()))
for i in a0:
a.append(i)
x = [i for i in range(1, n + 1)]
for j in range(m):
u = n
f... | Codeforces Round 401 (Div. 2) | CF | 2,017 | 1 | 256 | Alyona and Spreadsheet | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in... | The first line of the input contains two positive integers n and m (1 ≤ n·m ≤ 100 000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines co... | Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | null | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | [{"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "output": "Yes\nNo\nYes\nYes\nYes\nNo"}] | 1,600 | ["binary search", "data structures", "dp", "greedy", "implementation", "two pointers"] | 114 | [{"input": "5 4\r\n1 2 3 5\r\n3 1 3 2\r\n4 5 2 3\r\n5 5 3 2\r\n4 4 3 4\r\n6\r\n1 1\r\n2 5\r\n4 5\r\n3 5\r\n1 3\r\n1 5\r\n", "output": "Yes\r\nNo\r\nYes\r\nYes\r\nYes\r\nNo\r\n"}, {"input": "1 1\r\n1\r\n1\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n523130301\r\n127101624\r\n15573616\r\n703140639\r\n628818570\r... | false | stdio | null | true |
327/C | 327 | C | PyPy 3-64 | TESTS | 4 | 92 | 1,945,600 | 174864734 | n=input(); ans= 0; n *= int(input()); c = len(n)
for x in range(c) :
if n[x] == '0' or n[x] == '5' : ans+=2**(x)
print(ans) | 33 | 248 | 19,353,600 | 194605055 | import sys
import math
import random
input = sys.stdin.readline
def mod(a, b, m):
if b == 0:
return 1
else:
p = mod(a, b // 2, m)
if b % 2:
return (p ** 2 * a) % m
else:
return (p ** 2) % m
def g(l, M):
return mod(l, M - 2, M)
M = 10 ** 9 + ... | Codeforces Round 191 (Div. 2) | CF | 2,013 | 1 | 256 | Magic Five | There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ways... | In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k. | Print a single integer — the required number of ways modulo 1000000007 (109 + 7). | null | In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.
In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.
In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to d... | [{"input": "1256\n1", "output": "4"}, {"input": "13990\n2", "output": "528"}, {"input": "555\n2", "output": "63"}] | 1,700 | ["combinatorics", "math"] | 33 | [{"input": "1256\r\n1\r\n", "output": "4\r\n"}, {"input": "13990\r\n2\r\n", "output": "528\r\n"}, {"input": "555\r\n2\r\n", "output": "63\r\n"}, {"input": "14\r\n178\r\n", "output": "0\r\n"}, {"input": "277557766562106078327886194146355351781887756238383139670139581436190170050799912854698535037185625049275351767138797... | false | stdio | null | true |
393/B | 393 | B | Python 3 | TESTS | 1 | 93 | 307,200 | 49667745 | import math
n = int(input())
A = [[0.0]*n]*n
B = [[0.0]*n]*n
W = []
for i in range(n):
W.append(list(map(int, input().split())))
for i in range(n):
for j in range(n):
if i!=j:
if A[i][j] == 0:
A[i][j] = A[j][i] = min(W[i][j], W[j][i])+abs(W[i][j]-W[j][i])/2
if B[i][j]==0:
B[i][j] = W[i][j] - A[i][j]
... | 40 | 155 | 1,331,200 | 64654734 | n = int(input())
lst = [[int(x) for x in input().split()] for i in range(n)]
t = [[0] * n for y in range(n)]
for i in range(n):
t[i][i], lst[i][i] = lst[i][i], 0
for j in range(i + 1, n):
t[j][i] = t[i][j] = d = (lst[i][j] + lst[j][i]) / 2
lst[i][j] -= d
lst[j][i] -= d
for i in t:
pr... | Codeforces Round 230 (Div. 2) | CF | 2,014 | 1 | 256 | Three matrices | Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold:
- Aij = Aji, for all i, j (1 ≤ i, j ≤ n);
- Bij = - Bji, for all i, j (1 ≤... | The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717). | The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them.
The answer will be considered correct if the absolute or ... | null | null | [{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0... | null | [] | 40 | [{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000... | false | stdio | import sys
def is_close(a, b):
abs_tol = 1e-4
rel_tol = 1e-4
diff = abs(a - b)
if diff <= abs_tol:
return True
max_val = max(abs(a), abs(b))
return diff <= rel_tol * max_val
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.read().spl... | true |
778/A | 778 | A | PyPy 3 | TESTS | 29 | 592 | 45,465,600 | 90796107 | from collections import defaultdict
def isSubsequence(S,T,List,pos,Pos):
lenS = len(S)
lenT = len(T)
Sx = 0
Tx = 0
while(Tx<lenT and Sx<lenS):
if(Pos[Sx]<pos):
Sx+=1
elif(S[Sx] == T[Tx]):
Sx+=1
Tx+=1
else:
Sx+=1
if(Tx == len... | 43 | 187 | 31,744,000 | 195894676 | import sys
input = sys.stdin.readline
s = input()[:-1]
t = input()[:-1]
w = list(map(int, input().split()))
n = len(w)
l, r, x = 0, n-len(t)+1, 0
while l < r:
m = (l+r)//2
d = [0]*n
for i in range(m):
d[w[i]-1] = 1
j = 0
for i in range(n):
if s[i] == t[j] and d[i] == 0:
... | Codeforces Round 402 (Div. 1) | CF | 2,017 | 2 | 512 | String Game | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain ... | The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.
Next line contains a permutation a1, a2, ..., a|t| of letter in... | Print a single integer number, the maximum number of letters that Nastya can remove. | null | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" $$\rightarrow$$ "ababcba" $$\rightarrow$$ "ababcba" $$\rightarrow$$ "ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters. | [{"input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3"}, {"input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4"}] | 1,700 | ["binary search", "greedy", "strings"] | 43 | [{"input": "ababcba\r\nabb\r\n5 3 4 1 7 6 2\r\n", "output": "3"}, {"input": "bbbabb\r\nbb\r\n1 6 3 4 2 5\r\n", "output": "4"}, {"input": "cacaccccccacccc\r\ncacc\r\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2\r\n", "output": "9"}, {"input": "aaaabaaabaabaaaaaaaa\r\naaaa\r\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2\r\n... | false | stdio | null | true |
393/B | 393 | B | Python 3 | TESTS | 1 | 93 | 0 | 47525599 | n = int(input())
w = [None]*n
dsum_len = 2*n-1
dsum = [0]*dsum_len
for i in range(n):
w[i] = [int(j) for j in input().strip().split(' ')]
for j in range(n):
dsum[i+j] += w[i][j]
for i in range(n):
for j in range(n):
val = w[i][j]
if (i != j):
ij = i+j
... | 40 | 155 | 2,867,200 | 140353732 | n = int(input())
mat = []
mat1 = []
mat2 = []
for _ in range(n):
t = list(map(int, input().split()))
mat.append(t)
for i in range(n):
m = []
m1 = []
for j in range(n):
if(i==j):
m.append("{0:.8f}".format(mat[i][j]))
m1.append("{0:.8f}".format(0))
elif(i<j):
... | Codeforces Round 230 (Div. 2) | CF | 2,014 | 1 | 256 | Three matrices | Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold:
- Aij = Aji, for all i, j (1 ≤ i, j ≤ n);
- Bij = - Bji, for all i, j (1 ≤... | The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717). | The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them.
The answer will be considered correct if the absolute or ... | null | null | [{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0... | null | [] | 40 | [{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000... | false | stdio | import sys
def is_close(a, b):
abs_tol = 1e-4
rel_tol = 1e-4
diff = abs(a - b)
if diff <= abs_tol:
return True
max_val = max(abs(a), abs(b))
return diff <= rel_tol * max_val
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.read().spl... | true |
526/B | 526 | B | PyPy 3 | TESTS | 1 | 124 | 0 | 102859969 | import math
a = int(input())
b = list(map(int, input().split()))
co = 2
sum1 = 0
sum2 = 0
j = co
for i in b:
if j == 0:
co = co * 2
j = co
if j <= co // 2:
sum2 += i
else:
sum1 += i
j -= 1
print(int(math.fabs(sum2-sum1))) | 38 | 46 | 0 | 195061844 | def dfs(node, v):
global ans
if node >= len(a) + 2:
return 0
v = a[node - 2]
q = dfs(2 * node, v)
r = dfs(2 * node + 1, v)
v += max(q, r)
ans += abs(q - r)
return v
ans = 0
n = int(input())
a = list(map(int, input().split()))
dfs(1, 0)
print(ans) | ZeptoLab Code Rush 2015 | CF | 2,015 | 1 | 256 | Om Nom and Dark Park | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2n + 1 - 1 squares connected by roads so that ... | The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | null | Picture for the sample test. Green color denotes the additional street lights. | [{"input": "2\n1 2 3 4 5 6", "output": "5"}] | 1,400 | ["dfs and similar", "greedy", "implementation"] | 38 | [{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\... | false | stdio | null | true |
526/B | 526 | B | Python 3 | PRETESTS | 1 | 61 | 0 | 10576944 | n = int(input())
a = list(map(int, input().split()))
dp = [0] * (len(a) + 3)
for i in range(2, 2 ** (n + 1)):
dp[i] = a[i - 2] + dp[i // 2]
print(max(dp) * (2 ** (n)) - sum(dp)) | 38 | 61 | 0 | 10578835 | n = int(input())
M = 2 ** (n + 1)
A = [0, 0] + list(map(int, input().split()))
Ans = [0] * M
ans = 0
for i in range(2 ** n - 1, 0, -1):
left = i * 2
right = i * 2 + 1
m_l = A[left] + Ans[left]
m_r = A[right] + Ans[right]
Ans[i] = max(m_l, m_r)
ans += abs(m_l - m_r)
print(ans) | ZeptoLab Code Rush 2015 | CF | 2,015 | 1 | 256 | Om Nom and Dark Park | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2n + 1 - 1 squares connected by roads so that ... | The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | null | Picture for the sample test. Green color denotes the additional street lights. | [{"input": "2\n1 2 3 4 5 6", "output": "5"}] | 1,400 | ["dfs and similar", "greedy", "implementation"] | 38 | [{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\... | false | stdio | null | true |
526/B | 526 | B | PyPy 3 | TESTS | 1 | 93 | 0 | 106657103 | input()
l=list(map(int,input().split()))
l2=[]
for x in range(2):
y=2 if x==0 else 3
t=0
z=1
while x<len(l):
t+=sum(l[x:x+z])
x+=y
z*=2
y*=2
l2.append(t)
print(max(l2)-min(l2)) | 38 | 61 | 0 | 10581545 | #!/usr/bin/python3
n = 2**(int(input())+1)-1
d = input().split(' ')
for i in range(len(d)):
d[i] = int(d[i])
p = 0
for i in range(len(d)-1, 0, -2):
p += abs(d[i]-d[i-1])
d[i//2-1] += max(d[i], d[i-1])
print(p) | ZeptoLab Code Rush 2015 | CF | 2,015 | 1 | 256 | Om Nom and Dark Park | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2n + 1 - 1 squares connected by roads so that ... | The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | null | Picture for the sample test. Green color denotes the additional street lights. | [{"input": "2\n1 2 3 4 5 6", "output": "5"}] | 1,400 | ["dfs and similar", "greedy", "implementation"] | 38 | [{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\... | false | stdio | null | true |
526/B | 526 | B | Python 3 | PRETESTS | 1 | 46 | 614,400 | 10582416 | import sys, os
import fileinput
n = int(input()) + 1
a = [int(x) for x in input().split()]
all_count = 2 ** n - 1
b = [0] * all_count
counter = 0
for i in range(n, 1, -1):
lcnt = 2 ** (i - 1)
first = 2 ** (i - 1) - 2
#print(lcnt, first)
level = a[first:first + lcnt]
for j in range(0, lcnt, 2):
index = firs... | 38 | 61 | 0 | 10583501 | # fin = open("input.txt")
# n = int(fin.readline())
# A = [0] + list(map(int, fin.readline().split()))
n = int(input())
A = [0] + list(map(int, input().split()))
C = 0
for i in range(2 ** n - 2, -1, -1):
C += abs(A[i * 2 + 1] - A[i * 2 + 2])
A[i] += max(A[i * 2 + 1], A[i * 2 + 2])
print(C) | ZeptoLab Code Rush 2015 | CF | 2,015 | 1 | 256 | Om Nom and Dark Park | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2n + 1 - 1 squares connected by roads so that ... | The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | null | Picture for the sample test. Green color denotes the additional street lights. | [{"input": "2\n1 2 3 4 5 6", "output": "5"}] | 1,400 | ["dfs and similar", "greedy", "implementation"] | 38 | [{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\... | false | stdio | null | true |
703/B | 703 | B | PyPy 3-64 | TESTS | 1 | 46 | 0 | 176688839 | t=1
while t>0:
t-=1
n,k=(int(_) for _ in input().strip().split(' '))
a=list(map(int,input().split()))
num=0
for i in range(0,n):
num+=a[i]
sum=0
for i in range(0,n-1):
sum+=a[i]*a[i+1]
sum+=a[0]*a[n-1]
b=list(map(int,input().split()))
for i in range(0,k):
... | 63 | 108 | 19,148,800 | 176693684 | t=1
while t>0:
t-=1
n,k=(int(_) for _ in input().strip().split(' '))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
vis=[0]*100005
sum=0
for i in range(0,n):
sum+=a[i]
ans=0
tmp=0
for i in range(0,k):
vis[b[i]-1]=1
ans+=a[b[i]-1]*(sum-a[... | Codeforces Round 365 (Div. 2) | CF | 2,016 | 1 | 256 | Mishka and trip | Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in th... | The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.
The third line of the input contains k dis... | Print the only integer — summary price of passing each of the roads in XXX. | null | This image describes first sample case:
It is easy to see that summary price is equal to 17.
This image describes second sample case:
It is easy to see that summary price is equal to 71. | [{"input": "4 1\n2 3 1 2\n3", "output": "17"}, {"input": "5 2\n3 5 2 2 4\n1 4", "output": "71"}] | 1,400 | ["implementation", "math"] | 63 | [{"input": "4 1\r\n2 3 1 2\r\n3\r\n", "output": "17"}, {"input": "5 2\r\n3 5 2 2 4\r\n1 4\r\n", "output": "71"}, {"input": "3 1\r\n1 1 1\r\n1\r\n", "output": "3"}, {"input": "3 3\r\n1 1 1\r\n1 2 3\r\n", "output": "3"}, {"input": "7 7\r\n6 9 2 7 4 8 7\r\n1 2 3 4 5 6 7\r\n", "output": "775"}, {"input": "5 5\r\n6 2 4 10 2... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.