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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
607/A | 607 | A | Python 3 | TESTS | 10 | 873 | 15,974,400 | 81619958 | n=int(input())
arr=[0 for i in range(1000001)]
m=0
for i in range(n):
a,b=map(int,input().split())
if a>m:
m=a
arr[a]=b
dp=[0 for i in range(m+1)]
for i in range(m+1):
if i==0:
if arr[i]==0:
dp[i]=0
else:
dp[i]=1
else:
if arr[i]==0:
... | 41 | 280 | 9,523,200 | 187487591 | from sys import stdin
input = stdin.readline
n = int(input())
c = [0]*(10**6+5)
for _ in range(n):
a, b = [int(x) for x in input().split()]
c[a] = b
for i in range(10**6+1):
if c[i]:
if c[i] >= i: c[i] = 1
else: c[i] = c[i-c[i]-1]+1
else:
c[i] = c[i-1]
print(n-max(c)) | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
789/A | 789 | A | PyPy 3 | TESTS | 27 | 171 | 10,547,200 | 51799493 | n, k = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
ch = 0
for i in A:
cnt += (i + k - 1) // k
ch = max(ch, (i + k - 1) // k)
print(max(ch, (cnt + 1) // 2)) | 31 | 77 | 13,721,600 | 216209898 | import math
mode, capacity = map(int, input().split())
stones = list(map(int, input().split()))
pocket = 0
for i in range(len(stones)):
pocket += math.ceil(stones[i] / capacity)
print(math.ceil(pocket / 2)) | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Anastasia and pebbles | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | null | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
- In the second day she co... | [{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}] | 1,100 | ["implementation", "math"] | 31 | [{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11... | false | stdio | null | true |
789/A | 789 | A | Python 3 | TESTS | 27 | 124 | 11,878,400 | 25941711 | import math
n, k = list(map(int,input().split(" ")))
w = list(map(lambda x: math.ceil(int(x)/k),input().split(" ")))
# print(w)
ans = math.ceil(max(max(w), sum(w)/2))
print(ans) | 31 | 77 | 13,926,400 | 165484947 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for i in range(n):
c = c + 1 + a[i] // k if a[i] % k else c + a[i] // k
c = c // 2 if c % 2 == 0 else c // 2 + 1
print(c) | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Anastasia and pebbles | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | null | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
- In the second day she co... | [{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}] | 1,100 | ["implementation", "math"] | 31 | [{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11... | false | stdio | null | true |
276/A | 276 | A | PyPy 3 | TESTS | 30 | 372 | 21,401,600 | 132846848 | n,k=map(int,input().split())
maximum=-99999999
for i in range(n):
final_time,value_time=map(int,input().split())
if value_time>k:
final_time-=(value_time-k)
maximum=max(maximum,final_time)
print(maximum) | 35 | 92 | 0 | 154053467 | n, k = map(int, input().split())
c = -10**10
for _ in range(n):
f, t = map(int, input().split())
if t > k:
f = (f - t + k)
if f > c:
c = f
print(c) | Codeforces Round 169 (Div. 2) | CF | 2,013 | 2 | 256 | Lunch Rush | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char... | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | null | null | [{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}] | 900 | ["implementation"] | 35 | [{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp... | false | stdio | null | true |
702/B | 702 | B | Python 3 | TESTS | 10 | 311 | 12,902,400 | 227580935 | generate=[]
for i in range(30):
generate.append(1<<i)
def solve():
len1=int(input())
list1=list(map(int,input().split()))
res=0
dict1={list1[0]:1}
for i in range(1,len1):
for j in generate:
if j-list1[i] in dict1:
res+=dict1[j-list1[i]]
if list1[i] in ... | 43 | 155 | 17,100,800 | 185272711 | def start():
c=0
n=int(input())
a=list(map(int,input().split()))
d={}
s=[1]
while s[-1]<10**9:s.append(s[-1]*2)
for i in a:
for j in s:
if j-i in d:
c+=d[j-i]
if i in d:d[i]+=1
else:d[i]=1
print(c)
start() | Educational Codeforces Round 15 | ICPC | 2,016 | 3 | 256 | Powers of Two | You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x). | The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). | Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2. | null | In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).
In the second example all pairs of indexes (i, j) (where i < j) include in answer. | [{"input": "4\n7 3 2 1", "output": "2"}, {"input": "3\n1 1 1", "output": "3"}] | 1,500 | ["brute force", "data structures", "implementation", "math"] | 43 | [{"input": "4\r\n7 3 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "10\r\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607\r\n", "output": "2\r\n"}, {"input": "10\r\n6 6 7 3 9 14 15 7 2... | false | stdio | null | true |
607/A | 607 | A | PyPy 3 | TESTS | 10 | 1,247 | 14,336,000 | 15149542 | import sys
n = int(input())
a = [[0,0] for i in range(0,n)]
f = [0]*n
for i in range(0, n):
inp = input().split()
a[i][0],a[i][1] = int(inp[0]), int(inp[1])
best = n
left = 0
a = sorted(a)
for i in range(0,n):
while left+1<n and a[i][0]-a[i][1]>a[left+1][0]:
left+=1
f[i] = f[left] + i-left-b... | 41 | 311 | 15,974,400 | 169177946 | import sys
import math
import collections
from heapq import heappush, heappop
input = sys.stdin.readline
ints = lambda: list(map(int, input().split()))
n = int(input())
beacons = []
for i in range(n):
a, b = ints()
beacons.append((a, b))
beacons.sort(key=lambda x: x[0])
def bsearch(x):
l, r = 0, n - 1
... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
607/A | 607 | A | PyPy 3 | TESTS | 10 | 1,185 | 17,920,000 | 77082235 | import bisect
from collections import OrderedDict
n=int(input())
l,x=[0]*n,[]
d1={}
for i in range(n):
a,b=map(int,input().split())
d1[a]=b
d=OrderedDict(sorted(d1.items()))
i=0
for a in d:
if len(x)>0:
j=bisect.bisect_left(x,a-d[a])
l[i]=min(len(x)-j+l[j-1],l[i-1]+1)
x.append(a);i+=1
print(l[-1]) | 41 | 327 | 25,907,200 | 155265758 | from math import inf
from collections import *
import math, os, sys, heapq, bisect, random,threading
from functools import lru_cache
from itertools import *
def inp(): return sys.stdin.readline().rstrip("\r\n")
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def inpu(): return int(inp())... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
698/B | 698 | B | PyPy 3 | TESTS | 0 | 61 | 0 | 112882313 | class DSU(object):
def __init__(self, n):
self.p = list(range(n))
self.rk = [0] * n
def find(self, u):
while u != self.p[u]:
u = self.p[u]
return u
def unite(self, u, v):
u = self.find(u)
v = self.find(v)
if u == v:
return
... | 101 | 421 | 18,944,000 | 99957079 | # Why do we fall ? So we can learn to pick ourselves up.
root = -1
def find(i,time):
parent[i] = time
while not parent[aa[i]]:
i = aa[i]
parent[i] = time
# print(parent,"in",i)
if parent[aa[i]] == time:
global root
if root == -1:
root = i
if aa[... | Codeforces Round 363 (Div. 1) | CF | 2,016 | 2 | 256 | Fix a Tree | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n). | In the first line print the minimum number of elements to change, in order to get a valid sequence.
In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted. | null | In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On bo... | [{"input": "4\n2 3 3 4", "output": "1\n2 3 4 4"}, {"input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3"}, {"input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7"}] | 1,700 | ["constructive algorithms", "dfs and similar", "dsu", "graphs", "trees"] | 101 | [{"input": "4\r\n2 3 3 4\r\n", "output": "1\r\n2 3 4 4 \r\n"}, {"input": "5\r\n3 2 2 5 3\r\n", "output": "0\r\n3 2 2 5 3 \r\n"}, {"input": "8\r\n2 3 5 4 1 6 6 7\r\n", "output": "2\r\n2 3 7 8 1 6 6 7\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n2 2 \r\n"}, {"input": "7\r\n4 3 2 6 3 5 2\r\n", "output": "1\r\n4 3 3 6 ... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
assert len(a) == n
# Read submission's output
with open(submission_output_path... | true |
276/A | 276 | A | Python 3 | TESTS | 30 | 124 | 0 | 170964062 | n, k = map(int, input().split())
ud = -3200000
for i in range(n):
f, t = map(int, input().split())
if t > k:
f = f -(t - k)
if f > ud:
ud = f
print(ud) | 35 | 92 | 0 | 158673847 | a=[int(x) for x in input().split()]
d=[]
for i in range(a[0]):
b=[int(x) for x in input().split()]
if(b[1]>a[1]):
d.append(b[0]-(b[1]-a[1]))
else:
d.append(b[0])
print(max(d)) | Codeforces Round 169 (Div. 2) | CF | 2,013 | 2 | 256 | Lunch Rush | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char... | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | null | null | [{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}] | 900 | ["implementation"] | 35 | [{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp... | false | stdio | null | true |
276/A | 276 | A | PyPy 3-64 | TESTS | 30 | 310 | 6,144,000 | 208940976 | def main():
n, k = list(map(int, input().split()))
ans = -100000000
for i in range(n):
f, t = list(map(int, input().split()))
if t > k:
ans = max(ans, f - (t - k))
else:
ans = max(ans, f)
print(ans)
if __name__ == "__main__":
main() | 35 | 92 | 0 | 159096667 | import sys
k =input().split()
n,m = int(k[0]),int(k[1])
j = -999999999999
for i in range(n):
a = [int(a) for a in input().split()]
if a[1] <= m:
l=a[0]
else:
l=a[0]-(a[1]-m)
if l > j:
j=l
print(j) | Codeforces Round 169 (Div. 2) | CF | 2,013 | 2 | 256 | Lunch Rush | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char... | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | null | null | [{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}] | 900 | ["implementation"] | 35 | [{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp... | false | stdio | null | true |
276/A | 276 | A | PyPy 3-64 | TESTS | 30 | 312 | 6,963,200 | 172644917 | n,k=map(int,input().split())
l=[]
for _ in range(n):
l.append(list(map(int,input().split())))
ans=-99999999
for i in l:
if i[1]>k:
ans=max(ans,i[0]-i[1]+k)
else:
ans=max(ans,i[0])
print(ans) | 35 | 92 | 0 | 161479743 | a,b=map(int,input().split())
lst=[]
for i in range(a):
c,d=map(int,input().split())
if d>b:
lst.append(c-(d-b))
else:
lst.append(c)
print(max(lst)) | Codeforces Round 169 (Div. 2) | CF | 2,013 | 2 | 256 | Lunch Rush | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char... | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | null | null | [{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}] | 900 | ["implementation"] | 35 | [{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp... | false | stdio | null | true |
272/B | 272 | B | PyPy 3 | TESTS | 3 | 216 | 21,401,600 | 127216482 | f = [0 for _ in range(2*10**3+20)]
n = int(input())
a = list(map(int, input().split()))
for x in range(10**3+2):
f[2 * x] = f[x]
f[2 * x + 1] = f[x] + 1
def find_value(x):
while x > 1000:
if x % 2 == 0:
x = x // 2
else:
x -= 1
x // 2... | 42 | 218 | 10,444,800 | 211338092 | n=int(input())
z=10**5
a=[0]*z
for x in map(int,input().split()):
a[bin(x).count("1")]+=1
ans=0
for x in a:
ans+=x*(x-1)//2
print(ans) | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Sequence | Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
- f(0) = 0;
- f(2·x) = f(x);
- f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are the... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces. | In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do. | [{"input": "3\n1 2 4", "output": "3"}, {"input": "3\n5 3 1", "output": "1"}] | 1,400 | ["implementation", "math"] | 42 | [{"input": "3\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n469264357 996569493\r\n", "output": "0\r\n"}, {"input": "6\r\n396640239 62005863 473635171 329666981 510631133 207643327\r\n", "output": "2\r\n"}, {"input": "8\r\n851991424 32517099 310793856 776130403 34262... | false | stdio | null | true |
698/B | 698 | B | Python 3 | TESTS | 4 | 31 | 0 | 145139766 | n = int(input())
arr = list(map(int,input().split()))
arr.insert(0,0)
par = [i for i in range(0,n+1)]
def find(i):
if i!=par[i]:
par[i] = find(par[i])
return par[i]
def merge(x,y):
if x == y:return True
a = find(x)
b =find(y)
if a == b:
return False
par[a] = b
retu... | 101 | 421 | 22,220,800 | 94390383 | # from debug import debug
import sys; input = sys.stdin.readline
n = int(input())
lis = [0, *map(int , input().split())]
v = [0]*(n+1)
cycles = set()
roots = set()
for i in range(1, n+1):
if v[i] == 0:
node = i
while v[node] == 0:
v[node] = 1
node = lis[node]
if v[node] == 2: continue
start = node
igno... | Codeforces Round 363 (Div. 1) | CF | 2,016 | 2 | 256 | Fix a Tree | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n). | In the first line print the minimum number of elements to change, in order to get a valid sequence.
In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted. | null | In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On bo... | [{"input": "4\n2 3 3 4", "output": "1\n2 3 4 4"}, {"input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3"}, {"input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7"}] | 1,700 | ["constructive algorithms", "dfs and similar", "dsu", "graphs", "trees"] | 101 | [{"input": "4\r\n2 3 3 4\r\n", "output": "1\r\n2 3 4 4 \r\n"}, {"input": "5\r\n3 2 2 5 3\r\n", "output": "0\r\n3 2 2 5 3 \r\n"}, {"input": "8\r\n2 3 5 4 1 6 6 7\r\n", "output": "2\r\n2 3 7 8 1 6 6 7\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n2 2 \r\n"}, {"input": "7\r\n4 3 2 6 3 5 2\r\n", "output": "1\r\n4 3 3 6 ... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
assert len(a) == n
# Read submission's output
with open(submission_output_path... | true |
33/A | 33 | A | Python 3 | TESTS | 4 | 92 | 0 | 142031155 | n, m, k = [int(item) for item in (input().split(' '))]
_sum = 0
_dict = {}
for i in range(n):
_row, health = [int(item) for item in (input().split(' '))]
_dict[_row] = health
if _dict.__contains__(_row) and _dict[_row] > health or _dict.__contains__(_row):
_dict[_row] = health
for i in range(1,len(... | 31 | 92 | 0 | 225573474 | n, m, k = [int(item) for item in input().split()]
sum = 0
cont = {}
for _len in range(0, n, 1):
row, health = [int(item) for item in input().split()]
if(cont.get(row) != None and cont[row] >= health or cont.get(row) == None):
cont[row] = health
for [key, val] in cont.items():
sum += val
print((la... | Codeforces Beta Round 33 (Codeforces format) | CF | 2,010 | 2 | 256 | What is for dinner? | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
... | The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c... | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | null | null | [{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}] | 1,200 | ["greedy", "implementation"] | 31 | [{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\... | false | stdio | null | true |
789/A | 789 | A | Python 3 | TESTS | 26 | 311 | 11,878,400 | 25919694 | """ Created by Shahen Kosyan on 3/29/17 """
if __name__ == "__main__":
n, k = map(int, input().split())
w = [int(x) for x in input().split()]
# w = sorted(w)
days = 0
i = 0
pockets = 0
while i < len(w):
if w[i] >= 2 * k:
d = w[i] // (2 * k)
days += d
... | 31 | 77 | 17,612,800 | 184007780 | s = input().split()
n, k = int(s[0]), int(s[1])
l = []
s = input().split()
for i in range(n):
l.append(int(s[i]))
a = []
for i in range(n):
a.append((int(l[i] / k), l[i] % k))
fullDays = 0
modDays = 0
for i in range(n):
if a[i][0]:
fullDays += a[i][0]
if a[i][1]:
modDays += 1
if... | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Anastasia and pebbles | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | null | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
- In the second day she co... | [{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}] | 1,100 | ["implementation", "math"] | 31 | [{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11... | false | stdio | null | true |
621/C | 621 | C | Python 3 | TESTS | 3 | 31 | 0 | 205752948 | n,m=map(int,input().split())
l=[]
prop=1
for i in range(n):
a,b=map(int,input().split())
y=0
prop*=(b-a+1)
if a%m==0:
a-=1
y=1
div=b//m-a//m
if y:
a+=1
ndiv=(b-a)+1-div
l.append([ndiv,div])
suq=0
le=len(l)
pq1=1
for i in range(le):
re=(l[i][1])*(prop//sum(l[i]... | 94 | 124 | 9,318,400 | 218386639 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
alph = 'abcdefghijklmnopqrstuvwxyz'
#pow(x,mod-2,mod)
N,P = map(int,input().split(... | Codeforces Round 341 (Div. 2) | CF | 2,016 | 2 | 256 | Wet Shark and Flowers | There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.
Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from... | The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime.
The i-th of the following n lines contains information about i-th shark — two space-separated integers li and ri (1 ≤... | Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correc... | null | A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.
Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of ... | [{"input": "3 2\n1 2\n420 421\n420420 420421", "output": "4500.0"}, {"input": "3 5\n1 4\n2 3\n11 14", "output": "0.0"}] | 1,700 | ["combinatorics", "math", "number theory", "probabilities"] | 94 | [{"input": "3 2\r\n1 2\r\n420 421\r\n420420 420421\r\n", "output": "4500.0\r\n"}, {"input": "3 5\r\n1 4\r\n2 3\r\n11 14\r\n", "output": "0.0\r\n"}, {"input": "3 3\r\n3 3\r\n2 4\r\n1 1\r\n", "output": "4666.666666666667\r\n"}, {"input": "5 5\r\n5 204\r\n420 469\r\n417 480\r\n442 443\r\n44 46\r\n", "output": "3451.25\r\n... | false | stdio | import sys
def read_number(path):
with open(path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
if len(lines) != 1:
return None
try:
return float(lines[0])
except ValueError:
return None
def main():
input_path = ... | true |
620/D | 620 | D | PyPy 3-64 | TESTS | 8 | 139 | 14,848,000 | 170932164 | import sys
readline=sys.stdin.readline
write=sys.stdout.write
N=int(readline())
A=list(map(int,readline().split()))
M=int(readline())
B=list(map(int,readline().split()))
sum_A=sum(A)
sum_B=sum(B)
inf=1<<60
AA=[A[i]+A[j] for i in range(N) for j in range(i+1,N)]
BB=[B[i]+B[j] for i in range(M) for j in range(i+1,M)]
AA.... | 24 | 2,995 | 152,166,400 | 92182162 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
sum_a, sum_b = sum(a), sum(b)
delta = sum_b - sum_a
ans = abs(delta)
ans_swap = []
for i in range(n):
for j in range(m):
if abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b... | Educational Codeforces Round 6 | ICPC | 2,016 | 3 | 256 | Professor GukiZ and Two Arrays | Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.
In one operation professor can swap some element from the array a and some element f... | The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.
The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.
The fourth line contains m integers bj ( - 109 ... | In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.
The second line should contain the number of swaps k (0 ≤ k ≤ 2).
Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the ele... | null | null | [{"input": "5\n5 4 3 2 1\n4\n1 1 1 1", "output": "1\n2\n1 1\n4 2"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "0\n0"}, {"input": "5\n1 2 3 4 5\n4\n1 2 3 4", "output": "1\n1\n3 1"}] | 2,200 | ["binary search", "two pointers"] | 24 | [{"input": "5\r\n5 4 3 2 1\r\n4\r\n1 1 1 1\r\n", "output": "1\r\n2\r\n1 1\r\n4 2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "0\r\n0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n4\r\n1 2 3 4\r\n", "output": "1\r\n1\r\n3 1\r\n"}, {"input": "1\r\n-42\r\n1\r\n-86\r\n", "output": "44\r\n0\r\n"}, {"input": "1\r\n-21\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
a = list(map(int, f.readline().strip().split()))
m = int(f.readline().strip())
b = list(map(int, f.readline().strip().split()))
# Read r... | true |
620/D | 620 | D | PyPy 3 | TESTS | 9 | 1,840 | 72,601,600 | 92181127 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
sum_a, sum_b = sum(a), sum(b)
delta = sum_b - sum_a
ans = abs(delta)
ans_swap = []
for i, x in enumerate(a, start=1):
for j, y in enumerate(b, start=1):
if abs((sum_a - ... | 24 | 2,995 | 152,166,400 | 92182162 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
sum_a, sum_b = sum(a), sum(b)
delta = sum_b - sum_a
ans = abs(delta)
ans_swap = []
for i in range(n):
for j in range(m):
if abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b... | Educational Codeforces Round 6 | ICPC | 2,016 | 3 | 256 | Professor GukiZ and Two Arrays | Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.
In one operation professor can swap some element from the array a and some element f... | The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.
The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.
The fourth line contains m integers bj ( - 109 ... | In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.
The second line should contain the number of swaps k (0 ≤ k ≤ 2).
Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the ele... | null | null | [{"input": "5\n5 4 3 2 1\n4\n1 1 1 1", "output": "1\n2\n1 1\n4 2"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "0\n0"}, {"input": "5\n1 2 3 4 5\n4\n1 2 3 4", "output": "1\n1\n3 1"}] | 2,200 | ["binary search", "two pointers"] | 24 | [{"input": "5\r\n5 4 3 2 1\r\n4\r\n1 1 1 1\r\n", "output": "1\r\n2\r\n1 1\r\n4 2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "0\r\n0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n4\r\n1 2 3 4\r\n", "output": "1\r\n1\r\n3 1\r\n"}, {"input": "1\r\n-42\r\n1\r\n-86\r\n", "output": "44\r\n0\r\n"}, {"input": "1\r\n-21\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
a = list(map(int, f.readline().strip().split()))
m = int(f.readline().strip())
b = list(map(int, f.readline().strip().split()))
# Read r... | true |
111/B | 111 | B | Python 3 | TESTS | 4 | 186 | 0 | 50271901 | import sys
def divisor(n):
div = list()
i = 1
sqrt = n**(1/2)
while i <= sqrt:
if (n % i) == 0:
div.append(i)
if i != (n/i):
div.append(int(n/i))
i += 1
return div
n = int(sys.stdin.readline())
xs = list()
for i in range(n):
x = list(ma... | 44 | 1,278 | 10,854,400 | 91672692 | import sys
import collections as cc
input=sys.stdin.buffer.readline
I=lambda:list(map(int,input().split()))
prev=cc.defaultdict(int)
for tc in range(int(input())):
x,y=I()
div=set()
for i in range(1,int(x**0.5)+1):
if x%i==0:
div.add(i)
div.add(x//i)
ans=0
now=tc+1
for i in div:
if now-prev[i]>y:
ans... | Codeforces Beta Round 85 (Div. 1 Only) | CF | 2,011 | 5 | 256 | Petya and Divisors | Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him. | The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of t... | For each query print the answer on a single line: the number of positive integers k such that $${ x _ { i } \bmod k = 0 \& ( \forall j : i - y _ { i } \leq j < i ) x _ { j } \bmod k \neq 0 }$$ | null | Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | [{"input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3", "output": "3\n1\n1\n2\n2\n22"}] | 1,900 | ["binary search", "data structures", "number theory"] | 44 | [{"input": "6\r\n4 0\r\n3 1\r\n5 2\r\n6 2\r\n18 4\r\n10000 3\r\n", "output": "3\r\n1\r\n1\r\n2\r\n2\r\n22\r\n"}, {"input": "5\r\n10 0\r\n10 0\r\n10 0\r\n10 0\r\n10 0\r\n", "output": "4\r\n4\r\n4\r\n4\r\n4\r\n"}, {"input": "12\r\n41684 0\r\n95210 1\r\n60053 1\r\n32438 3\r\n97956 1\r\n21785 2\r\n14594 6\r\n17170 4\r\n939... | false | stdio | null | true |
390/A | 390 | A | Python 3 | TESTS | 14 | 592 | 0 | 64330370 | n=int(input())
lv=[];lg=[]
v,g=[0]*2
for i in range(n):
a,b=[int(x) for x in input().split()]
if a not in lv:
v+=1
lv.append(a)
if b not in lg:
g+=1
lg.append(a)
print(min(v,g)) | 19 | 171 | 0 | 159169799 | h=set()
v=set()
for i in range(int(input())):
k = input().split()
v.add(k[0])
h.add(k[1])
print(min(len(v),len(h))) | Codeforces Round 229 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Alarm Clock | Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.
The morning has ... | The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100).
Note that a single point in the room can contain any number of alarm clocks and t... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | null | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | [{"input": "4\n0 0\n0 1\n0 2\n1 0", "output": "2"}, {"input": "4\n0 0\n0 1\n1 0\n1 1", "output": "2"}, {"input": "4\n1 1\n1 2\n2 3\n3 3", "output": "3"}] | null | ["implementation"] | 19 | [{"input": "4\r\n0 0\r\n0 1\r\n0 2\r\n1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1\r\n1 2\r\n2 3\r\n3 3\r\n", "output": "3\r\n"}, {"input": "1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "42\r\n28 87\r\n26 16\r\n59 90\r\n47 61\r\n28 83\r\n36 30\r\n6... | false | stdio | null | true |
859/E | 859 | E | PyPy 3-64 | TESTS | 3 | 93 | 4,710,400 | 226374061 | import sys
import math
from math import ceil
from functools import lru_cache
input = sys.stdin.readline
def womais(i,j):
if i == 0:
return j
elif j == 0:
return i
else:
return min(i,j)
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
sel... | 36 | 187 | 16,076,800 | 226366340 | import sys
input = sys.stdin.readline
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
... | MemSQL Start[c]UP 3.0 - Round 1 | CF | 2,017 | 2 | 256 | Desk Disorder | A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,... | Input will begin with a line containing N (1 ≤ N ≤ 100000), the number of engineers.
N lines follow, each containing exactly two integers. The i-th line contains the number of the current desk of the i-th engineer and the number of the desk the i-th engineer wants to move to. Desks are numbered from 1 to 2·N. It is gu... | Print the number of possible assignments, modulo 1000000007 = 109 + 7. | null | These are the possible assignments for the first example:
- 1 5 3 7
- 1 2 3 7
- 5 2 3 7
- 1 5 7 3
- 1 2 7 3
- 5 2 7 3 | [{"input": "4\n1 5\n5 2\n3 7\n7 3", "output": "6"}, {"input": "5\n1 10\n2 10\n3 10\n4 10\n5 5", "output": "5"}] | 2,100 | ["combinatorics", "dfs and similar", "dsu", "graphs", "trees"] | 36 | [{"input": "4\r\n1 5\r\n5 2\r\n3 7\r\n7 3\r\n", "output": "6\r\n"}, {"input": "5\r\n1 10\r\n2 10\r\n3 10\r\n4 10\r\n5 5\r\n", "output": "5\r\n"}, {"input": "1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "30\r\n22 37\r\n12 37\r\n37 58\r\n29 57\r\n43 57\r\n57 58\r\n58 53\r\n45 4\r\n1 4\r\n4 51\r\n35 31\r\n21 31\r\n31 51\r... | false | stdio | null | true |
859/E | 859 | E | Python 3 | TESTS | 3 | 46 | 512,000 | 109511010 | class UnionFind:
def __init__(self, n):
self._num_of_set = n
self._set_size = [1] * n
self._rank = [0] * n
self._parent = [i for i in range(n)]
def findSet(self, i):
if self._parent[i] != i:
self._parent[i] = self.findSet(self._parent[i])
return self.... | 36 | 187 | 16,076,800 | 226366340 | import sys
input = sys.stdin.readline
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
... | MemSQL Start[c]UP 3.0 - Round 1 | CF | 2,017 | 2 | 256 | Desk Disorder | A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,... | Input will begin with a line containing N (1 ≤ N ≤ 100000), the number of engineers.
N lines follow, each containing exactly two integers. The i-th line contains the number of the current desk of the i-th engineer and the number of the desk the i-th engineer wants to move to. Desks are numbered from 1 to 2·N. It is gu... | Print the number of possible assignments, modulo 1000000007 = 109 + 7. | null | These are the possible assignments for the first example:
- 1 5 3 7
- 1 2 3 7
- 5 2 3 7
- 1 5 7 3
- 1 2 7 3
- 5 2 7 3 | [{"input": "4\n1 5\n5 2\n3 7\n7 3", "output": "6"}, {"input": "5\n1 10\n2 10\n3 10\n4 10\n5 5", "output": "5"}] | 2,100 | ["combinatorics", "dfs and similar", "dsu", "graphs", "trees"] | 36 | [{"input": "4\r\n1 5\r\n5 2\r\n3 7\r\n7 3\r\n", "output": "6\r\n"}, {"input": "5\r\n1 10\r\n2 10\r\n3 10\r\n4 10\r\n5 5\r\n", "output": "5\r\n"}, {"input": "1\r\n1 2\r\n", "output": "2\r\n"}, {"input": "30\r\n22 37\r\n12 37\r\n37 58\r\n29 57\r\n43 57\r\n57 58\r\n58 53\r\n45 4\r\n1 4\r\n4 51\r\n35 31\r\n21 31\r\n31 51\r... | false | stdio | null | true |
789/A | 789 | A | Python 3 | TESTS | 27 | 93 | 13,824,000 | 217967030 | # بسم الله (not accepted) ... time limit exceeded
n,k = map(int,input().split(' '))
pebbles_list = input().split(' ')
pebbles_list = [int(item) for item in pebbles_list]
output = 0
for value in pebbles_list :
if n ==1 :
output = 1
break
if value % k == 0 :
output += value/k
... | 31 | 78 | 7,372,800 | 146159356 | n,k = map(int,input().split())
w = list(map(int,input().split()))
cnt = 0
res = 0
for i in w:
cnt += (i+k-1)//k
print((cnt+1)//2) | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Anastasia and pebbles | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | null | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
- In the second day she co... | [{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}] | 1,100 | ["implementation", "math"] | 31 | [{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11... | false | stdio | null | true |
489/A | 489 | A | PyPy 3-64 | TESTS | 0 | 30 | 0 | 205286601 | n=int(input())
l=list(map(int,input().split()))
ll=[]
while 1:
itr=0
for i in range(n-1):
if l[i]>l[i+1]:
ll.append((i,i+1))
l[i+1],l[i]=l[i],l[i+1]
itr+=1
if itr==0:
break
print(len(ll))
for o,p in ll:
print(o,p) | 22 | 124 | 7,168,000 | 214607359 | def min_index(i,arr):
res=i
for j in range(i + 1, n):
if a[j] < a[res]:
res = j
return res
n = int(input())
a = list(map(int, input().split()))
swaps = []
for i in range(n):
m = min_index(i,a)
if i != m:
a[i], a[m] = a[m], a[i]
swaps.append((i, m))
print(len(s... | Codeforces Round 277.5 (Div. 2) | CF | 2,014 | 1 | 256 | SwapSort | In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of sw... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr... | In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per... | null | null | [{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}] | 1,200 | ["greedy", "implementation", "sortings"] | 22 | [{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
sub_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().split()))
with open(sub_path) as f:
lines = f.readlines()
if not lines:
... | true |
489/A | 489 | A | Python 3 | TESTS | 5 | 31 | 0 | 210207317 | length_array = int(input())
array = list(map(int, input().split()))
right_pointer = length_array
max_integer = - 10**9 - 1
position_max_integer = 0
swap_pairs = []
def swap(index_first, index_second, lst):
temp = lst[index_first]
lst[index_first] = lst[index_second]
lst[index_second] = temp
while right_... | 22 | 140 | 3,891,200 | 223354529 | n = int(input())
a = list(map(int, input().split()))
IT = []
for i in range(n):
ind = -1
minc = a[i]
for j in range(i + 1, n):
if a[j] < minc:
minc = a[j]
ind = j
if ind != -1:
a[i], a[ind] = a[ind], a[i]
IT.append((i, ind))
print(len(IT))
for i in IT:
... | Codeforces Round 277.5 (Div. 2) | CF | 2,014 | 1 | 256 | SwapSort | In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of sw... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr... | In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per... | null | null | [{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}] | 1,200 | ["greedy", "implementation", "sortings"] | 22 | [{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
sub_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().split()))
with open(sub_path) as f:
lines = f.readlines()
if not lines:
... | true |
985/C | 985 | C | PyPy 3-64 | TESTS | 7 | 93 | 13,721,600 | 183459953 | n, k, r = map(int, input().split())
a = sorted(list(map(int, input().split())))
if (a[n - 1] - a[0]) > r:
print(0)
else:
h = n - 1
u = 0
if k != 1:
for i in range(n, n * k):
if (a[i] - a[0]) > r:
break
else:
u += 1
h = i
... | 50 | 155 | 7,884,800 | 152488718 | R = lambda:map(int,input().split())
n, k, l = R()
a = sorted(R())
s = c = 0
for i in range(n*k-1, -1, -1):
c += 1
if a[i]-a[0] <= l and c>=k:
s += a[i]
c -= k
print((s,0)[c>0]) | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Liebig's Barrels | You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
You want to assemble exac... | The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n. | null | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | [{"input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7"}, {"input": "2 1 0\n10 10", "output": "20"}, {"input": "1 2 1\n5 2", "output": "2"}, {"input": "3 2 1\n1 2 3 4 5 6", "output": "0"}] | 1,500 | ["greedy"] | 50 | [{"input": "4 2 1\r\n2 2 1 2 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "2 1 0\r\n10 10\r\n", "output": "20\r\n"}, {"input": "1 2 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 2 1\r\n1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "10 3 189\r\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 4... | false | stdio | null | true |
985/C | 985 | C | PyPy 3-64 | TESTS | 7 | 108 | 15,155,200 | 183355520 | n, k, l = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
var = []
for i in range(n * k):
if a[i] - a[0] <= l:
var.append(a[i])
ans = 0
prosh = min(a[0:k:])
if a[n - 1] - a[0] > l:
print(0)
exit()
if k == 1:
ans = 0
for i in range(n):
ans += var[i]
... | 50 | 155 | 8,089,600 | 38548199 | from bisect import*
R=lambda:map(int,input().split())
n,k,l=R()
a=sorted(R())
i=bisect_right(a,a[0]+l)
if i<n:print(0)
else:
s=sum(a[0:i:k]);n-=(i-1)//k+1
while n:
i-=1
if i%k:
s+=a[i];n-=1
print(s) | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Liebig's Barrels | You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
You want to assemble exac... | The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n. | null | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | [{"input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7"}, {"input": "2 1 0\n10 10", "output": "20"}, {"input": "1 2 1\n5 2", "output": "2"}, {"input": "3 2 1\n1 2 3 4 5 6", "output": "0"}] | 1,500 | ["greedy"] | 50 | [{"input": "4 2 1\r\n2 2 1 2 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "2 1 0\r\n10 10\r\n", "output": "20\r\n"}, {"input": "1 2 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 2 1\r\n1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "10 3 189\r\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 4... | false | stdio | null | true |
484/B | 484 | B | Python 3 | TESTS | 11 | 405 | 14,336,000 | 43780439 | n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
k=0
ma=0
s=l[0]
r=0
for i in range(n-1) :
k+=l[i+1]%l[i]
while k>=s :
k-=l[r+1]%l[r]
r+=1
s=l[r]
ma=max(k,ma)
print(ma) | 45 | 358 | 45,568,000 | 143541801 | import bisect
MAXN = 10**6
N = int(input())
exist = [False for i in range(MAXN + 10)]
arr = list(map(int, input().split()))
a = []
for x in arr:
if exist[x] == False:
exist[x] = True
a.append(x)
a.sort()
N = len(a)
ans = 0
for i in range(N - 2, -1, -1):
if ans >= a[i] - 1:
break
... | Codeforces Round 276 (Div. 1) | CF | 2,014 | 1 | 256 | Maximum Value | You are given a sequence a consisting of n integers. Find the maximum possible value of $$a_i \bmod a_j$$ (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj. | The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106). | Print the answer to the problem. | null | null | [{"input": "3\n3 4 5", "output": "2"}] | 2,100 | ["binary search", "math", "sortings", "two pointers"] | 45 | [{"input": "3\r\n3 4 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000 999999\r\n", "output": "1\r\n"}, {"input": "12\r\n4 4 10 13 28 30 41 43 58 61 70 88\r\n", "output": "30\r... | false | stdio | null | true |
187/A | 187 | A | Python 3 | TESTS | 5 | 62 | 0 | 155371612 | n = int(input())
p1 = input().split(' ')
p2 = input().split(' ')
count = 0
c = 0
while p1 != p2 and c < 20:
c += 1
x = p1[-1]
for i in range(n):
if p1[:i + 1] != p2[:i + 1]:
p1.pop()
p1.insert(i, x)
count += 1
break
print(count) | 58 | 842 | 40,755,200 | 31481440 | n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
used = set()
j = len(l1)-1
worst = j
for i in range(len(l2)-1, -1, -1):
if l2[i] in used:
continue
if l2[i] == l1[j]:
j-=1
else:
while l2[i] != l1[j]:
used.add(l1[j])
... | Codeforces Round 119 (Div. 1) | CF | 2,012 | 2 | 256 | Permutations | Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot.
One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the perm... | The first line contains a single integer n (1 ≤ n ≤ 2·105) — the quantity of the numbers in the both given permutations.
Next line contains n space-separated integers — the first permutation. Each number between 1 to n will appear in the permutation exactly once.
Next line describe the second permutation in the same ... | Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. | null | In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3.
In the second sample, he removes number 5 and inserts it after 1.
In the third sample, the sequence of changes are like this:
- 1 5 2 3 4
- 1 4 5 2 3
- 1 3 4 5 2
-... | [{"input": "3\n3 2 1\n1 2 3", "output": "2"}, {"input": "5\n1 2 3 4 5\n1 5 2 3 4", "output": "1"}, {"input": "5\n1 5 2 3 4\n1 2 3 4 5", "output": "3"}] | 1,500 | ["greedy"] | 58 | [{"input": "3\r\n3 2 1\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1 5 2 3 4\r\n", "output": "1\r\n"}, {"input": "5\r\n1 5 2 3 4\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "7\r\n6 1 7 3 4 5 2\r\n6 1 7 3 4 5 2\r\n", "output": "0\r\n"}, {"input": ... | false | stdio | null | true |
298/A | 298 | A | PyPy 3 | TESTS | 4 | 280 | 0 | 77181342 | n=int(input())
x=input()
a=list(x)
s=0
t=0
if a.count("L")==0:
s=x.rindex("R")+1
t=s+1
elif a.count("R")==0:
s=a.index("L")+1
t=s-1
else:
if a.count("R")==a.count("L"):
s=a.index("R")+1
t=s+1
elif a.count("L")>a.count("R"):
s=a.index("L")+abs(a.count("L")-a... | 23 | 62 | 0 | 145061241 | n = int(input())
arr = input()
l = []
l[0:] = arr
arr = l
start = 0
end = 0
for i in range(n):
if arr[i] != '.':
start = i
break
for i in reversed(range(n)):
if arr[i] != '.':
end = i
break
if arr[start] == 'R' and arr[end] == 'R':
print(start + 1, end + 2)
elif arr[start]... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Snow Footprints | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed t... | Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them. | null | The first test sample is the one in the picture. | [{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}] | 1,300 | ["greedy", "implementation"] | 23 | [{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
road = f.readline().strip()
with open(submission_path) as f:
line = f.readline().strip()
try:
s, t = map(int, l... | true |
362/A | 362 | A | Python 3 | TESTS | 6 | 46 | 0 | 184401829 | def dfs(position, end, mark):
mark[position[0]][position[1]] = True
# print(position)
# Possible moves
# Move 1
row = position[0] + 2
col = position[1] + 2
if row >= 0 and row < 8 and col >= 0 and col < 8 and not mark[row][col]:
dfs((row, col), end, mark)
# Move 2
row = po... | 45 | 62 | 307,200 | 5100480 | def check(x, y):
return 0 <= x < 8 and 0 <= y < 8
def dfs1(x, y, T=0):
global first, used
if not(check(x, y)) or used[x][y]:
return
used[x][y] = True
first.add((x, y, T))
for pair in (2, 2), (2, -2), (-2, 2), (-2, -2):
dfs1(x + pair[0], y + pair[1], 1 - T)
def dfs2(x, y, T=0):
... | Codeforces Round 212 (Div. 2) | CF | 2,013 | 1 | 256 | Two Semiknights Meet | A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le... | The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t... | For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. | null | Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ... | [{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}] | 1,500 | ["greedy", "math"] | 45 | [{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n... | false | stdio | null | true |
651/B | 651 | B | Python 3 | TESTS | 5 | 61 | 0 | 109992369 | n=int(input())
arr=sorted(list(map(int,input().split())))
t=0
for i in arr:
if i<max(arr):
t+=1
print(t) | 31 | 46 | 0 | 223924642 | num=input()
arr=input().split(' ')
arr=list(map(int,arr))
freq_arr=dict()
for ele in arr:
if ele in freq_arr:
freq_arr[ele]+=1
else:
freq_arr[ele]=1
arr=list(freq_arr.values())
arr.sort()
ans=0
for indx in range(len(arr)):
for ele in range(indx+1,len(arr)):
arr[ele]-=arr[indx]
... | Codeforces Round 345 (Div. 2) | CF | 2,016 | 1 | 256 | Beautiful Paintings | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement. | null | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | [{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}] | 1,200 | ["greedy", "sortings"] | 31 | [{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67... | false | stdio | null | true |
788/C | 788 | C | Python 3 | TESTS | 2 | 93 | 0 | 52524634 | n, k = map(int, input().split())
arr = list(map(int, input().split()))
possible = [1000000007]*1001
arr.sort()
for i in arr:
possible[i] = 1
for i in range(1, 1001):
for j in arr:
if(i-j < 1):
break
possible[i] = min(possible[i], 1+possible[i-j])
if(possible[n] == 1000000007):
... | 48 | 467 | 44,851,200 | 98107843 | from collections import deque
n, k = map(int, input().split())
conc = set(int(x) - n for x in input().split())
q = deque()
q.append(0)
visited = {i : False for i in range(-1000, 1001)}
dist = {i : 0 for i in range(-1000, 1001)}
ans = -1
visited[0] = True
found = False
while q:
u = q.popleft()
... | Codeforces Round 407 (Div. 1) | CF | 2,017 | 1 | 256 | The Great Mixing | Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration $${ \frac { a _ { i } } { 1 0 0 0 } }$$. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentrati... | The first line contains two integers n, k (0 ≤ n ≤ 1000, 1 ≤ k ≤ 106) — carbon dioxide concentration the friends want and the number of Coke types.
The second line contains k integers a1, a2, ..., ak (0 ≤ ai ≤ 1000) — carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration. | Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration $$\frac{n}{1000}$$, or -1 if it is impossible. | null | In the first sample case, we can achieve concentration $$\frac{400}{1000}$$ using one liter of Coke of types $$\frac{300}{1000}$$ and $${ \frac { 5 0 0 } { 1 0 0 0 } }$$: $$\frac{300+500}{1000+1000}=\frac{400}{1000}$$.
In the second case, we can achieve concentration $${ \frac { 5 0 } { 1 0 0 0 } }$$ using two liters ... | [{"input": "400 4\n100 300 450 500", "output": "2"}, {"input": "50 2\n100 25", "output": "3"}] | 2,300 | ["dfs and similar", "graphs", "shortest paths"] | 48 | [{"input": "400 4\r\n100 300 450 500\r\n", "output": "2\r\n"}, {"input": "50 2\r\n100 25\r\n", "output": "3\r\n"}, {"input": "500 3\r\n1000 5 5\r\n", "output": "199\r\n"}, {"input": "500 1\r\n1000\r\n", "output": "-1\r\n"}, {"input": "874 3\r\n873 974 875\r\n", "output": "2\r\n"}, {"input": "999 2\r\n1 1000\r\n", "outp... | false | stdio | null | true |
985/C | 985 | C | Python 3 | TESTS | 6 | 155 | 7,987,200 | 38547223 | from bisect import*
R=lambda:map(int,input().split())
n,k,l=R()
a=sorted(R())
t=bisect_right(a,a[0]+l)
print(int(t>=n)and a[0]+sum(a[t-n+1:t])) | 50 | 155 | 8,089,600 | 38632447 | from bisect import bisect
def main():
n, k, d = map(int, input().split())
l = sorted(map(int, input().split()))
if l[0] + d < l[n - 1]:
print(0)
return
i = bisect(l, l[0] + d)
a = 0 if k == 1 else (n * k - i) // (k - 1)
print(sum(l[:i - a:k]) + sum(l[i - a:i]))
if __name__ ==... | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Liebig's Barrels | You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
You want to assemble exac... | The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n. | null | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | [{"input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7"}, {"input": "2 1 0\n10 10", "output": "20"}, {"input": "1 2 1\n5 2", "output": "2"}, {"input": "3 2 1\n1 2 3 4 5 6", "output": "0"}] | 1,500 | ["greedy"] | 50 | [{"input": "4 2 1\r\n2 2 1 2 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "2 1 0\r\n10 10\r\n", "output": "20\r\n"}, {"input": "1 2 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 2 1\r\n1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "10 3 189\r\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 4... | false | stdio | null | true |
985/C | 985 | C | Python 3 | TESTS | 6 | 155 | 8,192,000 | 38651840 | def main():
n, k, l = map(int, input().split())
arr = sorted(list(map(int, input().split())))
if arr[n - 1] - arr[0] <= l:
print(sum(arr[:n]))
else:
print("0")
if __name__ == "__main__":
main() | 50 | 171 | 12,902,400 | 133789670 | n, k, l = map(int, input().split())
L = sorted(map(int, input().split()))
a = []
for i in L:
if i <= L[0] + l:
a.append(i)
l1 = len(a)
if l1 < n:
print(0)
elif l1 == n:
print(sum(a))
else:
s = 0
i = 0
while i < l1:
s += a[i]
n -= 1
i = max(min(i + k, l1 - n), i + ... | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Liebig's Barrels | You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
You want to assemble exac... | The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n. | null | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | [{"input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7"}, {"input": "2 1 0\n10 10", "output": "20"}, {"input": "1 2 1\n5 2", "output": "2"}, {"input": "3 2 1\n1 2 3 4 5 6", "output": "0"}] | 1,500 | ["greedy"] | 50 | [{"input": "4 2 1\r\n2 2 1 2 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "2 1 0\r\n10 10\r\n", "output": "20\r\n"}, {"input": "1 2 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 2 1\r\n1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "10 3 189\r\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 4... | false | stdio | null | true |
1004/D | 1004 | D | Python 3 | TESTS | 11 | 1,918 | 63,078,400 | 48306076 | import math
t = int(input())
L = [int(x) for x in input().split()]
L.sort()
ma = max(L)
S = 2*sum(L)
Div = []
for i in range(1,int(math.sqrt(t))+1):
if t%i == 0:
Div.append(i)
Div.append(t//i)
if len(Div) >= 2:
if Div[-1] == Div[-2]:
Div.pop()
Div.sort()
Candidates = []
for i in rang... | 47 | 358 | 79,564,800 | 142294522 | import sys
input = sys.stdin.buffer.readline
def test(n, m, x, y, d):
d2 = [0 for i in range(len(d))]
for i in range(n):
for j in range(m):
D = abs(i-x)+abs(j-y)
if D >= len(d2):
return False
d2[D]+=1
return d==d2
def process(A):
t = len... | Codeforces Round 495 (Div. 2) | CF | 2,018 | 2 | 256 | Sonya and Matrix | Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ... | The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^6$$$) — the number of cells in the matrix.
The second line contains $$$t$$$ integers $$$a_1, a_2, \ldots, a_t$$$ ($$$0\leq a_i< t$$$) — the values in the cells in arbitrary order. | In the first line, print two positive integers $$$n$$$ and $$$m$$$ ($$$n \times m = t$$$) — the size of the matrix.
In the second line, print two integers $$$x$$$ and $$$y$$$ ($$$1\leq x\leq n$$$, $$$1\leq y\leq m$$$) — the row number and the column number where the cell with $$$0$$$ is located.
If there are multiple... | null | You can see the solution to the first example in the legend. You also can choose the cell $$$(2, 2)$$$ for the cell where $$$0$$$ is located. You also can choose a $$$5\times 4$$$ matrix with zero at $$$(4, 2)$$$.
In the second example, there is a $$$3\times 6$$$ matrix, where the zero is located at $$$(2, 3)$$$ there... | [{"input": "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4", "output": "4 5\n2 2"}, {"input": "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1", "output": "3 6\n2 3"}, {"input": "6\n2 1 0 2 1 2", "output": "-1"}] | 2,300 | ["brute force", "constructive algorithms", "implementation"] | 47 | [{"input": "20\r\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\r\n", "output": "4 5\r\n2 2\r\n"}, {"input": "18\r\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\r\n", "output": "3 6\r\n2 3\r\n"}, {"input": "6\r\n2 1 0 2 1 2\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1 1\r\n1 1\r\n"}, {"input": "7\r\n0 1 2 3 4 2 6\r... | false | stdio | import sys
from collections import defaultdict
def read_ints(file):
return list(map(int, file.read().split()))
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
input_lines = f.read().splitlines()
t = int(input_lines[0])
a = list(map(int, input_lines[1].spl... | true |
985/C | 985 | C | Python 3 | TESTS | 6 | 155 | 8,089,600 | 38592637 | def main():
n, k, l = map(int, input().split())
a = sorted(map(int, input().split()))[:n]
print(sum(a) * (a[-1] - a[0] <= l))
if __name__ == '__main__':
main() | 50 | 171 | 17,510,400 | 202628015 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter
N,K,L = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = []
while len(A)>N and A[-1]>A[0]+L:
B.append(A.pop())
if A[-1]>A[0]+L:
exit(print(0))
# print(A)
# print(B)
ans = 0
while A:
cnt... | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Liebig's Barrels | You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
You want to assemble exac... | The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n. | null | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so... | [{"input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7"}, {"input": "2 1 0\n10 10", "output": "20"}, {"input": "1 2 1\n5 2", "output": "2"}, {"input": "3 2 1\n1 2 3 4 5 6", "output": "0"}] | 1,500 | ["greedy"] | 50 | [{"input": "4 2 1\r\n2 2 1 2 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "2 1 0\r\n10 10\r\n", "output": "20\r\n"}, {"input": "1 2 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 2 1\r\n1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "10 3 189\r\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 4... | false | stdio | null | true |
607/A | 607 | A | PyPy 3 | TESTS | 8 | 327 | 10,649,600 | 78525444 | from sys import stdin
from collections import defaultdict
def solve():
n = int(stdin.readline())
energy = defaultdict(int)
maxn = 0
for i in range(n):
a, b, = tuple(map(int, stdin.readline().split(" ")))
maxn = max(maxn, a)
energy[a] = b
ans = 0
table = [1] * (maxn + 1... | 41 | 373 | 11,059,200 | 230287206 | n = int(input())
bb = [0] * 1000001
for _ in range(n):
a_and_b = input()
a, b = a_and_b.split() # n - кол-во целых чисел, k - кол-во элем. заданной посл-ти меньше либо равны x(результат программы)
a = int(a)
b = int(b)
bb[a] = b
a = 0
for i, b in enumerate(bb):
if b > 0:
if i > b:
... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
607/A | 607 | A | Python 3 | TESTS | 8 | 358 | 14,028,800 | 123394164 | from bisect import bisect_left as bl
def f(a,b):
cst=0
dp=[0]*(len(a)+1)
bad=[0]*(len(a))
i=len(a)-1
ans=float("inf")
for i in range(len(a)):
# print("upar i ",i)
l=a[i]
r=b[i]
rr=bl(a,l-r)
# print(i-rr)
if rr==0:
dp[i]=i
else:
dp[i]=i-rr+dp[rr-1]
ans=min(ans,len(a)-1-i+dp[i])
return ans... | 41 | 467 | 10,342,400 | 67523977 | from sys import stdin
item=lambda:stdin.readline().split()
n=int(stdin.readline())
lst,d=[],{}
for _ in range(n):
a,b=map(int,item())
d[a]=b
lst.append(a)
lst.sort()
res=[0]*n
from bisect import bisect_left as bis
for i,x in enumerate(lst):
elem=bis(lst,x-d[x])-1
if elem==-1:res[i]=i;continue
re... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
463/B | 463 | B | PyPy 3-64 | TESTS | 11 | 62 | 13,516,800 | 185176172 | n=int(input())
m=list(map(int,input().split()))
sum=0-m[0]
count=0
if(n==1):
print(abs(sum))
else:
for i in range(n - 1):
if (sum < 0):
count += abs(sum)
sum += abs(sum)
sum = sum + (m[i] - m[i + 1])
print(count) | 49 | 61 | 13,107,200 | 226982327 | int(input())
a = [int(_) for _ in input().split()]
print(max(a)) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
463/B | 463 | B | Python 3 | TESTS | 9 | 265 | 6,348,800 | 70524300 | c=0
z=int(input())
x=list(map(int,input().split()))
dollers=x[0]
for i in range(z-1):
if (x[i]-x[i+1])<0 and c-abs(x[i]-x[i+1])<0:
dollers+=abs(x[i]-x[i+1])-c
c=0
elif (x[i]-x[i+1])>0:
c+=(x[i]-x[i+1])
elif (x[i]-x[i+1])<0 and c-abs(x[i]-x[i+1])>0:
c-=abs(x[i]-x[i+1]) ... | 49 | 62 | 5,529,600 | 170419342 | print(max(map(int,[*open(0)][1].split()))) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
391/B | 391 | B | PyPy 3 | TESTS | 3 | 124 | 0 | 48091695 | a = str(input())
anss = []
for i in range(len(a)):
anss.append(a.count(a[i]))
print(max(anss)//2+1) | 25 | 31 | 0 | 177228846 | import sys
#sys.stdin = open("input.txt", "r")
a = [-1]*91
b = [0]*91
i = 0
for c in input():
c = ord(c)
b[c] += a[c] < 0 or i != a[c]
a[c] = i
i ^= 1
print(max(b)) | Rockethon 2014 | ICPC | 2,014 | 1 | 256 | Word Folding | You will receive 5 points for solving this problem.
Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using t... | The input will consist of one line containing a single string of n characters with 1 ≤ n ≤ 1000 and no spaces. All characters of the string will be uppercase letters.
This problem doesn't have subproblems. You will get 5 points for the correct submission. | Print a single integer — the size of the largest pile composed of identical characters that can be seen in a valid result of folding operations on the given string. | null | Consider the first example. Manao can create a pile of three 'A's using the folding "AB|RACAD|ABRA", which results in the following structure:
In the second example, Manao can create a pile of three 'B's using the following folding: "AB|BB|CBDB".
Another way for Manao to create a pile of three 'B's with "ABBBCBDB" is... | [{"input": "ABRACADABRA", "output": "3"}, {"input": "ABBBCBDB", "output": "3"}, {"input": "AB", "output": "1"}] | null | ["brute force"] | 25 | [{"input": "ABRACADABRA\r\n", "output": "3\r\n"}, {"input": "ABBBCBDB\r\n", "output": "3\r\n"}, {"input": "AB\r\n", "output": "1\r\n"}, {"input": "ABBCDEFB\r\n", "output": "3\r\n"}, {"input": "THISISATEST\r\n", "output": "3\r\n"}, {"input": "Z\r\n", "output": "1\r\n"}, {"input": "ZZ\r\n", "output": "2\r\n"}, {"input": ... | false | stdio | null | true |
390/A | 390 | A | Python 3 | TESTS | 8 | 452 | 1,945,600 | 120336279 | j= int(input())
x=[]
y=[]
for i in range(j):
f=list(map(int,input().split(' ')))
x.append(f[0])
y.append(f[1])
x1=[]
y1=[]
for i in range(j):
if x[i] not in x1:
x1.append(x[i])
if y[i] not in y1:
y1.append(y[i])
a=len(x1)
b=len(y1)
if x1>=y1:
print(b)
else:
print(a) | 19 | 186 | 0 | 176182857 | numOfAlarms = int(input())
columns = set()
rows = set()
for i in range(numOfAlarms):
x = input().split(' ')
columns.add(x[0])
rows.add(x[1])
print(min(len(columns), len(rows))) | Codeforces Round 229 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Alarm Clock | Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.
The morning has ... | The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100).
Note that a single point in the room can contain any number of alarm clocks and t... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | null | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | [{"input": "4\n0 0\n0 1\n0 2\n1 0", "output": "2"}, {"input": "4\n0 0\n0 1\n1 0\n1 1", "output": "2"}, {"input": "4\n1 1\n1 2\n2 3\n3 3", "output": "3"}] | null | ["implementation"] | 19 | [{"input": "4\r\n0 0\r\n0 1\r\n0 2\r\n1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1\r\n1 2\r\n2 3\r\n3 3\r\n", "output": "3\r\n"}, {"input": "1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "42\r\n28 87\r\n26 16\r\n59 90\r\n47 61\r\n28 83\r\n36 30\r\n6... | false | stdio | null | true |
390/A | 390 | A | Python 3 | TESTS | 8 | 483 | 1,638,400 | 12220225 | N=int(input())
Hor=Ver=1
H=[]
V=[]
for I in range(N):
Tmp=list(map(int,input().split()))
H+=[Tmp[0]]
V+=[Tmp[0]]
H.sort()
V.sort()
Tmp1=H[0]
Tmp2=V[0]
for I in range(1,N):
Hor+=1 if not Tmp1==H[I] else 0
Ver+=1 if not Tmp2==V[I] else 0
Tmp1=H[I]
Tmp2=V[I]
print(min(Hor,Ver)) | 19 | 186 | 6,860,800 | 126929669 | def alarm_clock():
count = int(input())
x_set = set()
y_set = set()
for _ in range(count):
coordinate = input().split()
x_set.add(coordinate[0])
y_set.add(coordinate[1])
moves = min(len(x_set), len(y_set))
print(moves)
alarm_clock() | Codeforces Round 229 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Alarm Clock | Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.
The morning has ... | The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100).
Note that a single point in the room can contain any number of alarm clocks and t... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | null | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | [{"input": "4\n0 0\n0 1\n0 2\n1 0", "output": "2"}, {"input": "4\n0 0\n0 1\n1 0\n1 1", "output": "2"}, {"input": "4\n1 1\n1 2\n2 3\n3 3", "output": "3"}] | null | ["implementation"] | 19 | [{"input": "4\r\n0 0\r\n0 1\r\n0 2\r\n1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1\r\n1 2\r\n2 3\r\n3 3\r\n", "output": "3\r\n"}, {"input": "1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "42\r\n28 87\r\n26 16\r\n59 90\r\n47 61\r\n28 83\r\n36 30\r\n6... | false | stdio | null | true |
390/A | 390 | A | Python 3 | TESTS | 8 | 311 | 0 | 15468427 | from math import *
n = int(input())
a = set()
for i in range(n):
x,y = map(int,input().split())
a.add(x)
print(len(a)) | 19 | 187 | 5,734,400 | 152267608 | def solve():
r=set()
c=set()
for i in arr :
r.add(i[0])
c.add(i[1])
return min(len(r),len(c))
from sys import stdin
input = stdin.readline
n=int(input())
arr=[]
for i in range(n):
arr.append([int(x) for x in input().split()])
print(solve())
'''
f... | Codeforces Round 229 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and Alarm Clock | Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.
The morning has ... | The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100).
Note that a single point in the room can contain any number of alarm clocks and t... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | null | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | [{"input": "4\n0 0\n0 1\n0 2\n1 0", "output": "2"}, {"input": "4\n0 0\n0 1\n1 0\n1 1", "output": "2"}, {"input": "4\n1 1\n1 2\n2 3\n3 3", "output": "3"}] | null | ["implementation"] | 19 | [{"input": "4\r\n0 0\r\n0 1\r\n0 2\r\n1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1\r\n1 2\r\n2 3\r\n3 3\r\n", "output": "3\r\n"}, {"input": "1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "42\r\n28 87\r\n26 16\r\n59 90\r\n47 61\r\n28 83\r\n36 30\r\n6... | false | stdio | null | true |
620/D | 620 | D | PyPy 3-64 | TESTS | 7 | 1,153 | 80,998,400 | 175719617 | from sys import stdin
input=lambda :stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
sa=sum(a)
sb=sum(b)
S=[]
for i in range(n):
for j in range(i+1,n):
S.append((a[i]+a[j],i,j))
S.sort(key=lambda x:x[0])
T=[]
for i in range(m):
for j in r... | 24 | 2,995 | 152,166,400 | 92182162 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
sum_a, sum_b = sum(a), sum(b)
delta = sum_b - sum_a
ans = abs(delta)
ans_swap = []
for i in range(n):
for j in range(m):
if abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b... | Educational Codeforces Round 6 | ICPC | 2,016 | 3 | 256 | Professor GukiZ and Two Arrays | Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.
In one operation professor can swap some element from the array a and some element f... | The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.
The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.
The fourth line contains m integers bj ( - 109 ... | In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.
The second line should contain the number of swaps k (0 ≤ k ≤ 2).
Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the ele... | null | null | [{"input": "5\n5 4 3 2 1\n4\n1 1 1 1", "output": "1\n2\n1 1\n4 2"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "0\n0"}, {"input": "5\n1 2 3 4 5\n4\n1 2 3 4", "output": "1\n1\n3 1"}] | 2,200 | ["binary search", "two pointers"] | 24 | [{"input": "5\r\n5 4 3 2 1\r\n4\r\n1 1 1 1\r\n", "output": "1\r\n2\r\n1 1\r\n4 2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "0\r\n0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n4\r\n1 2 3 4\r\n", "output": "1\r\n1\r\n3 1\r\n"}, {"input": "1\r\n-42\r\n1\r\n-86\r\n", "output": "44\r\n0\r\n"}, {"input": "1\r\n-21\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
a = list(map(int, f.readline().strip().split()))
m = int(f.readline().strip())
b = list(map(int, f.readline().strip().split()))
# Read r... | true |
698/B | 698 | B | Python 3 | TESTS | 4 | 77 | 7,168,000 | 128871677 | from collections import defaultdict,deque
n=int(input())
a=list(map(int,input().split()))
graph=defaultdict(list)
for i in range(n):
graph[i+1].append(a[i])
graph[a[i]].append((i+1))
vis=[False]*(n+1)
head=-1
for i in range(n):
if a[i]==i+1:
head=i+1
break
b=a.copy()
if head==-1:
head=1
... | 101 | 436 | 23,142,400 | 197509194 | import sys
input=sys.stdin.readline
def ss(n,l):
for i in range(n):
l[i]=l[i]-1
d={i:[] for i in range(n)}
for i in range(n):
d[l[i]].append(i)
parent=-1
t=l[:]
for i in range(n):
if l[i]==i:
if parent==-1:
parent=i
v... | Codeforces Round 363 (Div. 1) | CF | 2,016 | 2 | 256 | Fix a Tree | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n). | In the first line print the minimum number of elements to change, in order to get a valid sequence.
In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted. | null | In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On bo... | [{"input": "4\n2 3 3 4", "output": "1\n2 3 4 4"}, {"input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3"}, {"input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7"}] | 1,700 | ["constructive algorithms", "dfs and similar", "dsu", "graphs", "trees"] | 101 | [{"input": "4\r\n2 3 3 4\r\n", "output": "1\r\n2 3 4 4 \r\n"}, {"input": "5\r\n3 2 2 5 3\r\n", "output": "0\r\n3 2 2 5 3 \r\n"}, {"input": "8\r\n2 3 5 4 1 6 6 7\r\n", "output": "2\r\n2 3 7 8 1 6 6 7\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n2 2 \r\n"}, {"input": "7\r\n4 3 2 6 3 5 2\r\n", "output": "1\r\n4 3 3 6 ... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
assert len(a) == n
# Read submission's output
with open(submission_output_path... | true |
607/A | 607 | A | Python 3 | TESTS | 8 | 374 | 8,806,400 | 65557418 | from sys import stdin
import bisect
def d(beacon):
dp = [0]*len(beacon)
for i in range(len(beacon)):
if i == 0:
dp[0] = 1
else:
loc = bisect.bisect_left(beacon, (beacon[i][0]-beacon[i][1], ))
if loc == 0:
dp[i] = 1
else:
dp[i] = dp[loc-1]+1
return min(-dp[i]+len(dp) for i in range(len(dp))... | 41 | 467 | 11,878,400 | 111761622 | import sys,os,io
from sys import stdin
from bisect import bisect_left , bisect_right
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = io.BytesIO(os.read(0,... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
780/A | 780 | A | Python 3 | TESTS | 3 | 171 | 13,516,800 | 47612621 | a = int(input())
l = list(map(int,input().split()))
k = []
ans = 0
cnt = 0
for i in range(a):
ans += 1
if i > 0:
if l[i] == l[i - 1]:
ans -= 2
if ans > cnt :
cnt = ans
if cnt == 0:
print(1)
else:
print(cnt) | 56 | 124 | 26,316,800 | 195402446 | n = int(input())
arr = list(map(int , input().split()))
res , curr = 0 , 0
s = set()
for x in arr:
if x not in s : curr += 1
else : curr -= 1
s.add(x)
res = max(res , curr)
print(res) | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Andryusha and Socks | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock... | The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.
The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.
It is gua... | Print single integer — the maximum number of socks that were on the table at the same time. | null | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- In... | [{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}] | 800 | ["implementation"] | 56 | [{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ... | false | stdio | null | true |
532/B | 533 | B | Python 3 | TESTS | 1 | 61 | 5,529,600 | 28268923 | """import sys
try:
FILE = open(str(sys.argv[1]), "r")
except IOError:
print("IOError")
sys.exit(0)
except IndexError:
print("IndexError")
sys.exit(0)
NUM = int(FILE.readline())
"""
NUM = int(input())
class Emp:
"""employee class"""
def __init__(self, employee_num, efficiency):
sel... | 41 | 967 | 73,318,400 | 231037237 | n = int(input())
t = [list(map(int, input().split())) for q in range(n)]
n += 1
u = [-1e7] * n
v = [0] * n
for i, (j, a) in list(enumerate(t, 1))[::-1]:
u[i] = max(u[i], v[i] + a)
v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])
print(u[1]) | VK Cup 2015 - Round 2 | CF | 2,015 | 2 | 256 | Work Group | One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will call person a a subordinates of another person b, if either b is an immediate... | The first line contains integer n (1 ≤ n ≤ 2·105) — the number of workers of the Big Software Company.
Then n lines follow, describing the company employees. The i-th line contains two integers pi, ai (1 ≤ ai ≤ 105) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency... | Print a single integer — the maximum possible efficiency of the workgroup. | null | In the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6. | [{"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2", "output": "17"}] | 2,000 | [] | 41 | [{"input": "7\r\n-1 3\r\n1 2\r\n1 1\r\n1 4\r\n4 5\r\n4 3\r\n5 2\r\n", "output": "17\n"}, {"input": "1\r\n-1 42\r\n", "output": "42\n"}, {"input": "2\r\n-1 3\r\n1 2\r\n", "output": "3\n"}, {"input": "3\r\n-1 3\r\n1 1\r\n1 2\r\n", "output": "6\n"}, {"input": "3\r\n-1 1\r\n1 2\r\n1 3\r\n", "output": "6\n"}, {"input": "3\r... | false | stdio | null | true |
607/A | 607 | A | Python 3 | TESTS | 8 | 358 | 25,088,000 | 215467796 | import bisect
t = int(input())
mas = []
places = []
dp = [0]*t
bin_search = []
for _ in range(t):
a = list(map(int, input().split()))
mas.append(a)
bin_search.append(a[0])
for i in range(1, t):
ind = bisect.bisect_left(bin_search, bin_search[i]-mas[i][1])
dp[i] = i-ind+dp[ind-1]
ans = 10**21... | 41 | 467 | 18,534,400 | 20347209 | import sys
MAX_X = 1000 * 1000 + 10
def main():
n = int(sys.stdin.readline())
arr = [0] * MAX_X
cnt = [0] * MAX_X
dp = [0] * MAX_X
for i in range(n):
x, c = list(map(int, sys.stdin.readline().split()))
arr[x + 1] = c
for i in range(1, MAX_X):
cnt[i] += cnt[i - 1] + (a... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
607/A | 607 | A | PyPy 3-64 | TESTS | 8 | 109 | 10,752,000 | 206353041 | import sys
input = lambda: sys.stdin.readline().rstrip()
from bisect import *
N = int(input())
A,B = [],[]
for _ in range(N):
a,b = map(int, input().split())
A.append(a)
B.append(b)
dp = [0]*(N+1)
for i in range(N):
a,b = A[i],B[i]
pre = a-b
idx = bisect_left(A, pre)
dp[i+1] = dp[... | 41 | 482 | 15,769,600 | 72127996 | import sys
input = sys.stdin.readline
from bisect import *
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda k: k[0])
a = [-10**18]+[ai for ai, _ in ab]
dp = [0]*(n+1)
for i in range(1, n+1):
j = bisect_left(a, ab[i-1][0]-ab[i-1][1])-1
dp[i] = dp[j]+i-j-1
ans = 10*... | Codeforces Round 336 (Div. 1) | CF | 2,015 | 2 | 256 | Chain Reaction | There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.
The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | null | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}] | 1,600 | ["binary search", "dp"] | 41 | [{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
605/C | 605 | C | Python 3 | TESTS | 0 | 61 | 0 | 22165497 | import sys
jobs, xp, money = map(int, input().split())
vecs = []
maxsum = 0
for i in range(jobs):
x, m = map(int, input().split())
x *= money
m *= xp # ?
vecs.append((x, m))
if x+m > maxsum:
maxsum = x+m
maxvec = (x, m)
target = xp * money
mindays = target / min(maxvec)
for vec in vecs:
if vec[0] <= maxvec... | 86 | 1,341 | 14,643,200 | 113386000 | from fractions import Fraction
def higher(x1, y1, x2, y2):
if x1 == 0:
if x2 == 0:
return
def min_days(p, q, pr):
ma = max(a for a, b in pr)
mb = max(b for a, b in pr)
pr.sort(key=lambda t: (t[0], -t[1]))
ch = [(0, mb)]
for a, b in pr:
if a == ch[-1][0]:
... | Codeforces Round 335 (Div. 1) | CF | 2,015 | 2 | 256 | Freelancer's Dreams | Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site.
He has suggestions to wo... | The first line of the input contains three integers n, p and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money.
Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for work... | Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. 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 consid... | null | First sample corresponds to the example in the problem statement. | [{"input": "3 20 20\n6 2\n1 3\n2 6", "output": "5.000000000000000"}, {"input": "4 1 1\n2 3\n3 2\n2 3\n3 2", "output": "0.400000000000000"}] | 2,400 | ["geometry"] | 86 | [{"input": "3 20 20\r\n6 2\r\n1 3\r\n2 6\r\n", "output": "5.000000000000000\r\n"}, {"input": "4 1 1\r\n2 3\r\n3 2\r\n2 3\r\n3 2\r\n", "output": "0.400000000000000\r\n"}, {"input": "3 12 12\r\n5 1\r\n2 2\r\n1 5\r\n", "output": "4.000000000000000\r\n"}, {"input": "3 12 12\r\n5 1\r\n4 4\r\n1 5\r\n", "output": "3.000000000... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read correct answer
try:
with open(output_path, 'r') as f:
correct_line = f.readline().strip()
b = float(correct_line)
except:
print(0)
... | true |
272/B | 272 | B | PyPy 3 | TESTS | 3 | 248 | 0 | 60293122 | n = int(input())
f = sorted((list(map(int,input().split()))))
res = 0
i = 0
j = 1
c = 1
while i < n and j < n:
if f[i]*2 == f[j] or f[i]*2-1 == f[j]:
i+=1
j+=1
c+=1
else:
res+=c*(c-1)//2
i+=1
j+=1
res+=c*(c-1)//2
print(res) | 42 | 248 | 11,468,800 | 167457757 | import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
w = Counter(map(lambda x:(bin(int(x))[2:]).count('1'), input().split()))
c = 0
for i in w:
c += (w[i]*(w[i]-1))//2
print(c) | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Sequence | Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
- f(0) = 0;
- f(2·x) = f(x);
- f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are the... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces. | In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do. | [{"input": "3\n1 2 4", "output": "3"}, {"input": "3\n5 3 1", "output": "1"}] | 1,400 | ["implementation", "math"] | 42 | [{"input": "3\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n469264357 996569493\r\n", "output": "0\r\n"}, {"input": "6\r\n396640239 62005863 473635171 329666981 510631133 207643327\r\n", "output": "2\r\n"}, {"input": "8\r\n851991424 32517099 310793856 776130403 34262... | false | stdio | null | true |
463/D | 463 | D | Python 3 | TESTS | 4 | 108 | 6,963,200 | 79382822 | def Comparar(largoVuelta, nivelActual):
global largoMax
for vecino in series[0][nivelActual]:
largo = largoVuelta
matchGeneral = True
#print("\nvecino ", vecino)
for num in range(k-1): #reviso match entre series
match = False
#print("num ", num)
... | 40 | 93 | 4,403,200 | 231333630 | n, k = map(int, input().split())
a = [[]]*6
b = []
for i in range(6):
b.append([0]*(n + 1))
for i in range(k):
a[i] = list(map(int, input().split()))
for j in range(n):
b[i][a[i][j]] = j
dp = [1] * n
for i in range(n):
for j in range(i):
key = 1
for t in range(1, k):
... | Codeforces Round 264 (Div. 2) | CF | 2,014 | 2 | 256 | Gargari and Permutations | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can... | The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation. | Print the length of the longest common subsequence. | null | The answer for the first test sample is subsequence [1, 2, 3]. | [{"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3"}] | 1,900 | ["dfs and similar", "dp", "graphs", "implementation"] | 40 | [{"input": "4 3\r\n1 4 2 3\r\n4 1 2 3\r\n1 2 4 3\r\n", "output": "3\r\n"}, {"input": "6 3\r\n2 5 1 4 6 3\r\n5 1 4 3 2 6\r\n5 4 2 6 3 1\r\n", "output": "3\r\n"}, {"input": "41 4\r\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\r\n22 13 25 24 38 35 29 12... | false | stdio | null | true |
272/B | 272 | B | Python 3 | TESTS | 3 | 186 | 0 | 54885605 | n = int(input())
def norm(a):
if a % 2 == 0:
while a % 2 == 0:
a //= 2
if a > 1:
while (a - 1) % 4 == 0:
a = (a - 1) // 2 + 1
return a
m = sorted([norm(int(x)) for x in input().split()])
s = 0
w = 0
for i in range(len(m)-1):
if m[i] == m[i+1]:
w +=1
... | 42 | 278 | 8,089,600 | 184512393 | def f(x):
return bin(x).count("1")
from math import comb
def solve():
# Reading input
n = int(input())
a = list(map(int, input().split()))
freq = {}
for ai in a:
ai = f(ai)
freq[ai] = freq.get(ai, 0) + 1
count = sum([comb(f, 2) for f in freq.values()])
print(count)
... | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Sequence | Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:
- f(0) = 0;
- f(2·x) = f(x);
- f(2·x + 1) = f(x) + 1.
Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are the... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
The numbers in the lines are separated by single spaces. | In a single line print the answer to the problem.
Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | null | In the first sample any pair (i, j) will do, so the answer is 3.
In the second sample only pair (1, 2) will do. | [{"input": "3\n1 2 4", "output": "3"}, {"input": "3\n5 3 1", "output": "1"}] | 1,400 | ["implementation", "math"] | 42 | [{"input": "3\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n469264357 996569493\r\n", "output": "0\r\n"}, {"input": "6\r\n396640239 62005863 473635171 329666981 510631133 207643327\r\n", "output": "2\r\n"}, {"input": "8\r\n851991424 32517099 310793856 776130403 34262... | false | stdio | null | true |
780/A | 780 | A | Python 3 | TESTS | 3 | 139 | 13,516,800 | 147900646 | # input operation
n=int(input())
order_of_pulling=list(map(int,input().split()))
i=0
exist=1
out=0
while i <n:
if exist>out:
out=exist
if order_of_pulling[i]!=order_of_pulling[i+1]:
exist+=1
else:
exist-=1
i+=1
print(out) | 56 | 139 | 18,739,200 | 219549762 | n = int(input())
cur = set()
ans = -1
for x in input().split():
if x not in cur:
cur.add(x)
else:
cur.remove(x)
ans = max(ans, len(cur))
print(ans) | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Andryusha and Socks | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock... | The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.
The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.
It is gua... | Print single integer — the maximum number of socks that were on the table at the same time. | null | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- In... | [{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}] | 800 | ["implementation"] | 56 | [{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ... | false | stdio | null | true |
463/B | 463 | B | Python 3 | TESTS | 11 | 155 | 7,065,600 | 62041093 | if __name__ == '__main__':
n, columns = int(input()), list(map(int, input().split(" ")))
c = columns[0]
for i in range(1, n-1):
if c < columns[i]:
c += columns[i] - c
print(c) | 49 | 62 | 5,632,000 | 156377247 | import sys
input = sys.stdin.readline
n = int(input())
print(max((map(int, input().split())))) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
626/F | 626 | F | Python 3 | PRETESTS | 1 | 30 | 0 | 16007751 | q,w=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=0
import math
for i in range(0,q-1):
j=i
while (j<q):
if (a[j]-a[i])<=w:
j+=1
else:
break
m=j-i-1
n=math.factorial(m)
for j in range(1,m+1):
r+=n//(math.factorial(j)*math.factoria... | 66 | 904 | 19,865,600 | 212331798 | # Problem: F. Group Projects
# Contest: Codeforces - 8VC Venture Cup 2016 - Elimination Round
# URL: https://codeforces.com/contest/626/problem/F
# Memory Limit: 256 MB
# Time Limit: 2000 ms
import sys
import random
from types import GeneratorType
import bisect
import io, os
from bisect import *
from collections impor... | 8VC Venture Cup 2016 - Elimination Round | CF | 2,016 | 2 | 256 | Group Projects | There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.
If students work at different paces,... | The first line contains two space-separated integers n and k (1 ≤ n ≤ 200, 0 ≤ k ≤ 1000) — the number of students and the maximum total imbalance allowed, respectively.
The second line contains n space-separated integers ai (1 ≤ ai ≤ 500) — the time it takes the i-th student to complete his/her independent piece of wo... | Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7. | null | In the first sample, we have three options:
- The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2.
- The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1.
- All three students form their own groups. Total... | [{"input": "3 2\n2 4 5", "output": "3"}, {"input": "4 3\n7 8 9 10", "output": "13"}, {"input": "4 0\n5 10 20 21", "output": "1"}] | 2,400 | ["dp"] | 66 | [{"input": "3 2\r\n2 4 5\r\n", "output": "3\r\n"}, {"input": "4 3\r\n7 8 9 10\r\n", "output": "13\r\n"}, {"input": "4 0\r\n5 10 20 21\r\n", "output": "1\r\n"}, {"input": "20 1000\r\n50 50 100 100 150 150 200 200 250 250 300 300 350 350 400 400 450 450 500 500\r\n", "output": "97456952\r\n"}, {"input": "5 222\r\n58 369 ... | false | stdio | null | true |
463/B | 463 | B | PyPy 3-64 | TESTS | 11 | 92 | 13,516,800 | 197665225 | n = int(input())
a = list(map(int , input().split()))
if(n == 1):
print(a[0])
else:
s = 0
c = 0
x = 0
for el in range(0, n-1) :
y = a[el]
s += x - y
if(s < 0):
c += -s
s = 0
x = y
print(c) | 49 | 62 | 5,734,400 | 194440094 | n = int ( input())
s = map (int , input().split())
v = max (s)
print(v) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
463/B | 463 | B | PyPy 3-64 | TESTS | 11 | 77 | 13,516,800 | 173334414 | pylonNum = int(input())
heights = list(map(int, input().split()))
heights.insert(0,0)
energy = 0
dollars = 0
if(pylonNum == 1):
dollars = heights[1]
for pylon in range(pylonNum-1):
diff = heights[pylon+1] - heights[pylon]
energy -= diff
if(energy < 0):
dollars = dollars + abs(energy)
ene... | 49 | 62 | 5,836,800 | 166716627 | _, m = input(), max(map(int, input().split(' ')))
print(m) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
463/B | 463 | B | Python 3 | TESTS | 9 | 155 | 6,348,800 | 70585058 | columns_amount = int(input())
heights = [int(h) for h in input().split(' ')]
energy = 0
dollars = 0
current = 0
# print('heights = {}'.format(heights))
for h in heights:
if current < h:
if energy == 0:
dollars += h - current
else:
diff = h - current
if diff > e... | 49 | 62 | 7,065,600 | 187697374 | n = int(input())
heights = [int(x) for x in input().split()]
print(max(heights)) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
532/B | 533 | B | PyPy 3 | TESTS | 6 | 124 | 0 | 98025296 | import math
n = int(input())
superior = []
costs=[]
cost_total=0
for i in range(n):
a, b = map(int, input().split())
superior.append(a)
costs.append(b)
hijos = [[] for _ in range(n+1)]
for i in range(n):
if superior[i]==-1:
cost_total+=costs[i]
else:
hijos[superior[i]].append(i+1... | 41 | 967 | 73,318,400 | 231037237 | n = int(input())
t = [list(map(int, input().split())) for q in range(n)]
n += 1
u = [-1e7] * n
v = [0] * n
for i, (j, a) in list(enumerate(t, 1))[::-1]:
u[i] = max(u[i], v[i] + a)
v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])
print(u[1]) | VK Cup 2015 - Round 2 | CF | 2,015 | 2 | 256 | Work Group | One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will call person a a subordinates of another person b, if either b is an immediate... | The first line contains integer n (1 ≤ n ≤ 2·105) — the number of workers of the Big Software Company.
Then n lines follow, describing the company employees. The i-th line contains two integers pi, ai (1 ≤ ai ≤ 105) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency... | Print a single integer — the maximum possible efficiency of the workgroup. | null | In the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6. | [{"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2", "output": "17"}] | 2,000 | [] | 41 | [{"input": "7\r\n-1 3\r\n1 2\r\n1 1\r\n1 4\r\n4 5\r\n4 3\r\n5 2\r\n", "output": "17\n"}, {"input": "1\r\n-1 42\r\n", "output": "42\n"}, {"input": "2\r\n-1 3\r\n1 2\r\n", "output": "3\n"}, {"input": "3\r\n-1 3\r\n1 1\r\n1 2\r\n", "output": "6\n"}, {"input": "3\r\n-1 1\r\n1 2\r\n1 3\r\n", "output": "6\n"}, {"input": "3\r... | false | stdio | null | true |
780/A | 780 | A | Python 3 | TESTS | 3 | 93 | 22,630,400 | 231469305 | a = int(input())
b = input().split()
c = 0
d = 0
e = {}
for i in range(0, a):
if b[i] in e:
if c > d:
d = c
c = 0
del e[b[i]]
else:
c += 1
e[b[i]] = i
if c > d:
d = c
print(d) | 56 | 140 | 11,980,800 | 194523369 | input()
h = input().split()
s = set()
m = 0
for i in h :
s ^={i}
if len(s)>m :
m = len(s)
print(m) | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Andryusha and Socks | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock... | The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.
The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.
It is gua... | Print single integer — the maximum number of socks that were on the table at the same time. | null | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- In... | [{"input": "1\n1 1", "output": "1"}, {"input": "3\n2 1 1 3 2 3", "output": "2"}] | 800 | ["implementation"] | 56 | [{"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1 3 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 1 3 2 4 3 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 ... | false | stdio | null | true |
463/B | 463 | B | Python 3 | TESTS | 9 | 171 | 6,144,000 | 110041988 | n = int(input())
a = list(map(int, (input().split())))
energy = '0'
dollar = a[0]
#print(dollar)
for i in range(0,len(a)-1):
diff = a[i+1] - a[i]
#print("ENREGY", energy)
if diff > int(energy):
#print((diff - int(energy)))
dollar += (diff - int(energy))
energy = '0'
# print(energy)
#print(dolla... | 49 | 62 | 7,270,400 | 137320758 | import math
#s = input()
#n= (map(int, input().split()))
#(map(int, input().split()))
#a, b = (map(int, input().split()))
#for i in range(0, int(input())):
n = int(input())
mass = list(map(int, input().split()))
print(max(mass)) | Codeforces Round 264 (Div. 2) | CF | 2,014 | 1 | 256 | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon,... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | null | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | [{"input": "5\n3 4 3 2 4", "output": "4"}, {"input": "3\n4 4 4", "output": "4"}] | 1,100 | ["brute force", "implementation", "math"] | 49 | [{"input": "5\r\n3 4 3 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 4 4\r\n", "output": "4\r\n"}, {"input": "99\r\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269... | false | stdio | null | true |
53/D | 53 | D | Python 3 | TESTS | 0 | 92 | 204,800 | 107115104 | def main():
N = int(input())
order = list(input().split())
initial = list(input().split())
X = []
Y = []
ans = 0
for i in range(N):
if order[i] == initial[i]:
continue
else:
j = i + 1
for j in range(j, N):
X.insert(len(X), j... | 30 | 154 | 614,400 | 174605021 | import math
import random
from datetime import datetime
now = datetime.now()
def prime_generator(nr_elemente_prime):
vector_prime=[-1]*nr_elemente_prime
vector_rasp=[0]*nr_elemente_prime
vector_prime[1]=1
vector_rasp[1]=1
#primes sieve
contor=2
for i in range(2,nr_elemente_prime):
if vector_prime[i... | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Physical Education | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ... | In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1. | null | null | [{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}] | 1,500 | ["sortings"] | 30 | [{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_input:
n = int(f_input.readline().strip())
a = list(map(int, f_input.readline().split()))
initial_b = list(map(int, f_input.readline().split()))
with open(submission_path, 'r') as f_submi... | true |
396/B | 396 | B | Python 3 | TESTS | 1 | 62 | 307,200 | 110490982 | import math
def prime(n):
root = int(math.sqrt(n))
i=2
while(i<=root):
if(n%i==0):
return 0
i+=1
return 1
def diviseur(num):
root = int(math.sqrt(num))
i = 2
div = []
while(i < root):
if(num % i == 0):
div.append(i)
num /= i
... | 30 | 467 | 25,292,800 | 17700795 | def isPrime(n):
i = 2
while i * i <= n:
if n % i == 0:
return False
i += 1
return True
def prevPrime(n):
while not isPrime(n):
n -= 1
return n
def nextPrime(n):
n += 1
while not isPrime(n):
n += 1
return n
def gcd(a, b):
while(a):
... | Codeforces Round 232 (Div. 1) | CF | 2,014 | 2 | 256 | On Sum of Fractions | Let's assume that
- v(n) is the largest prime number, that does not exceed n;
- u(n) is the smallest prime number strictly greater than n.
Find $$\sum_{i=2}^{n}\frac{1}{v(i)u(i)}$$. | The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.
Each of the following t lines of the input contains integer n (2 ≤ n ≤ 109). | Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0. | null | null | [{"input": "2\n2\n3", "output": "1/6\n7/30"}] | null | ["math", "number theory"] | 30 | [{"input": "2\r\n2\r\n3\r\n", "output": "1/6\r\n7/30\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "999999941999999673/1999999887999999118\r\n"}, {"input": "5\r\n3\r\n6\r\n9\r\n10\r\n5\r\n", "output": "7/30\r\n5/14\r\n61/154\r\n9/22\r\n23/70\r\n"}, {"input": "5\r\n5\r\n8\r\n18\r\n17\r\n17\r\n", "output": "23/70\r\n... | false | stdio | null | true |
279/C | 279 | C | PyPy 3 | TESTS | 7 | 748 | 10,956,800 | 184862571 | from math import *
#from heapq import heappop, heappush
from collections import deque
from functools import lru_cache
from collections import defaultdict, Counter
from bisect import *
MOD = 10**9 + 7
import sys
#from sys import stdin,stdout
input=sys.stdin.readline
#n = int(input())
#map(int, input().split())... | 35 | 1,466 | 14,028,800 | 213714989 | import sys
sys.setrecursionlimit(2000000)
from collections import defaultdict
def clc():
n,m= map(int,input().split())
arr = list(map(int,input().split()))
dp0 =[0]*len(arr)
dp1= [0]*len(arr)
dp0[0],dp1[n-1] = 1,1
for i in range(1,n):
if arr[i]<=arr[i-1]:dp0[i] = dp0[i-1]+1
e... | Codeforces Round 171 (Div. 2) | CF | 2,013 | 2 | 256 | Ladder | You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the correspon... | The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element.
The following m lines contain the description of the queries. The ... | Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise. | null | null | [{"input": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "output": "Yes\nYes\nNo\nYes\nNo\nYes"}] | 1,700 | ["dp", "implementation", "two pointers"] | 35 | [{"input": "8 6\r\n1 2 1 3 3 5 2 1\r\n1 3\r\n2 3\r\n2 4\r\n8 8\r\n1 4\r\n5 8\r\n", "output": "Yes\r\nYes\r\nNo\r\nYes\r\nNo\r\nYes\r\n"}, {"input": "1 1\r\n6\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "2 5\r\n1 1\r\n1 2\r\n2 2\r\n2 2\r\n1 2\r\n1 2\r\n", "output": "Yes\r\nYes\r\nYes\r\nYes\r\nYes\r\n"}, {"input": "10 ... | false | stdio | null | true |
279/C | 279 | C | PyPy 3 | TESTS | 3 | 154 | 0 | 211365869 | n, m = map(int, input().split())
a = [int(i) for i in input().split()]
peak = [0] * n
valley = [0] * n
for i in range(1, n - 1):
if a[i] > a[i - 1] and a[i] > a[i + 1]:
peak[i] += 1
elif a[i] < a[i - 1] and a[i] < a[i + 1]:
valley[i] += 1
for i in range(1, n):
peak[i] += peak[i - 1]
v... | 35 | 1,558 | 14,233,600 | 211930972 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b,c=[0]*n,[0]*n
for i in range(1,n):
if a[i]<=a[i-1]: b[i]=b[i-1]+1
for i in range(n-2,-1,-1):
if a[i]<=a[i+1]: c[i]=c[i+1]+1
for i in range(m):
L,R=map(int,input().split())
if abs(R-L)<=c[L-1]+b[R-1]:
print("Yes")
else:
p... | Codeforces Round 171 (Div. 2) | CF | 2,013 | 2 | 256 | Ladder | You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the correspon... | The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element.
The following m lines contain the description of the queries. The ... | Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise. | null | null | [{"input": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "output": "Yes\nYes\nNo\nYes\nNo\nYes"}] | 1,700 | ["dp", "implementation", "two pointers"] | 35 | [{"input": "8 6\r\n1 2 1 3 3 5 2 1\r\n1 3\r\n2 3\r\n2 4\r\n8 8\r\n1 4\r\n5 8\r\n", "output": "Yes\r\nYes\r\nNo\r\nYes\r\nNo\r\nYes\r\n"}, {"input": "1 1\r\n6\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "2 5\r\n1 1\r\n1 2\r\n2 2\r\n2 2\r\n1 2\r\n1 2\r\n", "output": "Yes\r\nYes\r\nYes\r\nYes\r\nYes\r\n"}, {"input": "10 ... | false | stdio | null | true |
12/C | 12 | C | Python 3 | TESTS | 4 | 62 | 4,812,800 | 26787239 | def Invertir(A):
B =[]
k = len(A)-1
while k>=0:
B.append(A[k])
k -=1
return B
def SinRepetir(A):
ASP = [0]
for k in range (len(A)):
if k==0:
ASP[0]=A[k]
c = 0
for i in range (len(ASP)):
if A[k]==ASP[i]:
c+=1
... | 25 | 46 | 0 | 165379508 | n, m = map(int, input().split())
price_tags = list(map(int, input().split()))
price_tags_asc = sorted(price_tags)
price_tags_dsc = sorted(price_tags, reverse=True)
fruits = {}
for _ in range(m):
fruit = input()
if fruit in fruits:
fruits[fruit] += 1
else:
fruits[fruit] = 1
fruits_nums = l... | Codeforces Beta Round 12 (Div 2 Only) | ICPC | 2,010 | 1 | 256 | Fruits | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Asho... | The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exc... | Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | null | null | [{"input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19"}, {"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30"}] | 1,100 | ["greedy", "implementation", "sortings"] | 25 | [{"input": "5 3\r\n4 2 1 10 5\r\napple\r\norange\r\nmango\r\n", "output": "7 19\r\n"}, {"input": "6 5\r\n3 5 1 6 8 1\r\npeach\r\ngrapefruit\r\nbanana\r\norange\r\norange\r\n", "output": "11 30\r\n"}, {"input": "2 2\r\n91 82\r\neiiofpfpmemlakcystpun\r\nmcnzeiiofpfpmemlakcystpunfl\r\n", "output": "173 173\r\n"}, {"input"... | false | stdio | null | true |
12/C | 12 | C | Python 3 | TESTS | 4 | 61 | 0 | 117451075 | a, b = map(int,input().split())
pri = list(map(int,input().split()))
pri.sort()
li = []
new = []
new.sort()
high = 0
low = 0
for x in range(b):
k = input()
if k not in li:
li.append(k)
new.append(1)
else:new[li.index(k)] += 1
for x in range(len(new)):
high += new[-(x + 1)] * pri[-(x + 1)]
low += new[-(x + 1)] ... | 25 | 46 | 0 | 174607853 | n,m=map(int,input().split())
List=list(map(int,input().split()));List.sort()
list_0=List.copy()
List.reverse()
list_1=List.copy()
want=[input()for i in range(m)]
kind=list(set(want))
mmin=0;mmax=0
ss=[]
for i in kind:
ss.append(want.count(i))
ss.sort(reverse=True)
for i in range(len(ss)):
mmin+=ss[i]*list_0[i]
... | Codeforces Beta Round 12 (Div 2 Only) | ICPC | 2,010 | 1 | 256 | Fruits | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Asho... | The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exc... | Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | null | null | [{"input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19"}, {"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30"}] | 1,100 | ["greedy", "implementation", "sortings"] | 25 | [{"input": "5 3\r\n4 2 1 10 5\r\napple\r\norange\r\nmango\r\n", "output": "7 19\r\n"}, {"input": "6 5\r\n3 5 1 6 8 1\r\npeach\r\ngrapefruit\r\nbanana\r\norange\r\norange\r\n", "output": "11 30\r\n"}, {"input": "2 2\r\n91 82\r\neiiofpfpmemlakcystpun\r\nmcnzeiiofpfpmemlakcystpunfl\r\n", "output": "173 173\r\n"}, {"input"... | false | stdio | null | true |
460/C | 460 | C | PyPy 3-64 | TESTS | 6 | 77 | 13,209,600 | 209355184 | def check(a, n, m, w, up):
ans = m * w
for i in range(n):
if a[i] < up:
ans -= up - a[i]
return ans >= 0
if __name__ == '__main__':
n, m, w = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
left, right, res = min(a), max(a) + m, -1
wh... | 43 | 108 | 16,384,000 | 209356182 | def check(a, diff, n, m, w, up):
preSum, ans = 0, 0
for i in range(1, n + 1):
preSum += diff[i]
if preSum < up:
ans += up - preSum
diff[i] = up - preSum
if i + w <= n:
diff[i + w] -= up - preSum
preSum = up
for i in range(1, n +... | Codeforces Round 262 (Div. 2) | CF | 2,014 | 2 | 256 | Present | Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti... | The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). | Print a single integer — the maximum final height of the smallest flower. | null | In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test. | [{"input": "6 2 3\n2 2 2 2 1 1", "output": "2"}, {"input": "2 5 1\n5 8", "output": "9"}] | 1,700 | ["binary search", "data structures", "greedy"] | 43 | [{"input": "6 2 3\r\n2 2 2 2 1 1\r\n", "output": "2\r\n"}, {"input": "2 5 1\r\n5 8\r\n", "output": "9\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "2\r\n"}, {"input": "3 2 3\r\n999999998 999999998 999999998\r\n", "output": "1000000000\r\n"}, {"input": "10 8 3\r\n499 498 497 497 497 497 497 497 498 499\r\n", "output": "... | false | stdio | null | true |
460/C | 460 | C | PyPy 3-64 | TESTS | 28 | 109 | 18,329,600 | 176204334 | def check(x):
st = [0] * n
scurr, moves = 0, 0
for i in range(n):
if i - w >= 0:
scurr -= st[i - w]
if a[i] + scurr < x:
st[i] = x - a[i] - scurr
scurr += st[i]
moves += st[i]
if moves > m:
return False
return moves <= m... | 43 | 108 | 18,329,600 | 208910378 | n,m,w = map(int, input().split())
a = list(map(int, input().split()))
def check(up: int) -> bool:
diff = [0] * (n+1)
sm = 0
cap = m
for i, x in enumerate(a):
sm += diff[i]
curr = x + sm
if(curr < up):
cap -= up - curr
if(cap < 0):
return F... | Codeforces Round 262 (Div. 2) | CF | 2,014 | 2 | 256 | Present | Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti... | The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). | Print a single integer — the maximum final height of the smallest flower. | null | In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test. | [{"input": "6 2 3\n2 2 2 2 1 1", "output": "2"}, {"input": "2 5 1\n5 8", "output": "9"}] | 1,700 | ["binary search", "data structures", "greedy"] | 43 | [{"input": "6 2 3\r\n2 2 2 2 1 1\r\n", "output": "2\r\n"}, {"input": "2 5 1\r\n5 8\r\n", "output": "9\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "2\r\n"}, {"input": "3 2 3\r\n999999998 999999998 999999998\r\n", "output": "1000000000\r\n"}, {"input": "10 8 3\r\n499 498 497 497 497 497 497 497 498 499\r\n", "output": "... | false | stdio | null | true |
400/B | 400 | B | PyPy 3 | TESTS | 4 | 62 | 1,228,800 | 155687535 | n,m=map(int,input().split())
flag=0
d=dict()
for i in range(n):
x = input()
for j in range(m):
if x[j]=='G':
gidx=j
elif x[j]=='S':
sidx=j
if sidx-gidx<0:
flag=1;break
else:
if x in d:
d[x]+=1
else:
d[x]=1
print(len(d) if not flag else -1) | 34 | 46 | 204,800 | 195791131 | import sys
n, m = map(int, input().split())
output = set()
possible = True
for row in range(n):
initialState = input()
dwarfPos = initialState.find("G")
candyPos = initialState.find("S")
if dwarfPos > candyPos:
possible = False
break
elif dwarfPos < candyPos:
output.add(ca... | Codeforces Round 234 (Div. 2) | CF | 2,014 | 1 | 256 | Inna and New Matrix of Candies | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game la... | The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000).
Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn'... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | null | null | [{"input": "3 4\n*G*S\nG**S\n*G*S", "output": "2"}, {"input": "1 3\nS*G", "output": "-1"}] | 1,200 | ["brute force", "implementation", "schedules"] | 34 | [{"input": "3 4\r\n*G*S\r\nG**S\r\n*G*S\r\n", "output": "2\r\n"}, {"input": "1 3\r\nS*G\r\n", "output": "-1\r\n"}, {"input": "10 10\r\nG********S\r\n*G*******S\r\n**G******S\r\n***G*****S\r\n****G****S\r\n*****G***S\r\n******G**S\r\n*******G*S\r\n********GS\r\nG********S\r\n", "output": "9\r\n"}, {"input": "5 10\r\nG**... | false | stdio | null | true |
4/D | 4 | D | PyPy 3 | TESTS | 2 | 77 | 0 | 222160531 | n, w_card, h_card = map(int, input().split())
envelopes = []
for i in range(n):
w, h = map(int, input().split())
envelopes.append((w, h, i + 1))
envelopes.sort()
dp = [1] * n
prev = [-1] * n
for i in range(1, n):
for j in range(i):
if envelopes[i][0] > envelopes[j][0] and envelopes[i][1... | 33 | 452 | 8,499,200 | 223575394 | ################################################################################
n,w,h=map(int,input().split())
envelope=[]
for i in range(n):
wcup,hcup=map(int,input().split())
if (wcup>w) and (hcup>h):
envelope.append((wcup,hcup,i+1))
# n=2
# w=1
# h=1
# envelope=[(2,2,1),(2,2,2)]
# n=3
# w=3
# h=3
... | Codeforces Beta Round 4 (Div. 2 Only) | ICPC | 2,010 | 1 | 64 | Mysterious Present | Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the heigh... | The first line contains integers n, w, h (1 ≤ n ≤ 5000, 1 ≤ w, h ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi, hi ≤ 106). | In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, pr... | null | null | [{"input": "2 1 1\n2 2\n2 2", "output": "1\n1"}, {"input": "3 3 3\n5 4\n12 11\n9 8", "output": "3\n1 3 2"}] | 1,700 | ["dp", "sortings"] | 33 | [{"input": "2 1 1\r\n2 2\r\n2 2\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 3 3\r\n5 4\r\n12 11\r\n9 8\r\n", "output": "3\r\n1 3 2 \r\n"}, {"input": "5 10 10\r\n22 23\r\n17 19\r\n13 17\r\n8 12\r\n2 6\r\n", "output": "3\r\n3 2 1 \r\n"}, {"input": "5 13 13\r\n4 4\r\n10 10\r\n7 7\r\n1 1\r\n13 13\r\n", "output": "0\r\n"},... | false | stdio | import sys
def read_file_lines(path):
with open(path, 'r') as f:
return [line.strip() for line in f.readlines()]
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
input_lines = read_file_lines(input_path)
if not input_lines:
print(0)
... | true |
627/D | 627 | D | PyPy 3 | TESTS | 8 | 4,258 | 41,984,000 | 80969198 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
g = [[] for _ in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
g[u-1].append(v-1)
g[v-1].append(u-1)
stack = [0]
done = [False] * n
par = [0] * n
order = []
while len(stack) > 0:
x = sta... | 69 | 5,116 | 50,380,800 | 80969556 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
g = [[] for _ in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
g[u-1].append(v-1)
g[v-1].append(u-1)
stack = [0]
done = [False] * n
par = [0] * n
order = []
while len(stack) > 0:
x = sta... | 8VC Venture Cup 2016 - Final Round | CF | 2,016 | 7 | 256 | Preorder Test | For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.
Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to ... | The first line of the input contains two positive integers, n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ n) — the number of balls in Jacob's tree and the number of balls the teacher will inspect.
The second line contains n integers, ai (1 ≤ ai ≤ 1 000 000), the time Jacob used to build the i-th ball.
Each of the next n - 1 line... | Print a single integer — the maximum grade Jacob can get by picking the right root of the tree and rearranging the list of neighbors. | null | In the first sample, Jacob can root the tree at node 2 and order 2's neighbors in the order 4, 1, 5 (all other nodes have at most two neighbors). The resulting preorder traversal is 2, 4, 1, 3, 5, and the minimum ai of the first 3 nodes is 3.
In the second sample, it is clear that any preorder traversal will contain n... | [{"input": "5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3", "output": "3"}, {"input": "4 2\n1 5 5 5\n1 2\n1 3\n1 4", "output": "1"}] | 2,600 | ["binary search", "dfs and similar", "dp", "graphs", "greedy", "trees"] | 69 | [{"input": "5 3\r\n3 6 1 4 2\r\n1 2\r\n2 4\r\n2 5\r\n1 3\r\n", "output": "3\r\n"}, {"input": "4 2\r\n1 5 5 5\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 100000\r\n2 1\r\n", "output": "100000\r\n"}, {"input": "2 2\r\n1 1000000\r\n1 2\r\n", "output": "1\r\n"}, {"input": "10 4\r\n104325 153357 26508... | false | stdio | null | true |
53/D | 53 | D | PyPy 3 | TESTS | 3 | 124 | 0 | 146262643 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0]
for i in range(n):
bi = b[i]
x = a[i:].index(bi) + i
for j in range(x, i, -1):
a[j], a[j - 1] = a[j - 1], a[j]
ans.append((j, j + 1))
ans[0] = str(len(ans... | 30 | 186 | 102,400 | 156766195 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
f = 0
for i in range(n):
for j in range(i,n):
if a[i] == b[j]:
f = j
break
# print(f)
for j in range(f, i, -1):
temp = b[j]
b[j] = b[j-1]
b[j-1] = te... | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Physical Education | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ... | In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1. | null | null | [{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}] | 1,500 | ["sortings"] | 30 | [{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_input:
n = int(f_input.readline().strip())
a = list(map(int, f_input.readline().split()))
initial_b = list(map(int, f_input.readline().split()))
with open(submission_path, 'r') as f_submi... | true |
53/D | 53 | D | PyPy 3-64 | TESTS | 3 | 124 | 0 | 211348193 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
N = int(input())
B = list(map(int,input().split()))
A = list(map(int,input().split(... | 30 | 186 | 4,096,000 | 146263164 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0]
for i in range(n):
ai = a[i]
x = b[i:].index(ai) + i
for j in range(x, i, -1):
b[j], b[j - 1] = b[j - 1], b[j]
ans.append((j, j + 1))
ans[0] = str(len(ans... | Codeforces Beta Round 49 (Div. 2) | CF | 2,011 | 2 | 256 | Physical Education | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ... | In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1. | null | null | [{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}] | 1,500 | ["sortings"] | 30 | [{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_input:
n = int(f_input.readline().strip())
a = list(map(int, f_input.readline().split()))
initial_b = list(map(int, f_input.readline().split()))
with open(submission_path, 'r') as f_submi... | true |
182/B | 182 | B | Python 3 | TESTS | 7 | 122 | 0 | 113132142 | import math
d = int(input())
n = int(input())
a = list(map(int,input().split()))
disp = 0
count = 0
'''
everyday get up and clock adds 1
when this happens , if disp +1 > d then disp = 1
then if that same day if disp!= actu then disp+=1
and then also count+=1
disp -> 19900 ---d -> 20000
a[i] = 60
offset = 100
... | 40 | 92 | 0 | 4719186 | def readln(): return tuple(map(int, input().split()))
d, = readln()
n, = readln()
prev = ans = 0
for cur in readln():
ans += 0 if prev == 0 else d - prev
prev = cur % d
print(ans) | Codeforces Round 117 (Div. 2) | CF | 2,012 | 1 | 256 | Vasya's Calendar | Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information ab... | The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106).
The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000).
The third line contains n space-separated integers: ai (1 ≤ ai ≤ d) — the number of days in each month i... | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | null | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing.
- Day 2. Month 1. The clock shows 2. Vasya changes nothing.
- Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 ma... | [{"input": "4\n2\n2 2", "output": "2"}, {"input": "5\n3\n3 4 3", "output": "3"}, {"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7"}] | 1,000 | ["implementation"] | 40 | [{"input": "4\r\n2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "31\r\n12\r\n31 28 31 30 31 30 31 31 30 31 30 31\r\n", "output": "7\r\n"}, {"input": "1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2\r\n1 1\r\n",... | false | stdio | null | true |
12/C | 12 | C | Python 3 | TESTS | 3 | 31 | 0 | 230251490 | n,k = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
arr2 = []
for _ in range(k):
fruit = input()
arr2.append(fruit)
arr3 = set(arr2)
min_ =0
i = 0
while i <len(arr3):
min_ += arr[i]
i +=1
j = len(arr)-1
maxx_ = 0
while j > (len(arr)-1-len(arr3)):
maxx_ += arr[j]
j -=1
... | 25 | 46 | 0 | 178913623 | import sys; R = sys.stdin.readline
n,m = map(int,R().split())
a = sorted(map(int,R().split()))
dic = {}
for _ in range(m):
s = R()
if s not in dic: dic[s] = 1
else: dic[s] += 1
dic = sorted(dic.values(),reverse=True)
res1,res2 = 0,0
for i in range(len(dic)):
res1 += a[i]*dic[i]
res2 += a[-i-1]*dic[i... | Codeforces Beta Round 12 (Div 2 Only) | ICPC | 2,010 | 1 | 256 | Fruits | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Asho... | The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exc... | Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | null | null | [{"input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19"}, {"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30"}] | 1,100 | ["greedy", "implementation", "sortings"] | 25 | [{"input": "5 3\r\n4 2 1 10 5\r\napple\r\norange\r\nmango\r\n", "output": "7 19\r\n"}, {"input": "6 5\r\n3 5 1 6 8 1\r\npeach\r\ngrapefruit\r\nbanana\r\norange\r\norange\r\n", "output": "11 30\r\n"}, {"input": "2 2\r\n91 82\r\neiiofpfpmemlakcystpun\r\nmcnzeiiofpfpmemlakcystpunfl\r\n", "output": "173 173\r\n"}, {"input"... | false | stdio | null | true |
28/A | 28 | A | Python 3 | TESTS | 1 | 124 | 307,200 | 5760049 | from collections import defaultdict
n, m = map(int, input().split())
a, b = map(int, input().split())
x, y = a, b
s = [0] * n
for i in range(n - 1):
u, v = map(int, input().split())
if u == a: s[i], b = abs(v - b), v
else: s[i], a = abs(u - a), u
s[n - 1] = abs(a - x) + abs(b - y)
a = defaultdict(list)
for... | 51 | 154 | 2,252,800 | 199146404 | import sys; R = sys.stdin.readline
S = lambda: map(int,R().split())
from collections import Counter
n,m = S()
if m*2<n: print("NO"); exit()
a = [[*S()] for _ in range(n)]
a += a[0],
b = [abs(a[i][0]-a[i+1][0])+abs(a[i][1]-a[i+1][1]) for i in range(n)]
r = [*S()]
cr = Counter(r)
for k in -1,1:
b1 = [b[2*i]+b[2*i+k]... | Codeforces Beta Round 28 (Codeforces format) | CF | 2,010 | 2 | 256 | Bender Problem | Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ... | The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ... | If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them. | null | null | [{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}] | 1,600 | ["implementation"] | 51 | [{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0... | 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, m = map(int, f.readline().split())
nails = [tuple(map(int, f.readline().split())) for _ in range(n)]
rods = list(map(int, f.readline().split())... | true |
28/A | 28 | A | Python 3 | TESTS | 1 | 156 | 307,200 | 67726217 | def dist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
def get_sorted_required_pruts(dists):
return sorted([dists[i * 2] + dists[i * 2 + 1] for i in range(len(dists) // 2)])
def get_answer(pruts, required_pruts):
i = 0
j = 0
answer = "YES"
seq = []
while i < len(required_pruts):
... | 51 | 186 | 1,740,800 | 216108451 | import sys
def ff(x, y):
return abs(sum(x)-sum(y))
n, m = map(int, input().split())
points = [tuple(map(int, input().split())) for i in range(n)]
points.append(points[0])
segments = []
for i in range(n):
segments.append(ff(points[i], points[i + 1]))
rods = list(map(int, input().split()))
rod_indices = {}... | Codeforces Beta Round 28 (Codeforces format) | CF | 2,010 | 2 | 256 | Bender Problem | Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ... | The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ... | If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them. | null | null | [{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}] | 1,600 | ["implementation"] | 51 | [{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0... | 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, m = map(int, f.readline().split())
nails = [tuple(map(int, f.readline().split())) for _ in range(n)]
rods = list(map(int, f.readline().split())... | true |
27/C | 27 | C | PyPy 3 | TESTS | 25 | 372 | 32,256,000 | 38968630 | n = int(input())
l = input()
l = [int(i) for i in l.split()]
r = 0
for i in range(0 , len(l)-2):
if l[i]>l[i+1] and l[i+1]<l[i+2]:
print(3)
print(i+1 , i+2 , i+3)
r = 1
break
elif l[i]<l[i+1] and l[i+1]>l[i+2]:
print(3)
print(i+1 , i+2 , i+3)
r = 1 ; bre... | 37 | 184 | 13,209,600 | 216585228 | def main():
n = int(input())
a = list(map(int, input().split()))
p1, p2 = True, True
for i in range(1, n):
if a[i] > a[i - 1]:
p1 = False
if a[i] < a[i - 1]:
p2 = False
if not (p1 or p2):
print("3")
print(1, i, i + 1)
re... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | PyPy 3 | TESTS | 25 | 498 | 95,846,400 | 89534617 | # Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 11/08/2020
from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
... | 37 | 186 | 13,516,800 | 224073094 | input()
t = list(map(int, input().split()))
for i in range(2, len(t)):
if (t[i] - t[i - 1]) * (t[i - 1] - t[0]) < 0:
print(3, 1, i, i + 1)
exit()
print(0) | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
537/E | 538 | E | Python 3 | TESTS | 2 | 77 | 6,963,200 | 116183467 | import sys
input = sys.stdin.readline
def solve():
n = int(input())
g = [[] for i in range(n+1)]
for i in range(1, n):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
q = [1]
d = [None]*(n+1)
d[1] = 0
i = 0
while i < len(q):
x = q[i]
#print(x)
i += 1
for v in g[x]:
if d[v] is N... | 35 | 826 | 55,808,000 | 86848147 | import sys
fin = sys.stdin
n = int(fin.readline())
ut = [-1] * n
vc = [[] for i in range(0, n)]
cvc = [[] for i in range(0, n)]
nr = [0] * n
for i in range(0, n - 1):
a, b = [int(number) for number in fin.readline().split()]
a -= 1
b -= 1
vc[a].append(b)
cvc[b].append(a)
nr[a] += 1
size = [0] * ... | VK Cup 2015 - Wild Card Round 2 | IOI | 2,015 | 2 | 256 | Demiurges Play Again | Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.
There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of ... | The first line contains a single integer n — the number of nodes in the tree (1 ≤ n ≤ 2·105).
Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n) — the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the roo... | Print two space-separated integers — the maximum possible and the minimum possible result of the game. | null | Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.
In the second sample no m... | [{"input": "5\n1 2\n1 3\n2 4\n2 5", "output": "3 2"}, {"input": "6\n1 2\n1 3\n3 4\n1 5\n5 6", "output": "3 3"}] | 2,200 | ["dfs and similar", "dp", "math", "trees"] | 35 | [{"input": "5\r\n1 2\r\n1 3\r\n2 4\r\n2 5\r\n", "output": "3 2\r\n"}, {"input": "6\r\n1 2\r\n1 3\r\n3 4\r\n1 5\r\n5 6\r\n", "output": "3 3\r\n"}, {"input": "1\r\n", "output": "1 1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1 1\r\n"}, {"input": "3\r\n1 2\r\n1 3\r\n", "output": "2 2\r\n"}, {"input": "10\r\n1 2\r\n1 3\r\... | false | stdio | null | true |
961/E | 961 | E | PyPy 3 | TESTS | 6 | 296 | 18,124,800 | 50577971 | N = int(input())
A = list(map(int, input().split()))
def getsum(BITTree,i):
s = 0
i = i+1
while i > 0:
s += BITTree[i]
i -= i & (-i)
return s
def updatebit(BITTree , n , i ,v):
i += 1
while i <= n:
BITTree[i] += v
i += i & (-i)
def construct(arr, ... | 30 | 498 | 44,236,800 | 128480912 | from collections import defaultdict
import sys
input = sys.stdin.readline
def make_tree(n):
tree = [0] * (n + 1)
return tree
def get_sum(i):
s = 0
while i > 0:
s += tree[i]
i -= i & -i
return s
def get_sum_segment(s, t):
if s > t:
return 0
ans = get_sum(t) - get_su... | Educational Codeforces Round 41 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Tufurama | One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ... | The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons.
The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season. | Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x. | null | Possible pairs in the second example:
1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1);
2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2);
3. x = 1, y... | [{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}] | 1,900 | ["data structures"] | 30 | [{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000... | false | stdio | null | true |
106/D | 106 | D | PyPy 3-64 | TESTS | 4 | 186 | 2,764,800 | 176909944 | import sys
import math
import collections
import random
from heapq import heappush, heappop
from functools import reduce
input = sys.stdin.readline
ints = lambda: list(map(int, input().split()))
n, m = ints()
grid = []
for _ in range(n):
line = input().strip()
grid.append(list(line))
prefix_r = []
for i in... | 70 | 1,090 | 28,160,000 | 153861321 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a, pos = [], []
for i in range(n):
a.append(input().rstrip())
for j in range(m):
if a[i][j] != '.' and a[i][j] != '#':
pos.append((i, j))
W = [[0]*(m+3) for i in range(n+3)]
for i in range(n):
for j in range(m):
... | Codeforces Beta Round 82 (Div. 2) | CF | 2,011 | 2 | 256 | Treasure Island | Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle n × m in size. Each cell stands for an islands' square (the square's side length equals... | The first line contains two integers n and m (3 ≤ n, m ≤ 1000).
Then follow n lines containing m integers each — the island map's description. "#" stands for the sea. It is guaranteed that all cells along the rectangle's perimeter are the sea. "." stands for a penetrable square without any sights and the sights are ma... | Print all local sights that satisfy to the instructions as a string without any separators in the alphabetical order. If no sight fits, print "no solution" without the quotes. | null | null | [{"input": "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2", "output": "AD"}, {"input": "3 4\n####\n#.A#\n####\n2\nW 1\nN 2", "output": "no solution"}] | 1,700 | ["brute force", "implementation"] | 70 | [{"input": "6 10\r\n##########\r\n#K#..#####\r\n#.#..##.##\r\n#..L.#...#\r\n###D###A.#\r\n##########\r\n4\r\nN 2\r\nS 1\r\nE 1\r\nW 2\r\n", "output": "AD"}, {"input": "3 4\r\n####\r\n#.A#\r\n####\r\n2\r\nW 1\r\nN 2\r\n", "output": "no solution"}, {"input": "10 10\r\n##########\r\n#K#..##..#\r\n##...ZB..#\r\n##.......#\... | false | stdio | null | true |
28/A | 28 | A | Python 3 | TESTS | 1 | 124 | 0 | 11979634 | import sys
n, m = map(int, input().split())
points = [tuple(map(int, input().split())) for i in range(n)]
segments = []
x, y = points[-1]
for a, b in points:
if x == a:
segments.append(abs(y - b))
else:
segments.append(abs(x - a))
x, y = a, b
rods = list(map(int, input().split()))
rod_indices = {}
for ... | 51 | 186 | 2,457,600 | 228020885 | n, m = map(int,input().split())
dist = [0 for i in range(n)]
nails = []
for i in range(n):
nails.append(tuple(map(int,input().split())))
rods = list(map(int,input().split()))
rods_d_1 = {}
rods_d_2 = {}
for i in range(m):
if rods[i] in rods_d_1:
rods_d_1[rods[i]].append(i)
rods_d_2[rods[i]].append(i)
els... | Codeforces Beta Round 28 (Codeforces format) | CF | 2,010 | 2 | 256 | Bender Problem | Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ... | The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ... | If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.
If there are multiple solutions, print any of them. | null | null | [{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}] | 1,600 | ["implementation"] | 51 | [{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0... | 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, m = map(int, f.readline().split())
nails = [tuple(map(int, f.readline().split())) for _ in range(n)]
rods = list(map(int, f.readline().split())... | true |
459/B | 459 | B | PyPy 3-64 | TESTS | 5 | 92 | 23,552,000 | 184219990 | n=int(input())
m=list(map(int,input().split()))
x=max(m)
y=min(m)
a=b=0
if(x==y):
print(0,1,sep=' ')
else:
for i in range(n):
if (m[i] == x):
a += 1
if (m[i] == y):
b += 1
print(x - y, a * b, sep=' ') | 58 | 109 | 17,510,400 | 178082825 | n=int(input())
a=list(map(int,input().split()))
i,j=min(a),max(a)
print(j-i,[(n*(n-1))//2,a.count(i)*a.count(j)][i!=j]) | Codeforces Round 261 (Div. 2) | CF | 2,014 | 1 | 256 | Pashmak and Flowers | Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i... | The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | null | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers;
2. choosing the first and the fifth flowers;
3. choosing the fourth and the second flowers;
4. choosing the fourth and the fifth flowers. | [{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}] | 1,300 | ["combinatorics", "implementation", "sortings"] | 58 | [{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":... | false | stdio | null | true |
898/C | 898 | C | PyPy 3 | TESTS | 2 | 155 | 307,200 | 94495367 | from collections import defaultdict
n = int(input())
book = defaultdict(lambda : [])
for i in range(n):
s = input().split()
k = s[1]
for j in s[2:]:
book[s[0]].append(j)
for entry in book:
book[entry] = list(set(book[entry]))
for i in book[entry]:
for j in book[entry]:
if... | 59 | 46 | 0 | 160934983 | n = int(input())
records = dict()
for _ in range(n):
record = list(input().split())
name = record[0]
size = int(record[1])
phone = record[2:]
if name not in records:
records[name] = set()
for num in phone:
records[name].add(num)
print(len(records))
for name, phones i... | Codeforces Round 451 (Div. 2) | CF | 2,017 | 2 | 256 | Phone Numbers | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri... | First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books.
The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett... | Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books.
The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec... | null | null | [{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789... | 1,400 | ["implementation", "strings"] | 59 | [{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2... | false | stdio | import sys
from collections import defaultdict
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input and build friends data
friends = defaultdict(set)
with open(input_path, 'r') as f:
n = int(f.readline())
for _ in range(n):
... | true |
175/B | 175 | B | Python 3 | TESTS | 8 | 62 | 0 | 214349665 | n = int(input())
name = []
score = []
for _ in range(n):
a,b = input().split()
name.append(a)
score.append(int(b))
print(len(set(name)))
for i in range(n):
for j in range(n):
if i != j and name[i] == name[j]:
x = min(score[i],score[j])
name[score.index(x)] = 0
... | 46 | 124 | 409,600 | 14703186 | class Player:
def __init__(self, name, score):
self.name = name
self.score = score
class Tier:
def __init__(self, label, percentile):
self.label = label
self.percentile = percentile
tier_data = [ ('pro', 99), ('hardcore', 90),
('average', 80), ('random', 50) ]
tier... | Codeforces Round 115 | CF | 2,012 | 2 | 256 | Plane of Tanks: Pro | Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results.
A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has... | The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results.
Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T... | Print on the first line the number m — the number of players, who participated in one round at least.
Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th... | null | In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes... | [{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}] | 1,400 | ["implementation"] | 78 | [{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input data
with open(input_path) as f:
n = int(f.readline())
players = {}
for _ in range(n):
name, points = f.readline().strip().split()
points = int(points)
if name not in players ... | true |
27/C | 27 | C | Python 3 | TESTS | 25 | 778 | 7,680,000 | 8027210 | n = int(input())
a = list(map(int, input().split()))
b = list(sorted(a))
c = list(sorted(a, reverse=True))
if a == b or a == c:
print(0)
exit()
for i in range(n - 2):
x = [a[i], a[i + 1], a[i + 2]]
if not (x in (list(sorted(x)), list(sorted(x, reverse=True)))):
print(3)
print(i + 1, i ... | 37 | 186 | 13,619,200 | 214206414 | import sys
input = sys.stdin.readline
n = int(input())
ls = list(map(int,input().split()))
l1 = ls.copy()
l1.sort()
for i in range(n) :
if ls[i] != l1[i] :
break
else :
print(0)
exit()
l1.reverse()
for i in range(n) :
if ls[i] != l1[i] :
break
else :
print(0)
exit()
j = 1
while j... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | PyPy 3-64 | TESTS | 18 | 156 | 13,516,800 | 195448945 | import sys; R = sys.stdin.readline
S = lambda: map(int,R().split())
n = int(R())
if n<3: print(0); exit()
a = [*S()]
s,d = [0],0
for i in range(1,n):
g = a[i]-a[s[-1]]
if g>0:
if d==1: s[-1] = i
elif not d: d = 1; s += i,
else: print(3); print(s[0]+1,s[1]+1,i+1); exit()
elif g<0:
... | 37 | 186 | 13,926,400 | 231387860 | n=int(input())
a=list(map(int,input().split()))
for i in range(2,n):
if (a[i]-a[i-1])*(a[i-1]-a[0])<0:
print(3,1,i,i+1)
exit()
print(0) | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | Python 3 | TESTS | 17 | 156 | 13,926,400 | 225872930 | # LUOGU_RID: 126705765
input();a=list(map(int,input().split()));p=0;f=1
try:
while 1:
if a[p]>a[p+1]:
q=p+1
while 1:
if a[q]<a[q+1]:print(3);print(q,q+1,q+2);f=0;exit()
else:q+=1
elif a[p]<a[p+1]:
q=p+1
while 1:
... | 37 | 186 | 14,131,200 | 206998086 | # LUOGU_RID: 111117503
from sys import stdin
input = stdin.readline
n = int(input())
lst = [0] + list(map(int,input().split()))
for i in range(2, n) :
if (lst[i + 1] > lst[i] and lst[i] < lst[1]) or (lst[i + 1] < lst[i] and lst[i] > lst[1]) :
print(3)
print(1, i, i + 1)
exit()
pri... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | PyPy 3-64 | TESTS | 17 | 186 | 13,516,800 | 214196488 | import sys
input = sys.stdin.readline
n = int(input())
ls = list(map(int,input().split()))
l1 = ls.copy()
l1.sort()
for i in range(n) :
if ls[i] != l1[i] :
break
else :
print(0)
exit()
l1.reverse()
for i in range(n) :
if ls[i] != l1[i] :
break
else :
print(0)
exit()
j = 0
while j... | 37 | 248 | 7,372,800 | 155275806 | n = int(input())
array = list(map(int, input().split()))
maxx = array[0]
minn = array[0]
positionMin = 0
positionMax = 0
for i in range(n):
if positionMax < positionMin:
if (array[i] > minn) & (array[i] > minn):
print(3)
print(positionMax + 1, positionMin + 1, i + 1)
brea... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | PyPy 3-64 | TESTS | 17 | 186 | 13,619,200 | 214200066 | import sys
input = sys.stdin.readline
n = int(input())
ls = list(map(int,input().split()))
l1 = ls.copy()
l1.sort()
for i in range(n) :
if ls[i] != l1[i] :
break
else :
print(0)
exit()
l1.reverse()
for i in range(n) :
if ls[i] != l1[i] :
break
else :
print(0)
exit()
print(3)
j = ... | 37 | 248 | 11,059,200 | 213489237 | from sys import stdin
N = int(stdin.readline())
data = [int(w) for w in stdin.readline().split()]
# low , high, low
dp = [N - 1] * N
for i in range(N - 1, 0, -1):
if data[i - 1] < data[dp[i]]:
dp[i - 1] = i
else:
dp[i - 1] = dp[i]
low = 0
for i in range(1, N - 1):
if data[i] > data[low] ... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | Python 3 | TESTS | 17 | 280 | 6,348,800 | 45907733 | def main():
count=int(input())
arr=input().split(" ")
if count<=2:
print(0)
else:
base=int(arr[0])
bo=True
for x in range(1,count-1):
test=int(arr[x])
if test<base:
smallest=test
small=True
bo=False
... | 37 | 310 | 14,131,200 | 123102728 | s = input().split()
n = int(s[0])
s1 = input().split()
a = []
for i in range(1, n + 1) :
a.append(int(s1[i - 1]))
flag = 1
for i in range(2, n) :
if (((a[i] > a[i - 1]) and (a[i - 1] < a[0])) or ((a[i] < a[i - 1]) and (a[i -1] > a[0]))) :
print(3)
print(1, i, i + 1)
flag = 0
brea... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
27/C | 27 | C | Python 3 | TESTS | 17 | 342 | 14,540,800 | 80265323 | n = int(input().strip())
array = list(map(int, input().strip().split()))
def checker(array):
if len(array) <= 2:
print(0)
return
ind = 1
while ind < len(array) and array[ind] == array[0]:
ind += 1
if ind + 1 == len(array):
print(0)
return
ind_two = ind + 1
... | 37 | 310 | 18,329,600 | 151482720 | t = 1
while t:
t -= 1
q = int(input())
b = list(map(int, input().split()))
prev = -1
flag = 0
sa = []
k = 0
for i in b:
if i != prev:
sa.append([i, k])
prev = i
k += 1
for i in range(1, len(sa) - 1):
if sa[i - 1][0] < sa[i][0] and sa... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
459/B | 459 | B | PyPy 3-64 | TESTS | 5 | 93 | 22,118,400 | 172364500 | n = int(input())
flowers = list(map(int, input().split(' ')))
flowers_min = min(flowers)
flowers_max = max(flowers)
summary = flowers_max - flowers_min
if summary:
print(flowers_max - flowers_min, flowers.count(flowers_min) * flowers.count(flowers_max))
else:
print(0, 1) | 58 | 109 | 19,968,000 | 170468604 | n=int(input())
L=input().split()
maxm=0
c1=0
minm=float("inf")
c2=0
for i in range(n):
a=int(L[i])
if a<minm:
minm=a
c2=1
elif a==minm:
c2+=1
if a>maxm:
maxm=a
c1=1
elif a==maxm:
c1+=1
if minm==maxm:
print(0,c1*(c1-1)//2)
else:
print(maxm-minm,... | Codeforces Round 261 (Div. 2) | CF | 2,014 | 1 | 256 | Pashmak and Flowers | Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i... | The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | null | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers;
2. choosing the first and the fifth flowers;
3. choosing the fourth and the second flowers;
4. choosing the fourth and the fifth flowers. | [{"input": "2\n1 2", "output": "1 1"}, {"input": "3\n1 4 5", "output": "4 1"}, {"input": "5\n3 1 2 3 1", "output": "2 4"}] | 1,300 | ["combinatorics", "implementation", "sortings"] | 58 | [{"input": "2\r\n1 2\r\n", "output": "1 1"}, {"input": "3\r\n1 4 5\r\n", "output": "4 1"}, {"input": "5\r\n3 1 2 3 1\r\n", "output": "2 4"}, {"input": "2\r\n1 1\r\n", "output": "0 1"}, {"input": "3\r\n1 1 1\r\n", "output": "0 3"}, {"input": "4\r\n1 1 1 1\r\n", "output": "0 6"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":... | false | stdio | null | true |
27/C | 27 | C | Python 3 | TESTS | 17 | 434 | 6,144,000 | 39647677 | n=int(input())
x=input().split()
y=0
while y<n:
x[y]=int(x[y])
y+=1
y=0
ans=[1]
dec=0
inc=0
while y<len(x)-1:
if x[y]>x[y+1]:
ans.append(y+2)
dec=1
break
elif x[y]<x[y+1]:
ans.append(y+2)
inc=1
break
y=y+1
if dec==1:
while y<len(x)-1:
if x[... | 37 | 342 | 11,161,600 | 145984089 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
mil, mal = list(a), list(a)
for i in range(1, n):
mil[i] = min(mil[i], mil[i - 1])
for i in range(1, n):
mal[i] = max(mal[i], mal[i - 1])
mir, mar = list(a), list(a)
for i in range(n - 2, -1, -1):
mir[i] = min(mir[i]... | Codeforces Beta Round 27 (Codeforces format, Div. 2) | CF | 2,010 | 2 | 256 | Unordered Subsequence | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | null | null | [{"input": "5\n67 499 600 42 23", "output": "3\n1 3 5"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "3\n2 3 1", "output": "3\n1 2 3"}] | 1,900 | ["constructive algorithms", "greedy"] | 37 | [{"input": "3\r\n3 1 2\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "1\r\n-895376\r\n", "output": "0\r\n"}, {"input": "2\r\n166442 61629\r\n", "output": "0\r\n"}, {"input": "3\r\n-771740 -255752 -300809\r\n", "output": "3\r\n1 2 3\r\n"}, {"input": "4\r\n-227347 -573134 -671045 11011\r\n", "output": "3\r\n2 3 4\r\n"}, {... | false | stdio | import sys
def main():
input_path, output_path, submission_path = sys.argv[1:4]
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().strip().split()))
# Read reference output
with open(output_path) as f:
ref_lines ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.