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
755/B
755
B
PyPy 3-64
TESTS
14
124
5,120,000
187422326
n, m = list(map(int, input().split())) poland, enemy = set(), set() for _ in range(n): poland.add(input()) for _ in range(m): enemy.add(input()) common = poland.intersection(enemy) poland = poland.difference(common) enemy = enemy.difference(common) even = (len(common) % 2) == 0 if (even and len(poland) > le...
33
31
1,433,600
217500365
n,m=map(int,input().split()) a={input() for x in range(n)} b={input() for y in range(m)} t=n+m-len(a|b) print('YES' if n+t%2>m else 'NO')
8VC Venture Cup 2017 - Elimination Round
CF
2,017
1
256
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than onc...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
null
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
[{"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES"}, {"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES"}, {"input": "1 2\na\na\nb", "output": "NO"}]
1,100
["binary search", "data structures", "games", "greedy", "sortings", "strings"]
33
[{"input": "5 1\r\npolandball\r\nis\r\na\r\ncool\r\ncharacter\r\nnope\r\n", "output": "YES"}, {"input": "2 2\r\nkremowka\r\nwadowicka\r\nkremowka\r\nwiedenska\r\n", "output": "YES"}, {"input": "1 2\r\na\r\na\r\nb\r\n", "output": "NO"}, {"input": "2 2\r\na\r\nb\r\nb\r\nc\r\n", "output": "YES"}, {"input": "2 1\r\nc\r\na\...
false
stdio
null
true
25/D
25
D
PyPy 3
TESTS
21
372
3,891,200
97113322
n=int(input()) # Python3 program to implement Disjoint Set Data # Structure. class DisjSet: def __init__(self, n): # Constructor to create and # initialize sets of n items self.rank = [1] * n self.parent = [i for i in range(n)] self.extra=[] # Finds set of given item x ...
55
92
0
156916447
# Python3 STDIN """ import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) 1) inp ...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
null
null
[{"input": "2\n1 2", "output": "0"}, {"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7"}]
1,900
["dsu", "graphs", "trees"]
55
[{"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 7\r\n", "output": "1\r\n3 1 3 7\r\n"}, {"input": "3\r\n3 2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n3 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 4\r\n3 1\r\n3 4\r\n", "output": "1\r\n3 4 2 4\r\n"}, {"in...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) edges = set() for _ in range(n-1): a, b = map(int, f.readline().split()) if a > b: a, b = b, a edges.add((a, b)) return n, edges def check_in...
true
978/D
978
D
PyPy 3-64
TESTS
6
77
17,817,600
230440346
import math from math import lcm if __name__ == "__main__": n = int(input()) arr = list(map(int, input().split())) arr.sort() ans = [] for i in range(n-1): ans.append(arr[i+1] - arr[i]) total_moves = 0 #print(ans) for i in range(len(ans)-1): if ans[i] > ans[i+1]: ...
39
108
14,745,600
182220548
n = int (input()) arr = list (map (int, input().split(' ')) ) if (n <= 2 ): print (0) exit() ans = -1 one = [0,-1,1] two = [0,-1,1] for i in one: for j in two: d = (arr[1]-j) - (arr[0]-i) x = arr[0] - i res = 0 if i != 0: res = 1 ok = True ...
Codeforces Round 481 (Div. 3)
ICPC
2,018
1
256
Almost Arithmetic Progression
Polycarp likes arithmetic progressions. A sequence $$$[a_1, a_2, \dots, a_n]$$$ is called an arithmetic progression if for each $$$i$$$ ($$$1 \le i < n$$$) the value $$$a_{i+1} - a_i$$$ is the same. For example, the sequences $$$[42]$$$, $$$[5, 5, 5]$$$, $$$[2, 11, 20, 29]$$$ and $$$[3, 2, 1, 0]$$$ are arithmetic progr...
The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100\,000)$$$ — the number of elements in $$$b$$$. The second line contains a sequence $$$b_1, b_2, \dots, b_n$$$ $$$(1 \le b_i \le 10^{9})$$$.
If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't us...
null
In the first example Polycarp should increase the first number on $$$1$$$, decrease the second number on $$$1$$$, increase the third number on $$$1$$$, and the fourth number should left unchanged. So, after Polycarp changed three elements by one, his sequence became equals to $$$[25, 20, 15, 10]$$$, which is an arithme...
[{"input": "4\n24 21 14 10", "output": "3"}, {"input": "2\n500 500", "output": "0"}, {"input": "3\n14 5 1", "output": "-1"}, {"input": "5\n1 3 6 9 12", "output": "1"}]
1,500
["brute force", "implementation", "math"]
39
[{"input": "4\r\n24 21 14 10\r\n", "output": "3\r\n"}, {"input": "2\r\n500 500\r\n", "output": "0\r\n"}, {"input": "3\r\n14 5 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 3 6 9 12\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 1\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
63/A
63
A
Python 3
TESTS
4
186
307,200
94518226
n = int(input()) cap = '' w = [] m = [] for i in range(n): y = list(map(str, input().split())) if y[1] == 'captain': cap = y[0] elif y[1] == 'woman' or y[1] == 'child': w.append(y[0]) elif y[1] == 'man': m.append(y[0]) else: w.insert(0, y[0]) for i in w: print(i) for i in m: print(i) print(cap)
26
62
0
223624267
# Function to determine the evacuation order def evacuate_crew(n, crew_info): # Create a list of tuples (name, status, position) crew_list = [(crew_info[i][0], crew_info[i][1], i) for i in range(n)] # Define a custom sorting order def sorting_order(member): order = {"rat": 1, "woman": 2, "child...
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
299/B
299
B
Python 3
TESTS
32
342
7,577,600
35142111
from sys import stdin def read(): line = stdin.readline(); if line == "": exit(); return line; def main(): while True: n, k = map(int, read().split()); m = read(); dp = [0]*n; cnt = 0; for i in range(min(k+1,n)): if m[i] == '.': dp[i] = 1; cnt += 1; for i in r...
33
92
716,800
167119387
n,k = input().split() a = input() if "#"*(int(k)) in a: print("NO") else: print("YES")
Croc Champ 2013 - Round 2 (Div. 2 Edition)
CF
2,013
1
256
Ksusha the Squirrel
Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ks...
The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".".
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 1\n..", "output": "YES"}, {"input": "5 2\n.#.#.", "output": "YES"}, {"input": "7 3\n.#.###.", "output": "NO"}]
900
["brute force", "implementation"]
33
[{"input": "2 1\r\n..\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n.#.#.\r\n", "output": "YES\r\n"}, {"input": "7 3\r\n.#.###.\r\n", "output": "NO\r\n"}, {"input": "10 3\r\n..........\r\n", "output": "YES\r\n"}, {"input": "2 200\r\n..\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n..\r\n", "output": "YES\r\n"}, {"input...
false
stdio
null
true
46/C
46
C
Python 3
TESTS
8
154
7,065,600
37920226
R = lambda : map(int, input().split()) n = int(input()) s = input() c = 'H' if s.count('H') < s.count('T') else 'T' oc = 'H' if c == 'T' else 'T' l = s.find(c) cc = s.count(c) print(s[l:l + cc].count(oc))
27
92
0
139468732
n = int(input()) s = input() * 2 count = s.count("H") // 2 print(count - max(s[i:i + count].count('H') for i in range(n)))
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
46/C
46
C
Python 3
TESTS
10
216
307,200
91793311
n=int(input()) s=input() hct=s.count("H") tct=s.count("T") if(hct==1 or tct==1): print(0) exit() else: tlast=0 lindx=0 for i in range(n-1,-1,-1): if(s[i]=="H"): lindx=i break else: tlast+=1 if(tlast==tct): print(0) exit() fi...
27
92
0
143133605
n = int(input()) s = input() * 2 count = s.count("H") // 2 print(count - max(s[i:i + count].count('H') for i in range(n)))
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
644/C
644
C
Python 3
TESTS
52
888
38,400,000
16768808
P = 910519 MOD = 10 ** 9 + 7 p = [1] for i in range(1, 200010): p.append((P * p[i - 1]) % MOD) n = int(input()) s = list(set([input() for i in range(n)])) n = len(s) name = ['' for i in range(n)] path = ['' for i in range(n)] mp = {} for i in range(n): link = s[i] j = link[7:].find('/') if j != -1: ...
115
592
44,134,400
158695269
n=int(input()) d={};p={};ans=[] for f in range(n): s=input()+'/'; t=s.find('/',7); d.setdefault(s[:t],set()).add(s[t:]) for k in d: p.setdefault(frozenset(d[k]),[]).append(k) [ans.append(p[k]) for k in p if len(p[k])>1] print(len(ans)) print('\n'.join(map(' '.join,ans)))
CROC 2016 - Qualification
CF
2,016
5
256
Hostname Aliases
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: - <hostname> consists of lowercase English letters and dots, there are no two consecutive dots,...
First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups ...
null
null
[{"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "output": "1\nhttp://abacaba.de http://abacaba.ru"}, {"input": "14\nhttp://c\n...
2,100
["*special", "binary search", "data structures", "implementation", "sortings", "strings"]
115
[{"input": "10\r\nhttp://abacaba.ru/test\r\nhttp://abacaba.ru/\r\nhttp://abacaba.com\r\nhttp://abacaba.com/test\r\nhttp://abacaba.de/\r\nhttp://abacaba.ru/test\r\nhttp://abacaba.de/test\r\nhttp://abacaba.com/\r\nhttp://abacaba.com/t\r\nhttp://abacaba.com/test\r\n", "output": "1\r\nhttp://abacaba.de http://abacaba.ru \r...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Parse input to build hostname path sets hostname_paths = {} with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): line = f.readline().strip(...
true
22/D
22
D
Python 3
TESTS
8
93
0
29620183
n = int(input()) lines = sorted([sorted([int(i) for i in input().split()]) for _ in range(n)]) array = [] bool_array = [0]*n for i in range(n): array.append([lines[i][0], i]) array.append([lines[i][1], i]) array.sort() screws = [] last = -1 last_indx = -1 b_indx = 0 for i in array: if i[0] == last: ...
40
46
0
149816731
n = int(input()) intervals = [] for i in range(n): a, b = input().split() a = int(a) b = int(b) if a > b: a, b = b, a intervals.append((a, b)) intervals.sort(key=lambda x: x[1]) prev = intervals[0][1] results = [] results.append(prev) for i in range(1, n): if prev < intervals[i][0]: ...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
1
256
Segments
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails need...
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
null
null
[{"input": "2\n0 2\n2 5", "output": "1\n2"}, {"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7", "output": "3\n7 10 3"}]
1,900
["greedy", "sortings"]
40
[{"input": "2\r\n0 2\r\n2 5\r\n", "output": "1\r\n2 "}, {"input": "5\r\n0 3\r\n4 2\r\n4 8\r\n8 10\r\n7 7\r\n", "output": "3\r\n3 7 10 "}, {"input": "3\r\n40 -83\r\n52 -80\r\n-21 -4\r\n", "output": "1\r\n-4 "}, {"input": "4\r\n67 -88\r\n37 -62\r\n-26 91\r\n-99 -50\r\n", "output": "2\r\n-50 91 "}, {"input": "5\r\n45 58\r...
false
stdio
null
true
63/A
63
A
PyPy 3
TESTS
24
372
0
96591331
a = [] rat = [] wmn = [] man = [] cap = [] for j in range(int(input())): s = input() a.append(s) for j in range(len(a)): if(a[j].find("rat")!= -1): rat.append(a[j]) if(a[j].find("woman")!= -1 or a[j].find("child")!=-1): wmn.append(a[j]) if(a[j].find("man")!= -1 and a[j].find("woman")==-1): ...
26
92
0
10647512
# coding: utf-8 n = int(input()) d = {'rat':0, 'woman':1, 'child':1, 'man':2, 'captain':3} people = [] for i in range(n): tmp = input().split() people.append([d[tmp[1]], i, tmp[0]]) people.sort() for i in people: print(i[2])
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
63/A
63
A
PyPy 3
TESTS
24
310
0
74381714
n=int(input()) di={} for i in range(n): s=str(input()) if('captain' in s): e=s.index(" ") d=s[0:e] di[d]=4 if("man" in s and 'woman' not in s): e=s.index(" ") d=s[0:e] di[d]=3 if('woman' in s or 'child' in s): e=s.index(" ") d=s[0:e] ...
26
92
0
31908146
def my_cmp(e): if (e[1] == 'rat'): return 0 elif (e[1] == 'woman' or e[1] == 'child'): return 1 elif (e[1] == 'man'): return 2 return 3 n = int(input()) a = [None] * n for i in range(n): name, rank = input().split(' ') a[i] = (name, rank) a = sorted(a, key=my_cmp) for e ...
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
63/A
63
A
Python 3
TESTS
24
216
6,963,200
88276877
t=int(input()) a=[] a1=[] a3=[] a4=[] a5=[] for i in range(t): s=str(input()) if "rat" in s: a.append(s.split()) elif "woman" in s or "child" in s: a1.append(s.split()) elif "man" in s: a3.append(s.split()) elif "captain" in s: a4.append(s.split()) for i in range(len...
26
92
0
31908586
x = [] n = int(input()) for i in range(n): x.append(input().split()) for i in range (0,n): if x[i][1] == 'rat': print( x[i][0]) for i in range (0,n): if x[i][1] == 'woman': print (x[i][0]) if x[i][1] == 'child': print (x[i][0]) for i in range(0,n): if x[i][1] == 'man': ...
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
283/A
283
A
PyPy 3
TESTS
9
998
11,366,400
69433309
import sys def get_array(): return list(map(int, sys.stdin.readline().strip().split())) n=int(input()) l=[0] dp=[0] s=0 c=1 while n: #print(l) t=get_array() if t[0]==2: l.append(t[1]) dp.append(0) s+=t[1] c+=1 print(s/c) elif t[0]==3: s-=l[-1]+dp[-1] ...
46
499
13,312,000
184077842
import sys input = sys.stdin.readline n = int(input()) e = [0]*(n+1) d = [0] m = 1 c = 0 for _ in range(n): w = list(map(int, input().split())) if w[0] == 1: c += w[2]*min(w[1], m) e[min(w[1], m)-1] += w[2] elif w[0] == 2: d.append(w[1]) c += w[1] m += 1 else: ...
Codeforces Round 174 (Div. 1)
CF
2,013
1.5
256
Cows and Sequence
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: 1. Add the integer xi to the first ai elements of the sequence. 2. Append an integer ki to the end of the sequence. (A...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer ti (1 ≤ ti ≤ 3), denoting the type of the operation (see above). If ti = 1, it will be followed by two integers ai, xi (|xi| ≤ 103; 1 ≤ ai). If ti = 2, it...
Output n lines each containing the average of the numbers in the sequence after the corresponding operation. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.
null
In the second sample, the sequence becomes $$\{0\} \rightarrow \{0,1\} \rightarrow \{20,21\} \rightarrow \{20,21,2\} \rightarrow \{17,18,2\} \rightarrow \{17\}.$$
[{"input": "5\n2 1\n3\n2 3\n2 1\n3", "output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000"}, {"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3", "output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"}]
1,600
["constructive algorithms", "data structures", "implementation"]
46
[{"input": "5\r\n2 1\r\n3\r\n2 3\r\n2 1\r\n3\r\n", "output": "0.500000\r\n0.000000\r\n1.500000\r\n1.333333\r\n1.500000\r\n"}, {"input": "6\r\n2 1\r\n1 2 20\r\n2 2\r\n1 2 -3\r\n3\r\n3\r\n", "output": "0.500000\r\n20.500000\r\n14.333333\r\n12.333333\r\n17.500000\r\n17.000000\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "...
false
stdio
import sys import os class FenwickTree: def __init__(self, size): self.n = size self.tree = [0]*(self.n + 2) def update_point(self, idx, delta): while idx <= self.n: self.tree[idx] += delta idx += idx & -idx def query_prefix(self, idx): res ...
true
283/A
283
A
Python 3
TESTS
9
1,341
3,891,200
67189237
import sys input=sys.stdin.readline from decimal import * getcontext().prec = 8 n=int(input()) from collections import deque arr=[0]*(2*(10**5)+2) cnt=1 sm=0.0 rem=0 ind={} for i in range(n): qry=[int(i) for i in input().split()] if qry[0]==2: arr[cnt]=qry[1] sm+=qry[1] cnt+=1 ...
46
514
13,516,800
213530382
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) N = int(input()) add = [0]*(...
Codeforces Round 174 (Div. 1)
CF
2,013
1.5
256
Cows and Sequence
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: 1. Add the integer xi to the first ai elements of the sequence. 2. Append an integer ki to the end of the sequence. (A...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer ti (1 ≤ ti ≤ 3), denoting the type of the operation (see above). If ti = 1, it will be followed by two integers ai, xi (|xi| ≤ 103; 1 ≤ ai). If ti = 2, it...
Output n lines each containing the average of the numbers in the sequence after the corresponding operation. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.
null
In the second sample, the sequence becomes $$\{0\} \rightarrow \{0,1\} \rightarrow \{20,21\} \rightarrow \{20,21,2\} \rightarrow \{17,18,2\} \rightarrow \{17\}.$$
[{"input": "5\n2 1\n3\n2 3\n2 1\n3", "output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000"}, {"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3", "output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"}]
1,600
["constructive algorithms", "data structures", "implementation"]
46
[{"input": "5\r\n2 1\r\n3\r\n2 3\r\n2 1\r\n3\r\n", "output": "0.500000\r\n0.000000\r\n1.500000\r\n1.333333\r\n1.500000\r\n"}, {"input": "6\r\n2 1\r\n1 2 20\r\n2 2\r\n1 2 -3\r\n3\r\n3\r\n", "output": "0.500000\r\n20.500000\r\n14.333333\r\n12.333333\r\n17.500000\r\n17.000000\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "...
false
stdio
import sys import os class FenwickTree: def __init__(self, size): self.n = size self.tree = [0]*(self.n + 2) def update_point(self, idx, delta): while idx <= self.n: self.tree[idx] += delta idx += idx & -idx def query_prefix(self, idx): res ...
true
283/A
283
A
PyPy 3-64
TESTS
9
1,325
17,920,000
172987443
n = int(input()) res = 0 seq = [0] ans = [] count = 1 new = [0] * n for i in range(n): a = [int(i) for i in input().split()] if a[0] == 2: count += 1 seq.append(a[1]) res += a[1] ans.append(res / count) elif a[0] == 3: if count > 1: count -= 1 if new[len(seq)-1] > 0: res -= (new[len(seq)-1] + s...
46
872
19,968,000
110949403
import sys,os,io import math,bisect,operator inf,mod = float('inf'),10**9+7 # sys.setrecursionlimit(10 ** 6) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ Neo = la...
Codeforces Round 174 (Div. 1)
CF
2,013
1.5
256
Cows and Sequence
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: 1. Add the integer xi to the first ai elements of the sequence. 2. Append an integer ki to the end of the sequence. (A...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer ti (1 ≤ ti ≤ 3), denoting the type of the operation (see above). If ti = 1, it will be followed by two integers ai, xi (|xi| ≤ 103; 1 ≤ ai). If ti = 2, it...
Output n lines each containing the average of the numbers in the sequence after the corresponding operation. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.
null
In the second sample, the sequence becomes $$\{0\} \rightarrow \{0,1\} \rightarrow \{20,21\} \rightarrow \{20,21,2\} \rightarrow \{17,18,2\} \rightarrow \{17\}.$$
[{"input": "5\n2 1\n3\n2 3\n2 1\n3", "output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000"}, {"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3", "output": "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"}]
1,600
["constructive algorithms", "data structures", "implementation"]
46
[{"input": "5\r\n2 1\r\n3\r\n2 3\r\n2 1\r\n3\r\n", "output": "0.500000\r\n0.000000\r\n1.500000\r\n1.333333\r\n1.500000\r\n"}, {"input": "6\r\n2 1\r\n1 2 20\r\n2 2\r\n1 2 -3\r\n3\r\n3\r\n", "output": "0.500000\r\n20.500000\r\n14.333333\r\n12.333333\r\n17.500000\r\n17.000000\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "...
false
stdio
import sys import os class FenwickTree: def __init__(self, size): self.n = size self.tree = [0]*(self.n + 2) def update_point(self, idx, delta): while idx <= self.n: self.tree[idx] += delta idx += idx & -idx def query_prefix(self, idx): res ...
true
63/A
63
A
Python 3
TESTS
24
216
6,963,200
88279582
t=int(input()) a=[] a1=[] a3=[] a4=[] for i in range(t): s=str(input()) if "rat" in s : s=s.split() for j in s: if j!="rat": a.append(j) elif "woman" in s or "child" in s: s=s.split() for j in s: if j!="woman" and j!="child": ...
26
92
0
136252483
n=int(input()) lst=[] for i in range(n): s=[x for x in input().split()] lst.append(s) for i in lst: if i[1]=='rat': print(i[0]) for i in lst: if i[1]=='woman' or i[1]=='child': print(i[0]) for i in lst: if i[1]=='man': print(i[0]) for i in lst: if i[1]=='captain': print(i[0]) break
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
75/C
75
C
PyPy 3
TESTS
15
654
5,120,000
97373174
import math n, m = map(int, input().split()) g = math.gcd(n, m) t = int(input()) l = [] i = 1 while (i * i <= g): if (g % i) == 0: l.append(i) if i * i != g: l.append(g // i) i += 1 for _ in range(t): a, b = map(int,input().split()) if a ==1 and b==1: print(1) ...
60
310
0
147832410
def solve(): left=0 right=len(arr)-1 ant=-1 while left<=right: mid=left+right>>1 if arr[mid]<l: left=mid+1 elif arr[mid]>r: right=mid-1 else: ant=mid left=mid+1 return ant from math import * a,b=map(int,input().split()) n=int(input()) k=gcd(a,b...
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
543/B
543
B
Python 3
TESTS
4
77
819,200
11969200
import queue def bfs(s,t,l,a,n,q,from_): d = [-1] * (n+1) d[s] = 0 q.put(s) while (q.empty() != True): u = q.get() for i in range(len(a[u])): if (d[a[u][i]] == -1): d[a[u][i]] = d[u] + 1 q.put(a[u][i]) from_[a[u][i]] = u ret...
63
1,731
91,955,200
174886422
from collections import deque n,m=map(int,input().split()) graph=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) d=[[-1]*n for _ in range(n)] for i in range(n): q=deque() q.append(i) d[i][i]=0 while q: n...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Destroying Roads
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ...
The first line contains two integers n, m (1 ≤ n ≤ 3000, $$n-1\leq m\leq \min\{3000,\frac{n(n-1)}{2}\}$$) — the number of cities and roads in the country, respectively. Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are giv...
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
null
null
[{"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "output": "0"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "output": "1"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "output": "-1"}]
2,100
["constructive algorithms", "graphs", "shortest paths"]
63
[{"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 2\r\n", "output": "0\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n2 4 2\r\n", "output": "1\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 1\r\n", "output": "-1\r\n"}, {"input": "9 9\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n5 7\r\n5 6\...
false
stdio
null
true
813/D
813
D
Python 3
TESTS
9
623
1,843,200
27732848
import sys from collections import defaultdict def solver(notes): n = len(notes) dp = [[0 for j in range(n)] for i in range(n)] ret = 0 for i in range(0, n): dpcol_modmax = [0] * 7 dpcol_notemax = defaultdict(int) for j in range(1, i+1): dpcol_modmax[notes[j] % 7] =...
35
1,434
104,243,200
112897541
import sys def solve(): n = int(sys.stdin.readline()) a = [0] + [int(i) for i in sys.stdin.readline().split()] dp = [[0]*(n + 1) for i in range(n + 1)] ans = 0 maxnum = [0] * (10**5 + 2) maxmod = [0] * 7 for y in range(n + 1): maxmod = [0] * 7 for ai in a: ...
Educational Codeforces Round 22
ICPC
2,017
2
256
Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal. S...
The first line contains one integer number n (2 ≤ n ≤ 5000). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — notes written on a sheet.
Print maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
null
In the first example subsequences [1, 2] and [4, 5] give length 4 in total. In the second example subsequences [62, 48, 49] and [60, 61] give length 5 in total. If you choose subsequence [62, 61] in the first place then the second melody will have maximum length 2, that gives the result of 4, which is not maximal.
[{"input": "4\n1 2 4 5", "output": "4"}, {"input": "6\n62 22 60 61 48 49", "output": "5"}]
2,600
["dp", "flows"]
35
[{"input": "4\r\n1 2 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n62 22 60 61 48 49\r\n", "output": "5\r\n"}, {"input": "2\r\n1 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 4\r\n", "output": "2\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "9\r\n"}, {"input": "10\r\n7776 32915 1030 71664 7542 72359 6538...
false
stdio
null
true
984/A
984
A
Python 3
TESTS
21
124
307,200
69281293
x=int(input()) y=list(map(int,input().split())) if x==2: print(min(y)) elif x==3: y.remove(max(y)) y.remove(min(y)) print(y[0]) if x%2==0 and x!=2: while x>3: y.remove(max(y)) y.remove(min(y)) x=x-2 y.remove(max(y)) print(y[0]) else: if x%2!=0 and x!=3: if x=...
35
31
0
220821038
def main(): n = int(input()) a = list(map(int, input().split())) a = sorted(a) for i in range(n-1): if (i+1) % 2 == 0: a.pop(0) continue a.pop(len(a)-1) print(a[0]) if __name__ == '__main__': main()
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
CF
2,018
2
256
Game
Two players play a game. Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, t...
The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$).
Print one number that will be left on the board.
null
In the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board. In the second sample, $$$2$$$ is left on the board regardless of the actions of the players.
[{"input": "3\n2 1 3", "output": "2"}, {"input": "3\n2 2 2", "output": "2"}]
800
["sortings"]
35
[{"input": "3\r\n2 1 3\r\n", "output": "2"}, {"input": "3\r\n2 2 2\r\n", "output": "2"}, {"input": "9\r\n44 53 51 80 5 27 74 79 94\r\n", "output": "53"}, {"input": "10\r\n38 82 23 37 96 4 81 60 67 86\r\n", "output": "60"}, {"input": "10\r\n58 26 77 15 53 81 68 48 22 65\r\n", "output": "53"}, {"input": "1\r\n124\r\n", "...
false
stdio
null
true
505/C
505
C
Python 3
TESTS
3
296
3,584,000
9471355
def main(): n, step = map(int, input().split()) archipelago = [0] * 30001 for _ in range(n): archipelago[int(input())] += 1 le = len(archipelago) way = [0] * le next = {(0, step)} bigstep = True while next: if bigstep: cur, next = next, set() for x...
54
920
67,072,000
187382925
from collections import defaultdict, Counter # import threading # import sys def ri(): return int(input()) def rs(): return input() def rl(): return list(map(int, input().split())) def rls(): return list(input().split()) # threading.stack_size(10**8) # sys.setrecursionlimit(10**6) def main(): # think first code...
Codeforces Round 286 (Div. 2)
CF
2,015
1
256
Mr. Kitayuta, the Treasure Hunter
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi....
The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively. The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤...
Print the maximum number of gems that Mr. Kitayuta can collect.
null
In the first sample, the optimal route is 0 → 10 (+1 gem) → 19 → 27 (+2 gems) → ... In the second sample, the optimal route is 0 → 8 → 15 → 21 → 28 (+1 gem) → 36 (+1 gem) → 45 (+1 gem) → 55 (+1 gem) → 66 (+1 gem) → 78 (+1 gem) → ... In the third sample, the optimal route is 0 → 7 → 13 →...
[{"input": "4 10\n10\n21\n27\n27", "output": "3"}, {"input": "8 8\n9\n19\n28\n36\n45\n55\n66\n78", "output": "6"}, {"input": "13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30", "output": "4"}]
1,900
["dfs and similar", "dp", "two pointers"]
54
[{"input": "4 10\r\n10\r\n21\r\n27\r\n27\r\n", "output": "3\r\n"}, {"input": "8 8\r\n9\r\n19\r\n28\r\n36\r\n45\r\n55\r\n66\r\n78\r\n", "output": "6\r\n"}, {"input": "13 7\r\n8\r\n8\r\n9\r\n16\r\n17\r\n17\r\n18\r\n21\r\n23\r\n24\r\n24\r\n26\r\n30\r\n", "output": "4\r\n"}, {"input": "8 4\r\n9\r\n15\r\n15\r\n16\r\n22\r\n2...
false
stdio
null
true
63/A
63
A
Python 3
TESTS
24
124
0
7282611
n = int(input()) p = [] for i in range(n): p.append(input()) out = [] for i in range(n): if "rat" in p[i] and p[i][0:p[i].index(" ")] not in out: out.append(p[i][0:p[i].index(" ")]) for i in range(n): if ("woman" in p[i] or "child" in p[i]) and p[i][0:p[i].index(" ")] not in out : out.appen...
26
92
0
137902872
n=int(input()) d={'man':[], 'woman':[], "captain":[], "rat":[]} for i in range(n): a,b=input().split() if(b=="child"): b="woman" d[b].append(a) l=["rat", "woman","man", "captain"] for i in l: for j in d[i]: print(j)
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
63/A
63
A
Python 3
TESTS
24
124
0
117491984
b=[] m=[] f=["rat","child","man","captain"] for _ in range(int(input())): n=input() b.append(n) for i in range(len(f)): for j in b: if f[i]=='child': if f[i] in j or 'woman' in j: if j not in m: m.append(j) elif f[i] in j: if j not ...
26
92
0
138404866
t,m,n,p=[],[],[],[] for i in range(int(input())): a=input().split() if't'==a[1][2]: t.append(a[0]) elif a[1][2]in'mi': m.append(a[0]) elif'n'==a[1][2]: n.append(a[0]) else: p.append(a[0]) for i in'tmnp': exec('for a in '+i+':\n\tprint(a)')
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Sinking Ship
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o...
The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin...
Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.
null
null
[{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}]
900
["implementation", "sortings", "strings"]
26
[{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta...
false
stdio
null
true
1005/A
1005
A
Python 3
TESTS
6
46
6,758,400
129992353
n = int(input()) arr_a = input().replace(" ", "").split("1")[1:] answer = [int(i[-1]) if i != "" else 1 for i in arr_a] print(len(answer)) print(*answer) # Mon Sep 27 2021 14:11:36 GMT+0300 (Москва, стандартное время)
16
31
0
162454527
input() a=input().split() l=[x for x,y in zip(a,a[1:]+['1'])if'1'==y] print(len(l)) print(*l)
Codeforces Round 496 (Div. 3)
ICPC
2,018
1
256
Tanya and Stairways
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $$$1$$$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $$$3$$$ steps, and the second conta...
The first line contains $$$n$$$ ($$$1 \le n \le 1000$$$) — the total number of numbers pronounced by Tanya. The second line contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passin...
In the first line, output $$$t$$$ — the number of stairways that Tanya climbed. In the second line, output $$$t$$$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
null
null
[{"input": "7\n1 2 3 1 2 3 4", "output": "2\n3 4"}, {"input": "4\n1 1 1 1", "output": "4\n1 1 1 1"}, {"input": "5\n1 2 3 4 5", "output": "1\n5"}, {"input": "5\n1 2 1 2 1", "output": "3\n2 2 1"}]
800
["implementation"]
16
[{"input": "7\r\n1 2 3 1 2 3 4\r\n", "output": "2\r\n3 4 "}, {"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n1 1 1 1 "}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "1\r\n5 "}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "3\r\n2 2 1 "}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "48\r\n1 2 3 4 1 2 3 1 1 2 3 1 2 ...
false
stdio
null
true
1005/A
1005
A
PyPy 3-64
TESTS
6
62
2,969,600
226894411
input() str = input() c=0 for i in range(2, len(str), 2): if str[i]<=str[i-2] : c+=1 print(c+1) for i in range(2, len(str), 2): if str[i]<=str[i-2] : print(str[i-2], end=' ') print(str[len(str)-1])
16
31
0
163366837
n = int(input()) l = input().split() lst = [] for i in range(len(l)): if l[i] == '1': lst.append(i) lst.append(n) print(len(lst)-1) for i in range(len(lst)-1): print(abs(lst[i] - lst[i+1]), end=' ')
Codeforces Round 496 (Div. 3)
ICPC
2,018
1
256
Tanya and Stairways
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $$$1$$$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $$$3$$$ steps, and the second conta...
The first line contains $$$n$$$ ($$$1 \le n \le 1000$$$) — the total number of numbers pronounced by Tanya. The second line contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passin...
In the first line, output $$$t$$$ — the number of stairways that Tanya climbed. In the second line, output $$$t$$$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
null
null
[{"input": "7\n1 2 3 1 2 3 4", "output": "2\n3 4"}, {"input": "4\n1 1 1 1", "output": "4\n1 1 1 1"}, {"input": "5\n1 2 3 4 5", "output": "1\n5"}, {"input": "5\n1 2 1 2 1", "output": "3\n2 2 1"}]
800
["implementation"]
16
[{"input": "7\r\n1 2 3 1 2 3 4\r\n", "output": "2\r\n3 4 "}, {"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n1 1 1 1 "}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "1\r\n5 "}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "3\r\n2 2 1 "}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "48\r\n1 2 3 4 1 2 3 1 1 2 3 1 2 ...
false
stdio
null
true
25/D
25
D
Python 3
TESTS
11
218
6,963,200
79997366
def sort(component,cycle): for i in range(len(component)): for j in range(len(component)-1): if(len(cycle[component[j]])>len(cycle[component[j+1]])): component[j],component[j+1]=component[j+1],component[j] return component def find_set(v,parent): if(parent[v]<0): ...
55
92
0
172390519
class DSU: def __init__(self, n: int): self.n = n self.parent = [i for i in range(n + 1)] self.size = [1 for _ in range(n + 1)] def find(self, u: int) -> int: if u == self.parent[u]: return u self.parent[u] = self.find(self.parent[u]) return self.pare...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
null
null
[{"input": "2\n1 2", "output": "0"}, {"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7"}]
1,900
["dsu", "graphs", "trees"]
55
[{"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 7\r\n", "output": "1\r\n3 1 3 7\r\n"}, {"input": "3\r\n3 2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n3 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 4\r\n3 1\r\n3 4\r\n", "output": "1\r\n3 4 2 4\r\n"}, {"in...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) edges = set() for _ in range(n-1): a, b = map(int, f.readline().split()) if a > b: a, b = b, a edges.add((a, b)) return n, edges def check_in...
true
558/A
558
A
Python 3
TESTS
8
46
0
186571508
n1=int(input()) d={};n=[];p=[];c=0 for i in range(n1): a,b=[int(x) for x in input().split()] d[a]=b if a<0: n.append(a) else: p.append(a) n.sort();p.sort() if len(n)>=len(p): for i in range(len(p)): c+=d[n[i]]+d[p[i]] try: c+=d[n[len(p)]] except:None else: ...
46
46
0
217044933
n = int(input()) l = [] l2 = [] l3 = [] for i in range(0,n) : l.append(list(map(int,input().split(" ")))) for k in l : if k[0] > 0 : l2.append(k) else : l3.append(k) l2.sort() s = 0 lcv = min(len(l2),len(l3)) l3.sort(reverse=True) if len(l2) == len(l3) : for i in range(0,len...
Codeforces Round 312 (Div. 2)
CF
2,015
1
256
Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple tre...
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land. The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at ...
Output the maximum number of apples Amr can collect.
null
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then...
[{"input": "2\n-1 5\n1 5", "output": "10"}, {"input": "3\n-2 2\n1 4\n-1 3", "output": "9"}, {"input": "3\n1 9\n3 5\n7 10", "output": "9"}]
1,100
["brute force", "implementation", "sortings"]
46
[{"input": "2\r\n-1 5\r\n1 5\r\n", "output": "10"}, {"input": "3\r\n-2 2\r\n1 4\r\n-1 3\r\n", "output": "9"}, {"input": "3\r\n1 9\r\n3 5\r\n7 10\r\n", "output": "9"}, {"input": "1\r\n1 1\r\n", "output": "1"}, {"input": "4\r\n10000 100000\r\n-1000 100000\r\n-2 100000\r\n-1 100000\r\n", "output": "300000"}, {"input": "1\...
false
stdio
null
true
961/G
961
G
PyPy 3-64
TESTS
2
62
4,608,000
209858484
M=10**9+7 R=2*10**5 Fact=[1]*(R+1) for i in range(2, R+1): Fact[i]=(Fact[i-1]*i)%M def modpow(x, p): if p==0: return 1 if p<0: return modpow(x, (2-M)*p) y=modpow(x, p//2) if p%2: return (y*y*x)%M return (y*y)%M def modhyp(x): return modpow(x, -1) Facthyp=[1]*(R+1) Fac...
42
717
39,936,000
71167205
def read_data(): n, m = map(int, list(input().strip().split())) a = list(map(int, list(input().strip().split()))) return n, m, a def get_modinv(m): modinv = [-1 for _ in range(m+1)] modinv[1] = 1 for i in range(2,m+1): modinv[i] = (-(div//i) * modinv[div%i]) % div return modinv d...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Partitions
You are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as $$W(S) = |S| \cdot \sum_{i \in S} w_i$$. The weight of some partition R of a given set into k subsets is $$W(R) = \sum_{S \in R} W(S)$$ (recall that a partition of a given set ...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2·105) — the number of elements and the number of subsets in each partition, respectively. The second line contains n integers wi (1 ≤ wi ≤ 109)— weights of elements of the set.
Print one integer — the sum of weights of all partitions of a given set into k non-empty subsets, taken modulo 109 + 7.
null
Possible partitions in the first sample: 1. {{1, 2, 3}, {4}}, W(R) = 3·(w1 + w2 + w3) + 1·w4 = 24; 2. {{1, 2, 4}, {3}}, W(R) = 26; 3. {{1, 3, 4}, {2}}, W(R) = 24; 4. {{1, 2}, {3, 4}}, W(R) = 2·(w1 + w2) + 2·(w3 + w4) = 20; 5. {{1, 3}, {2, 4}}, W(R) = 20; 6. {{1, 4}, {2, 3}}, W(R) = 20; 7. {{1}, {2, 3, 4}}, W(R) = 26; ...
[{"input": "4 2\n2 3 2 3", "output": "160"}, {"input": "5 2\n1 2 3 4 5", "output": "645"}]
2,700
["combinatorics", "math", "number theory"]
42
[{"input": "4 2\r\n2 3 2 3\r\n", "output": "160\r\n"}, {"input": "5 2\r\n1 2 3 4 5\r\n", "output": "645\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "2 1\r\n6042 8885\r\n", "output": "29854\r\n"}, {"input": "2 2\r\n8224 8138\r\n", "output...
false
stdio
null
true
847/K
847
K
Python 3
TESTS
6
31
0
215865987
n,a,b,k,f=map(int,input().split()) arr=[] for i in range(n): arr.append(input().split()) count=0 co=0 c=[] for i in range(len(arr)): for j in range(len(arr)): if arr[i][1]==arr[j][0] and arr[i][0]==arr[j][1]: if i not in c and j not in c: if co<k: co+=1 ...
55
62
307,200
30863008
n, a, b, k, f = map(int, input().split()) slov = dict() temp = input().split() slov[frozenset(temp)] = a for i in range(1, n): temp2 = input().split() try: if temp2[0] == temp[1]: slov[frozenset(temp2)] += b else: slov[frozenset(temp2)] += a except KeyError: ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
4
256
Travel Cards
In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop t...
The first line contains five integers n, a, b, k, f (1 ≤ n ≤ 300, 1 ≤ b < a ≤ 100, 0 ≤ k ≤ 300, 1 ≤ f ≤ 1000) where: - n — the number of Polycarp trips, - a — the cost of a regualar single trip, - b — the cost of a trip after a transshipment, - k — the maximum number of travel cards Polycarp can buy, - f — the cost of...
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
null
In the first example Polycarp can buy travel card for the route "BerBank $$\leftarrow$$ University" and spend 8 burles. Note that his second trip "University" $$\rightarrow$$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles. In the s...
[{"input": "3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank", "output": "11"}, {"input": "4 2 1 300 1000\na A\nA aa\naa AA\nAA a", "output": "5"}]
1,800
["greedy", "implementation", "sortings"]
55
[{"input": "3 5 3 1 8\r\nBerBank University\r\nUniversity BerMall\r\nUniversity BerBank\r\n", "output": "11\r\n"}, {"input": "4 2 1 300 1000\r\na A\r\nA aa\r\naa AA\r\nAA a\r\n", "output": "5\r\n"}, {"input": "2 2 1 0 1\r\naca BCBA\r\nBCBA aca\r\n", "output": "3\r\n"}, {"input": "2 2 1 2 1\r\nBDDB C\r\nC BDDB\r\n", "ou...
false
stdio
null
true
631/A
631
A
Python 3
TESTS
6
280
307,200
16487096
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) maxi1 = 0 maxi2 = 0 for beg in range(n): tmp1 = a[beg] tmp2 = b[beg] for end in range(beg+1,n): tmp1 = tmp1 | a[end] tmp2 = tmp1 | b[end] if tmp1 > maxi1: maxi1=tmp1 if tmp2 > maxi2: m...
27
31
0
154826297
import sys input = sys.stdin.readline input() a = map(int, input().split()) b = map(int, input().split()) c,d =0,0 for i in a: c |= i for i in b: d |= i print(c+d)
Codeforces Round 344 (Div. 2)
CF
2,016
1
256
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
null
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, ...
[{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}]
900
["brute force", "implementation"]
27
[{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 1...
false
stdio
null
true
1005/A
1005
A
Python 3
TESTS
6
46
6,758,400
130461705
n = int(input()) a = input().split() b = [] print(a.count('1')) if n == 1: print(1) else: for i in range(n - 1): if a[i + 1] <= a[i]: print(a[i], end = " ") if i == (n - 2): print(a[i + 1]) # Fri Oct 01 2021 15:34:13 GMT+0300 (Москва, стандартное время)
16
31
0
166334899
n=int(input()) l=list(map(int,input().split())) m=[] for i in range(len(l)): if i==n-1: m.append(l[i]) elif l[i+1]==1: m.append(l[i]) print(l.count(1)) for i in m: print(i,end=" ")
Codeforces Round 496 (Div. 3)
ICPC
2,018
1
256
Tanya and Stairways
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $$$1$$$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $$$3$$$ steps, and the second conta...
The first line contains $$$n$$$ ($$$1 \le n \le 1000$$$) — the total number of numbers pronounced by Tanya. The second line contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passin...
In the first line, output $$$t$$$ — the number of stairways that Tanya climbed. In the second line, output $$$t$$$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
null
null
[{"input": "7\n1 2 3 1 2 3 4", "output": "2\n3 4"}, {"input": "4\n1 1 1 1", "output": "4\n1 1 1 1"}, {"input": "5\n1 2 3 4 5", "output": "1\n5"}, {"input": "5\n1 2 1 2 1", "output": "3\n2 2 1"}]
800
["implementation"]
16
[{"input": "7\r\n1 2 3 1 2 3 4\r\n", "output": "2\r\n3 4 "}, {"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n1 1 1 1 "}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "1\r\n5 "}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "3\r\n2 2 1 "}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "48\r\n1 2 3 4 1 2 3 1 1 2 3 1 2 ...
false
stdio
null
true
558/A
558
A
Python 3
TESTS
8
46
0
197297606
def solve(p_a, n_a, pos, neg): global ans for i, e in enumerate(p_a): ans += pos[e] if i >= len(n_a): break else: ans += neg[n_a[i]] n = int(input()) ans = 0 neg = {} pos = {} for i in range(n): a, w = map(int, input().split()) if a > 0: pos[a] =...
43
61
0
12045170
n = int(input()) left = [] right = [] for i in range(n): x, a = [int(i) for i in input().split()] if x < 0: left.append([x, a]) else: right.append([x, a]) left.sort() right.sort() ans = 0 length = min(len(left), len(right)) for i in left[::-1]: if length <= 0: break ans += i[...
Codeforces Round 312 (Div. 2)
CF
2,015
1
256
Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple tre...
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land. The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at ...
Output the maximum number of apples Amr can collect.
null
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then...
[{"input": "2\n-1 5\n1 5", "output": "10"}, {"input": "3\n-2 2\n1 4\n-1 3", "output": "9"}, {"input": "3\n1 9\n3 5\n7 10", "output": "9"}]
1,100
["brute force", "implementation", "sortings"]
46
[{"input": "2\r\n-1 5\r\n1 5\r\n", "output": "10"}, {"input": "3\r\n-2 2\r\n1 4\r\n-1 3\r\n", "output": "9"}, {"input": "3\r\n1 9\r\n3 5\r\n7 10\r\n", "output": "9"}, {"input": "1\r\n1 1\r\n", "output": "1"}, {"input": "4\r\n10000 100000\r\n-1000 100000\r\n-2 100000\r\n-1 100000\r\n", "output": "300000"}, {"input": "1\...
false
stdio
null
true
962/F
962
F
Python 3
TESTS
4
46
6,963,200
129751525
import sys def solve(): n, m = map(int, input().split()) g = [[] for i in range(n+1)] for i in range(m): u, v = map(int, input().split()) g[u].append([v,i]) g[v].append([u,i]) P = [-1]*(n+1) I = [0]*(n+1) st = [] D = [0]*(n+1) up = [0]*(n+1) W = [0]*(n+1) F = [False]*(n+1) for i in range(1, n+1): if...
42
857
40,243,200
129765854
import sys def solve(): n, m = map(int, input().split()) g = [[] for i in range(n+1)] E = [None]*m for i in range(m): u, v = map(int, input().split()) E[i] = (u, v) g[u].append([v,i]) g[v].append([u,i]) P = [-1]*(n+1) I = [0]*(n+1) st = [] D = [0]*(n+1) W = [0]*(n+1) S = [-1]*m U = [-1]*m V = [-1]*...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Simple Cycles Edges
You are given an undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself). A cycle in a graph is called a simple, if ...
The first line contain two integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 100\,000$$$, $$$0 \le m \le \min(n \cdot (n - 1) / 2, 100\,000))$$$ — the number of vertices and the number of edges. Each of the following $$$m$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the descr...
In the first line print the number of edges, which belong to exactly one simple cycle. In the second line print the indices of edges, which belong to exactly one simple cycle, in increasing order. The edges are numbered from one in the same order as they are given in the input.
null
null
[{"input": "3 3\n1 2\n2 3\n3 1", "output": "3\n1 2 3"}, {"input": "6 7\n2 3\n3 4\n4 2\n1 2\n1 5\n5 6\n6 1", "output": "6\n1 2 3 5 6 7"}, {"input": "5 6\n1 2\n2 3\n2 4\n4 3\n2 5\n5 3", "output": "0"}]
2,400
["dfs and similar", "graphs", "trees"]
42
[{"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "6 7\r\n2 3\r\n3 4\r\n4 2\r\n1 2\r\n1 5\r\n5 6\r\n6 1\r\n", "output": "6\r\n1 2 3 5 6 7 \r\n"}, {"input": "5 6\r\n1 2\r\n2 3\r\n2 4\r\n4 3\r\n2 5\r\n5 3\r\n", "output": "0\r\n\r\n"}, {"input": "4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 1\r\n1 3\r\n"...
false
stdio
null
true
555/A
555
A
Python 3
TESTS
10
62
0
11899457
##row, col, order = input().split(' ') ##row = int(row) ##col = int(col) ## ##init_list = [] ## ##for i in range(row): ## init_list.append(input().split(' ')) ## ##if order=='0': ## for i in range(row): ## print() ## for j in range(col,0,-1): ## print(init_list[i][j-1], end = ' ') ##e...
47
249
7,372,800
73427300
n,k=map(int,input().split()) l=0 g=k for i in range(k): s,*x=map(int,input().split()) if x[0]==1: for i in range(s): if x[i]!=i+1: i-=1 break i+=1 break ans=(n-1)+(n-k)-2*(i-1) print(ans)
Codeforces Round 310 (Div. 1)
CF
2,015
2
256
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbers ai1, ai2, ..., aimi — the numbers of mat...
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
null
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
[{"input": "3 2\n2 1 2\n1 3", "output": "1"}, {"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10"}]
1,500
["implementation"]
47
[{"input": "3 2\r\n2 1 2\r\n1 3\r\n", "output": "1\r\n"}, {"input": "7 3\r\n3 1 3 7\r\n2 2 5\r\n2 4 6\r\n", "output": "10\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 1 3\r\n", "output": "3\r\n"}, {"input": "5 3\r\n1 4\r\n3 1 2 3\r\n1 5\r\n", "output": "2\r\n"}, {"input": "8 5\r\n2 ...
false
stdio
null
true
686/B
686
B
PyPy 3
TESTS
5
93
1,843,200
197256649
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = [0] + list(map(int, input().split())) ans = [] for i in range(1, n + 1): for j in range(i, n): if a[j] > a[j + 1]: ans.append(" ".join(map(str, (j, j + 1)))) a[j], a[j + 1] = a[j + 1...
37
46
512,000
210936935
def rearrange_animals(n, animals): operations = [] for i in range(1, n): for j in range(0, n-i): if animals[j] > animals[j+1]: operations.append((j+1, j+2)) animals[j], animals[j+1] = animals[j+1], animals[j] if len(operat...
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the o...
null
Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
[{"input": "4\n2 1 4 3", "output": "1 4"}, {"input": "7\n36 28 57 39 66 69 68", "output": "1 4\n6 7"}, {"input": "5\n1 2 1 2 1", "output": "2 5\n3 4\n1 4\n1 4"}]
1,100
["constructive algorithms", "implementation", "sortings"]
37
[{"input": "4\r\n2 1 4 3\r\n", "output": "1 2\r\n3 4\r\n"}, {"input": "7\r\n36 28 57 39 66 69 68\r\n", "output": "1 2\r\n3 4\r\n6 7\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "2 3\r\n4 5\r\n3 4\r\n"}, {"input": "78\r\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 4...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path, 'r') as f: lines = f...
true
75/C
75
C
PyPy 3
TESTS
14
778
8,089,600
78379283
from bisect import bisect_left as bl import math def factors(n): l=[] for i in range(1,int(n**0.5)+1): if n%i==0: l.append(i) if i!=n//i: l.append(n//i) return(sorted(l)) a,b=map(int,input().split()) g=math.gcd(a,b) l=factors(g) #print(g) for i in range(int(i...
60
310
10,137,600
212367874
import sys input = sys.stdin.readline from math import gcd from bisect import bisect a, b = map(int, input().split()) x = gcd(a, b) y = x d = dict() s = set() for i in range(2, int(x**0.5)+1): if y % i == 0: c = 0 while y % i == 0: y //= i c += 1 d[i] = c if y != 1: ...
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
169/A
169
A
Python 3
TESTS
10
62
0
117794277
n,a,b=map(int,input().split()) l=list(map(int,input().split())) k=list(sorted(set(l),reverse=True)) if len(k)>min(a,b): print(k[min(a,b)-1]-k[min(a,b)]) else: print(0)
29
46
0
138619062
[n, a, b] = list(map(int,input().split(" "))) h = list(map(int,input().split(" "))) h.sort() print(h[b]-h[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
558/A
558
A
Python 3
TESTS
8
46
0
187088839
n = int(input()) l, r = [], [] for i in range(n): x, a = [int(i) for i in input().split()] if x < 0: l.append([x, a]) else: r.append([x, a]) l.sort(key = lambda e: e[0]) r.sort(key = lambda e: e[0]) m, n = sorted([l, r], key=len) c = 0 while len(m) != 0: c += m[0][1] + n[0][1] m = m[1:] n = n[1:] if len(...
43
61
0
12045733
n=int(input()) a=[[0,0]] xpos=0 xneg=0 for i in range(n): x,y=input().split(' ') a.append([int(x),int(y)]) if int(x)<0: xneg+=1 else: xpos+=1 a.sort() m=a.index([0,0]) if xpos>xneg: l=0 h=m+xneg+2 elif xneg>xpos: l=m-xpos-1 h=n+1 else: l=0 h=n+1 s=0 for i in range...
Codeforces Round 312 (Div. 2)
CF
2,015
1
256
Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple tre...
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land. The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at ...
Output the maximum number of apples Amr can collect.
null
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then...
[{"input": "2\n-1 5\n1 5", "output": "10"}, {"input": "3\n-2 2\n1 4\n-1 3", "output": "9"}, {"input": "3\n1 9\n3 5\n7 10", "output": "9"}]
1,100
["brute force", "implementation", "sortings"]
46
[{"input": "2\r\n-1 5\r\n1 5\r\n", "output": "10"}, {"input": "3\r\n-2 2\r\n1 4\r\n-1 3\r\n", "output": "9"}, {"input": "3\r\n1 9\r\n3 5\r\n7 10\r\n", "output": "9"}, {"input": "1\r\n1 1\r\n", "output": "1"}, {"input": "4\r\n10000 100000\r\n-1000 100000\r\n-2 100000\r\n-1 100000\r\n", "output": "300000"}, {"input": "1\...
false
stdio
null
true
424/B
424
B
Python 3
TESTS
4
31
0
220429091
from math import sqrt i = input().split() n = int(i[0]) s = int(i[1]) a = [] for i in range(n): i = input().split() x = int(i[0]) y = int(i[1]) z = int(i[2]) a.append([sqrt(x ** 2 + y ** 2), z]) a.sort(key=lambda x: x[0]) r = 0 for i in a: if s >= 1000000: print(r) exit() el...
54
62
102,400
30853912
import math as Math from sys import stdin if __name__ == '__main__': n, s = map(int, stdin.readline().strip().split()) points = dict() for i in range(0, n): x, y, pop = map(int, stdin.readline().strip().split()) rad = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) if points.get(rad) == N...
Codeforces Round 242 (Div. 2)
CF
2,014
2
256
Megacity
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with ...
The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 10...
In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity. The answer is considered correct if the absolute or relative error don'...
null
null
[{"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271"}, {"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136"}, {"input": "2 1\n1 1 999997\n2 2 1", "output": "-1"}]
1,200
["binary search", "greedy", "implementation", "sortings"]
54
[{"input": "4 999998\r\n1 1 1\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "2.8284271\r\n"}, {"input": "4 999998\r\n1 1 2\r\n2 2 1\r\n3 3 1\r\n2 -2 1\r\n", "output": "1.4142136\r\n"}, {"input": "2 1\r\n1 1 999997\r\n2 2 1\r\n", "output": "-1"}, {"input": "4 999998\r\n3 3 10\r\n-3 3 10\r\n3 -3 10\r\n-3 -3 10\r\n", "outpu...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.read().strip() with open(submission_path, 'r') as f: sub_line = f.read().strip() if ref_line == '-1': if sub_line...
true
988/F
988
F
PyPy 3-64
TESTS
4
62
3,072,000
145179932
import sys import io, os input = sys.stdin.buffer.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline INF = 10**18 a, n, m = map(int, input().split()) LR = [] for i in range(n): l, r = map(int, input().split()) LR.append((l, r)) XP = [] for i in range(m): x, p = map(int, input().split())...
37
248
63,283,200
167201416
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import sys input = sys.stdin.readline def main(): target, n, m = map(int, input().split()) rain = [False] * (target + 1) for _ in range(n): s...
Codeforces Round 486 (Div. 3)
ICPC
2,018
2
256
Rain and Umbrellas
Polycarp lives on a coordinate line at the point $$$x = 0$$$. He goes to his friend that lives at the point $$$x = a$$$. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $$$n$$$ non-intersecti...
The first line contains three integers $$$a$$$, $$$n$$$ and $$$m$$$ ($$$1 \le a, m \le 2000, 1 \le n \le \lceil\frac{a}{2}\rceil$$$) — the point at which Polycarp's friend lives, the number of the segments in the rain and the number of umbrellas. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_...
Print "-1" (without quotes) if Polycarp can't make his way from point $$$x = 0$$$ to point $$$x = a$$$. Otherwise print one integer — the minimum total fatigue after reaching $$$x = a$$$, if Polycarp picks up and throws away umbrellas optimally.
null
In the first example the only possible strategy is to take the fourth umbrella at the point $$$x = 1$$$, keep it till the point $$$x = 7$$$ (the total fatigue at $$$x = 7$$$ will be equal to $$$12$$$), throw it away, move on from $$$x = 7$$$ to $$$x = 8$$$ without an umbrella, take the third umbrella at $$$x = 8$$$ and...
[{"input": "10 2 4\n3 7\n8 10\n0 10\n3 4\n8 1\n1 2", "output": "14"}, {"input": "10 1 1\n0 9\n0 5", "output": "45"}, {"input": "10 1 1\n0 9\n1 5", "output": "-1"}]
2,100
["dp"]
37
[{"input": "10 2 4\r\n3 7\r\n8 10\r\n0 10\r\n3 4\r\n8 1\r\n1 2\r\n", "output": "14\r\n"}, {"input": "10 1 1\r\n0 9\r\n0 5\r\n", "output": "45\r\n"}, {"input": "10 1 1\r\n0 9\r\n1 5\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n0 1\r\n1 100000\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n0 1\r\n0 100000\r\n", "output...
false
stdio
null
true
988/F
988
F
PyPy 3-64
TESTS
4
62
2,867,200
175501360
import sys read=lambda:map(int,sys.stdin.readline().split()) dst,n,m=read() rain=sorted([[*read()] for _ in range(n)]) umb=sorted([[*read()] for _ in range(m)])+[[dst,dst]] if umb[0][0]>rain[0][0]:quit(print(-1)) dp,ridx=[0xFFFF0204]*(m+1),0 dp[0]=0 for i in range(1,m+1): if umb[i][0]>rain[ridx][0]: cur=umb...
37
265
62,156,800
167202817
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import sys input = sys.stdin.readline def main(): target, n, m = map(int, input().split()) l = [0] * n r = [0] * n for i in range(n): l[i...
Codeforces Round 486 (Div. 3)
ICPC
2,018
2
256
Rain and Umbrellas
Polycarp lives on a coordinate line at the point $$$x = 0$$$. He goes to his friend that lives at the point $$$x = a$$$. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $$$n$$$ non-intersecti...
The first line contains three integers $$$a$$$, $$$n$$$ and $$$m$$$ ($$$1 \le a, m \le 2000, 1 \le n \le \lceil\frac{a}{2}\rceil$$$) — the point at which Polycarp's friend lives, the number of the segments in the rain and the number of umbrellas. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_...
Print "-1" (without quotes) if Polycarp can't make his way from point $$$x = 0$$$ to point $$$x = a$$$. Otherwise print one integer — the minimum total fatigue after reaching $$$x = a$$$, if Polycarp picks up and throws away umbrellas optimally.
null
In the first example the only possible strategy is to take the fourth umbrella at the point $$$x = 1$$$, keep it till the point $$$x = 7$$$ (the total fatigue at $$$x = 7$$$ will be equal to $$$12$$$), throw it away, move on from $$$x = 7$$$ to $$$x = 8$$$ without an umbrella, take the third umbrella at $$$x = 8$$$ and...
[{"input": "10 2 4\n3 7\n8 10\n0 10\n3 4\n8 1\n1 2", "output": "14"}, {"input": "10 1 1\n0 9\n0 5", "output": "45"}, {"input": "10 1 1\n0 9\n1 5", "output": "-1"}]
2,100
["dp"]
37
[{"input": "10 2 4\r\n3 7\r\n8 10\r\n0 10\r\n3 4\r\n8 1\r\n1 2\r\n", "output": "14\r\n"}, {"input": "10 1 1\r\n0 9\r\n0 5\r\n", "output": "45\r\n"}, {"input": "10 1 1\r\n0 9\r\n1 5\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n0 1\r\n1 100000\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n0 1\r\n0 100000\r\n", "output...
false
stdio
null
true
314/C
314
C
PyPy 3-64
TESTS
8
124
512,000
210302474
MOD = 10**9 + 7 def update(tree, n, id, val): while id <= n: tree[id] += val tree[id] %= MOD id += id & -id def query(tree, id): sum = 0 while id > 0: sum += tree[id] sum %= MOD id -= id & -id return sum def solve(): n = int(input()) arr = li...
24
1,402
41,267,200
169478092
import os import sys from io import BytesIO, IOBase # region fastio 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" not in file.mode self.write = self.bu...
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Subsequences
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not excee...
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106).
In the single line print the answer to the problem modulo 1000000007 (109 + 7).
null
null
[{"input": "1\n42", "output": "42"}, {"input": "3\n1 2 2", "output": "13"}, {"input": "5\n1 2 3 4 5", "output": "719"}]
2,000
["data structures", "dp"]
24
[{"input": "1\r\n42\r\n", "output": "42\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "13\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "719\r\n"}, {"input": "4\r\n11479 29359 26963 24465\r\n", "output": "927446239\r\n"}, {"input": "5\r\n5706 28146 23282 16828 9962\r\n", "output": "446395832\r\n"}, {"input": "6\r\n49...
false
stdio
null
true
774/D
774
D
PyPy 3-64
TESTS
5
62
0
178643999
n,l,r=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) if a[0]==b[0] and a[-1]==b[-1]: print('TRUTH') else: print('LIE')
52
78
15,155,200
26150784
n, l, r = map(int, input().split()) l -= 1 a = input().split() b = input().split() if a[:l] == b[:l] and a[r:] == b[r:]: print("TRUTH") else: print("LIE")
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ...
false
stdio
null
true
547/D
547
D
PyPy 3-64
TESTS
0
31
0
224154739
n = int(input()) points = [] for _ in range(n): x, y = map(int, input().split()) points.append((x, y)) # Sort the points by x-coordinates and then by y-coordinates points.sort() colors = [None] * n red_count = 0 blue_count = 0 for i in range(n): x, y = points[i] if i % 2 == 0: # If the curren...
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
845/F
845
F
PyPy 3-64
TESTS
4
92
5,836,800
155379978
import sys readline=sys.stdin.readline N,M=map(int,readline().split()) S=[list(readline().rstrip()) for i in range(N)] if N<M: S=[[S[n][m] for n in range(N)] for m in range(M)] N,M=M,N mod=10**9+7 dp0=[[0]*2 for bit in range(1<<M)] dp1=[[0]*2 for bit in range(1<<M)] for bit in range(1<<M): if not any(bit&1...
34
140
23,347,200
130042461
import sys,io,os try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline except:Z=lambda:sys.stdin.readline().encode() Y=lambda:map(int,Z().split()) M=10**9+7 try: import __pypy__ int_add=__pypy__.intop.int_add int_sub=__pypy__.intop.int_sub int_mul=__pypy__.intop.int_mul def make_mod_mul(mod=M): ...
Educational Codeforces Round 27
ICPC
2,017
1.5
512
Guards In The Storehouse
Polycarp owns a shop in the capital of Berland. Recently the criminal activity in the capital increased, so Polycarp is thinking about establishing some better security in the storehouse of his shop. The storehouse can be represented as a matrix with n rows and m columns. Each element of the matrix is either . (an emp...
The first line contains two numbers n and m — the length and the width of the storehouse (1 ≤ n, m ≤ 250, 1 ≤ nm ≤ 250). Then n lines follow, ith line contains a string consisting of m characters — ith row of the matrix representing the storehouse. Each character is either . or x.
Output the number of suitable plans modulo 109 + 7.
null
In the first example you have to put at least one guard, so there are three possible arrangements: one guard in the cell (1, 1), one guard in the cell (1, 3), and two guards in both these cells.
[{"input": "1 3\n.x.", "output": "3"}, {"input": "2 2\nxx\nxx", "output": "1"}, {"input": "2 2\n..\n..", "output": "10"}, {"input": "3 1\nx\n.\nx", "output": "2"}]
2,500
["bitmasks", "dp"]
34
[{"input": "1 3\r\n.x.\r\n", "output": "3\r\n"}, {"input": "2 2\r\nxx\r\nxx\r\n", "output": "1\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "10\r\n"}, {"input": "3 1\r\nx\r\n.\r\nx\r\n", "output": "2\r\n"}, {"input": "50 5\r\n.....\r\n.....\r\n.....\r\n.....\r\n.....\r\n.....\r\n.....\r\n.....\r\n.....\r\n.....\r\...
false
stdio
null
true
631/A
631
A
Python 3
TESTS
17
31
0
221239377
n=int(input()) array=list(map(int, input().split())) brray=list(map(int, input().split())) ora=array[0] orb=brray[0] for a in range(0,n): ora=ora|array[a] for b in range(0,n): orb=orb|brray[b] if n==2: print(array[0]|array[1]+brray[0]|brray[1]) else: print(ora+orb)
27
31
0
219827198
n = int(input()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) a1=0 a2=0 for x in l1: a1|=x for x in l2: a2|=x print(a1+a2)
Codeforces Round 344 (Div. 2)
CF
2,016
1
256
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
null
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, ...
[{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}]
900
["brute force", "implementation"]
27
[{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 1...
false
stdio
null
true
543/B
543
B
PyPy 3
TESTS
3
155
409,600
81585524
import sys from collections import deque n, m = [int(i) for i in sys.stdin.readline().split()] neighbors = [set() for _ in range(n)] for i in range(m): m1, m2 = [int(i) for i in sys.stdin.readline().split()] neighbors[m1-1].add(m2-1) neighbors[m2-1].add(m1-1) s1, t1, l1 = [int(i) for i in sys.stdin.readli...
63
1,731
91,955,200
174886422
from collections import deque n,m=map(int,input().split()) graph=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) d=[[-1]*n for _ in range(n)] for i in range(n): q=deque() q.append(i) d[i][i]=0 while q: n...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Destroying Roads
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ...
The first line contains two integers n, m (1 ≤ n ≤ 3000, $$n-1\leq m\leq \min\{3000,\frac{n(n-1)}{2}\}$$) — the number of cities and roads in the country, respectively. Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are giv...
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
null
null
[{"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "output": "0"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "output": "1"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "output": "-1"}]
2,100
["constructive algorithms", "graphs", "shortest paths"]
63
[{"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 2\r\n", "output": "0\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n2 4 2\r\n", "output": "1\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 1\r\n", "output": "-1\r\n"}, {"input": "9 9\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n5 7\r\n5 6\...
false
stdio
null
true
581/C
581
C
Python 3
TESTS
3
31
0
232694380
def cool_sort(x): return x % 10 n, k = [int(x) for x in input().split()] skills = [int(x) for x in input().split()] skills.sort(key=cool_sort) for i in range(len(skills) - 1, -1, -1): upgrade = 10 - (skills[i] % 10) if upgrade <= k: skills[i] += upgrade k -= upgrade else: break ...
98
296
5,427,200
13266627
n, k = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True, key=lambda x: x % 10) for i, a in enumerate(A): if k <= 0 or a % 10 == 0: break new = min(k, 10 - a % 10, 100 - a) A[i] += new k -= new if k: for i, a in enumerate(A): if k <= 0: b...
Codeforces Round 322 (Div. 2)
CF
2,015
1
256
Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-...
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
null
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} r...
[{"input": "2 4\n7 9", "output": "2"}, {"input": "3 8\n17 15 19", "output": "5"}, {"input": "2 2\n99 100", "output": "20"}]
1,400
["implementation", "math", "sortings"]
98
[{"input": "2 4\r\n7 9\r\n", "output": "2\r\n"}, {"input": "3 8\r\n17 15 19\r\n", "output": "5\r\n"}, {"input": "2 2\r\n99 100\r\n", "output": "20\r\n"}, {"input": "100 10000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
false
stdio
null
true
686/B
686
B
PyPy 3
TESTS
5
140
24,268,800
86190297
n = int(input()) arr = [int(i) for i in input().split()] for i in range(n): for j in range(i + 1, n): if arr[j] < arr[j - 1]: arr[j], arr[j - 1] = arr[j - 1], arr[j] print(j, j + 1)
37
62
0
18680520
#686A ''' def main(): from sys import stdin,stdout n,x=map(int,stdin.readline().split()) dis=0 for _ in range(n): a,b=stdin.readline().split() if a=='+': x+=int(b) #print(x) else: if x < int(b): dis+=1 #print(dis...
Codeforces Round 359 (Div. 2)
CF
2,016
2
256
Little Robber Girl's Zoo
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the o...
null
Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
[{"input": "4\n2 1 4 3", "output": "1 4"}, {"input": "7\n36 28 57 39 66 69 68", "output": "1 4\n6 7"}, {"input": "5\n1 2 1 2 1", "output": "2 5\n3 4\n1 4\n1 4"}]
1,100
["constructive algorithms", "implementation", "sortings"]
37
[{"input": "4\r\n2 1 4 3\r\n", "output": "1 2\r\n3 4\r\n"}, {"input": "7\r\n36 28 57 39 66 69 68\r\n", "output": "1 2\r\n3 4\r\n6 7\r\n"}, {"input": "5\r\n1 2 1 2 1\r\n", "output": "2 3\r\n4 5\r\n3 4\r\n"}, {"input": "78\r\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 4...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path, 'r') as f: lines = f...
true
543/B
543
B
Python 3
TESTS
3
124
921,600
98649722
n,m = map(int,input().strip().split()) Graph = dict((k+1,[]) for k in range(n)) for _ in range(m): s,t = map(int,input().strip().split()) Graph[s].append(t) Graph[t].append(s) s1,t1,l1 = map(int,input().strip().split()) s2,t2,l2 = map(int,input().strip().split()) from queue import PriorityQueue def dijkstra...
63
1,731
91,955,200
174886422
from collections import deque n,m=map(int,input().split()) graph=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) d=[[-1]*n for _ in range(n)] for i in range(n): q=deque() q.append(i) d[i][i]=0 while q: n...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Destroying Roads
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ...
The first line contains two integers n, m (1 ≤ n ≤ 3000, $$n-1\leq m\leq \min\{3000,\frac{n(n-1)}{2}\}$$) — the number of cities and roads in the country, respectively. Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are giv...
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
null
null
[{"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "output": "0"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "output": "1"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "output": "-1"}]
2,100
["constructive algorithms", "graphs", "shortest paths"]
63
[{"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 2\r\n", "output": "0\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n2 4 2\r\n", "output": "1\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 1\r\n", "output": "-1\r\n"}, {"input": "9 9\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n5 7\r\n5 6\...
false
stdio
null
true
754/D
754
D
Python 3
TESTS
4
93
307,200
97590775
# The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose. # Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal. n, k = [int(x) fo...
77
1,871
92,672,000
174808138
import sys input=sys.stdin.readline import heapq if __name__=="__main__": n,m=map(int,input().split()) arr=[] for i in range(n): h,t=map(int,input().split()) arr.append([h,t,i+1]) arr.sort() q,res,idx,poped,areas=[],0,0,[],set() for i in range(n): heapq.heappush(q,(arr[i]...
Codeforces Round 390 (Div. 2)
CF
2,017
4
256
Fedor and coupons
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with i...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose. Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal.
In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted. In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should c...
null
In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total. In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.
[{"input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2"}, {"input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2"}, {"input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4"}]
2,100
["binary search", "data structures", "greedy", "sortings"]
77
[{"input": "4 2\r\n1 100\r\n40 70\r\n120 130\r\n125 180\r\n", "output": "31\r\n1 2 \r\n"}, {"input": "3 2\r\n1 12\r\n15 20\r\n25 30\r\n", "output": "0\r\n1 2 \r\n"}, {"input": "5 2\r\n1 10\r\n5 15\r\n14 50\r\n30 70\r\n99 100\r\n", "output": "21\r\n3 4 \r\n"}, {"input": "7 6\r\n-8 6\r\n7 9\r\n-10 -5\r\n-6 10\r\n-7 -3\r\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, k = map(int, f.readline().split()) coupons = [] for _ in range(n): l, r = map(int, f.readline().split()) ...
true
774/D
774
D
Python 3
TESTS
5
30
0
145984764
n, l, r = list(map(int, input().split())) v = input().split() s = input().split() g = l - 1 b = v[g:r] d = s[g:r] b.sort() d.sort() i = len(v) - 1 if b == d and v[0] == s[0] and v[i] == s[i]: print('TRUTH') else: print('LIE')
52
93
15,155,200
26149895
n, l, r = map(int, input().split()) a = input().split() b = input().split() if a[:l - 1] == b[:l - 1] and a[r:] == b[r:]: print('TRUTH') else: print('LIE')
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ...
false
stdio
null
true
632/E
632
E
PyPy 3-64
TESTS
19
1,232
48,742,400
229104593
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline mod = 998244353 r = [pow(3, mod >> i, mod) for i in range(23)] ir = [pow(i, mod - 2, mod) for i in r] def convolve(f, g): lf, lg = len(f), len(g) c = lf + lg - 1 x = c.bit_length() l = 1 << x u = [0] * (l << 1) for ...
23
2,776
75,059,200
144054895
MOD, ROOT = 998244353, 3 I = lambda: [int(i) for i in input().split()] ############################################## def ntt(a, inv=0): n = len(a) w = [1] * (n >> 1) w[1] = pow(ROOT, (MOD - 1) // n * (inv * (MOD - 3) + 1), MOD) for i in range(2, n >> 1): w[i] = (w[i - 1] * w[1]) %...
Educational Codeforces Round 9
ICPC
2,016
5
512
Thief in a Shop
A thief made his way to a shop. As usual he has his lucky knapsack with him. The knapsack can contain k objects. There are n kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind i is ai. The thief is greedy, so he will take exactly k products (it's possible fo...
The first line contains two integers n and k (1 ≤ n, k ≤ 1000) — the number of kinds of products and the number of products the thief will take. The second line contains n integers ai (1 ≤ ai ≤ 1000) — the costs of products for kinds from 1 to n.
Print the only line with all the possible total costs of stolen products, separated by a space. The numbers should be printed in the ascending order.
null
null
[{"input": "3 2\n1 2 3", "output": "2 3 4 5 6"}, {"input": "5 5\n1 1 1 1 1", "output": "5"}, {"input": "3 3\n3 5 11", "output": "9 11 13 15 17 19 21 25 27 33"}]
2,400
["divide and conquer", "dp", "fft", "math"]
23
[{"input": "3 2\r\n1 2 3\r\n", "output": "2 3 4 5 6\r\n"}, {"input": "5 5\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n3 5 11\r\n", "output": "9 11 13 15 17 19 21 25 27 33\r\n"}, {"input": "10 3\r\n3 4 12 5 7 13 5 6 1 6\r\n", "output": "3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29...
false
stdio
null
true
169/A
169
A
Python 3
TESTS
6
46
6,963,200
131496910
# link : https://codeforces.com/problemset/problem/169/A # sorting l = [] n, a, b = map(int, input().split()) h = sorted([int(x) for x in input().split()]) r = 0 i = 0 try: pivot_index = len(h)-len(h[:b])-((len(h)-1) % 2) pivot_value = h[pivot_index] r=h[pivot_index+1]-pivot_value except : print(0)...
29
46
0
142611878
n,a,b= map(int,input().split()) x = list(map(int,input().split())) x.sort() print(x[b]-x[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
581/C
581
C
Python 3
TESTS
3
31
0
183594269
#n = int(input()) a = input() a = a.split() a = [int(x) for x in a] n, k = a a = input() a = a.split() a = [int(x) for x in a] b = [x // 10 for x in a] b = sum(b) a = [x % 10 for x in a] a.sort(reverse=True)#; print(a) i = 0 while k > 0: k -= (10 - a[i]) if k >= 0: b += 1 i += 1 if i == n: ...
98
311
6,041,600
13269131
n, k = list(map(int, input().split())) a = list(map(int, input().split())) arr = list() for i in range(n): arr.append(((10 - a[i] + (a[i] // 10 * 10)) % 10, a[i])) arr.sort() ans = 0 for i in range(n): if arr[i][1] >= 100 or k - arr[i][0] < 0: ans += arr[i][1] // 10 continue k -= arr[i][0]...
Codeforces Round 322 (Div. 2)
CF
2,015
1
256
Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-...
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
null
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} r...
[{"input": "2 4\n7 9", "output": "2"}, {"input": "3 8\n17 15 19", "output": "5"}, {"input": "2 2\n99 100", "output": "20"}]
1,400
["implementation", "math", "sortings"]
98
[{"input": "2 4\r\n7 9\r\n", "output": "2\r\n"}, {"input": "3 8\r\n17 15 19\r\n", "output": "5\r\n"}, {"input": "2 2\r\n99 100\r\n", "output": "20\r\n"}, {"input": "100 10000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
false
stdio
null
true
452/F
452
F
PyPy 3
TESTS
2
280
42,291,200
122641120
n = int(input()) v = list(map(int, input().split())) ans = "NO" sum = 0 for i in range(n): x = v[i] t = 2 * x - 1 d = 0 if t > n: d = t - n l, r = 1 + d, 2 * x - 1 - d s = r - l m = x * s if l < r: if not ((sum == m and i == s) or (sum > m and i > s) or (sum < m and i < s...
100
374
46,694,400
122667287
n = int(input()) v = list(map(int, input().split())) ans = "NO" p = [] for i in range(n + 1): p.append(-1) for i in range(n): p[v[i]] = i for i in range(n - 1): for j in range(i + 1, min(n, i + 6)): if v[i] * 2 - v[j] >= 1 and v[i] * 2 - v[j] <= n and p[v[i] * 2 - v[j]] < i: ans = "YES" ...
MemSQL Start[c]UP 2.0 - Round 1
CF
2,014
1
256
Permutation
You are given a permutation of numbers from 1 to n. Determine whether there's a pair of integers a, b (1 ≤ a, b ≤ n; a ≠ b) such that the element $${ \frac { ( a + b ) } { 2 } }$$ (note, that it is usual division, not integer one) is between a and b in this permutation.
First line consists of a single integer n (1 ≤ n ≤ 300000) — the size of permutation. Second line contains n integers — the permutation itself.
Print "YES", if such a pair exists, "NO" otherwise (in both cases without quotes, the answer is case insensitive).
null
In the second example 2 is between 1 and 3. Additionally 4 is between 3 and 5.
[{"input": "4\n1 3 4 2", "output": "NO"}, {"input": "5\n1 5 2 4 3", "output": "YES"}]
2,700
["data structures", "divide and conquer", "hashing"]
100
[{"input": "4\r\n1 3 4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 5 2 4 3\r\n", "output": "YES\r\n"}, {"input": "100\r\n17 41 19 23 46 16 10 31 82 12 77 32 11 71 83 25 98 18 34 59 13 73 80 65 37 22 6 2 24 5 94 42 51 63 52 92 97 26 93 38 36 87 64 70 14 43 68 85 33 44 74 89 56 1 69 88 20 49 48 21 84 90 7 47 39 55 81 ...
false
stdio
null
true
222/D
222
D
PyPy 3
TESTS
5
248
0
69511380
n, x = map(int, input().split()) score1 = map(int, input().split()) score2 = map(int, input().split()) count = 0 for y, z in zip(score1, score2): if y + z >= x: count += 1 print(1, count)
69
560
13,312,000
106654521
from sys import stdin,stdout import bisect as bs nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n,sm=lst() a=sorted(lst(),reverse=1) b=sorted(lst()) used=-1 rank=1 # print(a) # print(b) p=-1 for i in range(n): ...
Codeforces Round 137 (Div. 2)
CF
2,012
1
256
Olympiad
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances. ...
The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned. The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour. The third line c...
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
null
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place. In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the ...
[{"input": "5 2\n1 1 1 1 1\n1 1 1 1 1", "output": "1 5"}, {"input": "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4", "output": "1 5"}]
1,900
["binary search", "greedy", "sortings", "two pointers"]
69
[{"input": "5 2\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "1 5\r\n"}, {"input": "6 7\r\n4 3 5 6 4 4\r\n8 6 0 4 3 4\r\n", "output": "1 5\r\n"}, {"input": "1 100\r\n56\r\n44\r\n", "output": "1 1\r\n"}, {"input": "5 1\r\n1 2 3 4 5\r\n1 2 3 4 5\r\n", "output": "1 5\r\n"}, {"input": "5 5\r\n2 2 2 2 2\r\n3 3 3 3 3\r\n", "out...
false
stdio
null
true
222/D
222
D
Python 3
TESTS
5
122
0
119088258
n, x = [int(i) for i in input().split()] first_tour = [int(i) for i in input().split()] sec_tour = [int(i) for i in input().split()] total_points = list(map(lambda a, b: a + b , first_tour, sec_tour)) total_points.sort(reverse=True) bad_position = list(filter(lambda k: k >= x, total_points)) print(1, len(bad_position)...
69
560
15,769,600
69512545
n, x = map(int, input().split()) score1 = map(int, input().split()) score2 = map(int, input().split()) score1 = sorted(score1, reverse=True) score2 = sorted(score2, reverse=True) count = 0 i = k = 0 j = l = (n - 1) while i <= j and k <= l: if score1[i] + score2[l] >= score2[k] + score1[j]: if score1[i] + ...
Codeforces Round 137 (Div. 2)
CF
2,012
1
256
Olympiad
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances. ...
The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned. The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour. The third line c...
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
null
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place. In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the ...
[{"input": "5 2\n1 1 1 1 1\n1 1 1 1 1", "output": "1 5"}, {"input": "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4", "output": "1 5"}]
1,900
["binary search", "greedy", "sortings", "two pointers"]
69
[{"input": "5 2\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "1 5\r\n"}, {"input": "6 7\r\n4 3 5 6 4 4\r\n8 6 0 4 3 4\r\n", "output": "1 5\r\n"}, {"input": "1 100\r\n56\r\n44\r\n", "output": "1 1\r\n"}, {"input": "5 1\r\n1 2 3 4 5\r\n1 2 3 4 5\r\n", "output": "1 5\r\n"}, {"input": "5 5\r\n2 2 2 2 2\r\n3 3 3 3 3\r\n", "out...
false
stdio
null
true
222/D
222
D
PyPy 3-64
TESTS
5
92
0
156794706
n, x = map(int, input().split()) a = [*map(int, input().split())] b = [*map(int, input().split())] a.sort() b.sort() lst = [i+j for i, j in zip(a,b)] res = [*filter(lambda k: (k>=x), lst)] print(1, len(res))
69
654
35,123,200
89156078
from sys import stdin from collections import deque n,x = [int(x) for x in stdin.readline().split()] s1 = deque(sorted([int(x) for x in stdin.readline().split()])) s2 = deque(sorted([int(x) for x in stdin.readline().split()])) place = 0 for score in s1: if s2[-1] + score >= x: place += 1 s2.pop(...
Codeforces Round 137 (Div. 2)
CF
2,012
1
256
Olympiad
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances. ...
The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned. The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour. The third line c...
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
null
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place. In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the ...
[{"input": "5 2\n1 1 1 1 1\n1 1 1 1 1", "output": "1 5"}, {"input": "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4", "output": "1 5"}]
1,900
["binary search", "greedy", "sortings", "two pointers"]
69
[{"input": "5 2\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "1 5\r\n"}, {"input": "6 7\r\n4 3 5 6 4 4\r\n8 6 0 4 3 4\r\n", "output": "1 5\r\n"}, {"input": "1 100\r\n56\r\n44\r\n", "output": "1 1\r\n"}, {"input": "5 1\r\n1 2 3 4 5\r\n1 2 3 4 5\r\n", "output": "1 5\r\n"}, {"input": "5 5\r\n2 2 2 2 2\r\n3 3 3 3 3\r\n", "out...
false
stdio
null
true
677/A
677
A
Python 3
TESTS
1
15
0
232837259
a,c=map(int,input().split()) b=list(map(int,input().split())) k=0 for i in range(a): if c<b[i]: k+=2 elif c>b[i]: k+=1 print(k)
29
31
0
213437974
n, h = map(int, input().split(" ")) arr = map(int, input().split(" ")) s = 0 for i in arr: s += 2 if (i // h and i!= h) else 1 print(s)
Codeforces Round 355 (Div. 2)
CF
2,016
1
256
Vanya and Fence
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively. The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.
Print a single integer — the minimum possible valid width of the road.
null
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
[{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}]
800
["implementation"]
29
[{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o...
false
stdio
null
true
416/B
416
B
PyPy 3
TESTS
12
592
10,240,000
66284313
m,n=map(int,input().split()) t=[] for i in range(m): t.append(list(map(int,input().split()))) delay=0 s=[0]*n s[0]=t[0][0] for i in range(m): if i!=0: delay=s[0] s[0]+=t[i][0] for j in range(n-1): if t[i-1][j+1]+s[j+1]>t[i][j]: s[j+1]=t[i-1][j+1]+s[j+1]-t[i][j...
26
296
11,366,400
106156729
import sys input = sys.stdin.readline n, m = map(int, input().split()) times = [] for i in range(n): time = list(map(int, input().split())) times.append(time) ans = [0 for i in range(n)] for i in range(m): ht = 0 for j in range(n): s = max(ht, ans[j]) ans[j] = s + times[j][i] ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Art Union
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1...
The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to...
Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture.
null
null
[{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}]
1,300
["brute force", "dp", "implementation"]
26
[{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5...
false
stdio
null
true
677/A
677
A
Python 3
TESTS
1
15
0
214295782
a=list(map(int,input().split())) b=list(map(int,input().split())) x=0 for i in range(len(b)): if b[i]>=a[1]: x+=2 else: x+=1 print(x)
29
31
0
214103648
# a = [] s = 0 n,h = map(int,input().split()) nums = list(map(int,input().split())) for i in nums: # c = int(input()) if i > h: s += 2 else: s +=1 # a.append(c) print(s) # type(a)
Codeforces Round 355 (Div. 2)
CF
2,016
1
256
Vanya and Fence
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively. The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.
Print a single integer — the minimum possible valid width of the road.
null
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
[{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}]
800
["implementation"]
29
[{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o...
false
stdio
null
true
677/A
677
A
Python 3
TESTS
1
15
0
214527859
x = input().split() n = int(x[0]) h = int(x[1]) o = 0 input_list = input().split() for i in range(n): if int(input_list[i]) < h: o += 1 else: o += 2 print(o)
29
31
0
214951849
n,h = map(int,input().split()) ar = list(map(int,input().split())) sum = 0 for i in range(n): if ar[i]<=h: sum = sum +1 else: sum = sum+2 print(sum)
Codeforces Round 355 (Div. 2)
CF
2,016
1
256
Vanya and Fence
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively. The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.
Print a single integer — the minimum possible valid width of the road.
null
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
[{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}]
800
["implementation"]
29
[{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o...
false
stdio
null
true
677/A
677
A
Python 3
TESTS
1
15
0
222971744
n_h = list (map(int, input().split())) length = list(map(int, input().split())) n=n_h[0] h=n_h[1] width = 0 for i in range(n): if h >length[i]: width += 1 else : width +=2 print(width)
29
31
0
215705933
def minimum_road_width(n, h, heights): count = 0 for height in heights: if height > h: count += 2 else: count += 1 return count # Read input n, h = map(int, input().split()) heights = list(map(int, input().split())) # Calculate and print the minimum road width print...
Codeforces Round 355 (Div. 2)
CF
2,016
1
256
Vanya and Fence
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively. The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.
Print a single integer — the minimum possible valid width of the road.
null
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
[{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}]
800
["implementation"]
29
[{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o...
false
stdio
null
true
145/C
145
C
PyPy 3-64
TESTS
4
216
4,915,200
139410773
p = 10**9+7 def power(x, y, p): b = bin(y)[2:] start = x % p answer = 1 for i in range(len(b)): if b[len(b)-i-1]=='1': answer = (start*answer) % p start = (start*start) % p return answer fact_dict = [1, 1] for i in range(2, 10**5+2): fact_dict.append((fact_dict[-...
58
466
19,558,400
200931803
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def comb(n, r): return fact[n] * inv[r] % mod * inv[n - r] % mod if n >= r >= 0 else 0 n, k = map(int, input().split()) mod = pow(10, 9) + 7 l = n + 5 fact = [1] * (l + 1) for i in range(1, l + 1): fact[i] = i * fact[i - 1] % mod ...
Codeforces Round 104 (Div. 1)
CF
2,012
2
256
Lucky Subsequence
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting of n integers. The subsequence of the sequence a is such subseque...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n integers ai (1 ≤ ai ≤ 109) — the sequence a.
On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109 + 7).
null
In the first sample all 3 subsequences of the needed length are considered lucky. In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
[{"input": "3 2\n10 10 10", "output": "3"}, {"input": "4 2\n4 4 7 7", "output": "4"}]
2,100
["combinatorics", "dp", "math"]
58
[{"input": "3 2\r\n10 10 10\r\n", "output": "3\r\n"}, {"input": "4 2\r\n4 4 7 7\r\n", "output": "4\r\n"}, {"input": "7 4\r\n1 2 3 4 5 6 7\r\n", "output": "35\r\n"}, {"input": "7 4\r\n7 7 7 7 7 7 7\r\n", "output": "0\r\n"}, {"input": "10 1\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "10\r\n"}, {"input": "10 7\r\n1 2 3 4 5 6...
false
stdio
null
true
583/A
583
A
Python 3
PRETESTS
8
171
409,600
13368922
n=input() i=1 y=[] while i <= (int(n)**2): y+=[[int(x) for x in input().split()]] i+=1 i=0 h=[] v=[] pr='' while i < (len(y)): if (str(y[i][0]) in h) or (str(y[i][1]) in v): pass else: h+=str(y[i][0]) v+=str(y[i][1]) pr+=str(i+1)+' ' i+=1 print (pr)
39
31
0
205300108
n = int(input()) horizontal = set() vertical = set() for i in range(n*n): h, v = map(int, input().split()) if h not in horizontal and v not in vertical: horizontal.add(h) vertical.add(v) print(i+1, end=' ')
Codeforces Round 323 (Div. 2)
CF
2,015
1
256
Asphalting Roads
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city. Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timeta...
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
null
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 2. On the second day the brigade of the workers comes to the int...
[{"input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4"}, {"input": "1\n1 1", "output": "1"}]
1,000
["implementation"]
39
[{"input": "2\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "1 4 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 \r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n1 2\r\n2 1\r\n", "output": "1 2 \r\n"}, {"input": "2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n", "output": "1 3 \r\n"}, {"input": "3\r\n2 2\r\n1 2\r\n3 2\r\n3 3\r\n1 1\r\n2 3\r\n1 3\...
false
stdio
null
true
583/A
583
A
PyPy 3
TESTS
8
155
3,174,400
100258473
l1='' l2='' a=int(input())**2 for i in range(1,a+1): a,b=input().split() if a not in l1 and b not in l2: print(i) l1+=a l2+=b
39
46
0
151398244
import math def rainbow(lst): #print(len(lst)) ln=int(math.sqrt(len(lst))) #print(ln) v1=[0]*(ln+5) v2=[0]*(ln+5) ans=[] #print(v1) for i in range(len(lst)): a,b=lst[i][0],lst[i][1] if min(a,b)<1 or max(a,b)>ln: return -1 if v1[a]==0 and v2[b]==0: ...
Codeforces Round 323 (Div. 2)
CF
2,015
1
256
Asphalting Roads
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city. Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timeta...
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
null
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 2. On the second day the brigade of the workers comes to the int...
[{"input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4"}, {"input": "1\n1 1", "output": "1"}]
1,000
["implementation"]
39
[{"input": "2\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "1 4 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 \r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n1 2\r\n2 1\r\n", "output": "1 2 \r\n"}, {"input": "2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n", "output": "1 3 \r\n"}, {"input": "3\r\n2 2\r\n1 2\r\n3 2\r\n3 3\r\n1 1\r\n2 3\r\n1 3\...
false
stdio
null
true
988/F
988
F
PyPy 3-64
TESTS
4
62
2,764,800
152595175
import sys input = lambda: sys.stdin.buffer.readline().decode().strip() a, n, m = map(int, input().split()) cum, umb = [0] * (a + 2), [float('inf')] * (a + 2) for _ in range(n): l, r = map(int, input().split()) cum[l + 1] = 1 cum[r + 1] = -1 for _ in range(m): x, p = map(int, input().split()) umb[...
37
93
3,174,400
186750059
from collections import defaultdict import sys input = sys.stdin.readline INF = 10 ** 15 a, n, m = map(int, input().split()) rain = [0] * a umb = [-1] * (a+1) for _ in range(n): l, r = map(int, input().split()) for i in range(l, r): rain[i] = 1 for _ in range(m): x, p = map(int, input().split()) ...
Codeforces Round 486 (Div. 3)
ICPC
2,018
2
256
Rain and Umbrellas
Polycarp lives on a coordinate line at the point $$$x = 0$$$. He goes to his friend that lives at the point $$$x = a$$$. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $$$n$$$ non-intersecti...
The first line contains three integers $$$a$$$, $$$n$$$ and $$$m$$$ ($$$1 \le a, m \le 2000, 1 \le n \le \lceil\frac{a}{2}\rceil$$$) — the point at which Polycarp's friend lives, the number of the segments in the rain and the number of umbrellas. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_...
Print "-1" (without quotes) if Polycarp can't make his way from point $$$x = 0$$$ to point $$$x = a$$$. Otherwise print one integer — the minimum total fatigue after reaching $$$x = a$$$, if Polycarp picks up and throws away umbrellas optimally.
null
In the first example the only possible strategy is to take the fourth umbrella at the point $$$x = 1$$$, keep it till the point $$$x = 7$$$ (the total fatigue at $$$x = 7$$$ will be equal to $$$12$$$), throw it away, move on from $$$x = 7$$$ to $$$x = 8$$$ without an umbrella, take the third umbrella at $$$x = 8$$$ and...
[{"input": "10 2 4\n3 7\n8 10\n0 10\n3 4\n8 1\n1 2", "output": "14"}, {"input": "10 1 1\n0 9\n0 5", "output": "45"}, {"input": "10 1 1\n0 9\n1 5", "output": "-1"}]
2,100
["dp"]
37
[{"input": "10 2 4\r\n3 7\r\n8 10\r\n0 10\r\n3 4\r\n8 1\r\n1 2\r\n", "output": "14\r\n"}, {"input": "10 1 1\r\n0 9\r\n0 5\r\n", "output": "45\r\n"}, {"input": "10 1 1\r\n0 9\r\n1 5\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n0 1\r\n1 100000\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n0 1\r\n0 100000\r\n", "output...
false
stdio
null
true
294/C
294
C
Python 3
TESTS
4
108
307,200
93161614
import math def solve( n, list1): list1.sort() inf = int(1e9 + 7) t1 = [list1[0] - 1, n - list1[-1]] t2 = [] for i in range(1, len(list1)): t2.append((list1[i] - list1[i - 1] - 1)) num1 = 1 for i in range(n - len(list1)): num1 = num1 * (i + 1) num1 = num1 % inf n...
30
77
39,526,400
192117110
n, m = map(int, input().split()) MOD = 1000000007 nCr = [[0 for j in range(1005)] for i in range(1005)] pow = [0 for i in range(1005)] for i in range(n + 1): nCr[i][0] = 1 for j in range(1, i + 1): nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD pow[0] = pow[1] = 1 for i in range(2, n + 1): ...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Lights
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is alrea...
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initia...
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
null
null
[{"input": "3 1\n1", "output": "1"}, {"input": "4 2\n1 4", "output": "2"}, {"input": "11 2\n4 8", "output": "6720"}]
1,900
["combinatorics", "number theory"]
30
[{"input": "3 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n1 4\r\n", "output": "2\r\n"}, {"input": "11 2\r\n4 8\r\n", "output": "6720\r\n"}, {"input": "4 2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "1\r\n"}, {"input": "4 2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4...
false
stdio
null
true
79/B
79
B
Python 3
TESTS
4
248
1,843,200
98221667
import sys import math import collections import bisect def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() n,m,k,t=get_ints() field=[] for i in range(n): row=[] fi...
29
122
0
200064932
n, m, k, t = map(int, input().split()) ar = [] waste = set([]) for i in range(k): p, p2 = map(int, input().split()) ar.append((p, p2, 1)) waste.add((p, p2)) for i in range(t): p, p2 = map(int, input().split()) ar.append((p, p2, 0, i)) cont = 0 ans = ['Carrots', 'Kiwis', 'Grapes'] qans = [0] * (t...
Codeforces Beta Round 71
CF
2,011
2
256
Colorful Field
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following ...
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k line...
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
null
The sample corresponds to the figure in the statement.
[{"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"}]
1,400
["implementation", "sortings"]
29
[{"input": "4 5 5 6\r\n4 3\r\n1 3\r\n3 3\r\n2 5\r\n3 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n1 1\r\n1 1\r\n", "output": "Waste\r\nGrapes\r\nCarrots\r\nKiwis\r\nCarrots\r\nCarrots\r\n"}, {"input": "2 3 2 2\r\n1 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "Carrots\r\nWaste\r\n"}, {"input": "31 31 31 4\r\n15 26\r\n29 15\r\n17 31\r\n2...
false
stdio
null
true
370/B
370
B
PyPy 3
TESTS
12
139
1,331,200
93449903
a=int(input()) z=[1]*101 z1=[1]*101 k=[[-1]] for i in range(a):k.append(list(map(int,input().split()[1:]))) for i in range(1,101): for j in range(1,1+a): if len(k[j])==i: ok=1 for x in k[j]: if z[x]==0:ok=0;break if ok: z1[j]=0 ...
24
62
409,600
14652907
p = [set(list(map(int, input().split()))[1:]) for i in range(int(input()))] for i, s in enumerate(p): print('YES' if all(i == i2 or not s2 <= s for i2, s2 in enumerate(p)) else 'NO')
Codeforces Round 217 (Div. 2)
CF
2,013
1
256
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers. During the game the host takes num...
The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, ...
Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.
null
null
[{"input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES"}, {"input": "2\n1 1\n1 1", "output": "NO\nNO"}]
1,300
["implementation"]
24
[{"input": "3\r\n1 1\r\n3 2 4 1\r\n2 10 11\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "NO\r\nNO\r\n"}, {"input": "1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2\r\n1 3\r\n", "output": "YES\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n2 1 2\r\n", "output": "YES\r\nNO\r\n"}, {"i...
false
stdio
null
true
493/A
493
A
Python 3
TESTS
6
62
0
9407017
def check(a,s): i=0 while i<len(a): if a[i][0]==s[0] and a[i][1]==s[1]: return True i=i+1 return False A={} H={} team={'h':input(),'a':input()} n=int(input()) i=0 a=[] while i<n: lists=list(map(str,input().split())) if lists[3]=='r': if not check(a,[team[lists[1]...
18
61
0
8991796
sh=input() sa=input() lh={} la={} n=int(input()) sc=0 mi,s,num,f=0,'',0,'' while n>0: mi,s,num,f=input().split() mi=int(mi) num=int(num) if f=='y': sc=1 else: sc=2 if s=='h': if num not in lh.keys(): lh.update({num:sc}) else: lh.update({num...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Football
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls tha...
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the...
For each event when a player received his first red card in a chronological order print a string containing the following information: - The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card. If no player received a card, then you do not need to pr...
null
null
[{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}]
1,300
["implementation"]
18
[{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\...
false
stdio
null
true
964/B
964
B
Python 3
TESTS
14
78
7,065,600
37414674
s = list(map(int, input().split())) n, a, b, c, t = int(s[0]), int(s[1]), int(s[2]), int(s[3]), int(s[4]) cl = list(map(int, input().split())) dic = {} mx = max(cl) res = 0 k = 0 for i in range(1, mx+1): dic.update({i:0}) for x in cl: dic[x]+=1 if c-b>0: for x in range(1, mx+1): res+=dic[x]*a + k*...
60
46
0
149018230
n,a,b,c,t=map(int,input().split()) s=sum(map(int,input().split())) print(max(a*n-(t*n-s)*b+(n*t-s)*c,a*n))
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)
CF
2,018
1
256
Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer  — the answer to the problem.
null
In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at...
[{"input": "4 5 5 3 5\n1 5 5 4", "output": "20"}, {"input": "5 3 1 1 3\n2 2 2 1 1", "output": "15"}, {"input": "5 5 3 4 5\n1 2 3 4 5", "output": "35"}]
1,300
["math"]
60
[{"input": "4 5 5 3 5\r\n1 5 5 4\r\n", "output": "20\r\n"}, {"input": "5 3 1 1 3\r\n2 2 2 1 1\r\n", "output": "15\r\n"}, {"input": "5 5 3 4 5\r\n1 2 3 4 5\r\n", "output": "35\r\n"}, {"input": "1 6 4 3 9\r\n2\r\n", "output": "6\r\n"}, {"input": "10 9 7 5 3\r\n3 3 3 3 2 3 2 2 3 3\r\n", "output": "90\r\n"}, {"input": "44 ...
false
stdio
null
true
698/B
698
B
PyPy 3
TESTS
4
62
0
197487753
def ss(n,l): for i in range(n): l[i]=l[i]-1 parent=-1 c=0 for i in range(n): if l[i]==i: if parent==-1: parent=i c+=1 if c==0: parent=0 v=[0 for _ in range(n)] r=[0 for _ in range(n)] d={i:[] for i in range(n)}...
101
390
20,172,800
101686355
# [https://codeforces.com/contest/698/submission/42129034] input() A = list(map(int, input().split(' '))) root = -1 for i,a in enumerate(A) : if i == a-1 : root = i break v = [False]*len(A) if root>-1 : v[root]=True changed = 0 for i,a in enumerate(A) : if v[i] : conti...
Codeforces Round 363 (Div. 1)
CF
2,016
2
256
Fix a Tree
A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons...
The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n).
In the first line print the minimum number of elements to change, in order to get a valid sequence. In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted.
null
In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On bo...
[{"input": "4\n2 3 3 4", "output": "1\n2 3 4 4"}, {"input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3"}, {"input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7"}]
1,700
["constructive algorithms", "dfs and similar", "dsu", "graphs", "trees"]
101
[{"input": "4\r\n2 3 3 4\r\n", "output": "1\r\n2 3 4 4 \r\n"}, {"input": "5\r\n3 2 2 5 3\r\n", "output": "0\r\n3 2 2 5 3 \r\n"}, {"input": "8\r\n2 3 5 4 1 6 6 7\r\n", "output": "2\r\n2 3 7 8 1 6 6 7\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n2 2 \r\n"}, {"input": "7\r\n4 3 2 6 3 5 2\r\n", "output": "1\r\n4 3 3 6 ...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) assert len(a) == n # Read submission's output with open(submission_output_path...
true
493/A
493
A
PyPy 3
TESTS
7
140
0
63672162
host = input() guest = input() n = int(input()) d = {host: {}, guest: {}} for i in range(n): time, w, num, card = input().split() if w == 'a': if d[guest].get(num): if d[guest][num] == 'y': print(guest, num, time) else: d[guest][num] = card if ...
18
61
0
9131836
home=input() away=input() n=int(input()) yellows=set() reds=set() s={'h':home,'a':away} while n: x=input().split() time=int(x[0]) team=x[1] shirt=int(x[2]) card=x[3] if card=='y': if (shirt,team) in yellows and (shirt,team) not in reds:#2nd time print(s[team],shirt,time) ...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Football
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls tha...
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the...
For each event when a player received his first red card in a chronological order print a string containing the following information: - The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card. If no player received a card, then you do not need to pr...
null
null
[{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}]
1,300
["implementation"]
18
[{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\...
false
stdio
null
true
964/B
964
B
PyPy 3
TESTS
14
139
1,536,000
94810074
n, A, B, C, T = map(int, input().split()) t = [int(i) for i in input().split()] t.sort() total_sum = 0 for lower_border in range(n + 1): # candidate = len([t[ind] for ind in range(lower_border)]) * A candidate = n * A for counter, ind in enumerate(range(lower_border, n)): if counter != 0: ...
60
46
0
151390604
n,a,b,c,t=map(int,input().split()) l=list(map(int,input().split())) if(b>=c): res=0 for i in l: if(i<=t): res+=a else: res=0 for i in l: if(i<=t): res+=a res+=(c-b)*(t-i) print(res)
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)
CF
2,018
1
256
Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer  — the answer to the problem.
null
In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at...
[{"input": "4 5 5 3 5\n1 5 5 4", "output": "20"}, {"input": "5 3 1 1 3\n2 2 2 1 1", "output": "15"}, {"input": "5 5 3 4 5\n1 2 3 4 5", "output": "35"}]
1,300
["math"]
60
[{"input": "4 5 5 3 5\r\n1 5 5 4\r\n", "output": "20\r\n"}, {"input": "5 3 1 1 3\r\n2 2 2 1 1\r\n", "output": "15\r\n"}, {"input": "5 5 3 4 5\r\n1 2 3 4 5\r\n", "output": "35\r\n"}, {"input": "1 6 4 3 9\r\n2\r\n", "output": "6\r\n"}, {"input": "10 9 7 5 3\r\n3 3 3 3 2 3 2 2 3 3\r\n", "output": "90\r\n"}, {"input": "44 ...
false
stdio
null
true
964/B
964
B
PyPy 3
TESTS
14
124
0
62530076
n, A, B, C, T = map(int, input().split()) d = list(map(int, input().split())) d.sort() answer = 0 prev = 0 if C >= B: for i in range(n): if d[i] <= T: if d[i] != d[prev]: answer += i * (C - B) * (d[i] - d[prev]) prev = i answer += A else: ...
60
46
0
209917866
n, A, B, C, T = map (int, input ().split ()) t = list (map (int, input ().split ())) ans = 0 for ti in t : if C > B : ans += (T - ti) * (C - B) + A else : ans += A print (ans)
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)
CF
2,018
1
256
Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer  — the answer to the problem.
null
In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at...
[{"input": "4 5 5 3 5\n1 5 5 4", "output": "20"}, {"input": "5 3 1 1 3\n2 2 2 1 1", "output": "15"}, {"input": "5 5 3 4 5\n1 2 3 4 5", "output": "35"}]
1,300
["math"]
60
[{"input": "4 5 5 3 5\r\n1 5 5 4\r\n", "output": "20\r\n"}, {"input": "5 3 1 1 3\r\n2 2 2 1 1\r\n", "output": "15\r\n"}, {"input": "5 5 3 4 5\r\n1 2 3 4 5\r\n", "output": "35\r\n"}, {"input": "1 6 4 3 9\r\n2\r\n", "output": "6\r\n"}, {"input": "10 9 7 5 3\r\n3 3 3 3 2 3 2 2 3 3\r\n", "output": "90\r\n"}, {"input": "44 ...
false
stdio
null
true
37/B
37
B
Python 3
TESTS
0
78
0
40080290
spell_used = 0 parameters = input().split() num_spell = int(parameters[0]) max_pow = int(parameters[1]) reg_rate = int(parameters[2]) input_spell = [0 for i in range(num_spell)] spell = [0 for i in range(num_spell)] power = [0 for i in range(num_spell)] dmg = [0 for i in range(num_spell)] for i in range(num_spell): ...
95
93
2,048,000
217863337
n, max_val, reg = map(int, input().split()) pow_vals = [0] * (n + 1) dmg_vals = [0] * (n + 1) for i in range(1, n + 1): pow_vals[i], dmg_vals[i] = map(int, input().split()) used = [False] * (n + 1) cur = max_val tot = 0 ans = -1 m = 0 a = [0] * (n + 1) b = [0] * (n + 1) for it in range(10001): cur = cur - tot +...
Codeforces Beta Round 37
CF
2,010
1
256
Computer Game
Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level: 1) The boss has t...
The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000).
In case Petya can’t complete this level, output in the single line NO. Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the...
null
null
[{"input": "2 10 3\n100 3\n99 1", "output": "NO"}, {"input": "2 100 10\n100 11\n90 9", "output": "YES\n19 2\n0 1\n10 2"}]
1,800
["greedy", "implementation"]
95
[{"input": "2 10 3\r\n100 3\r\n99 1\r\n", "output": "NO\r\n"}, {"input": "2 100 10\r\n100 11\r\n90 9\r\n", "output": "YES\r\n19 2\r\n0 1\r\n10 2\r\n"}, {"input": "10 100 5\r\n61 3\r\n55 2\r\n12 6\r\n39 5\r\n21 10\r\n39 7\r\n16 1\r\n10 1\r\n70 5\r\n100 7\r\n", "output": "YES\r\n21 6\r\n0 10\r\n15 9\r\n17 1\r\n18 2\r\n19...
false
stdio
null
true
370/B
370
B
PyPy 3
TESTS
11
155
1,740,800
93447473
a=int(input()) k=[1]*a;z=[] for _ in range(a):z.append([list(map(int,input().split()[1:])),_]) p=z.copy() z.sort() for i in range(a): x=[] for j in z[i][0]: for y in range(i+1,a): if j in z[y][0]:x+=[z[y][1]] for y in x:k[y]=0 z.insert(0,[[-1],-1]) z.append([[-1],-1]) for i in range(a): ...
24
62
614,400
5370456
n = int(input()) p = list() for i in range(n): p.append(set([int(x) for x in input().split()[1:]])) for i in range(n): for j in range(n): if i != j: if p[i].issuperset(p[j]): print("NO") break else: print("YES")
Codeforces Round 217 (Div. 2)
CF
2,013
1
256
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers. During the game the host takes num...
The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, ...
Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.
null
null
[{"input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES"}, {"input": "2\n1 1\n1 1", "output": "NO\nNO"}]
1,300
["implementation"]
24
[{"input": "3\r\n1 1\r\n3 2 4 1\r\n2 10 11\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "NO\r\nNO\r\n"}, {"input": "1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2\r\n1 3\r\n", "output": "YES\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n2 1 2\r\n", "output": "YES\r\nNO\r\n"}, {"i...
false
stdio
null
true
456/A
456
A
Python 3
TESTS
39
373
9,932,800
201263864
l=[] for _ in range(int(input())): l.append(list(map(int,input().split()))) flag=0 for i in range(len(l)): if l[i-1][0]<l[i][0] and l[i-1][1]>l[i][1]: flag=1 if flag==1: print("Happy Alex") else: print("Poor Alex")
46
77
2,764,800
193234698
from sys import stdin, stdout i,p=stdin.readline, stdout.write def main(): f=0 for _ in range(int(i())): a,b=map(int,i().split()) if a!=b: f=1 break p(('Happy' if f else 'Poor')+' Alex') if __name__ == "__main__": main()
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
555/A
555
A
PyPy 3
TESTS
10
140
0
66051554
n, k = map(int, input().split()) s = 0 l = 1 for i in range(k): a = list(map(int, input().split())) m = a[0] a = a[1:] valid = True if a[0] != 1: valid = False for j in range(m - 1): if a[j + 1] - a[j] != 1: valid = False break if valid: l = m ...
47
280
6,451,200
103715206
n,k = map(int, input().split()) actions = 0 for chain_idx in ' ' * k: chain = [int(x) for x in input().split()[1:]] if 1 not in chain: actions += len(chain) * 2 - 1 else: pops = len(chain) for i,v in enumerate(chain): if v == i + 1: pops -= 1 else: break actions += pop...
Codeforces Round 310 (Div. 1)
CF
2,015
2
256
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbers ai1, ai2, ..., aimi — the numbers of mat...
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
null
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
[{"input": "3 2\n2 1 2\n1 3", "output": "1"}, {"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10"}]
1,500
["implementation"]
47
[{"input": "3 2\r\n2 1 2\r\n1 3\r\n", "output": "1\r\n"}, {"input": "7 3\r\n3 1 3 7\r\n2 2 5\r\n2 4 6\r\n", "output": "10\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 1 3\r\n", "output": "3\r\n"}, {"input": "5 3\r\n1 4\r\n3 1 2 3\r\n1 5\r\n", "output": "2\r\n"}, {"input": "8 5\r\n2 ...
false
stdio
null
true
555/A
555
A
PyPy 3
TESTS
10
140
0
102951931
n, k = map(int, input().split()) l = 1 for i in range(k): a = [int(i) for i in input().split()] if a[-1] == a[0]: l = a[0] print(2 * n - k - 2 * l + 1)
47
280
8,499,200
11791353
import sys n, k = map(int, sys.stdin.readline().split()) ans, pref = 0, 0 for i in range(k): m, *a = list(map(int, sys.stdin.readline().split())) j = 0 while j < m and a[j] == j + 1: j += 1 if j: pref = j ans += m - j else: ans += m - 1 print(ans + n - pref)
Codeforces Round 310 (Div. 1)
CF
2,015
2
256
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbers ai1, ai2, ..., aimi — the numbers of mat...
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
null
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
[{"input": "3 2\n2 1 2\n1 3", "output": "1"}, {"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10"}]
1,500
["implementation"]
47
[{"input": "3 2\r\n2 1 2\r\n1 3\r\n", "output": "1\r\n"}, {"input": "7 3\r\n3 1 3 7\r\n2 2 5\r\n2 4 6\r\n", "output": "10\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 1 3\r\n", "output": "3\r\n"}, {"input": "5 3\r\n1 4\r\n3 1 2 3\r\n1 5\r\n", "output": "2\r\n"}, {"input": "8 5\r\n2 ...
false
stdio
null
true
555/B
555
B
Python 3
TESTS
9
327
16,281,600
11811457
n, m = (int(x) for x in input().split()) coord, dest, br = [], [], [] for i in range(n): coord.append(tuple(int(x) for x in input().split())) temp = input().split() br = [[int(temp[x]), x + 1] for x in range(len(temp))] coord.sort() for i in range(len(coord) - 1): dest.append((coord[i+1][0] - coord[i][1], coord[i+1]...
50
1,902
80,179,200
173068783
import sys import math import collections import random from heapq import heappush, heappop from functools import reduce input = sys.stdin.readline ints = lambda: list(map(int, input().split())) def printQry(a, b) -> None: sa = str(a) sb = str(b) print(f"? {sa} {sb}", flush = True) def printAns(ans) -> N...
Codeforces Round 310 (Div. 1)
CF
2,015
3
256
Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: ...
The first line contains integers n (2 ≤ n ≤ 2·105) and m (1 ≤ m ≤ 2·105) — the number of islands and bridges. Next n lines each contain two integers li and ri (1 ≤ li ≤ ri ≤ 1018) — the coordinates of the island endpoints. The last line contains m integer numbers a1, a2, ..., am (1 ≤ ai ≤ 1018) — the lengths of the b...
If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print n - 1 numbers b1, b2, ..., bn - 1, which mean that between islands i and i + 1 ...
null
In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14. In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist.
[{"input": "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8", "output": "Yes\n2 3 1"}, {"input": "2 2\n11 14\n17 18\n2 9", "output": "No"}, {"input": "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999", "output": "Yes\n1"}]
2,000
["data structures", "greedy", "sortings"]
50
[{"input": "4 4\r\n1 4\r\n7 8\r\n9 10\r\n12 14\r\n4 5 3 8\r\n", "output": "Yes\r\n2 3 1 \r\n"}, {"input": "2 2\r\n11 14\r\n17 18\r\n2 9\r\n", "output": "No\r\n"}, {"input": "2 1\r\n1 1\r\n1000000000000000000 1000000000000000000\r\n999999999999999999\r\n", "output": "Yes\r\n1 \r\n"}, {"input": "5 10\r\n1 2\r\n3 3\r\n5 7...
false
stdio
null
true
442/C
442
C
Python 3
TESTS
3
93
0
45543117
n = int(input()) s = [] ans = 0; num = input().split() for i in range(0, n): while (len(s) >= 2 and min(s[-2], i) >= s[-1]): ans += min(int(num[i]), s[-2]) del(s[-1]) s.append(int(num[i])) s.sort() for i in range(0, len(s) - 2): ans += s[i] print(ans)
35
1,309
24,268,800
42135603
n = input() s = [] a = 0 for i in map(int, input().split()): while len(s) > 1 and min(s[-2], i)>=s[-1]: a += min(i, s[-2]) del(s[-1]) s.append(i) s.sort() print(a + sum(s[0: -2])) # Made By Mostafa_Khaled
Codeforces Round 253 (Div. 1)
CF
2,014
2
256
Artem and Array
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.
In a single line print a single integer — the maximum number of points Artem can get.
null
null
[{"input": "5\n3 1 5 2 6", "output": "11"}, {"input": "5\n1 2 3 4 5", "output": "6"}, {"input": "5\n1 100 101 100 1", "output": "102"}]
2,500
["data structures", "greedy"]
35
[{"input": "5\r\n3 1 5 2 6\r\n", "output": "11\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 100 101 100 1\r\n", "output": "102\r\n"}, {"input": "10\r\n96 66 8 18 30 48 34 11 37 42\r\n", "output": "299\r\n"}, {"input": "1\r\n87\r\n", "output": "0\r\n"}, {"input": "2\r\n93 51\r\n", "output...
false
stdio
null
true
366/C
366
C
Python 3
TESTS
6
997
12,288,000
38618353
[n,k] = [int(x) for x in input().split()] a = [int(x) for x in input().split()] w = [int(x) for x in input().split()] a.insert(0,0) w.insert(0,0) s = sum(w) q = 0 f = [[0 for y in range(0, s + 1)] for x in range(0, n + 1)] for j in range(1,s+1): f[0][j] = -999999 for i in range(1,n+1): f[i][0] = 0 for i in ran...
28
374
43,008,000
97593122
class Dict(dict): def __missing__(self, key): return float('-inf') n, k = map(int, input().split()) a = [0] + list(map(int, input().split())) b = [0] + list(map(int, input().split())) dp = [Dict() for _ in range(n+1)] dp[0][n*100] = 0 for i in range(1, n+1): s = a[i] - b[i]*k for j in range(n*200...
Codeforces Round 214 (Div. 2)
CF
2,013
1
256
Dima and Salad
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad...
The first line of the input contains two integers n, k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10). The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 100) — the fruits' calories. Fruit number i has taste ai and c...
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits.
null
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition $$\frac{18}{9}=2=k$$ fulfills, that's exactly what Inna wants. In the second test sample we cannot choose the fruits so as to follow Inna's p...
[{"input": "3 2\n10 8 1\n2 7 1", "output": "18"}, {"input": "5 3\n4 4 4 4 4\n2 2 2 2 2", "output": "-1"}]
1,900
["dp"]
28
[{"input": "3 2\r\n10 8 1\r\n2 7 1\r\n", "output": "18\r\n"}, {"input": "5 3\r\n4 4 4 4 4\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n2\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n75 65\r\n16 60\r\n", "output": "-1\r\n"}, {"input": "21 8\r\n50 39 28...
false
stdio
null
true
74/A
74
A
Python 3
TESTS
7
124
0
10519564
import sys import math n = int(input()) vmax = 0 res = "" for i in range(n): st = (sys.stdin.readline()).split() vsum = int(st[1]) * 100 - int(st[2]) * 50 + sum(map(int, st[3:])) if(vsum > vmax): vmax = vsum res = st[0] print(res)
32
92
0
159871240
n = int(input()) lst = {} mx = [] for _ in range(n): nick , plus , minus , a , b , c , d , e = map(str , input().split()) points = (int(a) + int(b) + int(c) + int(d) + int(e) + (int(plus)*100)) - (int(minus)*50) lst[points] = nick mx.append(points) print( lst[max(mx)] )
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
555/B
555
B
Python 3
TESTS
5
46
0
11835508
n, m = map(int, input().split()) ils_r = [] #расстояние между соседними мостами (i-1 и i) ils_len = [] # длина моста ils_last = 0 for i in range(n): l , r = map(int, input().split()) ils_r.append(l - ils_last - 1) ils_last = r ils_len.append(1 + r - l) brd = list(map(int, input().split())) ans = [0]*(n-1) for ...
50
2,168
104,038,400
173147708
import sys from heapq import heapify, heappop, heappush input = sys.stdin.readline def solve(): n, m = list(map(int, input().split())) intervals = [] for _ in range(n): l, r = list(map(int, input().split())) intervals.append([l, r]) bridges = list(map(int, input().split())) # birdge...
Codeforces Round 310 (Div. 1)
CF
2,015
3
256
Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: ...
The first line contains integers n (2 ≤ n ≤ 2·105) and m (1 ≤ m ≤ 2·105) — the number of islands and bridges. Next n lines each contain two integers li and ri (1 ≤ li ≤ ri ≤ 1018) — the coordinates of the island endpoints. The last line contains m integer numbers a1, a2, ..., am (1 ≤ ai ≤ 1018) — the lengths of the b...
If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print n - 1 numbers b1, b2, ..., bn - 1, which mean that between islands i and i + 1 ...
null
In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14. In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist.
[{"input": "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8", "output": "Yes\n2 3 1"}, {"input": "2 2\n11 14\n17 18\n2 9", "output": "No"}, {"input": "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999", "output": "Yes\n1"}]
2,000
["data structures", "greedy", "sortings"]
50
[{"input": "4 4\r\n1 4\r\n7 8\r\n9 10\r\n12 14\r\n4 5 3 8\r\n", "output": "Yes\r\n2 3 1 \r\n"}, {"input": "2 2\r\n11 14\r\n17 18\r\n2 9\r\n", "output": "No\r\n"}, {"input": "2 1\r\n1 1\r\n1000000000000000000 1000000000000000000\r\n999999999999999999\r\n", "output": "Yes\r\n1 \r\n"}, {"input": "5 10\r\n1 2\r\n3 3\r\n5 7...
false
stdio
null
true
555/B
555
B
Python 3
TESTS
5
61
0
11834231
n, m = map(int, input().split()) q = [] last = 0 db = [] for i in range(n): a, d = map(int, input().split()) q.append(a-last-1) last = d db.append(d-a+1) #print(q[1:]) m = len(q)-1 aans = [-1]*(len(q)-1) can = list(map(int, input().split())) for po in range(m): i = min(q[1:]) u = q[1:].index(min(q[1:])) ...
50
1,856
79,257,600
173055136
import sys # sys.setrecursionlimit(10**9) # import random # from collections import Counter, defaultdict, deque # from functools import lru_cache, reduce # from itertools import accumulate,product from heapq import nsmallest, nlargest, heapify, heappop, heappush # from bisect import bisect_left,bisect_right # from sort...
Codeforces Round 310 (Div. 1)
CF
2,015
3
256
Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: ...
The first line contains integers n (2 ≤ n ≤ 2·105) and m (1 ≤ m ≤ 2·105) — the number of islands and bridges. Next n lines each contain two integers li and ri (1 ≤ li ≤ ri ≤ 1018) — the coordinates of the island endpoints. The last line contains m integer numbers a1, a2, ..., am (1 ≤ ai ≤ 1018) — the lengths of the b...
If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print n - 1 numbers b1, b2, ..., bn - 1, which mean that between islands i and i + 1 ...
null
In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14. In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist.
[{"input": "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8", "output": "Yes\n2 3 1"}, {"input": "2 2\n11 14\n17 18\n2 9", "output": "No"}, {"input": "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999", "output": "Yes\n1"}]
2,000
["data structures", "greedy", "sortings"]
50
[{"input": "4 4\r\n1 4\r\n7 8\r\n9 10\r\n12 14\r\n4 5 3 8\r\n", "output": "Yes\r\n2 3 1 \r\n"}, {"input": "2 2\r\n11 14\r\n17 18\r\n2 9\r\n", "output": "No\r\n"}, {"input": "2 1\r\n1 1\r\n1000000000000000000 1000000000000000000\r\n999999999999999999\r\n", "output": "Yes\r\n1 \r\n"}, {"input": "5 10\r\n1 2\r\n3 3\r\n5 7...
false
stdio
null
true
74/A
74
A
PyPy 3-64
TESTS
7
122
0
198475815
t = int(input()) mx = 0 pos = 0 for el in range(t): name , plus , minus , a , b , c , d , e = input().split() plus = int(plus) minus = int(minus) a = int(a) b = int(b) c = int(c) d = int(d) e = int(e) res = (a + b + c + d + e) +(plus * 100) - (minus * 50) if(res > mx): ...
32
92
0
162471142
n=int(input()) contestants=[] for i in range(n): entrada=input().split() name=entrada[0] count=int(entrada[1])*100-int(entrada[2])*50+int(entrada[3])+int(entrada[4])+int(entrada[5])+int(entrada[6])+int(entrada[7]) contestants.append([count,name]) contestants.sort(key=lambda contestant:contestant[0]) pri...
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
281/A
281
A
Python 3
TESTS
6
62
0
226364907
a=input() a_split=a.split(' ') formatted_word=[] for i in range(len(a_split)): formatted_word.append(a_split[i].replace(a_split[i][0],a_split[i][0].capitalize())) print( ' '.join(formatted_word))
25
62
0
223824220
s = input() d = s[1 : len(s) : 1] b = s[0] c = b.upper() print(c,d,sep='')
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD...
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
230914537
word = input() if(ord(word[0])>=ord("A") and ord(word[0])<=ord("Z")): print(word) else: print(word.capitalize())
25
62
0
224032795
s = input() print(s[0].capitalize() + s[1:])
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD...
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
229197758
a=input(); b=a.replace(a[0],a[0].upper()); print(b)
25
62
0
224050347
word = list(input()) word[0] = word[0].upper() print(''.join(let for let in word))
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD...
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
230780178
st=input() if st[0].isupper(): print(st) else: s=st.replace(st[0],chr(ord(st[0])-32)) print(s)
25
62
0
224102036
string = input() s = string[0] s = s.upper() print(s + string[1:len(string)])
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD...
false
stdio
null
true
281/A
281
A
Python 3
TESTS
6
62
0
232093865
word = input() if len(word) <= 10**3: if word[0].islower(): word = word.capitalize() print(word) else: print(word) else: print("Word is to long!")
25
62
0
224129191
def cap(s): beta_s = s[0].upper() + s[1:] return beta_s s_1 = input() print(cap(s_1))
Codeforces Round 172 (Div. 2)
CF
2,013
2
256
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
null
null
[{"input": "ApPLe", "output": "ApPLe"}, {"input": "konjac", "output": "Konjac"}]
800
["implementation", "strings"]
25
[{"input": "ApPLe\r\n", "output": "ApPLe\r\n"}, {"input": "konjac\r\n", "output": "Konjac\r\n"}, {"input": "a\r\n", "output": "A\r\n"}, {"input": "A\r\n", "output": "A\r\n"}, {"input": "z\r\n", "output": "Z\r\n"}, {"input": "ABACABA\r\n", "output": "ABACABA\r\n"}, {"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnD...
false
stdio
null
true
366/B
366
B
Python 3
TESTS
34
124
13,721,600
130728595
from collections import defaultdict n, k = map(int, input().split()) tasks = list(map(int, input().split())) sums = defaultdict(int) for i in range(n): sums[i%k] += tasks[i] min_sum = 10 ** 7 min_in = 1 for key, s in sums.items(): if s < min_sum: min_sum = s min_in = key + 1 print(min_in)
36
77
13,414,400
216230121
def main(): n, k = map(int, input().split()) a = [0] * k l=list(map(int,input().split())) for i in range(n): a[i % k] += l[i] m = 0 for i in range(1, k): if a[i] < a[m]: m = i print(m + 1) if __name__ == "__main__": main()
Codeforces Round 214 (Div. 2)
CF
2,013
1
256
Dima and To-do List
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task. It is guaranteed that n is divisible by k.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
null
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If ...
[{"input": "6 2\n3 2 1 6 5 4", "output": "1"}, {"input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3"}]
1,200
["brute force", "implementation"]
36
[{"input": "6 2\r\n3 2 1 6 5 4\r\n", "output": "1\r\n"}, {"input": "10 5\r\n1 3 5 7 9 9 4 1 8 5\r\n", "output": "3\r\n"}, {"input": "20 4\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "10 10\r\n8 4 5 7 6 9 2 2 3 5\r\n", "output": "7\r\n"}, {"input": "50 10\r\n1 2 3 4 5 6 7 8 9 10 10 1 1...
false
stdio
null
true
843/A
843
A
PyPy 3
TESTS
5
280
9,728,000
105284698
import math,sys #from itertools import permutations, combinations;import heapq,random; from collections import defaultdict,deque import bisect as bi def yes():print('YES') def no():print('NO') #sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); def I():return (int(sys.stdin.readline())) def In():return(...
71
296
16,793,600
140984830
from sys import stdin from collections import defaultdict, deque answer = [] n = int(input()) a = list(map(int, input().split())) b = sorted(a) d = {x: i for i, x in enumerate(a)} # parent = list(range(n)) visited = [0] * n for i, x in enumerate(a): if visited[i]: continue seq = [i] visited[i] = 1 ...
AIM Tech Round 4 (Div. 1)
CF
2,017
1
256
Sorting by Subsequences
You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order. Sorting integers in a subsequence is...
The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence. The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.
In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements. In the next k lines print the description of subsequences in the following format: the number of elements in subsequence ci (0 < ci ≤ n), then ci integers l1, l2, ..., lci (1 ≤...
null
In the first sample output: After sorting the first subsequence we will get sequence 1 2 3 6 5 4. Sorting the second subsequence changes nothing. After sorting the third subsequence we will get sequence 1 2 3 4 5 6. Sorting the last subsequence changes nothing.
[{"input": "6\n3 2 1 6 5 4", "output": "4\n2 1 3\n1 2\n2 4 6\n1 5"}, {"input": "6\n83 -75 -49 11 37 62", "output": "1\n6 1 2 3 4 5 6"}]
1,400
["dfs and similar", "dsu", "implementation", "math", "sortings"]
71
[{"input": "6\r\n3 2 1 6 5 4\r\n", "output": "4\r\n2 1 3\r\n1 2\r\n2 4 6\r\n1 5\r\n"}, {"input": "6\r\n83 -75 -49 11 37 62\r\n", "output": "1\r\n6 1 2 3 4 5 6\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 1\r\n1 2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) sorted_a = sorted(a) pos_in_sorted = {v: i+1 f...
true
366/B
366
B
PyPy 3
TESTS
12
186
8,192,000
71748471
n,k=map(int,input().split()) li=list(map(int,input().split())) min1=100000 ans=1 for i in range(0,k): sum1=0 for j in range(i,n,k): sum1+=li[j] #print(sum1,i) if(sum1<min1): ans=i+1 min1=sum1 print(ans)
36
77
13,516,800
171457203
n,k=map(int,input().split()) arr=list(map(int,input().split())) ans=float("inf") res=-1 for i in range(k): j=i temp=0 c=n//k while c: j%=n temp+=arr[j] j+=k c-=1 if temp<ans: ans=temp res=i print(res+1)
Codeforces Round 214 (Div. 2)
CF
2,013
1
256
Dima and To-do List
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task. It is guaranteed that n is divisible by k.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
null
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If ...
[{"input": "6 2\n3 2 1 6 5 4", "output": "1"}, {"input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3"}]
1,200
["brute force", "implementation"]
36
[{"input": "6 2\r\n3 2 1 6 5 4\r\n", "output": "1\r\n"}, {"input": "10 5\r\n1 3 5 7 9 9 4 1 8 5\r\n", "output": "3\r\n"}, {"input": "20 4\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "10 10\r\n8 4 5 7 6 9 2 2 3 5\r\n", "output": "7\r\n"}, {"input": "50 10\r\n1 2 3 4 5 6 7 8 9 10 10 1 1...
false
stdio
null
true
366/B
366
B
Python 3
TESTS
5
93
5,939,200
148115047
def solve(): rems={} for i in range(k) : rems[i]=0 for i in range(n) : rems[i%k]+=arr[i] mn=1000 ans=0 for i in rems : if mn > rems[i] : mn=rems[i] ans=i+1 return ans from sys import stdin input = stdin.readline n,k=[int(x) fo...
36
93
6,348,800
142603882
n,k=map(int,input().split()) l=list(map(int,input().split())) r=100000000000 for i in range(n): if l[i]==0: break; j=i sum=0 while j<n: sum=sum+l[j] l[j]=0 j=j+k if(r>sum): idx=i r=sum print(idx+1)
Codeforces Round 214 (Div. 2)
CF
2,013
1
256
Dima and To-do List
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task. It is guaranteed that n is divisible by k.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
null
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If ...
[{"input": "6 2\n3 2 1 6 5 4", "output": "1"}, {"input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3"}]
1,200
["brute force", "implementation"]
36
[{"input": "6 2\r\n3 2 1 6 5 4\r\n", "output": "1\r\n"}, {"input": "10 5\r\n1 3 5 7 9 9 4 1 8 5\r\n", "output": "3\r\n"}, {"input": "20 4\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "10 10\r\n8 4 5 7 6 9 2 2 3 5\r\n", "output": "7\r\n"}, {"input": "50 10\r\n1 2 3 4 5 6 7 8 9 10 10 1 1...
false
stdio
null
true
366/B
366
B
Python 3
TESTS
5
124
6,041,600
77919047
n,m = input().split() n =int(n) m = int(m) arr = [int(x) for x in input().split()] min = 10000000 ans= -1; for i in range(m): sum=0 for j in range(i,n,m): sum=sum+arr[j] if sum<min: min=sum ans=i print(ans+1)
36
93
7,372,800
5233682
__author__ = 'Lipen' def actions(n, k, a): smin = -1 answer = 1 for i in range(k): s = sum(a[i::k]) if s<smin or smin==-1: smin=s answer=i+1 return answer def main(): n,k = list(map(int, input().split())) a = list(map(int, input().split())) print(actions(n, k ,a)) if __name__=='__main__': main()
Codeforces Round 214 (Div. 2)
CF
2,013
1
256
Dima and To-do List
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task. It is guaranteed that n is divisible by k.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
null
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If ...
[{"input": "6 2\n3 2 1 6 5 4", "output": "1"}, {"input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3"}]
1,200
["brute force", "implementation"]
36
[{"input": "6 2\r\n3 2 1 6 5 4\r\n", "output": "1\r\n"}, {"input": "10 5\r\n1 3 5 7 9 9 4 1 8 5\r\n", "output": "3\r\n"}, {"input": "20 4\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "10 10\r\n8 4 5 7 6 9 2 2 3 5\r\n", "output": "7\r\n"}, {"input": "50 10\r\n1 2 3 4 5 6 7 8 9 10 10 1 1...
false
stdio
null
true
774/L
774
L
Python 3
TESTS
2
46
4,608,000
26154351
n, k = map(int, input().split()) s = input() l, r = int(-1), int(n) while r - l > 1: m = (l+r)//2 c, p = 1, 0 cond = True while p < n and c < m: i = p + m + 1 while i >= p and (i >= n or s[i] == '1'): i = i - 1; if (i == p): cond = False break...
81
545
12,288,000
85818864
import sys from math import * from fractions import gcd from random import * # randint(inclusive,inclusive) readints=lambda:map(int, input().strip('\n').split()) from itertools import permutations, combinations s = "abcdefghijklmnopqrstuvwxyz" # print('', end=" ") # for i in {1..5}; do echo "hi"; done n,k=readints(...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Bars
Polycarp's workday lasts exactly $$$n$$$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $$$k$$$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he...
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 200\,000$$$, $$$2 \le k \le n$$$) — the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday. The second line contains the string with length $$$n$$$ consisting of zeros and ones. I...
Print the minimum possible break in minutes between eating chocolate bars.
null
In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute. In the second example Polycarp will eat bars in the minutes $$$1$$$ and $$$8$$$ anyway, also he needs to eat the chocolate bar in the minute $$$5$$$, so that the time of the maximum break wi...
[{"input": "3 3\n010", "output": "1"}, {"input": "8 3\n01010110", "output": "3"}]
2,000
["*special", "binary search"]
81
[{"input": "3 3\r\n010\r\n", "output": "1\r\n"}, {"input": "8 3\r\n01010110\r\n", "output": "3\r\n"}, {"input": "9 5\r\n001100110\r\n", "output": "2\r\n"}, {"input": "2 2\r\n00\r\n", "output": "0\r\n"}, {"input": "3 2\r\n010\r\n", "output": "1\r\n"}, {"input": "3 2\r\n000\r\n", "output": "1\r\n"}, {"input": "3 3\r\n000...
false
stdio
null
true