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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
186/A | 186 | A | PyPy 3 | TESTS | 41 | 312 | 2,355,200 | 66290590 | first, second = input(), input()
f_len, s_len = len(first), len(second)
if f_len != s_len:
exit(print('NO'))
ix, c = [], 0
for i in range(f_len):
if c > 2:
exit(print('NO'))
if first[i] != second[i]:
ix.append(i)
c += 1
if c == 1:
exit(print('NO'))
if first[ix[0]] == second[ix... | 53 | 92 | 204,800 | 215041802 | if __name__ == "__main__":
S1 = input()
S2 = input()
if len(S1) != len(S2):
print("NO")
else:
c = 0
chars = set()
for i in range(len(S1)):
if S1[i] != S2[i]:
c += 1
chars.add(S1[i])
chars.add(S2[i])
i... | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
552/E | 552 | E | PyPy 3 | TESTS | 5 | 139 | 0 | 95328541 | s=input()
ans=0;
for i,x in enumerate(s):
if x=='*':
for j in range(0,i,2):
s2=f"{s[:j]}({s[j:i]}){s[i:]}"
ans=max(ans,eval(s2))
print(ans) | 69 | 326 | 3,276,800 | 213602925 | s = str(input())
val = eval(s)
n = len(s)
for i in range(-1, n):
if i == -1 or s[i] == '*':
for j in range(i + 1, n + 1):
if j == n or s[j] == '*':
new = s[0 : i + 1] + '(' + s[i + 1 : j] + ')' + s[j : n]
val = max(val, eval(new))
print(val) | Codeforces Round 308 (Div. 2) | CF | 2,015 | 1 | 256 | Vanya and Brackets | Vanya is doing his maths homework. He has an expression of form $$x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$$, where x1, x2, ..., xn are digits from 1 to 9, and sign $$\text{ }$$ represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this express... | The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * .
The number of signs * doesn't exceed 15. | In the first line print the maximum possible value of an expression. | null | Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60). | [{"input": "3+5*7+8*4", "output": "303"}, {"input": "2+3*5", "output": "25"}, {"input": "3*4*5", "output": "60"}] | 2,100 | ["brute force", "dp", "expression parsing", "greedy", "implementation", "strings"] | 69 | [{"input": "3+5*7+8*4\r\n", "output": "303\r\n"}, {"input": "2+3*5\r\n", "output": "25\r\n"}, {"input": "3*4*5\r\n", "output": "60\r\n"}, {"input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5\r\n", "output": "152587890625\r\n"}, {"input": "2*2+2*2\r\n", "output": "16\r\n"}, {"input": "1+1+1+1+1+1+1\r\n", "output": "7\r\n"}, {"inp... | false | stdio | null | true |
451/B | 451 | B | Python 3 | TESTS | 73 | 93 | 12,800,000 | 224830607 | n = int(input())
arr = list(map(int, input().split()))
max_val = -1
flag = 0
l = 0
r = 0
done = 0
for i in range(len(arr)):
if done == 0:
if arr[i] >= max_val and flag == 0:
max_val = arr[i]
elif arr[i] < max_val and flag == 0:
l = i-1
flag = 1
elif arr[i]... | 76 | 77 | 15,974,400 | 204724232 | n = int(input())
l = list(map(int,input().split()))
i = 1
while i<n and l[i]>=l[i-1]:
i += 1
j = i
while j < n and l[j] <= l[j-1]:
j += 1
t = l[:i-1] + l[i-1:j][::-1] + l[j:]
l.sort()
if t == l:
print("yes")
print(i,j)
else:
print("no") | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
247/A | 250 | A | Python 3 | TESTS | 7 | 218 | 0 | 59682556 | from math import *
import time
n=int(input())
l=input().split(" ")
ll=[]
c=0
s=0
for i in range(0,len(l)):
if(s==3):
ll.append(c-1)
c=2
s=1
else:
if(int(l[i])<0):
s=s+1
c=c+1
else:
c=c+1
if(s==3):
ll.append(c-1)
ll.append(1)
else:
ll.append(c)
print(len(ll))
print(*ll)
# print(time.time()-t1) | 69 | 92 | 0 | 156077954 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
c, s, q = 0, 0, 0
d = []
for i in range(n):
q += 1
if w[i] < 0:
c += 1
if c == 3:
s += 1
c = 1
q -= 1
d.append(q)
q = 1
s += 1
d.append(q)
prin... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Paper Work | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n... | The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. | Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them. | null | Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | [{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}] | 1,000 | [] | 69 | [{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n... | false | stdio | import sys
def read_input(input_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
return n, a
def compute_min_k(n, a):
if n == 0:
return 0
folders = 0
current_neg = 0
current_size = 0
for ai in a:
current_s... | true |
204/B | 204 | B | Python 3 | TESTS | 7 | 92 | 0 | 139255546 | import math
cards = int(input())
front = []
back = []
frontBack = {}
foundAnswer = False
for i in range(cards):
pair = list(map(int,input().split(" ")))
front.append(pair[0])
back.append(pair[1])
frontBack[pair[0]] = pair[1]
frontset = set(front)
backset = set(back)
commonElements = []
allElements = f... | 90 | 530 | 36,249,600 | 174821994 | import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
x = Counter()
y = Counter()
M = 1e9 + 7
for i in range(n):
a, b = map(int, input().split())
if a == b:
x[a] += 1
y[a] += 0
else:
x[a] += 1
x[b] += 1
y[a] += 0
y[b] += 1
c =... | Codeforces Round 129 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Cards | The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | null | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | [{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}] | 1,500 | ["binary search", "data structures"] | 90 | [{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n... | false | stdio | null | true |
899/E | 899 | E | Python 3 | TESTS | 6 | 373 | 15,052,800 | 33351655 | from heapq import *
n = int(input())
heap = []
nums = list(map(int, input().strip().split()))
pairs = []
C = 10**9
i = 0
while i < len(nums):
add = nums[i]
cnt = 1
while i+1 < len(nums) and nums[i+1] == add:
cnt += 1
i += 1
pairs.append([C-cnt, cnt, len(pairs), add, len(pairs)-1, l... | 97 | 1,466 | 38,297,600 | 138133134 | import heapq
class Node:
def __init__(self,idx,freq,val) -> None:
self.value=val
self.index=idx
self.occ=freq
self.front=None
self.back=None
class LinkedList:
def __init__(self) -> None:
self.head=None
self.h=[]
self.seen=[False]*200001
heapq.heapify(self... | Codeforces Round 452 (Div. 2) | CF | 2,017 | 2 | 256 | Segments Removal | Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat... | The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.
The second line contains a sequence a1, a2, ..., an (1 ≤ ai ≤ 109) — Vasya's array. | Print the number of operations Vasya should make to remove all elements from the array. | null | In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. I... | [{"input": "4\n2 5 5 2", "output": "2"}, {"input": "5\n6 3 4 1 5", "output": "5"}, {"input": "8\n4 4 4 2 2 100 100 100", "output": "3"}, {"input": "6\n10 10 50 10 50 50", "output": "4"}] | 2,000 | ["data structures", "dsu", "flows", "implementation", "two pointers"] | 97 | [{"input": "4\r\n2 5 5 2\r\n", "output": "2\r\n"}, {"input": "5\r\n6 3 4 1 5\r\n", "output": "5\r\n"}, {"input": "8\r\n4 4 4 2 2 100 100 100\r\n", "output": "3\r\n"}, {"input": "6\r\n10 10 50 10 50 50\r\n", "output": "4\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "100\r\n45 45 45 45 45 45 45 45 45 45 4... | false | stdio | null | true |
899/E | 899 | E | PyPy 3 | TESTS | 6 | 295 | 34,918,400 | 86611867 | import heapq
n = int(input())
a = list(map(int, input().split()))
# idx: l, r, length, val
d = {}
pre, l = None, 0
seg = []
for i, x in enumerate(a):
if pre is None:
pre = x
l = 1
else:
if x == pre:
l+=1
else:
seg.append([l, pre])
pre... | 97 | 1,466 | 38,297,600 | 138133134 | import heapq
class Node:
def __init__(self,idx,freq,val) -> None:
self.value=val
self.index=idx
self.occ=freq
self.front=None
self.back=None
class LinkedList:
def __init__(self) -> None:
self.head=None
self.h=[]
self.seen=[False]*200001
heapq.heapify(self... | Codeforces Round 452 (Div. 2) | CF | 2,017 | 2 | 256 | Segments Removal | Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat... | The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.
The second line contains a sequence a1, a2, ..., an (1 ≤ ai ≤ 109) — Vasya's array. | Print the number of operations Vasya should make to remove all elements from the array. | null | In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. I... | [{"input": "4\n2 5 5 2", "output": "2"}, {"input": "5\n6 3 4 1 5", "output": "5"}, {"input": "8\n4 4 4 2 2 100 100 100", "output": "3"}, {"input": "6\n10 10 50 10 50 50", "output": "4"}] | 2,000 | ["data structures", "dsu", "flows", "implementation", "two pointers"] | 97 | [{"input": "4\r\n2 5 5 2\r\n", "output": "2\r\n"}, {"input": "5\r\n6 3 4 1 5\r\n", "output": "5\r\n"}, {"input": "8\r\n4 4 4 2 2 100 100 100\r\n", "output": "3\r\n"}, {"input": "6\r\n10 10 50 10 50 50\r\n", "output": "4\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "100\r\n45 45 45 45 45 45 45 45 45 45 4... | false | stdio | null | true |
841/B | 841 | B | Python 3 | TESTS | 48 | 732 | 76,697,600 | 73857858 | t=int(input())
a=list(map(int,input().split()))[:t]
b=[]
for i in range(t):
b.append(a[i]%2)
if sum(b)>1:
print("First")
else:
print("Second") | 88 | 358 | 120,115,200 | 215085131 | n = int(input())
a = list(map(int, input().split()))
T = 0
for i in range(n):
if a[i] % 2 == 1:
T += 1
if T == 0:
print("Second")
else:
print("First") | Codeforces Round 429 (Div. 2) | CF | 2,017 | 2 | 256 | Godsend | Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a... | First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | null | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | [{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}] | 1,100 | ["games", "math"] | 88 | [{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0... | false | stdio | null | true |
841/B | 841 | B | Python 3 | TESTS | 48 | 576 | 76,390,400 | 121899660 | i = int(input())
l = list(map(int,input().split()))
a = 0
for x in l:
if x%2 == 1:
a += 1
print('First' if a > 1 else 'Second') | 88 | 373 | 81,510,400 | 81979092 | import sys
input=sys.stdin.buffer.readline
n=int(input())
arr=list(map(int,input().split()))
odd=0
for x in arr:
if x%2==0:
continue
else:
odd=1
break
if sum(arr)%2==1:
print("First")
else:
if odd>0:
print("First")
else:
print("Second")
#unknown_2433 | Codeforces Round 429 (Div. 2) | CF | 2,017 | 2 | 256 | Godsend | Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a... | First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | null | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | [{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}] | 1,100 | ["games", "math"] | 88 | [{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0... | false | stdio | null | true |
451/B | 451 | B | Python 3 | TESTS | 73 | 155 | 8,089,600 | 202174538 | n = int(input())
arr = list(map(int,input().split()))
if arr == sorted(arr):
print('yes')
print(1,1)
else:
f = 0
i = 0
start = n
end = n-1
while i<n-1:
if arr[i]>arr[i+1]:
start = min(i,start)
f = 1
elif f>0 and arr[i]<arr[i+1]:
end = i
... | 76 | 78 | 8,089,600 | 199602444 | from math import ceil
def solve():
n=int(input());a=list(map(int,input().split()))
b=sorted(a)
l,r=None,None
for i in range(n-1,-1,-1):
if a[i]!=b[i]:r=i;break
for i in range(n):
if a[i]!=b[i]:l=i;break
if l==None and r==None:
print("yes");print(1,1);return
c=a[l:r+1]... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
451/B | 451 | B | Python 3 | TESTS | 73 | 78 | 12,800,000 | 205731782 | n=int(input())
lst=list(map(int,input().rstrip().split()))
segct=0
seg=False
segst=1
segend=1
ans="yes"
if n==1:
print("yes")
print(segst,segend)
else:
for i in range(n-1):
if lst[i]>lst[i+1]:
if seg==False:
seg=True
segst=i+1
if seg and lst[i]<ls... | 76 | 78 | 8,089,600 | 202136629 | x = int(input())
l = list(map(int,input().split()))
c = l.copy()
c.sort()
if l == c:
print("yes")
print("1 1")
else:
left,right = 0,x-1
while l[left] == c[left]:
# print(left)
left+=1
while l[right] == c[right] and right>0 :
right-=1
v = l[left:right+1][::-1]
k =... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
863/E | 863 | E | PyPy 3-64 | TESTS | 13 | 592 | 61,337,600 | 203198877 | import sys
n = int(input())
used_nums = set()
intrvs = []
for _ in range(n):
l, r = map(int, sys.stdin.readline().split())
intrvs.append((l, r))
used_nums.add(l)
used_nums.add(r)
used_nums = list(used_nums)
used_nums.sort()
ind_dict = {used_nums[i]:i for i in range(len(used_nums))}
prefs = [0 f... | 55 | 873 | 106,496,000 | 160669876 | from math import ceil, log2
from bisect import bisect_left as bl
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b"": x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
... | Educational Codeforces Round 29 | ICPC | 2,017 | 2 | 256 | Turn Off The TV | Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas... | The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set. | If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them. | null | Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even wi... | [{"input": "3\n1 3\n4 6\n1 7", "output": "1"}, {"input": "2\n0 10\n0 10", "output": "1"}, {"input": "3\n1 2\n3 4\n6 8", "output": "-1"}, {"input": "3\n1 2\n2 3\n3 4", "output": "2"}] | 2,000 | ["data structures", "sortings"] | 55 | [{"input": "3\r\n1 3\r\n4 6\r\n1 7\r\n", "output": "1\r\n"}, {"input": "2\r\n0 10\r\n0 10\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2\r\n3 4\r\n6 8\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n0 500000000\r\n500000001 1000000000\r\n0 1000000000\r\n", "output":... | false | stdio | import bisect
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
intervals = []
for _ in range(n):
l, r = map(int, f.readline().split())
intervals.append((l, r))
# Compute redundant TVs
points = set()... | true |
451/B | 451 | B | Python 3 | TESTS | 73 | 109 | 7,782,400 | 190006705 | n = int(input())
nums = [int(x) for x in input().split()]
found = 0
indices = (1, 1)
i = j = 1
while i < n:
if nums[i-1] > nums[i]:
found += 1
j = i
while j < n and nums[j-1] > nums[j]:
j += 1
indices = (i, j)
if j == n:
break
if nums[i-1] > n... | 76 | 78 | 12,800,000 | 214230101 | n=int(input())
a=list(map(int,input().split()))
i = 0
while i<n-1 and a[i]<a[i+1]:
i+=1
j = i
while j<n-1 and a[j]>a[j+1]:
j+=1
# print(i,j)
if a[:i]+a[i:j+1][::-1]+a[j+1:] == sorted(a):
print("yes")
print(i+1,j+1)
else:
print("no") | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
908/B | 908 | B | Python 3 | TESTS | 3 | 46 | 5,632,000 | 33804678 | class Point:
def __init__(self,i,j):
self.i = i
self.j = j
def move(self,p):
return Point(self.i + p.i,self.j + p.j)
def pos(self,p):
return self.i == p.i and self.j == p.j
def out(self):
return self.i < 0 or self.i >= n or self.j < 0 or self.j >= m
n,m = map(int,... | 46 | 46 | 0 | 160714730 | from itertools import permutations
n, m = (int(c) for c in input().split())
s = '#'*(m+2)
for i in range(n):
s += '#'+input().strip()+'#'
s += '#'*(m+2)
ins = ['0123'.find(c) for c in input().strip()]
c = 0
for d in permutations([1, -1, m+2, -m-2]):
p = s.find('S')
for i in ins:
p += d[i]
if s[p]=='E'... | Good Bye 2017 | CF | 2,017 | 1 | 256 | New Year and Buggy Bot | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The las... | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | null | For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right. | [{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 46 | [{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
377/A | 377 | A | Python 3 | TESTS | 11 | 1,014 | 1,638,400 | 154054436 | mat=[]
seen=dict()
g=dict()
n,m,k = map(int,input().split())
c=0
for i in range(n) :
mat.append(list(input()))
for j in range(m) :
if mat[i][j]=='.' :
mat[i][j]='X'
x=(i,j)
c+=1
p=[x]
rest=0
while p :
i,j=p.pop()
if i<0 or i>=n or j>=m or j<0 :
c... | 89 | 264 | 58,470,400 | 219069063 | dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
N = 1234
a = []
was = [[False] * N for _ in range(N)]
x = [0] * (N * N)
y = [0] * (N * N)
n, m, s = map(int, input().split())
for _ in range(n):
a.append(input())
for i in range(n):
for j in range(m):
was[i][j] = False
found = False
for i in range(n):
for j in r... | Codeforces Round 222 (Div. 1) | CF | 2,013 | 2 | 256 | Maze | Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth... | The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.
Each of the next n lines contains m characters. They describe t... | Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. | null | null | [{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}] | 1,600 | ["dfs and similar"] | 89 | [{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#... | false | stdio | import sys
from collections import deque
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.readlines()
first_line = lines[0].strip().split()
n, m, k = map(int, first_line[:3])
original = [line.strip() ... | true |
743/A | 743 | A | Python 3 | TESTS | 45 | 109 | 307,200 | 49825614 | def findLR(s,a):
start = s[a-1]
l = -1
tmp = a-2
while(tmp>=0):
if start!=s[tmp]:
l = tmp
break
tmp = tmp-1
r = -1
tmp = a
while(tmp<len(s)):
if start!=s[tmp]:
r = tmp
break
tmp = tmp+1
return[a-l-1,r-a+1]
... | 56 | 46 | 0 | 150081613 | ## Vi el tutorial, mucho más facil de lo que pensaba, ver los codigos anteriores
n, a, b = map(int, input().split())
ars = input()
airports = int(ars, 2)
home_airport = ars[a-1]
dest_airport = ars[b-1]
#Si los aeropuertos son iguales el viaje es gratis
if home_airport == dest_airport:
print(0)
#Si no nos movemos ... | Codeforces Round 384 (Div. 2) | CF | 2,016 | 2 | 256 | Vladik and flights | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has uni... | The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th char... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | null | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | [{"input": "4 1 4\n1010", "output": "1"}, {"input": "5 5 2\n10110", "output": "0"}] | 1,200 | ["constructive algorithms", "greedy", "implementation"] | 56 | [{"input": "4 1 4\r\n1010\r\n", "output": "1"}, {"input": "5 5 2\r\n10110\r\n", "output": "0"}, {"input": "10 9 5\r\n1011111001\r\n", "output": "1"}, {"input": "7 3 7\r\n1110111\r\n", "output": "0"}, {"input": "1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 3 3\r\n1001011011\r\n", "output": "0"}, {"input": "1 1 1\r\n0\... | false | stdio | null | true |
863/E | 863 | E | PyPy 3-64 | TESTS | 13 | 1,029 | 86,937,600 | 160667289 | from sys import stdin
from math import ceil, log2
from bisect import bisect_left as bl
from collections import defaultdict
input = stdin.readline
read = lambda: map(int, input().strip().split())
def left(idx):
return 2 * idx
def right(idx):
return 2 * idx + 1
class SegmentTree:
def __init__(self, arr... | 55 | 888 | 26,521,600 | 200898326 | n = int(input())
lis = []
for i in range(n):
a, b = map(int, input().split())
lis.append([a, b, i+1])
lis.sort()
i = 1
ans = -1
while i<n:
if lis[i][1]<=lis[i-1][1]:
ans = lis[i][2]
print(ans)
exit(0)
elif( lis[i][0] <= lis[i-1][0] and lis[i][1] >= lis[i-1][1]):
ans = lis[i-1][2]
print(ans)
exit(0)
lis... | Educational Codeforces Round 29 | ICPC | 2,017 | 2 | 256 | Turn Off The TV | Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas... | The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set. | If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them. | null | Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even wi... | [{"input": "3\n1 3\n4 6\n1 7", "output": "1"}, {"input": "2\n0 10\n0 10", "output": "1"}, {"input": "3\n1 2\n3 4\n6 8", "output": "-1"}, {"input": "3\n1 2\n2 3\n3 4", "output": "2"}] | 2,000 | ["data structures", "sortings"] | 55 | [{"input": "3\r\n1 3\r\n4 6\r\n1 7\r\n", "output": "1\r\n"}, {"input": "2\r\n0 10\r\n0 10\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2\r\n3 4\r\n6 8\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n0 500000000\r\n500000001 1000000000\r\n0 1000000000\r\n", "output":... | false | stdio | import bisect
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
intervals = []
for _ in range(n):
l, r = map(int, f.readline().split())
intervals.append((l, r))
# Compute redundant TVs
points = set()... | true |
54/A | 54 | A | Python 3 | TESTS | 21 | 156 | 7,065,600 | 36566851 | n,k=map(int,input().split())
li=list(map(int,input().split()))
c=li[0]
cur=0
b=1
ans=0
for i in range(1,n+1):
cur+=1
if b<=c and li[b]==i:
ans+=1
cur=0
elif cur==k:
ans+=1
cur=0
print(ans) | 65 | 92 | 0 | 203395353 | I = lambda: map(int, input().split())
n, k = I()
C, *X = I()
X = [0] + X + [n+1]
print(C + sum((X[i+1]-X[i]-1)//k for i in range(C+1))) | Codeforces Beta Round 50 | CF | 2,011 | 2 | 256 | Presents | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c... | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N).
The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating ... | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | null | null | [{"input": "5 2\n1 3", "output": "3"}, {"input": "10 1\n3 6 7 8", "output": "10"}] | 1,300 | ["implementation"] | 65 | [{"input": "5 2\r\n1 3\r\n", "output": "3"}, {"input": "10 1\r\n3 6 7 8\r\n", "output": "10"}, {"input": "5 5\r\n1 3\r\n", "output": "1"}, {"input": "10 3\r\n3 3 6 9\r\n", "output": "3"}, {"input": "5 2\r\n0\r\n", "output": "2"}, {"input": "1 1\r\n0\r\n", "output": "1"}, {"input": "5 1\r\n0\r\n", "output": "5"}, {"inpu... | false | stdio | null | true |
993/C | 993 | C | PyPy 3 | TESTS | 8 | 702 | 1,126,400 | 39304586 | from collections import defaultdict
import sys
n, m = map(int, sys.stdin.readline().split())
l, r = list(map(int, sys.stdin.readline().split())), list(map(int, sys.stdin.readline().split()))
destroys = defaultdict(set)
for x in l:
for y in r:
destroys[x+y].add((x, 0))
destroys[x+y].add((y, 1))
max... | 88 | 1,981 | 3,686,400 | 163849332 | from itertools import combinations
[n, m] = map(int, input().strip().split())
y1s = list(map(int, input().strip().split()))
y2s = list(map(int, input().strip().split()))
pts = {}
for i1, y1 in enumerate(y1s):
for i2, y2 in enumerate(y2s):
y = y1 + y2
if y in pts:
pts[y][0].add(i1)
pts[y][1].add(i2)
els... | Codeforces Round 488 by NEAR (Div. 1) | CF | 2,018 | 2 | 256 | Careful Maneuvering | There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$-100$$$, while the second group is posit... | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 60$$$), the number of enemy spaceships with $$$x = -100$$$ and the number of enemy spaceships with $$$x = 100$$$, respectively.
The second line contains $$$n$$$ integers $$$y_{1,1}, y_{1,2}, \ldots, y_{1,n}$$$ ($$$|y_{1,i}| \le 10\,000$$$) — t... | Print a single integer – the largest number of enemy spaceships that can be destroyed. | null | In the first example the first spaceship can be positioned at $$$(0, 2)$$$, and the second – at $$$(0, 7)$$$. This way all the enemy spaceships in the first group and $$$6$$$ out of $$$9$$$ spaceships in the second group will be destroyed.
In the second example the first spaceship can be positioned at $$$(0, 3)$$$, an... | [{"input": "3 9\n1 2 3\n1 2 3 7 8 9 11 12 13", "output": "9"}, {"input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "10"}] | 2,100 | ["bitmasks", "brute force", "geometry"] | 88 | [{"input": "3 9\r\n1 2 3\r\n1 2 3 7 8 9 11 12 13\r\n", "output": "9\r\n"}, {"input": "5 5\r\n1 2 3 4 5\r\n1 2 3 4 5\r\n", "output": "10\r\n"}, {"input": "50 50\r\n744 333 562 657 680 467 357 376 759 311 371 327 369 172 286 577 446 922 16 69 350 92 627 852 878 733 148 857 663 969 131 250 563 665 67 169 178 625 975 457 4... | false | stdio | null | true |
863/E | 863 | E | PyPy 3-64 | TESTS | 13 | 1,996 | 120,217,600 | 199358828 | import sys
input = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, data, default=float('inf'), func=min):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bi... | 55 | 904 | 33,587,200 | 129463574 | n = int(input())
lis = []
for i in range(n):
a, b = map(int, input().split())
lis.append([a, b, i+1])
lis.sort()
i = 1
ans = -1
#Turn off the TV
while i<n:
if lis[i][1]<=lis[i-1][1]:
ans = lis[i][2]
print(ans)
exit(0)
elif( lis[i][0] <= lis[i-1][0] and lis[i][1] >= lis[i-1][1]):
ans = lis[i-1][2]
print(an... | Educational Codeforces Round 29 | ICPC | 2,017 | 2 | 256 | Turn Off The TV | Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas... | The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set. | If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them. | null | Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even wi... | [{"input": "3\n1 3\n4 6\n1 7", "output": "1"}, {"input": "2\n0 10\n0 10", "output": "1"}, {"input": "3\n1 2\n3 4\n6 8", "output": "-1"}, {"input": "3\n1 2\n2 3\n3 4", "output": "2"}] | 2,000 | ["data structures", "sortings"] | 55 | [{"input": "3\r\n1 3\r\n4 6\r\n1 7\r\n", "output": "1\r\n"}, {"input": "2\r\n0 10\r\n0 10\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2\r\n3 4\r\n6 8\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n0 500000000\r\n500000001 1000000000\r\n0 1000000000\r\n", "output":... | false | stdio | import bisect
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
intervals = []
for _ in range(n):
l, r = map(int, f.readline().split())
intervals.append((l, r))
# Compute redundant TVs
points = set()... | true |
451/B | 451 | B | PyPy 3-64 | TESTS | 74 | 109 | 17,510,400 | 207614679 | def Line():
return [int(x) for x in input().split()]
n = int(input())
lst = Line()
l,r = 0, len(lst)-1
c1,c2 = False,False
while True:
if l == len(lst)-1 or r == 0 or c1 and c2:
break
if lst[l] > lst[l+1]:
c1 = True
if lst[r] < lst[r-1]:
c2 = True
if lst[l] < lst[l+1]:
... | 76 | 78 | 12,800,000 | 216685738 | n = int(input())
array = list(map(int, input().split()))
size = len(array)
s = sorted(array)
l, r = 0, 0
for i in range(size):
if array[i] != s[i]:
l = i
break
for i in range(size-1, -1, -1):
if array[i] != s[i]:
r = i
break
# print(l, r)
for i in range(l, r):
if array[i] <... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
81/B | 81 | B | Python 3 | TESTS | 23 | 122 | 0 | 31930868 | ans = input().replace("...", " ...")
ans = ans.replace(" ,", ",").replace(",", ", ")
while " " in ans:
ans = ans.replace(" ", " ")
if ans[0] == " ": ans = ans[1:]
if ans[-1] == " ": ans = ans[:-1]
print(ans, end="") | 45 | 124 | 0 | 200852400 | t = input().split()
t = ' '.join(t)
t = t.replace(', ', ',')
t = t.replace(' ,', ',')
t = t.replace(',', ', ')
t = t.replace(' ...', '...')
t = t.replace('... ', '...')
t = t.replace('...', ' ...')
if t[0] == ' ':
t = t[1: ]
if t[-1] == ' ':
t = t[: -1]
print(t) | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
899/E | 899 | E | Python 3 | PRETESTS | 6 | 1,029 | 15,872,000 | 33348698 | import bisect
class TreeSet(object):
"""
Binary-tree set like java Treeset.
Duplicate elements will not be added.
When added new element, TreeSet will be sorted automatically.
"""
def __init__(self, elements):
self._treeset = []
self.addAll(elements)
def addAll(self, elemen... | 97 | 1,466 | 38,297,600 | 138133134 | import heapq
class Node:
def __init__(self,idx,freq,val) -> None:
self.value=val
self.index=idx
self.occ=freq
self.front=None
self.back=None
class LinkedList:
def __init__(self) -> None:
self.head=None
self.h=[]
self.seen=[False]*200001
heapq.heapify(self... | Codeforces Round 452 (Div. 2) | CF | 2,017 | 2 | 256 | Segments Removal | Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat... | The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.
The second line contains a sequence a1, a2, ..., an (1 ≤ ai ≤ 109) — Vasya's array. | Print the number of operations Vasya should make to remove all elements from the array. | null | In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. I... | [{"input": "4\n2 5 5 2", "output": "2"}, {"input": "5\n6 3 4 1 5", "output": "5"}, {"input": "8\n4 4 4 2 2 100 100 100", "output": "3"}, {"input": "6\n10 10 50 10 50 50", "output": "4"}] | 2,000 | ["data structures", "dsu", "flows", "implementation", "two pointers"] | 97 | [{"input": "4\r\n2 5 5 2\r\n", "output": "2\r\n"}, {"input": "5\r\n6 3 4 1 5\r\n", "output": "5\r\n"}, {"input": "8\r\n4 4 4 2 2 100 100 100\r\n", "output": "3\r\n"}, {"input": "6\r\n10 10 50 10 50 50\r\n", "output": "4\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "100\r\n45 45 45 45 45 45 45 45 45 45 4... | false | stdio | null | true |
853/B | 853 | B | Python 3 | TESTS | 43 | 498 | 10,035,200 | 30186799 | def main():
n, m, k = map(int, input().split())
ff, tt = [], []
for _ in range(m):
day, f, t, city = map(int, input().split())
if f:
ff.append((-day, f, city))
else:
tt.append((day, t, city))
for ft in ff, tt:
cnt, costs = n, [1000001] * (n + 1)
... | 83 | 389 | 19,251,200 | 230895494 | g = lambda: map(int, input().split())
n, m, k = g()
F, T = [], []
e = int(3e11)
for i in range(m):
d, f, t, c = g()
if f: F.append((d, f, c))
else: T.append((-d, t, c))
for p in [F, T]:
C = [e] * (n + 1)
s = n * e
q = []
p.sort()
for d, t, c in p:
if C[t] > c:
s +=... | Codeforces Round 433 (Div. 1, based on Olympiad of Metropolises) | CF | 2,017 | 1 | 512 | Jury Meeting | Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for... | The first line of input contains three integers n, m and k (1 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ k ≤ 106).
The i-th of the following m lines contains the description of the i-th flight defined by four integers di, fi, ti and ci (1 ≤ di ≤ 106, 0 ≤ fi ≤ n, 0 ≤ ti ≤ n, 1 ≤ ci ≤ 106, exactly one of fi and ti equals zero), the da... | Output the only integer that is the minimum cost of gathering all jury members in city 0 for k days and then sending them back to their home cities.
If it is impossible to gather everybody in Metropolis for k days and then send them back to their home cities, output "-1" (without the quotes). | null | The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more.
In the second sample it is impossible to send jury member from city 2 b... | [{"input": "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500", "output": "24500"}, {"input": "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000", "output": "-1"}] | 1,800 | ["greedy", "sortings", "two pointers"] | 83 | [{"input": "2 6 5\r\n1 1 0 5000\r\n3 2 0 5500\r\n2 2 0 6000\r\n15 0 2 9000\r\n9 0 1 7000\r\n8 0 2 6500\r\n", "output": "24500\r\n"}, {"input": "2 4 5\r\n1 2 0 5000\r\n2 1 0 4500\r\n2 1 0 3000\r\n8 0 1 6000\r\n", "output": "-1\r\n"}, {"input": "2 5 5\r\n1 1 0 1\r\n2 2 0 100\r\n3 2 0 10\r\n9 0 1 1000\r\n10 0 2 10000\r\n"... | false | stdio | null | true |
863/E | 863 | E | Python 3 | TESTS | 3 | 31 | 0 | 174565342 | n=int(input())
li=[]
d={}
for i in range(n):
start,end=list(map(int,input().split()))
li.append([start,end])
if (start,end) not in d:
d[(start,end)]=i+1
li.sort()
start,end=li[0]
isSingle=True
flag=False
for i in range(1,n):
l,r=li[i]
if r<=end:
print(d[(l,r)])
flag=True
... | 55 | 904 | 35,942,400 | 169894468 | import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n = int(input())
LRI = []
for i in range(n):
l, r = map(int, input().split())
LRI.append((l, r, i))
LRI.sort()
cur_l = LRI[0][0]
cur_r = LRI[0][1]
cur_idx = LRI[0][2]
for j in range(1, n):
l, r, i = LRI[j]
if l <= cur... | Educational Codeforces Round 29 | ICPC | 2,017 | 2 | 256 | Turn Off The TV | Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas... | The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set. | If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them. | null | Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even wi... | [{"input": "3\n1 3\n4 6\n1 7", "output": "1"}, {"input": "2\n0 10\n0 10", "output": "1"}, {"input": "3\n1 2\n3 4\n6 8", "output": "-1"}, {"input": "3\n1 2\n2 3\n3 4", "output": "2"}] | 2,000 | ["data structures", "sortings"] | 55 | [{"input": "3\r\n1 3\r\n4 6\r\n1 7\r\n", "output": "1\r\n"}, {"input": "2\r\n0 10\r\n0 10\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2\r\n3 4\r\n6 8\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n0 500000000\r\n500000001 1000000000\r\n0 1000000000\r\n", "output":... | false | stdio | import bisect
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
intervals = []
for _ in range(n):
l, r = map(int, f.readline().split())
intervals.append((l, r))
# Compute redundant TVs
points = set()... | true |
81/B | 81 | B | PyPy 3 | TESTS | 24 | 280 | 0 | 92889862 | s = input()
s = s.split(",")
def clean(i):
i = [ j for j in i.split(" ") if len(j) ]
return " ".join(i)
s = [ clean(i) for i in s]
s = [ " ...".join(i.split("...")) if "." in i else i for i in s ]
s = [ i.strip() for i in s]
s = ", ".join(s)
print(s.strip()) | 45 | 124 | 409,600 | 197532557 | # LUOGU_RID: 104833499
import re
s = input()
s = re.sub('\s*,', ', ', s)
s = re.sub('\s*\.\.\.\s*', ' ...', s)
s = re.sub('\s*\ \ \s*', ' ', s)
print(s.strip()) | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
269/A | 269 | A | PyPy 3-64 | TESTS | 23 | 810 | 16,588,800 | 210815994 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = []
for _ in range(N):
k,a = map(int, input().split())
A.append([k,a])
A.sort()
pre = 0
for i,(k,a) in enumerate(A):
if pre:
a+=1
pre=0
added = False
while a>4:
a = (a-1)//4+1
k+=1
... | 46 | 528 | 7,884,800 | 143307621 | t = [tuple(map(int, input().split())) for i in range(int(input()))]
print((max(2 * x + len(bin(y - 1)) for x, y in t) + 1) // 2 - 1) | Codeforces Round 165 (Div. 1) | CF | 2,013 | 2 | 256 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. | Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. | null | Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2. | [{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}] | 1,600 | ["greedy", "math"] | 46 | [{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ... | false | stdio | null | true |
14/B | 14 | B | PyPy 3 | TESTS | 6 | 248 | 0 | 101239646 | n, x = [int(j) for j in input().split()]
ref = 1001 * [0]
for j in range(n):
a, b = sorted([int(j) for j in input().split()])
for k in range(a, b + 1):
ref[k] += 1
def check(index):
if index >= 0 and index < 1001:
return ref[index] == n
return False
d = 0
while True:
if check(x - d) ... | 52 | 92 | 0 | 193742889 | n,x=[int(x) for x in input().split()];l1=[];l2=[]
for i in range(n):
a=[int(x) for x in input().split()]; a.sort()
l1.append(a[0]);l2.append(a[1])
start=max(l1);end=min(l2)
if start>end: print(-1)
elif x<start: print(start-x)
elif x>end: print(x-end)
else: print(0) | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
847/E | 847 | E | Python 3 | TESTS | 3 | 31 | 102,400 | 205386709 | input()
treats_positions = []
pacman_positions = []
for i, cell_type in enumerate(input()):
if cell_type == '*':
treats_positions.append(i)
elif cell_type == 'P':
pacman_positions.append(i)
def is_enough_go_left_first(time_limit) -> bool:
t_i = 0
for pacman_position in pacman_position... | 77 | 202 | 5,120,000 | 218466649 | n = int(input())
string = input()
player = []
food = []
for i in range(len(string)):
if string[i] == "*":
food.append(i)
elif string[i] == "P":
player.append(i)
def check(t):
idx = 0
for i in range(len(player)):
loc = player[i]
if idx == len(food):break
l = food... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 1 | 256 | Packmen | A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.
Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.
In the initial mome... | The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field.
The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is... | Print minimum possible time after which Packmen can eat all asterisks. | null | In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ... | [{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}] | 1,800 | ["binary search", "dp"] | 77 | [{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP.... | false | stdio | null | true |
584/C | 584 | C | PyPy 3-64 | TESTS | 8 | 62 | 0 | 210788258 | n,t=map(int,input().split())
s1=input()
s2=input()
difs=[]
for i in range(n):
if s1[i]!=s2[i]:
difs.append(i)
if len(difs)>2*t:
print(-1)
exit()
swaps=set(difs)
s3=list(s1)
for i in range(len(difs)):
if i<len(difs)-t:
s3[difs[i]]=s2[difs[i]]
elif i>t:
s3[difs[i]]=s1[difs[i]]
else:
s3[difs[i]]='a'
if s1[... | 78 | 139 | 2,969,600 | 13447337 | def read_numbers():
return list(map(int, input().split()))
def get_other_char(a, b):
for c in 'abc':
if c != a and c != b:
return c
n, t = read_numbers()
word1 = input()
word2 = input()
# find a word, that has minimal distance to both of them
# first, number of differences
diffs = len([id... | Codeforces Round 324 (Div. 2) | CF | 2,015 | 1 | 256 | Marina and Vasya | Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ... | The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).
The second line contains string s1 of length n, consisting of lowercase English letters.
The third line contain string s2 of length n, consisting of lowercase English letters. | Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. | null | null | [{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}] | 1,700 | ["constructive algorithms", "greedy", "strings"] | 78 | [{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"... | false | stdio | import sys
def hamming(s1, s2):
return sum(c1 != c2 for c1, c2 in zip(s1, s2))
def solution_exists(n, t, s1, s2):
a = sum(c1 == c2 for c1, c2 in zip(s1, s2))
d = n - a
min_k = max(d - t, 0)
max_k = min(d // 2, a + d - t)
return min_k <= max_k
def main():
input_path = sys.argv[1]
outpu... | true |
584/C | 584 | C | PyPy 3-64 | TESTS | 8 | 93 | 3,481,600 | 194526555 | # Problem: C. Marina and Vasya
# Contest: Codeforces - Codeforces Round #324 (Div. 2)
# URL: https://codeforces.com/problemset/problem/584/C
# Memory Limit: 256 MB
# Time Limit: 1000 ms
import sys
import bisect
import random
import io, os
from bisect import *
from collections import *
from contextlib import redirect_s... | 78 | 139 | 14,233,600 | 230147474 | import string
from os import path
from sys import stdin, stdout
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
stdout.write(end)
de... | Codeforces Round 324 (Div. 2) | CF | 2,015 | 1 | 256 | Marina and Vasya | Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ... | The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).
The second line contains string s1 of length n, consisting of lowercase English letters.
The third line contain string s2 of length n, consisting of lowercase English letters. | Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. | null | null | [{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}] | 1,700 | ["constructive algorithms", "greedy", "strings"] | 78 | [{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"... | false | stdio | import sys
def hamming(s1, s2):
return sum(c1 != c2 for c1, c2 in zip(s1, s2))
def solution_exists(n, t, s1, s2):
a = sum(c1 == c2 for c1, c2 in zip(s1, s2))
d = n - a
min_k = max(d - t, 0)
max_k = min(d // 2, a + d - t)
return min_k <= max_k
def main():
input_path = sys.argv[1]
outpu... | true |
731/B | 731 | B | Python 3 | TESTS | 1 | 30 | 0 | 189846734 | session = int(input())
teams = list(map(int,input().split()))
for i in range(session - 1):
if teams[i] < 0:
print('NO')
break
teams[i+1] -= teams[i] % 2
if teams[-1] % 2 == 0:
print('YES')
else:
print('NO') | 79 | 124 | 20,480,000 | 209549101 | input()
p=0
for x in map(int, input().split()):
p=1<<20 if x<p else p^x&1
print('NO' if p>0 else 'YES') | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Coupons and Discounts | The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu... | The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. | If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). | null | In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon n... | [{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}] | 1,100 | ["constructive algorithms", "greedy"] | 79 | [{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu... | false | stdio | null | true |
192/B | 192 | B | PyPy 3 | TESTS | 12 | 218 | 102,400 | 104135537 | from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst = lambda: list(map(int, input().split()))
for i in range(1):#nmbr():
n=nmbr()
a=lst()
PI=float('inf')
dp=[0]*n
for i in range(n):
prev=pprev=PI
if i-1>=0:prev=dp[i-1]
if i-2>=0:pprev=dp[i-2]
dp[i]=min(... | 85 | 92 | 0 | 172992538 | n=int(input())
a=list(map(int,input().split()))
day_0=a[0]
day_n=a[n-1]
mini_s=2**31
mini=2**31
for i in range(0,n-1):
temp=max(a[i],a[i+1])
mini=min(mini,temp)
mini=min(a[0],mini,a[n-1])
print(mini) | Codeforces Round 121 (Div. 2) | CF | 2,012 | 2 | 256 | Walking in the Rain | In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from ... | The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103). | Print a single number — the sought number of days. | null | In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ... | [{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}] | 1,100 | ["brute force", "implementation"] | 85 | [{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 ... | false | stdio | null | true |
670/F | 670 | F | PyPy 3-64 | TESTS | 3 | 46 | 0 | 211687507 | s = input()
a = input()
m = {
'0':0,
'1':0,
'2':0,
'3':0,
'4':0,
'5':0,
'6':0,
'7':0,
'8':0,
'9':0}
for i in s:
m[i] += 1
for i in a:
m[i] -= 1
for i in range(1, len(s)):
u = len(s) - i
fl = True
if len(str(u)) < len(s) - i == 0:
fl = False
for j i... | 118 | 436 | 14,028,800 | 20372817 | import sys
def main():
a = sys.stdin.readline().strip()
b = sys.stdin.readline().strip()
if a == "01" or a == "10":
print("0")
return
cnt = [0] * 256
for i in map(ord, a):
cnt[i] += 1
n = sum(cnt)
l = 0
for i in range(1, 8):
if i == le... | Codeforces Round 350 (Div. 2) | CF | 2,016 | 2 | 256 | Restore a Number | Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.
Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substri... | The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000.
The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes.
It is guaranteed that the input data is correct, and the answer always exists. | Print the smalles integer n which Vasya could pass to Kate. | null | null | [{"input": "003512\n021", "output": "30021"}, {"input": "199966633300\n63", "output": "3036366999"}] | 2,300 | ["brute force", "constructive algorithms", "strings"] | 118 | [{"input": "003512\r\n021\r\n", "output": "30021\r\n"}, {"input": "199966633300\r\n63\r\n", "output": "3036366999\r\n"}, {"input": "01\r\n0\r\n", "output": "0\r\n"}, {"input": "0000454312911\r\n9213544\r\n", "output": "92135440000\r\n"}, {"input": "13\r\n3\r\n", "output": "3\r\n"}, {"input": "00010454312921\r\n9213544\... | false | stdio | null | true |
192/B | 192 | B | Python 3 | TESTS | 12 | 92 | 0 | 183192060 | listTile = []
def runSolution():
n = int(input())
mas = input().split(" ")
for el in mas:
listTile.append(int(el))
k = 0
while True:
if listTile[len(listTile)-1] <= 0:
print(k)
return
for i in range(0, len(listTile)-2):
if listTile[i] <=... | 85 | 92 | 0 | 195573869 | n=int(input())
l=list(map(int,input().split()))
p=min(l[0],l[-1])
g=5
for i in range(p):
while i in l:
o=l.index(i)
l[o]="."
if l[o-1]=="." or l[o+1]==".":p=i;g=3;break
if g==3:break
print(p) | Codeforces Round 121 (Div. 2) | CF | 2,012 | 2 | 256 | Walking in the Rain | In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from ... | The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103). | Print a single number — the sought number of days. | null | In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ... | [{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}] | 1,100 | ["brute force", "implementation"] | 85 | [{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 ... | false | stdio | null | true |
186/A | 186 | A | Python 3 | TESTS | 47 | 248 | 716,800 | 90202343 | def comparingStrings():
s1=input()
s2=input()
if len(s1)!=len(s2):
print("NO")
return
c=0
i=0
while i<len(s1):
dc=0
if s1[i]!=s2[i]:
if i==len(s1)-1:
print("NO")
return
elif s1[i+1]==s2[i] and s1[i]==s2[i+1]:... | 53 | 92 | 204,800 | 218389219 | a, b = input(), input()
d = 0
ghapla = False
if len(a)!=len(b) or set(a)!=set(b): print('NO')
else:
for i in range(len(a)):
if a[i]!=b[i]: d+=1
if d>2:
ghapla = True
break
print('NO' if ghapla else 'YES') | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
605/B | 605 | B | Python 3 | TESTS | 26 | 1,153 | 15,052,800 | 15904854 | readInts=lambda: list(map(int, input().split()))
n,m=readInts()
edge=[]
for _ in range(m):
l,f=readInts()
if f==1:
f=-1
edge+=[(l,f,_)]
edge.sort()
ok=True
cnt=0;ret=[(0,0)]*m
u=2;v=3;t=2
for e in edge:
if e[1]==-1:
ret[e[2]]=(1,t)
cnt+=t-2
t+=1
elif cnt<=0:
o... | 76 | 576 | 28,979,200 | 231030378 | f = lambda: map(int, input().split())
n, m = f()
p = []
for i in range(m):
a, b = f()
p.append((a, 1 - b, i))
p.sort()
k = j = 0
s = [0] * m
u, v = 1, 3
for a, b, i in p:
if not b:
k += j
s[i] = (j + 1, j + 2)
j += 1
elif k:
k -= 1
s[i] = (u, v)
if v - u -... | Codeforces Round 335 (Div. 1) | CF | 2,015 | 2 | 256 | Lazy Student | Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin... | The first line of the input contains two integers n and m ($$2 \leq n \leq 100\ 000, 1 \leq m \leq 100\ 000, n - 1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertices and the number of edges in the graph.
Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109,... | If Vladislav has made a mistake and such graph doesn't exist, print - 1.
Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, mus... | null | null | [{"input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2"}, {"input": "3 3\n1 0\n2 1\n3 1", "output": "-1"}] | 1,700 | ["constructive algorithms", "data structures", "graphs"] | 76 | [{"input": "4 5\r\n2 1\r\n3 1\r\n4 0\r\n1 1\r\n5 0\r\n", "output": "2 4\r\n1 4\r\n3 4\r\n3 1\r\n3 2\r\n"}, {"input": "3 3\r\n1 0\r\n2 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n7 1\r\n", "output": "1 2\r\n"}, {"input": "3 2\r\n8 1\r\n9 1\r\n", "output": "1 2\r\n1 3\r\n"}, {"input": "3 3\r\n4 1\r\n5 0\r\n7 1\... | false | stdio | import sys
from collections import deque
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
input_lines = f.read().splitlines()
with open(output_path) as f:
reference_output = f.read().strip()
with open(sub... | true |
81/B | 81 | B | Python 3 | TESTS | 4 | 92 | 0 | 31930489 | s = input().split(",")
for j in range(len(s)):
el = s[j]
i = 0
for vv in el.replace("...", " ...").split():
if len(vv) > 0:
print((" " if i > 0 else "") + vv, end="")
i += 1
if j + 1 < len(s):
print(", ", end="") | 45 | 124 | 512,000 | 158761717 | s = input()
lst = []
i = 0
while i < len(s):
if s[i].isdigit():
num = ''
while i < len(s) and s[i].isdigit():
num += s[i]
i += 1
lst.append(num)
continue
if s[i] == '.':
lst.append('...')
i += 2
elif s[i] != ' ':
lst.append(s[i]... | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
81/B | 81 | B | PyPy 3 | TESTS | 4 | 278 | 0 | 92889570 | s = input()
s = s.split(",")
s = [ " ...".join(i.split("...")) if "." in i else i for i in s ]
s = [ i.strip() for i in s]
s = ", ".join(s)
print(s) | 45 | 124 | 6,758,400 | 125649588 | line = input()
b = []
for e in line.split(','):
c = [' '.join(ee.split()) for ee in e.split('...')]
b.append(' ...'.join(c).strip())
print(', '.join(b).strip()) | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
985/B | 985 | B | PyPy 3 | TESTS | 12 | 639 | 29,696,000 | 129797626 | n, m = map(int, input().split())
colCount = [0] * m
for i in range(n):
colCount = [col + entry for col, entry in zip(colCount, (int(s) for s in input()))]
if colCount.count(1) < n:
print("YES")
else:
print("NO") | 67 | 140 | 1,228,800 | 58690510 | R = lambda : map(int, input().split())
n,m = R()
a = []
b = 0
c = 0
for i in range(n):
s = int(input(),2)
a.append(s)
c |=s&b
b |=s
print(('YES','NO')[all(i&~c for i in a)]) | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Switches and Lamps | You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.
Initially all m lamps are t... | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.
The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.
It is guaranteed that if you press all... | Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. | null | null | [{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}] | 1,200 | ["implementation"] | 67 | [{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\... | false | stdio | null | true |
451/B | 451 | B | PyPy 3-64 | TESTS | 73 | 93 | 18,227,200 | 225631284 | n=int(input())
a=list(map(int,input().split()))
u=[]
for i in a :
u.append(i)
u.sort()
oa=[]
o=[-1,-1]
for i in range(0,n) :
j=i
while j<n-1 and a[j]>=a[j+1] :
if j==i :
o[0]=j+1
oa.append(a[j])
j+=1
oa.append(a[j])
o[1]=j+1
if j!=i :
break
p=0
for i i... | 76 | 78 | 12,800,000 | 217513695 | x = int(input())
l = list(map(int, input().split()))
c = sorted(l)
if l == c:
print("yes")
print("1 1")
else:
left, right = 0, x - 1
while l[left] == c[left]:
left += 1
while l[right] == c[right] and right > 0:
right -= 1
v = l[left:right + 1][::-1]
k = c[left:right + 1]
... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
451/B | 451 | B | PyPy 3-64 | TESTS | 73 | 93 | 15,667,200 | 189999151 | N = int(input())
nums = list(map(int,input().split()))
nums.append(float("inf"))
left = 0
count = 0
right = 0
ans = []
while right < len(nums):
if nums[left] < nums[right]:
if right - left != 1:
ans.append([left + 1,right])
left = right
right+=1
if len(ans) == 0:
print... | 76 | 78 | 12,800,000 | 219412086 | # Read the size of the array
n = int(input())
# Read the array
a = list(map(int, input().split()))
# Create a sorted version of the array
sorted_a = sorted(a)
# Find the first and last index where the original and sorted arrays differ
start = -1
end = -1
for i in range(n):
if a[i] != sorted_a[i]:
if star... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
451/B | 451 | B | PyPy 3-64 | TESTS | 73 | 93 | 13,619,200 | 226878791 | n = int(input())
a = [int(x) for x in input().split(' ')]
l = 0
r = 0
inorder = True
for i in range(n-1):
if a[i] > a[i+1]:
if not inorder:
r += 1
elif inorder:
l = i
r = i+1
inorder = not inorder
elif a[i] < a[i+1] and not inorder:
a = a[:l] + sorted(a[l:r+1]) + a[r+1:]
for... | 76 | 78 | 12,902,400 | 207293751 | def main():
n = int(input())
a = list(map(int, input().split()))
b = sorted(a, reverse=True)
c = sorted(a)
start = -1
for i in range(n - 1):
if a[i] > a[i + 1]:
start = i
break
if start == 0 and a == b:
print("yes\n{} {}".format(1, n))
return
... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
908/B | 908 | B | PyPy 3 | TESTS | 3 | 124 | 2,457,600 | 116974072 | import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import permutations
inf = float("inf")
# input = sys.stdin.readline
flush = lambda: sys.stdout.flush
comb = lambda x, y: (factorial(x) // factorial(y)) // fac... | 46 | 46 | 0 | 161042700 | import sys
input = sys.stdin.readline
from itertools import permutations
n, m = map(int, input().split())
g = [input()[:-1] for _ in range(n)]
s = input()[:-1]
a1, b1 = 0, 0
c1, d1 = 0, 0
for i in range(n):
for j in range(m):
if g[i][j] == 'S':
a1 = i
b1 = j
if g[i][j] == ... | Good Bye 2017 | CF | 2,017 | 1 | 256 | New Year and Buggy Bot | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The las... | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | null | For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right. | [{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 46 | [{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
908/B | 908 | B | PyPy 3 | TESTS | 3 | 124 | 0 | 92967537 | n,m=[int(n) for n in input().split()]
mat=[]
arr=[]
for i in range(n):
s1=input()
arr=list(s1)
mat.append(arr)
arr=[]
s=input()
count=0
for i in range(n):
for j in range(m):
if(mat[i][j]=="S"):
start=[i,j]
if(mat[i][j]=="E"):
end=[i,j]
r=[[0,1],[0,-1],[-1,0],[... | 46 | 46 | 0 | 187239113 | from itertools import permutations
n, m = [int(i) for i in input().split()]
field = []
start = None
for i in range(n):
cur = []
for j, c in enumerate(list(input())):
if c == 'S':
start = (i, j)
cur.append('.')
else:
cur.append(c)
field.append(cur)
progr... | Good Bye 2017 | CF | 2,017 | 1 | 256 | New Year and Buggy Bot | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The las... | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | null | For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right. | [{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 46 | [{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
10/D | 10 | D | PyPy 3 | TESTS | 16 | 140 | 1,228,800 | 94942367 | def lcis(a, b):
f = [[float("Inf"), float("Inf")] for i in range(min(len(a), len(b))+1)]
f[0][1] = -1
q = 0
for i in range(len(a)):
left, right = 1, q
k = 0
while left <= right:
mid = int((left + right)/2)
if f[mid][0] < a[i... | 60 | 186 | 0 | 11075489 | __author__ = 'Darren'
# dp(i,j): length of the LCIS between f[0:i+1] and s[0:j+1] that ends at s[j]
# if f[i] == s[j]: dp(i,j) = max_len + 1
# else: dp(i,j) = dp(i-1,j)
def solve():
n = int(input())
first = list(map(int, input().split()))
m = int(input())
second = list(map(int, input().split()))
i... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | LCIS | This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other wo... | The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-se... | In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | null | null | [{"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6"}, {"input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1"}] | 2,800 | ["dp"] | 61 | [{"input": "7\r\n2 3 1 6 5 4 6\r\n4\r\n1 3 5 6\r\n", "output": "3\r\n3 5 6 \r\n"}, {"input": "5\r\n1 2 0 2 1\r\n3\r\n1 0 1\r\n", "output": "2\r\n0 1 \r\n"}, {"input": "2\r\n6 10\r\n3\r\n6 3 3\r\n", "output": "1\r\n6 \r\n"}, {"input": "1\r\n7\r\n2\r\n7 9\r\n", "output": "1\r\n7 \r\n"}, {"input": "3\r\n37 49 24\r\n3\r\n3... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input data
with open(input_path, 'r') as f:
input_lines = [line.strip() for line in f]
n = int(input_lines[0])
a = list(map(int, input_lines[1].split()))
m = int(input... | true |
79/C | 79 | C | Python 3 | TESTS | 5 | 154 | 5,324,800 | 21602690 | import functools
def begs_ends(words, text):
l = set()
for i in range(len(text)):
for word in words:
if word == text[i:i + len(word)]:
l.add((i, i + len(word) - 1))
return {e[0]: e[1] for e in l}
def max_interval(possible, l):
i = 0
interval = (-1, -1)
pr... | 80 | 436 | 716,800 | 5639831 | s, n = input(), int(input())
t = [input() for i in range(n)]
def f(i):
global t
for j in range(n):
if i < j:
if len(t[j]) < len(t[i]) and t[j] in t[i]: return False
elif j < i and t[j] in t[i]: return False
return True
t = [t[i] for i in range(n) if f(i)]
n = len(s)
r = [0] * n... | Codeforces Beta Round 71 | CF | 2,011 | 2 | 256 | Beaver | After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.
However, Ciel fee... | In the first line there is a string s. The length of s will be between 1 and 105, inclusive.
In the second line there is a single integer n (1 ≤ n ≤ 10). Next n lines, there is a string bi (1 ≤ i ≤ n). Each length of bi will be between 1 and 10, inclusive.
Each character of the given strings will be either a English... | Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s.
If there are several... | null | In the first sample, the solution is traight_alon.
In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on.
In the third sample, the solution is either nagio or oisii. | [{"input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "output": "12 4"}, {"input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "output": "0 0"}, {"input": "unagioisii\n2\nioi\nunagi", "output": "5 5"}] | 1,800 | ["data structures", "dp", "greedy", "hashing", "strings", "two pointers"] | 80 | [{"input": "Go_straight_along_this_street\r\n5\r\nstr\r\nlong\r\ntree\r\nbiginteger\r\nellipse\r\n", "output": "12 4\r\n"}, {"input": "IhaveNoIdea\r\n9\r\nI\r\nh\r\na\r\nv\r\ne\r\nN\r\no\r\nI\r\nd\r\n", "output": "0 0\r\n"}, {"input": "unagioisii\r\n2\r\nioi\r\nunagi\r\n", "output": "5 5\r\n"}, {"input": "abcabcabcabc\... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:]
# Read input
with open(input_path, 'r') as f:
s = f.readline().strip()
n = int(f.readline())
forbidden = [f.readline().strip() for _ in range(n)]
# Read submission output
try:
wi... | true |
524/B | 524 | B | Python 3 | TESTS | 9 | 61 | 0 | 10450580 | n = int(input())
a = list()
Hmax = 0
Hmin = 0
for i in range(n):
wh = list(map(int, input().split()))
Hmax = max(Hmax, max(wh))
if min(wh) > Hmin:
Hmin = min(wh)
a.append(wh)
W1 = 0
W2 = 0
for wh in a:
if max(wh) > Hmin:
W1 += max(wh)
else:
W1 += min(wh)
if max(wh) > ... | 60 | 374 | 5,017,600 | 10380973 | t = []
x = int(input())
for i in range(x):
a, b = map(int, input().split(' '))
lx = [a, b]
lx.sort()
t.append(lx)
t.sort()
minn = 10**9
for i in range(x):
h = t[i][0]
w = t[i][1]
ok = 1
for j in range(x):
if ok == 1 and j != i:
if min(t[j]) > h:
ok = ... | VK Cup 2015 - Round 1 | CF | 2,015 | 2 | 256 | Фото на память - 2 (round version) | Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можно ... | В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей.
В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей. | Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. | null | null | [{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}] | 1,700 | ["dp", "greedy"] | 60 | [{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "10\r\n168 538\r\n836 439\r\n190 873\r\n206 47\r\n891 591\r\n939 481\r\n399 898\r\n859 466\r\n701 777\r\n629 222\r\n", "output": "34780... | false | stdio | null | true |
33/C | 33 | C | PyPy 3 | TESTS | 4 | 248 | 0 | 51244346 | n = int(input())
seq = list(map(int, input().split()))
sums = []
s = sum(seq)
for i, j in enumerate(seq):
if i > 0:
sums.append(sums[i-1]+(j*-1))
else:
sums.append(s+(j*-1))
if s > max(sums):
pass
else:
ind_left_right = sums.index(max(sums))
for i in range(ind_left_right+1):
... | 89 | 310 | 5,836,800 | 114497323 | n=int(input())
ans1=0
ans=0
sum=0
x=map(int,input().split())
for i in x:
sum+=i
ans1+=i
ans1=max(ans1,0)
ans=max(ans,ans1)
print(2*ans-sum) | Codeforces Beta Round 33 (Codeforces format) | CF | 2,010 | 2 | 256 | Wonderful Randomized Sum | Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th... | The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself. | The first and the only line of the output should contain the answer to the problem. | null | null | [{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}] | 1,800 | ["greedy"] | 89 | [{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}... | false | stdio | null | true |
825/C | 825 | C | Python 3 | TESTS | 6 | 62 | 4,812,800 | 28614035 | import bisect
n_k = list(map(int,input().rstrip().split(" ")))
n = n_k[0]
k = n_k[1]
a_i = list(map(int,input().rstrip().split(" ")))
max_a = 2*k
a_i.sort()
pos = bisect.bisect_right(a=a_i,x=max_a)
problems_to_be_solved = 0
for i in range(pos,n):
present = a_i[pos]
if present>max_a:
max_a = 2*present
... | 61 | 61 | 4,915,200 | 28641112 | n, mx = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
cntr = i = 0
while i < n:
if mx >= a[i] / 2:
mx = max(mx, a[i])
i += 1
else:
mx *= 2
cntr += 1
print(cntr) | Educational Codeforces Round 25 | ICPC | 2,017 | 1 | 256 | Multi-judge Solving | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).
Ma... | The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | null | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second ... | [{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}] | 1,600 | ["greedy", "implementation"] | 61 | [{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ... | false | stdio | null | true |
847/E | 847 | E | PyPy 3 | TESTS | 2 | 93 | 0 | 121278344 | '''
pacman->food
pacman->food->food :hmmge:
larges smaller val
smallest larger val
'''
from bisect import bisect_left as bl
def f(s,n):
p=[]
f=[]
for i in range(n):
if s[i]=="*":
f.append(i)
if s[i]=="P":
p.append(i)
ans=-1
for i in f:
l=float("inf")
# print("i is ",i)
hi=bl(p,i)
lo=hi-1
if hi... | 77 | 264 | 7,168,000 | 116313605 | from bisect import bisect_right,bisect_left
def check(t):
pt=0
contain_t=0
pt1,pt2=0,0
contain_t1,contain_t2=0,0
for i in range(l_p):
contain_t1,contain_t2=t,t
if pt>=l_s:
return 1
if ash[pt]<pokemon[i] and t<pokemon[i]-ash[pt]:
return 0
if as... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 1 | 256 | Packmen | A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.
Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.
In the initial mome... | The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field.
The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is... | Print minimum possible time after which Packmen can eat all asterisks. | null | In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ... | [{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}] | 1,800 | ["binary search", "dp"] | 77 | [{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP.... | false | stdio | null | true |
342/A | 342 | A | Python 3 | TESTS | 34 | 92 | 1,843,200 | 9361885 | from collections import Counter
def main():
input()
c = Counter(map(int, input().split()))
if c[7] or c[2] < c[4] or c[2] + c[3] != c[1] or c[1] != c[4] + c[6]:
print(-1)
return
res = [None] * c[1]
for i in range(c[4]):
res[i] = '1 2 4'
for i in range(c[4], c[2]):
... | 45 | 46 | 1,126,400 | 140416585 | grps = int(input())//3
st = input()
c1,c2,c3,c4,c6=[st.count(s) for s in '12346']
if c1 != grps or c1 != c2 + c3 or c1 != c4 + c6 or c2 < c4 or c3 > c6:
print(-1)
exit()
else:
print('1 2 4\n'*c4 + '1 2 6\n'*(grps - c3 - c4)+'1 3 6\n'*c3) | Codeforces Round 199 (Div. 2) | CF | 2,013 | 1 | 256 | Xenia and Divisors | Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
- a < b < c;
- a divides b, b divides c.
Naturally, Xenia wants each el... | The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3. | If the required partition exists, print $$\frac{\pi}{3}$$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution,... | null | null | [{"input": "6\n1 1 1 2 2 2", "output": "-1"}, {"input": "6\n2 2 1 1 4 6", "output": "1 2 4\n1 2 6"}] | 1,200 | ["greedy", "implementation"] | 45 | [{"input": "6\r\n1 1 1 2 2 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n2 2 1 1 4 6\r\n", "output": "1 2 4\r\n1 2 6\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n7 5 7\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "-1\r\n"}, {... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
numbers = list(map(int, f.readline().split()))
counts = [0] * 8
for num in numbers:
counts[num] += 1
w... | true |
186/A | 186 | A | PyPy 3 | TESTS | 39 | 372 | 29,081,600 | 87849115 | a=input()
b=input()
l2=[]
l22=[]
res=0
for i in range(0, min(len(b) , len(a))):
if a[i]!=b[i]:
res+=1
l2.append(a[i])
l22.append(b[i])
l2.sort()
l22.sort()
if res==2 and l2==l22:
print("YES")
else:
print("NO") | 53 | 92 | 204,800 | 229085358 | a1=input()
b1=input()
a,b,c=0,0,0
if(len(a1)!=len(b1)):print("NO")
else:
for i in range(len(a1)):
if(a1[i]!=b1[i]): a,b,c=b,i,c+1
if(c==2 and a1[a]==b1[b] and a1[b]==b1[a]):print("YES")
else:print("NO") | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
567/E | 567 | E | PyPy 3 | TESTS | 11 | 93 | 0 | 205455849 | import heapq
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def dijkstra(s, G):
dist = [inf] * (n + 1)
dist[s] = 0
visit = [0] * (n + 1)
p = []
heapq.heappush(p, (dist[s], s))
while p:
d, u = heapq.heappop(p)
if dist[u] < d:
continue
... | 109 | 1,372 | 111,513,600 | 231034427 | from heapq import *
from collections import defaultdict
def D(v,g):
h,p,o=[],defaultdict(lambda:1e99),[]
heappush(h,(0,v))
while h:
l,w=heappop(h)
if w in p:continue
p[w]=l
o.append(w)
for u,L in g[w]:
heappush(h,(L+l,u))
return p,o
n,m,s,t=map(int,input().split())
r=[]
g={i+1:[] for i in range(n)}
G={... | Codeforces Round #Pi (Div. 2) | CF | 2,015 | 2 | 256 | President and Roads | Berland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ t). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town t, for which his motorcade passes alo... | The first lines contain four integers n, m, s and t (2 ≤ n ≤ 105; 1 ≤ m ≤ 105; 1 ≤ s, t ≤ n) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (s ≠ t).
Next m lines contain the roads. Each road is given as a group of three integers ai, bi, li (1 ≤ ai, bi ≤ n; ai ≠... | Print m lines. The i-th line should contain information about the i-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the i-th road can be repaired s... | null | The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.
In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6. | [{"input": "6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1", "output": "YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES"}, {"input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 100", "output": "YES\nYES\nCAN 81"}, {"input": "2 2 1 2\n1 2 1\n1 2 2", "output": "YES\nNO"}] | 2,200 | ["dfs and similar", "graphs", "hashing", "shortest paths"] | 109 | [{"input": "6 7 1 6\r\n1 2 2\r\n1 3 10\r\n2 3 7\r\n2 4 8\r\n3 5 3\r\n4 5 2\r\n5 6 1\r\n", "output": "YES\r\nCAN 2\r\nCAN 1\r\nCAN 1\r\nCAN 1\r\nCAN 1\r\nYES\r\n"}, {"input": "3 3 1 3\r\n1 2 10\r\n2 3 10\r\n1 3 100\r\n", "output": "YES\r\nYES\r\nCAN 81\r\n"}, {"input": "2 2 1 2\r\n1 2 1\r\n1 2 2\r\n", "output": "YES\r\n... | false | stdio | null | true |
33/C | 33 | C | PyPy 3-64 | TESTS | 8 | 92 | 0 | 196832629 | n=int(input())
a=list(map(int,input().split()))
suffix=[[0,0] for i in range(n+1)]
for i in range(n-1,-1,-1):
if a[i]>=0:
suffix[i][0],suffix[i][1]=suffix[i+1][0]+a[i],suffix[i+1][1]+a[i]
else:
if -a[i]>=suffix[i+1][1]:
suffix[i][0],suffix[i][1]=suffix[i+1][0]-suffix[i+1][1]-a[i],0
... | 89 | 312 | 30,515,200 | 126925348 | n = int(input())
a = list(map(int,input().split()))
s = sum(a)
dp = [0]*n
dp[0] = a[0]
if n > 1:
for i in range(1,n):
dp[i] = max(dp[i-1]+a[i],a[i])
T = max(dp)
if max(a) <= 0:
print(-s)
else:
print(2*T-s) | Codeforces Beta Round 33 (Codeforces format) | CF | 2,010 | 2 | 256 | Wonderful Randomized Sum | Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th... | The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself. | The first and the only line of the output should contain the answer to the problem. | null | null | [{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}] | 1,800 | ["greedy"] | 89 | [{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}... | false | stdio | null | true |
225/A | 225 | A | Python 3 | TESTS | 9 | 124 | 0 | 104245219 | import sys
_ = input()
x = int(input())
_, _ = map(int, input().strip().split())
p = True
prev = 7 - x
lines = sys.stdin.readlines()
for line in lines:
line = line.strip()
if not line: break
a, b = map(int, line.split())
if prev in [a, 7-a, b, b-7]:
p = False
break
print("YES" if p else... | 52 | 92 | 0 | 145019974 | all = [1, 2, 3, 4, 5, 6]
def m(a, b):
return 7 - a, 7 - b
n = int(input())
top = int(input())
if n == 1:
a = input()
print('YES')
else:
t = n
rows = []
while t > 0:
t -= 1
rows.append(list(map(int, input().split(" "))))
sides = set(m(rows[0][0], rows[0][1]))
sides.add(t... | Codeforces Round 139 (Div. 2) | CF | 2,012 | 2 | 256 | Dice Tower | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of dice in the tower.
The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numb... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | null | null | [{"input": "3\n6\n3 2\n5 4\n2 4", "output": "YES"}, {"input": "3\n3\n2 6\n4 1\n5 3", "output": "NO"}] | 1,100 | ["constructive algorithms", "greedy"] | 52 | [{"input": "3\r\n6\r\n3 2\r\n5 4\r\n2 4\r\n", "output": "YES"}, {"input": "3\r\n3\r\n2 6\r\n4 1\r\n5 3\r\n", "output": "NO"}, {"input": "1\r\n3\r\n2 1\r\n", "output": "YES"}, {"input": "2\r\n2\r\n3 1\r\n1 5\r\n", "output": "NO"}, {"input": "3\r\n2\r\n1 4\r\n5 3\r\n6 4\r\n", "output": "NO"}, {"input": "4\r\n3\r\n5 6\r\n... | false | stdio | null | true |
817/B | 817 | B | Python 3 | TESTS | 18 | 1,372 | 14,131,200 | 134817601 | from collections import Counter
import math
def main():
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
lst = list(set(nums))
lst.sort()
counter = Counter(nums)
if counter[lst[0]] >= 3:
print(comb(counter[lst[0]],3))
elif counter[lst[0]] == 2:
print(c... | 80 | 109 | 8,806,400 | 27825988 | n = int(input())
a = sorted(map(int, input().split()))
x, y, z = a[0], a[1], a[2]
if x < y < z:
print(a.count(z))
elif x < y <= z:
c = a.count(y)
print(c*(c-1)//2)
elif x <= y < z:
print(a.count(z))
else:
c = a.count(z)
print(c*(c-1)*(c-2)//6) | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that ai·aj·ak is minimum possible, are there in t... | The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains n positive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array. | Print one number — the quantity of triples (i, j, k) such that i, j and k are pairwise distinct and ai·aj·ak is minimum possible. | null | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | [{"input": "4\n1 1 1 1", "output": "4"}, {"input": "5\n1 3 2 3 4", "output": "2"}, {"input": "6\n1 3 3 1 3 2", "output": "1"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
899/E | 899 | E | Python 3 | TESTS | 6 | 187 | 9,625,600 | 33469499 | def get_int_list(string):
ls = []
sum = ''
for s in string:
if s == ' ':
ls.append(int(sum))
sum = ''
else:
sum += s
ls.append(int(sum))
return ls
def ans():
prev = ls[0]
num = 1
sum = 0
d = {}
for i in ls:
if i == prev:
sum += 1
else:
ls2 = []
for j in d:
if d[j] >= sum:
l... | 97 | 1,466 | 38,297,600 | 138133134 | import heapq
class Node:
def __init__(self,idx,freq,val) -> None:
self.value=val
self.index=idx
self.occ=freq
self.front=None
self.back=None
class LinkedList:
def __init__(self) -> None:
self.head=None
self.h=[]
self.seen=[False]*200001
heapq.heapify(self... | Codeforces Round 452 (Div. 2) | CF | 2,017 | 2 | 256 | Segments Removal | Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operat... | The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.
The second line contains a sequence a1, a2, ..., an (1 ≤ ai ≤ 109) — Vasya's array. | Print the number of operations Vasya should make to remove all elements from the array. | null | In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. I... | [{"input": "4\n2 5 5 2", "output": "2"}, {"input": "5\n6 3 4 1 5", "output": "5"}, {"input": "8\n4 4 4 2 2 100 100 100", "output": "3"}, {"input": "6\n10 10 50 10 50 50", "output": "4"}] | 2,000 | ["data structures", "dsu", "flows", "implementation", "two pointers"] | 97 | [{"input": "4\r\n2 5 5 2\r\n", "output": "2\r\n"}, {"input": "5\r\n6 3 4 1 5\r\n", "output": "5\r\n"}, {"input": "8\r\n4 4 4 2 2 100 100 100\r\n", "output": "3\r\n"}, {"input": "6\r\n10 10 50 10 50 50\r\n", "output": "4\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "100\r\n45 45 45 45 45 45 45 45 45 45 4... | false | stdio | null | true |
847/E | 847 | E | PyPy 3-64 | TESTS | 2 | 62 | 0 | 166751139 | # https://codeforces.com/contest/847/problem/E
from collections import deque
from bisect import bisect_right
n = int(input())
field = input()
pacmen = []
pellets = []
for i, c in enumerate(field):
if c == 'P':
pacmen.append(i)
elif c == '*':
pellets.append(i)
def bs(lo, hi):
if lo >= hi... | 77 | 467 | 102,400 | 160908484 | n = int(input())
s = input()
def check(mid) :
left = -1
curr = -1
for i in range(0, n) :
if (s[i] == '*' and left == -1 and i > curr) : left = i
elif (s[i] == 'P') :
if (left == -1) : curr = i + mid
elif ((i-mid) > left) : return False
elif (left < i) : c... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 1 | 256 | Packmen | A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.
Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.
In the initial mome... | The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field.
The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is... | Print minimum possible time after which Packmen can eat all asterisks. | null | In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ... | [{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}] | 1,800 | ["binary search", "dp"] | 77 | [{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP.... | false | stdio | null | true |
958/F2 | 958 | F2 | Python 3 | TESTS | 8 | 93 | 6,963,200 | 86268678 | n,m=list(map(int,input().split()))
arr=list(map(int,input().split()))
marr=list(map(int,input().split()))
f=[0]*(m+1)
cnt=0
valid=sum(marr) #m
for i in range(n):
f[arr[i]]+=1
if f[arr[i]]<=marr[arr[i]-1]:
cnt+=1
if cnt==valid:
break
ans=(i+1)-valid
s,e=0,i
while(e<n):
while(f[a... | 59 | 467 | 45,568,000 | 37318624 | from collections import defaultdict
n, m = map(int, input().split())
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))
summs = sum(ms)
target = {
i: m
for i, m in enumerate(ms, 1)
}
remain = set(i for i, m in target.items() if m != 0)
count = defaultdict(int)
a = 0
b = 0
while rem... | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 1 | 256 | Lightsabers (medium) | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co... | Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1. | null | null | [{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}] | 1,800 | ["binary search", "two pointers"] | 59 | [{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\... | false | stdio | null | true |
186/A | 186 | A | Python 3 | TESTS | 39 | 92 | 3,993,600 | 206972331 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Input Func... | 53 | 92 | 307,200 | 211024964 | gnom1 = input()
gnom2 = input()
if len(gnom2) != len(gnom1):
print('NO')
else:
s1 = ''
s2 = ''
for i in range(len(gnom1)):
if gnom1[i] != gnom2[i]:
s1 = s1 + gnom1[i]
s2 = s2 + gnom2[i]
if all([len(s1) == len(s2), len(s1) == 2]):
if s1[1] + s1[0] == s2:
... | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
731/B | 731 | B | PyPy 3 | TESTS | 2 | 62 | 0 | 149481122 | n = int(input())
a = list(map(int, input().split()))
for i in range(0,len(a)):
if a[i] != 0:
if a[i]%2 == 0:
a[i] = 2
else:
a[i] = 1
printed = False
for i in range(0,len(a)-1):
if a[i] != 0:
if a[i] == a[i+1]:
a[i] = 0
a[i+1] = 0
... | 79 | 140 | 10,854,400 | 116624573 | n=int(input())
arr = map(int,input().split())
last = 0
for c in arr:
if last==0:
last = c%2
elif last==1:
if c==0:
print("NO")
exit()
else:
last = (c-1)&1
if last==1:
print("NO")
else:
print("YES") | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Coupons and Discounts | The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu... | The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. | If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). | null | In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon n... | [{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}] | 1,100 | ["constructive algorithms", "greedy"] | 79 | [{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu... | false | stdio | null | true |
216/B | 216 | B | Python 3 | TESTS | 23 | 124 | 5,632,000 | 34192357 | vertexes, edges = map(int, input().split())
graph = [[] for _ in range(vertexes + 1)]
In = (vertexes + 1) * [0]
for _ in range(edges):
from_, to_ = map(int, input().split())
graph[from_].append(to_)
graph[to_].append(from_)
res = 0
visited = (vertexes + 1) * [False]
for i in range(1, graph.__len__()):
... | 56 | 92 | 0 | 187459063 | def adj_list(nodes,edges):
graph=[[] for i in range(nodes)]
for edge in range(edges):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
return graph
nodes, edges = map(int, input().split())
graph=adj_list(nodes,edges)
visited=[False for i in range(nodes)... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
626/E | 626 | E | PyPy 3-64 | TESTS | 12 | 187 | 26,112,000 | 227207146 | n = int(input())
a = sorted(list(map(int, input().split())))
p = [0]
for i in range(n): p.append(p[-1] + a[i])
maxSkewness = 0
for i in range(n):
maxMean = median = a[i]
l = 0
r = min(i, n - i - 1)
while l <= r:
m = (l + r) // 2
s = (p[i] - p[i - m]) + a[i] + (p[n] - p[n - m])
... | 94 | 311 | 27,033,600 | 221423938 | def fans(p, q):
tans = sum[n] - sum[n - q] + sum[p + 1] - sum[p - q]
tans -= x[p] * (2 * q + 1)
return tans
n = int(input())
x = list(map(int, input().split()))
x.sort()
sum = [0] * (n + 1)
ans = -1
ansp = 0
ansq = 0
for i in range(n):
sum[i + 1] = sum[i] + x[i]
for i in range(n):
k = 0
for j in... | 8VC Venture Cup 2016 - Elimination Round | CF | 2,016 | 3 | 256 | Simple Skewness | Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.
The mean of a collection is the average of its elements. The median of a colle... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.
The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list. | In the first line, print a single integer k — the size of the subset.
In the second line, print k integers — the elements of the subset in any order.
If there are multiple optimal subsets, print any. | null | In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3.
In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed.
In the last case, any subset has the same median and mean, so all have simple skewness of 0. | [{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}] | 2,400 | ["binary search", "math", "ternary search"] | 94 | [{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = f.readlines()
return [line.strip() for line in lines]
def compute_skewness(subset):
sorted_subset = sorted(subset)
k = len(sorted_subset)
if k == 0:
return None
total = sum(sorted_subset)
mean = total / k
... | true |
216/B | 216 | B | Python 3 | TESTS | 23 | 92 | 0 | 145076548 | n, m = map(int, input().split(" "))
st_archen_dict = {i:[] for i in range(1,n+1)}
team_1 = []
team_2 = []
to_remove = 0
for _ in range(m):
s1, s2 = map(int, input().split(" "))
st_archen_dict[s1].append(s2)
st_archen_dict[s2].append(s1)
result = set()
for i in range(1,n+1):
if len(st_archen_dict[i]) == ... | 56 | 92 | 0 | 211753527 | def Dfs(node):
global nodesVisted
global result
visitedNodes[node]=True
nodesVisted+=1
if(len(archenemies[node])==2):
leftN,rightN=archenemies[node][0],archenemies[node][1]
if(visitedNodes[leftN]&visitedNodes[rightN]):
if(nodesVisted%2==1):
result+=1
... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
908/B | 908 | B | Python 3 | TESTS | 14 | 62 | 5,529,600 | 33817033 | from itertools import permutations
directiorens=[(0,-1),(-1,0),(0,1),(1,0)]
n,l=map(int,input().split())
a=[]
for i in range(n):
b=list(input())
a.append(b)
c=list(input())
c=list(map(int,c))
for i in range(n):
for j in range(l):
if a[i][j]=="S":
position=[i,j]
start=position... | 46 | 46 | 102,400 | 215851650 | def f(s):
global pi
if len(s)==4:
pi+=g(s)
else:
for i in range(1,4+1):
if str(i) not in s:
f(s+str(i))
def g(x):
q=qq
w=ww
op=[('u',x[0]),('l',x[1]),('d',x[2]),('r',x[3])]
op.sort(key=lambda x:x[1])
ty=1
for i in p:
if op[int(i)][0... | Good Bye 2017 | CF | 2,017 | 1 | 256 | New Year and Buggy Bot | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The las... | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | null | For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right. | [{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 46 | [{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
825/C | 825 | C | PyPy 3 | TESTS | 6 | 61 | 17,715,200 | 132632480 | n,k = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
cur = k
for a in A:
if 2*cur >= a:
continue
else:
ans += 1
cur = (a+1)//2
print(ans) | 61 | 61 | 4,915,200 | 28698078 | n,k = [int(a) for a in input().split()]
ar = [int(a) for a in input().split()]
ar.sort()
ct = 0
i = 0
while i < n:
if ar[i] > k:
if ar[i] > 2*k:
k *= 2
ct += 1
else:
k = ar[i]
i += 1
else:
i += 1
print(ct) | Educational Codeforces Round 25 | ICPC | 2,017 | 1 | 256 | Multi-judge Solving | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).
Ma... | The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | null | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second ... | [{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}] | 1,600 | ["greedy", "implementation"] | 61 | [{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ... | false | stdio | null | true |
216/B | 216 | B | PyPy 3 | TESTS | 23 | 154 | 0 | 176872409 | from sys import stdin,stdout
input=stdin.readline
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
def dfs(node,c):
global ans
visi[node]=c
for child in nodes[node]:
if not visi[child]:
dfs(child,c+1)
else:
if abs(visi[chil... | 56 | 124 | 0 | 166645558 | def dfs(s,e,g):
ss.add(s)
if vist[s] :
return "c"
vist[s] = True
for i in g[s]:
if i != e:
if dfs(i,s,g) == "c":
return "c"
return "p"
n,m = map(int,input().split())
g = [[]for i in range(n)]
vist = [0 for i in range(n)]
for _ in range(m):
a,b = map(int... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
216/B | 216 | B | Python 3 | TESTS | 23 | 218 | 0 | 59578435 | players, arm = input().split()
problems = dict()
players, arm, counter = int(players), int(arm), 0
for i in range(arm):
pl1, pl2 = input().split()
if pl1 not in problems:
problems[pl1]= [pl2]
else:
problems[pl1].append(pl2)
if pl2 not in problems:
problems[pl2]= [pl1]
els... | 56 | 124 | 0 | 205966766 | n,x=map(int,input().split())
dic={i:[] for i in range(1,n+1)}
for i in range(x):
a,b=map(int,input().split())
dic[a].append(b)
dic[b].append(a)
def dfs(s):
global vis,c,qw
if s in vis:
return
vis.add(s)
c+=1
qw=False
if len(dic[s])==2:
qw=True
for i in dic[s]:
... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
216/B | 216 | B | Python 3 | TESTS | 23 | 218 | 0 | 53766615 | def threeAnemeies(palyers, enemey1, enemey2):
if enemey1 in palyers[enemey2]:
return True
return False
def setPlayers(nPairs):
players = {}
c = 0
while c < nPairs:
player, enemey = map(int, input().split())
if player not in players:
players[player] = [enemey]
... | 56 | 124 | 614,400 | 161568573 | import sys
def solve():
n, e = list(map(int, sys.stdin.readline().split()))
enemies = []
for _ in range(n + 1):
enemies.append([])
for _ in range(e):
f, s = list(map(int, sys.stdin.readline().split()))
enemies[f].append(s)
enemies[s].append(f)
print(enemies, file=... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
216/B | 216 | B | Python 3 | TESTS | 23 | 248 | 0 | 63995075 | n,m=map(int,input().split())
L=[0 for i in range(n+1)]
d={}
for i in range(m) :
u,v=map(int,input().split())
vs=d.get(u,[])
vs.append(v)
d[u]=vs
vs=d.get(v,[])
vs.append(u)
d[v]=vs
ans=0
for i in range(1,n+1) :
if L[i]==1 :
continue
syd=d.get(i,[])
if len(syd)!=2 :
... | 56 | 124 | 5,529,600 | 32696670 | n,m=map(int,input().split())
ch=[False for i in range(n)]
a=[[]for i in range(n)]
va=[0]
def dfs(i):
if ch[i]:
return 0
if len(a[i])<2:
va[0]=0
re=0
ch[i]=True
for i in a[i]:
re+=dfs(i)
return re+1
for i in range(m):
x,y=map(int,input().split())
a[x - 1].append(y-... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
613/A | 613 | A | PyPy 3-64 | TESTS | 2 | 46 | 0 | 175237472 | import math
def prov():
cosc = (ax * cx + ay * cy) / (a * c)
if math.degrees(math.acos(cosc)) <= 90 and 180 - math.degrees(math.acos(cosa)) - math.degrees(math.acos(cosc)) <= 90:
return True
else:
return False
n, x0, y0 = [int(i) for i in input().split()]
toch = []
for i in range(n):
c... | 60 | 639 | 14,950,400 | 15366046 | __author__ = 'Utena'
import math
n,a,b=map(int,input().split())
m=[]
s=[]
for i in range(n):
m.append(list(map(int,input().split())))
for i in range(n):
a1,b1=m[i]
s.append((a1-a)**2+(b1-b)**2)
for i in range(n-1):
a1,b1=m[i]
a2,b2=m[i+1]
if ((a2-a1)*(a2-a)+(b2-b1)*(b2-b))*((a2-a1)*(a1-a)+(b2-b1... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P.
Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac... | null | In the first sample snow will be removed from that area: | [{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}] | 1,900 | ["binary search", "geometry", "ternary search"] | 60 | [{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
try:
b = float(ref_line)
except:
print(0)
return
with open(submission_path, 'r') as f:
... | true |
342/A | 342 | A | PyPy 3 | TESTS | 33 | 217 | 9,625,600 | 113561514 | n = int(input())
l = list(map(int, input().split()))
s = set(l)
if len(s) < 3 or 5 in l or 7 in l:
print(-1)
else:
d = {1: 0, 2: 0, 3: 0, 4: 0, 6: 0}
for i in l:
d[i] = d.get(i, 0) + 1
if 6 in s and 4 in s:
if d[1] == (d[6]+d[4]):
c = d[6] - d[3]
rem = d[2] - c
... | 45 | 46 | 1,126,400 | 156223119 | n=int(input())//3
s=input()
c1,c2,c3,c4,c6=[s.count(_)for _ in'12346']
if c1!=n or c2<c4 or c1!=c2+c3 or c1!=c4+c6:
print(-1)
exit()
print('1 2 4\n'*c4+'1 3 6\n'*c3+'1 2 6\n'*(n-c4-c3)) | Codeforces Round 199 (Div. 2) | CF | 2,013 | 1 | 256 | Xenia and Divisors | Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:
- a < b < c;
- a divides b, b divides c.
Naturally, Xenia wants each el... | The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3. | If the required partition exists, print $$\frac{\pi}{3}$$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution,... | null | null | [{"input": "6\n1 1 1 2 2 2", "output": "-1"}, {"input": "6\n2 2 1 1 4 6", "output": "1 2 4\n1 2 6"}] | 1,200 | ["greedy", "implementation"] | 45 | [{"input": "6\r\n1 1 1 2 2 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n2 2 1 1 4 6\r\n", "output": "1 2 4\r\n1 2 6\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n7 5 7\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "-1\r\n"}, {... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
numbers = list(map(int, f.readline().split()))
counts = [0] * 8
for num in numbers:
counts[num] += 1
w... | true |
351/A | 351 | A | Python 3 | TESTS | 5 | 92 | 0 | 5340830 | n, k, s = int(input()), 0, 0
for i in input().split():
j = int(i[-3: ])
if j == 0: k += 1
else: s += j
c = s // 1000 + int(s % 1000 > 500)
a, b = max(0, n - k), min(2 * n - k, n)
if a <= c <= b: s = abs(c * 1000 - s)
else: s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 10... | 63 | 154 | 1,945,600 | 220840239 | n=int(input())
s,z=0,0
for l in map(float,input().split()):
s+=(d:=l-int(l))
z+=d>0
print("%.3f"%min(abs(s-i) for i in range(z-n,min(z,n)+1))) | Codeforces Round 204 (Div. 1) | CF | 2,013 | 1 | 256 | Jeff and Rounding | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
- choose indexes i and j (i ≠ j) that haven't been chosen yet;
- round element ai ... | The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | null | In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | [{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}] | 1,800 | ["dp", "greedy", "implementation", "math"] | 63 | [{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486.... | false | stdio | null | true |
351/A | 351 | A | Python 3 | PRETESTS | 5 | 92 | 0 | 4661192 | n = int(input())
a = [float(x) - int(float(x)) for x in input().split()]
a = list(sorted(a))
ans = sum(a) - len(a) // 2
while len(a) > 0 and a[1] == 0:
if (abs(ans) > abs(ans - sum(a[:2]) + 1)):
ans = ans - sum(a[:2]) + 1
del a[:2]
print("{:.3f}".format(abs(ans))) | 63 | 154 | 1,945,600 | 231249920 | n=int(input())
s=z=0
for l in map(float,input().split()):
s+=(d:=l-int(l))
z+=d>0
print("%.3f"%min(abs(s-i) for i in range(z-n,n+1))) | Codeforces Round 204 (Div. 1) | CF | 2,013 | 1 | 256 | Jeff and Rounding | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
- choose indexes i and j (i ≠ j) that haven't been chosen yet;
- round element ai ... | The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | null | In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | [{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}] | 1,800 | ["dp", "greedy", "implementation", "math"] | 63 | [{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486.... | false | stdio | null | true |
204/B | 204 | B | PyPy 3 | TESTS | 7 | 280 | 0 | 43626782 | R = lambda: map(int, input().split())
n = int(input())
f, b = {}, {}
nums = set()
for x in range(n):
l, r = R()
f.setdefault(l, 0)
b.setdefault(r, 0)
f[l], b[r] = f[l] + 1, b[r] + 1
nums.add(l)
nums.add(r)
res = 10**9
for c in nums:
if f.get(c, 0) + b.get(c, 0) >= (n + 1) // 2:
res =... | 90 | 872 | 16,179,200 | 100394653 | from collections import defaultdict
n = int(input())
u, v = defaultdict(int), defaultdict(int)
for k in range(n):
a, b = map(int, input().split())
u[a] += 1
if b != a: v[b] += 1
k = (n - 1) // 2
s = any(v[b] > k for b in v)
t = [u[a] for a in u if u[a] + v[a] > k]
if t: print(max(0, k + 1 - max(t)))
else: p... | Codeforces Round 129 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Cards | The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | null | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | [{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}] | 1,500 | ["binary search", "data structures"] | 90 | [{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n... | false | stdio | null | true |
204/B | 204 | B | PyPy 3 | TESTS | 7 | 280 | 0 | 71042726 | import sys
from math import *
input=sys.stdin.readline
#n,m,k=map(int,input().split())
d={}
n=int(input())
for i in range(n):
x,y=map(int,input().split())
if x in d:
d[x][0]+=1
else:
d[x]=[1,0]
if y in d:
d[y][1]+=1
else:
d[y]=[0,1]
mini=10**15
for i in d:
... | 90 | 996 | 24,576,000 | 116421494 | from collections import defaultdict
n = int(input())
l1 = defaultdict(int)
l2 = defaultdict(int)
for _ in range(n):
a, b = [int(i) for i in input().split()]
if a != b:
l1[a] += 1
l2[b] += 1
else:
l1[a] += 1
k1 = list(l1.keys())
k2 = list(l2.keys())
ans = k1 + k2
ans = set(ans)
k = (n... | Codeforces Round 129 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Cards | The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | null | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | [{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}] | 1,500 | ["binary search", "data structures"] | 90 | [{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n... | false | stdio | null | true |
204/B | 204 | B | Python 3 | TESTS | 7 | 124 | 4,915,200 | 25585466 | import math
def get_min_changes(cards_n, all_numbers, dict1, dict2):
min_changes = cards_n + 1
found = False
for number in all_numbers:
if number in dict1 and len(dict1[number]) >= math.ceil(cards_n / 2):
return 0
else:
if number in dict1 and number in dict2:
changes = math.ceil(cards_n / 2) - len(dic... | 90 | 1,060 | 42,393,600 | 128056767 | from collections import defaultdict
n = int(input())
front = defaultdict(int)
back = defaultdict(int)
frontback = defaultdict(int)
colors = set()
for i in range(n):
x, y = input().split()
if x == y:
frontback[x] += 1
else:
front[x] += 1
back[y] += 1
colors.add(x)
colors.add... | Codeforces Round 129 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Cards | The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | null | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | [{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}] | 1,500 | ["binary search", "data structures"] | 90 | [{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n... | false | stdio | null | true |
730/H | 730 | H | Python 3 | TESTS | 26 | 77 | 6,963,200 | 123791511 | # _
#####################################################################################################################
def fileNamePattern(nNamesToDelete, name_sLength, namesToDelete, namesWithSimilarLength):
nNamesToTest = len(namesWithSimilarLength)
pattern = ''
onlyDeleteDesiredNames = not nNamesToTe... | 74 | 62 | 0 | 21702051 | m,n=list(map(int,input().split()))
s=[input().strip() for i in range(m)]
a=list(map(lambda x:int(x)-1,input().split()))
stmpl=s[a[0]]
f=1
def peres(s1,s2):
return ''.join([i if i==j else '?' for i,j in zip(s1,s2)])
for i in a:
if len(stmpl)!=len(s[i]):
f=0
break
stmpl=peres(stmpl,s[i])
for i,e in enumerate(s):
... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | null | null | [{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}] | 1,300 | ["constructive algorithms", "implementation"] | 74 | [{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"... | false | stdio | null | true |
38/A | 38 | A | PyPy 3-64 | TESTS | 5 | 92 | 0 | 220895934 | n = int(input())
l1 = list(map(int , input().split()))
l2 = list(map(int , input().split()))
res= 0
if l2[-1] == n :
print(sum(l1))
else :
print(sum(l1[l2[0] -1 : l2[-1] - 1])) | 50 | 62 | 0 | 162588184 | n = int(input())
x = list(map(int, input().split()))
(a, b) = map(int, input().split())
y = [0] * (n + 1)
for i in range(len(x)):
y[i + 1] = y[i] + x[i]
print(y[b - 1] - y[a - 1]) | School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | Army | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya ha... | The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | null | null | [{"input": "3\n5 6\n1 2", "output": "5"}, {"input": "3\n5 6\n1 3", "output": "11"}] | 800 | ["implementation"] | 50 | [{"input": "3\r\n5 6\r\n1 2\r\n", "output": "5\r\n"}, {"input": "3\r\n5 6\r\n1 3\r\n", "output": "11\r\n"}, {"input": "2\r\n55\r\n1 2\r\n", "output": "55\r\n"}, {"input": "3\r\n85 78\r\n1 3\r\n", "output": "163\r\n"}, {"input": "4\r\n63 4 49\r\n2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n93 83 42 56\r\n2 5\r\n", "out... | false | stdio | null | true |
817/B | 817 | B | Python 3 | TESTS | 18 | 124 | 9,113,600 | 27921633 | #def C(n, k):
#return( f(n) // (f(k) * f(n - k)))
#def f(m):
#r = 1
#for i in range(1, m + 1):
#r *= i
#return(r)
n = input()
a = list(map(int, input().split()))
mn = sorted(a)[:3]
res = 1
for i in mn:
c = a.count(i)
if mn.count(i) == 3:
res = ((c *(c - 1) * (c - 2) ) // 6)... | 80 | 109 | 9,113,600 | 27800790 | def c(n, k):
r = 1
for i in range(k):
r *= n
n -= 1
for i in range(2, k + 1):
r //= i
return r
n = int(input())
l = sorted(map(int, input().split()))
prev = l[0]
beg = 0
cnt = 0
ans = 1
for i in range(n):
if l[i] == prev:
cnt += 1
else:
ans *= c(i - beg, min(3, i) - beg)
cnt = 1
prev = l[i]
beg =... | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that ai·aj·ak is minimum possible, are there in t... | The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains n positive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array. | Print one number — the quantity of triples (i, j, k) such that i, j and k are pairwise distinct and ai·aj·ak is minimum possible. | null | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | [{"input": "4\n1 1 1 1", "output": "4"}, {"input": "5\n1 3 2 3 4", "output": "2"}, {"input": "6\n1 3 3 1 3 2", "output": "1"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
817/B | 817 | B | PyPy 3 | TESTS | 18 | 233 | 10,956,800 | 66778415 | n = int(input())
a = sorted(list(map(int, input().split())))
b = a[3:]
if a[0] == a[1] == a[2]:
n = a.count(a[0])
print(n * (n - 1) * (n - 2) // 6)
elif a[0] == a[1]:
print((1 + b.count(a[0])) * (1 + b.count(a[2])))
elif a[1] == a[2]:
print((1 + b.count(a[0])) * (1 + b.count(a[1])))
elif a[0] == a[2]:
... | 80 | 109 | 9,113,600 | 27800805 | n=int(input())
a=sorted(list(map(int, input().split())))
if a[0]!=a[1] and a[1]!=a[2]:
print(a.count(a[2]))
elif a[0]!=a[1] and a[1]==a[2]:
t=a.count(a[1])
print((t*(t-1))//2)
elif a[0]==a[1] and a[1]!=a[2]:
print(a.count(a[2]))
else:
t=a.count(a[0])
print((t*(t-1)*(t-2))//6) | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that ai·aj·ak is minimum possible, are there in t... | The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains n positive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array. | Print one number — the quantity of triples (i, j, k) such that i, j and k are pairwise distinct and ai·aj·ak is minimum possible. | null | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | [{"input": "4\n1 1 1 1", "output": "4"}, {"input": "5\n1 3 2 3 4", "output": "2"}, {"input": "6\n1 3 3 1 3 2", "output": "1"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
731/B | 731 | B | Python 3 | TESTS | 2 | 61 | 0 | 120234087 | n = int(input())
a = list(map(int, input().split()))
s = 0; flag = 1
for i in range(n):
s += a[i]
if a[i] == 0 and s&1: flag = 0; break
if flag: print("YES")
else: print("NO") | 79 | 155 | 13,516,800 | 157823880 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
ans = 'YES'
for i in range(n-1):
if w[i] % 2:
if w[i+1] == 0:
ans = "NO"
break
else:
w[i+1] += 1
if w[-1] % 2:
ans = "NO"
print(ans) | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Coupons and Discounts | The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu... | The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. | If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). | null | In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon n... | [{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}] | 1,100 | ["constructive algorithms", "greedy"] | 79 | [{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu... | false | stdio | null | true |
230/A | 230 | A | PyPy 3-64 | TESTS | 35 | 186 | 1,945,600 | 232319164 | s, n = map(int, input().split())
lst1 = []
lst2 = []
dic = {}
for _ in range(n):
xi, yi = map(int, input().split())
if xi < s:
s += yi
else:
dic.update({xi : yi})
myKeys = list(dic.keys())
myKeys.sort()
sorted_dict = {i: dic[i] for i in myKeys}
rval = True
for keys in sorted_dict:
if keys < s:
s+= s... | 54 | 62 | 102,400 | 232268766 | s, n=list(map(int, input().split()))
l=[]
for i in range(n):
a, b=list(map(int, input().split()))
l.append([a, b])
l.sort(key = lambda x: x[0])
#print(l)
for i in l:
a=i[0]
b=i[1]
if s<=a:
print("NO")
break
elif s>a:
s+=b
else:
print("YES") | Codeforces Round 142 (Div. 2) | CF | 2,012 | 2 | 256 | Dragons | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'... | The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | null | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | [{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}] | 1,000 | ["greedy", "sortings"] | 54 | [{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},... | false | stdio | null | true |
216/B | 216 | B | Python 3 | TESTS | 23 | 92 | 0 | 211713206 | def getAdjacent(node):
adjacents=[node,archenemies[node][0],archenemies[node][1]]
adjacents.sort()
return adjacents
n,m=list(map(int,input().split(" ")))
archenemies=[[] for i in range(n)]
result=0
visitedNodes=[False for k in range(n)]
for i in range(m):
ai,bi=list(map(int,input().split(" ")))
ar... | 56 | 124 | 5,632,000 | 35139089 | def readInts(): return map(int, input().split())
def dfs(g, seen, i):
if i in seen:
return 0,0
seen.add(i)
nodes = 1
edges = len(g[i])
for j in g[i]:
x, y = dfs(g, seen, j)
nodes += x
edges += y
return nodes, edges
def solve():
line0 = []
try: line0 = readInts()
except EOFError: ret... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Forming Teams | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ... | The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi... | Print a single integer — the minimum number of students you will have to send to the bench in order to start the game. | null | null | [{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}] | 1,700 | ["dfs and similar", "implementation"] | 56 | [{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou... | false | stdio | null | true |
204/B | 204 | B | PyPy 3 | TESTS | 7 | 716 | 9,625,600 | 83582250 | import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.std... | 90 | 1,184 | 21,299,200 | 42123854 | def main():
n = int(input())
d = {}
for i in range(n):
a, b = [int(i) for i in input().split()]
if a == b:
if a not in d:
d[a] = [0, 0]
d[a][0] += 1
else:
if a not in d:
d[a] = [0, 0]
d[a][0... | Codeforces Round 129 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Cards | The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | null | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | [{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}] | 1,500 | ["binary search", "data structures"] | 90 | [{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n... | false | stdio | null | true |
269/A | 269 | A | PyPy 3 | TESTS | 13 | 1,744 | 29,184,000 | 128505122 | from math import ceil, log
n = int(input())
s = 0
k1 = 0
for _ in range(n):
k, a = map(int, input().split())
g = k + ceil(log(a, 4))
if g > s:
s = g
k1 = k
print(max(s, k1 + 1)) | 46 | 530 | 7,577,600 | 186986462 | from collections import defaultdict
from sys import stdin
input = stdin.readline
n = int(input())
ans = 0
for _ in range(n):
k, a = [int(x) for x in input().split()]
if a == 1: k += 1
while a > 1:
a = (a+3)//4
k += 1
ans = max(ans, k)
print(ans)
# https://blog.csdn.net/qq_41289920/... | Codeforces Round 165 (Div. 1) | CF | 2,013 | 2 | 256 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. | Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. | null | Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2. | [{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}] | 1,600 | ["greedy", "math"] | 46 | [{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ... | false | stdio | null | true |
731/B | 731 | B | Python 3 | TESTS | 5 | 46 | 6,963,200 | 124925542 | def solution(ns):
for i in range(len(ns)):
if i == 0:
continue
if ns[i] >= 1 and ns[i - 1] >= 1:
ns[i] -= 1
ns[i - 1] -= 1
for n in ns:
if n % 2 != 0:
return "NO"
return "YES"
if __name__ == "__main__":
n = input()
ns ... | 79 | 155 | 20,582,400 | 122634805 | i = int(input())
l = list(map(int,input().split()))
c = 0
for x in l:
if c == 1:
x -= 1
if x < 0:
print('NO'); exit()
c = x%2
print('NO' if c == 1 else 'YES') | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Coupons and Discounts | The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu... | The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. | If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). | null | In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon n... | [{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}] | 1,100 | ["constructive algorithms", "greedy"] | 79 | [{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu... | false | stdio | null | true |
116/A | 116 | A | PyPy 3-64 | TESTS | 9 | 92 | 0 | 223053085 | n = int(input())
cap = 0
tram = 0
for i in range(1,n+1):
x,y = map(int, input().split())
if y == 0:
break
tram += - x + y
if tram < cap:
pass
else:
cap = tram
print(cap) | 71 | 92 | 0 | 208037159 | n = int(input())
ans = 0
ans_1 = []
for i in range(n):
ext,ent = map(int,input().split(" "))
ans = (ans-ext)+ent
ans_1.insert(0,ans)
print(max(ans_1)) | Codeforces Beta Round 87 (Div. 2 Only) | CF | 2,011 | 2 | 256 | Tram | Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ... | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.
Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | null | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
- At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas... | [{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}] | 800 | ["implementation"] | 71 | [{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp... | false | stdio | null | true |
725/A | 725 | A | Python 3 | TESTS | 6 | 62 | 409,600 | 22100654 | n=int(input())
s=input()
k=s.find('><')
while k!=-1:
s=s[:k]+s[k+2:]
k=s.find('><')
print(len(s)) | 78 | 46 | 512,000 | 172754438 | n=int(input())
s=input().lstrip("<").rstrip(">")
print(n-len(s)) | Canada Cup 2016 | CF | 2,016 | 2 | 256 | Jumping Ball | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | null | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | [{"input": "4\n<<><", "output": "2"}, {"input": "5\n>>>>>", "output": "5"}, {"input": "4\n>><<", "output": "0"}] | 1,000 | ["implementation"] | 78 | [{"input": "4\r\n<<><\r\n", "output": "2\r\n"}, {"input": "5\r\n>>>>>\r\n", "output": "5\r\n"}, {"input": "4\r\n>><<\r\n", "output": "0\r\n"}, {"input": "3\r\n<<>\r\n", "output": "3\r\n"}, {"input": "3\r\n<<<\r\n", "output": "3\r\n"}, {"input": "3\r\n><<\r\n", "output": "0\r\n"}, {"input": "1\r\n<\r\n", "output": "1\r\... | false | stdio | null | true |
552/E | 552 | E | PyPy 3 | TESTS | 5 | 140 | 0 | 95329205 | s=input()
ans=0;
n=len(s)
for i,x in enumerate(s):
if x=='*':
for j in range(0,i,2):
s2=f"{s[:j]}({s[j:i]}){s[i:]}"
ans=max(ans,eval(s2))
for j in range(i+2,n+1,2):
s2=f"{s[:i+1]}({s[i+1:j]}){s[j:]}"
ans=max(ans,eval(s2))
print(ans) | 69 | 327 | 2,662,400 | 211865059 | def main():
s = input()
max_res = eval(s)
data = s.split('*')
for i in range(len(data)):
old_i = data[i]
data[i] = f"({data[i]}"
for j in range(i, len(data)):
old_j = data[j]
data[j] = f"{data[j]})"
max_res = max(max_res, eval('*'.join(data)))
... | Codeforces Round 308 (Div. 2) | CF | 2,015 | 1 | 256 | Vanya and Brackets | Vanya is doing his maths homework. He has an expression of form $$x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$$, where x1, x2, ..., xn are digits from 1 to 9, and sign $$\text{ }$$ represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this express... | The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * .
The number of signs * doesn't exceed 15. | In the first line print the maximum possible value of an expression. | null | Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60). | [{"input": "3+5*7+8*4", "output": "303"}, {"input": "2+3*5", "output": "25"}, {"input": "3*4*5", "output": "60"}] | 2,100 | ["brute force", "dp", "expression parsing", "greedy", "implementation", "strings"] | 69 | [{"input": "3+5*7+8*4\r\n", "output": "303\r\n"}, {"input": "2+3*5\r\n", "output": "25\r\n"}, {"input": "3*4*5\r\n", "output": "60\r\n"}, {"input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5\r\n", "output": "152587890625\r\n"}, {"input": "2*2+2*2\r\n", "output": "16\r\n"}, {"input": "1+1+1+1+1+1+1\r\n", "output": "7\r\n"}, {"inp... | false | stdio | null | true |
116/A | 116 | A | Python 3 | TESTS | 4 | 62 | 0 | 222116317 | n = int(input())
max_size = 0
pas_in = 0
for i in range(n):
line = list(input().split())
if pas_in == 0:
pas_in = int(line[1])
max_size = pas_in
else:
pas_in -= int(line[0])
pas_in += int(line[1])
if max_size < pas_in:
max_size = pas_in
print(max_size) | 71 | 92 | 0 | 208037222 | n=int(input())
cap=0
max=0
for i in range(n):
a,b=map(int,input().split())
cap=cap-a+b
if cap>max:
max=cap
print(max) | Codeforces Beta Round 87 (Div. 2 Only) | CF | 2,011 | 2 | 256 | Tram | Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ... | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.
Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | null | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
- At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas... | [{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}] | 800 | ["implementation"] | 71 | [{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp... | false | stdio | null | true |
626/E | 626 | E | PyPy 3 | TESTS | 15 | 1,294 | 47,718,400 | 125816841 | def findMean(prefixSum, n, k, medianIdx, median):
if k == 0: return median
total = prefixSum[medianIdx+1] - prefixSum[medianIdx - k] + prefixSum[n] - prefixSum[n-k]
return total/(2*k + 1)
n = int(input())
nums = sorted(list(map(int, input().split())))
ans, bestK, bestMedianIdx = -1, 0, 0
prefSum = [0]
fo... | 94 | 343 | 27,033,600 | 217897255 | def CalcMean(n,a,c,median,k):
if k==0: return a[median]
s = c[median+1] - c[median-k] + c[n] - c[n-k]
return s/(2*k+1)
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=[0]
for i in range(n):
c.append(c[-1]+a[i])
ans=optMed=optK=0
for median in range(n):
L=0
R=min(median,n-median-1)
... | 8VC Venture Cup 2016 - Elimination Round | CF | 2,016 | 3 | 256 | Simple Skewness | Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.
The mean of a collection is the average of its elements. The median of a colle... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.
The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list. | In the first line, print a single integer k — the size of the subset.
In the second line, print k integers — the elements of the subset in any order.
If there are multiple optimal subsets, print any. | null | In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3.
In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed.
In the last case, any subset has the same median and mean, so all have simple skewness of 0. | [{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}] | 2,400 | ["binary search", "math", "ternary search"] | 94 | [{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = f.readlines()
return [line.strip() for line in lines]
def compute_skewness(subset):
sorted_subset = sorted(subset)
k = len(sorted_subset)
if k == 0:
return None
total = sum(sorted_subset)
mean = total / k
... | true |
626/E | 626 | E | PyPy 3-64 | TESTS | 12 | 186 | 22,323,200 | 218906343 | n = int(input())
a = [0]
a.extend(list(map(int, input().split())))
a.sort()
p = [0] * (n + 1)
p[1] = a[1]
for i in range(2, n + 1):
p[i] = a[i] + p[i - 1]
maxSkewness = 0
for i in range(1, n + 1):
median = maxMean = a[i]
l = 0
r = min(i - 1, n - i)
while l <= r:
m = l + (r - l) // 2
... | 94 | 1,560 | 55,398,400 | 125835053 | from fractions import Fraction
def findMean(prefixSum, n, k, medianIdx):
total = prefixSum[medianIdx + 1] - prefixSum[medianIdx - k] + prefixSum[n] - prefixSum[n - k]
return Fraction(total, (2 * k + 1))
n = int(input())
nums = sorted(list(map(int, input().split())))
ans, bestK, bestMedianIdx = -1, 0, 0
prefS... | 8VC Venture Cup 2016 - Elimination Round | CF | 2,016 | 3 | 256 | Simple Skewness | Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.
The mean of a collection is the average of its elements. The median of a colle... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.
The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list. | In the first line, print a single integer k — the size of the subset.
In the second line, print k integers — the elements of the subset in any order.
If there are multiple optimal subsets, print any. | null | In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3.
In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed.
In the last case, any subset has the same median and mean, so all have simple skewness of 0. | [{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}] | 2,400 | ["binary search", "math", "ternary search"] | 94 | [{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = f.readlines()
return [line.strip() for line in lines]
def compute_skewness(subset):
sorted_subset = sorted(subset)
k = len(sorted_subset)
if k == 0:
return None
total = sum(sorted_subset)
mean = total / k
... | true |
230/A | 230 | A | PyPy 3-64 | TESTS | 35 | 216 | 2,150,400 | 229401921 | s,n = list(map(int,input().split()))
health = []
bonus = []
for _ in range(n):
h,b = list(map(int,input().split()))
health.append(h)
bonus.append(b)
ans = True
while(len(health)):
mi = health.index(min(health))
if(s<=health[mi]):
ans =False
break
else:
s += bonus[mi]
health.remove(health[mi])
bonus.remo... | 54 | 92 | 0 | 227713029 | s,n=map(int,input().split())
dragons=[]
for _ in range(n):
xi,yi=map(int,input().split())
dragons.append((xi,yi))
dragons.sort()
for xi,yi in dragons:
if s>xi:
s+=yi
else:
print("NO")
break
else:
print("YES") | Codeforces Round 142 (Div. 2) | CF | 2,012 | 2 | 256 | Dragons | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'... | The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | null | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | [{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}] | 1,000 | ["greedy", "sortings"] | 54 | [{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},... | false | stdio | null | true |
817/B | 817 | B | PyPy 3-64 | TESTS | 18 | 202 | 21,708,800 | 172160874 | n = int(input())
a = map(int, input().split(' '))
mp = {}
for x in a:
if x not in mp:
mp[x] = 0
mp[x] += 1
smp = sorted(mp.items(), key=lambda x: x[0])
cnt = 3
i = 0
prod = 1
while cnt > 0:
t = min(cnt, smp[i][1])
prod *= smp[i][0] ** t
cnt -= t
i += 1
def getcnt(a, b, c):
if a =... | 80 | 109 | 9,113,600 | 27824979 | n=int(input())
l=list(map(int,input().strip().split(' ')))
l1=sorted(l)
a=l1[0]
b=l1[1]
c=l1[2]
if a==b and b==c:
ans=l.count(a)
a=ans
print((a*(a-1)*(a-2))//6)
elif b!=c:
ans=l.count(c)
c=ans
print(c)
else:
ans=l.count(b)
b=ans
print((b*(b-1))//2) | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that ai·aj·ak is minimum possible, are there in t... | The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains n positive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array. | Print one number — the quantity of triples (i, j, k) such that i, j and k are pairwise distinct and ai·aj·ak is minimum possible. | null | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | [{"input": "4\n1 1 1 1", "output": "4"}, {"input": "5\n1 3 2 3 4", "output": "2"}, {"input": "6\n1 3 3 1 3 2", "output": "1"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
613/A | 613 | A | Python 3 | TESTS | 2 | 46 | 0 | 29620769 | class vector:
def __init__(self, x, y):
self.x = x
self.y = y
def length(self):
return (self.x ** 2 + self.y ** 2) ** 0.5
n, x, y = map(int, input().split())
min_r = 2000000
max_r = 0
for i in range(n):
x1, y1 = map(int, input().split())
k = vector(x1 - x, y1 - y).length()
... | 60 | 686 | 2,867,200 | 15364669 | import math
n, a, b = [int(x) for x in input().split()]
distances = []
x, y = [int(x) for x in input().split()]
distances.append(math.hypot(x - a, y - b))
prevx, prevy = x, y
firstx, firsty = x, y
for i in range(n-1):
x, y = [int(x) for x in input().split()]
distances.append(math.hypot(x - a, y - b))
scala... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P.
Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac... | null | In the first sample snow will be removed from that area: | [{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}] | 1,900 | ["binary search", "geometry", "ternary search"] | 60 | [{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
try:
b = float(ref_line)
except:
print(0)
return
with open(submission_path, 'r') as f:
... | true |
613/A | 613 | A | Python 3 | TESTS | 2 | 46 | 0 | 29682373 | import math
n,p1,p2 = list(map(float,input().split()))
inp = []
mn = 1000000000000.0
mx = 0
for i in range(int(n)):
p = tuple(map(float,input().split()))
p = (p[0]-p1,p[1]-p2)
inp.append(p)
d = (p[0]**2) + (p[1]**2)
mn = min(mn,d)
mx = max(mx,d)
ans = math.pi * (mx-mn)
print(ans) | 60 | 686 | 8,192,000 | 15597140 | #!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
def dist2(x1, y1, x2, y2):
return (x1 - x2) ** 2 + (y1 - y2) ** 2
def find_dist(x1, y1, x2, y2, X, Y):
if x2 == x1:
if min(y1, y2) <= Y <= max(y1, y2):
return (x1 - X) ** 2
else:
return min(dist2(x1, y1, ... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P.
Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac... | null | In the first sample snow will be removed from that area: | [{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}] | 1,900 | ["binary search", "geometry", "ternary search"] | 60 | [{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
try:
b = float(ref_line)
except:
print(0)
return
with open(submission_path, 'r') as f:
... | true |
613/A | 613 | A | Python 3 | TESTS | 2 | 31 | 0 | 229272525 | pi = 3.141592653589793
p = [0,0]
m = []
def distance(p, a):
return ((a[0]-p[0])**2 + (a[1]-p[1])**2)**0.5
# [n, p[0], p[1]] = [int(i) for i in '3 0 0'.split()]
[n, p[0], p[1]] = [int(i) for i in input().split()]
for i in range(n):
m.append(
[int(i) for i in input().split()]
)
distances = [dista... | 60 | 779 | 10,649,600 | 69397139 | """ Peter and Snow Blower """
import math
def cross(vecA, vecB):
return abs(vecA[0] * vecB[1] - vecA[1] * vecB[0])
def l2_norm(pointA, pointB):
return (pointA[0] - pointB[0]) ** 2 + (pointA[1] - pointB[1]) ** 2
def height5(P, A, B):
a = l2_norm(A, P)
b = l2_norm(B, P)
base = l2_norm(A, B)
... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P.
Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac... | null | In the first sample snow will be removed from that area: | [{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}] | 1,900 | ["binary search", "geometry", "ternary search"] | 60 | [{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
try:
b = float(ref_line)
except:
print(0)
return
with open(submission_path, 'r') as f:
... | true |
436/A | 436 | A | Python 3 | PRETESTS | 7 | 62 | 0 | 6876016 | n, x = [int(c) for c in input().split()]
candies = [[], []]
for i in range(n):
a = [int(c) for c in input().split()]
if a[0] == 0:
candies[0].append(a[1:])
else:
candies[1].append(a[1:])
candies[0].sort(key=lambda x: x[1],reverse=True)
candies[1].sort(key=lambda x: x[1],reverse=True)
d... | 60 | 62 | 307,200 | 10550532 | import sys
from operator import itemgetter
def main():
str = sys.stdin.readline()
tokens = str.split()
n = int(tokens[0])
x = int(tokens[1])
s1=[]
s2=[]
for i in range(n):
str = sys.stdin.readline()
tokens = str.split()
t = int(tokens[0])
h = int(tokens[1])
m = int(tokens[2])
if t==0:
s1.append((h... | Zepto Code Rush 2014 | CF | 2,014 | 2 | 256 | Feed with Candy | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.
One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the ... | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump.
Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the cu... | Print a single integer — the maximum number of candies Om Nom can eat. | null | One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario:
1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7.... | [{"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "output": "4"}] | 1,500 | ["greedy"] | 60 | [{"input": "5 3\r\n0 2 4\r\n1 3 1\r\n0 8 3\r\n0 20 10\r\n1 5 5\r\n", "output": "4\r\n"}, {"input": "5 2\r\n1 15 2\r\n1 11 2\r\n0 17 2\r\n0 16 1\r\n1 18 2\r\n", "output": "0\r\n"}, {"input": "6 2\r\n1 17 3\r\n1 6 1\r\n0 4 2\r\n1 10 1\r\n1 7 3\r\n1 5 1\r\n", "output": "0\r\n"}, {"input": "7 2\r\n1 14 1\r\n1 9 2\r\n0 6 3\... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.