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
51/B
51
B
PyPy 3-64
TESTS
3
92
0
214317185
open_tag_count = -1 close_tag_count = -2 text = '' while open_tag_count != close_tag_count: text += input() open_tag_count = text.count('<table>') close_tag_count = text.count('</table>') result = [] cnt = 0 for element in text.split('<'): if element == 'table>' or element == '/table>': if c...
19
124
1,740,800
214326668
input_str = str(input()) while input_str.count("<table>") > input_str.count("</table>") or input_str.count("<table>") == 0: input_str += str(input()) split_list = list(map(str, input_str.split("<"))) result = [] stack = [] for i in range(1, len(split_list)): if split_list[i] == "table>": stack += [0...
Codeforces Beta Round 48
CF
2,010
2
256
bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML t...
For convenience, input data can be separated into non-empty lines in an arbitrary manner. The input data consist of no more than 10 lines. Combine (concatenate) all the input lines into one, to get a text representation s of the specified table. String s corresponds to the given grammar (the root element of grammar is ...
Print the sizes of all the tables in the non-decreasing order.
null
null
[{"input": "<table><tr><td></td></tr></table>", "output": "1"}, {"input": "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "output": "1 4"}, {"input": "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td>...
1,700
["expression parsing"]
19
[{"input": "<table><tr><td></td></tr></table>\r\n", "output": "1 "}, {"input": "<table>\r\n<tr>\r\n<td>\r\n<table><tr><td></td></tr><tr><td></\r\ntd\r\n></tr><tr\r\n><td></td></tr><tr><td></td></tr></table>\r\n</td>\r\n</tr>\r\n</table>\r\n", "output": "1 4 "}, {"input": "<table><tr><td>\r\n<table><tr><td>\r\n<table><t...
false
stdio
null
true
865/D
865
D
PyPy 3
TESTS
8
467
26,931,200
228870237
import heapq n = int(input()) prices = [int(i) for i in input().split()] #print(prices) sells = [-prices[-1]] bought = set() profit = 0 for i in range(len(prices) - 2,-1,-1): sell = -sells[0] buy = prices[i] if buy < sell: heapq.heappop(sells) profit += sell - buy bought.add(buy) if sell in bough...
29
280
33,792,000
203975181
import sys import heapq from collections import deque input = sys.stdin.readline def fgh(): return [int(xx) for xx in input().split()] def fg(): return int(input()) n = fg() a = fgh() ans = 0 h = [a[0]] for i in range(1, n): if h[0] < a[i]: ans += a[i] - heapq.heappop(h) heapq.heappush(h, a[...
MemSQL Start[c]UP 3.0 - Round 2 (onsite finalists)
CF
2,017
2
256
Buy Low Sell High
You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you...
Input begins with an integer N (2 ≤ N ≤ 3·105), the number of days. Following this is a line with exactly N integers p1, p2, ..., pN (1 ≤ pi ≤ 106). The price of one share of stock on the i-th day is given by pi.
Print the maximum amount of money you can end up with at the end of N days.
null
In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is - 5 - 4 + 9 + 12 - 2 + 10 = 20.
[{"input": "9\n10 5 4 7 9 12 6 2 10", "output": "20"}, {"input": "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4", "output": "41"}]
2,400
["constructive algorithms", "data structures", "greedy"]
29
[{"input": "9\r\n10 5 4 7 9 12 6 2 10\r\n", "output": "20\r\n"}, {"input": "20\r\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\r\n", "output": "41\r\n"}, {"input": "20\r\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19\r\n", "output": "147\r\n"}, {"input": "100\r\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 ...
false
stdio
null
true
724/D
724
D
Python 3
PRETESTS
4
62
4,608,000
21291011
if __name__ == '__main__': m = int(input()) s = str(input()) symbol_index = set() ans = [] for i in range(len(s) - m + 1): subseq = list(s[i:i + m]) lowest_letter = sorted(subseq)[0] new_index = subseq.index(lowest_letter) + i symbol_index.add(new_index) curre...
71
327
29,286,400
21293752
abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] m = int(input()) string = input() good = False toCheck = [] lenS = len(string) holes = [(-1, lenS)] have = {'s': 0, 'i': 0, 'y': 0, 'h': 0, 'r': 0, 'f': 0, 'd': 0, 'z': 0, 'q': 0, 't'...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
2
30
0
182723660
n, v = [int(i) for i in input().split()] x = [] for i in range(n): m = [int(i) for i in input().split()] for i in m[1:]: if v > i: x.append(m[0]) print(len(x)) print(*x)
26
46
0
137350227
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-29 22:52:48 LastEditTime: 2021-11-29 22:57:43 Description: Valera and Antique Items FilePath: CF441A.py ''' def func(): n, v = map(int, input().strip().split()) deal = [] for i in range(n): k, *s = map(int, input().strip().split(...
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
2
31
0
224256782
n, purse = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] res = [] for seller in arr: for j in range(1, len(seller)): if seller[j] < purse: if seller[0] not in res: res.append(seller[0]) break print(len(res)) if len(res) > 0: res.sort() print(*res)
26
46
0
137609281
def solve(n, v, arr): res = [] for j in range(n): for i in range(len(arr[j])-1): if arr[j][i+1] < v: res.append(str(j+1)) break return res, len(res) n, v = map(int, input().split()) arr = [] for i in range(n): temp = list(map(int, input().split())) ...
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
2
30
0
172499330
x,y = list(map(int , input().split())) l = [] for i in range(x): l.append(list(map(int , input().split()))) conter =0 sellers =[] for i in l: for j in i: if j<1000: continue elif j<y: conter +=1 sellers.append(i[0]) break print(conter) if len(sel...
26
46
0
140583065
s = input().split() (n,v) = (int(i) for i in s) res = [] cs = 0 for i in range(n): s = input().split() s = [int(j) for j in s] for j in range(1,s[0]+1): if(s[j] < v): cs += 1 res.append(i+1) break print(cs) for i in range(cs): print(res[i],end = ' ')
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
4
46
0
27624335
n,v = input().split() n,v = int(n),int(v) A = [] for i in range(0,n): C = [] a = input() for j in a.split(): C.append(int(j)) d = C[0] del C[0] C.sort() if v >C[0]: A.append(d) A= list(set(A)) A.sort() s = '' for k in A: s = s+str(k)+' ' if n == 50 and v == 100000: pr...
26
46
0
140739875
NUMBER_OR_SELLERS, VALERA_BUDGET = [int(x) for x in str(input()).split()] result = {} for i in range(NUMBER_OR_SELLERS): input_items = input().split() for x in input_items[1:]: if int(x) < VALERA_BUDGET: result[i + 1] = 1 print(len(result)) for i in result: print(i, end=" ")
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
2
30
0
166763385
n,v=list(map(int,input().split())) f=[] for pratyush in range(n): a=list(map(int,input().split())) x=a[1:] x.sort() if x[0]<v: f.append(a[0]) f.sort() print(len(f)) print(*f)
26
46
0
141232799
x,y=map(int,input().split()) s=0 list=[] for i in range(1,x+1): z=[int(k) for k in input().split()] for j in range(1,len(z),1): if (z[j]<y): s=s+1 list.append(i) break print(s) for i in list: print(i)
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
3
31
0
186336283
n, v = [int(i) for i in input().split()] x = [] if n == 50 and v == 100000: print(18) print("2 7 10 12 14 15 17 18 21 22 26 27 29 30 31 32 45 48") exit() for i in range(n): m = [int(i) for i in input().split()] for j in m[1:]: if v > j: ...
26
46
0
146016264
n,v=[int(x) for x in input().split()] count=0 ans=[] for i in range(n): price=[int(x) for x in input().split()] for j in range(1,price[0]+1): if price[j]<v: count+=1 ans.append(i+1) break print(count) for i in ans: print(i,end=" ")
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
441/A
441
A
Python 3
TESTS
2
30
0
224259046
n, m = map(int, input().split()) data = {} for _ in range(n): s = list(map(int, input().split())) data[s[0]] = s[1:] count = 0 result = [] for i in data: for j in data[i]: if m > j: count += 1 if i not in result: result.append(i) print(count) result.sort() ...
26
46
0
147678089
n, v = map(int, input().split()) count = 0 slist = [] for i in range(n): _, *l = map(int, input().split()) for j in l: if v > j: slist.append(i+1) count += 1 break print(count) for x in slist: print(x, end=' ')
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if h...
The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki...
In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
null
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
[{"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3"}, {"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0"}]
1,000
["implementation"]
26
[{"input": "3 50000\r\n1 40000\r\n2 20000 60000\r\n3 10000 70000 190000\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "3 50000\r\n1 50000\r\n3 100000 120000 110000\r\n3 120000 110000 120000\r\n", "output": "0\r\n\r\n"}, {"input": "2 100001\r\n1 895737\r\n1 541571\r\n", "output": "0\r\n\r\n"}, {"input": "1 1000000\r\n1 1...
false
stdio
null
true
149/D
149
D
PyPy 3-64
TESTS
5
154
0
203626521
import sys input = lambda: sys.stdin.readline().strip() arr = list(input()) n = len(arr) MOD = 1000000007 # lc * 3 + rc, 0 no 1 red 2 blue color = [4, 3, 3, 3, 2, 2, 3, 2, 2] # left pos, right pos, left color, right color def dp(l, r, lc, rc): if l == r - 1: return color[lc * 3 + rc] if match[l] == r: ...
38
310
4,300,800
203629614
Mod = 10 ** 9 + 7 s = input() n = len(s) from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: ...
Codeforces Round 106 (Div. 2)
CF
2,012
2
256
Coloring Brackets
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
The first line contains the single string s (2 ≤ |s| ≤ 700) which represents a correct bracket sequence.
Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109 + 7).
null
Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below. The two ways of coloring shown below are incorrect.
[{"input": "(())", "output": "12"}, {"input": "(()())", "output": "40"}, {"input": "()", "output": "4"}]
1,900
["dp"]
38
[{"input": "(())\r\n", "output": "12\r\n"}, {"input": "(()())\r\n", "output": "40\r\n"}, {"input": "()\r\n", "output": "4\r\n"}, {"input": "((()))\r\n", "output": "36\r\n"}, {"input": "()(())\r\n", "output": "42\r\n"}, {"input": "()()()\r\n", "output": "48\r\n"}, {"input": "(())(())\r\n", "output": "126\r\n"}, {"input"...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
280
7,065,600
32104701
n=int(input()) s=input() l=s.split() p=0 verif=True l=[int(l[i]) for i in range(len(l))] for i in range (len(l)): if (i==l[i]): p=p+1 elif((l[l[i]]==i)and (verif==True)): verif=False p=p+2 if (verif==True): p=p+1 print(p)
19
156
6,963,200
148057708
n = int(input()) l = list(map(int,input().split())) counter = 0 x1 = 0 x2 = 0 for i in range(len(l)): if l[i] == i: counter+=1 else: if i == l[l[i]]: x1 = 2 if x1 == 0: for j in range(len(l)): if j!=l[j] and j in l: x1 = 1 break print(counter+x1+x...
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
248
6,758,400
32083775
n=int(input()) tab=list(map(int,input().split(" "))) b=False cnt=0 for i in range(n): if (tab[i]==i): cnt+=1 elif (tab[tab[i]]==i): b=True if (b): print(cnt+2) else: print(cnt+1)
19
156
13,004,800
164476786
def fixed_points(): list_length = int(input()) points = list(map(int, input().split(" "))) fix_points = 0 swaps = True for i in range(list_length): if points[i] == i: fix_points += 1 elif swaps is True and points[points[i]] == i: swaps = False fix_...
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
2/A
2
A
Python 3
TESTS
13
62
0
147959585
n=int(input()) a={} s='' scor=int(0) max=-1001 maxs='' if n==600 : for _ in range(10) : for _ in range(60) : s,scor=input().split() print(s,scor,end=' ') print('|') else: for i in range(n) : s,scor=input().split() scor=int(scor) if not(s in a) : ...
20
62
0
158343764
''' ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╬╬ ▓▓ ▓▓ ╬╬ ╬╬ ▓▓ ▓▓ ╬╬ ╬╬ ▓▓█████▓▓ ╬╬ ╬╬ ▓▓ ▓▓ ╬╬ ╬╬ ▓▓ ▓▓ ╬╬ ╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ########################### // •︿• \\ /\\ //\ /\\ //\ /\\//\ ########################### ''' import sys input =...
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
981/C
981
C
Python 3
PRETESTS
4
514
10,035,200
38668479
n=int(input()) g=[[] for i in range(n)] for i in range(n-1): v,u=list(map(int,input().split())) g[v-1].append(u) g[u-1].append(v) t=True t1=False raiz=-1 for i in range(n): if len(g[i])>2: if len(g[i])==n-1: t1=True raiz=i+1 else: t=False b...
47
421
11,059,200
38703825
import sys n = int(sys.stdin.readline()) degree = [0 for i in range(n + 1)] for i in range(n - 1): u, v = map(int, sys.stdin.readline().split()) degree[u]+=1 degree[v]+=1 ok = sum([int(degree[u] > 2) for u in range(n + 1)]) < 2 if not ok: print('No') sys.exit() print('Yes') maxdeg = max(degree) center = degree.ind...
Avito Code Challenge 2018
CF
2,018
1
256
Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$. Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$...
null
The tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. The tree from the second example is shown on the picture below: We can show that there are no valid...
[{"input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4"}, {"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No"}, {"input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"}]
1,400
["implementation", "trees"]
47
[{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "Yes\r\n1\r\n1 4\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "Yes\r\n4\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "Yes\r\n1\r\n1 2\r\n"}, {"input"...
false
stdio
import sys from sys import stdin from collections import deque def main(input_path, output_path, submission_path): # Read input tree with open(input_path) as f: n = int(f.readline()) adj = [[] for _ in range(n+1)] edges = set() for _ in range(n-1): a, b = map(int, f....
true
981/C
981
C
PyPy 3
TESTS
4
935
19,148,800
71829990
n = int(input()) ab = [tuple(map(int, input().split())) for _ in range(n-1)] deg = [0]*n for a, b in ab: deg[a-1] += 1 deg[b-1] += 1 ideg = [(i, deg[i]) for i in range(n)] ideg.sort(key=lambda k: k[1]) deg2 = [ideg[i][1] for i in range(n)] if deg2==[1]*2+[2]*(n-2): print('Yes') print(1) print(ide...
47
436
37,785,600
160404380
from sys import stdin input=stdin.readline read=lambda :map(int,input().strip().split()) from collections import defaultdict n=int(input()) deg=[0]*n g=defaultdict(list) for i in range(n-1): x,y=read() x-=1 y-=1 deg[x]+=1 deg[y]+=1 g[x].append(y) g[y].append(x) c=0 res=0 for i in range(n):...
Avito Code Challenge 2018
CF
2,018
1
256
Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$. Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$...
null
The tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. The tree from the second example is shown on the picture below: We can show that there are no valid...
[{"input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4"}, {"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No"}, {"input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"}]
1,400
["implementation", "trees"]
47
[{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "Yes\r\n1\r\n1 4\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "Yes\r\n4\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "Yes\r\n1\r\n1 2\r\n"}, {"input"...
false
stdio
import sys from sys import stdin from collections import deque def main(input_path, output_path, submission_path): # Read input tree with open(input_path) as f: n = int(f.readline()) adj = [[] for _ in range(n+1)] edges = set() for _ in range(n-1): a, b = map(int, f....
true
981/C
981
C
PyPy 3
PRETESTS
6
904
8,806,400
38664303
if __name__ == "__main__": n = int(input()) deg = [0] * (n+1) for i in range(n-1): x, y = map(int, input().split()) deg[x] += 1 deg[y] += 1 if len(list(filter(lambda x : x > 2, deg))) > 1: print("No") else: print("Yes") d1 = [i for i in range(1, n+1)...
47
436
76,083,200
93736668
# Author: S Mahesh Raju # Username: maheshraju2020 # Created on: 25/09/2020 03:49:27 from sys import stdin, stdout, setrecursionlimit import heapq from math import gcd, ceil, sqrt from collections import Counter, deque from bisect import bisect_left, bisect_right from itertools import combinations, permutations ii1 = ...
Avito Code Challenge 2018
CF
2,018
1
256
Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$. Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$...
null
The tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. The tree from the second example is shown on the picture below: We can show that there are no valid...
[{"input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4"}, {"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No"}, {"input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"}]
1,400
["implementation", "trees"]
47
[{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "Yes\r\n1\r\n1 4\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "Yes\r\n4\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "Yes\r\n1\r\n1 2\r\n"}, {"input"...
false
stdio
import sys from sys import stdin from collections import deque def main(input_path, output_path, submission_path): # Read input tree with open(input_path) as f: n = int(f.readline()) adj = [[] for _ in range(n+1)] edges = set() for _ in range(n-1): a, b = map(int, f....
true
347/B
347
B
Python 3
TESTS
10
278
14,438,400
116116269
n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n): if a[i] == i: count += 1 for i in range(0,n): val = a[i] if a[val] == i and val != i: print(count + 2) exit() print(count+1)
19
156
13,516,800
169341636
n = int(input()) values = list(map(int, input().split())) ans = 0 to_add = 0 for x in range(n): if values[x] == x: ans += 1 elif to_add == 2: continue else: if values[values[x]] == x: to_add = 2 else: to_add = 1 print(ans + to_add)
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
248
7,065,600
4544469
n = int(input()) a = list(map(int, input().split())) c = 0 for i in range(n): if a[i] == i: c += 1 for i in range(n): if a[i] != i and a[a[i]] == i: c += 2 break else: c += 1 print(c)
19
156
13,516,800
195629894
input() a=list(map(int,input().split())) b=0 c=0 for i in a: if a[i]==i:b+=1 elif a[a[i]]==i:c+=1 print(b+2 if c else min(b+1,len(a)))
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
248
12,800,000
26415447
'''input 100 99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67 ''' n = int(input...
19
186
6,963,200
147915955
n=int(input()) c=0 t=0 a=list(map(int,input().split())) for i in range(n): if a[i]==i: c+=1 elif i==a[a[i]]: t=1 print(c+t+int(c!=n))
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
310
9,932,800
109827339
n = int(input()) arr = list(map(int, input().split())) d = {} ans = 0 flag = False for i,x in enumerate(arr): d[i] = x if i == x: ans += 1 for i in d: if i != d[i] and d[d[i]] == i: ans += 2 flag = True break if flag: print(ans) else: print(ans + 1)
19
186
6,963,200
149253802
z = int(input()) out, swap = 0, [1] n = list(map(int, input().split())) for i in range(z): if i == n[i]: out += 1 elif n[n[i]] == i and n[i] == n.index(i): swap.append(2) print(out + max(swap) if z-out >= 2 else out)
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
347/B
347
B
Python 3
TESTS
10
248
16,486,400
128978744
n=int(input()) a=list(map(int, input().split())) d=dict() c=0 for i in range(n): if i==a[i]: c+=1 else: d[i]=a[i] for i in d: if d[d[i]]==i: print(c+2) exit(0) print(c+1)
19
186
6,963,200
197559185
n=int(input()) arr=list(map(int,input().split())) f=True a=1 c=0 for i in range(len(arr)): if arr[i]==i: c+=1 elif f and arr[arr[i]]==i: f=False a=2 if c==n: print(c) else: print(c+a)
Codeforces Round 201 (Div. 2)
CF
2,013
2
256
Fixed Points
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation c...
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
null
null
[{"input": "5\n0 1 3 4 2", "output": "3"}]
1,100
["brute force", "implementation", "math"]
19
[{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18...
false
stdio
null
true
981/C
981
C
Python 3
TESTS
4
436
31,846,400
127043044
# _ ##################################################################################################################### def main(): nNodes = int(input()) neighborsOf = {node: [] for node in map(str, range(1, nNodes+1))} threeNeighborNodeExists, threeNeighborNode = False, None for i in range(1, nNodes...
47
467
2,048,000
132434813
def solve(): n = int(input()) deg = [0] * n for i in range(n - 1): u, v = map(int, input().split()) deg[u - 1] += 1 deg[v - 1] += 1 count = 0 root = 0 leaves = [] for i in range(n): if (deg[i] > 2): count += 1 root = i if (deg[i...
Avito Code Challenge 2018
CF
2,018
1
256
Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$. Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$...
null
The tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. The tree from the second example is shown on the picture below: We can show that there are no valid...
[{"input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4"}, {"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No"}, {"input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"}]
1,400
["implementation", "trees"]
47
[{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "Yes\r\n1\r\n1 4\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "Yes\r\n4\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "Yes\r\n1\r\n1 2\r\n"}, {"input"...
false
stdio
import sys from sys import stdin from collections import deque def main(input_path, output_path, submission_path): # Read input tree with open(input_path) as f: n = int(f.readline()) adj = [[] for _ in range(n+1)] edges = set() for _ in range(n-1): a, b = map(int, f....
true
509/C
509
C
PyPy 3
TESTS
3
109
0
120328026
def mk_minlen(l, x): digs = [1] + [0]*(l-1) x_digsum = 1 p = len(digs)-1 while x_digsum < x: while digs[p] == 9: p -= 1 digs[p] += 1 x_digsum += 1 return int(''.join(map(str, digs))) def solve(lo, x): s = str(lo) if x/9 > len(s): l = len(s) while x/9...
21
93
5,427,200
153762868
import sys def get_max(su, le): div, mod = divmod(su, 9) ret = ['9'] * div if mod: ret = [str(mod)] + ret if le - len(ret) > 0: x = str(int(ret.pop(0)) - 1) ret = ['1', x] + ret if le - len(ret) > 0: ret = [ret[0]] + ['0'] * (le - len(ret)) + ret[1:] ...
Codeforces Round 289 (Div. 2, ACM ICPC Rules)
ICPC
2,015
2
256
Sums of Digits
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possibl...
The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn  — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers witho...
null
null
[{"input": "3\n1\n2\n3", "output": "1\n2\n3"}, {"input": "3\n3\n2\n1", "output": "3\n11\n100"}]
2,000
["dp", "greedy", "implementation"]
21
[{"input": "3\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "3\r\n3\r\n2\r\n1\r\n", "output": "3\r\n11\r\n100\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n1\r\n", "output": "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n"}, {"input": "10\r\n8\r\n8\r\n5\r\n1\r\n2\r\n7\r\n3\r\n...
false
stdio
null
true
981/C
981
C
PyPy 3
TESTS
4
498
18,636,800
78371185
from collections import * import math from sys import * inp=stdin.readline str=str flag=1 if not flag: out=stdout.write else: out=print def linp(x): return list(map(int,x.split())) def minp(x): return map(int,x.split()) n=int(inp()) graph=defaultdict(list) while n-1>0: a,b=minp(inp()) ...
47
483
6,656,000
164651742
d = {} n = int(input()) for _ in range(n-1): a, b = map(int, input().split()) d[a] = d.get(a, 0) + 1 d[b] = d.get(b, 0) + 1 zz = list(filter(lambda x: d[x] > 2, d)) z = len(zz) y = list(filter(lambda x: d[x] == 1, d)) if z > 1: print("No") elif z == 0: print("Yes") print(1) print(*y)...
Avito Code Challenge 2018
CF
2,018
1
256
Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$. Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$...
null
The tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. The tree from the second example is shown on the picture below: We can show that there are no valid...
[{"input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4"}, {"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No"}, {"input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"}]
1,400
["implementation", "trees"]
47
[{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "Yes\r\n1\r\n1 4\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n3 4\r\n2 5\r\n3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n", "output": "Yes\r\n4\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "Yes\r\n1\r\n1 2\r\n"}, {"input"...
false
stdio
import sys from sys import stdin from collections import deque def main(input_path, output_path, submission_path): # Read input tree with open(input_path) as f: n = int(f.readline()) adj = [[] for _ in range(n+1)] edges = set() for _ in range(n-1): a, b = map(int, f....
true
560/A
560
A
Python 3
TESTS
3
46
6,656,000
126622318
def get_unfortunate(notes): for note in notes: if int(note) == 1: return -1 return 1 if __name__ == "__main__": n = input() notes = input() notes = notes.replace(' ', "") print(get_unfortunate(notes))
16
31
0
165441045
num_inp=lambda: int(input()) arr_inp=lambda: list(map(int,input().split())) sp_inp=lambda: map(int,input().split()) input() print(('1' in input().split())*-2+1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
124
6,758,400
126467827
alcohols = 'ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE' ans= 0 for i in range(int(input())): a = input() if(a in alcohols): ans+=1 elif(48<=ord(a[0])<=57): if(int(a)<18): ans+=1 print(ans)
28
46
307,200
4927607
def readln(): return tuple(map(int, input().split())) lst = 'ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE'.split(', ') n, = readln() ans = 0 for _ in range(n): inp = input() try: if int(inp) < 18: ans += 1 except: if inp in lst: an...
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
560/A
560
A
Python 3
TESTS
3
46
6,656,000
125110840
input() print(-1 if '1'in input().strip()else 1)
16
31
0
172437733
input();print(-1 if "1" in [i for i in input().split()] else 1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
175/B
175
B
PyPy 3-64
TESTS
23
156
5,324,800
189917101
n=int(input()) dicti={} cost={} for i in range(n): n,m=map(str,input().split()) dicti[n]=max(int(m),dicti.get(n,0)) cost[int(m)]=cost.get(int(m),0)+1 cost=dict(sorted(cost.items(),reverse=True)) sumi=0 out=0 for i in cost: sumi=(out/len(dicti))*100 out=out+cost[i] if sumi>50: cost[i]="no...
46
124
512,000
29810660
from collections import defaultdict from bisect import bisect_left p, n = defaultdict(int), int(input()) for i in range(n): a, b = input().split() p[a] = max(p[a], int(b)) p, n = sorted((b, a) for a, b in p.items()), len(p) t = [0] + [bisect_left(p, (p[n - 1 - n // k][0], '')) for k in [2, 5, 10, 100]] + [n] s ...
Codeforces Round 115
CF
2,012
2
256
Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has...
The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T...
Print on the first line the number m — the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th...
null
In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes...
[{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}]
1,400
["implementation"]
78
[{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) players = {} for _ in range(n): name, points = f.readline().strip().split() points = int(points) if name not in players ...
true
559/C
559
C
PyPy 3-64
TESTS
3
61
6,348,800
199045173
import bisect import heapq import sys from types import GeneratorType from functools import cmp_to_key from collections import defaultdict, Counter, deque import math from functools import lru_cache from heapq import nlargest from functools import reduce import random from itertools import combinations from itertools i...
55
264
9,420,800
194862736
# The idea is to compute dp[i], the number of paths from top left to ith point. # Here, the first and last point = top left and bottom right respectively # To compute dp[i], we use complementary counting to remove paths that are invalid. # The idea is that each invalid path has a "last" black cell j that they go throug...
Codeforces Round 313 (Div. 1)
CF
2,015
2
256
Gerald and Giant Chess
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of gia...
The first line of the input contains three integers: h, w, n — the sides of the board and the number of black cells (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000). Next n lines contain the description of black cells. The i-th of these lines contains numbers ri, ci (1 ≤ ri ≤ h, 1 ≤ ci ≤ w) — the number of the row and column of the i-t...
Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109 + 7.
null
null
[{"input": "3 4 2\n2 2\n2 3", "output": "2"}, {"input": "100 100 3\n15 16\n16 15\n99 88", "output": "545732279"}]
2,200
["combinatorics", "dp", "math", "number theory"]
55
[{"input": "3 4 2\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "100 100 3\r\n15 16\r\n16 15\r\n99 88\r\n", "output": "545732279\r\n"}, {"input": "1000 1000 4\r\n50 50\r\n51 50\r\n50 51\r\n51 51\r\n", "output": "899660737\r\n"}, {"input": "100000 100000 4\r\n50001 50001\r\n50000 50000\r\n50000 50001\r\n50001 50000\...
false
stdio
null
true
68/B
68
B
Python 3
TESTS
3
92
6,963,200
122348646
nk = list(input().split()) n, k = int(nk[0]), float(nk[1]) energy = list(map(float, input().split())) avg = sum(energy)/len(energy) sum_lf = 0 sum_rg = 0 cnt_lf = 0 cnt_rg = 0 for i in range(n): if(energy[i]<avg): cnt_lf+=1 sum_lf+=energy[i] else: cnt_rg+=1 sum_rg+=energy[i] x = ...
42
124
2,969,600
210677123
import sys input = lambda: sys.stdin.readline().rstrip() N,K = map(int, input().split()) A = list(map(int, input().split())) def check(m): sums,t=0,0 for a in A: if a>m: sums+=m t += (a-m)*(100-K)/100 else: sums+=a if sums+t>=m*N: return True ...
Codeforces Beta Round 62
CF
2,011
2
256
Energy exchange
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers. Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy. The absolute or relative error in the answer should not exceed 10 - 6.
null
null
[{"input": "3 50\n4 2 1", "output": "2.000000000"}, {"input": "2 90\n1 11", "output": "1.909090909"}]
1,600
["binary search"]
42
[{"input": "3 50\r\n4 2 1\r\n", "output": "2.000000000\r\n"}, {"input": "2 90\r\n1 11\r\n", "output": "1.909090909\r\n"}, {"input": "5 26\r\n42 65 23 43 64\r\n", "output": "45.415178571\r\n"}, {"input": "5 45\r\n964 515 454 623 594\r\n", "output": "594.109756098\r\n"}, {"input": "1 20\r\n784\r\n", "output": "784.000000...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read reference output with open(output_path, 'r') as f: ref_line = f.readline().strip() try: E_ref = float(ref_line) except: print(0) ...
true
152/B
152
B
Python 3
TESTS
6
156
0
121684589
n,m=map(int, input().split()) xc,yc=map(int, input().split()) ans,n1=0,int(input()) for _ in range(n1): dx,dy=map(int,input().split()) if dx>0: sx=(n-xc)//dx elif dx<0: sx=(xc-1)//(-dx) else: sx=n if dy>0: sy=(m-yc)//dy elif dy<0: sy=(yc-1)//(-dy) ...
34
92
0
218476865
n,m=map(int,input().split()) x,y=map(int,input().split()) k=int(input()) c=0 for i in range(k): s,d=map(int,input().split()) a=n+m if s>0: a=min(a, (n-x) // s) if s<0: a=min(a, (x-1) // -s) if d>0: a=min(a, (m-y) // d) if d<0: a=min(a, (y-1) // -d) c+=a x+...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
152/B
152
B
Python 3
TESTS
6
154
0
121683922
n,m=map(int,input().split()) xc,yc=map(int,input().split()) n1=int(input()) ans=0 for i in range(n1): dx,dy=map(int,input().split()) if dy>0: sty=(m-yc)//dy elif dy<0: sty=-(yc-1)//dy else: sty=m if dx>0: stx=(n-xc)//dx elif dx<0: stx=-(xc-1)//dx else:...
34
122
0
221482780
n, m = map(int, input().split()) xc, yc = map(int, input().split()) k = int(input()) total_steps = 0 # Initialize the total number of steps to zero for _ in range(k): dx, dy = map(int, input().split()) # Calculate the maximum number of valid steps in the current direction if dx > 0: max_step...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
560/A
560
A
Python 3
PRETESTS
3
46
0
12175946
# zadacha A n = int(input()) A = list(map(int, input().split())) if 1 in A: print("-1") else: minn = min(A) print(minn-1)
16
31
0
177224195
n = int(input()) checker = False a = list(map(int, input().split())) for i in range(len(a)): if a[i] == 1: checker = True break if checker: print(-1) else: print(1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
62/D
62
D
Python 3
TESTS
4
62
0
139384995
def find_index(path, elem, index): indexes = [] for i in range(len(path)): if path[i] == elem: if index != i and i + 1 != len(path): indexes.append(i) return indexes def build_home_path(n: int, m: int, old_path: list) -> list: """ Parameters: :n (int): numb...
30
124
819,200
187019306
n,m = map(int,input().split()) m+=1 p = list(map(lambda x:int(x)-1,input().split())) a = [0]*m q = [[False]*n for i in range(n)] d = [[] for i in range(n)] for i in range(1,m): d[p[i]].append(p[i-1]) d[p[i-1]].append(p[i]) for i in range(n): d[i].sort() s = [(p[0],True,p[0])] l = 0 while s: v,f,vv = s[-...
Codeforces Beta Round 58
CF
2,011
2
256
Wormhouse
Arnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the rooms from 1 to n. All the corridors are bidirectional. Arnie wants the new house to look just like the previous one....
The first line contains two integers n and m (3 ≤ n ≤ 100, 3 ≤ m ≤ 2000). It is the number of rooms and corridors in Arnie's house correspondingly. The next line contains m + 1 positive integers that do not exceed n. They are the description of Arnie's old path represented as a list of rooms he visited during the gnawi...
Print m + 1 positive integers that do not exceed n. Those numbers are the description of the new path, according to which Arnie should gnaw out his new house. If it is impossible to find new path you should print out No solution. The first number in your answer should be equal to the last one. Also it should be equal t...
null
null
[{"input": "3 3\n1 2 3 1", "output": "1 3 2 1"}, {"input": "3 3\n1 3 2 1", "output": "No solution"}]
2,300
["dfs and similar", "graphs"]
30
[{"input": "3 3\r\n1 2 3 1\r\n", "output": "1 3 2 1 "}, {"input": "3 3\r\n1 3 2 1\r\n", "output": "No solution"}, {"input": "4 4\r\n1 2 4 3 1\r\n", "output": "1 3 4 2 1 "}, {"input": "6 7\r\n3 2 4 1 6 5 1 3\r\n", "output": "No solution"}, {"input": "8 12\r\n4 6 5 1 4 3 1 8 3 7 8 5 4\r\n", "output": "4 6 5 1 4 3 1 8 7 3...
false
stdio
null
true
32/A
32
A
Python 3
TESTS
7
342
0
206847583
a, b = map(int, input().split()) c = list(map(int, input().split())) ans = 0 for i in c: for h in c: if i - h <= b and i - h > 0: ans += 2 for i in c: if c.count(i) >= 2: ans += 1 print(ans)
32
92
0
171048055
n,d = list(map(int, input().split())) lst = list(map(int, input().split())) cnt=0 i=0 j=1 lst.sort() while j<n: if lst[j]-lst[i]<=d: cnt+= (j-i) j+=1 else: i+=1 print(cnt*2)
Codeforces Beta Round 32 (Div. 2, Codeforces format)
CF
2,010
2
256
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
null
null
[{"input": "5 10\n10 20 50 60 65", "output": "6"}, {"input": "5 1\n55 30 29 31 55", "output": "6"}]
800
["brute force"]
32
[{"input": "5 10\r\n10 20 50 60 65\r\n", "output": "6\r\n"}, {"input": "5 1\r\n55 30 29 31 55\r\n", "output": "6\r\n"}, {"input": "6 10\r\n4 6 4 1 9 3\r\n", "output": "30\r\n"}, {"input": "7 100\r\n19 1694 261 162 1 234 513\r\n", "output": "8\r\n"}, {"input": "8 42\r\n37 53 74 187 568 22 5 65\r\n", "output": "20\r\n"},...
false
stdio
null
true
32/A
32
A
Python 3
TESTS
7
1,028
0
137970340
n,d = map(eval,input().split()) list_1 = list(map(eval,input().split())) N = 0 m = 0 for i in range(len(list_1)): if list_1.count(list_1[i]) == 2: N += 1 elif list_1.count(list_1[i]) > 2: m = list_1.count(list_1[i]) for j in range(len(list_1)): if list_1[i] != list_1[j] and abs(list_...
32
92
0
173010593
n, d = (int(i) for i in input().split()) a = sorted(int(i) for i in input().split()) res = 0 for i in range(n): lo, hi = i + 1, n while lo < hi: mi = lo + (hi - lo) // 2 if a[mi] - a[i] > d: hi = mi else: lo = mi + 1 res += 2 * (lo - i - 1) print(res)
Codeforces Beta Round 32 (Div. 2, Codeforces format)
CF
2,010
2
256
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
null
null
[{"input": "5 10\n10 20 50 60 65", "output": "6"}, {"input": "5 1\n55 30 29 31 55", "output": "6"}]
800
["brute force"]
32
[{"input": "5 10\r\n10 20 50 60 65\r\n", "output": "6\r\n"}, {"input": "5 1\r\n55 30 29 31 55\r\n", "output": "6\r\n"}, {"input": "6 10\r\n4 6 4 1 9 3\r\n", "output": "30\r\n"}, {"input": "7 100\r\n19 1694 261 162 1 234 513\r\n", "output": "8\r\n"}, {"input": "8 42\r\n37 53 74 187 568 22 5 65\r\n", "output": "20\r\n"},...
false
stdio
null
true
32/A
32
A
Python 3
TESTS
7
1,028
0
137968080
n,d = map(eval,input().split()) list_1 = list(map(eval,input().split())) N = 0 for i in range(len(list_1)): if list_1.count(list_1[i]) > 1: N += 1 for j in range(len(list_1)): if list_1[i] != list_1[j] and abs(list_1[i]-list_1[j])<=d: N += 1 print(N)
32
122
0
142411592
str1 = str(input()) n = int(str1.split(' ')[0]) d = int(str1.split(' ')[1]) str2 = str(input()) lis = [int(i) for i in str2.split(' ')] lis.sort() pair = 0 left = 0 right = 1 while right < n: if lis[right] - lis[left] <= d: pair += 2 * (right - left) else: while lis[right] - lis[left] > d and right != ...
Codeforces Beta Round 32 (Div. 2, Codeforces format)
CF
2,010
2
256
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
null
null
[{"input": "5 10\n10 20 50 60 65", "output": "6"}, {"input": "5 1\n55 30 29 31 55", "output": "6"}]
800
["brute force"]
32
[{"input": "5 10\r\n10 20 50 60 65\r\n", "output": "6\r\n"}, {"input": "5 1\r\n55 30 29 31 55\r\n", "output": "6\r\n"}, {"input": "6 10\r\n4 6 4 1 9 3\r\n", "output": "30\r\n"}, {"input": "7 100\r\n19 1694 261 162 1 234 513\r\n", "output": "8\r\n"}, {"input": "8 42\r\n37 53 74 187 568 22 5 65\r\n", "output": "20\r\n"},...
false
stdio
null
true
152/B
152
B
PyPy 3
TESTS
6
622
28,569,600
115397102
n, m = map(int, input().split()) xc, yc = map(int, input().split()) k = int(input()) steps = 0 for i in range(k): steps1, step2, ans = 0, 0, 0 dx, dy = map(int, input().split()) lo, hi = 0, n while lo <= hi: mid = lo + (hi - lo) // 2 if mid*dx + xc >= 1 and mid*dx + xc <= n: lo = mid + 1 steps1 = mid ...
34
124
0
209279034
n, m = map(int, input().split()) x, y = map(int, input().split()) k = int(input()) ans = 0 for _ in range(k): dx, dy = map(int, input().split()) if 0 < dx+x <= n and 0 < dy+y <= m: if dx >= 0: a = abs((n-x)//dx) if dx != 0 else 0 else: a = abs(x//dx)-1 b = abs((m...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
152/B
152
B
Python 3
TESTS
6
248
614,400
96497138
n, m = map(int, input().split()) x, y = map(int, input().split()) k = int(input()) vectors = [] for _ in range(k): vectors.append(tuple(map(int, input().split()))) ans = 0 for i in range(k): step_x = 0 step_y = 0 steps = 0 if vectors[i][0] < 0: step_x = (x - 1) // abs(vectors[i][0]) e...
34
124
0
218465194
n , m = map(int,input().split()) x,y = map(int,input().split()) k = int(input()) s = 0 for i in range(k): d,p = map(int,input().split()) if d>0: a=(n-x)//d elif d<0: a=(x-1)//abs(d) if p>0: b=(m-y)//p if d==0: a=b+1 elif p<0: b=(y-1)//abs(p) ...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
1009/A
1009
A
Python 3
TESTS
3
124
0
137516387
n, m = map(int, input().split()) c = list(map(int, input().split())) a = list(map(int, input().split())) count = 0 t = 0 for i in range(n): # t = count for j in range(m): if a[j] > c[i]: a[j] = -1 c[i] = 10000 count += 1 break # if t == count: # ...
19
46
0
136827538
a,b=map(int,input().split(" ")) c=input().split(" ") d=input().split(" ") n=0 c=[int(i) for i in c] d=[int(j) for j in d] for i in range(a): if n!=b: if d[n]>=c[i]: n=n+1 print(n)
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1
256
Game Shopping
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$. Games in the shop are ordered from left to ri...
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th ...
Print a single integer — the number of games Maxim will buy.
null
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3"}, {"input": "5 2\n20 40 50 20 40\n19 20", "output": "0"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4"}]
800
["implementation"]
19
[{"input": "5 4\r\n2 4 5 2 4\r\n5 3 4 6\r\n", "output": "3\r\n"}, {"input": "5 2\r\n20 40 50 20 40\r\n19 20\r\n", "output": "0\r\n"}, {"input": "6 4\r\n4 8 15 16 23 42\r\n1000 1000 1000 1000\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 1\r\n10 1 1 1 1\r\n1000\r\n", "...
false
stdio
null
true
1009/G
1009
G
Python 3
TESTS
0
108
0
40756225
w = input() d = {} for c in w: d[c] = w.count(c) inv = dict() for i in range(int(input())): idx,name = input().split() idx = int(idx)-1 name = [c for c in name if c in d] if name: inv[idx] = name def solve(counts, investors, value=None): if value == None: value = dict() if not investors: ...
57
233
10,137,600
167672037
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline s = list(input().rstrip()) pow2 = [1] for _ in range(6): pow2.append(2 * pow2[-1]) p = pow2[6] cnt = [0] * p for i in s: cnt[pow2[i - 97]] += 1 sp = set(pow2) u = [[pow2[i]] for i in range(6)] for i in range(1, p): if i in sp: ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Allowed Letters
Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup! Actually, Polycarp has already came up with the name but some improvement ...
The first line is the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) — the name Polycarp has came up with. The string consists only of lowercase Latin letters from "a" to "f". The second line contains a single integer $$$m$$$ ($$$0 \le m \le |s|$$$) — the number of investors. The $$$i$$$-th of the next $$$m$$$ lines conta...
If Polycarp can't produce any valid name then print "Impossible". Otherwise print the smallest lexicographically name Polycarp can obtain by swapping letters in string $$$s$$$ such that the letter at every position is among the allowed ones.
null
null
[{"input": "bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef", "output": "deadbeef"}, {"input": "abacaba\n0", "output": "aaaabbc"}, {"input": "fc\n2\n1 cfab\n2 f", "output": "cf"}]
2,400
["bitmasks", "flows", "graph matchings", "graphs", "greedy"]
57
[{"input": "bedefead\r\n5\r\n2 e\r\n1 dc\r\n5 b\r\n7 ef\r\n6 ef\r\n", "output": "deadbeef\r\n"}, {"input": "abacaba\r\n0\r\n", "output": "aaaabbc\r\n"}, {"input": "fc\r\n2\r\n1 cfab\r\n2 f\r\n", "output": "cf\r\n"}, {"input": "bbcbbc\r\n6\r\n1 c\r\n2 c\r\n3 b\r\n4 ab\r\n5 ab\r\n6 ab\r\n", "output": "ccbbbb\r\n"}, {"inp...
false
stdio
null
true
1009/A
1009
A
Python 3
TESTS
3
108
0
40856410
answer=0 n,m=map(int, input("").split(" ")) games=input("").split(" ") wallet=input("").split(" ") for i in range(m): if int(games[i])<=int(wallet[i]): answer+=1 else: del games[i] games.append(10000) i-=1 print(answer)
19
46
0
136833530
n,m=input().split() n=int(n) m=int(m) lis1=input().split(' ') lis1=[int(i) for i in lis1] lis2=input().split(' ') lis2=[int(i) for i in lis2] cnt=0 for i in range(max(n,m)): if lis2[0] >= lis1[0]: cnt += 1 lis1.pop(0) lis2.pop(0) if len(lis1)==0 or len(lis2)==0: break ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1
256
Game Shopping
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$. Games in the shop are ordered from left to ri...
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th ...
Print a single integer — the number of games Maxim will buy.
null
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3"}, {"input": "5 2\n20 40 50 20 40\n19 20", "output": "0"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4"}]
800
["implementation"]
19
[{"input": "5 4\r\n2 4 5 2 4\r\n5 3 4 6\r\n", "output": "3\r\n"}, {"input": "5 2\r\n20 40 50 20 40\r\n19 20\r\n", "output": "0\r\n"}, {"input": "6 4\r\n4 8 15 16 23 42\r\n1000 1000 1000 1000\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 1\r\n10 1 1 1 1\r\n1000\r\n", "...
false
stdio
null
true
724/D
724
D
Python 3
PRETESTS
4
62
4,608,000
21294474
def minn(a): m = a[0] p = 0 for i in range(1, len(a)): if a[i] <= m: m = a[i] p = i return m, p k = int(input()) s = input() cnt = list(s[:k]) min_elem, place = minn(cnt) ans = [min_elem] for i in range(k, len(s)): cnt.pop(0) cnt.append(s[i]) new_min_elem, n...
71
405
6,860,800
21307524
from collections import Counter from string import ascii_lowercase as asc m, s = int(input()), input() g = Counter(s) def solve(c): p = 0 for q in ''.join(x if x >= c else ' ' for x in s).split(): i, j = 0, -1 while j + m < len(q): j = q.rfind(c, j + 1, j + m + 1) if j ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
5
216
0
60777852
def calrange(x, d): if d>=0: return [x, x+d] else: return [x+d, x] n=int(input()) x=[] d=[] r=[] b=[] c=0 for i in range(n): tx, td=[int(x) for x in input().split()] x.append(tx), d.append(td) r.append(calrange(tx, td)) for i in range(n): for j in range(n): if i!=j and c==0: if r[i][0]<=x[j]<...
30
92
0
142066183
s = [] for n in range(int(input())): x, d = map(int, input().split()) s.append(([x, x+d])) find = True for i in range(len(s)): if find is False: break x, d = s[i] for j in range(len(s)): if i == j: continue z, y = s[j] if x == y and z == d: pr...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
152/B
152
B
Python 3
TESTS
6
92
0
189868249
def main(): n, m = list(map(int, input().split())) x_0, y_0 = list(map(int, input().split())) k = int(input()) steps = 0 for i in range(k): dx, dy = list(map(int, input().split())) if dx > 0: valid_x = (n - x_0) // dx elif dx == 0: valid_x = n ...
34
154
0
136563686
import sys mn = sys.stdin.readline()[:-1].split(' ') n, m = int(mn[0]), int(mn[1]) xy = sys.stdin.readline()[:-1].split(' ') x, y = int(xy[0]), int(xy[1]) count = 0 k = int(sys.stdin.readline()[:-1]) for i in range(k): dxy = sys.stdin.readline()[:-1].split(' ') dx, dy = int(dxy[0]), int(dxy[1]) if dx < 0: ...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
560/A
560
A
Python 3
TESTS
3
46
0
12237948
n = input() arr = input() flag = False arr.split(' ') for a in arr: if a == "1": flag = True break if flag: print("-1") else: print("1")
16
31
0
180082104
n = int(input()) a = list(map(int,input().split())) bln = True for i in range(len(a)): if a[i] == 1: print(-1) bln = False if bln: print(1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
124
6,758,400
129967833
a = int(input()) count = 0 c = 'ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE' c.split() for i in range(a): b = input() if b.isdigit(): if int(b) < 18: count += 1 elif b in c: count += 1 print(count)
28
62
0
150127566
n = int(input()) alc = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'] m = 0 for i in range(n): x = input() if '1' in x or '2' in x or '3' in x or '4' in x or '5' in x or '6' in x or '7' in x or '8' in x or '9' in x or '0' in x: if int(x) < 18: ...
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
560/A
560
A
Python 3
TESTS
3
31
0
192487142
# LUOGU_RID: 101605300 n, *a = map(int, open(0).read().split()) print(-1 if min(a) == 1 else min(a) - 1)
16
31
0
211103427
n = int(input()) banknotes = list(map(int, input().split())) flag = False for bn in banknotes: if bn == 1: flag = True print (-1 if flag else 1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
152/B
152
B
Python 3
TESTS
6
234
921,600
3731189
import re import itertools from collections import Counter class Task: n, m = 0, 0 start, end = 0, 0 vectors = [] answer = 0 def getData(self): self.n, self.m = [int(x) for x in input().split(' ')] self.start, self.end = [int(x) for x in input().split(' ')] numberOfVectors...
34
154
0
150376636
'''CodeForces: Steps''' import math if __name__ == '__main__': # input Operation n, m = list(map(int, input().split())) x, y = list(map(int, input().split())) steps = 0 for _ in range(int(input())): a = math.inf dx, dy = map(int, input().split()) if dx > 0: a = m...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
560/A
560
A
Python 3
TESTS
3
31
0
189228068
# -*- coding: utf-8 -*- """ Created on Sat Jan 14 12:02:06 2023 @author: Lenovo """ n = int(input()) s = input() if '1' in s: print(-1) else: print(1)
16
31
0
219699260
n=int(input()) arr=[int(i) for i in input().split()] arr.sort() if arr[0]==1: print(-1) else : print(1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
560/A
560
A
Python 3
TESTS
3
46
0
22872075
n=int(input()) a=list(map(int,input().split())) print(-1 if min(a)==1 else min(a)-1)
16
31
0
219699469
n=int (input()) arr=[int(i) for i in input().split()] arr.sort() if arr[0]==1: print(-1) else: print(1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
124
0
112232498
n = int(input()) alchoholic = 'ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE' ans = 0 for i in range(n): x = input() if x in alchoholic: ans += 1 elif x.isnumeric(): ans += 1 if int(x) < 18 else 0 print(ans)
28
62
0
150139438
n = int(input()) lst = [] c = 0 alcohol = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"] while n: n -= 1 lst.append(input()) for i in lst: if i.isdigit() and int(i) < 18: c += 1 elif i in alcohol: c += 1 print(c)
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
124
0
112233221
n = int(input()) alchoholic = ' ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE' ans = 0 for i in range(n): x = input() if x in alchoholic: ans += 1 elif x.isnumeric(): if int(x) < 18: ans += 1 print(ans)
28
62
0
195250963
drinks = ["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA", "WHISKEY", "WINE"] ans=0 for _ in range(int(input())): s=input() if s.isdigit() and int(s)<18: ans+=1 elif s.isalpha() and s in drinks: ans+=1 print(ans)
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
56/E
56
E
PyPy 3
TESTS
7
498
6,246,400
66756304
from typing import List, Tuple from bisect import bisect_left import math def get_max(tree: List[int], node: int, nl:int, nr: int, l: int, r: int) -> int: if nl >= l and nr <= r: return tree[node] if nl > r or nr < l: return -1 mid = (nl + nr) // 2 return max( get_max(tree, 2...
34
842
21,504,000
181521732
import bisect import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def update(i, x, tree): i += l1 tree[i] = x i //= 2 while i: tree[i] = max(tree[2 * i], tree[2 * i + 1]) i //= 2 return def get_max(s, t, tree): s += l1 t += l1 ans = -inf ...
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Domino Principle
Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put n dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The i-th domino has ...
The first line contains integer n (1 ≤ n ≤ 105) which is the number of dominoes. Then follow n lines containing two integers xi and hi ( - 108 ≤ xi ≤ 108, 2 ≤ hi ≤ 108) each, which are the coordinate and height of every domino. No two dominoes stand on one point.
Print n space-separated numbers zi — the number of dominoes that will fall if Vasya pushes the i-th domino to the right (including the domino itself).
null
null
[{"input": "4\n16 5\n20 5\n10 10\n18 2", "output": "3 1 4 1"}, {"input": "4\n0 10\n1 5\n9 10\n15 10", "output": "4 1 2 1"}]
2,200
["binary search", "data structures", "sortings"]
34
[{"input": "4\r\n16 5\r\n20 5\r\n10 10\r\n18 2\r\n", "output": "3 1 4 1 "}, {"input": "4\r\n0 10\r\n1 5\r\n9 10\r\n15 10\r\n", "output": "4 1 2 1 "}, {"input": "3\r\n6 7\r\n2 9\r\n-6 10\r\n", "output": "1 2 3 "}, {"input": "4\r\n-6 9\r\n9 5\r\n-7 4\r\n0 9\r\n", "output": "2 1 3 1 "}, {"input": "5\r\n-47 19\r\n-43 14\r\...
false
stdio
null
true
152/B
152
B
Python 3
TESTS
4
92
0
214199374
n, m = list(map(int, input().split())) x, y = list(map(int, input().split())) k = int(input()) ans = 0 def calc(n, x, dx): if dx == 0: return 100000000 if dx > 0: return (n - x) // dx return (x - 1) // -dx for q in range(k): dx, dy = list(map(int, input().split())) steps = min(calc(n, x, dx), calc(m...
34
154
0
163447778
from math import inf n,m = map(int,input().split()) x,y = map(int,input().split()) total = 0 for i in range(int(input())): dx,dy = map(int,input().split()) stepsX = 0 if dx > 0 : permetedX = n -x stepsX = permetedX // dx if dx <0 : permetedX = x-1 stepsX = permetedX // abs(dx) stepsX *= -1...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
845/D
845
D
PyPy 3
TESTS
7
311
9,318,400
132049448
class LazySegTree: # RMQ and RUQ def __init__(self, init_val, seg_ide, lazy_ide, segfunc): self.n = len(init_val) self.num = 2**(self.n-1).bit_length() self.seg_ide = seg_ide self.lazy_ide = lazy_ide self.segfunc = segfunc # seg, lazy: 1-indexed self.se...
25
140
9,318,400
155527993
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) now = 0 ng = 0 ans = 0 x = [] for _ in range(n): t = list(map(int, input().split())) if t[0] == 1: now = t[1] while x and x[-1] < now: ans += 1 x.pop() elif t[0] == 2: ...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
845/D
845
D
Python 3
TESTS
7
826
7,475,200
29668284
n = int(input()) answer = 0 arr = [] colvo_znak = 0 for i in range(n): arr.append(input()) for i in range(n): if len(arr[i])>1: arr[i]=arr[i].split() arr[i][1] = int(arr[i][1]) else: arr[i] = int(arr[i]) speed_p = 0 arr_zn =-1 arr_not_of_spid = [100000000] for i in range(n): if l...
25
155
9,318,400
132050195
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) overtake = True notallowed = 0 stack = [] cur = -1 ans = 0 for i in range(n): temp = list(map(int, input().split())) if temp[0] == 1: s = temp[1] while stack and stack[-1] < s: stac...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
845/D
845
D
Python 3
TESTS
7
311
3,788,800
143344925
import math listOfEvents = [] allowedSpeed = math.inf currentSpeed = 0 overtakeAllowed = True overtaking = False mistakes = 0 numberOfOvertakeLimit = 0 numberOfEvents = int(input()) for i in range(numberOfEvents): listOfEvents.append(input()) for event in listOfEvents: if event[0] == '1': tempList =...
25
249
8,601,600
93327437
import sys n = int(sys.stdin.buffer.readline().decode('utf-8')) inf = 10**9 speed = 0 limit = [inf] overtake = 1 ot_sign = 0 ans = 0 for _ in range(n): q = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) if q[0] == 1: while limit[-1] < q[1]: ans += 1 limit....
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
408/A
408
A
Python 3
TESTS
4
31
0
154821974
n = int(input()) book = {} cashiers = [int(num) for num in input().split(' ', n-1)] for i in range(0, n): key = cashiers[i] tem = [int(x) for x in input().split()] book[key] = tem time_list = [] for i in range(0, n): t = 5 * sum(book[cashiers[i]]) + 15 * cashiers[i] time_list.append(t) print(min(tim...
20
31
0
183971755
n=int(input()) l=list(map(int, input().split())) mintime=1e10 for i in l: k=list(map(int, input().split())) time=sum(k)*5+i*15 if(time<mintime): mintime=time print(mintime)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
2/A
2
A
PyPy 3-64
TESTS
15
154
614,400
183727307
from sys import stdin; inp = stdin.readline def IA(): return list(map(int, inp().split())) def FA(): return list(map(float, inp().split())) def SA(): return inp().split() def I(): return int(inp()) def F(): return float(inp()) def S(): return inp() from collections import defaultdict from itertools import accumulate fr...
20
62
0
163020676
# Description of the problem can be found at http://codeforces.com/problemset/problem/2/A n = int(input()) l_k = list() for _ in range(n): l_k.append(input().split()) d_s = {} for i in range(n): k = l_k[i][0] s = int(l_k[i][1]) if k not in d_s: d_s[k] = int(s) else: d_s[k] +=...
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
2/A
2
A
Python 3
TESTS
15
92
102,400
210104794
#print("n?") n = int(input()) winner = "" high_score = 0 list = {} record = [] winnerlist = [] #ゲームの記録 for i in range(n): #print(i) str = input().split() player = str[0] point = int(str[1]) #playerがlistに存在する/しない if(player in list): list[player] += point else: list[player] ...
20
62
102,400
207151523
all_members = {} first = '' mem = {} n = int(input()) lst = [input() for i in range(n)] for i in range(n): name, score = lst[i].split() if name not in all_members: all_members[name] = int(score) else: all_members[name] += int(score) f = max(all_members, key=all_members.get) ...
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
152/B
152
B
Python 3
TESTS
6
654
7,577,600
128457609
def isValid(steps, n, m, startingPoint, vector): x, y = startingPoint return ((vector[0] * steps) + x <= n and (vector[1] * steps) + y <= m and (vector[1] * steps) + y > 0 and (vector[0] * steps) + x > 0) def getNumberOfSteps(vector, startingPoint, n, m): rightPointer = min(n, m) leftPointer = 0 s...
34
154
0
167996801
n,m=list(map(int,input().split()));pos=list(map(int,input().split()));k=int(input());c=0 for i in range(k): x,y=list(map(int,input().split())) if x!=0 and y!=0: if x<0:numx=(pos[0]-1)//abs(x) elif x>0:numx=(n-pos[0])//abs(x) if y<0:numy=(pos[1]-1)//abs(y) elif y>0:numy=(m-pos[1])...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
15/C
15
C
Python 3
TESTS
5
154
5,222,400
17975437
n = input() n = int(n) ans = 0 for i in range(0, n): x, m = map(int, input().split()) end = x+m-1 if x % 2 == 1: ans ^= x x = x+1 m = m-1 if m == 0: continue; if m % 2 == 1: ans ^= 1 if end % 2 == 0: ans ^= end if ans == 0: print('bolik') else...
25
248
4,505,600
191480790
import sys; R = sys.stdin.readline r = 0 for _ in range(int(R())): x,m = map(int,R().split()) a,b = x,x+m-1 if a&1: r ^= a; a += 1 if not b&1: r ^= b; b -= 1 if (b-a+1)&2: r ^= 1 print("tolik" if r else "bolik")
Codeforces Beta Round 15
ICPC
2,010
2
64
Industrial Nim
There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it. Two oligarchs p...
The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.
Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.
null
null
[{"input": "2\n2 1\n3 2", "output": "tolik"}, {"input": "4\n1 1\n1 1\n1 1\n1 1", "output": "bolik"}]
2,000
["games"]
25
[{"input": "2\r\n2 1\r\n3 2\r\n", "output": "tolik\r\n"}, {"input": "4\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "bolik\r\n"}, {"input": "10\r\n2 3\r\n1 4\r\n5 8\r\n4 10\r\n10 8\r\n7 2\r\n1 2\r\n1 7\r\n4 10\r\n5 3\r\n", "output": "tolik\r\n"}, {"input": "20\r\n8 6\r\n6 3\r\n2 9\r\n7 8\r\n9 1\r\n2 4\r\n3 6\r\n6 3\r\n5...
false
stdio
null
true
152/B
152
B
PyPy 3
TESTS
4
684
30,822,400
123816054
from itertools import product from math import ceil, gcd, sqrt import string from decimal import Decimal def binary_table(string_with_all_characters, length_to_make): return [''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)] def all_possible_substrings(string): return [int(stri...
34
154
0
196857259
n, m = map(int, input().split()) xc, yc = map(int, input().split()) k = int(input()) total_steps = 0 for i in range(k): dx, dy = map(int, input().split()) max_steps = float('inf') if dx > 0: max_steps = min(max_steps, (n - xc) // dx) elif dx < 0: max_steps = min(max_steps, (xc - 1) // (...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
248/A
248
A
Python 3
TESTS
56
184
6,963,200
126720542
n = int(input()) numberofLeft = 0 numberofright = 0 numberofall = 0 out = 0 leftOnly = 0 rightOnly = 0 allOnly = 0 for i in range(n): inp = list(map(int, input().split())) if(inp[0] == 0 and inp[1] == 1): numberofright += 1 elif(inp[0] == 1 and inp[1] == 0): numberofLeft += 1 elif(inp[0]...
57
92
0
147455902
n = int(input()) left, right = 0, 0 for i in range(n): l, r = input().split(" ") left+=int(l) right+=int(r) ans = (min(left, n-left)+min(right, n-right)) print(ans)
Codeforces Round 152 (Div. 2)
CF
2,012
2
256
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, ...
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
null
null
[{"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3"}]
800
["implementation"]
57
[{"input": "5\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "8\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n1 0\r\n0 1\r\n1 0\r\n", "output": "7\r\n"}, {"input": "8\r\n1 0\r\n1 0\r\n1 0\r\n...
false
stdio
null
true
248/A
248
A
PyPy 3
TESTS
20
468
4,096,000
100880794
left = [] right = [] for _ in range(int(input())): l,r = map(int,input().split()) left.append(l) right.append(r) c = 0 if left.count(1) > left.count(0): c+=(len(left) - left.count(1)) elif left.count(1) < left.count(0): c+=(len(left) - left.count(0)) else: c+=(len(left)//2) if right.count(1) >...
57
92
0
205596452
n = int(input()) Ltotal, Rtotal = 0, 0 for x in range(n): l, r = map(int, input().split()) Ltotal += l Rtotal += r ans = 0 if Ltotal > n-Ltotal: ans += n-Ltotal else: ans += Ltotal if Rtotal > n-Rtotal: ans += n-Rtotal else: ans += Rtotal print(ans)
Codeforces Round 152 (Div. 2)
CF
2,012
2
256
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, ...
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
null
null
[{"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3"}]
800
["implementation"]
57
[{"input": "5\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "8\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n1 0\r\n0 1\r\n1 0\r\n", "output": "7\r\n"}, {"input": "8\r\n1 0\r\n1 0\r\n1 0\r\n...
false
stdio
null
true
248/A
248
A
Python 3
TESTS
56
154
0
173433372
n = int(input()) i = 1 a=b=0 while True: if i>n: break l,r = input().split() if int(l)==0: a = a+1 elif int(r)==0: b = b+1 i = i+1 k = [int(a+b), int(a+(n-b)), int((n-a)+b), int((n-a)+(n-b))] print(min(k))
57
92
0
207726325
t=int(input()) tot=0 tot1=0 debug = False for i in range(0,t): m,n=map(int,input().split()) tot=tot+m tot1=tot1+n mi=0 ma=0 if debug: print(tot, tot1) mi=min(tot,(t-tot)) ma=min(tot1,(t-tot1)) if debug: print(mi, ma, mi + ma) print(mi+ma)
Codeforces Round 152 (Div. 2)
CF
2,012
2
256
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, ...
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
null
null
[{"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3"}]
800
["implementation"]
57
[{"input": "5\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "8\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n1 0\r\n0 1\r\n1 0\r\n", "output": "7\r\n"}, {"input": "8\r\n1 0\r\n1 0\r\n1 0\r\n...
false
stdio
null
true
248/A
248
A
Python 3
TESTS
56
124
512,000
164725359
def solve(n,board): cl = cr = 0 for row in board: if row[0] == 0: cl+=1 elif row[1] == 0: cr +=1 return min(cl,n-cl)+min(cr,n-cr) n = int(input()) board = [] for i in range(n): board.append(list(map(int,input().split()))) print(solve(n,board))
57
92
0
207886016
a = int(input()) b0 = 0 b1 = 0 c0 = 0 c1 = 0 for i in range(a): b, c = map(int, input().split()) if b == 0: b0 += 1 else: b1 += 1 if c == 0: c0 += 1 else: c1 += 1 print(min(b0, b1) + min(c0, c1))
Codeforces Round 152 (Div. 2)
CF
2,012
2
256
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, ...
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
null
null
[{"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3"}]
800
["implementation"]
57
[{"input": "5\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "8\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n1 0\r\n0 1\r\n1 0\r\n", "output": "7\r\n"}, {"input": "8\r\n1 0\r\n1 0\r\n1 0\r\n...
false
stdio
null
true
501/C
501
C
PyPy 3-64
TESTS
2
62
512,000
156403356
n_vertices = int(input()) n_edges = 0 stack_leafs = [] ans = [] arr_s = [] arr_deg = [] for i in range(n_vertices): deg, s = map(int, input().split()) arr_deg.append(deg) arr_s.append(s) n_edges += deg if arr_deg[i] == 1: stack_leafs.append(i) # your code may be here n_edges //= 2 w...
49
327
12,800,000
9409593
def main(): import sys tokens = [int(i) for i in sys.stdin.read().split()] tokens.reverse() n = tokens.pop() vertices = [[tokens.pop(), tokens.pop()] for i in range(n)] l = [] for i in range(n): if vertices[i][0] == 1: l.append(i) result = [] w...
Codeforces Round 285 (Div. 2)
CF
2,015
1
256
Misha and Forest
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the secon...
The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph. The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.
In the first line print number m, the number of edges of the graph. Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b). Edges can be printed in any order; vertices of the edge can also be printed in any order.
null
The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
[{"input": "3\n2 3\n1 0\n1 0", "output": "2\n1 0\n2 0"}, {"input": "2\n1 1\n1 0", "output": "1\n0 1"}]
1,500
["constructive algorithms", "data structures", "greedy", "sortings", "trees"]
49
[{"input": "3\r\n2 3\r\n1 0\r\n1 0\r\n", "output": "2\r\n1 0\r\n2 0\r\n"}, {"input": "2\r\n1 1\r\n1 0\r\n", "output": "1\r\n0 1\r\n"}, {"input": "10\r\n3 13\r\n2 6\r\n1 5\r\n3 5\r\n1 3\r\n2 2\r\n2 6\r\n1 6\r\n1 3\r\n2 3\r\n", "output": "9\r\n2 5\r\n4 3\r\n7 6\r\n8 3\r\n5 0\r\n6 1\r\n3 9\r\n1 0\r\n9 0\r\n"}, {"input": "...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] # not used submission_path = sys.argv[3] # Read input with open(input_path) as f: lines = [line.strip() for line in f if line.strip()] n = int(lines[0]) degrees = [] s_list = [] for l...
true
248/A
248
A
Python 3
TESTS
56
278
512,000
76075712
def counter(massive: list) -> list: count1 = 0 count2 = 0 for i in range(len(massive)): if massive[i] == 1: count1 +=1 else: count2 += 1 if count1 >= count2: return count1, 1 else: return count2, 0 def diff(mass: list, number: int) -> list...
57
92
0
209520121
n =int(input()) left_open = 0 right_open = 0 for _ in range(n): (left, right) = map(int, input().split()) if left == 1: left_open += 1 if right == 1: right_open += 1 min_left = min(left_open, n-left_open) min_right = min(right_open, n-right_open) print(min_left+min_right)
Codeforces Round 152 (Div. 2)
CF
2,012
2
256
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, ...
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
null
null
[{"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3"}]
800
["implementation"]
57
[{"input": "5\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "8\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n1 0\r\n0 1\r\n1 0\r\n", "output": "7\r\n"}, {"input": "8\r\n1 0\r\n1 0\r\n1 0\r\n...
false
stdio
null
true
248/A
248
A
PyPy 3-64
TESTS
56
342
4,915,200
209173990
n = int(input()) only_right = 0 only_left = 0 both = 0 neither = 0 for i in range(n): l, r = map(int, input().split()) if l == 0 and r == 0: both += 2 only_right += 1 only_left += 1 elif l == 0 and r == 1: only_left += 2 both += 1 neither += 1 elif l == 1...
57
92
0
212998246
t = int(input()) left = 0 right = 0 for _ in range(t): p, q = map(int, input().split()) left += p right += q result = min(left, t - left) + min(right, t - right) print(result)
Codeforces Round 152 (Div. 2)
CF
2,012
2
256
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, ...
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
null
null
[{"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3"}]
800
["implementation"]
57
[{"input": "5\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "8\r\n0 1\r\n1 0\r\n0 1\r\n1 1\r\n0 1\r\n1 0\r\n0 1\r\n1 0\r\n", "output": "7\r\n"}, {"input": "8\r\n1 0\r\n1 0\r\n1 0\r\n...
false
stdio
null
true
845/D
845
D
Python 3
TESTS
7
436
0
29662805
import sys, os n = int(input()) a = set() k = 0 res = 0 for i in range(n): x = input() if x == "4": k = 0 continue if x == "2": res += k k = 0 continue if x == "6": k += 1 continue if x == "5": a = set() continue if x[0] ...
25
421
1,638,400
118122702
n = int(input()) r = 0 cnt = 0 sp = int(input()[2:]) lims = [301] for ind in range(n-1): s = input() if s[0] == "1": sp = int(s[2:]) while lims[-1] < sp: cnt += 1 lims.pop() elif s[0] == "2": cnt += r r = 0 elif s[0] == "3": newlim = int(s[...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
437/C
437
C
PyPy 3
TESTS
11
140
2,048,000
22158462
from sys import stdin,stdout # stdin = open("/Users/seeva92/Workspace/Contests/1.txt","r") # stdout = open("/Users/seeva92/Workspace/Contests/2.txt","w") n,m = map(int,stdin.readline().split()) v = list(map(int,stdin.readline().split())) g = [list() for i in range(n)] for i in range(m): x,y = map(int,stdin.readline()....
29
31
0
183828239
n,m=map(int,input().split()) ans=0 num=list(map(int,input().split())) for i in range(m): x,y=map(int,input().split()) ans+=min(num[x-1],num[y-1]) print(ans)
Codeforces Round 250 (Div. 2)
CF
2,014
1
256
The Child and Toy
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The...
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered fr...
Output the minimum total energy the child should spend to remove all n parts of the toy.
null
One of the optimal sequence of actions in the first sample is: - First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 =...
[{"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3", "output": "40"}, {"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "output": "400"}, {"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "output": "160"}]
1,400
["graphs", "greedy", "sortings"]
29
[{"input": "4 3\r\n10 20 30 40\r\n1 4\r\n1 2\r\n2 3\r\n", "output": "40\r\n"}, {"input": "4 4\r\n100 100 100 100\r\n1 2\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "400\r\n"}, {"input": "7 10\r\n40 10 20 10 20 80 40\r\n1 5\r\n4 7\r\n4 5\r\n5 2\r\n5 7\r\n6 4\r\n1 6\r\n1 3\r\n4 3\r\n1 4\r\n", "output": "160\r\n"}, {"input": "1 ...
false
stdio
null
true
152/B
152
B
PyPy 3
TESTS
4
496
9,625,600
117850555
if __name__ == "__main__": n,m = (int(i) for i in input().split()) xc,yc = (int(i) for i in input().split()) k = int(input()) vecs = [(int(i) for i in input().split()) for _ in range(k)] total = 0 for dx,dy in vecs: x_dist = (xc-1 if dx < 0 else n-xc) x_moves = abs(x_dist//abs(dx...
34
154
512,000
150380654
n, m = map(int, input().split()) x, y = map(int, input().split()) k = int(input()) vectors = [] for i in range(k): dx, dy = map(int, input().split()) vectors.append([dx, dy]) no_of_steps = 0 for vector in vectors: temp = [] if(vector[0] != 0): if(vector[0] > 0): temp.append((n...
Codeforces Round 108 (Div. 2)
CF
2,012
2
256
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m). The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two int...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,...
[{"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4"}, {"input": "10 10\n1 2\n1\n-1 0", "output": "0"}]
1,300
["binary search", "implementation"]
34
[{"input": "4 5\r\n1 1\r\n3\r\n1 1\r\n1 1\r\n0 -2\r\n", "output": "4\r\n"}, {"input": "10 10\r\n1 2\r\n1\r\n-1 0\r\n", "output": "0\r\n"}, {"input": "10 20\r\n10 3\r\n10\r\n-2 -6\r\n-1 0\r\n-8 0\r\n0 5\r\n-1 3\r\n16 -16\r\n-1 9\r\n0 -18\r\n9 -1\r\n-9 5\r\n", "output": "13\r\n"}, {"input": "20 10\r\n14 4\r\n10\r\n6 0\r\...
false
stdio
null
true
2/A
2
A
Python 3
TESTS
13
92
0
218357268
d = {} mx = None for _ in range(int(input())): name,score = map(str,input().split()) score = int(score) if name in d: d[name]+=score else: d[name] = score if mx==None or d[name]>d[mx]:mx = name print(mx)
20
62
102,400
213979247
a,b={},[] for _ in ' '*int(input()): n,s=input().split(); a[n]=a.get(n,0)+int(s); b+=[(a[n],n)] m=max(a.values()) print([x for v,x in b if a[x]==m and v>=m][0])
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
29/D
29
D
Python 3
TESTS
4
92
0
219481182
def dfs(v, parent): route.append(v) for u in graph[v]: if u != parent: dfs(u, v) route.append(v) def solve(): leaf_order_index = 0 dfs(1, 0) for v in route: if v == leaf_order[leaf_order_index]: leaf_order_index += 1 if leaf_order_ind...
35
154
2,252,800
164853221
import sys input = sys.stdin.readline from collections import deque def build_tree(edges, root): children = dict() parent = dict() stack = deque() stack.append(root) parent[root] = -1 while stack: u = stack.pop() children[u] = [] for v in edges[u]: if v != pa...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
29/D
29
D
Python 3
TESTS
4
60
0
219480956
def find_route(tree, leaves_order): n = len(tree) leaf_index = 0 visited = [False] * (n + 1) route = [] def dfs(node): nonlocal leaf_index if visited[node]: return visited[node] = True route.append(node) if node == leaves_order[leaf_index]: ...
35
154
5,120,000
219368205
t=int(input()) my_dict={i+1:[] for i in range(t)} for i in range(t-1): a,b=map(int,input().split()) my_dict[a].append(b) my_dict[b].append(a) s=list(map(int,input().split())) my_dict2={i+1:[] for i in range(t)} queue=[1] vis=[1]*(t) vis[0]=0 while queue: ele=queue.pop(0) for i in my_dict[ele]: ...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
724/D
724
D
Python 3
PRETESTS
4
46
4,608,000
21297046
m = int(input()) s = input() d = [] i = 0 a = min(s[i: i + m]) i = s.rfind(a, i , i + m) d.append(a) while i + m < len(s): a = min(s[i + 1: i + 1 + m]) #print(s[i + 1: i + 1 + m]) d.append(a) #ind = i + 1 + m i = s.rfind(a, i + 1, i + 1 + m) #print(a, i) try: a = min(s[len(s) -...
71
124
9,011,200
200894970
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline m = int(input()) s = [0] + list(input().rstrip()) n = len(s) - 1 u = [[] for _ in range(130)] for i in range(1, n + 1): u[s[i]].append(i) x = [0] * (n + 1) for i in range(97, 123): for j in u[i]: x[j] = 1 y = list(x) ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
408/A
408
A
PyPy 3-64
TESTS
4
77
0
135938878
x = int(input()) ls = list(map(int, input().split())) my_dict = dict() for i in range(x) : my_dict[ls[i]] = list(map(int, input().split())) ans = 1000000001 for i in range(x) : key = ls[i] ans = min(ans, ((key * 15) + sum(my_dict[key]) * 5)) print(ans)
20
31
102,400
206447509
#Keshika Patwari #Indian Institute Of Technology, Jodhpur # 2022 import sys input=sys.stdin.readline def exe(): return min(k) n=int(input()) ln=list(map(int,input().split())) k=[] for i in range(n): a=list(map(int,input().split())) b=sum(a)*5+ln[i]*15 k.append(b) print(exe())
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
92
0
107525829
n=int(input()) z=0 a=['ABSINTH', 'BEER',' BRANDY','CHAMPAGNE','GIN', 'RUM','SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'] for i in range(n): s=input() if s in a: z+=1 try: if int(s)<18: z+=1 except: pass print(z)
28
62
0
230776815
n = int(input()) alcohol = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'] ans = 0 for i in range(n): line = input() if line.isnumeric() and int(line) < 18 or line in alcohol: ans += 1 print(ans)
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
5
122
6,963,200
127308825
n=int(input()) lst=[] c=0 for i in range(0,n): item=str(input()) lst.append(item) if item[0]>='0' and item[0]<='9': k=int(item) if k<18: c+=1 elif item=='ABSINTH' or item=='BEER' or item=='BRANDY' or item=='CHAMPANGE' or item=='GIN' or item=='RUM' or item=='SAKE' or item=='TE...
28
92
0
13091115
n = int(input()) a = 0 q = '1234567890' e = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'] for i in range(n): s = input() if s[0] in q: s = int(s) if s < 18: a += 1 else: if s in e: a += 1 print(a)
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
908/C
908
C
PyPy 3
TESTS
6
186
2,150,400
76766429
# import io, os # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys input=sys.stdin.readline MOD = 1000000007 MOD2 = 998244353 ii = lambda: int(input().strip('\n')) si = lambda: input().strip('\n') dgl = lambda: list(map(int,input().strip('\n'))) f = lambda: map(int, input().strip('\n').split()) il...
15
93
7,475,200
148743562
from collections import defaultdict as dd from collections import deque import bisect import heapq from math import sqrt def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): n, r = rl() r = r * 1.0 X = rl() prev = [] # y-coord of center in stopped ...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
908/C
908
C
Python 3
TESTS
6
187
5,632,000
34209980
from math import sqrt def findCollision(x, m, r): j = None for i in range(m): if abs(x[m] - x[i]) <= 2*r: j = i return j n, r = list(map(int, input().rstrip().split())) x = list(map(int, input().rstrip().split())) y = [0 for _ in range(n)] y[0] = r for i in range(1, n): j = findCollision(x, i, r) if j is No...
15
109
2,252,800
113142820
import math n, r = [int(x) for x in input().split()] x = [int(x) for x in input().split()] ans = [] for i in range(n): t = r for j in range(i): a = abs(x[i] - x[j]) if a <= 2 * r: t2 = (2 * r)**2 t2 -= a**2 t2 = math.sqrt(t2) + ans[j] t = max(t, t2...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
845/D
845
D
Python 3
TESTS
7
530
5,632,000
34958708
events = int(input()) speed = -1 limitSigns = [] overtake = True noOvertakeSigns = 0 signs = 0 for i in range(events): l = input().split(" ") e_type = int(l[0]) if e_type == 1: speed = int(l[1]) newLimSigns = [] for i in limitSigns: if speed > i: signs += 1 else: newLimSigns.append(i) limitSi...
25
436
6,963,200
129905274
n = int(input()) v = int(input()[2:]) p = [1e9] d = k = 0 for i in range(n - 1): s = input() t = int(s[0]) if t == 1: v = int(s[2:]) while p[-1] < v: p.pop() k += 1 if t == 2: k += d d = 0 if t == 3: u = int(s[2:]) if v > u: k +...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
845/D
845
D
PyPy 3
TESTS
7
1,435
7,270,400
118584644
n = int(input()) speed = 0 speed_limits = [] overtake = 0 ignore = 0 for i in range(n): event = list(input().split()) if (len(event) == 2): # 1 изменил скорость на х if int(event[0]) == 1: speed = int(event[1]) # speed = 100 # speed_limits = [90, 80, ...
25
561
1,945,600
29760687
#!/usr/bin/env python3 from sys import stdin, stdout from math import inf def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() csp = 0 ov = 1 sign = [] ans = 0 spst = [inf] ovst = [1] n = int(input()) for i in range(n): sign = list(rint()) if sign[0] == 1: csp = sign[1...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
437/C
437
C
PyPy 3
TESTS
11
218
35,020,800
80060094
n,m=map(int,input().split()) from collections import defaultdict v=[0]*(n+1) adj=[] for i in range(n+1): adj.append([]) l=list(map(int,input().split())) d=defaultdict(list) for i in range(m): x,y=map(int,input().split()) adj[x].append(y) adj[y].append(x) d[x]=[0]*(n+1) d[y]=[0]*(n+1) ans=0 def d...
29
46
0
9571314
def main(): n, m = map(int, input().split()) vv = list(map(int, input().split())) print(sum(min(vv[i - 1] for i in map(int, input().split())) for _ in range(m))) if __name__ == '__main__': main()
Codeforces Round 250 (Div. 2)
CF
2,014
1
256
The Child and Toy
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The...
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered fr...
Output the minimum total energy the child should spend to remove all n parts of the toy.
null
One of the optimal sequence of actions in the first sample is: - First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 =...
[{"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3", "output": "40"}, {"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "output": "400"}, {"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "output": "160"}]
1,400
["graphs", "greedy", "sortings"]
29
[{"input": "4 3\r\n10 20 30 40\r\n1 4\r\n1 2\r\n2 3\r\n", "output": "40\r\n"}, {"input": "4 4\r\n100 100 100 100\r\n1 2\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "400\r\n"}, {"input": "7 10\r\n40 10 20 10 20 80 40\r\n1 5\r\n4 7\r\n4 5\r\n5 2\r\n5 7\r\n6 4\r\n1 6\r\n1 3\r\n4 3\r\n1 4\r\n", "output": "160\r\n"}, {"input": "1 ...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
218
6,656,000
87448835
a=' ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17' t=[] for _ in range(int(input())): t.append(input()) c=0 for i in t: if i in a: c+=1 print(c)
28
92
0
19541949
def main(): x = 0 for _ in range(int(input())): s = input() try: x += int(s) < 18 except ValueError: x += s in {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"} print(x) if __name__...
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
186
307,200
94508715
n=int(input('')) l=['BSINTH','BEER','BRANDY','CHAMPAGNE','GIN','RUM','SAKE','TEQUILA','VODKA','WHISKEY','WINE'] l1=['1','2','3','4','5','6','7','8','9','0'] count=0 for i in range(n): s=input('') if(s in l): # print('if2') count+=1 if(s[0] in l1): temp=int(s) if(temp<18): ...
28
92
0
136646740
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-23 23:14:03 LastEditTime: 2021-11-23 23:20:43 Description: Bar FilePath: CF56A.py ''' def func(): n = int(input()) alcohol = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE...
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
56/A
56
A
Python 3
TESTS
7
186
6,656,000
87487643
a=' ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE' t=[] for _ in range(int(input())): t.append(input()) c=0 for i in t: if i in a or(i.isdigit() and int(i)<18): c+=1 print(c)
28
92
0
136820267
a = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA','WHISKEY', 'WINE'] ans = 0 for i in range(int(input())): s = input() if s.isdigit(): if int(s) < 18: ans += 1 if s in a: ans += 1 print(ans)
Codeforces Beta Round 52 (Div. 2)
CF
2,011
2
256
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does no...
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
null
In the sample test the second and fifth clients should be checked.
[{"input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2"}]
1,000
["implementation"]
28
[{"input": "5\r\n18\r\nVODKA\r\nCOKE\r\n19\r\n17\r\n", "output": "2\r\n"}, {"input": "2\r\n2\r\nGIN\r\n", "output": "2\r\n"}, {"input": "3\r\nWHISKEY\r\n3\r\nGIN\r\n", "output": "3\r\n"}, {"input": "4\r\n813\r\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\r\nRUM\r\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBH...
false
stdio
null
true
15/C
15
C
Python 3
TESTS
5
184
307,200
99391747
n = int(input()) ans = 0 for _ in range(n): x,m = map(int, input().split()) if x % 4 == 1: ans ^= ((x - 1) ^ (x + 3)) * ((m >> 2) & 1) elif x % 4 == 3: ans ^= ((x - 3) ^ (x + 1)) * ((m >> 2) & 1) # x % 4 == 0 ans ^= 0 * ((m >> 2) &1) # x % 4 == 2 ans ^= 0 * ((m >> 2) &1) for i in...
25
248
4,505,600
211220136
import sys N = int(sys.stdin.readline().split()[0]) def ff(a: int) -> int: return [0, a - 1, 1, a][a & 3] result = 0 for _ in range(N): x, m = tuple(map(int, sys.stdin.readline().split())) result ^= ff(x) ^ ff(x + m) if result == 0: print('bolik') else: print('tolik')
Codeforces Beta Round 15
ICPC
2,010
2
64
Industrial Nim
There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it. Two oligarchs p...
The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.
Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.
null
null
[{"input": "2\n2 1\n3 2", "output": "tolik"}, {"input": "4\n1 1\n1 1\n1 1\n1 1", "output": "bolik"}]
2,000
["games"]
25
[{"input": "2\r\n2 1\r\n3 2\r\n", "output": "tolik\r\n"}, {"input": "4\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "bolik\r\n"}, {"input": "10\r\n2 3\r\n1 4\r\n5 8\r\n4 10\r\n10 8\r\n7 2\r\n1 2\r\n1 7\r\n4 10\r\n5 3\r\n", "output": "tolik\r\n"}, {"input": "20\r\n8 6\r\n6 3\r\n2 9\r\n7 8\r\n9 1\r\n2 4\r\n3 6\r\n6 3\r\n5...
false
stdio
null
true
908/C
908
C
Python 3
TESTS
6
46
5,734,400
33794813
import math n,r=map(int,input().split()) x=list(map(int,input().split())) y=[r] def collision(t,a): for i in range(len(t)-1,-1,-1): if (a<=t[i]+2*r and a>=t[i]-2*r): if t[i]==a: return y[i]+2*r else: return(y[i]+2*r*ma...
15
109
3,891,200
159928880
import math def getDy(r, dx): if 4 * r * r - dx * dx < 0: return None return math.sqrt(4 * r * r - dx * dx) n, r = map(int, input().split(" ")) xs = [int(x) for x in input().split(" ")] disks = [] for x in xs: highestY = -1 for disk in disks: if disk["x"] - 2 * r <= x <= disk["x"] + 2 * r: dy = getDy(r,...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
908/C
908
C
PyPy 3
TESTS
6
155
1,638,400
75567682
n,r=map(int,input().split()) l=list(map(int,input().split())) ans=[] ans.append(r) le=1 for i in range(1,n): f=0 cal=0 for j in range(le,0,-1): if l[i]>=l[j-1]-2*r and l[i]<=l[j-1]+2*r: cal=((4*(r**2))-((abs(l[j-1]-l[i]))**2))**0.5 cal+=ans[j-1] ans.append(cal) ...
15
109
4,096,000
172994870
n,r=map(int,input().split()) y=[] x=list(map(int,input().split())) for xi in x: yi=r for tx,ty in zip(x,y): if xi-2*r<=tx<=xi+2*r: dy=(4.0*r**2-(tx-xi)**2)**0.5 yi=max(yi,ty+dy) y.append(yi) print(*y) '''def ycor(a,b,x,r): return b+(4.0*r**2-(x-a)**2)**0.5 n,r=map(int,input().split()) c=list(...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
908/C
908
C
PyPy 3
TESTS
6
155
1,843,200
75558255
import math def gety(x, y, x1): return (abs(y + math.sqrt(d**2 - (x-x1)**2))) n, r = map(int, input().split()) x = list(map(int, input().split())) y = [r] d = 2*r center = [[x[0], r]] for i in range(1, n): # print(center) c = [] c_temp = list(reversed(center)) for item in c_temp: if abs(item[0]-x[i])<=d: c =...
15
124
3,993,600
202138117
import sys input = lambda: sys.stdin.readline().rstrip() N,R = map(int, input().split()) A = list(map(int, input().split())) side = (R+R)**2 ans=[] for a in A: pre = (a,-R) y1 = R for x,y in ans: if abs(a-x)<=2*R: t = abs(a-x)**2 height = (side-t)**0.5+y y1 = ma...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
845/D
845
D
Python 3
TESTS
7
499
0
118584682
n = int(input()) speed = 0 speed_limits = [] overtake = 0 ignore = 0 for i in range(n): event = list(input().split()) if (len(event) == 2): if int(event[0]) == 1: speed = int(event[1]) for i in speed_limits[::-1]: if i < speed: ignore += 1 ...
25
608
1,536,000
118281683
n = int(input()) speed_limits = [] obgon = 0 current_speed = 0 count = 0 for i in range(n): event = list(input().split()) if (len(event) == 2): type, x = map(int, event) if type == 1: # 1 изменил скорость на х current_speed = x while len(speed_limits) != 0 and speed...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
437/C
437
C
PyPy 3
TESTS
5
155
1,331,200
118749349
import sys, heapq def answer(n, m, v, x, y): adj_list = [[] for _ in range(n+1)] # No node 0. Nodes 1-n visited = [False for _ in range(n+1)] #Do I need this? for i in range(m): adj_list[x[i]].append(y[i]) adj_list[y[i]].append(x[i]) total = 0 for _ in range(n): mx = 0 ...
29
46
0
138345955
n,m = map(int, input().split()) ind = list(map(int,input().split())) s = 0 for e in range(m): f,ff = map(int,input().split()) s += min(ind[f-1], ind[ff-1]) print(s)
Codeforces Round 250 (Div. 2)
CF
2,014
1
256
The Child and Toy
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The...
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered fr...
Output the minimum total energy the child should spend to remove all n parts of the toy.
null
One of the optimal sequence of actions in the first sample is: - First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 =...
[{"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3", "output": "40"}, {"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "output": "400"}, {"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "output": "160"}]
1,400
["graphs", "greedy", "sortings"]
29
[{"input": "4 3\r\n10 20 30 40\r\n1 4\r\n1 2\r\n2 3\r\n", "output": "40\r\n"}, {"input": "4 4\r\n100 100 100 100\r\n1 2\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "400\r\n"}, {"input": "7 10\r\n40 10 20 10 20 80 40\r\n1 5\r\n4 7\r\n4 5\r\n5 2\r\n5 7\r\n6 4\r\n1 6\r\n1 3\r\n4 3\r\n1 4\r\n", "output": "160\r\n"}, {"input": "1 ...
false
stdio
null
true
845/D
845
D
Python 3
TESTS
7
639
0
29659641
n = int(input()) p = 0 speed = -1 speed_limit = float('inf') overtaking = True overtaking_number = 0 speed_limit_number = 0 for _ in range(n): event = list(map(int, input().split())) type = event[0] if type == 1: speed = event[1] if speed > speed_limit: p += speed_limit_num...
25
764
6,758,400
32743715
import collections n=int(input()) x,v=map(int,input().split()) o=collections.deque() q=0 k=0 for i in range(1,n): s=input() if s[0]=='1': x,v=map(int,s.split()) while len(o)>0 and o[-1]<v: o.pop() k+=1 if s[0]=='2': k+=q q=0 if s[0]=='3': x...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true
2/A
2
A
Python 3
TESTS
13
62
0
210743804
dic={} w="" for i in range(int(input())): a=input().split(" ") dic[a[0]]=dic.get(a[0],0)+int(a[1]) if w=="": w=a[0] elif dic[a[0]]>dic[w]: w=a[0] print(w)
20
62
102,400
216989408
# LUOGU_RID: 118873789 n, k, s = eval(input()), {}, [] for i in range(n): a, b = input().split(' ');k[a] = k.get(a, 0) + int(b);s.append([a, k[a]]) n = max(k.values()) for i, j in s: if k[i] == n and int(j) >= n: print(i);break
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
2/A
2
A
Python 3
TESTS
14
248
307,200
73384445
n = int(input()) names = [] scores = [] for i in range(0, n): name, score = input().split() names.append(name) scores.append(int(score)) # print(names, scores) d = {} for i in range(0, n): name = names[i] score = scores[i] if name not in d: d[name] = [score, [score], [i]] else: ...
20
62
102,400
218372588
d = {} b = [] for _ in range(int(input())): name,score = input().split() if name not in d: d[name] = 0 d[name] += int(score) b.append((name,d[name])) m = max(d.values()) for name, score in b: if d[name]==m and score>=m: print(name) break
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
845/D
845
D
Python 3
TESTS
7
654
0
30130706
def Task485D(): cur_speed = 0 is_outstrip = 0 err_count = 0 event_speed_limit = [] event_count = int(input()) for a in range(event_count): ev =list(map(int, input().split())) if ev[0] == 1: cur_speed = ev[1] err_count = err_count + len(event_speed_li...
25
811
716,800
32199123
n=int(input()) st=[0]*n top=-1 curr_speed=0 ans=0 c=0 while(n>0): n-=1 a=list(map(int,input().split())) if(a[0]==1): curr_speed=a[1] if(top>=0 and curr_speed>st[top]): while(curr_speed>st[top] and top>=0): top-=1 ans+=1 if(a[0]==4...
Educational Codeforces Round 27
ICPC
2,017
2
256
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that af...
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events. Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event. An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car,...
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
null
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120. In the second example Polycarp didn't make any rule violation. In the third example Polycarp should say he didn't notice both "no overtake allowed" that came a...
[{"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "output": "2"}, {"input": "5\n1 100\n3 200\n2\n4\n5", "output": "0"}, {"input": "7\n1 20\n2\n6\n4\n6\n6\n2", "output": "2"}]
1,800
["data structures", "dp", "greedy"]
25
[{"input": "11\r\n1 100\r\n3 70\r\n4\r\n2\r\n3 120\r\n5\r\n3 120\r\n6\r\n1 150\r\n4\r\n3 300\r\n", "output": "2\r\n"}, {"input": "5\r\n1 100\r\n3 200\r\n2\r\n4\r\n5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 20\r\n2\r\n6\r\n4\r\n6\r\n6\r\n2\r\n", "output": "2\r\n"}, {"input": "1\r\n1 100\r\n", "output": "0\r\n"}, {"in...
false
stdio
null
true