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
177/E1
177
E2
PyPy 3-64
TESTS2
7
124
1,740,800
182769804
def BSMax(): l = 0 r = 1e18 ans = -1 while l <= r: m = (l+r)//2 curr = (int)(0) for i in range(0, n): curr += a[i]*m//b[i]+1 if curr==c: ans = (int)(m) if curr<=c: l = (int)(m+1) else: r = (int)(m-1) ...
21
218
0
51613361
a=[] b=[] n=0 def cal(x): p=0 global n,a,b for i in range(n): p+=((a[i]*x)//b[i]) return p n,c=map(int,input().split()) c-=n if c < 0: print(0) exit(0) a=[0]*n b=[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) L=1 R=10**18 lower=R+1 while L<=R : m=(L+R)>>1 if cal(m) >= c: lower=m R=m-1 else...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
181/A
181
A
Python 3
TESTS
7
186
307,200
90038961
n=list(map(int,input().split())) lst=[] lst1=[] s='' v='' c='' for i in range(n[0]): n1=input() lst.append(n1) for j in range(len(lst)): for k in range(len(lst[j])): if(lst[j][k]=='*'): lst1.append(str(j+1)+str(k+1)) lst1.sort() for z in lst1: s+=z[0] v+=z[1] for m in s: if(s...
36
92
0
136212135
# Matheus de Souza Oliveira - RA: 203407 rowsAndColumns = list(map(int, input().split())) numberOfRows = rowsAndColumns[0] numberOfColumns = rowsAndColumns[1] matrix = [] aux = numberOfRows rows = [] columns = [] while aux != 0: matrix.append([char for char in input()]) aux -= 1 foundRowIndex = -1 for rowIn...
Croc Champ 2012 - Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Series of Crimes
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n × m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked t...
The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 100) — the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if ...
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
null
null
[{"input": "3 2\n.*\n..\n**", "output": "1 1"}, {"input": "3 3\n*.*\n*..\n...", "output": "2 3"}]
800
["brute force", "geometry", "implementation"]
36
[{"input": "3 2\r\n.*\r\n..\r\n**\r\n", "output": "1 1\r\n"}, {"input": "3 3\r\n*.*\r\n*..\r\n...\r\n", "output": "2 3\r\n"}, {"input": "2 5\r\n*....\r\n*...*\r\n", "output": "1 5\r\n"}, {"input": "7 2\r\n..\r\n**\r\n..\r\n..\r\n..\r\n..\r\n.*\r\n", "output": "7 1\r\n"}, {"input": "8 8\r\n........\r\n.*......\r\n.........
false
stdio
null
true
455/B
455
B
PyPy 3-64
TESTS
70
327
48,947,200
224704911
import sys class Node: def __init__(self): self.children = {} self.is_end = False def visit(self): """ Returns [can_win, can_lose]. """ if len(self.children) == 0: return [False, True] can_win = False can_lose = False for ...
75
218
26,521,600
230712465
# LUOGU_RID: 132709230 # pypy3 from collections import * from itertools import * from functools import * from bisect import * from heapq import * import sys from math import gcd IN = lambda: sys.stdin.readline().rstrip("\r\n") PN = lambda x: sys.stdout.write(x) I = lambda: int(IN()) S = lambda: IN().split() M = lambd...
Codeforces Round 260 (Div. 1)
CF
2,014
1
256
A Lot of Games
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the re...
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.
If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).
null
null
[{"input": "2 3\na\nb", "output": "First"}, {"input": "3 1\na\nb\nc", "output": "First"}, {"input": "1 2\nab", "output": "Second"}]
1,900
["dfs and similar", "dp", "games", "implementation", "strings", "trees"]
75
[{"input": "2 3\r\na\r\nb\r\n", "output": "First\r\n"}, {"input": "3 1\r\na\r\nb\r\nc\r\n", "output": "First\r\n"}, {"input": "1 2\r\nab\r\n", "output": "Second\r\n"}, {"input": "5 6\r\nabas\r\ndsfdf\r\nabacaba\r\ndartsidius\r\nkolobok\r\n", "output": "Second\r\n"}, {"input": "4 2\r\naaaa\r\nbbbb\r\nccccc\r\ndumbavumba...
false
stdio
null
true
471/B
471
B
Python 3
TESTS
7
62
307,200
8370632
n = int(input()) h = [int(x) for x in input().split()] sh = sorted((x, i + 1) for i, x in enumerate(h)) val = [[], [], []] i, cur = 0, 0 while i < n: if i < n - 1 and cur < 2 and sh[i][0] == sh[i + 1][0]: val[cur].extend((sh[i][1], sh[i + 1][1])) val[cur + 1].extend((sh[i + 1][1], sh[i][1])) ...
31
62
307,200
7991009
n = int(input()) diff = input().split() o=enumerate(map(int,diff),1) tasks=list(o) tasks.sort(key = lambda diffi: diffi[1]) i = 0 while i < n - 1: if tasks[i][1] == tasks[i + 1][1]: break i += 1 j = i + 1 while j < n - 1: if tasks[j][1] == tasks[j + 1][1]: break j += 1 if j > n - 2: print('NO') else: ...
Codeforces Round 269 (Div. 2)
CF
2,014
1
256
MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order...
The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order t...
null
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only tw...
[{"input": "4\n1 3 3 1", "output": "YES\n1 4 2 3\n4 1 2 3\n4 1 3 2"}, {"input": "5\n2 4 1 4 8", "output": "NO"}]
1,300
["implementation", "sortings"]
31
[{"input": "4\r\n1 3 3 1\r\n", "output": "YES\r\n1 4 2 3 \r\n4 1 2 3 \r\n4 1 3 2 \r\n"}, {"input": "5\r\n2 4 1 4 8\r\n", "output": "NO"}, {"input": "8\r\n1 5 4 12 7 2 10 11\r\n", "output": "NO"}, {"input": "6\r\n5 1 2 5 2 4\r\n", "output": "YES\r\n2 3 5 6 1 4 \r\n2 5 3 6 1 4 \r\n2 5 3 6 4 1 \r\n"}, {"input": "1\r\n1083...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(input_path, output_path, submission_path): input_lines = read_file(input_path) n = int(input_lines[0]) h = list(map(int, input_lines[1].split())) ref_lines = read_file(output...
true
471/B
471
B
Python 3
TESTS
7
61
307,200
8518625
n = int(input()) arr = list(map(int, input().split())) counter = [0 for _ in range(2005)] lol = 0 for x in arr: counter[x] += 1 for x in range(1,2001): if counter[x] >= 2: lol += (counter[x] // 2) if lol >= 2: print("YES") ans = [] for x in range(len(arr)): ans.append((arr[x], x + 1)) ans.sort() print(' ...
31
62
409,600
7966316
n = int(input()) A = list(map(int, input().split())) D = [[] for i in range(2001)] for i in range(n): D[A[i]].append(i + 1) D1 = [] D2 = [] D3 = [] three = 0 two = 0 bla = True for i in range(1, 2001): if len(D[i]) >= 3: D1.extend(D[i]) D2.extend(D[i][::-1]) D3.extend(D[i][len(D[i]) // 2...
Codeforces Round 269 (Div. 2)
CF
2,014
1
256
MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order...
The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order t...
null
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only tw...
[{"input": "4\n1 3 3 1", "output": "YES\n1 4 2 3\n4 1 2 3\n4 1 3 2"}, {"input": "5\n2 4 1 4 8", "output": "NO"}]
1,300
["implementation", "sortings"]
31
[{"input": "4\r\n1 3 3 1\r\n", "output": "YES\r\n1 4 2 3 \r\n4 1 2 3 \r\n4 1 3 2 \r\n"}, {"input": "5\r\n2 4 1 4 8\r\n", "output": "NO"}, {"input": "8\r\n1 5 4 12 7 2 10 11\r\n", "output": "NO"}, {"input": "6\r\n5 1 2 5 2 4\r\n", "output": "YES\r\n2 3 5 6 1 4 \r\n2 5 3 6 1 4 \r\n2 5 3 6 4 1 \r\n"}, {"input": "1\r\n1083...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(input_path, output_path, submission_path): input_lines = read_file(input_path) n = int(input_lines[0]) h = list(map(int, input_lines[1].split())) ref_lines = read_file(output...
true
355/B
355
B
PyPy 3
TESTS
11
139
1,228,800
55958926
a,b,c,d=list(map(int,input().split())) n,m=list(map(int,input().split())) s=u=0 p=list(map(int,input().split())) q=list(map(int,input().split())) for i in range(n): t=0 t=t+p[i]*a if(t>b): t=b s=s+t if(s>c): s=c for i in range(m): t=0 t=t+q[i]*b if(t>b): t=b u=u+t if(u>c): u=c if(s+u>d): print(d) else: ...
27
46
0
158131978
import sys input = sys.stdin.readline 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())) z = c2/c1 s1, s2 = 0, 0 for i in a: if i > z: s1 += c2 else: s1 += c1*i for i in b: if i > z: ...
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
11/A
11
A
Python 3
TESTS
24
124
307,200
26991310
x=input() x=x.split() arreglo=input() arreglo=arreglo.split() suma=0 contador=0 k=-1 for a in range (1,int(x[0])): if int(arreglo[1])==int(arreglo[a]): contador=contador+1 if contador==(int(x[0])-1) and int(x[0])>2: suma=(contador*(contador+1))//2 else: for p in range (1,len(arre...
25
62
0
162616406
import math n, d =list(map(int,input().split())) inp=list(map(int,input().split())) ans=0 for i in range(n-1): if(inp[i+1]<=inp[i]): z=inp[i]-inp[i+1]+1 k=math.ceil(z/d) ans+=k inp[i+1]=k*d + inp[i+1] print(ans)
Codeforces Beta Round 11
ICPC
2,010
1
64
Increasing Sequence
A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t. You are given a sequence b0, b1, ..., bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasin...
The first line of the input contains two integer numbers n and d (2 ≤ n ≤ 2000, 1 ≤ d ≤ 106). The second line contains space separated sequence b0, b1, ..., bn - 1 (1 ≤ bi ≤ 106).
Output the minimal number of moves needed to make the sequence increasing.
null
null
[{"input": "4 2\n1 3 3 2", "output": "3"}]
900
["constructive algorithms", "implementation", "math"]
25
[{"input": "4 2\r\n1 3 3 2\r\n", "output": "3\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 1\r\n2 5\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 7\r\n10 20\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 1\r\n...
false
stdio
null
true
607/B
607
B
PyPy 3-64
TESTS
14
389
7,475,200
201251330
n=int(input()) a=list(map(int,input().split())) if n==500 and a[1]==2: print(*a[250:400]) x=[1, 2, 3, 3, 1, 3, 2, 1, 1, 2, 1, 1, 2, 1, 1, 3, 3, 1, 1, 1, 1, 3, 1, 3, 2, 2, 3, 2, 3, 3, 1, 1, 2, 1, 2, 1, 3, 2, 2, 2, 3, 3, 2, 2, 3, 2, 3, 3, 3, 1, 2, 2, 3, 3, 1, 3, 2, 1, 3, 2, 2, 1, 3, 1, 2, 2, 3, 2, 3, 3, 3, 3, 2, 3, 2...
103
296
9,318,400
226549668
n = int(input()) gems = list(map(int, input().split())) dp = [[0] * n for _ in range(n)] def helper(i, j): if i < 0 or i >= n or j < 0 or j >= n: return 0 if dp[i][j] != 0: return dp[i][j] if i >= j: dp[i][j] = 1 else: b = 10e9 for k in range(i, j): ...
Codeforces Round 336 (Div. 1)
CF
2,015
2
512
Zuma
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
The first line of input contains a single integer n (1 ≤ n ≤ 500) — the number of gemstones. The second line contains n space-separated integers, the i-th of which is ci (1 ≤ ci ≤ n) — the color of the i-th gemstone in a line.
Print a single integer — the minimum number of seconds needed to destroy the entire line.
null
In the first sample, Genos can destroy the entire line in one second. In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds. In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 ...
[{"input": "3\n1 2 1", "output": "1"}, {"input": "3\n1 2 3", "output": "3"}, {"input": "7\n1 4 4 2 3 2 1", "output": "2"}]
1,900
["dp"]
103
[{"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "7\r\n1 4 4 2 3 2 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n"}, {"input": "8\r\n1 2 1 3 4 1 2 1...
false
stdio
null
true
606/B
606
B
PyPy 3
TESTS
14
483
31,539,200
19665320
x, y, x0, y0=list(map(int, input().split())) P=set() s=input() c=1 print(1, end=' ') for i in range(len(s)-1): if s[i] =='L': if y0>=2: y0-=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) else: print(0, end=' ') if s[i] =='R': if y0<y: y0+=1 if (x0, y0) i...
68
155
11,776,000
23077066
def tests(mr, mc, r0, c0, path): seen = set() r, c = r0, c0 for d in path: if (r, c) in seen: yield 0 else: seen.add((r, c)) yield 1 if d == 'U': if r > 1: r -= 1 elif d == 'D': if r < mr: ...
Codeforces Round 335 (Div. 2)
CF
2,015
2
256
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should b...
Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.
null
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: $$(2,2)\rightarrow(1,2)\rightarrow(1,3)\rightarrow(2,4)\rightarrow(3,3)$$.
[{"input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6"}, {"input": "2 2 2 2\nULD", "output": "1 1 1 1"}]
1,600
["implementation"]
68
[{"input": "3 4 2 2\r\nUURDRDRL\r\n", "output": "1 1 0 1 1 1 1 0 6\r\n"}, {"input": "2 2 2 2\r\nULD\r\n", "output": "1 1 1 1\r\n"}, {"input": "1 1 1 1\r\nURDLUURRDDLLURDL\r\n", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n"}, {"input": "15 17 8 9\r\nURRDLUULLDD\r\n", "output": "1 1 1 1 1 1 0 1 1 1 1 245\r\n"}, {"inp...
false
stdio
null
true
297/B
297
B
PyPy 3-64
TESTS
10
156
15,155,200
165681978
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n>m: print("YES") else: if sum(a)>sum(b) or max(a)>max(b): print("YES") else: print("NO")
62
374
28,774,400
165640326
import collections import os import sys from collections import Counter if os.getenv('LOCALCFTEST'): sys.stdin = open('cfinput.txt') MOD = 10 ** 9 + 7 def solve(n, m, k, a, b): cnt = collections.defaultdict(int) for i in a: cnt[i] += 1 for i in b: cnt[i] -= 1 s = 0 for i in so...
Codeforces Round 180 (Div. 1)
CF
2,013
1
256
Fish Weight
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are g...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the l...
Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise.
null
In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish.
[{"input": "3 3 3\n2 2 2\n1 1 3", "output": "YES"}, {"input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7", "output": "NO"}]
1,600
["constructive algorithms", "greedy"]
62
[{"input": "3 3 3\r\n2 2 2\r\n1 1 3\r\n", "output": "YES\r\n"}, {"input": "4 7 9\r\n5 2 7 3\r\n3 5 2 7 3 8 7\r\n", "output": "NO\r\n"}, {"input": "5 5 10\r\n8 2 8 5 9\r\n9 1 7 5 1\r\n", "output": "YES\r\n"}, {"input": "7 7 10\r\n8 2 8 10 6 9 10\r\n2 4 9 5 6 2 5\r\n", "output": "YES\r\n"}, {"input": "15 15 10\r\n4 5 9 1...
false
stdio
null
true
157/A
157
A
Python 3
TESTS
8
124
6,963,200
126018185
import bisect n = int(input()) a = [] rs = [] cs = [0 for _ in range(n)] for _ in range(n): r = [int(x) for x in input().split()] s = 0 for c in range(n): v = r[c] s += v cs[c] += v rs.append(s) cs.sort() ret = 0 for r in rs: ret += bisect.bisect_left(cs, r) print(ret)
49
92
0
170523889
n=int(input()) a=[] for _ in range(n): l=list(map(int,input().split())) a.append(l) sr=[] sc=[] c=0 for i in range(n): sr.append(sum(a[i])) for i in range(n): s=0 for j in range(n): s+=a[j][i] sc.append(s) for x in sc: for y in sr: if x>y: c+=1 print(c)
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
157/A
157
A
PyPy 3-64
TESTS
8
124
0
167028284
n = int(input()) a = [] rows = [0 for i in range(n)] cols = [0 for i in range(n)] for i in range(n): a.append(list(map(int, input().split()))) rows[i] = sum(a[i]) cnt = 0 for j in range(n): s = 0 for i in range(n): s += a[i][j] cols[j] = s for i in range(n): for j in range(n): ...
49
92
0
174368002
n = int(input()) lst,row,col = [],[],[] ans=0 for _ in range(n): z = list(map(int, input().split())) lst.append(z) row.append(sum(z)) for i in range(n): z=[] for j in range(n): z.append(lst[j][i]) col.append(sum(z)) for i in range(n): for j in range(n): if col[i]>...
Codeforces Round 110 (Div. 2)
CF
2,012
2
256
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
null
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
[{"input": "1\n1", "output": "0"}, {"input": "2\n1 2\n3 4", "output": "2"}, {"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6"}]
800
["brute force"]
49
[{"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "4\r\n5 7 8 4\r\n9 5 3 2\r\n1 6 6 4\r\n9 5 7 3\r\n", "output": "6\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2 ...
false
stdio
null
true
181/A
181
A
Python 3
TESTS
7
216
0
55277329
n,m=map(int,input().split()) a=[input() for i in range(n)] c=[] d=[] for i in range(n): for j in range(m): if a[i][j]=="*": c.append(i+1) d.append(j+1) c=list(map(str,c)) d=list(map(str,d)) k=''.join(c) l=''.join(d) # print(k,l) for i in range(3): if k.count(k[i])==1: print(int(k[i]),end=' ') for i in r...
36
92
0
136258031
l, c = map(int, input().split()) matriz = [] ps = [] for i in range(l): for j, char in enumerate(input()): if(char=="*"): ps.append((i,j)) if(ps[1][0] - ps[0][0]!=0): if(ps[0][1]==ps[-1][1]): print(ps[0][0]+1, ps[1][1]+1) else: print(ps[0][0]+1, ps[-1][1]+1) else: if(ps[-1][1]==ps[0][1]): ...
Croc Champ 2012 - Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Series of Crimes
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n × m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked t...
The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 100) — the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if ...
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
null
null
[{"input": "3 2\n.*\n..\n**", "output": "1 1"}, {"input": "3 3\n*.*\n*..\n...", "output": "2 3"}]
800
["brute force", "geometry", "implementation"]
36
[{"input": "3 2\r\n.*\r\n..\r\n**\r\n", "output": "1 1\r\n"}, {"input": "3 3\r\n*.*\r\n*..\r\n...\r\n", "output": "2 3\r\n"}, {"input": "2 5\r\n*....\r\n*...*\r\n", "output": "1 5\r\n"}, {"input": "7 2\r\n..\r\n**\r\n..\r\n..\r\n..\r\n..\r\n.*\r\n", "output": "7 1\r\n"}, {"input": "8 8\r\n........\r\n.*......\r\n.........
false
stdio
null
true
892/B
892
B
Python 3
TESTS
11
1,231
76,492,800
147216582
n = int(input()) l = list(map(int,input().split())) dead = {} c = 0 for i in range(n): l[i]=i-l[i] j = n-1 mi = 1000000000 least = j while j>0: if l[j]<0: c+=abs(min(j,mi+1)-0) break if l[j]<mi: mi = l[j] for i in range(mi,j): dead[i]=1 least = j j-=1...
43
280
68,710,400
184019382
def main(): n = get_int() claws = get_list_int() alive_mark = n - 1 alive = 0 for i in range(n - 1, -1, -1): if i == alive_mark: alive += 1 claw = claws[i] alive_mark = min(alive_mark, i - claw - 1) print(alive) def get_int() -> int: return int(input...
Codeforces Round 446 (Div. 2)
CF
2,017
2
256
Wrath
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
null
In first sample the last person kills everyone in front of him.
[{"input": "4\n0 1 0 10", "output": "1"}, {"input": "2\n0 0", "output": "2"}, {"input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3"}]
1,200
["greedy", "implementation", "two pointers"]
43
[{"input": "4\r\n0 1 0 10\r\n", "output": "1\r\n"}, {"input": "2\r\n0 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 3 0 0 0 2 1 0 3\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 2 0 0 3 3 2 2 0\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n0 0 0 1 0\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
895/D
895
D
Python 3
PRETESTS
9
1,403
31,232,000
32690261
a = input().strip() b = input().strip() MOD = 10**9 + 7 f = [1]*(10**6+1) inv = [1]*(10**6 + 1) st = 1 for i in range(1, 10**6 + 1): st = st*i % MOD f[i] = st if i < 10**5: inv[i] = pow(st, MOD - 2, MOD) def ways(sez): vrni = f[sum(sez)] for x in sez: if x < len(inv): ...
60
764
47,206,400
179991485
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline a = list(input().rstrip()) b = list(input().rstrip()) a = [i - 97 for i in a] b = [i - 97 for i in b] n = len(a) mod = pow(10, 9) + 7 cnt = [0] * 26 for i in a: cnt[i] += 1 l = n + 5 fact = [1] * (l + 1) for i in range(1, l + 1): f...
Codeforces Round 448 (Div. 2)
CF
2,017
4
256
String Mark
At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexicographically smaller than x. Recently at the BSU was an important test work on which Vasya recived the mark a. It is very hard for the teacher to remember the exact mark of every student, but h...
First line contains string a, second line contains string b. Strings a, b consist of lowercase English letters. Their lengths are equal and don't exceed 106. It is guaranteed that a is lexicographically smaller than b.
Print one integer  — the number of different strings satisfying the condition of the problem modulo 109 + 7.
null
In first sample from string abc can be obtained strings acb, bac, bca, cab, cba, all of them are larger than abc, but smaller than ddd. So the answer is 5. In second sample any string obtained from abcdef is larger than abcdeg. So the answer is 0.
[{"input": "abc\nddd", "output": "5"}, {"input": "abcdef\nabcdeg", "output": "0"}, {"input": "abacaba\nubuduba", "output": "64"}]
2,100
["combinatorics", "math", "strings"]
60
[{"input": "abc\r\nddd\r\n", "output": "5\r\n"}, {"input": "abcdef\r\nabcdeg\r\n", "output": "0\r\n"}, {"input": "abacaba\r\nubuduba\r\n", "output": "64\r\n"}, {"input": "aac\r\nbbb\r\n", "output": "1\r\n"}, {"input": "aaaccc\r\nbbbbbb\r\n", "output": "9\r\n"}, {"input": "aaaaaa\r\nzzzzzz\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
181/A
181
A
Python 3
TESTS
5
92
0
187059950
n = input() m = int(n[2]) n = int(n[0]) for i in range(n) : robery = input() # Robery string. if '*' in robery and robery.count('*') == 1: row = i + 1 col = robery.index('*') + 1 if '*' in robery and robery.count('*') == 2 : # Count of star is two. c1 ...
36
92
0
136271012
n, m = input().split(' ') n = int(n) m = int(m) v = [] u = [] w = [] for i in range(0, n): b = input() v.append(list(b)) for i in range(0, n): for j in range(0, m): if v[i][j] == '*': u.append(i+1) w.append(j+1) for i in u: if u.count(i) == 1: x = i break for i in w: if w.count(...
Croc Champ 2012 - Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Series of Crimes
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n × m rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked t...
The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 100) — the number of rows and columns in the table, correspondingly. Each of the next n lines contains m characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if ...
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
null
null
[{"input": "3 2\n.*\n..\n**", "output": "1 1"}, {"input": "3 3\n*.*\n*..\n...", "output": "2 3"}]
800
["brute force", "geometry", "implementation"]
36
[{"input": "3 2\r\n.*\r\n..\r\n**\r\n", "output": "1 1\r\n"}, {"input": "3 3\r\n*.*\r\n*..\r\n...\r\n", "output": "2 3\r\n"}, {"input": "2 5\r\n*....\r\n*...*\r\n", "output": "1 5\r\n"}, {"input": "7 2\r\n..\r\n**\r\n..\r\n..\r\n..\r\n..\r\n.*\r\n", "output": "7 1\r\n"}, {"input": "8 8\r\n........\r\n.*......\r\n.........
false
stdio
null
true
74/A
74
A
PyPy 3-64
TESTS
7
124
0
225732296
n=int(input()) a=[] b=[] for i in range(n): x,y,z,r,s,t,u,v=input().split() q=int(y)*100-int(z)*50+int(r)+int(s)+int(t)+int(u)+int(v) a.append(q) b.append(x) q=0 for i in range(n): q=max(a[i],q) for j in range(n): if a[j]==q: print(b[j])
32
92
0
153816738
t = int(input()) output = [] scores = [] for _ in range(t): score = 0 info = input().split() handle, successful, failure, a, b, c, d, e = info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7] output.append(info) score += (100 * int(successful)) score -= (50 * int(failure)) s...
Codeforces Beta Round 68
CF
2,011
2
256
Room Leader
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document. In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five proble...
The first line contains an integer n, which is the number of contestants in the room (1 ≤ n ≤ 50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessf...
Print on the single line the handle of the room leader.
null
The number of points that each participant from the example earns, are as follows: - Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R —  - 350 - some_participant — 2220 Thus, the leader of the room is tourist.
[{"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0", "output": "tourist"}]
1,000
["implementation"]
32
[{"input": "5\r\nPetr 3 1 490 920 1000 1200 0\r\ntourist 2 0 490 950 1100 1400 0\r\nEgor 7 0 480 900 950 0 1000\r\nc00lH4x0R 0 10 150 0 0 0 0\r\nsome_participant 2 1 450 720 900 0 0\r\n", "output": "tourist"}, {"input": "1\r\nA 0 0 200 0 0 0 0\r\n", "output": "A"}, {"input": "2\r\n12345678901234567890 1 0 200 0 0 0 0\r...
false
stdio
null
true
892/B
892
B
PyPy 3
TESTS
11
1,169
77,516,800
56488585
def answer(a,n): i,j = n-1,n-1 ans = n while i > 0: if i < j: j = i if a[i] != 0: tmp = i - a[i] if tmp < 0: ans-=i break if tmp < j: ans-=(j-tmp) j = tmp i-=1 return ...
43
296
92,979,200
220794142
n = int(input()) L = [int(i) for i in input().split()] x = n-1-L[n-1] total = 1 for i in range(n-2, -1, -1): total += (x > i) x = min(x, i-L[i]) print(total)
Codeforces Round 446 (Div. 2)
CF
2,017
2
256
Wrath
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
null
In first sample the last person kills everyone in front of him.
[{"input": "4\n0 1 0 10", "output": "1"}, {"input": "2\n0 0", "output": "2"}, {"input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3"}]
1,200
["greedy", "implementation", "two pointers"]
43
[{"input": "4\r\n0 1 0 10\r\n", "output": "1\r\n"}, {"input": "2\r\n0 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 3 0 0 0 2 1 0 3\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 2 0 0 3 3 2 2 0\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n0 0 0 1 0\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
892/B
892
B
PyPy 3
TESTS
11
1,122
114,995,200
36766871
n = int(input()) l = list(map(int,input().split())) cnt = n if n != 1: if l[-1] >= n-1: cnt = 1 else: cnt -= l[-1] next = (n-1) - l[-1] for i in range(n-2,0,-1): if l[i] > i: cnt -= i break if i > next: if i-...
43
296
93,081,600
211958916
def alive_people(n, L): x = n # minimum of j - Lj for all j > i alive = 0 # the number of people who are still alive for i in range(n - 1, -1, -1): # if x > i, the i-th person will be alive if x > i: alive += 1 # update x x = min(x, i - L[i]) return alive ...
Codeforces Round 446 (Div. 2)
CF
2,017
2
256
Wrath
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
null
In first sample the last person kills everyone in front of him.
[{"input": "4\n0 1 0 10", "output": "1"}, {"input": "2\n0 0", "output": "2"}, {"input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3"}]
1,200
["greedy", "implementation", "two pointers"]
43
[{"input": "4\r\n0 1 0 10\r\n", "output": "1\r\n"}, {"input": "2\r\n0 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 3 0 0 0 2 1 0 3\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 2 0 0 3 3 2 2 0\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n0 0 0 1 0\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
892/B
892
B
PyPy 3
TESTS
11
1,075
78,643,200
85820937
n=int(input()) arr=list(map(int,input().split())) alive=[1]*n if arr[-1]>=n-1: print(1) else: i=1 while i<n: if arr[i]>0: if i-arr[i]>=0: alive[i-arr[i]: i]=[0]*arr[i] else: alive[0: i]=[0]*arr[i] i=i+1 else: i=i...
43
327
117,452,800
173668931
import sys from math import gcd from collections import Counter as cc input=sys.stdin.readline I = lambda : list(map(int,input().split())) t,=[1] for _ in range(t): n, = I() an = 0 l = I();reach = n for i in range(n-1,-1,-1): if i<reach: an+=1 reach = min(reach,i-l[i]) print(an)
Codeforces Round 446 (Div. 2)
CF
2,017
2
256
Wrath
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
null
In first sample the last person kills everyone in front of him.
[{"input": "4\n0 1 0 10", "output": "1"}, {"input": "2\n0 0", "output": "2"}, {"input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3"}]
1,200
["greedy", "implementation", "two pointers"]
43
[{"input": "4\r\n0 1 0 10\r\n", "output": "1\r\n"}, {"input": "2\r\n0 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 3 0 0 0 2 1 0 3\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 2 0 0 3 3 2 2 0\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n0 0 0 1 0\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
892/B
892
B
PyPy 3
TESTS
11
982
79,257,600
85869857
n=int(input()) a=list(map(int,input().split())) alive=[1]*n if a[-1]>=n-1: print(1) else: for i in range(1,n): k=a[i] if i-k<0: alive[0:i]=[0]*k else: alive[i-k:i]=[0]*k ans=alive.count(1) print(ans)
43
343
112,128,000
219076403
n = int(input()) L = list(map(int, input().split())) answer = 0 current_person = n - 1 last_person_alive = n - 1 while last_person_alive >= 0 and current_person >= 0: if current_person <= last_person_alive: answer += 1 last_person_alive = min(current_person - L[current_person] - 1, last_person_alive) ...
Codeforces Round 446 (Div. 2)
CF
2,017
2
256
Wrath
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
null
In first sample the last person kills everyone in front of him.
[{"input": "4\n0 1 0 10", "output": "1"}, {"input": "2\n0 0", "output": "2"}, {"input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3"}]
1,200
["greedy", "implementation", "two pointers"]
43
[{"input": "4\r\n0 1 0 10\r\n", "output": "1\r\n"}, {"input": "2\r\n0 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 3 0 0 0 2 1 0 3\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 2 0 0 3 3 2 2 0\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n0 0 0 1 0\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
892/B
892
B
Python 3
TESTS
11
857
77,107,200
58103026
n = int(input()) a = list(map(int, input().split())) s = n l, r = n - 1, n - 1 for i in range (n - 1, -1, -1): r = i - a[i] if a[i] == 0 and l == i: l -= 1 if r >= 0: if r < l: s -= (l - r) l = r else: s -= i break print(s)
43
358
118,886,400
190908078
N = int(input()) nums = list(map(int, input().split())) claw = 0 ans = 0 for n in nums[::-1]: if claw == 0: ans += 1 claw = n else: claw = max(claw - 1, n) print(ans)
Codeforces Round 446 (Div. 2)
CF
2,017
2
256
Wrath
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
null
In first sample the last person kills everyone in front of him.
[{"input": "4\n0 1 0 10", "output": "1"}, {"input": "2\n0 0", "output": "2"}, {"input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3"}]
1,200
["greedy", "implementation", "two pointers"]
43
[{"input": "4\r\n0 1 0 10\r\n", "output": "1\r\n"}, {"input": "2\r\n0 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 3 0 0 0 2 1 0 3\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 2 0 0 3 3 2 2 0\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n0 0 0 1 0\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
471/B
471
B
Python 3
TESTS
7
62
1,331,200
11713719
__author__ = 'Sandi' import sys from itertools import permutations from collections import defaultdict from functools import reduce def bp(): exit(); def isOK(p, mapping): new = list() for i in p: add = mapping[i-1][0] new.append(add) prev = -1 for i in new: if i < prev: ...
31
62
409,600
8143565
n,inp = int(input()),input().split(" ") dict = [ [i,int(inp[i])] for i in range(n)] dict.sort(key=lambda i: i[1]) val = [i[1] for i in dict] f = [i[0]+1 for i in dict] i = p = 0 if len(val) - len(set(val)) < 2: print("NO") else: print("YES") print(" ".join(map(str,f))) for i in range(n): if val[...
Codeforces Round 269 (Div. 2)
CF
2,014
1
256
MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order...
The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order t...
null
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only tw...
[{"input": "4\n1 3 3 1", "output": "YES\n1 4 2 3\n4 1 2 3\n4 1 3 2"}, {"input": "5\n2 4 1 4 8", "output": "NO"}]
1,300
["implementation", "sortings"]
31
[{"input": "4\r\n1 3 3 1\r\n", "output": "YES\r\n1 4 2 3 \r\n4 1 2 3 \r\n4 1 3 2 \r\n"}, {"input": "5\r\n2 4 1 4 8\r\n", "output": "NO"}, {"input": "8\r\n1 5 4 12 7 2 10 11\r\n", "output": "NO"}, {"input": "6\r\n5 1 2 5 2 4\r\n", "output": "YES\r\n2 3 5 6 1 4 \r\n2 5 3 6 1 4 \r\n2 5 3 6 4 1 \r\n"}, {"input": "1\r\n1083...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(input_path, output_path, submission_path): input_lines = read_file(input_path) n = int(input_lines[0]) h = list(map(int, input_lines[1].split())) ref_lines = read_file(output...
true
549/D
549
D
Python 3
PRETESTS
1
61
0
11472974
def f(x, y): global s global t i = 0 while i <= x: j = 0 while j <= y: if s[i][j] == 'W': s[i][j] = 'B' else: s[i][j] = 'W' j += 1 i += 1 a, b = list(map(int, input().split())) s = [] for i in range(a): s.app...
47
77
0
31212944
n,m=[int(i) for i in input().split()] l=[] for i in range(n): l.append(input()) la=[0 for i in range(m)] s=0 for i in range(n-1,-1,-1): cv=0 for j in range(m-1,-1,-1): la[j]+=cv if l[i][j]=='W': if la[j]!=1: cv+=1-la[j] la[j]=1 s+=1...
Looksery Cup 2015
CF
2,015
1
256
Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represent...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if i...
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
null
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: 1. add the sum of pixels in...
[{"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "2"}, {"input": "3 3\nWBW\nBWW\nWWW", "output": "4"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "output": "3"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "output": "4"}]
1,900
["greedy", "implementation"]
47
[{"input": "6 8\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "3 3\r\nWBW\r\nBWW\r\nWWW\r\n", "output": "4\r\n"}, {"input": "3 6\r\nWWBBWW\r\nWWBBWW\r\nWWBBWW\r\n", "output": "3\r\n"}, {"input": "4 4\r\nBBBB\r\nBBBB\r\nBBBB\r\nBBBW\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
549/D
549
D
PyPy 3
PRETESTS
4
93
0
11474107
__author__ = 'Данила' n, m = map(int, input().split()) mat = [['' for i in range(m)] for j in range(n)] for i in range(n): s = input().rstrip() for j in range(len(s)): mat[i][j] = s[j] mat1 = [[0 for i in range(m)] for j in range(n)] mat1[0][0] = 1 for i in range(1, m): if mat[0][i] != mat[0][i -...
47
109
1,433,600
11545628
# -*- coding: utf-8 -*- a = [] k = [] n, m = map(int, input().split()) for i in range(n + 1): if i < n: a.append(input()) k.append([0 for j in range(m + 1)]) ans = 0 for i in range(n - 1, -1, -1): add = 0 for j in range(m - 1, -1, -1): sign = 1 if a[i][j] == 'B': ...
Looksery Cup 2015
CF
2,015
1
256
Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represent...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if i...
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
null
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: 1. add the sum of pixels in...
[{"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "2"}, {"input": "3 3\nWBW\nBWW\nWWW", "output": "4"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "output": "3"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "output": "4"}]
1,900
["greedy", "implementation"]
47
[{"input": "6 8\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "3 3\r\nWBW\r\nBWW\r\nWWW\r\n", "output": "4\r\n"}, {"input": "3 6\r\nWWBBWW\r\nWWBBWW\r\nWWBBWW\r\n", "output": "3\r\n"}, {"input": "4 4\r\nBBBB\r\nBBBB\r\nBBBB\r\nBBBW\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
549/D
549
D
Python 3
TESTS
4
61
307,200
31200098
n,m=[int(i) for i in input().split()] l=[] for i in range(n): l.append(input()) def fun(): global l l1=[[0 for i in range(m)] for j in range(n)] for i in range(n): for j in range(m): c=l[i][j] if j+1<m and l[i][j+1]!=c: if i+1>=n or (l[i+1][j]!=c and l[i+1...
47
109
24,064,000
32458046
n, m = map(int, input().split()) p = [input() for i in range(n)] t = [0] * m k = 0 for i in range(1, n + 1): s = 0 for j in range(1, m + 1): s += t[-j] q = s + 2 * (p[-i][-j] == 'W') - 1 t[-j] -= q s -= q if q: k += 1 print(k)
Looksery Cup 2015
CF
2,015
1
256
Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represent...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if i...
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
null
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: 1. add the sum of pixels in...
[{"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "2"}, {"input": "3 3\nWBW\nBWW\nWWW", "output": "4"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "output": "3"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "output": "4"}]
1,900
["greedy", "implementation"]
47
[{"input": "6 8\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "3 3\r\nWBW\r\nBWW\r\nWWW\r\n", "output": "4\r\n"}, {"input": "3 6\r\nWWBBWW\r\nWWBBWW\r\nWWBBWW\r\n", "output": "3\r\n"}, {"input": "4 4\r\nBBBB\r\nBBBB\r\nBBBB\r\nBBBW\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
4/D
4
D
PyPy 3-64
TESTS
3
46
0
210746779
import sys def input(): return sys.stdin.readline().strip() n,wc,hc=map(int,input().split()) s=set() L=[] for i in range(n): w,h=map(int,input().split()) L.append((w,h)) s.add((w,h)) d={} for x in s: d[x]=0 for i in range(n): d[L[i]]=i+1 myKeys = list(d.keys()) myKeys.sort() sorted_dict = {i: d[i] f...
33
373
10,547,200
218728491
import sys input = sys.stdin.readline n, w, h = map(int, input().split()) d = [(w, h, 0)] for i in range(n): a, b = map(int, input().split()) if a > w and b > h: d.append((a, b, i+1)) d.sort() m = len(d) x = [(1, 0) for i in range(m)] if len(d) == 1: print(0) exit() for i in range(1, m): fo...
Codeforces Beta Round 4 (Div. 2 Only)
ICPC
2,010
1
64
Mysterious Present
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the heigh...
The first line contains integers n, w, h (1 ≤ n ≤ 5000, 1 ≤ w, h ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi, hi ≤ 106).
In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, pr...
null
null
[{"input": "2 1 1\n2 2\n2 2", "output": "1\n1"}, {"input": "3 3 3\n5 4\n12 11\n9 8", "output": "3\n1 3 2"}]
1,700
["dp", "sortings"]
33
[{"input": "2 1 1\r\n2 2\r\n2 2\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 3 3\r\n5 4\r\n12 11\r\n9 8\r\n", "output": "3\r\n1 3 2 \r\n"}, {"input": "5 10 10\r\n22 23\r\n17 19\r\n13 17\r\n8 12\r\n2 6\r\n", "output": "3\r\n3 2 1 \r\n"}, {"input": "5 13 13\r\n4 4\r\n10 10\r\n7 7\r\n1 1\r\n13 13\r\n", "output": "0\r\n"},...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] input_lines = read_file_lines(input_path) if not input_lines: print(0) ...
true
1298/D
978
E
PyPy 3-64
TESTS
4
77
2,764,800
168025971
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import operator import sys input = sys.stdin.readline def lower_bound(lo, hi, key): ans = None while lo <= hi: mid = (lo + hi) // 2 if key...
42
46
0
208638886
n, w = map(int, input().split()) a = list(map(int, input().split())) minn = a[0] maxx = a[0] for i in range(1, n): a[i] += a[i-1] minn = min(minn, a[i]) maxx = max(maxx, a[i]) start, end = 0, 0 if maxx < 0: start = -minn end = w elif minn > 0: start = 0 end = w - maxx else: start = -...
Kotlin Heroes: Practice 3
ICPC
2,020
1
256
Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus ...
The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded...
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
null
In the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers. In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers. In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.
[{"input": "3 5\n2 1 -3", "output": "3"}, {"input": "2 4\n-1 1", "output": "4"}, {"input": "4 10\n2 4 1 2", "output": "2"}]
null
["*special", "combinatorics", "math"]
42
[{"input": "3 5\r\n2 1 -3\r\n", "output": "3\r\n"}, {"input": "2 4\r\n-1 1\r\n", "output": "4\r\n"}, {"input": "4 10\r\n2 4 1 2\r\n", "output": "2\r\n"}, {"input": "2 10\r\n-1 2\r\n", "output": "9\r\n"}, {"input": "3 4\r\n-3 -4 4\r\n", "output": "0\r\n"}, {"input": "10 1\r\n-1 -1 3 -4 2 3 0 -3 3 2\r\n", "output": "0\r\...
false
stdio
null
true
547/D
547
D
PyPy 3
TESTS
7
124
1,433,600
98764461
import operator as op from sys import stdin,stdout f_range=range f_len=len def FuerzaBruta(points): answer=[0]*f_len(points) answer[0]=color=0 p=sorted(points,key=op.itemgetter(0,1)) for i in f_range(f_len(points)): flag=False if(i==f_len(p)-1): break if p[i]...
50
889
112,640,000
224152629
from sys import stdin, stdout from collections import defaultdict time = 0 c = 2*10**5 n = 4*10**5+2 col = 0 finished= [0]*n for_node = [0]*n f_range=range f_len=len def dfs_euler_tour(node: int, graph): stack = [] global colour global col global time stack.append((node, -1)) while stack: ...
Codeforces Round 305 (Div. 1)
CF
2,015
3
256
Mike and Fish
As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the diff...
The first line of input contains integer n (1 ≤ n ≤ 2 × 105). The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates. It is guaranteed that there is at least one valid answer.
Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point.
null
null
[{"input": "4\n1 1\n1 2\n2 1\n2 2", "output": "brrb"}, {"input": "3\n1 1\n1 2\n2 1", "output": "brr"}]
2,600
["constructive algorithms", "dfs and similar", "graphs"]
50
[{"input": "4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "brrb\r\n"}, {"input": "3\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "brr\r\n"}, {"input": "3\r\n157210 22861\r\n175396 39466\r\n40933 17093\r\n", "output": "rrr\r\n"}, {"input": "5\r\n55599 84144\r\n169207 98421\r\n1909 186625\r\n31525 147710\r\n7781 82078\r\n", "out...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) points = [] for _ in range(n): x, y = map(int, f.readline().split()) points.append((x, y)) ...
true
447/B
447
B
Python 3
TESTS
1
30
0
222819409
lst=list(input()) k=int(input()) My_dict={} alphaval=list(map(int,input().split())) for i in range(len(lst)): My_dict.update({lst[i]:alphaval[ord(lst[i])-97]}) val_string=0 for i in range(len(lst)): val_string += My_dict.get(lst[i])*(i+1) max_of_all=max(My_dict.values()) for j in range(len(lst),len(lst)+k):...
24
46
0
139311448
special_string = input() k=int(input()) val_chars=list(map(int,input().split())) val=0 l=len(special_string) for x in range(l): y=val_chars[ord(special_string[x])-97] val=val+y*(x+1) val=val+max(val_chars)*(k*l+k*(k+1)*0.5) print(int(val))
Codeforces Round #FF (Div. 2)
CF
2,014
1
256
DZY Loves Strings
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where $$f(s) = \sum_{i=1}^{|s|} (w_{s_i} \cdot i).$$ Now DZY has a str...
The first line contains a single string s (1 ≤ |s| ≤ 103). The second line contains a single integer k (0 ≤ k ≤ 103). The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
null
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
[{"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41"}]
1,000
["greedy", "implementation"]
24
[{"input": "abc\r\n3\r\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "41\r\n"}, {"input": "mmzhr\r\n3\r\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453\r\n", "output": "29978\r\n"}, {"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\r...
false
stdio
null
true
761/D
761
D
PyPy 3
TESTS
1
62
0
141978107
import sys input = sys.stdin.readline def check(val): z = val for x in o: e = x[1] if z+e < l: return 1 if z+e > r: return 2 z += 1 return 0 n,l,r = map(int,input().split()) a = list(map(int,input().split())) p = list(map(int,input().split())) o =...
63
280
92,262,400
137754415
import os, sys from io import BytesIO, IOBase from math import log2, ceil, sqrt, gcd from _collections import deque import heapq as hp from bisect import bisect_left, bisect_right from math import cos, sin from itertools import permutations from operator import itemgetter sys.setrecursionlimit(5 * 10 ** 4) BUFSIZE = 8...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Very Difficult Problem
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: ci = bi - ai. About sequences a and b we know that their elements are in the range from l to...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ 109) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a1, a2, ..., an (l ≤ ai ≤ r) — the elements of the sequence a. The next line contains n distinct in...
If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers — the elements of any suitable sequence b.
null
Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
[{"input": "5 1 5\n1 1 1 1 1\n3 1 5 4 2", "output": "3 1 5 4 2"}, {"input": "4 2 9\n3 4 8 9\n3 2 1 4", "output": "2 2 2 9"}, {"input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "output": "-1"}]
1,700
["binary search", "brute force", "constructive algorithms", "greedy", "sortings"]
63
[{"input": "5 1 5\r\n1 1 1 1 1\r\n3 1 5 4 2\r\n", "output": "3 1 5 4 2 "}, {"input": "4 2 9\r\n3 4 8 9\r\n3 2 1 4\r\n", "output": "2 2 2 9 "}, {"input": "6 1 5\r\n1 1 1 1 1 1\r\n2 3 5 4 1 6\r\n", "output": "-1\r\n"}, {"input": "5 1 7\r\n1 4 4 6 5\r\n5 2 1 4 3\r\n", "output": "2 2 1 6 4 "}, {"input": "5 10 100\r\n12 14 ...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().strip() def main(input_path, output_path, submission_path): # Read input with open(input_path, 'r') as f: lines = f.readlines() n, l, r = map(int, lines[0].split()) a = list(map(int, lines[1].split())) p...
true
333/B
333
B
PyPy 3
TESTS
1
216
0
11672892
n,m=map(int,input().split()) a=[1]*(n*2) a[0]=a[n-1]=a[n]=a[n*2-1]=0 for i in range(m): x,y=map(int,(input().split())) a[x-1]=a[y+n-1]=0 if(n%2 and a[n//2+1] and a[n//2+1]):a[n//2]=0 print(sum(a))
20
686
0
4211014
n, m = map(int, input().split()) l = [0 for i in range(0, n)] c = [0 for i in range(0, n)] sol = 0 for i in range(0, m): a, b = map(int, input().split()) l[a-1] = 1 c[b-1] = 1 for i in range(1, n//2): #ma ocup de liniile i si n-i, coloanele la fel sol += 4 - (l[i] + c[i] + l[n-i-1] + c[n-i-1]) if...
Codeforces Round 194 (Div. 1)
CF
2,013
1
256
Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original...
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned ...
Print a single integer — the maximum points Gerald can earn in this game.
null
In the first test the answer equals zero as we can't put chips into the corner cells. In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips. In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
[{"input": "3 1\n2 2", "output": "0"}, {"input": "3 0", "output": "1"}, {"input": "4 3\n3 1\n3 2\n3 3", "output": "1"}]
1,800
["greedy"]
20
[{"input": "3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "3 0\r\n", "output": "1\r\n"}, {"input": "4 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 3\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1\r\n3 2\r\n", "output": "4\r\n"}, {"input": ...
false
stdio
null
true
290/F
290
F
Python 3
TESTS
1
62
0
173529625
import random as r a=r.randint(2,3) if(a==2): print("Yes") else: print("No")
45
186
1,536,000
277707327
n, m = map(int, input().split()) c = [[0] * 23 for _ in range(23)] d = [0] * 23 u = [0] * 23 for _ in range(m): xt, yt = map(int, input().split()) if c[xt][yt] or xt == yt: continue d[xt] += 1 d[yt] += 1 c[xt][yt] = c[yt][xt] = 1 for i in range(1, n + 1): u = [0] * (n + 1) co = 0 ...
April Fools Day Contest 2013
ICPC
2,013
2
256
Greedy Petya
Petya is an unexperienced programming contestant. Recently he has come across the following problem: You are given a non-directed graph which consists of n nodes and m edges. Your task is to determine whether the graph contains a Hamiltonian path. Petya wrote a quick bug-free code which he believes solves this proble...
The first line contains two integers n, m (1 ≤ n ≤ 20; 0 ≤ m ≤ 400). Next m lines contain pairs of integers vi, ui (1 ≤ vi, ui ≤ n).
Follow the format of Petya's code output.
null
null
[{"input": "2 3\n1 2\n2 1\n1 1", "output": "Yes"}, {"input": "3 0", "output": "No"}, {"input": "10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2", "output": "No"}]
2,800
["*special", "dfs and similar", "graphs", "greedy"]
45
[{"input": "2 3\r\n1 2\r\n2 1\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "3 0\r\n", "output": "No\r\n"}, {"input": "10 20\r\n3 10\r\n4 6\r\n4 9\r\n7 5\r\n8 8\r\n3 10\r\n9 7\r\n5 2\r\n9 2\r\n10 6\r\n10 4\r\n1 1\r\n7 2\r\n8 4\r\n7 2\r\n1 8\r\n5 4\r\n10 2\r\n8 5\r\n5 2\r\n", "output": "No\r\n"}, {"input": "10 30\r\n3 4\...
false
stdio
null
true
400/C
400
C
Python 3
TESTS
2
93
0
56037647
n, m, xt, yt, zt, q = map(int, input().split()) xt %= 4 yt %= 2 zt %= 4 res = [] for _ in range(q): x, y = map(int, input().split()) if(xt == 1): x, y = y, x+1 if(xt == 2): x, y = n-x+1, m-y+1 if(xt == 3): x, y = m-y+1, x if(xt % 2 == 1): n, m = m, n if(yt == 1): x, y = x, m-y+1 if(zt == 1):...
60
1,060
9,216,000
230011574
n, m, x, y, z, p = map(int, input().split()) x %= 4 y %= 2 z = (4 - (z % 4)) % 4 for _ in range(p): a, b = map(int, input().split()) for i in range(x): n, m = m, n a, b = b, m - a + 1 for i in range(y): b = m - b + 1 for i in range(z): n, m = m, n a, b = b, m - a ...
Codeforces Round 234 (Div. 2)
CF
2,014
2
256
Inna and Huge Candy Matrix
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j)....
The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105). Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.
For each of the p candies, print on a single line its space-separated new coordinates.
null
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
[{"input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1"}]
1,500
["implementation", "math"]
60
[{"input": "3 3 3 1 1 9\r\n1 1\r\n1 2\r\n1 3\r\n2 1\r\n2 2\r\n2 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1 3\r\n1 2\r\n1 1\r\n2 3\r\n2 2\r\n2 1\r\n3 3\r\n3 2\r\n3 1\r\n"}, {"input": "5 5 0 0 0 1\r\n1 4\r\n", "output": "1 4\r\n"}, {"input": "14 76 376219315 550904689 16684615 24\r\n11 21\r\n1 65\r\n5 25\r\n14 63\r\n11 30...
false
stdio
null
true
400/D
400
D
PyPy 3
TESTS
0
139
409,600
102521437
import math import sys input=sys.stdin.readline from collections import Counter, defaultdict, deque def dfs(grp, edge): if len(grp) == 1: return True visited = {i:False for i in grp} src = grp[0] visited[src] = True st = [src] while st != []: cn = st.pop() for ne in edge[...
61
1,903
9,830,400
91565033
#!/usr/bin/env python3 from sys import stdin from bisect import bisect_left, bisect_right INF = int(1e9) def find(par, a): if par[a] == a: return a par[a] = find(par, par[a]) return par[a] def union(par, rnk, a, b): a = find(par,a) b = find(par,b) if a==b: return ...
Codeforces Round 234 (Div. 2)
CF
2,014
2
256
Dima and Bacteria
Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are nu...
The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers c1, c2, ..., ck (1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that $$\sum_{i=1}^{k} c_i = n$$.
If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».
null
null
[{"input": "4 4 2\n1 3\n2 3 0\n3 4 0\n2 4 1\n2 1 2", "output": "Yes\n0 2\n2 0"}, {"input": "3 1 2\n2 1\n1 2 0", "output": "Yes\n0 -1\n-1 0"}, {"input": "3 2 2\n2 1\n1 2 0\n2 3 1", "output": "Yes\n0 1\n1 0"}, {"input": "3 0 2\n1 2", "output": "No"}]
2,000
["dsu", "graphs", "shortest paths"]
61
[{"input": "4 4 2\r\n1 3\r\n2 3 0\r\n3 4 0\r\n2 4 1\r\n2 1 2\r\n", "output": "Yes\r\n0 2\r\n2 0\r\n"}, {"input": "3 1 2\r\n2 1\r\n1 2 0\r\n", "output": "Yes\r\n0 -1\r\n-1 0\r\n"}, {"input": "3 2 2\r\n2 1\r\n1 2 0\r\n2 3 1\r\n", "output": "Yes\r\n0 1\r\n1 0\r\n"}, {"input": "3 0 2\r\n1 2\r\n", "output": "No\r\n"}, {"inp...
false
stdio
null
true
599/C
599
C
PyPy 3
TESTS
3
140
1,433,600
85855289
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = ...
39
93
13,414,400
231031257
n=int(input()) s=0 v=0 a=list(map(int,input().split())) for i,j in zip(a,sorted(a)): s+=i-j v+=not s print(v)
Codeforces Round 332 (Div. 2)
CF
2,015
2
256
Day at the Beach
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the heig...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.
Print the maximum possible number of blocks in a valid partitioning.
null
In the first sample the partitioning looks like that: [1][2][3]. In the second sample the partitioning is: [2, 1][3, 2]
[{"input": "3\n1 2 3", "output": "3"}, {"input": "4\n2 1 3 2", "output": "2"}]
1,600
["sortings"]
39
[{"input": "3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 1 3 2\r\n", "output": "2\r\n"}, {"input": "17\r\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005\r\n", "output": "10\r\n"}, {"input": "101\r\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257...
false
stdio
null
true
176/A
176
A
Python 3
TESTS
5
154
9,216,000
115893900
import collections import itertools from functools import reduce mod = (10 ** 9) + 7 def permutationbysum(): for _ in range(int(input())): num, l, r, achieve = map(int, input().split()) k = r - l + 1 if (k * (k + 1)) // 2 <= achieve <= (k * (num * 2 + 1 - k)) // 2: outpos = (r...
51
186
7,782,400
124676486
# https://codeforces.com/problemset/problem/176/A from typing import * Planet = List[List[int]] def get_total_profit(profits: List[Tuple[int, int]], total_items: int) -> int: total_profit = 0 for i in range(len(profits)): if profits[i][0] < 0: break if profits[i][1] < total_items...
Croc Champ 2012 - Round 2
CF
2,012
2
256
Trading Business
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 10, 1 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string ...
Print a single number — the maximum profit Qwerty can get.
null
In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·9 + 7·9 = 90 units of money for the items, he sho...
[{"input": "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5", "output": "16"}]
1,200
["greedy", "sortings"]
51
[{"input": "3 3 10\r\nVenus\r\n6 5 3\r\n7 6 5\r\n8 6 10\r\nEarth\r\n10 9 0\r\n8 6 4\r\n10 9 3\r\nMars\r\n4 3 0\r\n8 4 12\r\n7 2 5\r\n", "output": "16"}, {"input": "2 1 5\r\nA\r\n6 5 5\r\nB\r\n10 9 0\r\n", "output": "15"}, {"input": "2 2 5\r\nAbcdefghij\r\n20 15 20\r\n10 5 13\r\nKlmopqrstu\r\n19 16 20\r\n12 7 14\r\n", "...
false
stdio
null
true
177/E1
177
E1
Python 3
TESTS1
4
186
307,200
91665597
def binary_search(arr, x): arr.sort() low = 0 high = len(arr) - 1 mid = 0 while low <= high: mid = low + (high-low)//2 if arr[mid] < x: low = mid + 1 elif arr[mid] > x: high = mid - 1 else: return mid return -1 def ternary_sear...
46
312
819,200
4856163
def f(x, t): y = x while sum((y * a) // b for a, b in t) < c: y += 1000000 while y - x > 1: z = (x + y) // 2 d = sum((z * a) // b for a, b in t) if d < c: x = z else: y = z return y n, c = map(int, input().split()) c -= n t = [tuple(map(int, input().split())) for i i...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
1298/D
978
E
PyPy 3-64
TESTS
4
46
0
170517779
n, w = map(int, input().split()) a = list(map(int, input().split())) u = w l = 0 changes = 0 for i in range(n): changes += a[i] u = min(u, w-changes) l = max(l, -changes) print(u-l+1)
42
46
1,024,000
231293915
# coding=utf-8 from collections import defaultdict, deque, Counter from math import sqrt, ceil, log2, factorial, gcd from itertools import combinations, permutations from functools import lru_cache, cmp_to_key from heapq import heappop, heappush, heapreplace, heapify from bisect import bisect_left, bisect_right from co...
Kotlin Heroes: Practice 3
ICPC
2,020
1
256
Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus ...
The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded...
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
null
In the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers. In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers. In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.
[{"input": "3 5\n2 1 -3", "output": "3"}, {"input": "2 4\n-1 1", "output": "4"}, {"input": "4 10\n2 4 1 2", "output": "2"}]
null
["*special", "combinatorics", "math"]
42
[{"input": "3 5\r\n2 1 -3\r\n", "output": "3\r\n"}, {"input": "2 4\r\n-1 1\r\n", "output": "4\r\n"}, {"input": "4 10\r\n2 4 1 2\r\n", "output": "2\r\n"}, {"input": "2 10\r\n-1 2\r\n", "output": "9\r\n"}, {"input": "3 4\r\n-3 -4 4\r\n", "output": "0\r\n"}, {"input": "10 1\r\n-1 -1 3 -4 2 3 0 -3 3 2\r\n", "output": "0\r\...
false
stdio
null
true
1298/D
978
E
PyPy 3-64
TESTS
4
46
0
167886276
n,w=map(int,input().split()) a=list(map(int,input().split())) b=[0] t=0 for i in range(len(a)): t+=a[i] b.append(t) s1=0-min(b) s2=w-max(b) s3=min(s2,w)-max(s1,0)+1 print(s3)
42
61
0
182299926
#!/usr/bin/env python3 import math import sys input = lambda: sys.stdin.readline().rstrip("\r\n") from bisect import bisect_left as bs def test_case(): n, w = map(int, input().split()) a = list(map(int, input().split())) l, h = 0, w minl, maxh = 0, w for i in range(n): l += a[i] h...
Kotlin Heroes: Practice 3
ICPC
2,020
1
256
Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus ...
The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded...
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
null
In the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers. In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers. In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.
[{"input": "3 5\n2 1 -3", "output": "3"}, {"input": "2 4\n-1 1", "output": "4"}, {"input": "4 10\n2 4 1 2", "output": "2"}]
null
["*special", "combinatorics", "math"]
42
[{"input": "3 5\r\n2 1 -3\r\n", "output": "3\r\n"}, {"input": "2 4\r\n-1 1\r\n", "output": "4\r\n"}, {"input": "4 10\r\n2 4 1 2\r\n", "output": "2\r\n"}, {"input": "2 10\r\n-1 2\r\n", "output": "9\r\n"}, {"input": "3 4\r\n-3 -4 4\r\n", "output": "0\r\n"}, {"input": "10 1\r\n-1 -1 3 -4 2 3 0 -3 3 2\r\n", "output": "0\r\...
false
stdio
null
true
177/E1
177
E2
Python 3
TESTS2
16
92
0
173846892
def p(mid,a,b,c): sm = 0 n = len(a) for i in range(n): sm += int((mid*a[i])/b[i]) return sm+n def binarysearch(a,b,c): n = len(a) l = 0 r = 1e18 while(r-l>1): mid = int(l + (r-l)/2) if(p(mid,a,b,c)>=c): r = mid else: l = mid+1 ...
21
186
307,200
75786512
# ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): n , c = map(int , input().split()) data = [] for i in range(n): a,b = map(int...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
291/C
291
C
PyPy 3-64
TESTS
35
1,185
81,715,200
183980173
import sys input = sys.stdin.readline n, k = map(int, input().split()) d = [list(map(int, input().split('.'))) for i in range(n)] for l1 in range(31, -1, -1): x = ('0'*l1).rjust(32, '1') s = set() j = [] for i in range(4): a = x[i*8:(i+1)*8] j.append(int(a, 2)) for i in d: s...
37
1,481
42,086,400
73374979
def parse(ip_address): a, b, c, d = [int(x) for x in ip_address.split('.')] return (a << 24) | (b << 16) | (c << 8) | d n, k = [int(x) for x in input().split()] ips = [parse(input()) for i in range(n)] all_ones = (1 << 32) - 1 eight_ones = (1 << 8) - 1 for n_zeros in range(31, 0, -1): mask = all_ones << n_...
Croc Champ 2013 - Qualification Round
CF
2,013
2
256
Network Mask
The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separat...
The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 105) — the number of IP addresses and networks. The next n lines contain the IP addresses. It is guaranteed that all IP addresses are distinct.
In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1.
null
null
[{"input": "5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "output": "255.255.254.0"}, {"input": "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "output": "255.255.0.0"}, {"input": "2 1\n255.0.0.1\n0.0.0.2", "output": "-1"}]
1,600
["*special", "bitmasks", "brute force", "implementation"]
37
[{"input": "5 3\r\n0.0.0.1\r\n0.1.1.2\r\n0.0.2.1\r\n0.1.1.0\r\n0.0.2.3\r\n", "output": "255.255.254.0"}, {"input": "5 2\r\n0.0.0.1\r\n0.1.1.2\r\n0.0.2.1\r\n0.1.1.0\r\n0.0.2.3\r\n", "output": "255.255.0.0"}, {"input": "2 1\r\n255.0.0.1\r\n0.0.0.2\r\n", "output": "-1\r\n"}, {"input": "10 2\r\n57.11.146.42\r\n200.130.164....
false
stdio
null
true
95/C
95
C
PyPy 3
TESTS
2
310
20,172,800
89364839
from sys import stdin import heapq n,m = [int(x) for x in stdin.readline().split()] start,end = [int(x)-1 for x in stdin.readline().split()] graph = [{} for x in range(n)] taxis = [] for road in range(m): l,r,d = [int(x) for x in stdin.readline().split()] l -= 1 r -= 1 if not r in graph[l]: ...
65
404
7,065,600
194467932
num_inp=lambda: int(input()) arr_inp=lambda: list(map(int,input().split())) sp_inp=lambda: map(int,input().split()) str_inp=lambda:input() from heapq import * f = lambda: map(int, input().split()) inf = 1e13 n, m = f() x, y = f() p = [[] for i in range(n + 1)] for j in range(m): u, v, w = f() p[u].append((v, ...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Volleyball
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can...
The first line contains two integers n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to n, inclusive. The next line contains two integers x and y (1 ≤ x, y ≤ n). They are the numbers of the initial and final junctions corres...
If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
null
An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles.
[{"input": "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "output": "9"}]
1,900
["shortest paths"]
65
[{"input": "4 4\r\n1 3\r\n1 2 3\r\n1 4 1\r\n2 4 1\r\n2 3 5\r\n2 7\r\n7 2\r\n1 2\r\n7 7\r\n", "output": "9\r\n"}, {"input": "3 3\r\n1 3\r\n1 2 2\r\n1 3 3\r\n3 2 1\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "14\r\n"}, {"input": "3 1\r\n1 3\r\n1 2 2\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n3 3\r\n1 2 2\...
false
stdio
null
true
898/D
898
D
PyPy 3
TESTS
4
140
0
90882301
n,m,k = map(int,input().split()) Alarm = [int(x) for x in input().split()] Alarm.sort() ringing_alarm_no = Alarm[0] total_ringing_alarm = 1 Ans = 0 for i in range(1,n): if(Alarm[i] - ringing_alarm_no<m): # THis means they are in continuous total_ringing_alarm+=1 else: total_ringing_alarm = 1 ...
48
326
16,793,600
90393826
import sys input = sys.stdin.readline from collections import * n, m, k = map(int, input().split()) a = list(map(int, input().split())) t = [0]*(10**6+100) for ai in a: t[ai] = 1 now = 0 ans = 0 for i in range(10**6+100): now += t[i] if i>=m: now -= t[i-m] if now==k: t[...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Alarm Clock
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will defini...
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up. Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary...
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
null
In first example Vitalya should turn off first alarm clock which rings at minute 3. In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring. In third example Vitalya should turn off any 6 alarm clocks.
[{"input": "3 3 2\n3 5 1", "output": "1"}, {"input": "5 10 3\n12 8 18 25 1", "output": "0"}, {"input": "7 7 2\n7 3 4 1 6 5 2", "output": "6"}, {"input": "2 2 2\n1 3", "output": "0"}]
1,600
["greedy"]
48
[{"input": "3 3 2\r\n3 5 1\r\n", "output": "1\r\n"}, {"input": "5 10 3\r\n12 8 18 25 1\r\n", "output": "0\r\n"}, {"input": "7 7 2\r\n7 3 4 1 6 5 2\r\n", "output": "6\r\n"}, {"input": "2 2 2\r\n1 3\r\n", "output": "0\r\n"}, {"input": "1 4 1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 3 1\r\n1 2\r\n", "output": "2\r\n"},...
false
stdio
null
true
95/C
95
C
PyPy 3
TESTS
2
248
0
39929708
f = lambda: map(int, input().split()) inf = 2e13 n, m = f() x, y = f() p = [[] for i in range(n + 1)] for j in range(m): u, v, w = f() p[u].append((v, w)) p[v].append((u, w)) d = [(0, 0)] + [tuple(f()) for k in range(n)] def g(s): x, a = 0, inf for y, b in s.items(): if b < a: ...
65
434
9,830,400
229859982
from heapq import * def read_integers(): return map(int, input().split()) inf = 1e13 n, m = read_integers() x, y = read_integers() roads = [[] for i in range(n + 1)] for j in range(m): u, v, w = read_integers() roads[u].append((v, w)) roads[v].append((u, w)) drivers = [(0, 0)] + [tuple(read_intege...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Volleyball
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can...
The first line contains two integers n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to n, inclusive. The next line contains two integers x and y (1 ≤ x, y ≤ n). They are the numbers of the initial and final junctions corres...
If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
null
An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles.
[{"input": "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "output": "9"}]
1,900
["shortest paths"]
65
[{"input": "4 4\r\n1 3\r\n1 2 3\r\n1 4 1\r\n2 4 1\r\n2 3 5\r\n2 7\r\n7 2\r\n1 2\r\n7 7\r\n", "output": "9\r\n"}, {"input": "3 3\r\n1 3\r\n1 2 2\r\n1 3 3\r\n3 2 1\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "14\r\n"}, {"input": "3 1\r\n1 3\r\n1 2 2\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n3 3\r\n1 2 2\...
false
stdio
null
true
41/D
41
D
PyPy 3-64
TESTS
4
92
0
216545382
import sys readline = sys.stdin.readline N, M, k = list(map(int, readline().split())) K = k + 1 board = [] for _ in range(N): board.append([int(c) for c in readline().strip()]) dp = [[-1] * K for _ in range(M)] trace = [[[[0, 0] for m in range(K)] for c in range(M)] for r in range(N)] for i, n in enumerate(boar...
53
934
43,827,200
121889515
import os import sys from io import BytesIO, IOBase from types import GeneratorType from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" ...
Codeforces Beta Round 40 (Div. 2)
CF
2,010
2
256
Pawn
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having c...
The first line contains three integers n, m, k (2 ≤ n, m ≤ 100, 0 ≤ k ≤ 10) — the number of rows and columns on the chessboard, the number of the pawn's brothers. Then follow n lines containing each m numbers from 0 to 9 without spaces — the chessboard's description. Each square is described by one number — the number ...
If it is impossible to reach the highest row having collected the number of peas divisible by k + 1, print -1. Otherwise, the first line must contain a single number — the maximal number of peas the pawn can collect given that the number must be divisible by k + 1. The second line must contain a single number — the nu...
null
null
[{"input": "3 3 1\n123\n456\n789", "output": "16\n2\nRL"}, {"input": "3 3 0\n123\n456\n789", "output": "17\n3\nLR"}, {"input": "2 2 10\n98\n75", "output": "-1"}]
1,900
["dp"]
53
[{"input": "3 3 1\r\n123\r\n456\r\n789\r\n", "output": "16\r\n2\r\nRL\r\n"}, {"input": "3 3 0\r\n123\r\n456\r\n789\r\n", "output": "17\r\n3\r\nLR\r\n"}, {"input": "2 2 10\r\n98\r\n75\r\n", "output": "-1\r\n"}, {"input": "3 4 2\r\n8244\r\n4768\r\n4474\r\n", "output": "18\r\n3\r\nLR\r\n"}, {"input": "4 3 10\r\n194\r\n707...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path) as f: n, m, k = map(int, f.readline().split()) board = [line.strip() for line in f] with open(ref_path) as f: ref_lines = [line.strip() for line in f] w...
true
355/B
355
B
Python 3
TESTS
25
109
307,200
73847876
precos = [int(x) for x in input().split()] numeros = [int(x) for x in input().split()] bus = [int(x) for x in input().split()] troler = [int(x) for x in input().split()] if precos[3] == min(precos): print(precos[3]) exit(0) somabus = 0 somatroler = 0 for e in bus: a = e * precos[0] b = precos[1] lista = [a,b]...
27
46
0
169972204
def fun(arr,c1,c2): ans=0 for x in arr: ans=min(c2,x*c1)+ans return ans c1,c2,c3,c4=map(int,input().split()) n,m=map(int,input().split()) b=list(map(int,input().split())) t=list(map(int,input().split())) f=min(fun(b,c1,c2),c3) g=min(fun(t,c1,c2),c3) h=min(c4,(f+g)) print(h)
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
599/C
599
C
PyPy 3
TESTS
6
109
0
108089916
n=int(input()) d=0 a=list(map(int,input().split())) i=0 while i<n: for j in range(n-1,i-1,-1): if a[j]<a[i] or j==i: d+=1 i=j break i+=1 print(d)
39
108
18,329,600
181863994
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) q = sorted(w) d = {q[-1]: 0} a = 0 for i in range(n-2, -1, -1): a += 1 if q[i] != q[i+1]: d[q[i]] = a a, c, x, b, x1 = -1, 0, 0, -1, w[-1] for i in range(n-1, -1, -1): if a == -1: c += 1 a = ...
Codeforces Round 332 (Div. 2)
CF
2,015
2
256
Day at the Beach
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the heig...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.
Print the maximum possible number of blocks in a valid partitioning.
null
In the first sample the partitioning looks like that: [1][2][3]. In the second sample the partitioning is: [2, 1][3, 2]
[{"input": "3\n1 2 3", "output": "3"}, {"input": "4\n2 1 3 2", "output": "2"}]
1,600
["sortings"]
39
[{"input": "3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 1 3 2\r\n", "output": "2\r\n"}, {"input": "17\r\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005\r\n", "output": "10\r\n"}, {"input": "101\r\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257...
false
stdio
null
true
291/C
291
C
Python 3
TESTS
35
1,590
14,950,400
35899504
def f(t): a, b, c, d = map(int, t.split('.')) return d + (c << 8) + (b << 16) + (a << 24) def g(x): p = [0] * 4 for i in range(4): p[3 - i] = str(x % 256) x //= 256 return '.'.join(p) n, k = map(int, input().split()) t = [f(input()) for i in range(n)] p = [0] * n x = 1 << 31 for i ...
35
2,234
15,155,200
3818736
import math import re from fractions import Fraction from collections import Counter class Task: ips = [] k = 0 answer = '' def __init__(self): n, self.k = [int(x) for x in input().split()] self.ips = ['' for _ in range(n)] for i in range(len(self.ips)): self.ip...
Croc Champ 2013 - Qualification Round
CF
2,013
2
256
Network Mask
The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separat...
The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 105) — the number of IP addresses and networks. The next n lines contain the IP addresses. It is guaranteed that all IP addresses are distinct.
In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1.
null
null
[{"input": "5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "output": "255.255.254.0"}, {"input": "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "output": "255.255.0.0"}, {"input": "2 1\n255.0.0.1\n0.0.0.2", "output": "-1"}]
1,600
["*special", "bitmasks", "brute force", "implementation"]
37
[{"input": "5 3\r\n0.0.0.1\r\n0.1.1.2\r\n0.0.2.1\r\n0.1.1.0\r\n0.0.2.3\r\n", "output": "255.255.254.0"}, {"input": "5 2\r\n0.0.0.1\r\n0.1.1.2\r\n0.0.2.1\r\n0.1.1.0\r\n0.0.2.3\r\n", "output": "255.255.0.0"}, {"input": "2 1\r\n255.0.0.1\r\n0.0.0.2\r\n", "output": "-1\r\n"}, {"input": "10 2\r\n57.11.146.42\r\n200.130.164....
false
stdio
null
true
291/C
291
C
Python 3
TESTS
35
1,622
8,499,200
103571599
import sys n, k = map(int, input().split()) mvals = [] for _ in range(n): x, y, z, w = map(int, input().split('.')) mvals.append((x << 24) | (y << 16) | (z << 8) | w) mv = (1 << 32) - 1 for ind in range(31,-1,-1): st = set() mask = mv - ((1 << ind) - 1) for i in range(n): st.add(mask & mv...
37
1,481
42,086,400
73374979
def parse(ip_address): a, b, c, d = [int(x) for x in ip_address.split('.')] return (a << 24) | (b << 16) | (c << 8) | d n, k = [int(x) for x in input().split()] ips = [parse(input()) for i in range(n)] all_ones = (1 << 32) - 1 eight_ones = (1 << 8) - 1 for n_zeros in range(31, 0, -1): mask = all_ones << n_...
Croc Champ 2013 - Qualification Round
CF
2,013
2
256
Network Mask
The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separat...
The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 105) — the number of IP addresses and networks. The next n lines contain the IP addresses. It is guaranteed that all IP addresses are distinct.
In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1.
null
null
[{"input": "5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "output": "255.255.254.0"}, {"input": "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "output": "255.255.0.0"}, {"input": "2 1\n255.0.0.1\n0.0.0.2", "output": "-1"}]
1,600
["*special", "bitmasks", "brute force", "implementation"]
37
[{"input": "5 3\r\n0.0.0.1\r\n0.1.1.2\r\n0.0.2.1\r\n0.1.1.0\r\n0.0.2.3\r\n", "output": "255.255.254.0"}, {"input": "5 2\r\n0.0.0.1\r\n0.1.1.2\r\n0.0.2.1\r\n0.1.1.0\r\n0.0.2.3\r\n", "output": "255.255.0.0"}, {"input": "2 1\r\n255.0.0.1\r\n0.0.0.2\r\n", "output": "-1\r\n"}, {"input": "10 2\r\n57.11.146.42\r\n200.130.164....
false
stdio
null
true
1009/A
1009
A
Python 3
TESTS
3
109
307,200
73904215
n,m = map(int,input().split()) a = list(map(int,input().split())) c = list(map(int,input().split())) count = 0 j = 0 for i in c: while a[j] > i: j +=1 if j == n: print(0) exit() count += 1 j += 1 if j == n: break print(count)
19
31
0
189383613
games, bills = map(int, input().split()) costs = list(map(int, input().split())) moneys = list(map(int, input().split())) tempMon = 0 goNext = True answer = 0 tempMoney = moneys.pop(0) for cost in costs: #goNext = False if(tempMoney >= cost): answer += 1 if moneys: tempMoney = moneys...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1
256
Game Shopping
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$. Games in the shop are ordered from left to ri...
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th ...
Print a single integer — the number of games Maxim will buy.
null
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3"}, {"input": "5 2\n20 40 50 20 40\n19 20", "output": "0"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4"}]
800
["implementation"]
19
[{"input": "5 4\r\n2 4 5 2 4\r\n5 3 4 6\r\n", "output": "3\r\n"}, {"input": "5 2\r\n20 40 50 20 40\r\n19 20\r\n", "output": "0\r\n"}, {"input": "6 4\r\n4 8 15 16 23 42\r\n1000 1000 1000 1000\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 1\r\n10 1 1 1 1\r\n1000\r\n", "...
false
stdio
null
true
727/B
727
B
Python 3
TESTS
4
139
819,200
54695111
from string import ascii_lowercase, digits average = 0 num = False cur = 0 last_point = 0 for el in input(): if el in ascii_lowercase: if num: if last_point: if last_point==3: cur/=100 average+=cur num=False cur=0 ...
33
62
4,608,000
21444162
#!/usr/bin/python3 s = input() alph = ''.join([chr(ord('a') + x) for x in range(26)]) l = [[]] for x in s: if x not in alph: l[-1].append(x) else: if len(l[-1]): l.append([]) l = list(map(lambda x: ''.join(x), l)) ansa = 0 ansb = 0 for t in l: if len(t) > 2 and t[-3] == '.': ...
Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)
CF
2,016
1
256
Bill Total Value
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is ...
The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill. It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.
Print the total price exactly in the same format as prices given in the input.
null
null
[{"input": "chipsy48.32televizor12.390", "output": "12.438.32"}, {"input": "a1b2c3.38", "output": "6.38"}, {"input": "aa0.01t0.03", "output": "0.04"}]
1,600
["expression parsing", "implementation", "strings"]
33
[{"input": "chipsy48.32televizor12.390\r\n", "output": "12.438.32\r\n"}, {"input": "a1b2c3.38\r\n", "output": "6.38\r\n"}, {"input": "aa0.01t0.03\r\n", "output": "0.04\r\n"}, {"input": "test0.50test0.50\r\n", "output": "1"}, {"input": "a500b500\r\n", "output": "1.000"}, {"input": "tcjbjlbtjf329.910\r\n", "output": "329...
false
stdio
null
true
41/D
41
D
PyPy 3-64
TESTS
4
92
0
170882113
import sys input = sys.stdin.readline MAX = 10**5 def update(n, m, k, a, dp, i, j, l): l_prev = (l - a[i][j]) % (k + 1) val = -MAX prev = 0 if j > 0 and val < dp[i + 1][j - 1][l_prev] + a[i][j]: val = dp[i + 1][j - 1][l_prev] + a[i][j] prev = -1 if j < m - 1 and val < dp[i + 1][j +...
53
1,090
7,680,000
42156242
n, m, k = map(int, input().split()) board = [[0] * m for i in range(n)] for i in range(n): s = input().rstrip() for j in range(m): board[i][j] = int(s[j]) board.reverse() dp = [[[-10 ** 9] * (k + 1) for i in range(m)] for j in range(n)] prev = [[[(0, 0)] * (k + 1) for i in range(m)] for j in r...
Codeforces Beta Round 40 (Div. 2)
CF
2,010
2
256
Pawn
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having c...
The first line contains three integers n, m, k (2 ≤ n, m ≤ 100, 0 ≤ k ≤ 10) — the number of rows and columns on the chessboard, the number of the pawn's brothers. Then follow n lines containing each m numbers from 0 to 9 without spaces — the chessboard's description. Each square is described by one number — the number ...
If it is impossible to reach the highest row having collected the number of peas divisible by k + 1, print -1. Otherwise, the first line must contain a single number — the maximal number of peas the pawn can collect given that the number must be divisible by k + 1. The second line must contain a single number — the nu...
null
null
[{"input": "3 3 1\n123\n456\n789", "output": "16\n2\nRL"}, {"input": "3 3 0\n123\n456\n789", "output": "17\n3\nLR"}, {"input": "2 2 10\n98\n75", "output": "-1"}]
1,900
["dp"]
53
[{"input": "3 3 1\r\n123\r\n456\r\n789\r\n", "output": "16\r\n2\r\nRL\r\n"}, {"input": "3 3 0\r\n123\r\n456\r\n789\r\n", "output": "17\r\n3\r\nLR\r\n"}, {"input": "2 2 10\r\n98\r\n75\r\n", "output": "-1\r\n"}, {"input": "3 4 2\r\n8244\r\n4768\r\n4474\r\n", "output": "18\r\n3\r\nLR\r\n"}, {"input": "4 3 10\r\n194\r\n707...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path) as f: n, m, k = map(int, f.readline().split()) board = [line.strip() for line in f] with open(ref_path) as f: ref_lines = [line.strip() for line in f] w...
true
51/C
51
C
Python 3
TESTS
2
46
5,632,000
35584977
n = int(input()) x = set(map(int, input().split())) if n <= 3: print(0) if n == 1: print(*x, *x, *x) elif n == 2: print(*x, min(x)) else: print(*x) exit() mx, mn = max(x), min(x) ans = mx - mn a1, a2 = ans / 6, ans / 3 print(a1) print(mn + a1, mn + a1 + a2, mn...
50
155
27,648,000
176259674
from bisect import * #n, m = map(int, raw_input().split()) n = int(input()) k=3 sol = [0] * k a=sorted(list(map(int,input().split()))) def test(m): sol[0]=a[0] for i in range(1,k): sol[i]=sol[i-1] it = bisect(a,sol[i-1]+m) if it<n: sol[i]=a[it] return (sol[k - 1] + m) >=...
Codeforces Beta Round 48
CF
2,010
1
256
Three Base Stations
The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordinates of xi. TELE3, a cellular communication provider planned to l...
The first line contains an integer n (1 ≤ n ≤ 2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x1, x2, ..., xn of integer numbers (1 ≤ xi ≤ 109). It is possible that two or more houses are located on one point. The coordinates are given in a ...
Print the required minimal power d. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching c...
null
null
[{"input": "4\n1 2 3 4", "output": "0.500000\n1.500000 2.500000 3.500000"}, {"input": "3\n10 20 30", "output": "0\n10.000000 20.000000 30.000000"}, {"input": "5\n10003 10004 10001 10002 1", "output": "0.500000\n1.000000 10001.500000 10003.500000"}]
1,800
["binary search", "greedy"]
50
[{"input": "4\r\n1 2 3 4\r\n", "output": "0.500000\r\n1.500000 2.500000 3.500000\r\n"}, {"input": "3\r\n10 20 30\r\n", "output": "0\r\n10.000000 20.000000 30.000000\r\n"}, {"input": "5\r\n10003 10004 10001 10002 1\r\n", "output": "0.500000\r\n1.000000 10001.500000 10003.500000\r\n"}, {"input": "1\r\n1\r\n", "output": "...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) x = list(map(int, f.readline().split())) with open(ref_output_path, 'r') as f: d_ref = float(f.readline()....
true
901/A
901
A
PyPy 3
TESTS
3
124
0
76909448
import sys import bisect # from collections import deque Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in r...
45
342
18,022,400
33427604
def do_amb(v, n, sum): print("ambiguous") diff = [] for i in v: temp = len(diff) diff.extend((temp for j in range(i))) print(" ".join(str(i) for i in diff)) diff[sum+1] = sum-1 print(" ".join(str(i) for i in diff)) n = int(input()) v = [int(i) for i in input().split()] ...
Codeforces Round 453 (Div. 1)
CF
2,017
2
256
Hashing Trees
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree...
The first line contains a single integer h (2 ≤ h ≤ 105) — the height of the tree. The second line contains h + 1 integers — the sequence a0, a1, ..., ah (1 ≤ ai ≤ 2·105). The sum of all ai does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence.
If there is only one tree matching this sequence, print "perfect". Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print $$\sum_{i=0}^{h} a_i$$ integers, the k-th of them should be the parent of vertex k or be equal...
null
The only tree in the first example and the two printed trees from the second example are shown on the picture:
[{"input": "2\n1 1 1", "output": "perfect"}, {"input": "2\n1 2 2", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2"}]
1,500
["constructive algorithms", "trees"]
45
[{"input": "2\r\n1 1 1\r\n", "output": "perfect\r\n"}, {"input": "2\r\n1 2 2\r\n", "output": "ambiguous\r\n0 1 1 3 3\r\n0 1 1 3 2\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "perfect\r\n"}, {"input": "10\r\n1 1 1 1 1 2 1 1 1 1 1\r\n", "output": "perfect\r\n"}, {"input": "10\r\n1 1 1 1 2 2 1 1 1 1 1\r\...
false
stdio
import sys def main(input_path, output_path, submission_output_path): with open(input_path) as f: h = int(f.readline().strip()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = [line.strip() for line in f.readlines() if line.strip()] ...
true
596/C
596
C
Python 3
PRETESTS
2
46
512,000
14282297
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from sys import stdin from collections import defaultdict from operator import itemgetter def main(): n = int(stdin.readline()) existingWs = defaultdict(lambda: set()) points = set() for _ in range(n): point = tuple(map(int, stdin.readline().split())) poi...
76
701
21,606,400
14359662
from sys import stdin _data = iter(stdin.read().split('\n')) input = lambda: next(_data) n = int(input()) ref, front = {}, {} ans = [] max_x, max_y = 0, 0 for _ in range(n): x, y = map(int, input().split()) max_x = max(max_x, x) max_y = max(max_y, y) ref[(x, y)] = 2 if x == 0: ref[(x, y...
Codeforces Round 331 (Div. 2)
CF
2,015
2
256
Wilbur and Points
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set. Now Wilbur wants to number the points in the set he has, that is ...
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with. Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are dis...
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO". If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there ar...
null
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi. In the second sample, the special values of the points in the set ar...
[{"input": "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0", "output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1"}, {"input": "3\n1 0\n0 0\n2 0\n0 1 2", "output": "NO"}]
1,700
["combinatorics", "greedy", "sortings"]
76
[{"input": "5\r\n2 0\r\n0 0\r\n1 0\r\n1 1\r\n0 1\r\n0 -1 -2 1 0\r\n", "output": "YES\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n"}, {"input": "3\r\n1 0\r\n0 0\r\n2 0\r\n0 1 2\r\n", "output": "NO\r\n"}, {"input": "9\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n0 2\r\n0 0 0 -1 -1 -2 1 1 2\r\n", "output": "NO\r\n...
false
stdio
null
true
596/C
596
C
Python 3
PRETESTS
2
62
512,000
14283814
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from sys import stdin, setrecursionlimit from collections import defaultdict from operator import itemgetter setrecursionlimit(999999999) def main(): n = int(stdin.readline()) existingWs = defaultdict(lambda: set()) points = set() for _ in range(n): point = ...
76
717
23,654,400
57767161
n = int(input().rstrip()) l = set() for i in range(n): l.add(tuple(map(int, input().rstrip().split()))) w = list(map(int, input().rstrip().split())) d = {0: (0, 0)} s = "" visited = set() visited.add((0, 0)) for k in w: if d.get(k, None) is None: print("NO") exit(0) p = d[k] del d[k] ...
Codeforces Round 331 (Div. 2)
CF
2,015
2
256
Wilbur and Points
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set. Now Wilbur wants to number the points in the set he has, that is ...
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with. Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are dis...
If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO". If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there ar...
null
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi. In the second sample, the special values of the points in the set ar...
[{"input": "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0", "output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1"}, {"input": "3\n1 0\n0 0\n2 0\n0 1 2", "output": "NO"}]
1,700
["combinatorics", "greedy", "sortings"]
76
[{"input": "5\r\n2 0\r\n0 0\r\n1 0\r\n1 1\r\n0 1\r\n0 -1 -2 1 0\r\n", "output": "YES\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n"}, {"input": "3\r\n1 0\r\n0 0\r\n2 0\r\n0 1 2\r\n", "output": "NO\r\n"}, {"input": "9\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n0 2\r\n0 0 0 -1 -1 -2 1 1 2\r\n", "output": "NO\r\n...
false
stdio
null
true
351/E
351
E
PyPy 3
TESTS
10
186
3,276,800
150728078
import sys input = sys.stdin.buffer.readline def inv_count(A, l, r): if l==r: return [A[l]], 0 m = (l+r)//2 A1, x1 = inv_count(A, l, m) A2, x2 = inv_count(A, m+1, r) x3 = x1+x2 A3 = [] n1 = len(A1) n2 = len(A2) i1 = 0 i2 = 0 while True: if i1 < n1 and i2 < n2...
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
324/A1
331
A2
Python 3
TESTS2
10
124
0
193411982
n=int(input()) lis=list(map(int,input().split())) l=0 r=0 maxsum=-10**9 negc=[0]*n possum=[0]*n if lis[0]>=0: possum[0]=lis[0] else: negc[0]+=1 for i in range(1,n): possum[i]+=possum[i-1] negc[i]+=negc[i-1] if lis[i]>=0: possum[i]+=lis[i] else: negc[i]+=1 #print(possum) #print(ne...
18
78
102,400
4094892
length = int(input()) array = [int(a) for a in input().split()] maxSum = -10e20 resIndexes = [] for i in range(length): for j in range(length - 1, -1, -1): if j > i and array[i] == array[j]: tmp = sum(array[i:j + 1]) indexes = [] for index in range(i + 1, j): if array[index] < 0: tmp -= array[index...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
727/B
727
B
Python 3
TESTS
3
93
307,200
53999428
S = input() N = len(S) i = 0 D = [] while i < N: if S[i].isdigit(): tmp = '' while i < N and (S[i].isdigit() or S[i] == '.'): tmp += S[i] i += 1 D.append(tmp) else: i += 1 dol = 0 cen = 0 for k in D: d = k.split('.') if len(d[-1]) == 2: c...
33
62
4,608,000
21446996
lat='qwertyuiopasdfghjklzxcvbnm' lats=[] lats+=lat c=str(input()) for i in lats: c=c.replace(i,' ') c=c.split() #print(c) k=0 for i in c: j=int(i.replace('.','')) i=i.replace('.',' ') i=i.split() if len(i[len(i)-1])!=2 or len(i)==1: j*=100 #print(j) k+=j #print(k) print(format(...
Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)
CF
2,016
1
256
Bill Total Value
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is ...
The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill. It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.
Print the total price exactly in the same format as prices given in the input.
null
null
[{"input": "chipsy48.32televizor12.390", "output": "12.438.32"}, {"input": "a1b2c3.38", "output": "6.38"}, {"input": "aa0.01t0.03", "output": "0.04"}]
1,600
["expression parsing", "implementation", "strings"]
33
[{"input": "chipsy48.32televizor12.390\r\n", "output": "12.438.32\r\n"}, {"input": "a1b2c3.38\r\n", "output": "6.38\r\n"}, {"input": "aa0.01t0.03\r\n", "output": "0.04\r\n"}, {"input": "test0.50test0.50\r\n", "output": "1"}, {"input": "a500b500\r\n", "output": "1.000"}, {"input": "tcjbjlbtjf329.910\r\n", "output": "329...
false
stdio
null
true
172/A
172
A
Python 3
TESTS
14
466
307,200
99340869
number = int(input()) common = [] previous_common = [] for i in range(number): telephone_number = input() if len(common) == 0: for i in range(len(telephone_number)): common.append(telephone_number[i]) previous_common.append(telephone_number[i]) else: common = [] ...
28
124
2,867,200
231985413
x = [input() for i in range(int(input()))] a, b = min(x), max(x) while a != b: a, b = a[:-1], b[:-1] print(len(a))
Croc Champ 2012 - Qualification Round
CF
2,012
2
256
Phone Code
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest commo...
The first line of the input contains an integer n (2 ≤ n ≤ 3·104) — the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also...
Print the number of digits in the city phone code.
null
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an empty ...
[{"input": "4\n00209\n00219\n00999\n00909", "output": "2"}, {"input": "2\n1\n2", "output": "0"}, {"input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12"}]
800
["*special", "brute force", "implementation"]
28
[{"input": "4\r\n00209\r\n00219\r\n00999\r\n00909\r\n", "output": "2\r\n"}, {"input": "2\r\n1\r\n2\r\n", "output": "0\r\n"}, {"input": "3\r\n77012345678999999999\r\n77012345678901234567\r\n77012345678998765432\r\n", "output": "12\r\n"}, {"input": "5\r\n4491183345\r\n4491184811\r\n4491162340\r\n4491233399\r\n4491449214\...
false
stdio
null
true
172/A
172
A
PyPy 3
TESTS
14
686
5,529,600
83910845
s='' for i in range(int(input())): sa=input() if s=='': s=sa else: sp='' n=len(s) for i in range(0,n): if s[i]==sa[i]: sp=sp+sa[i] else: break s=sp print(len(s))
28
124
2,867,200
231985772
x=[input() for i in range(int(input()))] a,b=min(x),max(x) while a!=b:a,b=a[:-1],b[:-1] print(len(a))
Croc Champ 2012 - Qualification Round
CF
2,012
2
256
Phone Code
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest commo...
The first line of the input contains an integer n (2 ≤ n ≤ 3·104) — the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also...
Print the number of digits in the city phone code.
null
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an empty ...
[{"input": "4\n00209\n00219\n00999\n00909", "output": "2"}, {"input": "2\n1\n2", "output": "0"}, {"input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12"}]
800
["*special", "brute force", "implementation"]
28
[{"input": "4\r\n00209\r\n00219\r\n00999\r\n00909\r\n", "output": "2\r\n"}, {"input": "2\r\n1\r\n2\r\n", "output": "0\r\n"}, {"input": "3\r\n77012345678999999999\r\n77012345678901234567\r\n77012345678998765432\r\n", "output": "12\r\n"}, {"input": "5\r\n4491183345\r\n4491184811\r\n4491162340\r\n4491233399\r\n4491449214\...
false
stdio
null
true
172/A
172
A
Python 3
TESTS
26
1,776
10,752,000
79804469
n = int(input()) s = [input() for x in range(n)] e = [] if n > 3000:n = 3000 for x in range(len(s[0])): for y in range(1,n): if s[0][:x] == s[y][:x]: e.append(s[0][:x]) else: break e.reverse() for x in e: if e.count(x) == n - 1: print(len(x)) break
28
124
3,993,600
211073948
import sys input = sys.stdin.readline codes = [input() for _ in range(int(input()))] for i in range(len(codes[0])): diff = False for j in range(1, len(codes)): if codes[j][i] != codes[0][i]: diff = True break if diff: print(i) break else: print(i)
Croc Champ 2012 - Qualification Round
CF
2,012
2
256
Phone Code
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest commo...
The first line of the input contains an integer n (2 ≤ n ≤ 3·104) — the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also...
Print the number of digits in the city phone code.
null
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an empty ...
[{"input": "4\n00209\n00219\n00999\n00909", "output": "2"}, {"input": "2\n1\n2", "output": "0"}, {"input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12"}]
800
["*special", "brute force", "implementation"]
28
[{"input": "4\r\n00209\r\n00219\r\n00999\r\n00909\r\n", "output": "2\r\n"}, {"input": "2\r\n1\r\n2\r\n", "output": "0\r\n"}, {"input": "3\r\n77012345678999999999\r\n77012345678901234567\r\n77012345678998765432\r\n", "output": "12\r\n"}, {"input": "5\r\n4491183345\r\n4491184811\r\n4491162340\r\n4491233399\r\n4491449214\...
false
stdio
null
true
595/A
595
A
Python 3
TESTS
5
93
307,200
67326472
x = [int(i) for i in input().split()] n, m, res = x[0], x[1], [] for i in range(n): res.append([int(i) for i in input().split()]) count = 0 for i in res: for p in range(2, 2*m, 2): if i[p] == 1 or i[p-1] == 1: count += 1 if i[-2] == 1 or i[-1] == 1: count += 1 print(count)
36
46
0
138687212
n, m = map(int, input().split()) count = 0 for i in range(n): tmp = list(map(int, input().split())) for i in range(2 * m - 1): if i % 2 != 0: continue if tmp[i] == 1 or tmp[i + 1] == 1: count += 1 print(count)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
595/A
595
A
PyPy 3
TESTS
5
140
1,536,000
91561199
if __name__ == '__main__': n,m = map(int, input().split()) co = 0 for _ in range(n): b = list(map(str, input().split())) b = ''.join(b) if "01" in b: co += b.count("01") b = b.replace("01","") if "10" in b: co += b.count("10") b...
36
46
0
141617589
# import sys # sys.stdout = open('DSA/Stacks/output.txt', 'w') # sys.stdin = open('DSA/Stacks/input.txt', 'r') n, m = map(int, input().split()) cc=0 for _ in range(n): ll = list(map(int, input().split())) i=1 while i<(2*m): if ll[i]==1 or ll[i-1]==1: cc+=1 i+=2 print(cc)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
595/A
595
A
Python 3
TESTS
6
109
0
49202168
f=lambda:map(int,input().split()) n,m=f() a=n c=0 while n: s=input().replace(' ','') c+=s.count('00') n-=1 print(a*m-c)
36
46
0
143816130
n,m = map(int,input().split(' ')) count = 0 for i in range(n): l = list(map(int,input().split(' '))) for i in range(0,2*m,2): if l[i] or l[i+1]: count += 1 print(count)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
595/A
595
A
Python 3
TESTS
6
109
0
49201345
f=lambda:map(int,input().split()) n,m=f() print(n*m-sum((''.join(input().split())).count('00') for i in range(n)))
36
46
0
145120395
n, m = map(int, input().split()) count = 0 for _ in range(n): windows = list(map(int, input().split())) for i in range(m): if windows[i*2] == 1 or windows[i*2+1] == 1: count += 1 print(count)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
595/A
595
A
PyPy 3
TESTS
6
92
20,172,800
124026518
n, m = map(int, input().split(' ')) res = 0 for _ in range(n): row = input().replace(' ', '') res += m - row.count('00') print(res)
36
46
0
149080874
n,m=map(int,input().split()) k=0 for i in ' '*n: a=list(map(int,input().split())) k+=sum([a[i]|a[i+1] for i in range(0,len(a),2)]) print(k)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
595/B
595
B
Python 3
PRETESTS
5
46
0
14154464
n, k = map(int, input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] blocks = n // k counter = [0] * blocks for i in range(blocks): a_i = a[i] b_i = b[i] count = 0 if k > 1: if b_i != 0: delta = ((b_i + 1) * (10 ** (k - 1))) // a_i - (b_i * (...
38
108
10,444,800
201145226
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(x, y): return x // y + 1 n, k = map(int, input().split()) mod = pow(10, 9) + 7 a = list(map(int, input().split())) b = list(map(int, input().split())) u = pow(10, k) - 1 v = pow(10, k - 1) ans = 1 for i, j in zip(a, b): ans ...
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Pasha and Phone
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of le...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., a...
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
null
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
[{"input": "6 2\n38 56 49\n7 3 4", "output": "8"}, {"input": "8 2\n1 22 3 44\n5 4 3 2", "output": "32400"}]
1,600
["binary search", "math"]
38
[{"input": "6 2\r\n38 56 49\r\n7 3 4\r\n", "output": "8\r\n"}, {"input": "8 2\r\n1 22 3 44\r\n5 4 3 2\r\n", "output": "32400\r\n"}, {"input": "2 1\r\n9 9\r\n9 9\r\n", "output": "1\r\n"}, {"input": "2 1\r\n9 9\r\n0 9\r\n", "output": "1\r\n"}, {"input": "4 1\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "540\r\n"}, {"input": "18...
false
stdio
null
true
351/D
351
D
Python 3
TESTS
10
1,684
9,625,600
147926952
from collections import defaultdict import sys readline=sys.stdin.readline class Segment_Tree: def __init__(self,N,f,e,lst=None): self.f=f self.e=e self.N=N if lst==None: self.segment_tree=[self.e]*2*self.N else: assert len(lst)<=self.N se...
29
2,495
84,889,600
202114591
# ====== author: kuanc (www.hank.fyi) | created: 04/15/23 01:14:36 CST ====== # from sys import stdin, stderr, stdout, setrecursionlimit from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter from itertools import accumulate, combinations, permutatio...
Codeforces Round 204 (Div. 1)
CF
2,013
3
256
Jeff and Removing Periods
Cosider a sequence, consisting of n integers: a1, a2, ..., an. Jeff can perform the following operation on sequence a: - take three integers v, t, k (1 ≤ v, t ≤ n; 0 ≤ k; v + tk ≤ n), such that av = av + t, av + t = av + 2t, ..., av + t(k - 1) = av + tk; - remove elements av, av + t, ..., av + t·k from the sequence a,...
The first line contains integer m (1 ≤ m ≤ 105). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 105). The third line contains integer q (1 ≤ q ≤ 105) — the number of questions. The next q lines contain pairs of integers, i-th of them contains a pair of integers li, ri (1 ≤ li ≤ ri ≤ m) — the description o...
In q lines print the answers to Jeff's queries. Print the answers according to the order of questions in input.
null
null
[{"input": "5\n2 2 1 1 2\n5\n1 5\n1 1\n2 2\n1 3\n2 3", "output": "2\n1\n1\n2\n2"}, {"input": "10\n2 1 3 3 3 3 1 3 1 1\n10\n4 8\n2 10\n1 10\n4 4\n1 3\n2 4\n6 7\n1 9\n2 5\n1 1", "output": "2\n3\n3\n1\n3\n2\n2\n3\n2\n1"}]
2,700
["data structures"]
29
[{"input": "5\r\n2 2 1 1 2\r\n5\r\n1 5\r\n1 1\r\n2 2\r\n1 3\r\n2 3\r\n", "output": "2\r\n1\r\n1\r\n2\r\n2\r\n"}, {"input": "10\r\n2 1 3 3 3 3 1 3 1 1\r\n10\r\n4 8\r\n2 10\r\n1 10\r\n4 4\r\n1 3\r\n2 4\r\n6 7\r\n1 9\r\n2 5\r\n1 1\r\n", "output": "2\r\n3\r\n3\r\n1\r\n3\r\n2\r\n2\r\n3\r\n2\r\n1\r\n"}, {"input": "15\r\n3 3 ...
false
stdio
null
true
595/A
595
A
Python 3
TESTS
5
109
0
45161078
n,m=map(int,input().split()) cnt=0 for i in range(n): a=list(map(int,input().split())) for i in range(m): if a[i]==1 or a[i+m]==1: cnt+=1 print(cnt)
36
46
0
151400121
inp = [int(x) for x in input().split(" ")] lights = [] not_sleeping = 0 for floor in range(inp[0]): lights.append([int(x) for x in input().split(" ")]) for floor in range(inp[0]): for j in range(0, (2*inp[1])-1, 2): if (lights[floor][j] + lights[floor][j+1])/2 > 0: not_s...
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
595/A
595
A
Python 3
PRETESTS
5
62
204,800
14145336
n, m = map(int, input().split()) lst = [] ans = 0 for i in range(n): lst.append(list(map(int, input().split()))) for i in range(n): for j in range(m): if lst[i][j] == 1 or lst[i][j + m] == 1: ans += 1 print(ans)
36
46
0
162419073
(floors, flats) = map(int, input().split(' ')) awaking = 0 for i in range(floors): windows = input().split() for i in range(2 * flats): windows[i] = int(windows[i]) for i in range(0, flats * 2, 2): if windows[i] == 1 or windows[i + 1] == 1: awaking += 1 print(awaking)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Vitaly and Night
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char...
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
null
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off. In the second test case the house has one floor and the first floor has three flats. The ligh...
[{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}]
800
["constructive algorithms", "implementation"]
36
[{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
false
stdio
null
true
1298/D
978
E
PyPy 3-64
TESTS
4
61
0
230622625
n,w = map(int, input().split()) nums = [int(x) for x in input().split()] low = 0 high = w cur = 0 for x in nums: cur+=x if cur + high > w: high = w - cur if cur + low < 0: low = -cur if low > high: print(-1) else: print(high-low+1)
42
62
0
166295293
import sys input = sys.stdin.readline n, m = map(int, input().split()) w = list(map(int, input().split())) a, b = 0, 0 c = 0 for i in w: c += i if c > 0: a = max(a, c) elif c < 0: b = min(b, c) if c > m or c < -m: print(0) exit(0) print(max(0, b+m - a+1))
Kotlin Heroes: Practice 3
ICPC
2,020
1
256
Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus ...
The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded...
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
null
In the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers. In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers. In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.
[{"input": "3 5\n2 1 -3", "output": "3"}, {"input": "2 4\n-1 1", "output": "4"}, {"input": "4 10\n2 4 1 2", "output": "2"}]
null
["*special", "combinatorics", "math"]
42
[{"input": "3 5\r\n2 1 -3\r\n", "output": "3\r\n"}, {"input": "2 4\r\n-1 1\r\n", "output": "4\r\n"}, {"input": "4 10\r\n2 4 1 2\r\n", "output": "2\r\n"}, {"input": "2 10\r\n-1 2\r\n", "output": "9\r\n"}, {"input": "3 4\r\n-3 -4 4\r\n", "output": "0\r\n"}, {"input": "10 1\r\n-1 -1 3 -4 2 3 0 -3 3 2\r\n", "output": "0\r\...
false
stdio
null
true
1298/D
978
E
Python 3
TESTS
4
31
0
208831459
n,w=map(int,input().split()) stop=list(map(int,input().split())) sol=w+1 min=0 max=w na7imin=0 na7imax=0 for i in stop: min+=i max+=i if min<0: if na7imin<abs(min): na7imin=abs(min) if max>w: if na7imax<max: na7imax=max-w print(sol-na7imin-na7imax)
42
62
0
175675041
n, w = map(int, input().split()) maxx = 0 minx = 0 current = 0 for i in map(int, input().split()): current += i if current > maxx: maxx = current if current < minx: minx = current if maxx - minx > w: print(0) else: print(w - maxx + minx + 1)
Kotlin Heroes: Practice 3
ICPC
2,020
1
256
Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus ...
The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded...
Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.
null
In the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers. In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers. In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.
[{"input": "3 5\n2 1 -3", "output": "3"}, {"input": "2 4\n-1 1", "output": "4"}, {"input": "4 10\n2 4 1 2", "output": "2"}]
null
["*special", "combinatorics", "math"]
42
[{"input": "3 5\r\n2 1 -3\r\n", "output": "3\r\n"}, {"input": "2 4\r\n-1 1\r\n", "output": "4\r\n"}, {"input": "4 10\r\n2 4 1 2\r\n", "output": "2\r\n"}, {"input": "2 10\r\n-1 2\r\n", "output": "9\r\n"}, {"input": "3 4\r\n-3 -4 4\r\n", "output": "0\r\n"}, {"input": "10 1\r\n-1 -1 3 -4 2 3 0 -3 3 2\r\n", "output": "0\r\...
false
stdio
null
true
671/B
671
B
Python 3
TESTS
5
61
4,608,000
17880396
def main(): n, k = map(int, input().split()) l = sorted(map(int, input().split())) lo, hi = l[0], l[-1] while lo < hi - 1: mid = (lo + hi) // 2 t = k for x in l: if x > mid: lo = mid break t -= mid - x if t < 0: ...
60
935
38,912,000
42128856
import sys inp = sys.stdin.read().splitlines() n,k = list(map(int,inp[0].split())) lst = list(map(int,inp[1].split())) lst.sort() total = sum(lst) lower = int(total/n) nupper = total%n if nupper == 0: upper = lower; else: upper = lower+1; nlower = n - nupper; i = 0; while i<n and lst[i]<lower: i...
Codeforces Round 352 (Div. 1)
CF
2,016
1
256
Robin Hood
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to t...
The first line of the input contains two integers n and k (1 ≤ n ≤ 500 000, 0 ≤ k ≤ 109) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement. The second line contains n integers, the i-th of them is ci (1 ≤ ci ≤ 109) — initial wealth of the i-th person.
Print a single line containing the difference between richest and poorest peoples wealth.
null
Lets look at how wealth changes through day in the first sample. 1. [1, 1, 4, 2] 2. [2, 1, 3, 2] or [1, 2, 3, 2] So the answer is 3 - 1 = 2 In second sample wealth will remain the same for each person.
[{"input": "4 1\n1 1 4 2", "output": "2"}, {"input": "3 1\n2 2 2", "output": "0"}]
2,000
["binary search", "greedy"]
60
[{"input": "4 1\r\n1 1 4 2\r\n", "output": "2\r\n"}, {"input": "3 1\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "10 20\r\n6 4 7 10 4 5 5 3 7 10\r\n", "output": "1\r\n"}, {"input": "30 7\r\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2\r\n", "output": "2\r\n"}, {"input": "2 0\r\n182 2\r\n", "output": "180...
false
stdio
null
true
727/E
727
E
PyPy 3-64
TESTS
49
1,497
62,361,600
140696720
# add k-1 chars onto the end of the string so we can deal with the loop over # assign game ids: # generate all the hash values of each game # sort the games # hash each possible substring with length k (length of game name) (O(1) time) # binary search the hash value of each substring in all the game hashes (log(g)) #...
87
3,244
54,476,800
158830314
import sys input = sys.stdin.buffer.readline p = 24738041398529 def process(n, k, S, G): g = len(G) matrix = [[0 for j in range(k)] for i in range(g)] sums = [0 for i in range(k)] word_dict = {} for i in range(g): word = 0 for j in range(k): si = ord(G[i][j])-ord('a')...
Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)
CF
2,016
4
512
Games on a CD
Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap. Thus, there is a c...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105) — the amount of games Tolya burned to the CD, and the length of each of the names. The second line of the input contains one string consisting of lowercase English letters — the string Tolya wrote on the CD, split in arbitrar...
If there is no answer, print "NO" (without quotes). Otherwise, print two lines. In the first line print "YES" (without quotes). In the second line, print n integers — the games which names were written on the CD. You should print games in the order they could have been written on the CD, it means, in clockwise order. ...
null
null
[{"input": "3 1\nabc\n4\nb\na\nc\nd", "output": "YES\n2 1 3"}, {"input": "4 2\naabbccdd\n4\ndd\nab\nbc\ncd", "output": "NO"}]
2,300
["data structures", "hashing", "string suffix structures", "strings"]
87
[{"input": "3 1\r\nabc\r\n4\r\nb\r\na\r\nc\r\nd\r\n", "output": "YES\r\n2 1 3 \r\n"}, {"input": "4 2\r\naabbccdd\r\n4\r\ndd\r\nab\r\nbc\r\ncd\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nkdcj\r\n4\r\ncj\r\nkd\r\njk\r\ndc\r\n", "output": "YES\r\n3 4 \r\n"}, {"input": "10 10\r\nlgfrjgityzwtmfyygmpsmokiwphewhpoelsvnctwxmp...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, k = map(int, f.readline().split()) cd_str = f.readline().strip() g = int(f.readline()) games = [f.readlin...
true
300/B
300
B
PyPy 3-64
TESTS
4
92
0
214170773
def dfs(s): vis[s] = True z.append(s) for i in range(len(d[s])): if not vis[d[s][i]]: dfs(d[s][i]) n,m=map(int, input().split()) d,z={},[] for i in range(m): a,b=map(int, input().split()) if a not in d.keys(): d[a] = [] if b not in d.keys(): d[b] = [] d[a].append(b); d[b].append(a)...
27
154
2,457,600
214171202
def dfs(s): vis[s] = True z.append(s) for i in range(len(p[s])): if not vis[p[s][i]]: dfs(p[s][i]) n, m = map(int, input().split()) p,z={},[] for i in range(m): a, b = map(int, input().split()) if a not in p.keys():p[a] = [] if b not in p.keys():p[b] = [] p[a].append(b)...
Codeforces Round 181 (Div. 2)
CF
2,013
2
256
Coach
A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the sa...
The first line of the input contains integers n and m (3 ≤ n ≤ 48, $$0 \leq m \leq \frac{n(n-1)}{2}$$. Then follow m lines, each contains a pair of integers ai, bi (1 ≤ ai < bi ≤ n) — the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It i...
If the required division into teams doesn't exist, print number -1. Otherwise, print $$\frac{\pi}{3}$$ lines. In each line print three integers xi, yi, zi (1 ≤ xi, yi, zi ≤ n) — the i-th team. If there are multiple answers, you are allowed to print any of them.
null
null
[{"input": "3 0", "output": "3 2 1"}, {"input": "6 4\n1 2\n2 3\n3 4\n5 6", "output": "-1"}, {"input": "3 3\n1 2\n2 3\n1 3", "output": "3 2 1"}]
1,500
["brute force", "dfs and similar", "graphs"]
27
[{"input": "3 0\r\n", "output": "3 2 1 \r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n3 4\r\n5 6\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "3 2 1 \r\n"}, {"input": "6 3\r\n1 2\r\n3 4\r\n5 6\r\n", "output": "-1\r\n"}, {"input": "15 9\r\n1 4\r\n1 6\r\n2 7\r\n2 11\r\n4 6\r\n5 12\r\n7 11\r\n9 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) pairs = [] for _ in range(m): a, b = map(int, f.readline().split()) pairs.appen...
true
1212/C
977
C
PyPy 3-64
TESTS
5
92
19,558,400
229111806
def solve(): input_line = input().split() number_el = int(input_line[0]) k = int(input_line[1]) erer = list(map(int, input().split())) if k == 0: if erer[0] - 1 == 0: return -1 else: return erer[0] - 1 erer.sort() if k == number_el: ...
38
139
27,545,600
232709964
n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() if k==0: if a[0]!=1: print(a[0]-1) else: print(-1) else: if k==n : print(a[-1]) elif a[k-1]<a[k]: print(a[k-1]) else: print(-1)
Kotlin Heroes: Practice 2
ICPC
2,019
2
256
Less or Equal
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$. Note that the sequence can contain equal e...
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
null
In the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$. In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this n...
[{"input": "7 4\n3 7 5 1 10 3 20", "output": "6"}, {"input": "7 2\n3 7 5 1 10 3 20", "output": "-1"}]
1,200
["*special", "sortings"]
38
[{"input": "7 4\r\n3 7 5 1 10 3 20\r\n", "output": "5\r\n"}, {"input": "7 2\r\n3 7 5 1 10 3 20\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n1\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3 0\r\n3 3 3\r\n", "output": "...
false
stdio
import sys def check_x_possible(n, k, a): a_sorted = sorted(a) if k == 0: if a_sorted[0] == 1: return False candidate = a_sorted[0] - 1 if candidate < 1: return False cnt = sum(1 for num in a if num <= candidate) return cnt == 0 else: ...
true
294/B
294
B
PyPy 3
TESTS
26
109
21,708,800
129141520
n=int(input()) a=[0]*n for i in range(n): a[i]=list(map(int,input().split())) s=sum(x[1] for x in a) x=10000 dp=[0]*x for v,w in a: for i in range(x-1,v-1,-1): dp[i]=max(dp[i],dp[i-v]+w) for i in range(x): if i>=s-dp[i]: print(i) break
27
46
0
213222025
n=int(input()) t1,t2=[],[] for i in range(n): t,w=map(int,input().split()) if t==1: t1.append(w) else: t2.append(w) t1.sort() t2.sort() ans=1000000 maxw=len(t1)+len(t2)*2 for i_t1 in range(len(t1)+1): for i_t2 in range(len(t2)+1): if sum(t1[:i_t1])+sum(t2[:i_t2])<=maxw-(i_t1+i_t2...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
294/B
294
B
PyPy 3
TESTS
26
109
1,740,800
173590546
import collections import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os ###################################################################################### #--------------------------------------funs here-------------------------------------# ###################...
27
62
2,764,800
167646394
class Book: def __init__(self, thickness, width): self.thickness = thickness self.width = width n = int(input()) books = [] total = 0 for i in range(0, n): thickness, width = map(int, input().split()) books.append(Book(thickness, width)) total += thickness def getValue(i): return i...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
46/C
46
C
Python 3
TESTS
2
62
0
218366053
n = int(input()) s = input() # Count the total number of tigers. tigers = s.count('T') # Create a cyclic version of the arrangement. s += s[:tigers-1] # Use the sliding window to find the maximum number of tigers in any segment of length "tigers". max_tigers = 0 current_tigers = s[:tigers].count('T') for i in range(...
27
62
0
218584704
n = int(input()) s = input() s = s+s count = s.count("H") // 2 x = 0 for i in range(n): z = s[i:i + count].count('H') x = max(x,z) print(count-x)
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
1212/C
977
C
PyPy 3-64
TESTS
27
171
27,545,600
223691140
n,k=map(int,input().split()) a=sorted(list(map(int,input().split()))) if k==n: print(a[-1]) quit() try: s=a[k-1] if k==1: print(a[0]) elif k==0: if a[0]>1: print(a[0]-1) else: print(-1) elif s==a[k]: print(-1) else: print(s) except: print(-1)
38
140
26,726,400
223967340
n,k = map(int, input().split()) a = list(map(int, input().split())) a.sort() if k == 0: print(a[0] - 1 if a[0] - 1 > 0 else -1) elif n == k: print(a[-1]) else: if a[k-1] < a[k]: print(a[k-1]) else: print(-1)
Kotlin Heroes: Practice 2
ICPC
2,019
2
256
Less or Equal
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$. Note that the sequence can contain equal e...
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
null
In the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$. In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this n...
[{"input": "7 4\n3 7 5 1 10 3 20", "output": "6"}, {"input": "7 2\n3 7 5 1 10 3 20", "output": "-1"}]
1,200
["*special", "sortings"]
38
[{"input": "7 4\r\n3 7 5 1 10 3 20\r\n", "output": "5\r\n"}, {"input": "7 2\r\n3 7 5 1 10 3 20\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n1\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3 0\r\n3 3 3\r\n", "output": "...
false
stdio
import sys def check_x_possible(n, k, a): a_sorted = sorted(a) if k == 0: if a_sorted[0] == 1: return False candidate = a_sorted[0] - 1 if candidate < 1: return False cnt = sum(1 for num in a if num <= candidate) return cnt == 0 else: ...
true
706/A
706
A
Python 3
TESTS
2
30
0
216364703
firstin = [input() for i in range(2)] lokshun = list(map(int, firstin[0].split())) taxicount = int(firstin[1]) del firstin fastest = [] for c in range(taxicount): ipt = list(map(int, input().split())) coord = ipt[:2] speed = ipt[2] pair = [[a,b] for a,b in zip(coord, lokshun) if a != b] if len(p...
53
46
0
218820833
import math def calculate_time(x, y, v): return math.sqrt(x**2 + y**2) / v a, b = map(int, input().split()) n = int(input()) min_time = float('inf') # Initialize min_time to positive infinity for _ in range(n): xi, yi, vi = map(int, input().split()) time = calculate_time(a - xi, b - yi, vi) # Calculat...
Codeforces Round 367 (Div. 2)
CF
2,016
1
256
Beru-taxi
Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy a...
The first line of the input contains two integers a and b ( - 100 ≤ a, b ≤ 100) — coordinates of Vasiliy's home. The second line contains a single integer n (1 ≤ n ≤ 1000) — the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≤ xi, yi ≤ 100, 1...
Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer corr...
null
In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
[{"input": "0 0\n2\n2 0 1\n0 2 2", "output": "1.00000000000000000000"}, {"input": "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10", "output": "0.50000000000000000000"}]
900
["brute force", "geometry", "implementation"]
53
[{"input": "0 0\r\n2\r\n2 0 1\r\n0 2 2\r\n", "output": "1.00000000000000000000"}, {"input": "1 3\r\n3\r\n3 3 2\r\n-2 3 6\r\n-2 7 10\r\n", "output": "0.50000000000000000000"}, {"input": "2 2\r\n10\r\n8 10 1\r\n14 18 5\r\n2 2 1\r\n4 2 2\r\n5 2 1\r\n0 2 1\r\n2 10 4\r\n10 2 4\r\n14 18 20\r\n14 18 10\r\n", "output": "0.0000...
false
stdio
import math def compute_min_time(input_path): with open(input_path, 'r') as f: a, b = map(int, f.readline().split()) n = int(f.readline()) min_time = float('inf') for _ in range(n): xi, yi, vi = map(int, f.readline().split()) dx = xi - a dy = yi -...
true
580/B
580
B
Python 3
TESTS
9
31
0
227133979
def R():return map(int,input().split()) a,b=R();B={} A=sorted([[*R()] for _ in range(a)]) for I in A: x,y=I for m in B: if x<m:B[m]+=y B[x+b]=y print(max(B.values()))
35
373
19,353,600
224986696
n, d = map(int,input().split()) d1 = {} for i in range(n): a1,a2 = map(int,input().split()) if a1 in d1: n -= 1 d1[a1] += a2 else: d1[a1] = a2 d1 = list(d1.items()) d1 = sorted(d1) i = 0 j = -1 s = 0 s1 = s while j+1<n: j += 1 s += d1[j][1] while d1[i][0] + d <= d1[j][...
Codeforces Round 321 (Div. 2)
CF
2,015
2
256
Kefa and Company
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to...
The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, $$1 \leq d \leq 10^9$$) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contai...
Print the maximum total friendship factir that can be reached.
null
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse. In the second sample test we can take all the friends.
[{"input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100"}, {"input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111"}]
1,500
["binary search", "sortings", "two pointers"]
35
[{"input": "4 5\r\n75 5\r\n0 100\r\n150 20\r\n75 1\r\n", "output": "100\r\n"}, {"input": "5 100\r\n0 7\r\n11 32\r\n99 10\r\n46 8\r\n87 54\r\n", "output": "111\r\n"}, {"input": "1 1000000000\r\n15 12\r\n", "output": "12\r\n"}, {"input": "5 1\r\n5 9\r\n2 10\r\n8 5\r\n18 12\r\n1 1\r\n", "output": "12\r\n"}, {"input": "3 3...
false
stdio
null
true
508/C
508
C
PyPy 3-64
TESTS
3
46
0
181874686
import sys input = sys.stdin.readline m, t, r = map(int, input().split()) w = list(map(int, input().split())) d = [] q = 0 if t + 1 < r: print(-1) exit() for i in range(m): if len(d) == 0: x = r else: ed = [] a = w[i] - t c = 0 for i1, i2 in d: if i2...
61
62
0
9583751
m, t, r = map(int, input().split()) data = list(map(int, input().split())) if r > t: print(-1) else: candles = [] total = 0 for x in data: while candles and candles[0] + t - 1 < x: candles.pop(0) need = r - len(candles) for n in range(need): candles.ap...
Codeforces Round 288 (Div. 2)
CF
2,015
2
256
Anya and Ghosts
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one can...
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them r...
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1.
null
Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from se...
[{"input": "1 8 3\n10", "output": "3"}, {"input": "2 10 1\n5 8", "output": "1"}, {"input": "1 1 3\n10", "output": "-1"}]
1,600
["constructive algorithms", "greedy"]
61
[{"input": "1 8 3\r\n10\r\n", "output": "3\r\n"}, {"input": "2 10 1\r\n5 8\r\n", "output": "1\r\n"}, {"input": "1 1 3\r\n10\r\n", "output": "-1\r\n"}, {"input": "21 79 1\r\n13 42 51 60 69 77 94 103 144 189 196 203 210 215 217 222 224 234 240 260 282\r\n", "output": "4\r\n"}, {"input": "125 92 2\r\n1 2 3 4 5 7 8 9 10 12...
false
stdio
null
true
169/A
169
A
Python 3
TESTS
6
93
0
49765305
f=lambda:map(int,input().split()) n,p,v=f() l=list(f()) l.sort() (p,v)=(max(p,v),min(p,v)) if len(l[:p])==p and len(l[p:])==v: print(l[p]-l[p-1]) else: print(0)
29
31
0
153845602
n, a, b = map(int, input().split()) w = sorted(map(int, input().split())) print(w[b]-w[b-1])
VK Cup 2012 Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Chores
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi. As Petya is older, he wants to take the chores with complexity larger...
The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t...
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
null
In the first sample the possible values of x are 3, 4 or 5. In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
[{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}]
800
["sortings"]
29
[{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "...
false
stdio
null
true
169/A
169
A
Python 3
TESTS
6
109
0
49764325
f=lambda:map(int,input().split()) n,p,v=f() l=list(f()) l.sort() (p,v)=(max(p,v),min(p,v)) print(l[p]-l[p-1])
29
31
0
159515922
inputs = list(map(int,input().split(" "))) n = inputs[0] olderBrother = inputs[1] arr = list(map(int,input().split(" "))) arr = sorted(arr, reverse=True) sum=arr[olderBrother-1]-arr[olderBrother] if sum>0: print(sum) else: print(0)
VK Cup 2012 Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Chores
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi. As Petya is older, he wants to take the chores with complexity larger...
The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t...
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
null
In the first sample the possible values of x are 3, 4 or 5. In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
[{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}]
800
["sortings"]
29
[{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "...
false
stdio
null
true
543/C
543
C
Python 3
TESTS
3
77
409,600
111156906
from copy import deepcopy size = [int(x) for x in input().split(" ")] n = size[0] m = size[1] # def check(arr): # for num in arr: # if 1 not in num: # return False # return True inputs = [] for i in range(0, n): inputs.append(input()) # arr = [] # for i in range(0, m): # arr.ap...
51
686
21,504,000
172918363
I=input;R,G=lambda:map(int,I().split()),range;n,m=R();s=[I()for _ in G(n)] a=[[*R()]for _ in G(n)];N=1<<n;f=[float('inf')]*(N);f[0]=0 c=[[0]*m for _ in G(n)];sv=[[0]*m for _ in G(n)] for i in G(n): for j in G(m): v=0 for k in G(n): if s[i][j]==s[k][j]:sv[i][j]|=(1<<k);c[i][j]+=a[k][j];v=max(v,a[k][j]) ...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Remembering Strings
You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English alphabet, such that this string is the only string in the multiset that has letter c in position i....
The first line contains two integers n, m (1 ≤ n, m ≤ 20) — the number of strings in the multiset and the length of the strings respectively. Next n lines contain the strings of the multiset, consisting only of lowercase English letters, each string's length is m. Next n lines contain m integers each, the i-th of them...
Print a single number — the answer to the problem.
null
null
[{"input": "4 5\nabcde\nabcde\nabcde\nabcde\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "output": "3"}, {"input": "4 3\nabc\naba\nadc\nada\n10 10 10\n10 1 10\n10 10 10\n10 1 10", "output": "2"}, {"input": "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1", "output": "0"}]
2,500
["bitmasks", "dp"]
51
[{"input": "4 5\r\nabcde\r\nabcde\r\nabcde\r\nabcde\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "4 3\r\nabc\r\naba\r\nadc\r\nada\r\n10 10 10\r\n10 1 10\r\n10 10 10\r\n10 1 10\r\n", "output": "2\r\n"}, {"input": "3 3\r\nabc\r\nada\r\nssa\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "outpu...
false
stdio
null
true
294/B
294
B
PyPy 3-64
TESTS
11
93
10,956,800
169451397
import sys import math import collections from heapq import heappush, heappop from functools import reduce input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n = int(input()) b = [] mx = 0 for _ in range(n): t, w = ints() mx += w b.append((t, w)) dp = [[math.inf for _ in range(mx ...
27
77
1,638,400
145000837
n = int(input()) t = [0]*(n+1) w = [0]*(n+1) S = 0 for i in range(1, n+1): t[i], w[i] = map(int, input().split()) S += t[i] dp = [float('inf')]*(S+1) dp[0] = 0 for i in range(1, n+1): for j in range(S, t[i]-1, -1): dp[j] = min(dp[j], dp[j-t[i]]+w[i]) for i in range(S, -1, -1): if S-i >= dp[i...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
294/B
294
B
PyPy 3
TESTS
11
77
1,433,600
104087854
#!/usr/bin/env python3 # created : 2020. 12. 31. 23:59 import os from sys import stdin, stdout def solve(tc): n = int(stdin.readline().strip()) tsum = 0 wsum = 0 books = [] for i in range(n): books.append(list(map(int, stdin.readline().split()))) tsum += books[-1][0] wsum ...
27
93
1,331,200
104876383
n=int(input()) t1=[] t2=[] for _ in range(n): t,w=map(int,input().split()) if t==1: t1.append(w) else: t2.append(w) t1.sort() t2.sort() n1=len(t1) n2=len(t2) p1=[0] p2=[0] for i in range(n1): p1.append(p1[-1]+t1[i]) for i in range(n2): p2.append(t2[i]+p2[-1]) ans=1 while True: am...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
294/B
294
B
PyPy 3
TESTS
26
140
1,331,200
97716675
n=int(input()) width,thickness=[],[] one,two=[],[] for _ in range(n): ti,wi=map(int,input().split()) thickness.append(ti),width.append(wi) if ti==1:one.append(wi) if ti==2:two.append(wi) one.sort(),two.sort() one=[0]+one two=[0]+two for i in range(1,len(one)): one[i]=one[i-1]+one[i] for i in range(1...
27
124
0
60513672
#!/usr/bin/python3 n = int(input()) t = [] w = [] n1, n2 = 0, 0 for i in range(n): x, y = map(int, input().split()) t.append(x) w.append(y) n1 += x == 1 n2 += x == 2 w1 = [] w2 = [] for i in range(n): if t[i] == 1: w1.append(w[i]) else: w2.append(w[i]) w1.sort(reverse=True)...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
294/B
294
B
Python 3
TESTS
26
124
307,200
102523942
n = int(input()) t = [] for i in range(n): e = list(map(int,input().split())) t.append(e) size = 0 size2 = 0 for i in t: size += i[0] size2 += i[1] matrix = [[0]*(size+1) for i in range(n)] for i in range(n): for j in range(1,size+1): if t[i][0] <= j: matrix[i][j] = max(matr...
27
124
716,800
50413805
R = lambda: map(int, input().split()) n = int(input()) unset = -1000000 bs = [[0, 0]] + [list(R()) for i in range(n)] dp = [[unset] * 201 for i in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(201): t, w = bs[i + 1][0], bs[i + 1][1] if dp[i][j] != unset: dp[i + 1][j + t] =...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
167/B
167
B
PyPy 3
TESTS
2
528
5,939,200
54587279
from fractions import Fraction n, l, k = map(int, input().split(' ')) p = list(map(int, input().split(' '))) a = list(map(int, input().split(' '))) memo = {} def solve(curr, cap, won): if curr == n: if cap >= k and won >= l: return 1 else: return 0 if (curr, cap, won) ...
94
404
512,000
42123510
from collections import * f = lambda: list(map(int, input().split())) n, l, a = f() p, s = f(), f() m = s.count(-1) x = {(0, min(a, m)): 1} r = [1] for p, s in zip(p, s): p /= 100 if s > 0: y = defaultdict(int) for (k, a), q in x.items(): y[(k, a)] += q - q * p ...
Codeforces Round 114 (Div. 1)
CF
2,012
2
256
Wizards and Huge Prize
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees. One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've b...
The first line contains three integers n, l, k (1 ≤ n ≤ 200, 0 ≤ l, k ≤ 200) — the number of tours, the minimum number of tours to win, and the number of prizes that you can fit in the bags brought from home, correspondingly. The second line contains n space-separated integers, pi (0 ≤ pi ≤ 100) — the probability to w...
Print a single real number — the answer to the problem. The answer will be accepted if the absolute or relative error does not exceed 10 - 6.
null
In the first sample we need either win no tour or win the third one. If we win nothing we wouldn't perform well. So, we must to win the third tour. Other conditions will be satisfied in this case. Probability of wining the third tour is 0.3. In the second sample we win the only tour with probability 1.0, and go back h...
[{"input": "3 1 0\n10 20 30\n-1 -1 2", "output": "0.300000000000"}, {"input": "1 1 1\n100\n123", "output": "1.000000000000"}]
1,800
["dp", "math", "probabilities"]
94
[{"input": "3 1 0\r\n10 20 30\r\n-1 -1 2\r\n", "output": "0.300000000000\r\n"}, {"input": "1 1 1\r\n100\r\n123\r\n", "output": "1.000000000000\r\n"}, {"input": "5 1 2\r\n36 44 13 83 63\r\n-1 2 -1 2 1\r\n", "output": "0.980387276800\r\n"}, {"input": "9 9 2\r\n91 96 99 60 42 67 46 39 62\r\n5 -1 2 -1 -1 -1 7 -1 3\r\n", "o...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(output_path) as f: expected_str = f.read().strip() with open(submission_path) as f: submission_str = f.read().strip() try: expected = float(expected_str) submission = float(submission_str) exce...
true
75/C
75
C
Python 3
TESTS
13
218
0
221754565
import math def solve(a, b, n): for _ in range(n): l, r = map(int, input().split()) minn = min(a,b); maxx = max(a, b) if l == minn: if maxx % minn == 0: print(minn) else: print(-1) elif l > minn: print(-1) ...
60
278
7,987,200
86110101
from sys import stdin from bisect import bisect def divisors(n): ans = set() i = 1 while i * i <= n: if n % i == 0: ans.add(i) i += 1 return ans | {n // e for e in ans} test = stdin.readlines() a, b = map(int, test[0].split()) n = int(test[1]) cdiv = sorted(divisors(a) ...
Codeforces Beta Round 67 (Div. 2)
CF
2,011
2
256
Modified GCD
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task...
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
null
null
[{"input": "9 27\n3\n1 5\n10 11\n9 11", "output": "3\n-1\n9"}]
1,600
["binary search", "number theory"]
60
[{"input": "9 27\r\n3\r\n1 5\r\n10 11\r\n9 11\r\n", "output": "3\r\n-1\r\n9\r\n"}, {"input": "48 72\r\n2\r\n8 29\r\n29 37\r\n", "output": "24\r\n-1\r\n"}, {"input": "90 100\r\n10\r\n51 61\r\n6 72\r\n1 84\r\n33 63\r\n37 69\r\n18 21\r\n9 54\r\n49 90\r\n14 87\r\n37 90\r\n", "output": "-1\r\n10\r\n10\r\n-1\r\n-1\r\n-1\r\n1...
false
stdio
null
true
294/B
294
B
Python 3
TESTS
26
62
4,505,600
132977118
n = int(input()) v = [] w = [] total_v = 0 total_w = 0 for i in range(n): a,b = map(int,input().split()) v.append(a) w.append(b) total_v += a total_w += b dp = [[0]*(total_v + 1) for i in range(n)] for i in range(n): for j in range(total_v + 1): if j >= v[i]: dp[i][j] = ma...
27
155
0
97401690
n = int(input()) lis = [] for _ in range(n): tt, ww = [int(x) for x in input().split()] lis.append((tt, -ww)) lis.sort() sum1, sum2 = [0], [0] for i in range(n): if lis[i][0] == 1: sum1.append(sum1[-1] - lis[i][1]) else: sum2.append(sum2[-1] - lis[i][1]) ans = 1000000000 k1, k2 = len(sum...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Bookshelf
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the b...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
null
null
[{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}]
1,700
["dp", "greedy"]
27
[{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r...
false
stdio
null
true
779/C
779
C
Python 3
TESTS
17
233
8,704,000
52715668
n,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) sum_max = sum(b) c = list(map(lambda x,y :x-y , a,b)) # print(c) left = sorted(list(filter(lambda t: t<0,c))) right = sorted(list(filter(lambda t:t>0,c))) # print(left) # print(right) if len(left) >= k: sum_max += sum...
67
156
31,539,200
210693325
n,k=map(int,input().split()) ll=list(map(int,input().split())) kk=list(map(int,input().split())) ff=[] t,c,m=0,0,k for i in range(n): r=kk[i]-ll[i] if r>=0: c+=ll[i] m-=1 else: t+=kk[i] ff.append(r) tt=[] ff.sort(reverse=True) if m>0: c+=(t-sum(ff[:m])) else: c+=t pri...
Codeforces Round 402 (Div. 2)
CF
2,017
2
256
Dishonest Sellers
Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discou...
In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third...
Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.
null
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ...
[{"input": "3 1\n5 4 6\n3 1 5", "output": "10"}, {"input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25"}]
1,200
["constructive algorithms", "greedy", "sortings"]
67
[{"input": "3 1\r\n5 4 6\r\n3 1 5\r\n", "output": "10\r\n"}, {"input": "5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n", "output": "25\r\n"}, {"input": "1 0\r\n9\r\n8\r\n", "output": "8\r\n"}, {"input": "2 0\r\n4 10\r\n1 2\r\n", "output": "3\r\n"}, {"input": "4 2\r\n19 5 17 13\r\n3 18 8 10\r\n", "output": "29\r\n"}, {"input": "5 ...
false
stdio
null
true
779/C
779
C
Python 3
TESTS
21
358
22,220,800
26747057
n, k = map(int, input().split() ) a = list(map(int, input().split() ) ) b = list(map(int, input().split() ) ) c = 0 ans = sum(a) dif = [0] * n for i in range( len(a) ): dif[i] = b[i]-a[i] dif = sorted(dif) for i in range( len(dif) ): if dif[i] < 0: ans += dif[i] c+=1 if c == n-k: b...
67
202
23,961,600
192869678
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [i - j for i, j in zip(a, b)] c.sort() ans = sum(b) + sum(c[:k]) for i in c[k:]: ans += min(0, i) print(ans)
Codeforces Round 402 (Div. 2)
CF
2,017
2
256
Dishonest Sellers
Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discou...
In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third...
Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.
null
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ...
[{"input": "3 1\n5 4 6\n3 1 5", "output": "10"}, {"input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25"}]
1,200
["constructive algorithms", "greedy", "sortings"]
67
[{"input": "3 1\r\n5 4 6\r\n3 1 5\r\n", "output": "10\r\n"}, {"input": "5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n", "output": "25\r\n"}, {"input": "1 0\r\n9\r\n8\r\n", "output": "8\r\n"}, {"input": "2 0\r\n4 10\r\n1 2\r\n", "output": "3\r\n"}, {"input": "4 2\r\n19 5 17 13\r\n3 18 8 10\r\n", "output": "29\r\n"}, {"input": "5 ...
false
stdio
null
true
779/C
779
C
Python 3
TESTS
21
343
18,227,200
116693196
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) wynik = 0 lista = [] if n == k: for x in range(n): wynik = wynik + b[x] else: for x in range(n): wynik = wynik + b[x] roznica = a[x] - b[x] if roznica < 0: w...
67
202
30,208,000
162908968
def Solucion(n,k,a,b): res = 0 dishonest = [] for i in range(n): if b[i] - a[i] >= 0: k-=1 res += a[i] else: res += b[i] dishonest.append(a[i] - b[i]) if k > 0: dishonest.sort() for i in range(k): res+=disho...
Codeforces Round 402 (Div. 2)
CF
2,017
2
256
Dishonest Sellers
Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discou...
In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third...
Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.
null
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ...
[{"input": "3 1\n5 4 6\n3 1 5", "output": "10"}, {"input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25"}]
1,200
["constructive algorithms", "greedy", "sortings"]
67
[{"input": "3 1\r\n5 4 6\r\n3 1 5\r\n", "output": "10\r\n"}, {"input": "5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n", "output": "25\r\n"}, {"input": "1 0\r\n9\r\n8\r\n", "output": "8\r\n"}, {"input": "2 0\r\n4 10\r\n1 2\r\n", "output": "3\r\n"}, {"input": "4 2\r\n19 5 17 13\r\n3 18 8 10\r\n", "output": "29\r\n"}, {"input": "5 ...
false
stdio
null
true
686/A
686
A
Python 3
TESTS
11
46
0
198413886
storage=list(map(int,input( ).split())) loops=storage[0];icecreem_you_have=storage[1];counter1=0 for i in range(loops): possitive,numbers=input().split();numbers=int(numbers) if possitive=='+': icecreem_you_have+=numbers elif possitive=='-' and icecreem_you_have>=numbers: icecreem_you_ha...
34
31
0
144079083
s=input().split() n=int(s[0]) x=int(s[1]) p=x dis=0 for i in range(n): s=input().split() c=s[0] d=int(s[1]) if c=='+': p+=d else: if d>p: dis+=1 else: p-=d print(p,dis)
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Free Ice Cream
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the q...
The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the q...
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
null
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 2. Carrier brings 5 more, so now they have 12 packs. 3. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 5. Car...
[{"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1"}, {"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2"}]
800
["constructive algorithms", "implementation"]
34
[{"input": "5 7\r\n+ 5\r\n- 10\r\n- 20\r\n+ 40\r\n- 20\r\n", "output": "22 1\r\n"}, {"input": "5 17\r\n- 16\r\n- 2\r\n- 98\r\n+ 100\r\n- 98\r\n", "output": "3 2\r\n"}, {"input": "6 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n+ 1000000000\r\n", "output": "7000000000 0\r\...
false
stdio
null
true
344/A
344
A
PyPy 3-64
TESTS
13
122
0
228401906
n = int(input()) o = 0 q = 1 l = [] a = 1 if n == 100000: print(100000) else: for i in range(n): m = input() l.append(m) f = l[0] i = 1 while n > q: if f == l[i]: a = a else: f = l[i] o += 1 q += 1 i += 1 print(o...
31
92
0
217196850
p=f=-1 for s in open(0):f+=p!=s;p=s print(f)
Codeforces Round 200 (Div. 2)
CF
2,013
1
256
Magnets
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
null
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
[{"input": "6\n10\n10\n10\n01\n10\n10", "output": "3"}, {"input": "4\n01\n01\n10\n10", "output": "2"}]
800
["implementation"]
31
[{"input": "6\r\n10\r\n10\r\n10\r\n01\r\n10\r\n10\r\n", "output": "3\r\n"}, {"input": "4\r\n01\r\n01\r\n10\r\n10\r\n", "output": "2\r\n"}, {"input": "1\r\n10\r\n", "output": "1\r\n"}, {"input": "2\r\n01\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n10\r\n10\r\n", "output": "1\r\n"}, {"input": "3\r\n10\r\n01\r\n10\r\n...
false
stdio
null
true