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
681/D
681
D
Python 3
TESTS
0
31
102,400
194010460
from collections import defaultdict, deque # read input n, m = map(int, input().split()) # build graph graph = defaultdict(list) in_degree = [0] * (n+1) for _ in range(m): p, q = map(int, input().split()) graph[p].append(q) in_degree[q] += 1 # read gift wishes gifts = list(map(int, input().split())) # p...
38
202
18,841,600
197407343
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def make_graph(n, m): x, s = [0] * (2 * m), [0] * (n + 3) for i in range(0, 2 * m, 2): u, v = map(int, input().split()) s[u + 2] += 1 x[i], x[i + 1] = u, v for i in range(3, n + 3): s[i] += s[i -...
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
Gifts by the List
Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n. Each man has at most one father but may have arbitrary number of sons. Man number A is considered to b...
In the first line of the input two integers n and m (0 ≤ m < n ≤ 100 000) are given — the number of the men in the Sasha's family and the number of family relations in it respectively. The next m lines describe family relations: the (i + 1)th line consists of pair of integers pi and qi (1 ≤ pi, qi ≤ n, pi ≠ qi) meanin...
Print an integer k (1 ≤ k ≤ n) — the number of the men in the list of candidates, in the first line. Print then k pairwise different positive integers not exceeding n — the numbers of the men in the list in an order satisfying every of the men's wishes, one per line. If there are more than one appropriate lists, prin...
null
The first sample explanation: - if there would be no 1 in the list then the first and the third man's wishes would not be satisfied (a1 = a3 = 1); - if there would be no 2 in the list then the second man wish would not be satisfied (a2 = 2); - if 1 would stay before 2 in the answer then the second man would have to gi...
[{"input": "3 2\n1 2\n2 3\n1 2 1", "output": "-1"}, {"input": "4 2\n1 2\n3 4\n1 2 3 3", "output": "3\n2\n1\n3"}]
2,000
["constructive algorithms", "dfs and similar", "graphs", "trees"]
38
[{"input": "3 2\r\n1 2\r\n2 3\r\n1 2 1\r\n", "output": "-1"}, {"input": "4 2\r\n1 2\r\n3 4\r\n1 2 3 3\r\n", "output": "3\r\n2\r\n1\r\n3\r\n"}, {"input": "1 0\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 1\r\n2 1\r\n2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "2 1\r\n2 1\r\n1 2\r\n", "output": "2\r\n1\r\n2\r\n"}, {...
false
stdio
import sys from sys import stdin def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, m = map(int, f.readline().split()) parent = [0] * (n + 1) for _ in range(m): p, q = map(int, f.readline()...
true
383/D
383
D
Python 3
TESTS
1
30
0
228198201
MOD = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) total_sum = sum(a) half_sum = (total_sum + 1) // 2 dp = [[0] * (half_sum + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(1, n + 1): for j in range(half_sum + 1): dp[i][j] = dp[i - 1][j] if j >= a[i - 1]: dp[...
48
280
83,660,800
196824676
#from turtle import * import math MOD = 1000000007 MAXN = 10000 N = 5000 n = int( input( ) ) a = list( map( int , input( ).split( ) ) ) f = [ [0 for i in range( 0 , MAXN + 2 ) ] for j in range( 0 , n + 2 )] ans = 0 for i in range( 1 , n + 1 ) : f[i-1][N] += 1 for j in range( 0 , MAXN + 1 ) : if j ...
Codeforces Round 225 (Div. 1)
CF
2,014
1
256
Antimatter
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode fo...
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
null
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
[{"input": "4\n1 1 1 1", "output": "12"}]
2,300
["dp"]
48
[{"input": "4\r\n1 1 1 1\r\n", "output": "12\r\n"}, {"input": "10\r\n16 9 9 11 10 12 9 6 10 8\r\n", "output": "86\r\n"}, {"input": "50\r\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\r\n", "output": "115119382\r\n"}, {"input": "100\r\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 ...
false
stdio
null
true
351/E
351
E
Python 3
TESTS
1
60
0
228778988
def count_inversions(arr): inv_count = 0 for i in range(len(arr)): for j in range(i+1, len(arr)): if arr[i] > arr[j]: inv_count += 1 return inv_count n = int(input()) a = list(map(int, input().split())) original_inversions = count_inversions(a) flipped_inversions = coun...
36
280
3,686,400
150804902
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) S = [1 for i in range(n)] d = {} for i in range(n): ai = abs(A[i]) if ai not in d: d[ai] = [] d[ai].append(i) L = sorted(d) answer = 0 while len(L) > 0: ai = L.pop() f...
Codeforces Round 204 (Div. 1)
CF
2,013
2
256
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
null
null
[{"input": "2\n2 1", "output": "0"}, {"input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6"}]
2,200
["greedy"]
36
[{"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "9\r\n-2 0 -1 0 -1 2 1 0 -1\r\n", "output": "6\r\n"}, {"input": "9\r\n0 0 1 1 0 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "8\r\n0 1 2 -1 -2 1 -2 2\r\n", "output": "3\r\n"}, {"input": "24\r\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\r\n", "output...
false
stdio
null
true
803/F
803
F
Python 3
TESTS
0
608
6,451,200
84620361
N = 10**5+5 MOD = 10**9+7 freq = [0 for i in range(N)] # Calculating {power(2,i)%MOD} and storing it at ith pos in p2 arr p2 = [0 for i in range(N)] p2[0] = 1 for i in range(1,N): p2[i] = p2[i-1]*2 p2[i]%=MOD def Calculate_Mobius(N): arr = [1 for i in range(N+1)] prime_count = [0 for i in range(N+1)]...
35
202
14,950,400
199478424
# Problem - F - Codeforces # 題意: # 給 N 個元素的數列 A。問有幾種不同的非空子序列,其最大公因數不為 1。輸出方案數對 1e9 + 7 取模。 # 制約: # The first line contains one integer number n (1 ≤ n ≤ 100000). # The second line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 100000). # 解法: # 看起來就很排容。 # 首先計算: # mcnt[ i ]: i 的倍數的元素數量。 # mans[ i ]: 最大公因數為 i 的倍數的非空...
Educational Codeforces Round 20
ICPC
2,017
2
256
Coprime Subsequences
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109 + 7. Note th...
The first line contains one integer number n (1 ≤ n ≤ 100000). The second line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 100000).
Print the number of coprime subsequences of a modulo 109 + 7.
null
In the first example coprime subsequences are: 1. 1 2. 1, 2 3. 1, 3 4. 1, 2, 3 5. 2, 3 In the second example all subsequences are coprime.
[{"input": "3\n1 2 3", "output": "5"}, {"input": "4\n1 1 1 1", "output": "15"}, {"input": "7\n1 3 5 15 3 105 35", "output": "100"}]
2,000
["bitmasks", "combinatorics", "number theory"]
35
[{"input": "3\r\n1 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "15\r\n"}, {"input": "7\r\n1 3 5 15 3 105 35\r\n", "output": "100\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n100000\r\n", "output": "0\r\n"}, {"input": "5\r\n10 8 6 4 6\r\n", "output": "0\r\n"}, {"input": "5...
false
stdio
null
true
51/B
51
B
Python 3
TESTS
0
60
0
231584013
n="" cnt=-1 flag=False ans=[] while True: k=input() if "<table>" in k: cnt+=1 if "</table>" in k: cnt-=1 if cnt==-1: break n+=k n=n[1:len(n)-1].split("><") for i in n: if i=="table": cnt+=1 ans.append(0) if i=="/table": cnt+=1 if i=="td": ans[cnt]+=1 print(*sorted(ans))
19
154
716,800
13939844
import fileinput s = '' for line in fileinput.input(): s += line.strip() #print(s) if s[0] == '<': s = s[1:] if s[-1] == '>': s = s[:-1] #print(s) a = s.split('><') #print(a) ans = [] b = [] for i in a: if i == 'table': b.append(0) elif i == '/table': u = 0 ans.append(b[-1...
Codeforces Beta Round 48
CF
2,010
2
256
bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML t...
For convenience, input data can be separated into non-empty lines in an arbitrary manner. The input data consist of no more than 10 lines. Combine (concatenate) all the input lines into one, to get a text representation s of the specified table. String s corresponds to the given grammar (the root element of grammar is ...
Print the sizes of all the tables in the non-decreasing order.
null
null
[{"input": "<table><tr><td></td></tr></table>", "output": "1"}, {"input": "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "output": "1 4"}, {"input": "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td>...
1,700
["expression parsing"]
19
[{"input": "<table><tr><td></td></tr></table>\r\n", "output": "1 "}, {"input": "<table>\r\n<tr>\r\n<td>\r\n<table><tr><td></td></tr><tr><td></\r\ntd\r\n></tr><tr\r\n><td></td></tr><tr><td></td></tr></table>\r\n</td>\r\n</tr>\r\n</table>\r\n", "output": "1 4 "}, {"input": "<table><tr><td>\r\n<table><tr><td>\r\n<table><t...
false
stdio
null
true
351/E
351
E
Python 3
TESTS
1
92
0
228813962
n = int(input()) sequence = list(map(int, input().split())) # Count the number of negative and positive elements negatives = 0 positives = 0 inversions = 0 for num in sequence: if num < 0: negatives += 1 elif num > 0: positives += 1 # Count the number of inversions by considering elements wit...
36
280
3,686,400
150804902
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) S = [1 for i in range(n)] d = {} for i in range(n): ai = abs(A[i]) if ai not in d: d[ai] = [] d[ai].append(i) L = sorted(d) answer = 0 while len(L) > 0: ai = L.pop() f...
Codeforces Round 204 (Div. 1)
CF
2,013
2
256
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
null
null
[{"input": "2\n2 1", "output": "0"}, {"input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6"}]
2,200
["greedy"]
36
[{"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "9\r\n-2 0 -1 0 -1 2 1 0 -1\r\n", "output": "6\r\n"}, {"input": "9\r\n0 0 1 1 0 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "8\r\n0 1 2 -1 -2 1 -2 2\r\n", "output": "3\r\n"}, {"input": "24\r\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\r\n", "output...
false
stdio
null
true
177/D1
177
D2
PyPy 3-64
TESTS2
2
92
614,400
158569827
import sys, collections, heapq, math readline = sys.stdin.readline # [a, a + b, a + b + c] # [c, b, a] # [c, b + c, a + b + c] def solve(A, B, c): C = B[:] for i in range(1, len(B)): B[i] += B[i - 1] C[i] += C[i - 1] for i in range(len(A)//2): A[i] = (A[i] + B[min(i, len(B) - 1)]) % c j = 0 f...
12
124
1,740,800
179828902
L = lambda : list(map(int, input().split())) n, m, c = L() a = L() b = L() for i in range(n - m + 1): for j in range(m): a[i + j] += b[j] a[i + j] %= c a = list(map(str, a)) print(" ".join(a))
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
The first input line contains three integers n, m and c, separated by single spaces. The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message. The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limit...
Print n space-separated integers — the result of encrypting the original message.
null
In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.
[{"input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0"}, {"input": "3 1 5\n1 2 3\n4", "output": "0 1 2"}]
1,200
["brute force"]
12
[{"input": "4 3 2\r\n1 1 1 1\r\n1 1 1\r\n", "output": "0 1 1 0\r\n"}, {"input": "3 1 5\r\n1 2 3\r\n4\r\n", "output": "0 1 2\r\n"}, {"input": "5 2 7\r\n0 0 1 2 4\r\n3 5\r\n", "output": "3 1 2 3 2\r\n"}, {"input": "20 15 17\r\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\r\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15\r\n", ...
false
stdio
null
true
437/D
437
D
Python 3
TESTS
0
218
25,497,600
128303076
import sys inp = sys.stdin.readlines() first_line = inp.pop(0).replace('\n','').split() n = int(first_line[0]) m = int(first_line[1]) maximum = 1000005 animals = [0 for i in range(maximum)] parent = [0 for i in range(maximum)] size = [0 for i in range(maximum)] edges = [[-1,-1,-1] for i in range(m+1)] second_line = in...
27
607
30,720,000
128061089
import io, os import math input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m = map(int, input().split()) a = list(map(int, input().split())) edges = [] for i in range(m): u, v = map(int, input().split()) smallest = min(a[u-1], a[v-1]); edges.append((u-1, v-1, smallest)) # Kruskal MST paren...
Codeforces Round 250 (Div. 2)
CF
2,014
2
256
The Child and Zoo
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area using the roads....
The first line contains two integers n and m (2 ≤ n ≤ 105; 0 ≤ m ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each line contains two integers xi and yi (1 ≤ xi, yi ≤ n; xi ≠ yi), denoting the road between areas xi and yi. All roads are bidirectional, each pair of ar...
Output a real number — the value of $$\frac{\sum_{p,q,p\neq q} f(p,q)}{n(n-1)}$$. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4.
null
Consider the first sample. There are 12 possible situations: - p = 1, q = 3, f(p, q) = 10. - p = 2, q = 3, f(p, q) = 20. - p = 4, q = 3, f(p, q) = 30. - p = 1, q = 2, f(p, q) = 10. - p = 2, q = 4, f(p, q) = 20. - p = 4, q = 1, f(p, q) = 10. Another 6 cases are symmetrical to the above. The average is $$(10+20+30+10+2...
[{"input": "4 3\n10 20 30 40\n1 3\n2 3\n4 3", "output": "16.666667"}, {"input": "3 3\n10 20 30\n1 2\n2 3\n3 1", "output": "13.333333"}, {"input": "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7", "output": "18.571429"}]
1,900
["dsu", "sortings"]
27
[{"input": "4 3\r\n10 20 30 40\r\n1 3\r\n2 3\r\n4 3\r\n", "output": "16.666667\r\n"}, {"input": "3 3\r\n10 20 30\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "13.333333\r\n"}, {"input": "7 8\r\n40 20 10 30 20 50 40\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n1 4\r\n5 7\r\n", "output": "18.571429\r\n"}, {"input": "10 14\r\n594...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read expected output with open(output_path, 'r') as f: expected_line = f.read().strip() try: expected = float(expected_line) except: print(0) return ...
true
177/D1
177
D1
Python 3
TESTS1
2
62
0
176969598
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' n,m,c=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) prefsum=[b[0]] for j...
12
154
1,331,200
141781115
n, m, c = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] k = 0 for i in range(0, (n-m) + 1): for j in range(0, m): if(j + k >= n): break a[j+k] = (a[j+k] + b[j]) % c k += 1 a = [str(x) for x in a] print(' '.join(a))
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
The first input line contains three integers n, m and c, separated by single spaces. The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message. The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limit...
Print n space-separated integers — the result of encrypting the original message.
null
In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.
[{"input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0"}, {"input": "3 1 5\n1 2 3\n4", "output": "0 1 2"}]
1,200
["brute force"]
12
[{"input": "4 3 2\r\n1 1 1 1\r\n1 1 1\r\n", "output": "0 1 1 0\r\n"}, {"input": "3 1 5\r\n1 2 3\r\n4\r\n", "output": "0 1 2\r\n"}, {"input": "5 2 7\r\n0 0 1 2 4\r\n3 5\r\n", "output": "3 1 2 3 2\r\n"}, {"input": "20 15 17\r\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\r\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15\r\n", ...
false
stdio
null
true
177/D1
177
D2
Python 3
TESTS2
2
92
204,800
4855542
n, m, c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = 0 for i in range(n): if i < m: s += b[i] if i > n - m: s -= b[i - n + m] a[i] = (a[i] + s) % c print(' '.join(str(i) for i in a))
12
154
1,740,800
193597553
n, m, c = map(int, input().split()) data = list(map(int, input().split())) keys = tuple(map(int, input().split())) for i in range(n - m + 1): for j in range(m): data[i + j] += keys[j] data[i + j] %= c print(*data)
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
The first input line contains three integers n, m and c, separated by single spaces. The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message. The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limit...
Print n space-separated integers — the result of encrypting the original message.
null
In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.
[{"input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0"}, {"input": "3 1 5\n1 2 3\n4", "output": "0 1 2"}]
1,200
["brute force"]
12
[{"input": "4 3 2\r\n1 1 1 1\r\n1 1 1\r\n", "output": "0 1 1 0\r\n"}, {"input": "3 1 5\r\n1 2 3\r\n4\r\n", "output": "0 1 2\r\n"}, {"input": "5 2 7\r\n0 0 1 2 4\r\n3 5\r\n", "output": "3 1 2 3 2\r\n"}, {"input": "20 15 17\r\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\r\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15\r\n", ...
false
stdio
null
true
351/B
351
B
Python 3
TESTS
2
62
307,200
4789312
from sys import * n=int(stdin.readline().strip()) s1=stdin.readline().strip() a=list(map(int,s1.split())) x=0 for i in range (n-1): for j in range (i+1,n): if a[i]>a[j]: x+=1 n=x//2 #print(x,n,' !!!') r=(x)*((0.5)**n) i=1 bi=3 eps=0.00000001 if x>0: while (x+2*i)*bi*((0.5)**(n+i))>eps: ...
25
156
2,048,000
219395895
import sys input = sys.stdin.readline MOD=10**9+7 if __name__ == '__main__': n=int(input()) arr=list(map(int, input().split())) cnt=0 for i in range(n-1): for j in range(i+1,n): if arr[j]<arr[i]: cnt +=1 print((cnt*2-(cnt%2))*1.0)
Codeforces Round 204 (Div. 1)
CF
2,013
1
256
Jeff and Furik
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace...
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
null
In the first test the sequence is already sorted, so the answer is 0.
[{"input": "2\n1 2", "output": "0.000000"}, {"input": "5\n3 5 2 4 1", "output": "13.000000"}]
1,900
["combinatorics", "dp", "probabilities"]
25
[{"input": "2\r\n1 2\r\n", "output": "0.000000\r\n"}, {"input": "5\r\n3 5 2 4 1\r\n", "output": "13.000000\r\n"}, {"input": "16\r\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\r\n", "output": "108.000000\r\n"}, {"input": "9\r\n1 7 8 5 3 4 6 9 2\r\n", "output": "33.000000\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "8.00...
false
stdio
import sys def read_float_from_line(line): line = line.strip() try: return float(line) except: return None def is_acceptable(ref, sub, abs_tol=1e-6, rel_tol=1e-6): if abs(ref - sub) <= abs_tol: return True denom = max(abs(ref), 1e-8) return abs(ref - sub) / denom <= rel...
true
412/D
412
D
Python 3
TESTS
2
62
0
6418045
n, m = list(map(int, input().split())) res = [i + 1 for i in range(n)] no = [0] * m for i in range(m): no[i] = list(map(int, input().split())) for j in range(n - 1): if res[i:i + 2] == no[i]: res[i], res[i + 1] = res[i + 1], res[i] for i in range(n - 1): if res[i:i + 2] in no: pr...
33
499
7,168,000
7104128
n, m = map(int,input().split()) g = [set() for i in range(n)] for i in range(m): a, b = map(int,input().split()) g[a-1].add(b-1) c = [0] * n for i in range(n): c[i] = i for i in range(n): j = i while (j > 0)and(c[j] in g[c[j - 1]]): c[j], c[j-1] = c[j-1], c[j] j -= 1 for i in c: ...
Coder-Strike 2014 - Round 1
CF
2,014
1
256
Giving Awards
The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else. Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ...
The first line contains space-separated integers n and m $$(2\leq n\leq3\cdot10^{4};1\leq m\leq min(10^{5},\frac{n(n-1)}{2}))$$ — the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), these integers indicate ...
Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on. If there are multiple correct orders, you are allowed to prin...
null
null
[{"input": "2 1\n1 2", "output": "2 1"}, {"input": "3 3\n1 2\n2 3\n3 1", "output": "2 1 3"}]
2,000
["dfs and similar"]
33
[{"input": "2 1\r\n1 2\r\n", "output": "2 1 \r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2 1 3 \r\n"}, {"input": "10 45\r\n10 5\r\n10 7\r\n6 1\r\n5 8\r\n3 5\r\n6 5\r\n1 2\r\n6 10\r\n2 9\r\n9 5\r\n4 1\r\n7 5\r\n1 8\r\n6 8\r\n10 9\r\n7 2\r\n7 9\r\n4 10\r\n7 3\r\n4 8\r\n10 3\r\n10 8\r\n2 10\r\n8 2\r\n4 2\r...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = set() for _ in range(m): a, b = map(int, f.readline().split()) ...
true
986/B
986
B
Python 3
TESTS
1
108
0
65581546
n=int(input()) a=[0] + list(map(int,input().split())) d={} for i in range(1,n+1): d[a[i]]=i ans=0 for i in range(1,n+1): if d[i]!=i: d[a[i]]=d[i] a[i]=i ans+=1 # print(a,ans,d) if (3*n - ans)%2==0: print("Petr") else: print("Um_nik")
24
296
86,425,600
216972507
n = int(input()) a = [int(x) - 1 for x in input().split()] ans = 0 for i in range(n): if a[i] == -1: continue ans ^= 1 x = i while x != -1: y = a[x] a[x] = -1 x = y if ans: print("Um_nik") else: print("Petr")
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
23/B
23
B
Python 3
TESTS
1
1,278
0
206891934
# LUOGU_RID: 111050227 from sys import stdin input = stdin.readline def check(num) : t = n - num return t >= num - 1 T = int(input()) for _ in range(T) : n = int(input()) l = 0 ; r = n while l < r : mid = l + r + 1 >> 1 if check(mid) : l = mid else : r = mi...
2
218
9,420,800
199473248
import sys input = lambda: sys.stdin.readline().rstrip() for _ in range(int(input())): N = int(input()) print(max(0,N-2))
Codeforces Beta Round 23
ICPC
2,010
2
256
Party
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of pe...
The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
null
null
[{"input": "1\n3", "output": "1"}]
1,600
["constructive algorithms", "graphs", "math"]
2
[{"input": "1\r\n3\r\n", "output": "1\r\n"}]
false
stdio
null
true
792/F
792
F
PyPy 3-64
TESTS
1
46
0
182577807
# https://codeforces.com/contest/792/problem/F?f0a28=2 spells = [] def main(): J = 0 n_queries, mana = input().split() n_queries = int(n_queries) mana = int(mana) for i in range(n_queries): kind, x, y = input().split() x = ((int(x) + J) % 10**6) + 1 ...
36
873
15,564,800
37535361
#!/usr/bin/env python3 # solution after hint # (instead of best hit/mana spell store convex hull of spells) # O(n^2) instead of O(n log n) [q, m] = map(int, input().strip().split()) qis = [tuple(map(int, input().strip().split())) for _ in range(q)] mod = 10**6 j = 0 spell_chull = [(0, 0)] # lower hull _/ def is_...
Educational Codeforces Round 18
ICPC
2,017
2
256
Mages and Monsters
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova ...
The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight. i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106). Using them you can restore queries this way: let j be the index...
For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise.
null
In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with...
[{"input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO"}]
3,100
["data structures", "geometry"]
36
[{"input": "3 100\r\n1 4 9\r\n2 19 49\r\n2 19 49\r\n", "output": "YES\r\nNO\r\n"}, {"input": "10 442006988299\r\n2 10 47\r\n1 9 83\r\n1 15 24\r\n2 19 47\r\n2 75 99\r\n2 85 23\r\n2 8 33\r\n2 9 82\r\n1 86 49\r\n2 71 49\r\n", "output": "NO\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "2 424978864039\r\n2 7 3...
false
stdio
null
true
397/B
397
B
PyPy 3
TESTS
1
139
0
71673582
def main(): temp = list(map(int, (input().split()))) n = temp[0] l = temp[1] r = temp[2] i = r while i >= l: remain = n % i if remain >= l and remain < r: print("Yes") return 0 i -= 1 print("No") return n = int(input()) for i in rang...
6
62
0
5924432
t = int(input()) for i in range(0, t) : n, l, r = [int(s) for s in input().split()] print('Yes' if n % l <= (r - l) * (n // l) else 'No')
Codeforces Round 232 (Div. 2)
CF
2,014
1
256
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
null
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
[{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}]
null
["constructive algorithms", "implementation", "math"]
6
[{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38...
false
stdio
null
true
23/B
23
B
Python 3
TESTS
1
1,340
2,662,400
40262778
t = int(input()) a = [] for i in range(0,t): a.append(int(input())-2) for i in range(0,t): print(a[i])
2
280
9,523,200
182431083
import sys input = sys.stdin.readline for _ in range(int(input())): print(max(0, int(input())-2))
Codeforces Beta Round 23
ICPC
2,010
2
256
Party
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of pe...
The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
null
null
[{"input": "1\n3", "output": "1"}]
1,600
["constructive algorithms", "graphs", "math"]
2
[{"input": "1\r\n3\r\n", "output": "1\r\n"}]
false
stdio
null
true
23/B
23
B
Python 3
TESTS
1
1,464
0
172994287
N = int(input()) for i in range(N): b = int(input()) print(b // 2)
2
342
102,400
206892050
# LUOGU_RID: 111050302 from sys import stdin input = stdin.readline T = int(input()) for _ in range(T) : n = int(input()) print(0 if n <= 2 else n - 2)
Codeforces Beta Round 23
ICPC
2,010
2
256
Party
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of pe...
The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
null
null
[{"input": "1\n3", "output": "1"}]
1,600
["constructive algorithms", "graphs", "math"]
2
[{"input": "1\r\n3\r\n", "output": "1\r\n"}]
false
stdio
null
true
23/B
23
B
PyPy 3
TESTS
1
466
9,625,600
110131849
import sys input=sys.stdin.readline t=int(input()) for you in range(t): n=int(input()) print(n-2)
2
404
6,656,000
108582736
import sys input = sys.stdin.readline for _ in range(int(input())): n=int(input()) if n>2: sys.stdout.write(str(n-2)+'\n') else: sys.stdout.write('0\n')
Codeforces Beta Round 23
ICPC
2,010
2
256
Party
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of pe...
The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
null
null
[{"input": "1\n3", "output": "1"}]
1,600
["constructive algorithms", "graphs", "math"]
2
[{"input": "1\r\n3\r\n", "output": "1\r\n"}]
false
stdio
null
true
23/B
23
B
Python 3
TESTS
1
528
6,656,000
11922651
num_tests = int(input()) results = num_tests * [None] for i in range(num_tests): n = int(input()) result = (n // 4) * 2 if n % 4 == 3: result += 1 results[i] = result print('\n'.join(map(str, results)))
2
436
8,908,800
141723547
import sys t = int(sys.stdin.readline()) for _ in range(t): print(str(max(0, int(sys.stdin.readline()) - 2)))
Codeforces Beta Round 23
ICPC
2,010
2
256
Party
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of pe...
The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
null
null
[{"input": "1\n3", "output": "1"}]
1,600
["constructive algorithms", "graphs", "math"]
2
[{"input": "1\r\n3\r\n", "output": "1\r\n"}]
false
stdio
null
true
986/B
986
B
PyPy 3
TESTS
1
77
0
172326219
n = int(input()) a = [int(x) for x in input().split()] cnt=0 for i in range(len(a)): if(i+1)==a[i]: cnt+=1 if cnt: print("Um_nik") else: print("Petr")
24
390
118,886,400
191157313
n=int(input()) arr=list(map(int,input().split())) arr=[el-1 for el in arr] ans=0 for i in range(n): if arr[i]==-1: continue ans^=1 x=i while x!=-1: y=arr[x] arr[x]=-1 x=y if ans: print("Um_nik") else: print("Petr")
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
208/E
208
E
PyPy 3-64
TESTS
0
92
0
221094016
import sys input = sys.stdin.readline def dfs(v, parent, tree, cnt): cnt[v] = 1 for u in tree[v]: if u != parent: cnt[v] += dfs(u, v, tree, cnt) return cnt[v] def main(): n = int(input()) parent = list(map(int, input().split())) tree = [[] for _ in range(n+1)] for ...
64
1,434
108,032,000
229646493
import sys import random input = sys.stdin.readline rd = random.randint(10 ** 9, 2 * 10 ** 9) n = int(input()) p = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(n): if p[i] == 0: continue g[p[i] - 1].append(i) q = int(input()) queries = [[] for _ in range(n)] queries2 = [[]...
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
351/B
351
B
PyPy 3-64
TESTS
1
62
0
222018915
n = int(input()) nums = list(map(int, input().split())) num_nxd = 0 for i in range(n-1): for j in range(i+1, n): if nums[j] < nums[i]: print(i, j) num_nxd += 1 if num_nxd == 0: print(0) elif num_nxd == 1: print(1) elif num_nxd % 2 == 0: print(2 * num_nxd) else: print((num_nxd-1) * 2...
25
218
307,200
97900420
n=int(input().strip()) p=[0]+list(map(int,input().split())) c=[0]*(n+1) def lowbit(x): return x&(-x) def add(x,v): while x<=n: c[x]+=v x+=lowbit(x) def get(x): ans=0 while x: ans+=c[x] x-=lowbit(x) return ans ans=0 for i in range(n,0,-1): ans+=get(p[i]) add(...
Codeforces Round 204 (Div. 1)
CF
2,013
1
256
Jeff and Furik
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace...
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
null
In the first test the sequence is already sorted, so the answer is 0.
[{"input": "2\n1 2", "output": "0.000000"}, {"input": "5\n3 5 2 4 1", "output": "13.000000"}]
1,900
["combinatorics", "dp", "probabilities"]
25
[{"input": "2\r\n1 2\r\n", "output": "0.000000\r\n"}, {"input": "5\r\n3 5 2 4 1\r\n", "output": "13.000000\r\n"}, {"input": "16\r\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\r\n", "output": "108.000000\r\n"}, {"input": "9\r\n1 7 8 5 3 4 6 9 2\r\n", "output": "33.000000\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "8.00...
false
stdio
import sys def read_float_from_line(line): line = line.strip() try: return float(line) except: return None def is_acceptable(ref, sub, abs_tol=1e-6, rel_tol=1e-6): if abs(ref - sub) <= abs_tol: return True denom = max(abs(ref), 1e-8) return abs(ref - sub) / denom <= rel...
true
171/C
171
C
PyPy 3
TESTS
1
248
0
68564637
s = [int(i) for i in input().split(" ")] ans = 0 for i in s[1:]: ans += i*i print(ans)
41
62
0
207105716
p= input ().split() #pieee t=0 for i in range (1,int (p [0])+1): t+=i*eval (p[i]) print (t)
April Fools Day Contest
ICPC
2,012
2
256
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread into the mixing bowl. 6....
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
Output a single integer.
null
null
[{"input": "4 1 2 3 4", "output": "30"}]
2,000
["*special", "implementation"]
41
[{"input": "4 1 2 3 4\r\n", "output": "30\r\n"}, {"input": "4 802 765 992 1\r\n", "output": "5312\r\n"}, {"input": "4 220 380 729 969\r\n", "output": "7043\r\n"}, {"input": "3 887 104 641\r\n", "output": "3018\r\n"}, {"input": "12 378 724 582 387 583 241 294 159 198 653 369 418\r\n", "output": "30198\r\n"}, {"input": "...
false
stdio
null
true
171/C
171
C
Python 3
TESTS
1
218
0
58235107
a, b, *r, c = input().split() print((int(b) + int (c)) * eval('*'.join(r)))
41
92
0
137353413
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-29 23:34:16 LastEditTime: 2021-11-29 23:36:05 Description: A Piece of Cake FilePath: CF171C.py ''' def func(): n, *lst = map(int, input().strip().split()) count = 0 for i in range(n): count += lst[i] * (i + 1) print(count) ...
April Fools Day Contest
ICPC
2,012
2
256
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread into the mixing bowl. 6....
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
Output a single integer.
null
null
[{"input": "4 1 2 3 4", "output": "30"}]
2,000
["*special", "implementation"]
41
[{"input": "4 1 2 3 4\r\n", "output": "30\r\n"}, {"input": "4 802 765 992 1\r\n", "output": "5312\r\n"}, {"input": "4 220 380 729 969\r\n", "output": "7043\r\n"}, {"input": "3 887 104 641\r\n", "output": "3018\r\n"}, {"input": "12 378 724 582 387 583 241 294 159 198 653 369 418\r\n", "output": "30198\r\n"}, {"input": "...
false
stdio
null
true
474/B
474
B
PyPy 3-64
TESTS
26
967
18,329,600
193017542
n=int(input()) a=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) l=[] k,t=0,0 for i in range(n): k+=a[i] l.append(k) for i in range(m): if q[i]<l[t]: t=0 elif q[i]==l[t]: print(t+1) break while q[i]>l[t]: t+=1 print(t+1)
38
155
14,438,400
196309371
#**************************************************** #***************Shariar Hasan************************ #**************CSE CU Batch 18*********************** #**************************************************** #import os #import sys from math import * #import re #import random #sys.set_int_max_str_digits(int(1e9...
Codeforces Round 271 (Div. 2)
CF
2,014
1
256
Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile. The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmo...
Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.
null
For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth ...
[{"input": "5\n2 7 3 4 9\n3\n1 25 11", "output": "1\n5\n3"}]
1,200
["binary search", "implementation"]
38
[{"input": "5\r\n2 7 3 4 9\r\n3\r\n1 25 11\r\n", "output": "1\r\n5\r\n3\r\n"}]
false
stdio
null
true
47/D
47
D
Python 3
TESTS
0
60
0
212685560
def is_consistent(code, responses): for i, response in enumerate(responses): count = sum(a == b for a, b in zip(code, response)) if count != responses[i]: return False return True def generate_codes(n, code, index, responses, count_variants): if index == n: if is_consist...
26
3,648
10,444,800
156930466
import sys readline=sys.stdin.readline def Pop_Count(N): r=(N&0x5555555555555555)+((N>>1)&0x5555555555555555) r=(r&0x3333333333333333)+((r>>2)&0x3333333333333333) r=(r&0x0f0f0f0f0f0f0f0f)+((r>>4)&0x0f0f0f0f0f0f0f0f) r=(r&0x00ff00ff00ff00ff)+((r>>8)&0x00ff00ff00ff00ff) r=(r&0x0000ffff0000ffff)+((r>>...
Codeforces Beta Round 44 (Div. 2)
CF
2,010
5
256
Safe
Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unluc...
The first input line contains two integers n and m (6 ≤ n ≤ 35, 1 ≤ m ≤ 10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow m lines, each containing space-separated si and ci which correspondingly indicate Vasya’s attempt (a line containing n numbers which are 0 o...
Print the single number which indicates how many possible code variants that do not contradict the m system responses are left.
null
null
[{"input": "6 2\n000000 2\n010100 4", "output": "6"}, {"input": "6 3\n000000 2\n010100 4\n111100 0", "output": "0"}, {"input": "6 3\n000000 2\n010100 4\n111100 2", "output": "1"}]
2,200
["brute force"]
26
[{"input": "6 2\r\n000000 2\r\n010100 4\r\n", "output": "6\r\n"}, {"input": "6 3\r\n000000 2\r\n010100 4\r\n111100 0\r\n", "output": "0\r\n"}, {"input": "6 3\r\n000000 2\r\n010100 4\r\n111100 2\r\n", "output": "1\r\n"}, {"input": "6 1\r\n101011 2\r\n", "output": "15\r\n"}, {"input": "7 2\r\n1011111 2\r\n1001111 1\r\n",...
false
stdio
null
true
509/C
509
C
Python 3
TESTS
0
93
307,200
89815762
n = int(input()) last=0 for i in range(n): a = int(input()) s='' val=0 if i==0: for j in range(a): s+='1' last = int(s) print(last) else: for j in range(a): s += '1' val = int(s) while (val<=last): val*=10 l...
21
233
2,560,000
230063199
n = int(input()) def get_sum(x): result = 0 while x > 0: d, m = divmod(x, 10) result += m x = d return result def dec(x): t = x mult = 1 while True: d, m = divmod(x, 10) if m != 0: return t + (10 - m) * mult x = d mult *= 10 ...
Codeforces Round 289 (Div. 2, ACM ICPC Rules)
ICPC
2,015
2
256
Sums of Digits
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possibl...
The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn  — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers witho...
null
null
[{"input": "3\n1\n2\n3", "output": "1\n2\n3"}, {"input": "3\n3\n2\n1", "output": "3\n11\n100"}]
2,000
["dp", "greedy", "implementation"]
21
[{"input": "3\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "3\r\n3\r\n2\r\n1\r\n", "output": "3\r\n11\r\n100\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n1\r\n", "output": "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n"}, {"input": "10\r\n8\r\n8\r\n5\r\n1\r\n2\r\n7\r\n3\r\n...
false
stdio
null
true
598/E
598
E
PyPy 3-64
TESTS
1
31
0
201934756
# https://codeforces.com/contest/598/problem/E for _ in range(int(input())): n, m, k = map(int, input().split()) cout = 0 while k > 0 and n * m != k: if n > m: n, m = m, n # n <= m y_coupe = k // n if y_coupe > 0: k -= y_coupe * n m -= y_coupe ...
5
482
9,113,600
175317754
from sys import stdin input=lambda :stdin.readline()[:-1] dp=[[[10**9]*51 for i in range(31)] for i in range(31)] for n in range(1,31): for m in range(1,31): for k in range(51): if k==0: dp[n][m][k]=0 continue if n*m<k: continue if n*m==k: dp[n][m][k]=0 ...
Educational Codeforces Round 1
ICPC
2,015
2
256
Chocolate Bar
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically....
The first line of the input contains a single integer t (1 ≤ t ≤ 40910) — the number of values n, m and k to process. Each of the next t lines contains three integers n, m and k (1 ≤ n, m ≤ 30, 1 ≤ k ≤ min(n·m, 50)) — the dimensions of the chocolate bar and the number of squares you want to eat respectively.
For each n, m and k print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly k squares.
null
In the first query of the sample one needs to perform two breaks: - to split 2 × 2 bar into two pieces of 2 × 1 (cost is 22 = 4), - to split the resulting 2 × 1 into two 1 × 1 pieces (cost is 12 = 1). In the second query of the sample one wants to eat 3 unit squares. One can use exactly the same strategy as in the fi...
[{"input": "4\n2 2 1\n2 2 3\n2 2 2\n2 2 4", "output": "5\n5\n4\n0"}]
2,000
["brute force", "dp"]
5
[{"input": "4\r\n2 2 1\r\n2 2 3\r\n2 2 2\r\n2 2 4\r\n", "output": "5\r\n5\r\n4\r\n0\r\n"}]
false
stdio
null
true
29/E
29
E
PyPy 3-64
TESTS
0
124
102,400
213880873
import sys from collections import deque readline = sys.stdin.readline N, M = [int(w) for w in readline().split()] city = [[] for _ in range(N + 1)] for _ in range(M): u, v = [int(w) for w in readline().split()] city[u].append(v) city[v].append(u) seen = {(1, N, 0): (-1, -1, -1)} que = deque([(1, N, 0)]) ...
56
872
71,475,200
213890023
import sys from collections import deque readline = sys.stdin.readline N, M = [int(w) for w in readline().split()] city = [[] for _ in range(N + 1)] edges = [] for _ in range(M): u, v = [int(w) for w in readline().split()] city[u].append(v) city[v].append(u) edges.append((u, v)) def gen_dists(node: in...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
1
256
Quarrel
Friends Alex and Bob live in Bertown. In this town there are n crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads number n. One day Alex and Bob had a big quarrel, and they refused to see each other. It occ...
The first line contains two integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ 10000) — the amount of crossroads and the amount of roads. Each of the following m lines contains two integers — the numbers of crossroads connected by the road. It is guaranteed that no road connects a crossroads with itself and no two crossroads are c...
If the required routes don't exist, output -1. Otherwise, the first line should contain integer k — the length of shortest routes (the length of the route is the amount of roads in it). The next line should contain k + 1 integers — Bob's route, i.e. the numbers of k + 1 crossroads passed by Bob. The last line should co...
null
null
[{"input": "2 1\n1 2", "output": "1\n1 2\n2 1"}, {"input": "7 5\n1 2\n2 7\n7 6\n2 3\n3 4", "output": "-1"}, {"input": "7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5", "output": "6\n1 2 3 4 3 2 7\n7 6 7 2 1 5 1"}]
2,400
["graphs", "shortest paths"]
56
[{"input": "2 1\r\n1 2\r\n", "output": "1\r\n1 2 \r\n2 1 \r\n"}, {"input": "7 5\r\n1 2\r\n2 7\r\n7 6\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "7 6\r\n1 2\r\n2 7\r\n7 6\r\n2 3\r\n3 4\r\n1 5\r\n", "output": "6\r\n1 2 3 4 3 2 7 \r\n7 6 7 2 1 5 1 \r\n"}, {"input": "6 10\r\n3 6\r\n3 5\r\n1 3\r\n2 6\r\n5 4\r\n6 4\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: input_lines = [line.strip() for line in f] if not input_lines: print(0) return n, m = map(int, input_lines[0].split()...
true
29/E
29
E
PyPy 3-64
TESTS
0
92
614,400
196078778
from collections import deque n, m = map(int, input().split()) edge = [[] for _ in range(n+1)] for _ in range(m): u, v = map(int, input().split()) edge[u].append(v) edge[v].append(u) pos = [[[-1]*2 for _ in range(n+1)] for _ in range(n+1)] fromx = [[[-1]*2 for _ in range(n+1)] for _ in range(n+1)] fromy ...
56
872
71,475,200
213890023
import sys from collections import deque readline = sys.stdin.readline N, M = [int(w) for w in readline().split()] city = [[] for _ in range(N + 1)] edges = [] for _ in range(M): u, v = [int(w) for w in readline().split()] city[u].append(v) city[v].append(u) edges.append((u, v)) def gen_dists(node: in...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
1
256
Quarrel
Friends Alex and Bob live in Bertown. In this town there are n crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads number n. One day Alex and Bob had a big quarrel, and they refused to see each other. It occ...
The first line contains two integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ 10000) — the amount of crossroads and the amount of roads. Each of the following m lines contains two integers — the numbers of crossroads connected by the road. It is guaranteed that no road connects a crossroads with itself and no two crossroads are c...
If the required routes don't exist, output -1. Otherwise, the first line should contain integer k — the length of shortest routes (the length of the route is the amount of roads in it). The next line should contain k + 1 integers — Bob's route, i.e. the numbers of k + 1 crossroads passed by Bob. The last line should co...
null
null
[{"input": "2 1\n1 2", "output": "1\n1 2\n2 1"}, {"input": "7 5\n1 2\n2 7\n7 6\n2 3\n3 4", "output": "-1"}, {"input": "7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5", "output": "6\n1 2 3 4 3 2 7\n7 6 7 2 1 5 1"}]
2,400
["graphs", "shortest paths"]
56
[{"input": "2 1\r\n1 2\r\n", "output": "1\r\n1 2 \r\n2 1 \r\n"}, {"input": "7 5\r\n1 2\r\n2 7\r\n7 6\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "7 6\r\n1 2\r\n2 7\r\n7 6\r\n2 3\r\n3 4\r\n1 5\r\n", "output": "6\r\n1 2 3 4 3 2 7 \r\n7 6 7 2 1 5 1 \r\n"}, {"input": "6 10\r\n3 6\r\n3 5\r\n1 3\r\n2 6\r\n5 4\r\n6 4\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: input_lines = [line.strip() for line in f] if not input_lines: print(0) return n, m = map(int, input_lines[0].split()...
true
598/E
598
E
PyPy 3-64
TESTS
1
62
0
194358928
t = int(input()) for i in range(t): n,m,k = map(int,input().split()) ans = 0 if k == n*m: print(0) continue while k != 0: if n < m: cnt = k//n if cnt == 0: ans += n*n+1 break ans += n*n k -= n*cnt m -= cnt else: cnt = k//m if cnt ==...
5
794
30,105,600
128888073
from collections import defaultdict, deque, Counter from heapq import heapify, heappop, heappush import math from copy import deepcopy from itertools import combinations, permutations, product, combinations_with_replacement from bisect import bisect_left, bisect_right import sys def input(): return sys.stdin.readl...
Educational Codeforces Round 1
ICPC
2,015
2
256
Chocolate Bar
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically....
The first line of the input contains a single integer t (1 ≤ t ≤ 40910) — the number of values n, m and k to process. Each of the next t lines contains three integers n, m and k (1 ≤ n, m ≤ 30, 1 ≤ k ≤ min(n·m, 50)) — the dimensions of the chocolate bar and the number of squares you want to eat respectively.
For each n, m and k print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly k squares.
null
In the first query of the sample one needs to perform two breaks: - to split 2 × 2 bar into two pieces of 2 × 1 (cost is 22 = 4), - to split the resulting 2 × 1 into two 1 × 1 pieces (cost is 12 = 1). In the second query of the sample one wants to eat 3 unit squares. One can use exactly the same strategy as in the fi...
[{"input": "4\n2 2 1\n2 2 3\n2 2 2\n2 2 4", "output": "5\n5\n4\n0"}]
2,000
["brute force", "dp"]
5
[{"input": "4\r\n2 2 1\r\n2 2 3\r\n2 2 2\r\n2 2 4\r\n", "output": "5\r\n5\r\n4\r\n0\r\n"}]
false
stdio
null
true
598/E
598
E
PyPy 3-64
TESTS
1
77
4,198,400
194357463
t = int(input()) for i in range(t): n,m,k = map(int,input().split()) ans = float("inf") for bit in range(10): nn,mm = n,m left = k tmp = 0 for i in range(10): if (bit>>i) & 1: cnt = left // nn if cnt == mm: break if cnt != 0: nn,mm = nn, mm-cnt lef...
5
1,778
11,878,400
218464936
def relaxMin(a, b): return min(a, b) def Eval(n, m, k): if n > m: n, m = m, n if k == 0: return 0 if n * m == k: return 0 if n * m < k: return float('inf') if dp[n][m][k] >= 0: return dp[n][m][k] val = float('inf') cost = m ** 2 for tn in range...
Educational Codeforces Round 1
ICPC
2,015
2
256
Chocolate Bar
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically....
The first line of the input contains a single integer t (1 ≤ t ≤ 40910) — the number of values n, m and k to process. Each of the next t lines contains three integers n, m and k (1 ≤ n, m ≤ 30, 1 ≤ k ≤ min(n·m, 50)) — the dimensions of the chocolate bar and the number of squares you want to eat respectively.
For each n, m and k print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly k squares.
null
In the first query of the sample one needs to perform two breaks: - to split 2 × 2 bar into two pieces of 2 × 1 (cost is 22 = 4), - to split the resulting 2 × 1 into two 1 × 1 pieces (cost is 12 = 1). In the second query of the sample one wants to eat 3 unit squares. One can use exactly the same strategy as in the fi...
[{"input": "4\n2 2 1\n2 2 3\n2 2 2\n2 2 4", "output": "5\n5\n4\n0"}]
2,000
["brute force", "dp"]
5
[{"input": "4\r\n2 2 1\r\n2 2 3\r\n2 2 2\r\n2 2 4\r\n", "output": "5\r\n5\r\n4\r\n0\r\n"}]
false
stdio
null
true
598/E
598
E
PyPy 3
TESTS
1
93
22,118,400
128886561
from collections import defaultdict, deque, Counter from heapq import heapify, heappop, heappush import math from copy import deepcopy from itertools import combinations, permutations, product, combinations_with_replacement from bisect import bisect_left, bisect_right import sys def input(): return sys.stdin.readl...
5
482
9,113,600
175317754
from sys import stdin input=lambda :stdin.readline()[:-1] dp=[[[10**9]*51 for i in range(31)] for i in range(31)] for n in range(1,31): for m in range(1,31): for k in range(51): if k==0: dp[n][m][k]=0 continue if n*m<k: continue if n*m==k: dp[n][m][k]=0 ...
Educational Codeforces Round 1
ICPC
2,015
2
256
Chocolate Bar
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically....
The first line of the input contains a single integer t (1 ≤ t ≤ 40910) — the number of values n, m and k to process. Each of the next t lines contains three integers n, m and k (1 ≤ n, m ≤ 30, 1 ≤ k ≤ min(n·m, 50)) — the dimensions of the chocolate bar and the number of squares you want to eat respectively.
For each n, m and k print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly k squares.
null
In the first query of the sample one needs to perform two breaks: - to split 2 × 2 bar into two pieces of 2 × 1 (cost is 22 = 4), - to split the resulting 2 × 1 into two 1 × 1 pieces (cost is 12 = 1). In the second query of the sample one wants to eat 3 unit squares. One can use exactly the same strategy as in the fi...
[{"input": "4\n2 2 1\n2 2 3\n2 2 2\n2 2 4", "output": "5\n5\n4\n0"}]
2,000
["brute force", "dp"]
5
[{"input": "4\r\n2 2 1\r\n2 2 3\r\n2 2 2\r\n2 2 4\r\n", "output": "5\r\n5\r\n4\r\n0\r\n"}]
false
stdio
null
true
47/D
47
D
Python 3
TESTS
0
60
0
230675950
from itertools import product n, m = map(int, input().split()) p = set(product('01', repeat=n)) for i in range(m): s, c = input().split() c = int(c) v = set() for c in p: cor = sum(s[i] == c[i] for i in range(n)) if cor == c: v.add(c) p = v print(len(p))
26
466
3,686,400
181406585
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m = map(int, input().split()) pow2 = [1] for _ in range(20): pow2.append(2 * pow2[-1]) n1, n2 = n // 2, (n + 1) // 2 x, y, z = [], [], [] for _ in range(m): s, c = list(input().rstrip().decode...
Codeforces Beta Round 44 (Div. 2)
CF
2,010
5
256
Safe
Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unluc...
The first input line contains two integers n and m (6 ≤ n ≤ 35, 1 ≤ m ≤ 10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow m lines, each containing space-separated si and ci which correspondingly indicate Vasya’s attempt (a line containing n numbers which are 0 o...
Print the single number which indicates how many possible code variants that do not contradict the m system responses are left.
null
null
[{"input": "6 2\n000000 2\n010100 4", "output": "6"}, {"input": "6 3\n000000 2\n010100 4\n111100 0", "output": "0"}, {"input": "6 3\n000000 2\n010100 4\n111100 2", "output": "1"}]
2,200
["brute force"]
26
[{"input": "6 2\r\n000000 2\r\n010100 4\r\n", "output": "6\r\n"}, {"input": "6 3\r\n000000 2\r\n010100 4\r\n111100 0\r\n", "output": "0\r\n"}, {"input": "6 3\r\n000000 2\r\n010100 4\r\n111100 2\r\n", "output": "1\r\n"}, {"input": "6 1\r\n101011 2\r\n", "output": "15\r\n"}, {"input": "7 2\r\n1011111 2\r\n1001111 1\r\n",...
false
stdio
null
true
149/D
149
D
Python 3
TESTS
1
62
0
218131269
# LUOGU_RID: 120094842 print(12)### ## ##
38
780
38,092,800
203670327
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 # 这道题 # 难点 1:想到用区间dp # 难点 2:不同状态之间的转移以及计算 def main()...
Codeforces Round 106 (Div. 2)
CF
2,012
2
256
Coloring Brackets
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
The first line contains the single string s (2 ≤ |s| ≤ 700) which represents a correct bracket sequence.
Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109 + 7).
null
Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below. The two ways of coloring shown below are incorrect.
[{"input": "(())", "output": "12"}, {"input": "(()())", "output": "40"}, {"input": "()", "output": "4"}]
1,900
["dp"]
38
[{"input": "(())\r\n", "output": "12\r\n"}, {"input": "(()())\r\n", "output": "40\r\n"}, {"input": "()\r\n", "output": "4\r\n"}, {"input": "((()))\r\n", "output": "36\r\n"}, {"input": "()(())\r\n", "output": "42\r\n"}, {"input": "()()()\r\n", "output": "48\r\n"}, {"input": "(())(())\r\n", "output": "126\r\n"}, {"input"...
false
stdio
null
true
908/G
908
G
Python 3
PRETESTS
1
1,122
5,529,600
33790693
n = int(input()) s = 0 for i in range(1,n+1): x = list(str(i)) # print(x) l = sorted(x) n = int(''.join(map(str,l))) s += n print(s)
20
77
0
113281106
# Problem G num = input() num_list = [] for i in range(len(num)): num_list.append(int(num[i])) myMod = (10 ** 9) + 7 length = len(num_list) f = [0] * (length + 1) t = [1] * (length + 1) for i in range(length): f[i+1] = (f[i] * 10 + 1) % myMod t[i+1] = (t[i] * 10) % myMod ans = 0 for i in range(1, 10): dp...
Good Bye 2017
CF
2,017
2
256
New Year and Original Order
Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555. Given a number X, compute $$\sum_{1 \leq k \leq X} S(k)$$ modulo 109 + 7.
The first line of input will contain the integer X (1 ≤ X ≤ 10700).
Print a single integer, the answer to the question.
null
The first few values of S are 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 12. The sum of these values is 195.
[{"input": "21", "output": "195"}, {"input": "345342", "output": "390548434"}]
2,800
["dp", "math"]
20
[{"input": "21\r\n", "output": "195\r\n"}, {"input": "345342\r\n", "output": "390548434\r\n"}, {"input": "9438174368\r\n", "output": "419438859\r\n"}, {"input": "33340691714056185860211260984431382156326935244157\r\n", "output": "683387308\r\n"}, {"input": "60659389952427965488066632743799525603106037644498358605868947...
false
stdio
null
true
171/C
171
C
Python 3
TESTS
1
186
0
74875321
a,b,c,d,e=map(int,input().split()) print(a*2+b*1+c*4+d*3+e*1)
41
92
0
173781945
a=list(map(int,input().split())) ans=0 for num in range(0,len(a)): ans=ans+a[num]*num print(ans)
April Fools Day Contest
ICPC
2,012
2
256
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread into the mixing bowl. 6....
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
Output a single integer.
null
null
[{"input": "4 1 2 3 4", "output": "30"}]
2,000
["*special", "implementation"]
41
[{"input": "4 1 2 3 4\r\n", "output": "30\r\n"}, {"input": "4 802 765 992 1\r\n", "output": "5312\r\n"}, {"input": "4 220 380 729 969\r\n", "output": "7043\r\n"}, {"input": "3 887 104 641\r\n", "output": "3018\r\n"}, {"input": "12 378 724 582 387 583 241 294 159 198 653 369 418\r\n", "output": "30198\r\n"}, {"input": "...
false
stdio
null
true
171/C
171
C
PyPy 3
TESTS
1
186
0
111647518
cases=list(map(int,input().split())) cnt=0 for i in cases[1:]: cnt+=i*i print(cnt)
41
92
0
205826256
a = list(map(int, input().split())) ans = 0 for i in range(1, len(a)) : ans += i*a[i] print(ans)
April Fools Day Contest
ICPC
2,012
2
256
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread into the mixing bowl. 6....
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
Output a single integer.
null
null
[{"input": "4 1 2 3 4", "output": "30"}]
2,000
["*special", "implementation"]
41
[{"input": "4 1 2 3 4\r\n", "output": "30\r\n"}, {"input": "4 802 765 992 1\r\n", "output": "5312\r\n"}, {"input": "4 220 380 729 969\r\n", "output": "7043\r\n"}, {"input": "3 887 104 641\r\n", "output": "3018\r\n"}, {"input": "12 378 724 582 387 583 241 294 159 198 653 369 418\r\n", "output": "30198\r\n"}, {"input": "...
false
stdio
null
true
171/C
171
C
Python 3
TESTS
1
92
4,608,000
25945668
a = list(map(int,input().split())) print(2*(sum(a)+1))
41
92
0
206951318
# /** # * author: brownfox2k6 # * created: 23/05/2023 20:41:01 Hanoi, Vietnam # **/ print(sum(i*j for i,j in enumerate(map(int, input().split()), 0)))
April Fools Day Contest
ICPC
2,012
2
256
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread into the mixing bowl. 6....
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
Output a single integer.
null
null
[{"input": "4 1 2 3 4", "output": "30"}]
2,000
["*special", "implementation"]
41
[{"input": "4 1 2 3 4\r\n", "output": "30\r\n"}, {"input": "4 802 765 992 1\r\n", "output": "5312\r\n"}, {"input": "4 220 380 729 969\r\n", "output": "7043\r\n"}, {"input": "3 887 104 641\r\n", "output": "3018\r\n"}, {"input": "12 378 724 582 387 583 241 294 159 198 653 369 418\r\n", "output": "30198\r\n"}, {"input": "...
false
stdio
null
true
598/E
598
E
Python 3
TESTS
1
15
0
202355620
for _ in range(int(input())): n,m,k=map(int,input().split()) if k%2!=0: print(min(n*n+1,m*m+1)) else: z=min(n*n+1,m*m+1) for i in range(1,k+1): if k%i==0: x=k//i y=i if y!=n and x!=m: z=min(z,m*m+y*y,n*n+...
5
794
30,105,600
128888073
from collections import defaultdict, deque, Counter from heapq import heapify, heappop, heappush import math from copy import deepcopy from itertools import combinations, permutations, product, combinations_with_replacement from bisect import bisect_left, bisect_right import sys def input(): return sys.stdin.readl...
Educational Codeforces Round 1
ICPC
2,015
2
256
Chocolate Bar
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically....
The first line of the input contains a single integer t (1 ≤ t ≤ 40910) — the number of values n, m and k to process. Each of the next t lines contains three integers n, m and k (1 ≤ n, m ≤ 30, 1 ≤ k ≤ min(n·m, 50)) — the dimensions of the chocolate bar and the number of squares you want to eat respectively.
For each n, m and k print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly k squares.
null
In the first query of the sample one needs to perform two breaks: - to split 2 × 2 bar into two pieces of 2 × 1 (cost is 22 = 4), - to split the resulting 2 × 1 into two 1 × 1 pieces (cost is 12 = 1). In the second query of the sample one wants to eat 3 unit squares. One can use exactly the same strategy as in the fi...
[{"input": "4\n2 2 1\n2 2 3\n2 2 2\n2 2 4", "output": "5\n5\n4\n0"}]
2,000
["brute force", "dp"]
5
[{"input": "4\r\n2 2 1\r\n2 2 3\r\n2 2 2\r\n2 2 4\r\n", "output": "5\r\n5\r\n4\r\n0\r\n"}]
false
stdio
null
true
677/C
677
C
Python 3
TESTS
0
15
0
232376718
MOD = 10**9 + 7 def convert_to_num(char): if char.isdigit(): return int(char) elif char.isupper(): return ord(char) - ord('A') + 10 elif char.islower(): return ord(char) - ord('a') + 36 elif char == '-': return 62 elif char == '_': return 63 def count_pairs(...
46
93
5,120,000
18198069
def count(num): string = bin(num)[2:] return string.count('0') + 6 - len(string) key = [3 ** count(x) for x in range(64)] dic = {} for i in range(10): dic[chr(ord('0') + i)] = key[i] for i in range(26): dic[chr(ord('A') + i)] = key[i + 10] for i in range(26): dic[chr(ord('a') + i)] = key[i + 36] d...
Codeforces Round 355 (Div. 2)
CF
2,016
1
256
Vanya and Label
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bit...
The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.
Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.
null
For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia. In the first sample, there are 3 possible solutions: 1. z&_ = 61&63 = 61 = z 2. _&z = 63&61 = 61 = z 3. z&z = 61&61 = 61 = z
[{"input": "z", "output": "3"}, {"input": "V_V", "output": "9"}, {"input": "Codeforces", "output": "130653412"}]
1,500
["bitmasks", "combinatorics", "implementation", "strings"]
46
[{"input": "z\r\n", "output": "3\r\n"}, {"input": "V_V\r\n", "output": "9\r\n"}, {"input": "Codeforces\r\n", "output": "130653412\r\n"}, {"input": "zHsIINYjVtU71kmM9E\r\n", "output": "130312847\r\n"}, {"input": "fRRNAdMvLFTX21T0FG5gyn7NG0SaIvzGG_g_SO\r\n", "output": "547121709\r\n"}, {"input": "Lb1T3sA4BcTx4KAgLIsl-dNO...
false
stdio
null
true
811/E
811
E
Python 3
TESTS
1
46
204,800
27584672
#!/usr/bin/python3 import sys def get_str_deb(): yield list(int(x) for x in "4 5 4".split()) yield list(int(x) for x in "1 1 1 1 1".split()) yield list(int(x) for x in "1 2 2 3 3".split()) yield list(int(x) for x in "1 1 1 2 5".split()) yield list(int(x) for x in "4 4 5 5 5".split()) yield list...
120
1,653
111,513,600
221893861
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * n + v def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): s, t = get_root(s), get_root(t) i...
Codeforces Round 416 (Div. 2)
CF
2,017
2
256
Vladik and Entertaining Flags
In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix n × m which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set the...
First line contains three space-separated integers n, m, q (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 105) — dimensions of flag matrix and number of segments respectively. Each of next n lines contains m space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106. Each of ne...
For each segment print the result on the corresponding line.
null
Partitioning on components for every segment from first test case:
[{"input": "4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5", "output": "6\n7\n3\n4"}]
2,600
["data structures", "dsu", "graphs"]
120
[{"input": "4 5 4\r\n1 1 1 1 1\r\n1 2 2 3 3\r\n1 1 1 2 5\r\n4 4 5 5 5\r\n1 5\r\n2 5\r\n1 2\r\n4 5\r\n", "output": "6\r\n7\r\n3\r\n4\r\n"}, {"input": "5 2 9\r\n6 1\r\n6 6\r\n6 6\r\n6 6\r\n5 6\r\n1 2\r\n1 1\r\n1 2\r\n1 2\r\n1 2\r\n1 1\r\n1 1\r\n1 2\r\n1 1\r\n", "output": "3\r\n2\r\n3\r\n3\r\n3\r\n2\r\n2\r\n3\r\n2\r\n"}, ...
false
stdio
null
true
247/D
250
D
Python 3
TESTS
1
92
0
11597490
import sys from itertools import * from math import * def solve(): n,m,leftbank,rightbank = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = list(map(int, input().split())) dist = rightbank - leftbank smallx = leftbank leftbest, rightbest,...
33
1,122
11,878,400
13858446
from math import sqrt,fabs def dist(x1, y1, x2, y2): return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2)) def calcOptimumRightPoint(startX, startY): l = float("inf") idx = -1 for i in range(len(B)): d = dist(startX, startY, b, B[i]) + L[i] if d <= l: l = d i...
CROC-MBTU 2012, Final Round
CF
2,012
1
256
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = a and x = b (0 < a < b). The west village lies in a steppe at point O = (0...
The first line contains integers n, m, a, b (1 ≤ n, m ≤ 105, 0 < a < b < 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≤ 106). The third line contains m integers in the ascending order: the i-th integer determines the coord...
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
null
null
[{"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2"}]
1,900
[]
33
[{"input": "3 2 3 5\r\n-2 -1 4\r\n-1 2\r\n7 3\r\n", "output": "2 2"}, {"input": "1 1 10 20\r\n5\r\n-5\r\n1\r\n", "output": "1 1"}, {"input": "2 2 1 2\r\n-1 10\r\n8 9\r\n3 7\r\n", "output": "1 1"}, {"input": "10 20 50 60\r\n-96 -75 32 37 42 43 44 57 61 65\r\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94...
false
stdio
null
true
678/E
678
E
PyPy 3
TESTS
0
576
147,865,600
148038367
n = int(input()) a = [[0]*(n+1) for i in range(n+1)] for i in range(n): j = 0 for v in map(float, input().split()): a[i][j] = v j += 1 f = [[0]*20 for i in range(1<<20)] f[1][1] = 1 for k in range(1, 1<<n): for i in range(n): if (1<<i) & k != 0: for j in range(n): ...
41
1,419
80,793,600
126740185
from decimal import * ar = [list(map(float, input().split())) for i in range(int(input()))] dp = [[0 for i in range(1 << 18)] for j in range(18)] n, ans = len(ar), 0 dp[0][(1 << n) - 1] = 1 for i in range((1 << n) - 1, 0, -1): for j in range(n): if i & (1 << j) == 0: continue for k in ra...
Educational Codeforces Round 13
ICPC
2,016
2.5
256
Another Sith Tournament
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b...
The first line contains a single integer n (1 ≤ n ≤ 18) — the number of participants of the Sith Tournament. Each of the next n lines contains n real numbers, which form a matrix pij (0 ≤ pij ≤ 1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel. The elements on the main d...
Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10 - 6.
null
null
[{"input": "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0", "output": "0.680000000000000"}]
2,200
["bitmasks", "dp", "math", "probabilities"]
41
[{"input": "3\r\n0.0 0.5 0.8\r\n0.5 0.0 0.4\r\n0.2 0.6 0.0\r\n", "output": "0.680000000000000\n"}, {"input": "1\r\n0.0\r\n", "output": "1.000000000000000\n"}, {"input": "2\r\n0.00 0.75\r\n0.25 0.00\r\n", "output": "0.750000000000000\n"}, {"input": "4\r\n0.0 0.6 0.5 0.4\r\n0.4 0.0 0.3 0.8\r\n0.5 0.7 0.0 0.5\r\n0.6 0.2 0...
false
stdio
import sys def read_value(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] if len(lines) != 1: return None try: return float(lines[0]) except: return None def main(): input_path = sys.argv[1] correct_output_path ...
true
145/C
145
C
PyPy 3
TESTS
0
122
20,172,800
123056951
import math def main(): n, k = map(int, input().split()) a = list(map(int, input().split())) # A = [4,4,4,4,7,7,7,44,44,44,44,1,1,1,1,1,1,1,1,1,1,123,123,123,123,123,123,123,12,3,12,3,12,1,13,123,123,123,123,123,123,12,3,12,3,12,1,1,2,12,1] # k = 24 Ocurrencias = [] print( Calcular(a,k)) Ocu...
58
872
22,937,600
70819857
import sys MOD = 10 ** 9 + 7 def is_lucky(n): n = str(n) return n.count('4') + n.count('7') == len(n) def get_inv(n): return pow(n, MOD - 2, MOD) def c(n, k): if n < k or k < 0: return 0 global fact, rfact return (fact[n] * rfact[k] * rfact[n - k]) % MOD fact = [1] rfact = [1] for i ...
Codeforces Round 104 (Div. 1)
CF
2,012
2
256
Lucky Subsequence
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting of n integers. The subsequence of the sequence a is such subseque...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n integers ai (1 ≤ ai ≤ 109) — the sequence a.
On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109 + 7).
null
In the first sample all 3 subsequences of the needed length are considered lucky. In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
[{"input": "3 2\n10 10 10", "output": "3"}, {"input": "4 2\n4 4 7 7", "output": "4"}]
2,100
["combinatorics", "dp", "math"]
58
[{"input": "3 2\r\n10 10 10\r\n", "output": "3\r\n"}, {"input": "4 2\r\n4 4 7 7\r\n", "output": "4\r\n"}, {"input": "7 4\r\n1 2 3 4 5 6 7\r\n", "output": "35\r\n"}, {"input": "7 4\r\n7 7 7 7 7 7 7\r\n", "output": "0\r\n"}, {"input": "10 1\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "10\r\n"}, {"input": "10 7\r\n1 2 3 4 5 6...
false
stdio
null
true
149/D
149
D
Python 3
TESTS
0
60
0
219448747
# LUOGU_RID: 121658616 print("4")
38
1,090
111,513,600
181683625
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(l, r, c1, c2): return 9 * n * l + 9 * r + 3 * c1 + c2 def sparse_table(a): mi = [] s0, l = list(a), 1 mi.append(s0) while 2 * l <= len(a): s = [min(s0[i], s0[i + l]) for i in range(len(s0) - l)] m...
Codeforces Round 106 (Div. 2)
CF
2,012
2
256
Coloring Brackets
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
The first line contains the single string s (2 ≤ |s| ≤ 700) which represents a correct bracket sequence.
Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109 + 7).
null
Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below. The two ways of coloring shown below are incorrect.
[{"input": "(())", "output": "12"}, {"input": "(()())", "output": "40"}, {"input": "()", "output": "4"}]
1,900
["dp"]
38
[{"input": "(())\r\n", "output": "12\r\n"}, {"input": "(()())\r\n", "output": "40\r\n"}, {"input": "()\r\n", "output": "4\r\n"}, {"input": "((()))\r\n", "output": "36\r\n"}, {"input": "()(())\r\n", "output": "42\r\n"}, {"input": "()()()\r\n", "output": "48\r\n"}, {"input": "(())(())\r\n", "output": "126\r\n"}, {"input"...
false
stdio
null
true
149/D
149
D
Python 3
TESTS
0
60
0
226513509
# LUOGU_RID: 127442379 print("4")
38
92
307,200
183796920
# LUOGU_RID: 96524724 def dp(left, right): color = {(i,j):0 for i in range(3) for j in range(3)} # 用字典代替二维列表表示九种方案,初始值均为0 if right-left == 1: # 只有一对括号的情况 for x in [(0,1), (0,2), (1,0), (2,0)]: # 一对配对的括号只有这四种合法的上色方案,下同 color[x] = 1 # 合法方案为1 elif bracket[left] == right: # 左右括号配对成功 ...
Codeforces Round 106 (Div. 2)
CF
2,012
2
256
Coloring Brackets
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
The first line contains the single string s (2 ≤ |s| ≤ 700) which represents a correct bracket sequence.
Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109 + 7).
null
Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below. The two ways of coloring shown below are incorrect.
[{"input": "(())", "output": "12"}, {"input": "(()())", "output": "40"}, {"input": "()", "output": "4"}]
1,900
["dp"]
38
[{"input": "(())\r\n", "output": "12\r\n"}, {"input": "(()())\r\n", "output": "40\r\n"}, {"input": "()\r\n", "output": "4\r\n"}, {"input": "((()))\r\n", "output": "36\r\n"}, {"input": "()(())\r\n", "output": "42\r\n"}, {"input": "()()()\r\n", "output": "48\r\n"}, {"input": "(())(())\r\n", "output": "126\r\n"}, {"input"...
false
stdio
null
true
848/B
848
B
Python 3
TESTS
0
46
5,529,600
33455772
n, w, h = map(int, input().split(" ")) x = [] y = [] for _ in range(n): g, p, t = map(int, input().split(" ")) if g == 1: x.append([p,t]) else: y.append([p,t]) xf = [] yf = [] for i in x: for j in y: p1 = i[0] t1 = i[1] p2 = j[0] t2 = j[1] if (p1+t1 == p2+t2): y.append(x.remove(i)) x.append(y.re...
23
779
75,673,600
130213364
import sys input = sys.stdin.buffer.readline def process(A, w, h): d = {} n = len(A) for i in range(n): gi, pi, ti = A[i] if gi==1: xi = pi if (xi-ti) not in d: d[(xi-ti)] = {'x': [], 'y': []} d[(xi-ti)]['x'].append(i+1) else: ...
Codeforces Round 431 (Div. 1)
CF
2,017
2
256
Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
The first line of input contains three space-separated positive integers n, w and h (1 ≤ n ≤ 100 000, 2 ≤ w, h ≤ 100 000) — the number of dancers and the width and height of the stage, respectively. The following n lines each describes a dancer: the i-th among them contains three space-separated integers gi, pi, and t...
Output n lines, the i-th of which contains two space-separated integers (xi, yi) — the stopping position of the i-th dancer in the input.
null
The first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure. In the second example, no dancers collide.
[{"input": "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1", "output": "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6"}, {"input": "3 2 3\n1 1 2\n2 1 1\n1 1 5", "output": "1 3\n2 1\n1 3"}]
1,900
["constructive algorithms", "data structures", "geometry", "implementation", "sortings", "two pointers"]
23
[{"input": "8 10 8\r\n1 1 10\r\n1 4 13\r\n1 7 1\r\n1 8 2\r\n2 2 0\r\n2 5 14\r\n2 6 0\r\n2 6 1\r\n", "output": "4 8\r\n10 5\r\n8 8\r\n10 6\r\n10 2\r\n1 8\r\n7 8\r\n10 6\r\n"}, {"input": "3 2 3\r\n1 1 2\r\n2 1 1\r\n1 1 5\r\n", "output": "1 3\r\n2 1\r\n1 3\r\n"}, {"input": "1 10 10\r\n1 8 1\r\n", "output": "8 10\r\n"}, {"...
false
stdio
null
true
839/D
839
D
PyPy 3
TESTS
1
171
13,414,400
103996864
visited=[0]*(10**6+1) lastfactor=[-1]*(10**6+1) for j in range(2,10**6+1): for k in range(2*j,10**6+1,j): lastfactor[k]=j n=int(input()) count=[0]*(10**6+1) a=list(map(int,input().split())) for i in range(n): r=a[i] curr=1 while curr*curr<=r: if r%curr==0: count[curr]+=1 count[r//curr]+=1 ...
47
1,106
51,404,800
70405101
import sys useless = sys.stdin.readline() a = list(map(int,sys.stdin.readline().split())) n = 1000001 mod = 1000000007 cnt = [0]*n for i in a: cnt[i]+=1 arr = [0]*n ans = 0 for i in range(n-1,1,-1): j = sum(cnt[i::i]) if j > 0: arr[i]= (j*pow(2,j-1,mod)-sum(arr[i::i]))%mod ans=(ans+i*arr[i])...
Codeforces Round 428 (Div. 2)
CF
2,017
3
256
Winter is here
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a method to know how strong his army is. Let the i-th soldier’s strength...
The first line contains integer n (1 ≤ n ≤ 200000) — the size of the army. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000000) — denoting the strengths of his soldiers.
Print one integer — the strength of John Snow's army modulo 1000000007 (109 + 7).
null
In the first sample the clans are {1}, {2}, {1, 2} so the answer will be 1·3 + 1·3 + 2·3 = 12
[{"input": "3\n3 3 1", "output": "12"}, {"input": "4\n2 3 4 6", "output": "39"}]
2,200
["combinatorics", "dp", "math", "number theory"]
47
[{"input": "3\r\n3 3 1\r\n", "output": "12\r\n"}, {"input": "4\r\n2 3 4 6\r\n", "output": "39\r\n"}]
false
stdio
null
true
316/E1
316
E1
PyPy 3
TESTS1
0
122
819,200
106242658
import sys f = [-1] * 200000 def fib(n): if f[n] == -1: k = n//2 while k > 0 and f[k] == -1: k = k/2 for i in range(k, n): f[i+1] = f[i] + f[i-1]; return f[n] def solve(numbers, t, l, r, d): if t ==...
19
904
307,200
104278377
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
863/D
863
D
PyPy 3
TESTS
1
156
102,400
81022183
import sys import math from collections import defaultdict,deque def get(ind ,arr): n = len(arr) for i in range(n): t,l,r = arr[i] if t == 1: if l <= ind <= r: if ind == l: ind = r else: ind -= 1 continue if t == 2: if l <=ind <= r: ind = (r - ind + l) continue return ind n,q,...
23
670
27,238,400
161145571
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, q, m = map(int, input().split()) A = list(map(int, input().split())) Q = [] for i in range(q): t, l, r = map(int, input().split()) l, r = l-1, r-1 Q.append((t, l, r)) B = list(map(int, input().split())) B = [b-1 for b i...
Educational Codeforces Round 29
ICPC
2,017
2
256
Yet Another Array Queries Problem
You are given an array a of size n, and q queries to it. There are queries of two types: - 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari; - 2 ...
The first line contains three integer numbers n, q and m (1 ≤ n, q ≤ 2·105, 1 ≤ m ≤ 100). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109). Then q lines follow. i-th of them contains three integer numbers ti, li, ri, where ti is the type of i-th query, and [li, ri] is the segment where this q...
Print m numbers, i-th of which is equal to the number at index bi after all queries are done.
null
null
[{"input": "6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3", "output": "3 3 1 5 2"}]
1,800
["data structures", "implementation"]
23
[{"input": "6 3 5\r\n1 2 3 4 5 6\r\n2 1 3\r\n2 3 6\r\n1 1 6\r\n2 2 1 5 3\r\n", "output": "3 3 1 5 2 \r\n"}, {"input": "5 2 5\r\n64 3 4 665 2\r\n1 1 3\r\n2 1 5\r\n1 2 3 4 5\r\n", "output": "2 665 3 64 4 \r\n"}, {"input": "1 1 1\r\n474812122\r\n2 1 1\r\n1\r\n", "output": "474812122 \r\n"}]
false
stdio
null
true
852/G
852
G
Python 3
TESTS
1
46
204,800
30031423
n,m=map(int,input().split(" ")) word=[] pattern=[] count=0 for i in range (0,n): word.append(input()) for i in range (0,m): pattern.append(input()) for i in range (0,m): for j in range (0,n): flag=1 if(len(word[j])==len(pattern[i])): for k in range(len(word[j])): if(word[j][k] != pattern[i][k] and pattern...
15
872
31,846,400
105100981
import sys from itertools import product from collections import defaultdict r=sys.stdin.readline N,M=map(int,r().split()) words=defaultdict(int) tb=['a','b','c','d','e'] st=set() cnt=0 res="" def dfs(u): global res,cnt if u==l: if res in st: return if words[res]>0: cnt+=words[res] ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
2
256
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
The first line of input contains two integers N and M (1 ≤ N ≤ 100 000, 1 ≤ M ≤ 5000), representing the number of words and patterns respectively. The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). E...
Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
null
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
[{"input": "3 1\nabc\naec\nac\na?c", "output": "3"}]
1,700
["implementation"]
15
[{"input": "3 1\r\nabc\r\naec\r\nac\r\na?c\r\n", "output": "3\r\n"}, {"input": "22 2\r\naaaab\r\naaabb\r\naabab\r\naabbb\r\nabaab\r\nababb\r\nabbab\r\nabbbb\r\naaab\r\naabb\r\nabab\r\nabbb\r\naab\r\nabb\r\nab\r\ncccd\r\nccdd\r\ncdcd\r\ncddd\r\nccd\r\ncdd\r\ncd\r\na???b\r\nc??d\r\n", "output": "15\r\n7\r\n"}, {"input": ...
false
stdio
null
true
975/E
975
E
Python 3
TESTS
1
77
7,065,600
38005912
n, q = map(int, input().split()) polygon = [] for _ in range(n): polygon.append([int(x) for x in input().split()]) #print(polygon) requests = [] for _ in range(q): requests.append([int(x) for x in input().split()]) #print(requests) time = len(requests) #print(time) # формула центроида: # xc = (x1 + x2 + ....
31
2,136
23,449,600
38080955
#!/usr/bin/env python3 from math import hypot [n, q] = map(int, input().strip().split()) xys = [tuple(map(int, input().strip().split())) for _ in range(n)] qis = [tuple(map(int, input().strip().split())) for _ in range(q)] dxys = [(xys[(i + 1) % n][0] - xys[i][0], xys[(i + 1) % n][1] - xys[i][1]) for i in range(n)]...
Codeforces Round 478 (Div. 2)
CF
2,018
3
256
Hag's Khashba
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and othe...
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$3\leq n \leq 10\,000$$$, $$$1 \leq q \leq 200000$$$) — the number of vertices in the polygon and the number of queries. The next $$$n$$$ lines describe the wooden polygon, the $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$|x_i|, |y_i|\leq...
The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|...
null
In the first test note the initial and the final state of the wooden polygon. Red Triangle is the initial state and the green one is the triangle after rotation around $$$(2,0)$$$. In the second sample note that the polygon rotates $$$180$$$ degrees counter-clockwise or clockwise direction (it does not matter), becau...
[{"input": "3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3", "output": "3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624"}, {"input": "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1", "output": "1.0000000000 -1.0000000000"}]
2,600
["geometry"]
31
[{"input": "3 4\r\n0 0\r\n2 0\r\n2 2\r\n1 1 2\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "3.4142135624 -1.4142135624\r\n2.0000000000 0.0000000000\r\n0.5857864376 -1.4142135624\r\n"}, {"input": "3 2\r\n-1 1\r\n0 0\r\n1 1\r\n1 1 2\r\n2 1\r\n", "output": "1.0000000000 -1.0000000000\r\n"}, {"input": "10 10\r\n0 -100000000\r\n1 -...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input to count type 2 queries with open(input_path, 'r') as f: n, q = map(int, f.readline().split()) for _ in range(n): f.readline() # skip vertices t...
true
898/C
898
C
PyPy 3
TESTS
1
155
409,600
62421625
n=int(input()) #s=input().split() from collections import defaultdict d=defaultdict(list) for i in range(n): s=input().split() a=s[0] b=s[1:] for x in b: if x not in d[a]: d[a].append(x) #d[a].append(b) for i in d: curr=d[i] ans=curr [:] curr.sort(key=lambda x...
59
62
5,632,000
33294470
n = int(input()) d = dict() for i in range(n): a = input().split() if a[0] not in d: d[a[0]] = [] for j in range(2, len(a)): a[j] = a[j][::-1] d[a[0]] += a[2:] print(len(d)) for x in d: a = d[x] a.sort(reverse = True) ##print(a) b = [a[0]] for i in range(1, len(a)): ...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
986/B
986
B
PyPy 3
TESTS
3
140
1,433,600
99558388
class BIT(): def __init__(self, n): self.n = n self.data = [0]*(n+1) def to_sum(self, i): s = 0 while i > 0: s += self.data[i] i -= (i & -i) return s def add(self, i, x): while i <= self.n: self.data[i] += x i ...
24
498
60,825,600
176109577
n=int(input()) a=list(map(int,input().split())) if sum(a[i]==i+1 for i in range(n))>=n//1000:print("Petr") else:print("Um_nik") # Made By Mostafa_Khaled
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
986/B
986
B
PyPy 3-64
TESTS
2
46
0
232298157
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) cycle = [0 for i in range(n+1)] answer = 0 for i in range(1, n+1): if cycle[i]==0: my_cycle = [i] cycle[i] = 1 while True: x = my_cycle[-1] y = A[x-1] ...
24
654
61,030,400
38739617
import math n = int(input()) a = list(map(int, input().split())) if n < 10: print('Petr') else: print(['Petr', 'Um_nik'][sum(a[i] == i + 1 for i in range(n)) < math.log(n) / 3])
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
986/B
986
B
PyPy 3
TESTS
2
92
20,172,800
115365991
n = int(input()) p = list(map(lambda x: int(x) - 1, input().split())) vis = [False] * n odd = 0 for x in range(n): if vis[x]: continue sz = 0 while not vis[x]: sz += 1 vis[x] = True x = p[x] odd ^= (sz - 1) % 2 print('Petr' if (3 * n + odd) % 2 == 0 else 'Alex')
24
670
61,337,600
40105676
import random n = int(input()) a = list(map(int,input().split(' '))) c = 0 for i in range(1,n+1): if a[i-1]==i: c += 1 if c >= n//1000: print("Petr") else: print("Um_nik")
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
813/F
813
F
Python 3
TESTS
1
31
4,915,200
27952713
class DoubleGraf: def __init__(self, n): self.points = [set() for i in range(n)] self.n = n def add(self, a, b): self.points[a].add(b) self.points[b].add(a) def rem(self, a, b): self.points[a].discard(b) self.points[b].discard(a) def line(self, a, b): ...
25
1,185
83,660,800
215838651
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v, w): return (u * n2 + v) * n2 + w def g(u, v): return u * n2 + v def get_root(s): while s ^ root[s]: s = root[s] return s def unite(s, t, i): s, t = get_root(s),...
Educational Codeforces Round 22
ICPC
2,017
6
256
Bipartite Checking
You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the g...
The first line contains two integers n and q (2 ≤ n, q ≤ 100000). Then q lines follow. ith line contains two numbers xi and yi (1 ≤ xi < yi ≤ n). These numbers describe ith query: if there is an edge between vertices xi and yi, then remove it, otherwise add it.
Print q lines. ith line must contain YES if the graph is bipartite after ith query, and NO otherwise.
null
null
[{"input": "3 5\n2 3\n1 3\n1 2\n1 2\n1 2", "output": "YES\nYES\nNO\nYES\nNO"}]
2,500
["data structures", "dsu", "graphs"]
25
[{"input": "3 5\r\n2 3\r\n1 3\r\n1 2\r\n1 2\r\n1 2\r\n", "output": "YES\r\nYES\r\nNO\r\nYES\r\nNO\r\n"}, {"input": "5 10\r\n1 5\r\n2 5\r\n2 4\r\n1 4\r\n4 5\r\n2 4\r\n2 5\r\n1 4\r\n2 3\r\n1 2\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "10 20\r\n1 10\r\n5 7\r\n1 2\r\...
false
stdio
null
true
908/G
908
G
Python 3
TESTS
1
997
0
57311629
n=int(input()) sum=0 for i in range(1,n+1): t=str(i) m=sorted(t) g=[str(j) for j in m] j=int("".join(g)) sum=sum+j print(sum)
20
77
0
113281106
# Problem G num = input() num_list = [] for i in range(len(num)): num_list.append(int(num[i])) myMod = (10 ** 9) + 7 length = len(num_list) f = [0] * (length + 1) t = [1] * (length + 1) for i in range(length): f[i+1] = (f[i] * 10 + 1) % myMod t[i+1] = (t[i] * 10) % myMod ans = 0 for i in range(1, 10): dp...
Good Bye 2017
CF
2,017
2
256
New Year and Original Order
Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555. Given a number X, compute $$\sum_{1 \leq k \leq X} S(k)$$ modulo 109 + 7.
The first line of input will contain the integer X (1 ≤ X ≤ 10700).
Print a single integer, the answer to the question.
null
The first few values of S are 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 12. The sum of these values is 195.
[{"input": "21", "output": "195"}, {"input": "345342", "output": "390548434"}]
2,800
["dp", "math"]
20
[{"input": "21\r\n", "output": "195\r\n"}, {"input": "345342\r\n", "output": "390548434\r\n"}, {"input": "9438174368\r\n", "output": "419438859\r\n"}, {"input": "33340691714056185860211260984431382156326935244157\r\n", "output": "683387308\r\n"}, {"input": "60659389952427965488066632743799525603106037644498358605868947...
false
stdio
null
true
171/C
171
C
Python 3
TESTS
1
186
0
52143309
a = list(map(int, input().split())) print(3*sum(a[1:]))
41
92
0
206952329
a=input().split() s=0 for i in range(1,int(a[0])+1): s+=i*eval(a[i]) print(s)
April Fools Day Contest
ICPC
2,012
2
256
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread into the mixing bowl. 6....
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
Output a single integer.
null
null
[{"input": "4 1 2 3 4", "output": "30"}]
2,000
["*special", "implementation"]
41
[{"input": "4 1 2 3 4\r\n", "output": "30\r\n"}, {"input": "4 802 765 992 1\r\n", "output": "5312\r\n"}, {"input": "4 220 380 729 969\r\n", "output": "7043\r\n"}, {"input": "3 887 104 641\r\n", "output": "3018\r\n"}, {"input": "12 378 724 582 387 583 241 294 159 198 653 369 418\r\n", "output": "30198\r\n"}, {"input": "...
false
stdio
null
true
839/D
839
D
PyPy 3-64
TESTS
1
421
19,865,600
231993374
M=10**9+7 n=int(input()) a=[int(e) for e in input().split()] R=10**6 c=[0]*(R+1) for i in range(n): j=1 while j*j<=a[i]: if a[i]%j==0: c[j]+=1 J=a[i]//j if J!=j: c[J]+=1 j+=1 F=[0]*(R+1) for i in range(R,0,-1): F[i]=c[i]*pow(2,c[i]-1,M) ...
47
1,434
35,942,400
186589212
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 = list(map(int, input().split())) l = max(a) + 5 cnt = [0] * l for i in a: cnt[i] += 1 dp = [0] * l pow2 = [1] for _ in range(n + 5): pow2.append(2 * pow2[-1] % mod) ans = 0 for i in range(l ...
Codeforces Round 428 (Div. 2)
CF
2,017
3
256
Winter is here
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a method to know how strong his army is. Let the i-th soldier’s strength...
The first line contains integer n (1 ≤ n ≤ 200000) — the size of the army. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000000) — denoting the strengths of his soldiers.
Print one integer — the strength of John Snow's army modulo 1000000007 (109 + 7).
null
In the first sample the clans are {1}, {2}, {1, 2} so the answer will be 1·3 + 1·3 + 2·3 = 12
[{"input": "3\n3 3 1", "output": "12"}, {"input": "4\n2 3 4 6", "output": "39"}]
2,200
["combinatorics", "dp", "math", "number theory"]
47
[{"input": "3\r\n3 3 1\r\n", "output": "12\r\n"}, {"input": "4\r\n2 3 4 6\r\n", "output": "39\r\n"}]
false
stdio
null
true
986/B
986
B
PyPy 3
TESTS
4
77
0
172417015
n = int(input()) l = [int(x) for x in input().split()] if n%5==0: print("Petr") else: print("Um_nik")
24
748
47,308,800
164539860
print(('Um_nik', 'Petr')[int(input()) // 1000 <= sum(i == x for i, x in enumerate(map(int, input().split()), 1))])
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
379/B
379
B
PyPy 3
TESTS
0
77
0
216445885
n = int(input()) arr = list(map(int,input().split())) ans = 'PRL' * arr[0] for i in range(1,n): ans += 'R' +' PLR' * arr[i] print(ans)
15
46
1,024,000
5574523
n=int(input()) A=list(map(int,input().split())) import sys ans="" x=0 ind=0 for i in range(n): if(i!=0): ans+="R" if(i!=n-1): ans+="PRL"*A[i] else: ans+="PLR"*A[i] sys.stdout.write(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
852/E
852
E
PyPy 3
TESTS
1
93
307,200
30117160
print(4+0+0)
12
420
15,155,200
34109480
n = int(input()) cnt = [[] for _ in range(n)] for i in range (n - 1): fr, to = map(int, input().split()) cnt[fr - 1].append(to - 1); cnt[to - 1].append(fr - 1); l = 0 for i in range(n): if (len(cnt[i]) == 1): l += 1 ans = (n - l) * pow(2, n - l, 10 ** 9 + 7) ans += l * pow(2, n - l + 1, 10 ** 9 ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
1
256
Casinos and travel
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
In the first line, a positive integer N (1 ≤ N ≤ 100000), the number of cities. In the next N - 1 lines, two numbers a, b (1 ≤ a, b ≤ N) separated by a single space meaning that cities a and b are connected by a bidirectional road.
Output one number, the answer to the problem modulo 109 + 7.
null
Example 1: If Jack selects city 1 as John's starting city, he can either build 0 casinos, so John will be happy all the time, or build a casino in both cities, so John would visit a casino in city 1, become unhappy, then go to city 2, visit a casino there and become happy and his journey ends there because he can't go ...
[{"input": "2\n1 2", "output": "4"}, {"input": "3\n1 2\n2 3", "output": "10"}]
2,100
["dp"]
12
[{"input": "2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n", "output": "10\r\n"}, {"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "24\r\n"}]
false
stdio
null
true
852/G
852
G
Python 3
TESTS
1
46
0
30338778
import sys, itertools n, m = map(int, sys.stdin.readline().split()) lines = [] for _ in range(n): lines.append(sys.stdin.readline().strip()) for _ in range(m): c = 0 p = sys.stdin.readline().strip().split('?') s = [(p[0],)] o = ('a','b','c','d','e','') for d in p[1:]: s.append(o) ...
15
872
31,846,400
105100981
import sys from itertools import product from collections import defaultdict r=sys.stdin.readline N,M=map(int,r().split()) words=defaultdict(int) tb=['a','b','c','d','e'] st=set() cnt=0 res="" def dfs(u): global res,cnt if u==l: if res in st: return if words[res]>0: cnt+=words[res] ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
2
256
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
The first line of input contains two integers N and M (1 ≤ N ≤ 100 000, 1 ≤ M ≤ 5000), representing the number of words and patterns respectively. The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). E...
Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
null
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
[{"input": "3 1\nabc\naec\nac\na?c", "output": "3"}]
1,700
["implementation"]
15
[{"input": "3 1\r\nabc\r\naec\r\nac\r\na?c\r\n", "output": "3\r\n"}, {"input": "22 2\r\naaaab\r\naaabb\r\naabab\r\naabbb\r\nabaab\r\nababb\r\nabbab\r\nabbbb\r\naaab\r\naabb\r\nabab\r\nabbb\r\naab\r\nabb\r\nab\r\ncccd\r\nccdd\r\ncdcd\r\ncddd\r\nccd\r\ncdd\r\ncd\r\na???b\r\nc??d\r\n", "output": "15\r\n7\r\n"}, {"input": ...
false
stdio
null
true
852/C
852
C
PyPy 3
TESTS
1
93
0
30117081
print("0 2 1")
29
155
12,083,200
217501588
n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) b = [] for i in range(0, n-1): b.append((a[i]-(n-a[i+1]), i)) b.append((a[n-1]-(n-a[0]), n-1)) b = sorted(b) ans = n*[0] for i in range(n): # the line segment at index b[i][1] ans[b[i][1]] = i for i in range(n): print(ans[i], e...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
0.5
256
Property
Bill is a famous mathematician in BubbleLand. Thanks to his revolutionary math discoveries he was able to make enough money to build a beautiful house. Unfortunately, for not paying property tax on time, court decided to punish Bill by making him lose a part of his property. Bill’s property can be observed as a convex...
The first line contains one integer number n (2 ≤ n ≤ 50000), representing number of edges of 2n-sided polygon. The second line contains n distinct integer numbers B2k (0 ≤ B2k ≤ n - 1, k = 0... n - 1) separated by a single space, representing points the court chose. If B2k = i, the court chose point Pi on side A2k A...
Output contains n distinct integers separated by a single space representing points B1, B3, ..., B2n - 1 Bill should choose in order to maximize the property area. If there are multiple solutions that maximize the area, return any of them.
null
To maximize area Bill should choose points: B1 = P0, B3 = P2, B5 = P1
[{"input": "3\n0 1 2", "output": "0 2 1"}]
2,100
["greedy", "sortings"]
29
[{"input": "3\r\n0 1 2\r\n", "output": "0 2 1\r\n"}, {"input": "10\r\n0 1 2 3 4 5 6 7 8 9\r\n", "output": "0 1 2 3 5 6 7 8 9 4\r\n"}, {"input": "10\r\n1 7 3 6 8 2 4 5 0 9\r\n", "output": "2 6 5 9 7 1 4 0 3 8\r\n"}, {"input": "10\r\n4 9 7 2 3 5 6 1 8 0\r\n", "output": "8 9 6 1 4 7 2 5 3 0\r\n"}, {"input": "5\r\n1 2 3 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] submission_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline().strip()) court = list(map(int, f.readline().split())) with open(submission_path, 'r') as f: submission = list(map(int, f.readline().split...
true
852/G
852
G
Python 3
TESTS
1
46
0
30212008
n,m = map(int , input().split()) str1 = [] shabl1 = [] answ = 0 for i in range(n): str1.append(input()) d = 0 for i in range(m): shabl1.append(input()) shabl1[i]+=str("000") for shabl in shabl1: answ = 0 for i in str1: for j in range(len(i)): if shabl[j]!=i[j] and shabl[j]!="...
15
872
31,846,400
105100981
import sys from itertools import product from collections import defaultdict r=sys.stdin.readline N,M=map(int,r().split()) words=defaultdict(int) tb=['a','b','c','d','e'] st=set() cnt=0 res="" def dfs(u): global res,cnt if u==l: if res in st: return if words[res]>0: cnt+=words[res] ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
2
256
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
The first line of input contains two integers N and M (1 ≤ N ≤ 100 000, 1 ≤ M ≤ 5000), representing the number of words and patterns respectively. The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). E...
Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
null
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
[{"input": "3 1\nabc\naec\nac\na?c", "output": "3"}]
1,700
["implementation"]
15
[{"input": "3 1\r\nabc\r\naec\r\nac\r\na?c\r\n", "output": "3\r\n"}, {"input": "22 2\r\naaaab\r\naaabb\r\naabab\r\naabbb\r\nabaab\r\nababb\r\nabbab\r\nabbbb\r\naaab\r\naabb\r\nabab\r\nabbb\r\naab\r\nabb\r\nab\r\ncccd\r\nccdd\r\ncdcd\r\ncddd\r\nccd\r\ncdd\r\ncd\r\na???b\r\nc??d\r\n", "output": "15\r\n7\r\n"}, {"input": ...
false
stdio
null
true
383/D
383
D
Python 3
TESTS
1
30
0
228198474
MOD = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) total_sum = sum(a) half_sum = (total_sum + 1) // 2 dp = [0] * (half_sum + 1) dp[0] = 1 for i in range(n): for j in range(half_sum, a[i] - 1, -1): dp[j] = (dp[j] + dp[j - a[i]]) % MOD # Calculate the number of ways for the target sum r...
48
327
159,948,800
123422157
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) a = list(map(int, input().split())) m = sum(a) M = 10**9+7 dp = [0]*(2*m+1) ...
Codeforces Round 225 (Div. 1)
CF
2,014
1
256
Antimatter
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode fo...
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
null
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
[{"input": "4\n1 1 1 1", "output": "12"}]
2,300
["dp"]
48
[{"input": "4\r\n1 1 1 1\r\n", "output": "12\r\n"}, {"input": "10\r\n16 9 9 11 10 12 9 6 10 8\r\n", "output": "86\r\n"}, {"input": "50\r\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\r\n", "output": "115119382\r\n"}, {"input": "100\r\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 ...
false
stdio
null
true
158/C
158
C
Python 3
TESTS
0
62
0
226886524
n = int(input()) # Read the number of commands current_directory = "/" # Initialize the current directory as the root "/" for _ in range(n): command = input().split() # Read the command and its parameter if command[0] == "cd": path = command[1] if path.startswith("/"): ...
29
124
0
18858108
class Shell: def __init__(self): self.wd = [''] def cd(self, where: str): glob = where.startswith('/') directories = where.split('/') if directories and not directories[0]: directories.pop(0) if glob: self._reset() for d in directories: ...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Cd and pwd commands
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure...
The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Lat...
For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots.
null
null
[{"input": "7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "output": "/\n/home/vasya/\n/home/\n/home/petya/"}, {"input": "4\ncd /a/b\npwd\ncd ../a/b\npwd", "output": "/a/b/\n/a/a/b/"}]
1,400
["*special", "data structures", "implementation"]
29
[{"input": "7\r\npwd\r\ncd /home/vasya\r\npwd\r\ncd ..\r\npwd\r\ncd vasya/../petya\r\npwd\r\n", "output": "/\r\n/home/vasya/\r\n/home/\r\n/home/petya/\r\n"}, {"input": "4\r\ncd /a/b\r\npwd\r\ncd ../a/b\r\npwd\r\n", "output": "/a/b/\r\n/a/a/b/\r\n"}, {"input": "1\r\npwd\r\n", "output": "/\r\n"}, {"input": "2\r\ncd /test...
false
stdio
null
true
342/E
342
E
PyPy 3
TESTS
2
140
0
99283930
n,m=map(int,input().split()) tr=[set() for i in range(n+1)] trr=[[] for i in range(n+1)] for _ in range(n-1): a,b=map(int,input().split()) trr[a].append(b);trr[b].append(a) tr[a].add(b);tr[b].add(a) euler=[] disc=[-1 for i in range(n+1)] hei=[-1 for i in range(n+1)] def eulerr(): q=[1] pa={1:-1} hei[1]=0 whi...
23
997
27,648,000
109826106
class CentroidDecomposition(): def __init__(self, g): self.g = g self.n = len(g) self.parent = [-1]*self.n self.size = [1]*self.n self.cdparent = [-1]*self.n self.cddepth = [0]*self.n self.cdorder = [-1]*self.n self.cdused = [0]*self.n cnt = ...
Codeforces Round 199 (Div. 2)
CF
2,013
5
256
Xenia and Tree
Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tree nodes v and u is the number of edges in the shortest path between v and u...
The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree. Next m lines contain queries. Each query is spe...
For each second type query print the reply in a single line.
null
null
[{"input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5", "output": "0\n3\n2"}]
2,400
["data structures", "divide and conquer", "trees"]
23
[{"input": "5 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n2 1\r\n2 5\r\n1 2\r\n2 5\r\n", "output": "0\r\n3\r\n2\r\n"}]
false
stdio
null
true
342/E
342
E
PyPy 3
TESTS
2
93
20,684,800
128984780
import os import sys from io import BytesIO, IOBase _print = print BUFSIZE = 8192 def dbg(*args, **kwargs): _print('\33[95m', end='') _print(*args, **kwargs) _print('\33[0m', end='') class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buff...
23
1,153
46,694,400
103009002
class Tree(): def __init__(self, n): self.n = n self.tree = [[] for _ in range(n)] self.root = None def add_edge(self, u, v): self.tree[u].append(v) self.tree[v].append(u) def set_root(self, r=0): self.root = r self.par = [None] * self.n self...
Codeforces Round 199 (Div. 2)
CF
2,013
5
256
Xenia and Tree
Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tree nodes v and u is the number of edges in the shortest path between v and u...
The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree. Next m lines contain queries. Each query is spe...
For each second type query print the reply in a single line.
null
null
[{"input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5", "output": "0\n3\n2"}]
2,400
["data structures", "divide and conquer", "trees"]
23
[{"input": "5 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n2 1\r\n2 5\r\n1 2\r\n2 5\r\n", "output": "0\r\n3\r\n2\r\n"}]
false
stdio
null
true
802/M
802
M
Python 3
TESTS
0
30
0
120657957
input() input() print(1)
14
46
102,400
224698431
x,y=map(int,input().split()) n=list(map(int,input().split())) n=sorted(n) ans=0 for num in range(y): ans=ans+n[num] print(ans)
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
2
256
April Fools' Problem (easy)
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea...
The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104).
Output one number.
null
null
[{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}]
1,200
["greedy", "sortings"]
14
[{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1...
false
stdio
null
true
159/E
159
E
Python 3
TESTS
0
46
307,200
15156452
def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] [n]=get() p = {} for i in range(n): [a,b] = get() if a not in p: p[a]=[] p[a].append([b,i+1]) h=[] for i...
35
1,200
31,129,600
144123105
from collections import defaultdict n=int(input()) g=defaultdict(list) for i in range(n): c,s=map(int,input().strip().split()) g[c].append((s,i+1)) pref=defaultdict(list) for i in g: g[i].sort(key=lambda s:s[0],reverse=True) pre=g[i][0][0] sz=1 pref[sz].append((pre,i)) for id in range(1,le...
VK Cup 2012 Qualification Round 2
CF
2,012
1.5
256
Zebra Tower
Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color ci and size si. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in ...
The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers ci and si (1 ≤ ci, si ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there ...
Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bot...
null
null
[{"input": "4\n1 2\n1 3\n2 4\n3 3", "output": "9\n3\n2 3 1"}, {"input": "2\n1 1\n2 1", "output": "2\n2\n2 1"}]
1,700
["*special", "data structures", "greedy", "sortings"]
35
[{"input": "4\r\n1 2\r\n1 3\r\n2 4\r\n3 3\r\n", "output": "9\r\n3\r\n2 3 1 \r\n"}, {"input": "2\r\n1 1\r\n2 1\r\n", "output": "2\r\n2\r\n2 1 \r\n"}, {"input": "3\r\n1 2\r\n2 2\r\n2 1\r\n", "output": "5\r\n3\r\n2 1 3 \r\n"}, {"input": "4\r\n2 1\r\n2 1\r\n1 1\r\n1 2\r\n", "output": "5\r\n4\r\n4 2 3 1 \r\n"}, {"input": "6...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline()) cubes = [] for i in range(n): c, s = map(int, f.readline().split()) cubes.append((c...
true
397/B
397
B
Python 3
TESTS
1
93
0
62337644
for i in range(int(input())): n,l,r = map(int,input().split()) i = n%r while i>0 and l<r: if i%l !=0: l+=1 else:i = 0 print('Yes') if i==0 else print('No')
6
62
0
5946952
T=int(input()) while T>0: T-=1 n,l,r=map(int,input().split()) t = n//l if t*r>=n: print("Yes") else: print("No")
Codeforces Round 232 (Div. 2)
CF
2,014
1
256
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
null
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
[{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}]
null
["constructive algorithms", "implementation", "math"]
6
[{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38...
false
stdio
null
true
397/B
397
B
Python 3
TESTS
1
78
307,200
72907387
class CodeforcesTask397BSolution: def __init__(self): self.result = '' self.t = 0 self.queries = [] def read_input(self): self.t = int(input()) for _ in range(self.t): self.queries.append([int(x) for x in input().split(" ")]) def process_task(self): ...
6
62
0
29595548
for i in range(int(input())): n, l, r = map(int, input().split()) print('No' if (n // l) * r < n else 'Yes')
Codeforces Round 232 (Div. 2)
CF
2,014
1
256
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
null
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
[{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}]
null
["constructive algorithms", "implementation", "math"]
6
[{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38...
false
stdio
null
true
342/E
342
E
PyPy 3-64
TESTS
3
2,948
60,928,000
190924318
import os, sys from io import BytesIO, IOBase from array import array from itertools import accumulate import bisect import math from collections import deque # from functools import cache # cache cf需要自己提交 pypy3.9! from copy import deepcopy class FastIO(IOBase): newlines = 0 def __init__(self, file): ...
23
1,356
62,566,400
211268601
class Tree(): def __init__(self, n): self.n = n self.tree = [[] for _ in range(n)] self.root = None def addEdge(self, u, v): self.tree[u].append(v) self.tree[v].append(u) def setRoot(self, r=0): self.root = r self.par = [None] * self.n self.d...
Codeforces Round 199 (Div. 2)
CF
2,013
5
256
Xenia and Tree
Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tree nodes v and u is the number of edges in the shortest path between v and u...
The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree. Next m lines contain queries. Each query is spe...
For each second type query print the reply in a single line.
null
null
[{"input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5", "output": "0\n3\n2"}]
2,400
["data structures", "divide and conquer", "trees"]
23
[{"input": "5 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n2 1\r\n2 5\r\n1 2\r\n2 5\r\n", "output": "0\r\n3\r\n2\r\n"}]
false
stdio
null
true
342/E
342
E
Python 3
TESTS
3
1,886
16,588,800
69301594
def dfs(neighbours, queue, distances): t = 0 while(t < len(queue)): for x in neighbours[queue[t]]: if distances[x] > distances[queue[t]] + 1: distances[x] = distances[queue[t]] + 1 queue.append(x) t += 1 return 0 l = input().split() n = int(l[0]) ...
23
2,480
64,307,200
190927214
import os, sys from io import BytesIO, IOBase from array import array from itertools import accumulate import bisect import math from collections import deque # from functools import cache # cache cf需要自己提交 pypy3.9! from copy import deepcopy class FastIO(IOBase): newlines = 0 def __init__(self, file): ...
Codeforces Round 199 (Div. 2)
CF
2,013
5
256
Xenia and Tree
Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tree nodes v and u is the number of edges in the shortest path between v and u...
The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree. Next m lines contain queries. Each query is spe...
For each second type query print the reply in a single line.
null
null
[{"input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5", "output": "0\n3\n2"}]
2,400
["data structures", "divide and conquer", "trees"]
23
[{"input": "5 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n2 1\r\n2 5\r\n1 2\r\n2 5\r\n", "output": "0\r\n3\r\n2\r\n"}]
false
stdio
null
true
37/D
37
D
PyPy 3-64
TESTS
0
46
614,400
215318826
import sys from functools import cache MOD = 10**9 + 7 def make_comb_matrix(n: int) -> list: comb = [[1] * (n + 1) for i in range(n + 1)] for i in range(2, n + 1): for j in range(1, i): comb[i][j] = (comb[i - 1][j] + comb[i - 1][j -1]) % MOD return comb readline = sys.stdin.readline ...
76
124
11,673,600
215322269
import sys from functools import cache MOD = 10**9 + 7 def make_comb_matrix(n: int) -> list: comb = [[1] * (n + 1) for i in range(n + 1)] for i in range(2, n + 1): for j in range(1, i): comb[i][j] = (comb[i - 1][j] + comb[i - 1][j -1]) % MOD return comb readline = sys.stdin.readline ...
Codeforces Beta Round 37
CF
2,010
1
256
Lesson Timetable
When Petya has free from computer games time, he attends university classes. Every day the lessons on Petya’s faculty consist of two double classes. The floor where the lessons take place is a long corridor with M classrooms numbered from 1 to M, situated along it. All the students of Petya’s year are divided into N g...
The first line contains one integer M (1 ≤ M ≤ 100) — the number of classrooms. The second line contains M space-separated integers — Xi (0 ≤ Xi ≤ 100) the amount of groups present in classroom i during the first lesson. The third line contains M space-separated integers — Yi (0 ≤ Yi ≤ 100) the maximal amount of grou...
In the single line output the answer to the problem modulo 109 + 7.
null
In the second sample test the first and the second lessons of each group must take place in the same classroom, that’s why the timetables will only be different in the rearrangement of the classrooms’ numbers for each group, e.g. 3! = 6.
[{"input": "3\n1 1 1\n1 2 3", "output": "36"}, {"input": "3\n1 1 1\n1 1 1", "output": "6"}]
2,300
["combinatorics", "dp", "math"]
76
[{"input": "3\r\n1 1 1\r\n1 2 3\r\n", "output": "36\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3\r\n2 1 1\r\n5 1 2\r\n", "output": "72\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n5 3 1 1 3\r\n", "output": "49320\r\n"}, {"input": "5\r\n1 3 15 3 18\r\n2 6 18 5 19\r\n", "output": "921487545\r\n"}, ...
false
stdio
null
true
986/B
986
B
PyPy 3
TESTS
2
171
4,812,800
160459989
from bisect import * from collections import * import sys import io, os import math import random from heapq import * gcd = math.gcd sqrt = math.sqrt def ceil(a, b): a = -a k = a // b k = -k return k # arr=list(map(int, input().split())) input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def s...
24
748
75,059,200
39037427
n=int(input()) a=[0]+list(map(int,input().split())) ans=0 for i in range(1,len(a)): if a[i]==-1: continue j=i while a[j]!=-1: prev=j j=a[j] a[prev]=-1 ans+=1 if n%2==0: #n even ans also even even number of swaps required #3*n if ans%2==0: print("Petr"...
Codeforces Round 485 (Div. 1)
CF
2,018
2
256
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ...
In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$...
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
null
Please note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC. Due to randomness of input hacks in this problem are forbidden.
[{"input": "5\n2 4 5 1 3", "output": "Petr"}]
1,800
["combinatorics", "math"]
24
[{"input": "5\r\n2 4 5 1 3\r\n", "output": "Petr\r\n"}]
false
stdio
null
true
177/D1
177
D2
Python 3
TESTS2
0
60
0
142746309
line = input().split(' ') n, m, c = int(line[0]), int(line[1]), int(line[2]) arr = input().split(' ') for i in range(len(arr)): arr[i] = int(arr[i]) enc = input().split(' ') for i in range(len(enc)): enc[i] = int(enc[i]) dif = [0] * (n + 2) for i in range(m): dif[i + 1] += enc[i] if n - m + i + 2 < n...
12
184
2,048,000
197629446
L = lambda: list(map(int, input().split())) n, m, c = L() A, B = L(), L() for i in range(n-m+1): for j in range(i, i+m): A[j] += B[j-i] A[j] %= c print(*A)
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
The first input line contains three integers n, m and c, separated by single spaces. The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message. The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limit...
Print n space-separated integers — the result of encrypting the original message.
null
In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.
[{"input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0"}, {"input": "3 1 5\n1 2 3\n4", "output": "0 1 2"}]
1,200
["brute force"]
12
[{"input": "4 3 2\r\n1 1 1 1\r\n1 1 1\r\n", "output": "0 1 1 0\r\n"}, {"input": "3 1 5\r\n1 2 3\r\n4\r\n", "output": "0 1 2\r\n"}, {"input": "5 2 7\r\n0 0 1 2 4\r\n3 5\r\n", "output": "3 1 2 3 2\r\n"}, {"input": "20 15 17\r\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\r\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15\r\n", ...
false
stdio
null
true
451/C
451
C
PyPy 3-64
TESTS
1
1,013
9,011,200
214655604
t = int(input()) for _ in range(t): n, k, d1, d2 = list(map(int, input().split())) if (n % 3 != 0): print("no") continue x1 = (2 * d1 + d2 + k) // 3 x2 = x1 - d1 x3 = x2 - d2 if not (x1 <= n // 3 and x2 <= n // 3 and x3 <= n // 3): print("no") continue r = n -...
36
529
11,776,000
212078103
from sys import stdin ,stdout input=stdin.readline inp = lambda : map(int,input().split()) def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) def check() : global ans , arr , n , k for i in arr : if i<0 : return 0 ans += max(arr ) - i if an...
Codeforces Round 258 (Div. 2)
CF
2,014
2
256
Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each ...
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105). Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
null
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win. Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournam...
[{"input": "5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2", "output": "yes\nyes\nyes\nno\nno"}]
1,700
["brute force", "implementation", "math"]
36
[{"input": "5\r\n3 0 0 0\r\n3 3 0 0\r\n6 4 1 0\r\n6 3 3 0\r\n3 3 3 2\r\n", "output": "yes\r\nyes\r\nyes\r\nno\r\nno\r\n"}]
false
stdio
null
true
689/E
689
E
Python 3
PRETESTS
0
46
0
18935365
N, K = map(int,input().split()) L = [list(map(int,input().split())) for x in range(N)] a = [L[x][0] for x in range(N)] b = [L[x][1] for x in range(N)] s = 0 a.sort() b.sort() a = a[K-1:] + [a[-1]]*(K-1) b = [b[0]]*(K-1) + b[:K-1] print(sum(a)+sum(b))
69
1,513
48,128,000
228758837
from collections import defaultdict mod=10**9+7 MAXN=300001 def power(a,b): res=1 while b>0: if b&1: res=(res*a)%mod b>>=1 a=(a*a)%mod return res fact=[1 for _ in range(MAXN)] inv_fact=[1 for _ in range(MAXN)] for i in range(2,MAXN): fact[i]=(fact[i-1]*i)%mo...
Codeforces Round 361 (Div. 2)
CF
2,016
3
256
Mike and Geometry Problem
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that $$f(\varnothing) = 0$$). You are given two integers n and k and n closed intervals [li, ri...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively. Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds.
Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.
null
In the first example: $$f([1,2]\cap[1,3])=f([1,2])=2$$; $$f([1,2]\cap[2,3])=f([2,2])=1$$; $$f([1,3]\cap[2,3])=f([2,3])=2$$. So the answer is 2 + 1 + 2 = 5.
[{"input": "3 2\n1 2\n1 3\n2 3", "output": "5"}, {"input": "3 3\n1 3\n1 3\n1 3", "output": "3"}, {"input": "3 1\n1 2\n2 3\n3 4", "output": "6"}]
2,000
["combinatorics", "data structures", "dp", "geometry", "implementation"]
69
[{"input": "3 2\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "5\r\n"}, {"input": "3 3\r\n1 3\r\n1 3\r\n1 3\r\n", "output": "3\r\n"}, {"input": "3 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "6\r\n"}, {"input": "1 1\r\n45 70\r\n", "output": "26\r\n"}, {"input": "1 1\r\n-35 -8\r\n", "output": "28\r\n"}, {"input": "1 1\r\n-79 -51\r\n"...
false
stdio
null
true
451/C
451
C
PyPy 3-64
TESTS
1
1,075
10,547,200
214707025
t = int(input()) for _ in range(t): n, k, d1, d2 = list(map(int, input().split())) if (n % 3 != 0): print("no") continue v = False for sign1 in range(-1, 2): for sign2 in range(-1, 2): if (sign1 == 0 or sign2 == 0): continue d1 = d1 * sign1 d2 ...
36
1,232
512,000
7228790
import itertools import sys ''' w1 - w2 = d1 w2 - w3 = d2 w1 + w2 + w3 = k w1 = w2 + d1 w3 = w2 - d2 w2 + d1 + w2 + w2 - d2 = k w2 = (k - d1 + d2) / 3 w1 = w2 + d1 w3 = w2 - d2 ''' for _ in range(int(input())): n, k, d1, d2 = map(int, str.split(sys.stdin.readline())) for s1, s2 in itertools.product((1, -1)...
Codeforces Round 258 (Div. 2)
CF
2,014
2
256
Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each ...
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105). Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
null
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win. Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournam...
[{"input": "5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2", "output": "yes\nyes\nyes\nno\nno"}]
1,700
["brute force", "implementation", "math"]
36
[{"input": "5\r\n3 0 0 0\r\n3 3 0 0\r\n6 4 1 0\r\n6 3 3 0\r\n3 3 3 2\r\n", "output": "yes\r\nyes\r\nyes\r\nno\r\nno\r\n"}]
false
stdio
null
true
852/E
852
E
PyPy 3
TESTS
1
78
0
30117158
print(4+0)
12
577
8,089,600
175629065
''' john以好心情开始、在n个“由n-1条双向边连通”的城市间旅行,每个城市呆一天,然后选择相邻未访问的城市, 到达有赌场的城市时john一定会试下身手,并且赌博会改变心情,即由好变坏、或反之, 求使得john总是会以好心情结束旅程的“选择起始城市和设赌场的”方案数。 dfs计数,超时。 描述问题:在树上任意选择根节点并将每个节点描为红或黑色, 求满足“从根节点到任意叶节点的路径上包含偶数个黑节点”的方案数。 考虑如何使“路径上包含偶数个黑节点”,……答案是其他节点任意设颜色、由叶节点来修正 做完这题给人带来的直觉是,关于奇偶性的问题,解法可以是简单的。 ''' I=input;n=int(I());d=[0]*n for ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
1
256
Casinos and travel
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
In the first line, a positive integer N (1 ≤ N ≤ 100000), the number of cities. In the next N - 1 lines, two numbers a, b (1 ≤ a, b ≤ N) separated by a single space meaning that cities a and b are connected by a bidirectional road.
Output one number, the answer to the problem modulo 109 + 7.
null
Example 1: If Jack selects city 1 as John's starting city, he can either build 0 casinos, so John will be happy all the time, or build a casino in both cities, so John would visit a casino in city 1, become unhappy, then go to city 2, visit a casino there and become happy and his journey ends there because he can't go ...
[{"input": "2\n1 2", "output": "4"}, {"input": "3\n1 2\n2 3", "output": "10"}]
2,100
["dp"]
12
[{"input": "2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n", "output": "10\r\n"}, {"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "24\r\n"}]
false
stdio
null
true
545/A
545
A
Python 3
TESTS
3
31
0
181555683
size = int(input()) matrix = [[int(x) for x in input().split(" ")] for y in range(size)] sols = [] for irow in range(size): sols.append(irow) for icol in range(size): if matrix[irow][icol] == 3 or matrix[irow][icol] == 1: if len(sols) > 0: sols.pop(len(sols)-1) print(len(s...
35
46
0
188007982
n = int(input()) i = 0 data = [] while i < n: data.append([int(x) for x in input().split()]) i += 1 i = 0 bad_cars = set() while i < n: j = 0 while j < n: if data[i][j] == 1: bad_cars.add(i + 1) elif data[i][j] == 2: bad_cars.add(j + 1) elif data[i][j] == 3: bad_cars.add(i + 1) bad_cars.add(j + 1)...
Codeforces Round 303 (Div. 2)
CF
2,015
1
256
Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned ...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that ...
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
null
null
[{"input": "3\n-1 0 0\n0 -1 1\n0 2 -1", "output": "2\n1 3"}, {"input": "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1", "output": "0"}]
900
["implementation"]
35
[{"input": "3\r\n-1 0 0\r\n0 -1 1\r\n0 2 -1\r\n", "output": "2\r\n1 3 "}, {"input": "4\r\n-1 3 3 3\r\n3 -1 3 3\r\n3 3 -1 3\r\n3 3 3 -1\r\n", "output": "0\r\n"}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n-1 0\r\n0 -1\r\n", "output": "2\r\n1 2 "}, {"input": "2\r\n-1 1\r\n2 -1\r\n", "output": "1\r\n2 ...
false
stdio
null
true
451/C
451
C
PyPy 3-64
TESTS
1
1,060
10,444,800
208580733
def is_possible(n, k, d1, d2): # Check for the case where no games have been played yet if k == 0: if (d1 + d2) % 3 == 0: return "yes" else: return "no" # Check if it is possible to have a valid tournament using the remaining games remaining_games = n - k ...
36
1,996
0
18778723
read = lambda: map(int, input().split()) f = lambda x, y, a, b: x > a or y > b or (a - x) % 3 or (b - y) % 3 g = lambda x, y, a, b: f(x, y, a, b) and f(x, y, b, a) t = int(input()) for i in range(t): n, k, d1, d2 = read() r = n - k d = d1 + d2 p = 2 * d2 - d1 if d2 > d1 else 2 * d1 - d2 pri...
Codeforces Round 258 (Div. 2)
CF
2,014
2
256
Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each ...
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105). Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
null
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win. Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournam...
[{"input": "5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2", "output": "yes\nyes\nyes\nno\nno"}]
1,700
["brute force", "implementation", "math"]
36
[{"input": "5\r\n3 0 0 0\r\n3 3 0 0\r\n6 4 1 0\r\n6 3 3 0\r\n3 3 3 2\r\n", "output": "yes\r\nyes\r\nyes\r\nno\r\nno\r\n"}]
false
stdio
null
true
817/E
817
E
PyPy 3
TESTS
1
187
5,017,600
170367366
from collections import defaultdict, deque, Counter import sys from decimal import * from heapq import heapify, heappop, heappush import math import random import string from copy import deepcopy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce,...
42
358
28,262,400
132474088
import sys input = sys.stdin.buffer.readline def binary_trie(l): G0, G1, cnt = [-1], [-1], [0] return G0, G1, cnt, l def insert(x): j = 0 for i in range(l, -1, -1): cnt[j] += 1 if x & pow2[i]: if G1[j] == -1: G0.append(-1) G1.append(-1) ...
Educational Codeforces Round 23
ICPC
2,017
2
256
Choosing The Commander
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires. Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors. Ea...
The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events. Then q lines follow. Each line describes the event: - 1 pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army; - 2 pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova's army (it is guaranteed that there is at le...
For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.
null
In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him ($$4 \oplus 6 = 2$$, and 2 < 3, but $$3 \oplus 6 = 5$$, and 5 ≥ 3). Then warrior with personality 4 leaves, and w...
[{"input": "5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3", "output": "1\n0"}]
2,000
["bitmasks", "data structures", "trees"]
42
[{"input": "5\r\n1 3\r\n1 4\r\n3 6 3\r\n2 4\r\n3 6 3\r\n", "output": "1\r\n0\r\n"}]
false
stdio
null
true
774/H
774
H
Python 3
TESTS
0
46
4,812,800
26153704
n = int(input()) a = list(map(int, input().split())) cur = 0 k = 0 for i in range(n - 1, -1, -1): k += cur a[i] -= k cur += a[i] b = [[0, 0]] * n; for i in range(n - 1, -1, -1): b[i] = [ a[i], i + 1 ] for i in range(n): for j in range(n - 1): if b[j][0] < b[j + 1][0]: swap(b[j][0], b[j + 1][0]) pos = 0 cur =...
44
62
0
120297469
import sys n = int(input()) c = list(map(int, input().split())) cc = ord('a') ans = "" cur = n - 1 if 1: cur = n - 1 while cur >= 0: while c[cur] > 0: if chr(cc) > 'z': cc = ord('a') ans += chr(cc) * (cur + 1) c[cur] -= 1 for i in range(cu...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Repairing Of String
Stepan had a favorite string s which consisted of the lowercase letters of the Latin alphabet. After graduation, he decided to remember it, but it was a long time ago, so he can't now remember it. But Stepan remembers some information about the string, namely the sequence of integers c1, c2, ..., cn, where n equals th...
The first line contains the integer n (1 ≤ n ≤ 2000) — the length of the Stepan's favorite string. The second line contains the sequence of integers c1, c2, ..., cn (0 ≤ ci ≤ 2000), where ci equals the number of substrings of the string s with the length i, consisting of the same letters. It is guaranteed that the in...
Print the repaired Stepan's favorite string. If there are several answers, it is allowed to print any of them. The string should contain only lowercase letters of the English alphabet.
null
In the first test Stepan's favorite string, for example, can be the string "kkrrrq", because it contains 6 substrings with the length 1, consisting of identical letters (they begin in positions 1, 2, 3, 4, 5 and 6), 3 substrings with the length 2, consisting of identical letters (they begin in positions 1, 3 and 4), an...
[{"input": "6\n6 3 1 0 0 0", "output": "kkrrrq"}, {"input": "4\n4 0 0 0", "output": "abcd"}]
2,200
["*special", "constructive algorithms"]
44
[{"input": "6\r\n6 3 1 0 0 0\r\n", "output": "aaabbc\r\n"}, {"input": "4\r\n4 0 0 0\r\n", "output": "abcd\r\n"}, {"input": "1\r\n1\r\n", "output": "a\r\n"}, {"input": "5\r\n5 0 0 0 0\r\n", "output": "abcde\r\n"}, {"input": "10\r\n10 8 7 6 5 4 3 2 1 0\r\n", "output": "aaaaaaaaab\r\n"}, {"input": "20\r\n20 16 12 8 5 2 1 ...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: n = int(f.readline()) c_input = list(map(int, f.readline().split())) with open(sub_path) as f: s = f.readline().strip() if len(s) != n: print(0) return if not s.islower(...
true
817/E
817
E
PyPy 3
TESTS
1
92
1,228,800
120284085
from sys import stdin input=stdin.readline class Node: def __init__(self,data): self.data=data self.left=None self.right=None self.count=0 class Trie(): def __init__(self): self.root=Node(0) def insert(self,preXor): self.temp=self.root for i in range...
42
623
45,158,400
111339985
import sys from collections import defaultdict class Node: def __init__(self, val): self.val = val self.left = None self.right = None q = int(sys.stdin.readline()) root = Node(0) # def search(node, bit, ) for _ in range(q): l = list(map(int, sys.stdin.readline().split())) if l[0] == 1: # add bit = 28 ...
Educational Codeforces Round 23
ICPC
2,017
2
256
Choosing The Commander
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires. Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors. Ea...
The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events. Then q lines follow. Each line describes the event: - 1 pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army; - 2 pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova's army (it is guaranteed that there is at le...
For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.
null
In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him ($$4 \oplus 6 = 2$$, and 2 < 3, but $$3 \oplus 6 = 5$$, and 5 ≥ 3). Then warrior with personality 4 leaves, and w...
[{"input": "5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3", "output": "1\n0"}]
2,000
["bitmasks", "data structures", "trees"]
42
[{"input": "5\r\n1 3\r\n1 4\r\n3 6 3\r\n2 4\r\n3 6 3\r\n", "output": "1\r\n0\r\n"}]
false
stdio
null
true
717/D
717
D
PyPy 3
TESTS
1
77
1,740,800
103902825
import os from io import BytesIO #input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): n = 0 r = 0 r2 = 0 class Matrix(): def __init__(self,ar): self.ar = ar def __mul__(self,other): ans = [0 for i in r] for i in r2: ...
11
108
1,945,600
103911369
import os from io import BytesIO #input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): def mult(m1,m2): ans = [0] * 128 for i in range(128): for j in range(128): ans[i^j] += m1[i] * m2[j] return ans def power(number, n): res = ...
Bubble Cup 9 - Finals [Online Mirror]
ICPC
2,016
1
256
Dexterina’s Lab
Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re ...
The first line of the input contains two integers n (1 ≤ n ≤ 109) and x (1 ≤ x ≤ 100) — the number of heaps and the maximum number of objects in a heap, respectively. The second line contains x + 1 real numbers, given with up to 6 decimal places each: P(0), P(1), ... , P(X). Here, P(i) is the probability of a heap havi...
Output a single real number, the probability that the first player wins. The answer will be judged as correct if it differs from the correct answer by at most 10 - 6.
null
null
[{"input": "2 2\n0.500000 0.250000 0.250000", "output": "0.62500000"}]
1,900
["games", "matrices", "probabilities"]
11
[{"input": "2 2\r\n0.500000 0.250000 0.250000\r\n", "output": "0.62500000\r\n"}, {"input": "9 9\r\n0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000\r\n", "output": "0.93687014\r\n"}, {"input": "1000001 5\r\n0.000000 0.300000 0.000000 0.500000 0.000000 0.200000\r\n", "output": "1...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] try: with open(correct_output_path, 'r') as f: correct_line = f.read().strip() correct_val = float(correct_line) except: print(0) retur...
true
66/C
66
C
Python 3
TESTS
0
30
0
205652350
foldersName = set() filesName = [] while True: try: path = input().strip() # Split path into folders and files folders = [] for folder in path.split("\\"): if "." not in folder: folders.append(folder) # Add folders and files to sets fold...
100
342
4,403,200
97929765
is_file = dict() edges = dict() used = dict() dirs_count = dict() files_count = dict() def dfs(key): dirs_count[key] = 1 - is_file.get(key, 0) files_count[key] = is_file.get(key, 0) used.setdefault(key, 1) for v in edges[key]: if used.get(v, 0) == 0: dfs(v) dirs_count[ke...
Codeforces Beta Round 61 (Div. 2)
CF
2,011
3
256
Petya and File System
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo...
Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file...
Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as fol...
null
In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1. In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder ...
[{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfi...
1,800
["data structures", "implementation"]
100
[{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4...
false
stdio
null
true
13/B
13
B
PyPy 3
TESTS
1
1,778
10,547,200
118548184
def dot(a,b): return a[0]*b[0] + a[1]*b[1] for _ in range(int(input())): points = [list(map(int,input().split())) for i in range(3)] points = [[points[i][:2],points[i][2:]] for i in range(3)] diff = [[[points[i][ti^1][k] - points[i][ti][k] for k in range(2)] for ti in range(2)] for i in range(3)] ...
2
528
409,600
69798233
""" A : Determine if three line segments form A """ def cross(vecA, vecB): return vecA[0] * vecB[1] - vecA[1] * vecB[0] def dot(vecA, vecB): return vecA[0] * vecB[0] + vecA[1] * vecB[1] def angle(lineA, lineB): x1, y1 = (lineA[0][0] - lineA[1][0], lineA[0][1] - lineA[1][1]) x2, y2 = (...
Codeforces Beta Round 13
ICPC
2,010
1
64
Letter A
Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A. You are given three segments on the plane. They form the letter A if the following conditions hold: - Two segments have common endpoint...
The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have pos...
Output one line for each test case. Print «YES» (without quotes), if the segments form the letter A and «NO» otherwise.
null
null
[{"input": "3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1", "output": "YES\nNO\nYES"}]
2,000
["geometry", "implementation"]
2
[{"input": "3\r\n4 4 6 0\r\n4 1 5 2\r\n4 0 4 4\r\n0 0 0 6\r\n0 6 2 -4\r\n1 1 0 1\r\n0 0 0 5\r\n0 5 2 -1\r\n1 2 0 1\r\n", "output": "YES\r\nNO\r\nYES\r\n"}]
false
stdio
null
true
474/F
474
F
PyPy 3
TESTS
1
390
5,529,600
202420101
import math def main(): n = int(input()) a = list(map(int, input().split())) t = int(input()) for _ in range(t): l, r = map(int, input().split()) l -= 1 r -= 1 gcd = math.gcd(a[l], a[r]) cnt = sum(1 for i in range(l, r + 1) if a[i] == gcd) print(r - l + 1...
65
608
23,756,800
188542239
## user: https://codeforces.com/contest/474/submission/122199538 import sys,os,io from sys import stdin from math import log, gcd, ceil from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from bisect import bisect_left , bisect_right import math alphabets = list('abcde...
Codeforces Round 271 (Div. 2)
CF
2,014
1
256
Ant colony
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices betwe...
The first line contains one integer n (1 ≤ n ≤ 105), the size of the ant colony. The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 109), the strengths of the ants. The third line contains one integer t (1 ≤ t ≤ 105), the number of test cases. Each of the next t lines contains two integers li and ri (1 ≤ ...
Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li, ri].
null
In the first test battle points for each ant are v = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5. In the second test case battle points are v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole. In the third test case battle points are v = [2, 0, 2], so ants number 3 and ...
[{"input": "5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5", "output": "4\n4\n1\n1"}]
2,100
["data structures", "math", "number theory"]
65
[{"input": "5\r\n1 3 2 4 2\r\n4\r\n1 5\r\n2 5\r\n3 5\r\n4 5\r\n", "output": "4\r\n4\r\n1\r\n1\r\n"}]
false
stdio
null
true
474/F
474
F
PyPy 3-64
TESTS
1
124
8,192,000
212136414
import sys import math def binary_search(nums, target): start, end = 0, len(nums) - 1 while end - start > 1: mid = (start + end) // 2 if target <= nums[mid]: end = mid else: start = mid if nums[start] >= target: return start if nums[end] >= target...
65
717
71,475,200
198901725
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 operator import mul inf = float("inf") PLATFOR...
Codeforces Round 271 (Div. 2)
CF
2,014
1
256
Ant colony
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices betwe...
The first line contains one integer n (1 ≤ n ≤ 105), the size of the ant colony. The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 109), the strengths of the ants. The third line contains one integer t (1 ≤ t ≤ 105), the number of test cases. Each of the next t lines contains two integers li and ri (1 ≤ ...
Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li, ri].
null
In the first test battle points for each ant are v = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5. In the second test case battle points are v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole. In the third test case battle points are v = [2, 0, 2], so ants number 3 and ...
[{"input": "5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5", "output": "4\n4\n1\n1"}]
2,100
["data structures", "math", "number theory"]
65
[{"input": "5\r\n1 3 2 4 2\r\n4\r\n1 5\r\n2 5\r\n3 5\r\n4 5\r\n", "output": "4\r\n4\r\n1\r\n1\r\n"}]
false
stdio
null
true
817/E
817
E
PyPy 3-64
TESTS
2
93
3,891,200
213147568
from collections import * from functools import * from itertools import * from operator import * from bisect import * from heapq import * import math import re import os import io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def I(): return input().decode('utf-8').strip() def II(base=10): ...
42
857
105,881,600
213145853
from collections import * from functools import * from itertools import * from operator import * from bisect import * from heapq import * import math import re import os import io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def I(): return input().decode('utf-8').strip() def II(base=10): ...
Educational Codeforces Round 23
ICPC
2,017
2
256
Choosing The Commander
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires. Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors. Ea...
The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events. Then q lines follow. Each line describes the event: - 1 pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army; - 2 pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova's army (it is guaranteed that there is at le...
For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.
null
In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him ($$4 \oplus 6 = 2$$, and 2 < 3, but $$3 \oplus 6 = 5$$, and 5 ≥ 3). Then warrior with personality 4 leaves, and w...
[{"input": "5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3", "output": "1\n0"}]
2,000
["bitmasks", "data structures", "trees"]
42
[{"input": "5\r\n1 3\r\n1 4\r\n3 6 3\r\n2 4\r\n3 6 3\r\n", "output": "1\r\n0\r\n"}]
false
stdio
null
true
397/B
397
B
Python 3
TESTS
0
109
0
46220368
t=int(input()) for i in range(t): n,l,r=map(int,input().split()) if r>n: print("NO") elif(l==r)and(n%l!=0): print("NO") elif l>n//2: print("NO") else: print("YES")
6
62
0
136741825
t=int(input()) while t>0: t-=1 n,l,r=map(int,input().split()) k=n//l if r*k>=n: print('Yes') else: print('No')
Codeforces Round 232 (Div. 2)
CF
2,014
1
256
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
null
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
[{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}]
null
["constructive algorithms", "implementation", "math"]
6
[{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38...
false
stdio
null
true
397/B
397
B
Python 3
TESTS
1
46
0
12519021
__author__ = 'aadityataparia' def is_sum(): m, l, r = (input()).split() m = int(m) l = int(l) r = int(r) jj=m poss=list(range(l,r+1)) j=len(poss)-1 while(j>=0): ab=poss[j] jj=jj%ab j-=1 if jj==0: return 'Yes' return'No' n = int(input())...
6
77
0
6759074
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) print("No" if n // l * r < n else "Yes")
Codeforces Round 232 (Div. 2)
CF
2,014
1
256
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
null
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
[{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}]
null
["constructive algorithms", "implementation", "math"]
6
[{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38...
false
stdio
null
true
355/B
355
B
Python 3
TESTS
0
15
0
232313765
cost=list(map(int,input().split())) n,m=map(int,input().split()) bus=list(map(int,input().split())) troller=list(map(int,input().split())) bt=0 tt=0 for num in bus: if num*cost[0]>=cost[1]: bt+=cost[1] else: bt+=cost[0]*num if bt>=cost[2]: bt=cost[2] if bt>= cost[3]: bt=cost[3] break print...
27
46
307,200
4782118
c1,c2,c3,c4 = map(int, input().split()) n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) suma = sum(min(c1*x, c2) for x in a) sumb = sum(min(c1*x, c2) for x in b) print(min(min(suma,c3) + min(sumb, c3), c4))
Codeforces Round 206 (Div. 2)
CF
2,013
1
256
Vasya and Public Transport
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one ride...
The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets. The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use. The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is go...
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
null
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles. In the second sample the profitable strategy is to buy one ticket of t...
[{"input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12"}, {"input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1"}, {"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16"}]
1,100
["greedy", "implementation"]
27
[{"input": "1 3 7 19\r\n2 3\r\n2 5\r\n4 4 4\r\n", "output": "12\r\n"}, {"input": "4 3 2 1\r\n1 3\r\n798\r\n1 2 3\r\n", "output": "1\r\n"}, {"input": "100 100 8 100\r\n3 5\r\n7 94 12\r\n100 1 47 0 42\r\n", "output": "16\r\n"}, {"input": "3 103 945 1000\r\n7 9\r\n34 35 34 35 34 35 34\r\n0 0 0 0 0 0 0 0 0\r\n", "output": ...
false
stdio
null
true
474/F
474
F
Python 3
TESTS
4
686
5,632,000
207153785
import math # Node class representing a node in the segment tree class Node: def __init__(self, value, gcd): self.value = value self.gcd = gcd # Function to build the segment tree def build_segment_tree(arr, tree, node, start, end): if start == end: tree[node] = Node(arr[start], arr[st...
65
889
60,211,200
196363549
import time import bisect import functools import math import os import random import re import sys import threading from collections import Counter, defaultdict, deque from copy import deepcopy from functools import cmp_to_key, lru_cache, reduce from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsma...
Codeforces Round 271 (Div. 2)
CF
2,014
1
256
Ant colony
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices betwe...
The first line contains one integer n (1 ≤ n ≤ 105), the size of the ant colony. The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 109), the strengths of the ants. The third line contains one integer t (1 ≤ t ≤ 105), the number of test cases. Each of the next t lines contains two integers li and ri (1 ≤ ...
Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li, ri].
null
In the first test battle points for each ant are v = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5. In the second test case battle points are v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole. In the third test case battle points are v = [2, 0, 2], so ants number 3 and ...
[{"input": "5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5", "output": "4\n4\n1\n1"}]
2,100
["data structures", "math", "number theory"]
65
[{"input": "5\r\n1 3 2 4 2\r\n4\r\n1 5\r\n2 5\r\n3 5\r\n4 5\r\n", "output": "4\r\n4\r\n1\r\n1\r\n"}]
false
stdio
null
true