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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
82/B | 82 | B | Python 3 | TESTS | 32 | 1,714 | 2,867,200 | 56191977 | n = int(input())
common,mas = set(),[]
for i in range(n*(n-1)//2):
lst = list(map(int,input().split()))
lst.pop(0)
for i,x in enumerate(lst):
common.add(x)
mas.append(set(lst))
d = {}
for x in common:d[x]=False
for x in common:
if d[x]==False:
res = set(common)
for i,y in enu... | 34 | 312 | 2,662,400 | 5043606 | from collections import defaultdict
n = int(input())
if n == 2:
t = input().split()
print(1, t[1])
print(int(t[0]) - 1, ' '.join(t[2: ]))
else:
m = (n * (n - 1)) // 2
t = [0] * m
p = defaultdict(list)
for i in range(m):
t[i] = list(map(int, input().split()))[1: ]
for j in... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
358/C | 358 | C | Python 3 | TESTS | 2 | 78 | 204,800 | 5042432 | n = int( input() )
Q = 0
P = 0
Df = 0
Db = 0
l=[]
for _ in range(n):
x = int(input())
if x==0:
if l!=[]:
Q = max(l)
for i in l:
if i==Q:
print("pushQueue")
elif i>P and P<=Df:
print("pushStack")
P=i
elif i>Df and Df<=P:
print("pushFront")
Df=i
else:
print("pushBack")
... | 26 | 826 | 12,800,000 | 149773930 | n = int(input())
last_zero, largest, nd_largest, rd_largest = -1, -1, -1, -1
arr = [int(input()) for _ in range(n)]
for i in range(n):
if arr[i] == 0:
filled_stk, filled_queue, filled_front = False, False, False
for j in range(last_zero + 1, i):
if arr[j] == largest and not filled_stk:
... | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Containers | Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her present to show Dima how great a programmer he is. For that, she is going to g... | The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer:
1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers.
2. Integer 0 shows that Inna asks Dima to make at most... | Each command of the input must correspond to one line of the output — Dima's action.
For the command of the first type (adding) print one word that corresponds to Dima's choice:
- pushStack — add to the end of the stack;
- pushQueue — add to the end of the queue;
- pushFront — add to the beginning of the deck;
- push... | null | null | [{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}] | 2,000 | ["constructive algorithms", "greedy", "implementation"] | 26 | [{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
input_lines = f.read().splitlines()
n = int(input_lines[0])
input_commands = input_lines[1:n+1]
with open(submission_path) as f:
submission_lines = [line.strip()... | true |
247/B | 250 | B | PyPy 3-64 | TESTS | 1 | 154 | 0 | 165702430 | for i in range(int(input())):
a = input().split(':')
for j in range(len(a)):
if len(a[j]) == 0:
while len(a) < 8:
a.insert(j, '')
for j in range(8):
a[j] = '0' * (4 - len(a[j])) + a[j]
print(*a, sep=':') | 40 | 92 | 0 | 187122060 | n = int(input())
for i in range(n):
s = input().split(':')
if (s[0] == ''):
s[0] = '0'*4
if s[-1] == '':
s[-1] = '0'*4
idx = -1
for i in range(len(s)):
if s[i] == '':
idx = i
break
for i in range(len(s)):
if (len(s[i]) < 4):
s[i... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
246/E | 246 | E | Python 3 | TESTS | 1 | 60 | 307,200 | 229854455 | import heapq
import itertools
import sys
# from typing import Counter
# import itertools
# import math
# import os
# import random
from collections import defaultdict
from functools import lru_cache
from bisect import bisect_left, bisect_right
# from heapq import heapify, heappop, heappush
# from io import BytesIO, ... | 72 | 1,652 | 89,702,400 | 230808843 | import os,sys,random,threading
from random import randint
from copy import deepcopy
from io import BytesIO, IOBase
from types import GeneratorType
from functools import lru_cache, reduce
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from itertools import accumulate, co... | Codeforces Round 151 (Div. 2) | CF | 2,012 | 3 | 256 | Blood Cousins Return | Polycarpus got hold of a family tree. The found tree describes the family relations of n people, numbered from 1 to n. Every person in this tree has at most one direct ancestor. Also, each person in the tree has a name, the names are not necessarily unique.
We call the man with a number a a 1-ancestor of the man with ... | The first line of the input contains a single integer n (1 ≤ n ≤ 105) — the number of people in the tree. Next n lines contain the description of people in the tree. The i-th line contains space-separated string si and integer ri (0 ≤ ri ≤ n), where si is the name of the man with a number i, and ri is either the number... | Print m whitespace-separated integers — the answers to Polycarpus's records. Print the answers to the records in the order, in which the records occur in the input. | null | null | [{"input": "6\npasha 0\ngerald 1\ngerald 1\nvalera 2\nigor 3\nolesya 1\n5\n1 1\n1 2\n1 3\n3 1\n6 1", "output": "2\n2\n0\n1\n0"}, {"input": "6\nvalera 0\nvalera 1\nvalera 1\ngerald 0\nvalera 4\nkolya 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "output": "1\n0\n0\n0\n2\n0\n0"}] | 2,400 | ["binary search", "data structures", "dfs and similar", "dp", "sortings"] | 72 | [{"input": "6\r\npasha 0\r\ngerald 1\r\ngerald 1\r\nvalera 2\r\nigor 3\r\nolesya 1\r\n5\r\n1 1\r\n1 2\r\n1 3\r\n3 1\r\n6 1\r\n", "output": "2\r\n2\r\n0\r\n1\r\n0\r\n"}, {"input": "6\r\nvalera 0\r\nvalera 1\r\nvalera 1\r\ngerald 0\r\nvalera 4\r\nkolya 4\r\n7\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n4 1\r\n5 1\r\n6 1\r\n", "output... | false | stdio | null | true |
247/B | 250 | B | PyPy 3 | TESTS | 1 | 186 | 0 | 203520865 | for _ in range((int)(input())) :
s = input().split(':')
for _ in range(len(s)) :
if s[_] == "" :
while len(s) < 8 : s.insert(_ , "")
for _ in range(8) : s[_] = s[_].zfill(4)
print(":".join(s)) | 40 | 92 | 614,400 | 208397906 | import ipaddress
def solve():
src = input()
addr = ipaddress.ip_address(src)
print(addr.exploded)
def main():
n = int(input())
for _ in range(n):
solve()
main() | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
82/B | 82 | B | Python 3 | TESTS | 32 | 278 | 307,200 | 14960585 | c, v = [[0] * 201 for i in range(201)], []
n = int(input())
for i in range(n * (n - 1) // 2):
a = list(map(int, input().split()))[1:]
for x in a:
for y in a:
c[x][y] += 1
for i, ci in enumerate(c):
if ci[i]:
a = [j for j, cij in enumerate(ci) if cij == n - 1]
v.append(a)
... | 34 | 560 | 9,523,200 | 197184607 | def solve():
n = int(input())
all_elements, set_list = set(), []
for i in range(n * (n - 1) // 2):
inp_list = list(map(int, input().split()))
inp_list.pop(0)
set_list.append(set(inp_list))
all_elements |= set(inp_list)
if n == 2:
item = list(set_list[0])
p... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
82/B | 82 | B | PyPy 3-64 | TESTS | 32 | 436 | 9,625,600 | 159106321 | I = lambda:list(map(int, input().split()))
unions = []
n = int(input())
loc = {}
s1, s2 = -1, -1
for i in range(n*(n-1)//2):
lst = I()[1:]
for num in lst:
if num in loc:
s1, s2 = loc[num], i
else:
loc[num] = i
unions.append(lst)
sets = []
sets.append([v for v in unio... | 34 | 186 | 2,457,600 | 4454031 | n=int(input())
L=[]
for i in range((n*(n-1))//2):
A=input().split()
L.append(A[1:])
x=L[0][0]
Set=list(L[0])
Set.remove(x)
for i in range(1,(n*(n-1))//2):
if(x in L[i]):
for item in L[i]:
if(item in Set):
Set.remove(item)
break
x=Set[0]
Sets=[]
Sets.append(... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
82/B | 82 | B | PyPy 3 | TESTS | 32 | 530 | 27,852,800 | 129293680 | def process(n, A):
d = {}
n2 = n*(n-1)//2
for i in range(n2):
row = A[i]
m = len(row)
for j in range(1, m):
c = row[j]
if c not in d:
d[c] = set([])
d[c].add(i)
if n==2:
row = A[0]
S1 = []
S2 = []
... | 34 | 186 | 10,649,600 | 126790096 | #Med_Neji
#x,y=map( lambda x:int(x)//abs(int(x)) ,input().split())
#x,y=map(int,input().split())
#n=int(input())
#l=list(map(int,input().split()))
#s=input()
#x=0
n=int(input())
l = [(set(input().split()[1:])) for _ in range(n*(n-1)//2)]
if n==2:
l=list(l[0])
print(1,l[0])
print(len(l)-1,*l[1:])
q=set()
... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 124 | 409,600 | 14751560 | import re
n = int(input())
for i in range(n):
s = input().strip()
group_count = s.count(':') + 1
if group_count < 8:
s = re.sub('::', ':' + (9 - group_count) * '0000:', s)
groups = s.split(':')
for i, group in enumerate(groups):
if len(group) < 4:
groups[i] = (4 - len(gr... | 40 | 92 | 614,400 | 208398186 | import ipaddress
for _ in range(int(input())):
print(ipaddress.ip_address(input()).exploded) | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 124 | 4,608,000 | 20167972 | n = int(input())
ips = [input() for j in range(n)]
for ip in ips:
colonNum = ip.count(":")
if colonNum < 7:
ip = ip.replace("::", ":" * (9 - colonNum))
comps = ip.split(":")
for i in range(len(comps)):
comps[i] = "0" * (4 - len(comps[i])) + comps[i]
print(":".join(comps)) | 40 | 124 | 0 | 11596106 | import sys
def solve():
n = int(input())
for test in range(n):
line = input().split(':')
i = 0
while i < len(line):
if i > 0 and line[i] == '' and line[i-1] == '':
line.pop(i)
i-=1
i+=1
for i, string in enumerate(line):
... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 154 | 0 | 51964779 | n=int(input())
for i in range(n):
s=input().split(":")
t=True
for i in range(len(s)):
if 0<len(s[i])<4:
s[i]=(4-len(s[i]))*'0'+s[i]
elif t and len(s[i])==0:
s[i]="0000:"*(8-len(s))+"0000"
t=False
elif len(s[i])==0:
s[i]="0000"
for ... | 40 | 124 | 0 | 117566553 | for _ in range(int(input())):
D = input().split(':')
if not D[0]:
D = D[1:]
if not D[-1]:
D.pop()
n = len(D)
for i in range(n):
D[i] = D[i].zfill(4) if D[i] else '0000:' * (8 - n) + '0000'
print(':'.join(D)) | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
665/B | 665 | B | Python 3 | TESTS | 3 | 46 | 4,608,000 | 17403780 | #!/usr/bin/python3
n, m, k = map(int, input().split())
positionOf = [x-1 for x in map(int, input().split())]
sol = 0
for i in range(n):
v = [x-1 for x in map(int, input().split())]
for x in v:
sol += positionOf[x] + 1
for y in range(k):
if positionOf[y] < positionOf[x]:
... | 10 | 46 | 0 | 186638540 | n, m, k = map(int, input().split())
a = list(map(int,input().split()))
ans = m*n
for i in range(n):
b = list(map(int,input().split()))
for j in range(m):
pos = a.index(b[j])
ans += pos
del a[pos]
a.insert(0,b[j])
print(ans) | Educational Codeforces Round 12 | ICPC | 2,016 | 1 | 256 | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the ... | The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are... | Print the only integer t — the total time needed for Ayush to process all the orders. | null | Customer 1 wants the items 1 and 5.
pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
pos(1) = 3, so the new positi... | [{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}] | 1,400 | ["brute force"] | 10 | [{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99... | false | stdio | null | true |
632/F | 632 | F | PyPy 3-64 | TESTS | 2 | 46 | 0 | 216944293 | import sys
def input(): return sys.stdin.readline().strip()
n = int(input())
l = [0]*n
for x in range(n): l[x] = tuple(input().split())
l2 = list(zip(*l))
for x in range(n):
if l[x] != l2[x]:
print("NOT MAGIC")
break
else: print("MAGIC") | 34 | 3,306 | 474,521,600 | 142642726 | from collections import defaultdict, deque
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
rs, rt = get_root(s), get_roo... | Educational Codeforces Round 9 | ICPC | 2,016 | 5 | 512 | Magic Matrix | You're given a matrix A of size n × n.
Let's call the matrix with nonnegative elements magic if it is symmetric (so aij = aji), aii = 0 and aij ≤ max(aik, ajk) for all triples i, j, k. Note that i, j, k do not need to be distinct.
Determine if the matrix is magic.
As the input/output can reach very huge size it is r... | The first line contains integer n (1 ≤ n ≤ 2500) — the size of the matrix A.
Each of the next n lines contains n integers aij (0 ≤ aij < 109) — the elements of the matrix A.
Note that the given matrix not necessarily is symmetric and can be arbitrary. | Print ''MAGIC" (without quotes) if the given matrix A is magic. Otherwise print ''NOT MAGIC". | null | null | [{"input": "3\n0 1 2\n1 0 2\n2 2 0", "output": "MAGIC"}, {"input": "2\n0 1\n2 3", "output": "NOT MAGIC"}, {"input": "4\n0 1 2 3\n1 0 3 4\n2 3 0 5\n3 4 5 0", "output": "NOT MAGIC"}] | 2,400 | ["brute force", "divide and conquer", "graphs", "matrices", "trees"] | 34 | [{"input": "3\r\n0 1 2\r\n1 0 2\r\n2 2 0\r\n", "output": "MAGIC\r\n"}, {"input": "2\r\n0 1\r\n2 3\r\n", "output": "NOT MAGIC\r\n"}, {"input": "4\r\n0 1 2 3\r\n1 0 3 4\r\n2 3 0 5\r\n3 4 5 0\r\n", "output": "NOT MAGIC\r\n"}, {"input": "5\r\n0 2 5 9 5\r\n2 0 5 9 5\r\n5 5 0 9 4\r\n9 9 9 0 9\r\n5 5 4 9 0\r\n", "output": "MA... | false | stdio | null | true |
367/A | 367 | A | PyPy 3-64 | TESTS | 2 | 46 | 0 | 174047011 | import sys
input = sys.stdin.readline
s = input()[:-1]
d = [[0, 0, 0]]
for i in s:
e = d[-1].copy()
e[ord(i)-120] += 1
d.append(e)
for _ in range(int(input())):
a, b = map(int, input().split())
q = []
for i in range(3):
q.append(d[b][i]-d[a-1][i])
q.sort()
if q[2] - q[0] > 1:
... | 38 | 624 | 6,451,200 | 5285846 | import sys
s=sys.stdin.readline().split()[0]
m=int(sys.stdin.readline())
Numx=[]
Numy=[]
Numz=[]
x=0
y=0
z=0
for i in range(len(s)):
if(s[i]=='x'):
x+=1
if(s[i]=='y'):
y+=1
if(s[i]=='z'):
z+=1
Numx.append(x)
Numy.append(y)
Numz.append(z)
Ans=""
for M in range(m):
... | Codeforces Round 215 (Div. 1) | CF | 2,013 | 1 | 256 | Sereja and Algorithm | Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q1q2... qk. The algorithm consists of two steps:
1. Find any continuous subsequence (substring) of three characters of string q, which doesn'... | The first line contains non-empty string s, its length (n) doesn't exceed 105. It is guaranteed that string s only contains characters: 'x', 'y', 'z'.
The second line contains integer m (1 ≤ m ≤ 105) — the number of tests. Next m lines contain the tests. The i-th line contains a pair of integers li, ri (1 ≤ li ≤ ri ≤ ... | For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise. | null | In the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string "xzyx" on which the algorithm will terminate. In all other tests the algorithm doesn't work correctly. | [{"input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6", "output": "YES\nYES\nNO\nYES\nNO"}] | 1,500 | ["data structures", "implementation"] | 38 | [{"input": "zyxxxxxxyyz\r\n5\r\n5 5\r\n1 3\r\n1 11\r\n1 4\r\n3 6\r\n", "output": "YES\r\nYES\r\nNO\r\nYES\r\nNO\r\n"}, {"input": "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\r\n10\r\n17 67\r\n6 35\r\n12 45\r\n56 56\r\n14 30\r\n25 54\r\n1 1\r\n46 54\r\n3 33\r\n19 40\r\n", "output": "NO\r\nNO\r\n... | false | stdio | null | true |
840/B | 840 | B | PyPy 3 | PRETESTS | 3 | 93 | 0 | 29576435 | import sys
sys.setrecursionlimit(500000)
n, m = map(int, sys.stdin.readline().split())
d = list(map(int, sys.stdin.readline().split()))
gph = [[] for _ in range(n)]
for _ in range(m):
u, v = map(int, sys.stdin.readline().split())
u -= 1
v -= 1
gph[u].append((v, _))
gph[v].append((u, _))
t = ... | 73 | 2,979 | 87,756,800 | 167362143 | import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush... | Codeforces Round 429 (Div. 1) | CF | 2,017 | 3 | 256 | Leha and another game about graph | Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say... | The first line contains two integers n, m (1 ≤ n ≤ 3·105, n - 1 ≤ m ≤ 3·105) — number of vertices and edges.
The second line contains n integers d1, d2, ..., dn ( - 1 ≤ di ≤ 1) — numbers on the vertices.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) — edges. It's guaranteed, that graph in the ... | Print - 1 in a single line, if solution doesn't exist. Otherwise in the first line k — number of edges in a subset. In the next k lines indexes of edges. Edges are numerated in order as they are given in the input, starting from 1. | null | In the first sample we have single vertex without edges. It's degree is 0 and we can not get 1. | [{"input": "1 0\n1", "output": "-1"}, {"input": "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4", "output": "0"}, {"input": "2 1\n1 1\n1 2", "output": "1\n1"}, {"input": "3 3\n0 -1 1\n1 2\n2 3\n1 3", "output": "1\n2"}] | 2,100 | ["constructive algorithms", "data structures", "dfs and similar", "dp", "graphs"] | 73 | [{"input": "1 0\r\n1\r\n", "output": "-1\r\n"}, {"input": "4 5\r\n0 0 0 -1\r\n1 2\r\n2 3\r\n3 4\r\n1 4\r\n2 4\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1 2\r\n", "output": "1\r\n1\r\n"}, {"input": "3 3\r\n0 -1 1\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "1\r\n2\r\n"}, {"input": "10 10\r\n-1 -1 -1 -1 -1 -1 -1 -1 -1 ... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
d = list(map(int, f.readline().split()))
edges = [tuple(map(int, f.readline().split())) for _ in range(m)]
# Read submission... | true |
665/B | 665 | B | Python 3 | TESTS | 3 | 62 | 4,608,000 | 18257545 | import math
[n, m, k] = map(int,input().split(" "))
pos = list(map(int,input().split(" ")))
queue = [0] * k
for i in range(k):
# print(i, pos[i])
queue[pos[i]-1] = i+1
# print(queue)
time = 0
for i in range(n):
items = list(map(int,input().split(" ")))
for j in range(m):
item = items[j]
# print(item, queue.i... | 10 | 61 | 0 | 215054002 | n , m , k = map ( int , input () . split () )
p = list ( map ( int , input () . split () ) )
ans = 0
for _ in range ( n ) :
arr = list ( map ( int , input () . split () ) )
for i in arr :
pos = p . index ( i )
ans += pos + 1
p = [p [pos]] + p[:pos] + p[pos + 1:]
print (ans) | Educational Codeforces Round 12 | ICPC | 2,016 | 1 | 256 | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the ... | The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are... | Print the only integer t — the total time needed for Ayush to process all the orders. | null | Customer 1 wants the items 1 and 5.
pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
pos(1) = 3, so the new positi... | [{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}] | 1,400 | ["brute force"] | 10 | [{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99... | false | stdio | null | true |
82/B | 82 | B | PyPy 3-64 | TESTS | 32 | 186 | 7,577,600 | 196929606 | from copy import copy
from sys import stdin
n = int(stdin.readline())
previous = []
neigh_by_element = dict()
for i in range(n * (n - 1) // 2):
m = 0
arr = set()
for z, p in enumerate(map(int, stdin.readline().strip().split())):
if z == 0:
continue
arr.add(p)
for elem in ... | 34 | 248 | 7,577,600 | 196930821 | from copy import copy
from sys import stdin
n = int(stdin.readline())
if n == 2:
a, *arr = map(int, stdin.readline().strip().split())
first = arr[:len(arr) // 2]
second = arr[len(arr) // 2:]
print(len(first), *first)
print(len(second), *second)
exit()
neigh_by_element = dict()
for i in range(... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
367/A | 367 | A | Python 3 | TESTS | 2 | 61 | 307,200 | 103952039 | s=input()
xc=yc=zc=0
xlis,ylis,zlis=[0],[0],[0]
for i in s:
if i=='x':
xc+=1
elif i=='y':
yc+=1
else:
zc+=1
xlis.append(xc)
ylis.append(yc)
zlis.append(zc)
for __ in range(int(input())):
l,r=map(int,input().split())
xc=xlis[r]-xlis[l-1]
yc=ylis[r]-ylis[l-1]
... | 38 | 639 | 6,451,200 | 5250794 | import sys
s=sys.stdin.readline().split()[0]
m=int(sys.stdin.readline())
Numx=[]
Numy=[]
Numz=[]
x=0
y=0
z=0
for i in range(len(s)):
if(s[i]=='x'):
x+=1
if(s[i]=='y'):
y+=1
if(s[i]=='z'):
z+=1
Numx.append(x)
Numy.append(y)
Numz.append(z)
Ans=""
for M in range(m):
... | Codeforces Round 215 (Div. 1) | CF | 2,013 | 1 | 256 | Sereja and Algorithm | Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q1q2... qk. The algorithm consists of two steps:
1. Find any continuous subsequence (substring) of three characters of string q, which doesn'... | The first line contains non-empty string s, its length (n) doesn't exceed 105. It is guaranteed that string s only contains characters: 'x', 'y', 'z'.
The second line contains integer m (1 ≤ m ≤ 105) — the number of tests. Next m lines contain the tests. The i-th line contains a pair of integers li, ri (1 ≤ li ≤ ri ≤ ... | For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise. | null | In the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string "xzyx" on which the algorithm will terminate. In all other tests the algorithm doesn't work correctly. | [{"input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6", "output": "YES\nYES\nNO\nYES\nNO"}] | 1,500 | ["data structures", "implementation"] | 38 | [{"input": "zyxxxxxxyyz\r\n5\r\n5 5\r\n1 3\r\n1 11\r\n1 4\r\n3 6\r\n", "output": "YES\r\nYES\r\nNO\r\nYES\r\nNO\r\n"}, {"input": "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\r\n10\r\n17 67\r\n6 35\r\n12 45\r\n56 56\r\n14 30\r\n25 54\r\n1 1\r\n46 54\r\n3 33\r\n19 40\r\n", "output": "NO\r\nNO\r\n... | false | stdio | null | true |
639/A | 639 | A | Python 3 | PRETESTS | 7 | 1,278 | 15,462,400 | 16998331 | str1 = input().split()
n = int(str1[0])
k = int(str1[1])
q = int(str1[2])
friends = input().split()
online = set()
for i in range(q):
str1 = input().split()
if str1[0] == '2':
if int(str1[1]) in online:
print("YES")
else:
print("NO")
else:
online.add(int(str... | 44 | 265 | 20,480,000 | 188466426 | from sys import stdin; inp = stdin.readline
from math import dist, ceil, floor, sqrt, log
from collections import defaultdict, Counter
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): return float... | VK Cup 2016 - Round 1 | CF | 2,016 | 2 | 256 | Bear and Displayed Friends | Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is ... | The first line contains three integers n, k and q (1 ≤ n, q ≤ 150 000, 1 ≤ k ≤ min(6, n)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 109) where ti describes how good is Limak's relation w... | For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. | null | In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online.
2. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" — We should ... | [{"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3", "output": "NO\nYES\nNO\nYES\nYES"}, {"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3", "output": "NO\nYES\nNO\nYES"}] | 1,200 | ["implementation"] | 44 | [{"input": "4 2 8\r\n300 950 500 200\r\n1 3\r\n2 4\r\n2 3\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "6 3 9\r\n50 20 51 17 99 24\r\n1 3\r\n1 4\r\n1 5\r\n1 2\r\n2 4\r\n2 2\r\n1 1\r\n2 4\r\n2 3\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "6 3 10\r\n6241... | false | stdio | null | true |
665/B | 665 | B | PyPy 3 | TESTS | 3 | 280 | 6,656,000 | 59228344 | import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations
def li ():
return list (map (int, input ().split ()))
def num ():
return map (int, input ().split ())
def nu ():
return int (input ())
def... | 10 | 61 | 4,710,400 | 17420179 | def main():
n, m, k = map(int, input().split())
aa, t = list(map(int, input().split())), n * m * k
aa.reverse()
u, v, w = aa.index, aa.remove, aa.append
for _ in range(n):
for a in map(int, input().split()):
t -= u(a)
v(a)
w(a)
print(t)
if __name__ =... | Educational Codeforces Round 12 | ICPC | 2,016 | 1 | 256 | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the ... | The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are... | Print the only integer t — the total time needed for Ayush to process all the orders. | null | Customer 1 wants the items 1 and 5.
pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
pos(1) = 3, so the new positi... | [{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}] | 1,400 | ["brute force"] | 10 | [{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99... | false | stdio | null | true |
24/A | 24 | A | PyPy 3 | TESTS | 4 | 280 | 0 | 56988831 | n = int(input())
e = [ [] for i in range(n)]
e2 = {}
C = 0
for i in range(n):
a,b,c = map(int,input().split())
a-=1
b-=1
e[a].append((b,c))
e2[a] = (b,c)
e[b].append((a,c))
C += c
r = e[0][0]
l = e[0][1]
right = 0
left = 0
rr = [r[0]]
for i in range(n-1):
for node in e[r[0]]:
i... | 21 | 92 | 0 | 187852605 | n = int(input())
lst = []
for _ in range(n):
a, b, c = map(int, input().split())
lst.append([a,b,c])
pos1, pos2, f1, f2 = lst[0][1], lst[0][0], lst[0][0], lst[0][1]
sc1, sc2 = 0, lst[0][2]
del lst[0]
lst2 = lst*1
while pos1 != f1:
for x in range(len(lst)):
if lst[x][0] == pos1:
pos1 = l... | Codeforces Beta Round 24 | ICPC | 2,010 | 2 | 256 | Ring road | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot... | The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci. | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | null | null | [{"input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1"}, {"input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2"}, {"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39"}, {"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0"}] | 1,400 | ["graphs"] | 21 | [{"input": "3\r\n1 3 1\r\n1 2 1\r\n3 2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n1 2 5\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n1 5 4\r\n5 3 8\r\n2 4 15\r\n1 6 16\r\n2 3 23\r\n4 6 42\r\n", "output": "39\r\n"}, {"input": "4\r\n1 2 9\r\n2 3 8\r\n3 4 7\r\n4 1 5\r\n", "output": "0\r\n"}, {"input": "5\r... | false | stdio | null | true |
24/A | 24 | A | PyPy 3-64 | TESTS | 4 | 124 | 0 | 225896932 | n = int(input())
sl,el,c1,c2 = [],[],0,0
for i in range(n):
s,e,c = map(int,input().split())
if s not in sl and e not in el:
sl.append(s)
el.append(e)
c1 += c
else:
c2 += c
print(min(c1,c2)) | 21 | 92 | 0 | 203666447 | def main():
n = int(input())
road_cost = {}
road_dict = {i: [] for i in range(1, n + 1)}
total_cost = 0
for _ in range(n):
ai, bi, ci = map(int, input().split())
road_dict[ai].append(bi)
road_dict[bi].append(ai)
road_cost[(ai, bi)] = ci
total_cost += ci
c... | Codeforces Beta Round 24 | ICPC | 2,010 | 2 | 256 | Ring road | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot... | The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci. | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | null | null | [{"input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1"}, {"input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2"}, {"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39"}, {"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0"}] | 1,400 | ["graphs"] | 21 | [{"input": "3\r\n1 3 1\r\n1 2 1\r\n3 2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n1 2 5\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n1 5 4\r\n5 3 8\r\n2 4 15\r\n1 6 16\r\n2 3 23\r\n4 6 42\r\n", "output": "39\r\n"}, {"input": "4\r\n1 2 9\r\n2 3 8\r\n3 4 7\r\n4 1 5\r\n", "output": "0\r\n"}, {"input": "5\r... | false | stdio | null | true |
837/G | 837 | G | PyPy 3-64 | TESTS | 9 | 1,403 | 42,905,600 | 198697694 | import bisect
import heapq
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
m = 333
s = [0] * (2 * n)
x0, c1, c2, c3 = [], [], [], []
for i in range(n):
x1, x2, y1, a, b, y2 = map(int, input().split())
s[2 * i], s[2 * i + 1] = x1, x2
x0.append((x1, x2))
c... | 25 | 2,917 | 232,038,400 | 227942774 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_segment(s, t):
s, t = s + l1, t + l1
ans = []
while s <= t:
if s & 1:
ans.append(s)
s += 1
s >>= 1
if not t & 1:
ans.append(t)
t -= 1
t >>=... | Educational Codeforces Round 26 | ICPC | 2,017 | 5 | 1,024 | Functions On The Segments | You have an array f of n functions.The function fi(x) (1 ≤ i ≤ n) is characterized by parameters: x1, x2, y1, a, b, y2 and take values:
- y1, if x ≤ x1.
- a·x + b, if x1 < x ≤ x2.
- y2, if x > x2.
There are m queries. Each query is determined by numbers l, r and x. For a query with number i (1 ≤ i ≤ m), you need to c... | First line contains one integer number n (1 ≤ n ≤ 75000).
Each of the next n lines contains six integer numbers: x1, x2, y1, a, b, y2 (0 ≤ x1 < x2 ≤ 2·105, 0 ≤ y1, y2 ≤ 109, 0 ≤ a, b ≤ 104).
Next line contains one integer number m (1 ≤ m ≤ 500000).
Each of the next m lines contains three integer numbers: l, r and x ... | null | null | null | [{"input": "1\n1 2 1 4 5 10\n1\n1 1 2", "output": "13"}, {"input": "3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5", "output": "19\n17\n11"}] | 2,500 | ["data structures"] | 25 | [{"input": "1\r\n1 2 1 4 5 10\r\n1\r\n1 1 2\r\n", "output": "13\r\n"}, {"input": "3\r\n2 5 1 1 1 4\r\n3 6 8 2 5 7\r\n1 3 5 1 4 10\r\n3\r\n1 3 3\r\n2 3 2\r\n1 2 5\r\n", "output": "19\r\n17\r\n11\r\n"}, {"input": "7\r\n4 8 562244866 6 8 140807945\r\n5 7 415374420 7 6 596093578\r\n3 4 766370993 3 7 973128805\r\n4 6 841321... | false | stdio | null | true |
843/A | 843 | A | Python 3 | TESTS | 2 | 30 | 0 | 195043692 | n = int(input())
a = list(map(int, input().split()))
sorted_a = sorted(a)
ind = 0
num = a[0]
ans = []
k = 0 if a[0] == sorted_a[0] else 1
for i in range(1, n):
num = max(a[ind:i + 1])
k += 1 if a[i] != sorted_a[i] else 0
if sorted_a[i] == num and ind != i:
ans.append([k, ind + 1, i + 1])
fo... | 71 | 389 | 44,441,600 | 129813603 | import io
import os
import sys
class UnionFind:
def __init__(self, n):
self.cnt = n
self.par = list(range(n))
self.ext = [1] * (n)
def find(self, u):
while u != self.par[u]:
u = self.par[u]
return u
def unite(self, u, v):
u, v = self.find(u)... | AIM Tech Round 4 (Div. 1) | CF | 2,017 | 1 | 256 | Sorting by Subsequences | You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a subsequence is... | The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence.
The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct. | In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements.
In the next k lines print the description of subsequences in the following format: the number of elements in subsequence ci (0 < ci ≤ n), then ci integers l1, l2, ..., lci (1 ≤... | null | In the first sample output:
After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
Sorting the second subsequence changes nothing.
After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
Sorting the last subsequence changes nothing. | [{"input": "6\n3 2 1 6 5 4", "output": "4\n2 1 3\n1 2\n2 4 6\n1 5"}, {"input": "6\n83 -75 -49 11 37 62", "output": "1\n6 1 2 3 4 5 6"}] | 1,400 | ["dfs and similar", "dsu", "implementation", "math", "sortings"] | 71 | [{"input": "6\r\n3 2 1 6 5 4\r\n", "output": "4\r\n2 1 3\r\n1 2\r\n2 4 6\r\n1 5\r\n"}, {"input": "6\r\n83 -75 -49 11 37 62\r\n", "output": "1\r\n6 1 2 3 4 5 6\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 1\r\n1 2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n2... | false | stdio | import sys
from collections import defaultdict
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
sorted_a = sorted(a)
pos_in_sorted = {v: i+1 f... | true |
24/A | 24 | A | PyPy 3 | TESTS | 4 | 248 | 0 | 95306811 | arr = {}
arr2 = {}
cost = 0
cost2 = 0
n = int(input())
for _ in range(n):
a, b, c = list(map(int, input().split()))
cost2 += c
if a in arr:
arr[a].append(b)
else:
arr[a] = [b]
arr2[a, b] = c
#print(arr)
#print(arr2)
count = 0
for k in arr:
if len(arr[k]) > 1:
for kk in ar... | 21 | 92 | 0 | 216797067 | n=int(input())
ar=[]
br=[]
p,y=0,0
for _ in range(n):
a,b,c=map(int,input().split())
if (a in ar or b in br):
a,b=b,a
y+=c
p+=c
ar.append(a)
br.append(b)
print(min(y,p-y)) | Codeforces Beta Round 24 | ICPC | 2,010 | 2 | 256 | Ring road | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot... | The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci. | Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. | null | null | [{"input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1"}, {"input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2"}, {"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39"}, {"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0"}] | 1,400 | ["graphs"] | 21 | [{"input": "3\r\n1 3 1\r\n1 2 1\r\n3 2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n1 2 5\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n1 5 4\r\n5 3 8\r\n2 4 15\r\n1 6 16\r\n2 3 23\r\n4 6 42\r\n", "output": "39\r\n"}, {"input": "4\r\n1 2 9\r\n2 3 8\r\n3 4 7\r\n4 1 5\r\n", "output": "0\r\n"}, {"input": "5\r... | false | stdio | null | true |
43/E | 43 | E | PyPy 3-64 | TESTS | 2 | 186 | 70,451,200 | 153601015 | # @Chukamin ICPC_TRAIN
def main():
n, s = map(int, input().split())
Nnum = 0
func = [[0 for i in range(40010)] for j in range(210)]
for i in range(1, n + 1):
data = list(map(int, input().split()))
j = 0
cnt = data[0]
for _ in range(cnt):
v = data[_ * 2 + 1]
... | 48 | 716 | 8,396,800 | 216866689 | import sys
readline = sys.stdin.readline
N, S = 0, 0
cars = []
# input
def read():
global N, S
N, S = list(map(int, readline().split()))
for i in range(N):
nums = list(map(int, readline().split()))
cars.append([])
carid = len(cars)
t0 = 0
for i in range(1, len(num... | Codeforces Beta Round 42 (Div. 2) | CF | 2,010 | 2 | 256 | Race | Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is known its behavior — the system of segments on each of which the s... | The first line contains two integers n and s (2 ≤ n ≤ 100, 1 ≤ s ≤ 106) — the number of cars and the length of the track in kilometers. Then follow n lines — the description of the system of segments for each car. Every description starts with integer k (1 ≤ k ≤ 100) — the number of segments in the system. Then k space... | Print the single number — the number of times some car managed to take the lead over another car during the race. | null | null | [{"input": "2 33\n2 5 1 2 14\n1 3 11", "output": "1"}, {"input": "2 33\n2 1 3 10 3\n1 11 3", "output": "0"}, {"input": "5 33\n2 1 3 3 10\n1 11 3\n2 5 3 3 6\n2 3 1 10 3\n2 6 3 3 5", "output": "2"}] | 2,300 | ["brute force", "implementation", "two pointers"] | 48 | [{"input": "2 33\r\n2 5 1 2 14\r\n1 3 11\r\n", "output": "1\r\n"}, {"input": "2 33\r\n2 1 3 10 3\r\n1 11 3\r\n", "output": "0\r\n"}, {"input": "5 33\r\n2 1 3 3 10\r\n1 11 3\r\n2 5 3 3 6\r\n2 3 1 10 3\r\n2 6 3 3 5\r\n", "output": "2\r\n"}, {"input": "2 166755\r\n2 733 187 362 82\r\n3 813 147 565 57 557 27\r\n", "output"... | false | stdio | null | true |
653/F | 653 | F | PyPy 3-64 | TESTS | 2 | 62 | 1,126,400 | 189179950 | import sys, random
input = lambda : sys.stdin.readline().rstrip()
write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split()));... | 68 | 904 | 55,910,400 | 169979803 | import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def suffix_array(s):
l = len(s)
x = [[] for _ in range(222)]
for i in range(l):
x[s[i]].append(i)
y = []
z = [0]
for x0 in x:
for i in x0:
y.append(i)
z.append(len(y... | IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) | CF | 2,016 | 3 | 512 | Paper task | Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time.
For the purpose of this problem we consider only strings cons... | The first line of the input contains an integer n (1 ≤ n ≤ 500 000) — the length of the string s.
The second line contains a string s of length n consisting of only '(' and ')'. | Print the number of distinct non-empty correct sequences that occur in s as substring. | null | In the first sample, there are 5 distinct substrings we should count: "()", "()()", "()()()", "()()()()" and "()()()()()".
In the second sample, there are 3 distinct substrings we should count: "()", "(())" and "(())()". | [{"input": "10\n()()()()()", "output": "5"}, {"input": "7\n)(())()", "output": "3"}] | 2,600 | ["data structures", "string suffix structures", "strings"] | 68 | [{"input": "10\r\n()()()()()\r\n", "output": "5\r\n"}, {"input": "7\r\n)(())()\r\n", "output": "3\r\n"}, {"input": "1\r\n(\r\n", "output": "0\r\n"}, {"input": "2\r\n))\r\n", "output": "0\r\n"}, {"input": "15\r\n(())(()())(()()\r\n", "output": "5\r\n"}, {"input": "30\r\n()(())(())(())()(())()()()(()(\r\n", "output": "34... | false | stdio | null | true |
652/F | 652 | F | PyPy 3 | TESTS | 3 | 77 | 0 | 198407499 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m, t = map(int, input().split())
j = 0
p, q = [], []
for i in range(n):
s, d = input().rstrip().decode().split()
s = int(s) % m
x = 2 * s + 1
p.append(s * n + i)
if d == "R":
q.append((s + t) % m)
u =... | 30 | 1,076 | 40,243,200 | 181254094 | import sys
input = sys.stdin.readline
n, m, t = [int(i) for i in input().split()]
a, b, ans, cnt = [0]*n, [0]*n, [0]*n, 0
for i in range(n):
x, ch = input().split()
a[i] = int(x) - 1
b[i] = (a[i], i)
dr = 1 if ch == "R" else -1
w, u = divmod(a[i] + t * dr, m)
a[i], cnt = u, cnt +... | Educational Codeforces Round 10 | ICPC | 2,016 | 2 | 256 | Ants on a Circle | n ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the all ants are dis... | The first line contains three integers n, m and t (2 ≤ n ≤ 3·105, 2 ≤ m ≤ 109, 0 ≤ t ≤ 1018) — the number of ants, the length of the circle and the number of time units.
Each of the next n lines contains integer si and symbol di (1 ≤ si ≤ m and di is either L or R) — the position and the direction of the i-th ant at t... | Print n integers xj — the position of the j-th ant after t units of time. The ants are numbered from 1 to n in order of their appearing in input. | null | null | [{"input": "2 4 8\n1 R\n3 L", "output": "1 3"}, {"input": "4 8 6\n6 R\n5 L\n1 R\n8 L", "output": "7 4 2 7"}, {"input": "4 8 2\n1 R\n5 L\n6 L\n8 R", "output": "3 3 4 2"}] | 2,800 | ["constructive algorithms", "math"] | 30 | [{"input": "2 4 8\r\n1 R\r\n3 L\r\n", "output": "1 3\r\n"}, {"input": "4 8 6\r\n6 R\r\n5 L\r\n1 R\r\n8 L\r\n", "output": "7 4 2 7\r\n"}, {"input": "4 8 2\r\n1 R\r\n5 L\r\n6 L\r\n8 R\r\n", "output": "3 3 4 2\r\n"}, {"input": "10 10 90\r\n2 R\r\n1 R\r\n3 L\r\n4 R\r\n7 L\r\n8 L\r\n6 R\r\n9 R\r\n5 R\r\n10 L\r\n", "output":... | false | stdio | null | true |
583/A | 583 | A | Python 3 | TESTS | 3 | 46 | 0 | 201876395 | n = int(input())
ar = []
ans = []
for i in range(n * n):
x, y = map(int, input().split())
if x not in ar and y not in ar:
ans += [i + 1]
ar += [x, y]
print(*ans) | 39 | 46 | 0 | 177339118 | import os,sys,io,math
from array import array
from math import *
I=lambda:[*map(int,sys.stdin.readline().split())]
IS=lambda:input()
IN=lambda:int(input())
IF=lambda:float(input())
n=IN()
a,b,c=[0]*n,[0]*n,[]
for i in range(n**2):
h,v=map(int,input().split())
if a[h-1]==0 and b[v-1]==0:
c.append(i+1)
... | Codeforces Round 323 (Div. 2) | CF | 2,015 | 1 | 256 | Asphalting Roads | City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was made to asphal... | The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city.
Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timeta... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | null | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road;
2. On the second day the brigade of the workers comes to the int... | [{"input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4"}, {"input": "1\n1 1", "output": "1"}] | 1,000 | ["implementation"] | 39 | [{"input": "2\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "1 4 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 \r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n1 2\r\n2 1\r\n", "output": "1 2 \r\n"}, {"input": "2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n", "output": "1 3 \r\n"}, {"input": "3\r\n2 2\r\n1 2\r\n3 2\r\n3 3\r\n1 1\r\n2 3\r\n1 3\... | false | stdio | null | true |
364/D | 364 | D | PyPy 3 | TESTS | 2 | 3,556 | 125,030,400 | 71102642 | from typing import List
from random import randrange
from sys import stdin
from functools import reduce
def read_integers():
return list(map(int, stdin.readline().strip().split()))
def decompose(n):
return sorted(set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i... | 115 | 3,900 | 133,734,400 | 179459001 | import math
from random import randint
from bisect import bisect_left
test = False
if test:
n = randint(100000,100000)
a = [randint(1,100000000) for _ in range(n)]
#print('n =', n)
#print('a =', a)
else:
n = int(input())
a=[*map(int,input().split())]
dr = 1
for x in range(9):
... | Codeforces Round 213 (Div. 1) | CF | 2,013 | 4 | 256 | Ghd | John Doe offered his sister Jane Doe find the gcd of some set of numbers a.
Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisible by g'.
Unfortunately Jane couldn't cope with the task and John offered... | The first line contains an integer n (1 ≤ n ≤ 106) showing how many numbers are in set a. The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1012). Please note, that given set can contain equal numbers.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is pref... | Print a single integer g — the Ghd of set a. | null | null | [{"input": "6\n6 2 3 4 5 6", "output": "3"}, {"input": "5\n5 5 6 10 15", "output": "5"}] | 2,900 | ["brute force", "math", "probabilities"] | 115 | [{"input": "6\r\n6 2 3 4 5 6\r\n", "output": "3\r\n"}, {"input": "5\r\n5 5 6 10 15\r\n", "output": "5\r\n"}, {"input": "100\r\n32 40 7 3 7560 21 7560 7560 10 12 3 7560 7560 7560 7560 5 7560 7560 6 7560 7560 7560 35 7560 18 7560 7560 7560 7560 7560 48 2 7 25 7560 2 2 49 7560 7560 15 16 7560 7560 2 7560 27 7560 7560 7560... | false | stdio | null | true |
831/B | 831 | B | Python 3 | TESTS | 2 | 30 | 0 | 136741375 | c1 = list(input())
c2 = list(input())
c3 = list(input())
c4 = list()
c5 = list()
for i in range(len(c3)):
if 64 < ord(c3[i]) < 91:
c4.append(i)
c3 = [x.lower() for x in c3 if isinstance(x,str)]
a = len(c3)
for i in range(a):
n = 0
for b in range(len(c1)):
if c3[i] == c1[b]:
c5.ap... | 19 | 31 | 0 | 144988702 | p1 = input()
p2=input()
s = input()
res = ''
for i in s:
if(i.lower() in p1):
l= p2[p1.index(i.lower())]
if(i.isupper()):
res+=l.upper()
else:
res+=l
else:
res+=i
print(res) | Codeforces Round 424 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Keyboard Layouts | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string s consisting of lowercase and... | Print the text if the same keys were pressed in the second layout. | null | null | [{"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "output": "HelloVKCup2017"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "output": "7uduGUDUUDUgudu7"}] | 800 | ["implementation", "strings"] | 19 | [{"input": "qwertyuiopasdfghjklzxcvbnm\r\nveamhjsgqocnrbfxdtwkylupzi\r\nTwccpQZAvb2017\r\n", "output": "HelloVKCup2017\r\n"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\r\nasdfghjklqwertyuiopzxcvbnm\r\n7abaCABAABAcaba7\r\n", "output": "7uduGUDUUDUgudu7\r\n"}, {"input": "ayvguplhjsoiencbkxdrfwmqtz\r\nkhzvtbspcndierqumlojyagf... | false | stdio | null | true |
65/C | 65 | C | Python 3 | TESTS | 0 | 60 | 102,400 | 217458268 | import math
import sys
eps = 1e-8
n = int(input())
al = [list(map(int, input().split())) for _ in range(n + 1)]
vp, vs = map(int, input().split())
px, py, pz = p0 = map(int, input().split())
al = [(x - px, y - py, z - pz) for x, y, z in al]
d3 = lambda x, y, z: x * x + y * y + z * z
t0, ts = 0, 0
rt = None
for i in ... | 45 | 248 | 3,891,200 | 217460027 | import math, sys
eps = 1e-8
n = int(input())
al = [list(map(int, input().split())) for _ in range(n + 1)]
vp, vs = map(int, input().split())
px, py, pz = map(int, input().split())
al = [(x - px, y - py, z - pz) for x, y, z in al]
d3 = lambda x, y, z: x*x + y*y + z*z
t0 = 0
rt, pt = None, 0
ts = 0
def tsol(t)... | Codeforces Beta Round 60 | CF | 2,011 | 2 | 256 | Harry Potter and the Golden Snitch | Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at... | The first line contains a single integer n (1 ≤ n ≤ 10000). The following n + 1 lines contain the coordinates xi, yi, zi, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities vp and vs, the last line contains Px, Py, Pz, separated by single spa... | If Harry Potter can catch the snitch while it is moving along the polyline (including the end (xn, yn, zn)), print "YES" in the first line (without the quotes). Print in the second line t, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers X, Y, Z, t... | null | null | [{"input": "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "output": "YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000"}, {"input": "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "output": "NO"}, {"input": "1\n1 2 3\n4 5 6\n20 10\n1 2 3", "output": "YES\n0.0000000000\n1.0000000000 2.000000... | 2,100 | ["binary search", "geometry"] | 45 | [{"input": "4\r\n0 0 0\r\n0 10 0\r\n10 10 0\r\n10 0 0\r\n0 0 0\r\n1 1\r\n5 5 25\r\n", "output": "YES\r\n25.5000000000\r\n10.0000000000 4.5000000000 0.0000000000\r\n"}, {"input": "4\r\n0 0 0\r\n0 10 0\r\n10 10 0\r\n10 0 0\r\n0 0 0\r\n1 1\r\n5 5 50\r\n", "output": "NO\r\n"}, {"input": "1\r\n1 2 3\r\n4 5 6\r\n20 10\r\n1 2... | false | stdio | import sys
import math
def read_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]
ref_lines = read_lines(output_path)
sub_lines = read_lines(submission_pa... | true |
65/C | 65 | C | Python 3 | TESTS | 0 | 62 | 102,400 | 217457935 | import sys
eps = 1e-8
n = int(input())
al = [list(map(int, input().split())) for _ in range(n+1)]
vp, vs = map(int, input().split())
px, py, pz = p0 = map(int, input().split())
al = [(x-px, y-py, z-pz) for x, y, z in al]
d3 = lambda x, y, z: x*x + y*y + z*z
t0, ts = 0, 0
rt = None
for i in range(n):
c = [... | 45 | 248 | 3,891,200 | 217460027 | import math, sys
eps = 1e-8
n = int(input())
al = [list(map(int, input().split())) for _ in range(n + 1)]
vp, vs = map(int, input().split())
px, py, pz = map(int, input().split())
al = [(x - px, y - py, z - pz) for x, y, z in al]
d3 = lambda x, y, z: x*x + y*y + z*z
t0 = 0
rt, pt = None, 0
ts = 0
def tsol(t)... | Codeforces Beta Round 60 | CF | 2,011 | 2 | 256 | Harry Potter and the Golden Snitch | Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at... | The first line contains a single integer n (1 ≤ n ≤ 10000). The following n + 1 lines contain the coordinates xi, yi, zi, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities vp and vs, the last line contains Px, Py, Pz, separated by single spa... | If Harry Potter can catch the snitch while it is moving along the polyline (including the end (xn, yn, zn)), print "YES" in the first line (without the quotes). Print in the second line t, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers X, Y, Z, t... | null | null | [{"input": "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "output": "YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000"}, {"input": "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "output": "NO"}, {"input": "1\n1 2 3\n4 5 6\n20 10\n1 2 3", "output": "YES\n0.0000000000\n1.0000000000 2.000000... | 2,100 | ["binary search", "geometry"] | 45 | [{"input": "4\r\n0 0 0\r\n0 10 0\r\n10 10 0\r\n10 0 0\r\n0 0 0\r\n1 1\r\n5 5 25\r\n", "output": "YES\r\n25.5000000000\r\n10.0000000000 4.5000000000 0.0000000000\r\n"}, {"input": "4\r\n0 0 0\r\n0 10 0\r\n10 10 0\r\n10 0 0\r\n0 0 0\r\n1 1\r\n5 5 50\r\n", "output": "NO\r\n"}, {"input": "1\r\n1 2 3\r\n4 5 6\r\n20 10\r\n1 2... | false | stdio | import sys
import math
def read_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]
ref_lines = read_lines(output_path)
sub_lines = read_lines(submission_pa... | true |
30/C | 30 | C | PyPy 3 | TESTS | 5 | 186 | 0 | 140566719 | def r(x1, y1, x2, y2):
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
n = int(input())
f = [[] for i in range(n)]
for i in range(n):
x, y, t, p = map(float, input().split())
f[i] = [x, y, t, p]
f.sort(key=lambda x: x[0])
dp = [f[i][3] for i in range(n)]
for i in range(1, n):
for j in range(0, i)... | 50 | 466 | 2,150,400 | 117763382 | n=int(input())
b=[]
for i in range(n):
x,y,t,p=map(float,input().split())
b.append([t,x,y,p])
b.sort()
dp=[0 for j in range(n)]
dp[0]=b[0][3]
ans=0
for i in range(1,n):
t,x,y,p=b[i]
j=i-1
while(j>=0):
t1,x1,y1,p1=b[j]
if ((x1-x)**2+(y1-y)**2)**0.5<=(t-t1):
dp[i]=max(dp[... | Codeforces Beta Round 30 (Codeforces format) | CF | 2,010 | 2 | 256 | Shooting Gallery | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.
The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ... | The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers, - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits ... | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6. | null | null | [{"input": "1\n0 0 0 0.5", "output": "0.5000000000"}, {"input": "2\n0 0 0 0.6\n5 0 5 0.7", "output": "1.3000000000"}] | 1,800 | ["dp", "probabilities"] | 50 | [{"input": "1\r\n0 0 0 0.5\r\n", "output": "0.5000000000\r\n"}, {"input": "2\r\n0 0 0 0.6\r\n5 0 5 0.7\r\n", "output": "1.3000000000\r\n"}, {"input": "1\r\n-5 2 3 0.886986\r\n", "output": "0.8869860000\r\n"}, {"input": "4\r\n10 -7 14 0.926305\r\n-7 -8 12 0.121809\r\n-7 7 14 0.413446\r\n3 -8 6 0.859061\r\n", "output": "... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
correct_line = f.readline().strip()
try:
correct = float(correct_line)
except:
print(0)
return
with... | true |
30/C | 30 | C | PyPy 3 | TESTS | 5 | 248 | 0 | 61558376 | if __name__ == '__main__':
n = int(input())
targets = [input() for _ in range(n)]
targets = [line.split() for line in targets]
targets = [(int(x), int(y), int(t), float(p)) for x, y, t, p in targets]
targets = sorted(targets, key=lambda x: x[2])
max_scores = [0] * n
for i in range(n - 1, -... | 50 | 684 | 2,662,400 | 168603661 | n=int(input())
class Target:
def __init__(self,x,y,t,p):
self.x=x
self.y=y
self.t=t
self.p=p
self.best=0
targets=[0]*(n)
for i in range(n):
p=[el for el in input().split()]
targets[i]=Target(int(p[0]),int(p[1]),int(p[2]),float(p[3]))
targets.sort(key=lambda x:(x.t))
b... | Codeforces Beta Round 30 (Codeforces format) | CF | 2,010 | 2 | 256 | Shooting Gallery | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.
The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ... | The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers, - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits ... | Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6. | null | null | [{"input": "1\n0 0 0 0.5", "output": "0.5000000000"}, {"input": "2\n0 0 0 0.6\n5 0 5 0.7", "output": "1.3000000000"}] | 1,800 | ["dp", "probabilities"] | 50 | [{"input": "1\r\n0 0 0 0.5\r\n", "output": "0.5000000000\r\n"}, {"input": "2\r\n0 0 0 0.6\r\n5 0 5 0.7\r\n", "output": "1.3000000000\r\n"}, {"input": "1\r\n-5 2 3 0.886986\r\n", "output": "0.8869860000\r\n"}, {"input": "4\r\n10 -7 14 0.926305\r\n-7 -8 12 0.121809\r\n-7 7 14 0.413446\r\n3 -8 6 0.859061\r\n", "output": "... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
correct_line = f.readline().strip()
try:
correct = float(correct_line)
except:
print(0)
return
with... | true |
1000/D | 1000 | D | PyPy 3-64 | TESTS | 2 | 77 | 3,584,000 | 148239548 | def fact(be, en):
res, res2 = [1], [1]
for i in range(be, en + 1):
res.append(mult(res[-1], i))
res2.append(inv(res[-1]))
return res, res2
def ncr(n, r):
if n < r:
return 0
return mult(mult(facs[n], invs[n - r]), invs[r])
mod = 998244353
add = lambda a, b: (a % mod + b % ... | 22 | 124 | 6,246,400 | 169757071 | N = 10**5
mod = 998244353
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
finv[i] = finv[i+1] * (i+1) % mod
def cmb1(n, r):
if r <0 or r > n:
return 0
r = min(r, n-r)
return fac[n] * finv[r]... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Yet Another Problem On a Subsequence | The sequence of integers $$$a_1, a_2, \dots, a_k$$$ is called a good array if $$$a_1 = k - 1$$$ and $$$a_1 > 0$$$. For example, the sequences $$$[3, -1, 44, 0], [1, -99]$$$ are good arrays, and the sequences $$$[3, 7, 8], [2, 5, 4, 1], [0]$$$ — are not.
A sequence of integers is called good if it can be divided into a... | The first line contains the number $$$n~(1 \le n \le 10^3)$$$ — the length of the initial sequence. The following line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n~(-10^9 \le a_i \le 10^9)$$$ — the sequence itself. | In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353. | null | In the first test case, two good subsequences — $$$[a_1, a_2, a_3]$$$ and $$$[a_2, a_3]$$$.
In the second test case, seven good subsequences — $$$[a_1, a_2, a_3, a_4], [a_1, a_2], [a_1, a_3], [a_1, a_4], [a_2, a_3], [a_2, a_4]$$$ and $$$[a_3, a_4]$$$. | [{"input": "3\n2 1 1", "output": "2"}, {"input": "4\n1 1 1 1", "output": "7"}] | 1,900 | ["combinatorics", "dp"] | 22 | [{"input": "3\r\n2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "7\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}] | false | stdio | null | true |
1000/D | 1000 | D | PyPy 3-64 | TESTS | 2 | 1,388 | 10,035,200 | 188233846 | def Fact(N):
global factorials
return factorials[N]
def C(N, K):
global mod
f1, f2, f3 = Fact(N), Fact(K), Fact(N - K)
return (f1 * pow((f2 * f3) % mod, mod - 2, mod)) % mod
n = int(input())
a = list(map(int, input().split()))
mod = 998244353
pref, zero, dp, factorials = [0] * (n + 1), [0] * (n ... | 22 | 171 | 4,300,800 | 193699512 | from heapq import heappush, heappop
from collections import defaultdict, Counter, deque
import threading
import sys
import bisect
input = sys.stdin.readline
def ri(): return int(input())
def rs(): return input()
def rl(): return list(map(int, input().split()))
def rls(): return list(input().split())
# threading.stack... | Educational Codeforces Round 46 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Yet Another Problem On a Subsequence | The sequence of integers $$$a_1, a_2, \dots, a_k$$$ is called a good array if $$$a_1 = k - 1$$$ and $$$a_1 > 0$$$. For example, the sequences $$$[3, -1, 44, 0], [1, -99]$$$ are good arrays, and the sequences $$$[3, 7, 8], [2, 5, 4, 1], [0]$$$ — are not.
A sequence of integers is called good if it can be divided into a... | The first line contains the number $$$n~(1 \le n \le 10^3)$$$ — the length of the initial sequence. The following line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n~(-10^9 \le a_i \le 10^9)$$$ — the sequence itself. | In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353. | null | In the first test case, two good subsequences — $$$[a_1, a_2, a_3]$$$ and $$$[a_2, a_3]$$$.
In the second test case, seven good subsequences — $$$[a_1, a_2, a_3, a_4], [a_1, a_2], [a_1, a_3], [a_1, a_4], [a_2, a_3], [a_2, a_4]$$$ and $$$[a_3, a_4]$$$. | [{"input": "3\n2 1 1", "output": "2"}, {"input": "4\n1 1 1 1", "output": "7"}] | 1,900 | ["combinatorics", "dp"] | 22 | [{"input": "3\r\n2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "7\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}] | false | stdio | null | true |
990/F | 990 | F | Python 3 | TESTS | 1 | 62 | 0 | 39187965 | def i_ints():
return list(map(int, input().split()))
#############
n, = i_ints()
s = [0] + i_ints()
m, = i_ints()
vs = [i_ints() for _ in range(m)]
used_pipe = [0] * (n + 1) # 0 is dummy pipe to have x, y be indices into array
unseen = set(range(1, n+1))
for i, (x, y) in enumerate(vs):
if x in unseen:
... | 37 | 1,388 | 80,486,400 | 39209819 | import sys
from time import time
def i_ints():
return list(map(int, sys.stdin.readline().split()))
def main():
limit =10**10
n, = i_ints()
s = [0] + i_ints()
if sum(s):
print("Impossible")
return
print("Possible")
m, = i_ints()
es = [i_ints() for _ in range(m)]
n... | Educational Codeforces Round 45 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Flow Control | You have to handle a very complex water distribution system. The system consists of $$$n$$$ junctions and $$$m$$$ pipes, $$$i$$$-th pipe connects junctions $$$x_i$$$ and $$$y_i$$$.
The only thing you can do is adjusting the pipes. You have to choose $$$m$$$ integer numbers $$$f_1$$$, $$$f_2$$$, ..., $$$f_m$$$ and use ... | The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of junctions.
The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$-10^4 \le s_i \le 10^4$$$) — constraints for the junctions.
The third line contains an integer $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) — the ... | If you can choose such integer numbers $$$f_1, f_2, \dots, f_m$$$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $$$m$$$ lines, $$$i$$$-th line should contain $$$f_i$$$ — the chosen setting numbers for the pipes. Pipes are numbere... | null | null | [{"input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Possible\n4\n-6\n8\n-7\n7"}, {"input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Impossible"}] | 2,400 | ["dfs and similar", "dp", "greedy", "trees"] | 37 | [{"input": "4\r\n3 -10 6 1\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Possible\r\n-3\r\n-6\r\n1\r\n0\r\n0\r\n"}, {"input": "4\r\n3 -10 6 4\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n0\r\n0\r\n", "output": "Possible\r\n"}, {"input": "1\r\n123\r\n0\r\n", "outp... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline())
s = list(map(int, f.readline().split()))
m = int(f.readline())
pipes = [tuple(map(int, f.readline().split())) for _ in range(m)]
sum_s = ... | true |
786/B | 786 | B | Python 3 | TESTS | 3 | 61 | 4,915,200 | 25805460 | plans = []
helpl = []
matrix = []
minprice = []
now = 0
res = ''
(n,q,se) = map(int,input().split())
for i in range(0,q):
s = input().split()
helpl = [int(c) for c in s]
plans.append([])
for j in range(0,len(helpl)):
plans[i].append(helpl[j])
for i in range(0,n):
matrix.append([])
for j in range(0,n):
matrix[... | 49 | 1,981 | 182,374,400 | 205981387 | from sys import stdin
input=lambda :stdin.readline()[:-1]
from heapq import heappush, heappop
INF=10**18
def dijkstra(start,n):
dist=[INF]*n
hq=[(0,start)]
dist[start]=0
seen=[False]*n
while hq:
w,v=heappop(hq)
if dist[v]<w:
continue
seen[v]=True
for to,cost in edge[v]:
if seen[to... | Codeforces Round 406 (Div. 1) | CF | 2,017 | 2 | 256 | Legacy | Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.
There are n planets in their universe numbered from 1 to n. Rick is in planet number s (the earth) and he doesn't know where Morty is. As we all know, ... | The first line of input contains three integers n, q and s (1 ≤ n, q ≤ 105, 1 ≤ s ≤ n) — number of planets, number of plans and index of earth respectively.
The next q lines contain the plans. Each line starts with a number t, type of that plan (1 ≤ t ≤ 3). If t = 1 then it is followed by three integers v, u and w whe... | In the first and only line of output print n integers separated by spaces. i-th of them should be minimum money to get from earth to i-th planet, or - 1 if it's impossible to get to that planet. | null | In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2. | [{"input": "3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17", "output": "0 28 12"}, {"input": "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16", "output": "0 -1 -1 12"}] | 2,300 | ["data structures", "graphs", "shortest paths"] | 49 | [{"input": "3 5 1\r\n2 3 2 3 17\r\n2 3 2 2 16\r\n2 2 2 3 3\r\n3 3 1 1 12\r\n1 3 3 17\r\n", "output": "0 28 12 \r\n"}, {"input": "4 3 1\r\n3 4 1 3 12\r\n2 2 3 4 10\r\n1 2 4 16\r\n", "output": "0 -1 -1 12 \r\n"}, {"input": "6 1 5\r\n1 3 6 80612370\r\n", "output": "-1 -1 -1 -1 0 -1 \r\n"}, {"input": "10 8 7\r\n1 10 7 3666... | false | stdio | null | true |
226/D | 226 | D | PyPy 3 | TESTS | 3 | 278 | 0 | 84116366 | import math
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(n):
a[i] = [int(_) for _ in input().split()]
row = []
col = []
while True:
bad = False
for i in range(n):
total = 0
for j in range(m):
total += a[i][j]
... | 95 | 372 | 2,048,000 | 84116428 | import math
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(n):
a[i] = [int(_) for _ in input().split()]
row = []
col = []
rowStat = [1] * n
colStat = [1] * m
while True:
bad = False
for i in range(n):
total = 0
for j in range(... | Codeforces Round 140 (Div. 1) | CF | 2,012 | 2 | 256 | The table | Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negative the ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of rows and the number of columns.
Next n lines follow, each contains m integers: j-th integer in the i-th line is ai, j (|ai, j| ≤ 100), the number in the i-th row and j-th column of the table.
The rows of the table numbered from 1 to n. The... | In the first line print the number a — the number of required applications of the first spell. Next print a space-separated integers — the row numbers, you want to apply a spell. These row numbers must be distinct!
In the second line print the number b — the number of required applications of the second spell. Next pr... | null | null | [{"input": "4 1\n-1\n-1\n-1\n-1", "output": "4 1 2 3 4\n0"}, {"input": "2 4\n-1 -1 -1 2\n1 1 1 1", "output": "1 1\n1 4"}] | 2,100 | ["constructive algorithms", "greedy"] | 95 | [{"input": "4 1\r\n-1\r\n-1\r\n-1\r\n-1\r\n", "output": "4 1 2 3 4 \r\n0 \r\n"}, {"input": "2 4\r\n-1 -1 -1 2\r\n1 1 1 1\r\n", "output": "1 1 \r\n1 4 \r\n"}, {"input": "10 5\r\n1 7 1 6 -3\r\n8 -8 0 -7 -8\r\n7 -10 -8 -3 6\r\n-3 0 -9 0 -3\r\n-1 5 -2 -9 10\r\n-2 9 2 0 7\r\n5 0 -1 -10 6\r\n7 -8 -3 -9 1\r\n-5 10 -10 5 9\r\n... | false | stdio | null | true |
95/C | 95 | C | PyPy 3-64 | TESTS | 1 | 92 | 0 | 174810199 | '''
# Submitted By M7moud Ala3rj
Don't Copy This Code, CopyRight . [email protected] © 2022-2023 :)
'''
# Problem Name = "Volleyball"
# Class: C
import sys
from heapq import *
#sys.setrecursionlimit(2147483647)
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(st... | 65 | 966 | 28,057,600 | 144034839 | import sys
def input():
return sys.stdin.readline()[:-1]
N,M = list(map(int,input().split()))
e_list = [[] for i in range(N)]
X,Y = list(map(int,input().split()))
X-=1
Y-=1
for i in range(M):
u,v,w = list(map(int,input().split()))
u-=1
v-=1
e_list[u].append((v,w))
e_list[v].append((u,w))
DP... | Codeforces Beta Round 77 (Div. 1 Only) | CF | 2,011 | 2 | 256 | Volleyball | Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can... | The first line contains two integers n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to n, inclusive. The next line contains two integers x and y (1 ≤ x, y ≤ n). They are the numbers of the initial and final junctions corres... | If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | null | An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles. | [{"input": "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "output": "9"}] | 1,900 | ["shortest paths"] | 65 | [{"input": "4 4\r\n1 3\r\n1 2 3\r\n1 4 1\r\n2 4 1\r\n2 3 5\r\n2 7\r\n7 2\r\n1 2\r\n7 7\r\n", "output": "9\r\n"}, {"input": "3 3\r\n1 3\r\n1 2 2\r\n1 3 3\r\n3 2 1\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "14\r\n"}, {"input": "3 1\r\n1 3\r\n1 2 2\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n3 3\r\n1 2 2\... | false | stdio | null | true |
272/D | 272 | D | PyPy 3 | TESTS | 2 | 184 | 0 | 117478825 | n=int(input())
a=sorted(list(map(int,input().split()))+list(map(int,input().split())))
m=int(input())
b=[]
c=1
for i in range(1,n+1):
c*=i
c%=m
b.append(c)
d=0
e=1
for i in range(n):
if a[i]!=a[i-1]:
e*=b[i-d-1]
e%=m
d=i
e*=b[n-d-1]
print(e%m) | 51 | 872 | 81,203,200 | 190272675 | import abc
import itertools
import math
from math import gcd as gcd
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
def solve():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
m... | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Two Sequences | Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in th... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 109). The numbers in the lines are separated by spaces.
The last line contains integer m (2 ≤ m ≤ 109 + 7). | In the single line print the remainder after dividing the answer to the problem by number m. | null | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | [{"input": "1\n1\n2\n7", "output": "1"}, {"input": "2\n1 2\n2 3\n11", "output": "2"}] | 1,600 | ["combinatorics", "math", "sortings"] | 51 | [{"input": "1\r\n1\r\n2\r\n7\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n2 3\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n1 2\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n1009\r\n", "output": "16\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n1 2 3 5 3\r\n12\r\n", "output": "0\r\n"}, {"input... | false | stdio | null | true |
272/D | 272 | D | Python 3 | TESTS | 2 | 154 | 0 | 32560588 | f = lambda: map(int, input().split())
n = int(input())
c, d = {}, {}
for x, y in zip(f(), f()):
c[x] = c.get(x, 0) + 1
c[y] = c.get(y, 0) + 1
if x == y: d[x] = d.get(x, 0) + 2
s, m = 1, int(input())
for k, v in c.items():
u = d.get(k, 0)
for i in range(v - u, v, 2): s = s * (i * i + i) // 2 % m
... | 51 | 902 | 20,070,400 | 121344663 | n = input()
c_n = {}
d_n = {}
for a_i, b_i in zip(input().split(), input().split()):
if a_i == b_i:
d_n[a_i] = d_n.get(a_i,0) + 2
c_n[a_i] = c_n.get(a_i,0) + 1
c_n[b_i] = c_n.get(b_i,0) + 1
result = 1
k = int(input())
for a_i, cant in c_n.items():
cant_rep = d_n.get(a_i,0)
for ... | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Two Sequences | Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in th... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 109). The numbers in the lines are separated by spaces.
The last line contains integer m (2 ≤ m ≤ 109 + 7). | In the single line print the remainder after dividing the answer to the problem by number m. | null | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | [{"input": "1\n1\n2\n7", "output": "1"}, {"input": "2\n1 2\n2 3\n11", "output": "2"}] | 1,600 | ["combinatorics", "math", "sortings"] | 51 | [{"input": "1\r\n1\r\n2\r\n7\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n2 3\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n1 2\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n1009\r\n", "output": "16\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n1 2 3 5 3\r\n12\r\n", "output": "0\r\n"}, {"input... | false | stdio | null | true |
383/E | 383 | E | Python 3 | TESTS | 1 | 124 | 409,600 | 45697746 | import collections, functools
M = 10
n = int(input())
f = collections.defaultdict(int)
for _ in range(n):
f[functools.reduce(lambda x, y: x | y, [1<<(ord(x)-ord('a')) for x in input()])] += 1
ans = 0
for i in range(M):
for mask in range(1<<M):
if(mask & (1<<i)):
f[mask] += f[mask^(1<<i)];
for mask in range(1<... | 68 | 3,026 | 69,324,800 | 155280550 | import sys
readline=sys.stdin.readline
N=int(readline())
dp=[0]*(1<<24)
dp[-1]=N
for _ in range(N):
bit=(1<<24)-1
for a in readline().rstrip():
a=ord(a)-97
if bit&1<<a:
bit^=1<<a
dp[bit]-=1
for i in range(24):
for bit in range((1<<24)-1,-1,-1):
if not bit&1<<i:
... | Codeforces Round 225 (Div. 1) | CF | 2,014 | 4 | 256 | Vowels | Iahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of n 3-words. A 3-word is a sequence of exactly 3 lowercase letters of the first 24 letters of the English alphabet (a to x). She decided that some of the letters are vowels, and... | The first line contains one integer, n (1 ≤ n ≤ 104). Each of the next n lines contains a 3-word consisting of 3 lowercase letters. There will be no two identical 3-words. | Print one number, the xor of the squared answers to the queries. | null | null | [{"input": "5\nabc\naaa\nada\nbcd\ndef", "output": "0"}] | 2,700 | ["combinatorics", "divide and conquer", "dp"] | 68 | [{"input": "5\r\nabc\r\naaa\r\nada\r\nbcd\r\ndef\r\n", "output": "0\r\n"}, {"input": "100\r\namd\r\namj\r\natr\r\nbcp\r\nbjm\r\ncna\r\ncpj\r\ncse\r\ndij\r\ndjp\r\ndlv\r\nebk\r\nedf\r\nelw\r\nfbr\r\nfcl\r\nfhs\r\nflo\r\nfmj\r\ngcg\r\ngen\r\nghg\r\ngvb\r\ngxx\r\nhbe\r\nhbf\r\nhgu\r\nhlv\r\nhqa\r\nibg\r\nifp\r\nima\r\nitt... | false | stdio | null | true |
526/B | 526 | B | Python 3 | PRETESTS | 0 | 46 | 0 | 10582995 | # fin = open("input.txt")
# n = int(fin.readline())
# A = [0] + list(map(int, fin.readline().split()))
n = int(input())
A = list(map(int, input().split()))
C = 0
for i in range(n - 1, -1, -1):
C += abs(A[i * 2] - A[i * 2 + 1])
A[i] += max(A[i * 2], A[i * 2 + 1])
print(C) | 38 | 61 | 0 | 10586802 | from math import floor
def main():
n = int(input())
a = list(map(int, input().split()))
streets = []
for i in range(2**n, 2**(n+1)):
#print('---')
idx = i
#print(idx)
if idx > 1:
#print('Cost: %d' % a[idx-2])
res = a[idx-2]
while idx > 0:
idx = int(floor(idx/2))
if idx > 1:
#print(... | ZeptoLab Code Rush 2015 | CF | 2,015 | 1 | 256 | Om Nom and Dark Park | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2n + 1 - 1 squares connected by roads so that ... | The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | null | Picture for the sample test. Green color denotes the additional street lights. | [{"input": "2\n1 2 3 4 5 6", "output": "5"}] | 1,400 | ["dfs and similar", "greedy", "implementation"] | 38 | [{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\... | false | stdio | null | true |
832/D | 832 | D | PyPy 3 | TESTS | 3 | 61 | 409,600 | 149775433 | import sys
input = sys.stdin.readline
from collections import deque
def solve(n, q, graph, ABC):
for a, b, c in ABC:
a, b, c = sorted([a, b, c])
if a == b == c:
print(1)
else:
q = deque([(a, 0)])
vis = {a}
ab, ac = -1, -1
while q:... | 94 | 1,325 | 40,550,400 | 110042385 | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def pre(n,path,lim):
# lim = n.bit_length()
up = [[-1]*(lim+1) for _ in range(n)]
st,visi,height = [0],[1]+[0]*(n-1),[0]*n
start,finish,time = [0]*n,[0]*n,0
while len(st):
x = st[-1]
... | Codeforces Round 425 (Div. 2) | CF | 2,017 | 2 | 256 | Misha, Grisha and Underground | Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.
The boys decided to have fun and came up with a plan. Namely, in some day in the morning M... | The first line contains two integers n and q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of stations and the number of days.
The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n). The integer pi means that there is a route between stations pi and i. It is guaranteed that it's possible to reach every station... | Print q lines. In the i-th of these lines print the maximum possible number Grisha can get counting when the stations s, t and f are chosen optimally from the three stations on the i-th day. | null | In the first example on the first day if s = 1, f = 2, t = 3, Misha would go on the route 1 $$\rightarrow$$ 2, and Grisha would go on the route 3 $$\rightarrow$$ 1 $$\rightarrow$$ 2. He would see the text at the stations 1 and 2. On the second day, if s = 3, f = 2, t = 3, both boys would go on the route 3 $$\rightarrow... | [{"input": "3 2\n1 1\n1 2 3\n2 3 3", "output": "2\n3"}, {"input": "4 1\n1 2 3\n1 2 3", "output": "2"}] | 1,900 | ["dfs and similar", "graphs", "trees"] | 94 | [{"input": "3 2\r\n1 1\r\n1 2 3\r\n2 3 3\r\n", "output": "2\r\n3\r\n"}, {"input": "4 1\r\n1 2 3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "2 4\r\n1\r\n1 1 1\r\n1 1 2\r\n1 2 2\r\n2 2 2\r\n", "output": "1\r\n2\r\n2\r\n1\r\n"}, {"input": "5 20\r\n4 1 1 4\r\n2 2 5\r\n3 2 5\r\n2 3 4\r\n4 2 5\r\n4 1 2\r\n5 3 1\r\n2 1 2\r\... | false | stdio | null | true |
379/C | 379 | C | PyPy 3-64 | TESTS | 5 | 670 | 74,444,800 | 213215323 | from collections import defaultdict as ded
d = ded(lambda:None)
n = int(input())
a = input().split()
for i in a:
if d[i]==None:
print(i,end= " ")
d[i]=int(i)+1
else:
j =d[i]
while d[str(j)]:
j+=1
print(j,end=" ")
d[i]=j+1 | 41 | 670 | 53,862,400 | 167040474 | import sys
input = sys.stdin.readline
n = int(input())
w = sorted(enumerate(map(int, input().split())), key=lambda x:x[1])
x = [0]*n
c = 0
for i in range(n):
if w[i][1] > c:
x[w[i][0]] = w[i][1]
c = w[i][1] + 1
else:
x[w[i][0]] = c
c += 1
print(' '.join(map(str, x))) | Good Bye 2013 | CF | 2,013 | 1 | 256 | New Year Ratings Change | One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin... | The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109). | Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them. | null | null | [{"input": "3\n5 1 1", "output": "5 1 2"}, {"input": "1\n1000000000", "output": "1000000000"}] | 1,400 | ["greedy", "sortings"] | 41 | [{"input": "3\r\n5 1 1\r\n", "output": "5 1 2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"}, {"input": "10\r\n1 10 1 10 1 1 7 8 6 7\r\n", "output": "1 10 2 11 3 4 7 9 6 8\r\n"}, {"input": "10\r\n20 19 12 1 12 15 2 12... | false | stdio | null | true |
340/E | 340 | E | PyPy 3-64 | TESTS | 1 | 92 | 0 | 200984693 | def main():
n, *a = map(int, open(0).read().split())
ok = [True] * (n + 1)
ok[0] = False
for i, x in enumerate(a, 1):
if x != -1:
ok[i] = False
ok[x] = False
n = sum(ok)
mod = 10 ** 9 + 7
m = Mod(n, mod)
ans = m.fact[n]
for i in range(1, n + 1):
... | 18 | 218 | 512,000 | 102160229 | MOD = 10**9+7
def solve(values):
notUsed = set(range(1, len(values)+1))
chairs = set()
for i, a in enumerate(values, 1):
if a == -1:
chairs.add(i)
else:
notUsed -= {a}
fixed = len(chairs & notUsed)
m = len(notUsed)
fact, fact_inv = facts(m)
ans = fac... | Codeforces Round 198 (Div. 2) | CF | 2,013 | 1 | 256 | Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). | null | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | [{"input": "5\n-1 -1 4 3 -1", "output": "2"}] | 2,000 | ["combinatorics", "math"] | 18 | [{"input": "5\r\n-1 -1 4 3 -1\r\n", "output": "2\r\n"}, {"input": "8\r\n2 4 5 3 -1 8 -1 6\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 -1 7 1 6\r\n", "output": "4\r\n"}, {"input": "6\r\n-1 -1 -1 -1 -1 -1\r\n", "output": "265\r\n"}, {"input": "2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "10\r\n4 10 -1 1 6 8 9 2 ... | false | stdio | null | true |
340/E | 340 | E | Python 3 | TESTS | 2 | 124 | 7,065,600 | 36718163 | from math import factorial as f
def der(n):
s=0
for i in range(2,n+1):
s+=((-1)**i)/f(i)
return f(n)*s
x=input()
l=[i for i in input().split()]
print(int(der(l.count("-1"))%(1000000007))) | 18 | 248 | 7,168,000 | 85499531 | MOD = 10**9+7
n = int(input())
notUsed = set(range(1, n+1))
chairs = set()
for i, a in enumerate(map(int, input().split()), 1):
if a == -1:
chairs.add(i)
else:
notUsed -= {a}
fixed = len(chairs & notUsed)
m = len(notUsed)
U = m
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
fact[i] =... | Codeforces Round 198 (Div. 2) | CF | 2,013 | 1 | 256 | Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). | null | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | [{"input": "5\n-1 -1 4 3 -1", "output": "2"}] | 2,000 | ["combinatorics", "math"] | 18 | [{"input": "5\r\n-1 -1 4 3 -1\r\n", "output": "2\r\n"}, {"input": "8\r\n2 4 5 3 -1 8 -1 6\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 -1 7 1 6\r\n", "output": "4\r\n"}, {"input": "6\r\n-1 -1 -1 -1 -1 -1\r\n", "output": "265\r\n"}, {"input": "2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "10\r\n4 10 -1 1 6 8 9 2 ... | false | stdio | null | true |
296/B | 296 | B | PyPy 3 | TESTS | 2 | 124 | 0 | 136781572 | def special(lst1, lst2, m):
a,b,c=1,1,1
ln=len(lst1)
for i in range(ln):
if lst1[i]=="?" and lst2[i]=="?": b*=10
elif lst1[i]!=lst2[i] and lst1[i]!="?" and lst2[i]!="?": b=0
b%=m
for i in range(n):
if lst1[i]=="?" and lst2[i]=="?":
a*=55
c*=55
... | 38 | 840 | 7,065,600 | 28195911 | from functools import reduce
n, s1, s2, f1, f2 = int(input()), str(input()), str(input()), lambda x: reduce((lambda a, b: (a * b) % 1000000007), x, 1), lambda x: reduce((lambda a, b: a or b), x, False)
print((10 ** sum([(s1[i] == '?') + (s2[i] == '?') for i in range(n)]) - (not f2([s1[i] != '?' and s2[i] != '?' and ord... | Codeforces Round 179 (Div. 2) | CF | 2,013 | 2 | 256 | Yaroslav and Two Strings | Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w.
A string's template is a string... | The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. | In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). | null | The first test contains no question marks and both strings are incomparable, so the answer is 1.
The second test has no question marks, but the given strings are comparable, so the answer is 0. | [{"input": "2\n90\n09", "output": "1"}, {"input": "2\n11\n55", "output": "0"}, {"input": "5\n?????\n?????", "output": "993531194"}] | 2,000 | ["combinatorics", "dp"] | 38 | [{"input": "2\r\n90\r\n09\r\n", "output": "1\r\n"}, {"input": "2\r\n11\r\n55\r\n", "output": "0\r\n"}, {"input": "5\r\n?????\r\n?????\r\n", "output": "993531194\r\n"}, {"input": "10\r\n104?3?1??3\r\n?1755?1??7\r\n", "output": "91015750\r\n"}, {"input": "10\r\n6276405116\r\n6787?352?9\r\n", "output": "46\r\n"}, {"input"... | false | stdio | null | true |
690/F1 | 690 | F1 | Python 3 | TESTS | 4 | 46 | 0 | 19014662 | n = int(input())
l = []
for _ in range(n-1):
a,b = map(int,input().split())
l.append([a,b])
c=0
for i in l:
for j in l:
if i[0] == j[0] and i[1] != j[1]:
c+=1
elif i[1] == j[0] and i[0] != j[1]:
c+=1
elif i[0] == j[1] and i[1] != j[0]:
c+=1
print(... | 19 | 62 | 102,400 | 198725128 | import math
n=int(input())
l=[0]*(n+1)
# print(*l)
for i in range(n-1):
a,b=map(int,input().split())
l[a]+=1
l[b]+=1
ans=0
for i in range(1,n+1):
if l[i]>=2:
ans+=math.comb(l[i],2)
print(ans) | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Tree of Life (easy) | Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (... | The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n).... | Print one integer – the number of lifelines in the tree. | null | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | [{"input": "4\n1 2\n1 3\n1 4", "output": "3"}, {"input": "5\n1 2\n2 3\n3 4\n3 5", "output": "4"}] | 1,300 | [] | 19 | [{"input": "4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "3"}, {"input": "5\r\n1 2\r\n2 3\r\n3 4\r\n3 5\r\n", "output": "4"}, {"input": "2\r\n1 2\r\n", "output": "0"}, {"input": "3\r\n2 1\r\n3 2\r\n", "output": "1"}, {"input": "10\r\n5 1\r\n1 2\r\n9 3\r\n10 5\r\n6 3\r\n8 5\r\n2 7\r\n2 3\r\n9 4\r\n", "output": "11"}] | false | stdio | null | true |
690/F1 | 690 | F1 | PyPy 3 | TESTS | 4 | 140 | 0 | 92413083 | a=int(input());ans=0
z=[list(map(int,input().split())) for _ in " "*(a-1)]
z.sort();k=a-1
r =lambda x:(x*(x+1))//2;t=0
for i in range(k-1):
if z[i][0]==z[i+1][0]:t+=1
else:ans+=r(t);t=0
ans+=r(t);t=0
for i in range(k-1):
if z[i][1]==z[i+1][1]:t+=1
else:ans+=r(t);t=0
ans+=r(t);t=0
for i in range(k-1):
... | 19 | 62 | 2,252,800 | 164936319 | import sys
input = sys.stdin.readline
n = int(input())
d = [0 for _ in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
d[a-1] += 1
d[b-1] += 1
print(sum(i*(i-1)//2 for i in d)) | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Tree of Life (easy) | Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (... | The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n).... | Print one integer – the number of lifelines in the tree. | null | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | [{"input": "4\n1 2\n1 3\n1 4", "output": "3"}, {"input": "5\n1 2\n2 3\n3 4\n3 5", "output": "4"}] | 1,300 | [] | 19 | [{"input": "4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "3"}, {"input": "5\r\n1 2\r\n2 3\r\n3 4\r\n3 5\r\n", "output": "4"}, {"input": "2\r\n1 2\r\n", "output": "0"}, {"input": "3\r\n2 1\r\n3 2\r\n", "output": "1"}, {"input": "10\r\n5 1\r\n1 2\r\n9 3\r\n10 5\r\n6 3\r\n8 5\r\n2 7\r\n2 3\r\n9 4\r\n", "output": "11"}] | false | stdio | null | true |
690/F1 | 690 | F1 | PyPy 3 | TESTS | 4 | 140 | 0 | 92409871 | from sys import stdin
a=int(stdin.readline());ans=0
z=[list(map(int,stdin.readline().split())) for _ in " "*(a-1)]
w=[]
for i in range(a-1):
s=z[i]
for j in range(a-1):
if i!=j:
if [max(i,j),min(i,j)] in w:continue
if s[0]==z[j][1] or s[0]==z[j][0]:ans+=1;w.append([max(i,j),min(i... | 19 | 77 | 7,884,800 | 124377070 | # Test
#####################################################################################################################
def main():
tree_sLength = int(input()) - 1
tree = {}
for i in range(tree_sLength):
v1, v2 = map(int, input().split())
tree[v1] = tree.get(v1, ()) + (v2, )
tr... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Tree of Life (easy) | Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (... | The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n).... | Print one integer – the number of lifelines in the tree. | null | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | [{"input": "4\n1 2\n1 3\n1 4", "output": "3"}, {"input": "5\n1 2\n2 3\n3 4\n3 5", "output": "4"}] | 1,300 | [] | 19 | [{"input": "4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "3"}, {"input": "5\r\n1 2\r\n2 3\r\n3 4\r\n3 5\r\n", "output": "4"}, {"input": "2\r\n1 2\r\n", "output": "0"}, {"input": "3\r\n2 1\r\n3 2\r\n", "output": "1"}, {"input": "10\r\n5 1\r\n1 2\r\n9 3\r\n10 5\r\n6 3\r\n8 5\r\n2 7\r\n2 3\r\n9 4\r\n", "output": "11"}] | false | stdio | null | true |
796/D | 796 | D | PyPy 3-64 | TESTS | 4 | 1,668 | 195,788,800 | 195240992 | from collections import defaultdict, deque
from sys import stdin, stdout
def inp():
return int(stdin.readline())
def inlt():
return list(map(int, stdin.readline().strip().split()))
def insr():
s = stdin.readline().strip()
return list(s[:len(s)])
def invr():
return map(int, stdin.readline().s... | 135 | 1,669 | 108,544,000 | 152757338 | import math
from collections import defaultdict, deque, Counter
from sys import stdin
import heapq
inf = int(1e18)
input = stdin.readline
n,k,d = map(int, input().split())
ps = [int(i) for i in input().split()]
adj = [[] for i in range (n+1)]
for i in range (n-1):
u,v = map(int, input().split())
adj[u].append(... | Codeforces Round 408 (Div. 2) | CF | 2,017 | 2 | 256 | Police Stations | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos... | The first line contains three integers n, k, and d (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105, 0 ≤ d ≤ n - 1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — each denoting the city each police station ... | In the first line, print one integer s that denotes the maximum number of roads that can be shut down.
In the second line, print s distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | null | In the first sample, if you shut down road 5, all cities can still reach a police station within k = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | [{"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "1\n5"}, {"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "output": "2\n4 5"}] | 2,100 | ["constructive algorithms", "dfs and similar", "dp", "graphs", "shortest paths", "trees"] | 135 | [{"input": "6 2 4\r\n1 6\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n", "output": "1\r\n3 "}, {"input": "6 3 2\r\n1 5 6\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n5 6\r\n", "output": "2\r\n4 5 "}, {"input": "10 1 5\r\n5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n", "output": "0\r\n"}, {"input": "11 1 5\r\n6\r\n1 ... | false | stdio | null | true |
999/D | 999 | D | PyPy 3-64 | TESTS | 6 | 187 | 34,201,600 | 219020028 | def rl():
return list(map(int,input().split()))
def ri():
return int(input())
def rs():
return input()
def rm():
return map(int,input().split())
def main():
n,m=rm()
a=rl()
cnt=[0]*m
loc=[[] for i in range(m)]
for i in range(n):
cnt[a[i]%m]+=1
loc[a[i]%m].append(i)
... | 47 | 389 | 40,755,200 | 167327303 | from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
target = n // m
locs = [[] for _ in range(m)... | Codeforces Round 490 (Div. 3) | ICPC | 2,018 | 3 | 256 | Equalize the Remainders | You are given an array consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, and a positive integer $$$m$$$. It is guaranteed that $$$m$$$ is a divisor of $$$n$$$.
In a single move, you can choose any position $$$i$$$ between $$$1$$$ and $$$n$$$ and increase $$$a_i$$$ by $$$1$$$.
Let's calculate $$$c_r$$$ ($$$0 ... | The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le m \le n$$$). It is guaranteed that $$$m$$$ is a divisor of $$$n$$$.
The second line of input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$), the elements of the array. | In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $$$0$$$ to $$$m - 1$$$, the number of elements of the array having this remainder equals $$$\frac{n}{m}$$$.
In the second line, print any array satisfying the condition and can b... | null | null | [{"input": "6 3\n3 2 0 6 10 12", "output": "3\n3 2 0 7 10 14"}, {"input": "4 2\n0 1 2 3", "output": "0\n0 1 2 3"}] | 1,900 | ["data structures", "greedy", "implementation"] | 47 | [{"input": "6 3\r\n3 2 0 6 10 12\r\n", "output": "3\r\n3 2 0 7 10 14 \r\n"}, {"input": "4 2\r\n0 1 2 3\r\n", "output": "0\r\n0 1 2 3 \r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "0\r\n1000000000 \r\n"}, {"input": "6 3\r\n3 2 0 6 10 11\r\n", "output": "1\r\n3 2 0 7 10 11 \r\n"}, {"input": "100 25\r\n6745 2075 74... | false | stdio | import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
a_original = list(map(int, f.readline().split()))
# Read reference output to get correct m... | true |
484/D | 484 | D | Python 3 | TESTS | 0 | 31 | 0 | 228199270 | def max_sociability(n, charisma):
max_diff = 0
current_diff = 0
for i in range(1, n):
diff = abs(charisma[i] - charisma[i - 1])
current_diff = max(current_diff + diff, diff)
max_diff = max(max_diff, current_diff)
return max_diff
n = int(input())
charisma = list(map(int... | 71 | 1,310 | 79,462,400 | 147542209 | n = int(input())
if n == 1:
print(0)
else:
a = [0]*(n+1)
i = 1
for v in map(int, input().split()):
a[i] = v
i += 1
dp = [0]*(n+1)
dp[2] = abs(a[1]-a[2])
for i in range(3, n+1):
# 单调
if (a[i-2] < a[i-1] and a[i-1] < a[i]) or (a[i-2] > a[i-1] and a[i-1] > a[i]):... | Codeforces Round 276 (Div. 1) | CF | 2,014 | 2 | 256 | Kindergarten | In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maxim... | The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106).
The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109). | Print the maximum possible total sociability of all groups. | null | In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.
In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group. | [{"input": "5\n1 2 3 1 2", "output": "3"}, {"input": "3\n3 3 3", "output": "0"}] | 2,400 | ["data structures", "dp", "greedy"] | 71 | [{"input": "5\r\n1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1000000000 1000000000\r\n", "output": "2000000000\r\n"}, {"input": "4\r\n1 4 2 3\r\n", "output": "4\r\n"}, {"input": "4\r\n23 5 7 1\r\n", "output": "24\r\n"},... | false | stdio | null | true |
24/C | 24 | C | PyPy 3 | TESTS | 2 | 280 | 4,096,000 | 154968873 | n,j=map(int,input().split())
x0,y0=map(int,input().split())
A=[tuple(map(int,input().split())) for i in range(n)]
x,y=x0,y0
for z,w in A:
x=2*z-x
y=2*w-y
rep=j//n
rest=j%n
nx=(x-x0)*rep+x0
ny=(y-y0)*rep+y0
x,y=nx,ny
for i in range(rest):
z,w=A[i]
x=2*z-x
y=2*w-y
print(x,y) | 23 | 310 | 14,643,200 | 212806082 | from sys import stdin
N, J = [int(w) for w in stdin.readline().split()]
J = J % (N + N)
points = []
x, y = [int(w) for w in stdin.readline().split()]
for _ in range(N):
points.append([int(w) for w in stdin.readline().split()])
for i in range(J):
i %= N
x += (points[i][0] - x) * 2
y += (points[i]... | Codeforces Beta Round 24 | ICPC | 2,010 | 2 | 256 | Sequence of points | You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according $${ A } _ { ( i - 1 ) \mod n }$$ (for every natural number i). Here point B is symmetric to A accordin... | On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates o... | On a single line output the coordinates of Mj, space separated. | null | null | [{"input": "3 4\n0 0\n1 1\n2 3\n-5 3", "output": "14 0"}, {"input": "3 1\n5 5\n1000 1000\n-1000 1000\n3 100", "output": "1995 1995"}] | 1,800 | ["geometry", "implementation", "math"] | 23 | [{"input": "3 4\r\n0 0\r\n1 1\r\n2 3\r\n-5 3\r\n", "output": "14 0\r\n"}, {"input": "3 1\r\n5 5\r\n1000 1000\r\n-1000 1000\r\n3 100\r\n", "output": "1995 1995\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n1000 1000\r\n", "output": "3000 3000\r\n"}, {"input": "1 1000000000000000000\r\n-1000 1000\r\n1000 -1000\r\n", "output": ... | false | stdio | null | true |
999/D | 999 | D | Python 3 | TESTS | 7 | 919 | 23,142,400 | 121169118 | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*m
x = n//m
ans = 0
c = []
for i in range(n):
cr = a[i]%m
if b[cr]<x:
b[cr]+=1
else:
c.append([cr,i])
c.sort()
i = 0
j = 0
n1 = len(c)
while i<m and j<n1:
if b[i]>=x:
i+=1
else:
b[i]+=1
c... | 47 | 389 | 53,862,400 | 167326676 | from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
A = list(map(int, input().split()))
target = n // m
locs = [[]... | Codeforces Round 490 (Div. 3) | ICPC | 2,018 | 3 | 256 | Equalize the Remainders | You are given an array consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, and a positive integer $$$m$$$. It is guaranteed that $$$m$$$ is a divisor of $$$n$$$.
In a single move, you can choose any position $$$i$$$ between $$$1$$$ and $$$n$$$ and increase $$$a_i$$$ by $$$1$$$.
Let's calculate $$$c_r$$$ ($$$0 ... | The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le m \le n$$$). It is guaranteed that $$$m$$$ is a divisor of $$$n$$$.
The second line of input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$), the elements of the array. | In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $$$0$$$ to $$$m - 1$$$, the number of elements of the array having this remainder equals $$$\frac{n}{m}$$$.
In the second line, print any array satisfying the condition and can b... | null | null | [{"input": "6 3\n3 2 0 6 10 12", "output": "3\n3 2 0 7 10 14"}, {"input": "4 2\n0 1 2 3", "output": "0\n0 1 2 3"}] | 1,900 | ["data structures", "greedy", "implementation"] | 47 | [{"input": "6 3\r\n3 2 0 6 10 12\r\n", "output": "3\r\n3 2 0 7 10 14 \r\n"}, {"input": "4 2\r\n0 1 2 3\r\n", "output": "0\r\n0 1 2 3 \r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "0\r\n1000000000 \r\n"}, {"input": "6 3\r\n3 2 0 6 10 11\r\n", "output": "1\r\n3 2 0 7 10 11 \r\n"}, {"input": "100 25\r\n6745 2075 74... | false | stdio | import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
a_original = list(map(int, f.readline().split()))
# Read reference output to get correct m... | true |
216/D | 216 | D | Python 3 | TESTS | 0 | 60 | 0 | 206619409 | def main():
n = int(input())
bridges = []
for i in range(n):
k, *bridge_distances = map(int, input().split())
bridges.append(bridge_distances)
unstable_cells = 0
for i in range(n):
k = len(bridges[i])
for j in range(k):
left = bridges[i][k - 1] if j == 0... | 55 | 560 | 30,412,800 | 125084763 | import math
import sys
def search(arr,l,r,p1,p2):
i1=-1
i2=-1
copy_l=l
copy_r=r
while l<=r:
m=(l+r)//2
val=arr[m]
if p1<=val and val<=p2:
i1=m
r=m-1
elif val>p2:
r=m-1
else:
l=m+1
l=copy_l
r=copy_r
while l<=r:
m=(l+r)//2
val=arr[m]
... | Codeforces Round 133 (Div. 2) | CF | 2,012 | 2 | 256 | Spider's Web | Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web.
There are n main threads going from the center of the web. All main threads are located in one plane and divide it into n equal infinite sectors. The sectors are indexed fro... | The first line contains integer n (3 ≤ n ≤ 1000) — the number of main threads.
The i-th of following n lines describe the bridges located in the i-th sector: first it contains integer ki (1 ≤ ki ≤ 105) equal to the number of bridges in the given sector. Then follow ki different integers pij (1 ≤ pij ≤ 105; 1 ≤ j ≤ ki)... | Print a single integer — the number of unstable cells in Paw the Spider's web. | null | null | [{"input": "7\n3 1 6 7\n4 3 5 2 9\n2 8 1\n4 3 7 6 4\n3 2 5 9\n3 6 3 8\n3 4 2 9", "output": "6"}] | 1,700 | ["binary search", "sortings", "two pointers"] | 55 | [{"input": "7\r\n3 1 6 7\r\n4 3 5 2 9\r\n2 8 1\r\n4 3 7 6 4\r\n3 2 5 9\r\n3 6 3 8\r\n3 4 2 9\r\n", "output": "6"}, {"input": "3\r\n1 1\r\n1 2\r\n1 3\r\n", "output": "0"}, {"input": "3\r\n2 1 2\r\n2 3 4\r\n2 5 6\r\n", "output": "0"}, {"input": "5\r\n3 2 4 10\r\n2 1 6\r\n2 8 7\r\n3 2 4 10\r\n2 1 6\r\n", "output": "2"}, {... | false | stdio | null | true |
463/D | 463 | D | PyPy 3 | TESTS | 1 | 140 | 1,536,000 | 118700926 | import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=[list(map(int,input().split())) for i in range(k)]
g=[[] for i in range(n+1)]
for i in range(n):
x=a[0][i]
s1=set(a[0][i+1:])
idx2=a[1].index(x)
s2=set(a[1][idx2+1:])
idx3=a[2].index(x)
s3=set(a[2][idx3+1:])
s=s1&s2&s3
fo... | 40 | 124 | 2,867,200 | 197562869 | n, k = map(int, input().split())
a, b = [[] for row in range(6)], [[0 for col in range(n + 1)] for row in range(6)]
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):
flag = 1
for x in ra... | 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 |
960/F | 960 | F | Python 3 | PRETESTS | 3 | 62 | 7,065,600 | 37064950 | n,m = map(int,input().split())
e=[tuple(map(int,input().split()))for i in range(m)]
ans = {}
def f(lans,w):
left=0
right = len(lans)
while True:
middle = (left+right)//2
if right==left+1:
if lans[left][1]<=w:
return lans[left][0]
return 0
if la... | 63 | 685 | 44,236,800 | 206868890 | import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * z + v
def update(i, x):
i += l1
tree[i] = x
i //= 2
while i:
tree[i] = max(tree[2 * i], tree[2 * i + 1])
i //= 2
return
def get_max(s, t):
s, t = s + l1, ... | Divide by Zero 2018 and Codeforces Round 474 (Div. 1 + Div. 2, combined) | CF | 2,018 | 1 | 256 | Pathwalks | You are given a directed graph with n nodes and m edges, with all edges having a certain weight.
There might be multiple edges and self loops, and the graph can also be disconnected.
You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are i... | The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.
m lines follows.
The i-th of these lines contains three space separated integers ai, bi and wi (1 ≤ ai, bi ≤ n, 0 ≤ wi ≤ 100000), denoting an edge from vertex ai to vertex bi hav... | Print one integer in a single line — the maximum number of edges in the path. | null | The answer for the first sample input is 2: $$1 \rightarrow 2 \rightarrow 3$$. Note that you cannot traverse $$1 \rightarrow 2 \rightarrow 3 \rightarrow 1$$ because edge $$\overset{3}{\rightarrow}1$$ appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two... | [{"input": "3 3\n3 1 3\n1 2 1\n2 3 2", "output": "2"}, {"input": "5 5\n1 3 2\n3 2 3\n3 4 5\n5 4 0\n4 5 8", "output": "3"}] | 2,100 | ["data structures", "dp", "graphs"] | 63 | [{"input": "3 3\r\n3 1 3\r\n1 2 1\r\n2 3 2\r\n", "output": "2"}, {"input": "5 5\r\n1 3 2\r\n3 2 3\r\n3 4 5\r\n5 4 0\r\n4 5 8\r\n", "output": "3"}, {"input": "5 10\r\n3 4 8366\r\n5 1 6059\r\n2 1 72369\r\n2 2 35472\r\n5 3 50268\r\n2 4 98054\r\n5 1 26220\r\n2 3 24841\r\n1 3 42450\r\n3 1 59590\r\n", "output": "3"}, {"input... | false | stdio | null | true |
690/D1 | 690 | D1 | Python 3 | TESTS | 0 | 31 | 4,608,000 | 25933138 | import sys
#with open(filename, 'r') as f:
with sys.stdin as f:
input_list = list(f)
for i, line in enumerate(input_list):
if i == 0:
R = int(line.split(" ")[0])
else:
if i == R:
print(len(list(filter(lambda x: len(x) > 0, line.split('.'))))) | 119 | 62 | 0 | 18999968 | r, c = map(int, input().split())
for _ in range(r-1):
input()
bottom = input()
sections = 0
looking_for_new_section = True
for brick in bottom:
if looking_for_new_section:
if brick == 'B':
looking_for_new_section = False
sections += 1
else:
if brick == '.':
... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 0.5 | 256 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:
- each of the R lines contains a string of length C,
- the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise. | The number of wall segments in the input configuration. | null | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | [{"input": "3 7\n.......\n.......\n.BB.B..", "output": "2"}, {"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "output": "2"}, {"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "output": "1"}, {"input": "1 1\nB", "output": "1"}, {"input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\... | 1,200 | [] | 119 | [{"input": "3 7\r\n.......\r\n.......\r\n.BB.B..\r\n", "output": "2\r\n"}, {"input": "4 5\r\n..B..\r\n..B..\r\nB.B.B\r\nBBB.B\r\n", "output": "2\r\n"}, {"input": "4 6\r\n..B...\r\nB.B.BB\r\nBBB.BB\r\nBBBBBB\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "1\r\n"}, {"input": "10 7\r\n.......\r\n.......\r\n... | false | stdio | null | true |
797/E | 797 | E | PyPy 3-64 | TESTS | 7 | 218 | 72,704,000 | 223292411 | # https://github.com/Tsuzat/fast-IO-for-python/blob/master/fast_IO/__init__.py
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE: int = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = ... | 53 | 576 | 92,364,800 | 92972860 | import sys
n = int(sys.stdin.buffer.readline().decode('utf-8'))
a = [0] + list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))
q = int(sys.stdin.buffer.readline().decode('utf-8'))
dp_size = 200
dp = [[1]*(n+1) for _ in range(dp_size+1)]
for k in range(1, dp_size+1):
for i in range(n, 0, -1):
... | Educational Codeforces Round 19 | ICPC | 2,017 | 2 | 256 | Array Queries | a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap + k. There operations are applied until p becomes greater than n. ... | The first line contains one integer n (1 ≤ n ≤ 100000).
The second line contains n integers — elements of a (1 ≤ ai ≤ n for each i from 1 to n).
The third line containts one integer q (1 ≤ q ≤ 100000).
Then q lines follow. Each line contains the values of p and k for corresponding query (1 ≤ p, k ≤ n). | Print q integers, ith integer must be equal to the answer to ith query. | null | Consider first example:
In first query after first operation p = 3, after second operation p = 5.
In next two queries p is greater than n after the first operation. | [{"input": "3\n1 1 1\n3\n1 1\n2 1\n3 1", "output": "2\n1\n1"}] | 2,000 | ["brute force", "data structures", "dp"] | 53 | [{"input": "3\r\n1 1 1\r\n3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "2\r\n1\r\n1\r\n"}, {"input": "10\r\n3 5 4 3 7 10 6 7 2 3\r\n10\r\n4 5\r\n2 10\r\n4 6\r\n9 9\r\n9 2\r\n5 1\r\n6 4\r\n1 1\r\n5 6\r\n6 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n"}, {"input": "50\r\n6 2 5 6 10 2 5 8 9 2 9 5 10 4 3 ... | false | stdio | null | true |
19/A | 19 | A | Python 3 | TESTS | 3 | 92 | 0 | 214148780 | n = int(input())
teams, index = [], {}
for i in range(n):
team = input()
teams.append([team, [0, 0, 0]])
index[team] = i
for i in range(int(n*(n-1)/2)):
game = input().split()
A, B = game[0].split('-')
a, b = map(int, game[1].split(':'))
if a > b:
teams[index[A]][1][0] += 3
eli... | 29 | 92 | 0 | 151243272 | class Info:
def __init__(self, _teamName, _points, _goalDiff, _scoredGoals):
self.teamName = _teamName
self.points = _points
self.goalDiff = _goalDiff
self.scoredGoals = _scoredGoals
def __str__(self):
return f"[teamName: '{self.teamName}', points: {self.points}, goalDif... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
643/A | 643 | A | Python 3 | TESTS | 2 | 46 | 0 | 21002892 | def main():
n = int(input())
cnt, winner = ([[0] * i for i in range(1, n + 1)] for _ in (0, 1))
order = [[] for _ in range(n)]
for i, t in enumerate(map(int, input().split())):
order[t - 1].append(i)
for t, l in enumerate(order):
while l:
x, hi = len(l), l.pop()
... | 35 | 265 | 9,523,200 | 230903750 | n = int(input())
t = [int(q) - 1 for q in input().split()]
k = [0] * n
for i in range(n):
s = [0] * n
b = 0
for a in t[i:]:
s[a] += 1
if s[a] > s[b] or a < b and s[a] == s[b]: b = a
k[b] += 1
print(*k) | VK Cup 2016 - Round 3 | CF | 2,016 | 2 | 256 | Bear and Colors | Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the bigges... | The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball. | Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color. | null | In the first sample, color 2 is dominant in three intervals:
- An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
- An interval [4, 4] contains one ball, with color 2 again.
- An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more interva... | [{"input": "4\n1 2 1 2", "output": "7 3 0 0"}, {"input": "3\n1 1 1", "output": "6 0 0"}] | 1,500 | ["implementation"] | 35 | [{"input": "4\r\n1 2 1 2\r\n", "output": "7 3 0 0 \r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "6 0 0 \r\n"}, {"input": "10\r\n9 1 5 2 9 2 9 2 1 1\r\n", "output": "18 30 0 0 1 0 0 0 6 0 \r\n"}, {"input": "50\r\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 47 22 34 21 21 30 7 22 21 32... | false | stdio | null | true |
19/A | 19 | A | Python 3 | TESTS | 3 | 92 | 0 | 217704800 | class Solve:
def __init__(self) -> None:
self.n = 0;
self.team = dict();
def vao(self) -> None:
self.n = int(input());
for _ in range(self.n):
x = input();
self.team[x] = 0;
def tinhDiem(self, team1, team2, diem) -> None:
diem1, diem2 = ... | 29 | 92 | 0 | 158272335 | class Info:
def __init__(self, newTeamName, newPoints, newGoalDiff, newScoredGoals):
self.teamName = newTeamName
self.points = newPoints
self.goalDiff = newGoalDiff
self.scoredGoals = newScoredGoals
def __str__(self):
return f"[teamName: '{self.teamName}',points: {self.p... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
467/D | 467 | D | Python 3 | TESTS | 0 | 15 | 307,200 | 213192184 | from sys import stdin
from collections import defaultdict
def main():
num = {}
stdin.readline()
essay = []
for word in stdin.readline().strip().lower().split():
count_r = word.count('r')
length = len(word)
num.setdefault(word, len(num))
essay.append((count_r, length, num... | 68 | 311 | 36,454,400 | 229763337 | if 1:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input... | Codeforces Round 267 (Div. 2) | CF | 2,014 | 2 | 256 | Fedor and Essay | After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all... | The first line contains a single integer m (1 ≤ m ≤ 105) — the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed 105 characters.
The next line contains a single integer n (0 ≤ n ... | Print two integers — the minimum number of letters «R» in an optimal essay and the minimum length of an optimal essay. | null | null | [{"input": "3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y", "output": "2 6"}, {"input": "2\nRuruRu fedya\n1\nruruRU fedor", "output": "1 10"}] | 2,400 | ["dfs and similar", "dp", "graphs", "hashing", "strings"] | 68 | [{"input": "3\r\nAbRb r Zz\r\n4\r\nxR abRb\r\naA xr\r\nzz Z\r\nxr y\r\n", "output": "2 6\r\n"}, {"input": "2\r\nRuruRu fedya\r\n1\r\nruruRU fedor\r\n", "output": "1 10\r\n"}, {"input": "1\r\nffff\r\n1\r\nffff r\r\n", "output": "0 4\r\n"}, {"input": "2\r\nYURA YUrA\r\n1\r\nyura fedya\r\n", "output": "0 10\r\n"}, {"input... | false | stdio | null | true |
959/B | 959 | B | Python 3 | TESTS | 2 | 30 | 0 | 212073868 | n, k, m = map(int, input().split())
d = dict()
x = list(map(str, input().split()))
a = list(map(int, input().split()))
#for i in range(n):
# d[x[i]] = a[i]
#print(d)
for i in range(k):
y = list(map( int, input().split()))
if y[0] > 1:
y = y[1::]
for i in range(len(y)-1):
#print(a... | 22 | 249 | 40,038,400 | 189251762 | import sys
input = sys.stdin.buffer.readline
n, k, m = map(int, input().split())
s = [x.decode() for x in input().split()]
a = [int(x) for x in input().split()]
for _ in range(k) :
x, *b = map(int, input().split())
mn = min(a[i - 1] for i in b)
for i in b :
a[i - 1] = mn
c = {x : i for i, x ... | Codeforces Round 473 (Div. 2) | CF | 2,018 | 2 | 256 | Mahmoud and Ehab and the message | Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the i-th word can be sent with cost ai. For each word in his messa... | The first line of input contains integers n, k and m (1 ≤ k ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains n strings consisting of lowercase English letters of length not exceeding 20 wh... | The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning. | null | In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | [{"input": "5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second", "output": "107"}, {"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second", "output": "116"}] | 1,200 | ["dsu", "greedy", "implementation"] | 22 | [{"input": "5 4 4\r\ni loser am the second\r\n100 1 1 5 10\r\n1 1\r\n1 3\r\n2 2 5\r\n1 4\r\ni am the second\r\n", "output": "107"}, {"input": "5 4 4\r\ni loser am the second\r\n100 20 1 5 10\r\n1 1\r\n1 3\r\n2 2 5\r\n1 4\r\ni am the second\r\n", "output": "116"}, {"input": "1 1 1\r\na\r\n1000000000\r\n1 1\r\na\r\n", "o... | false | stdio | null | true |
732/D | 732 | D | PyPy 3-64 | TESTS | 0 | 30 | 0 | 231111067 | N,K=map(int,input().split())
A=[int(x)-1 for x in input().split()]
P=[int(x) for x in input().split()]
def judge(X):
last_day = [-1]*K
for d in range(X):
if A[d]!=-1:
last_day[A[d]]=d
if min(last_day)==-1:
return False
last_day_ls = [(a,i) for i,a in enumerate(last_day)]
... | 53 | 218 | 13,926,400 | 208657531 | import sys
from heapq import heappush, heappop
# https://codeforces.com/problemset/problem/732/D
params = sys.stdin.readline().split(' ')
n = int(params[0])
m = int(params[1])
d = [int(d) for d in sys.stdin.readline().split(' ')]
exams = [int(e) for e in sys.stdin.readline().split(' ')]
# Minimal time for doi... | Codeforces Round 377 (Div. 2) | CF | 2,016 | 1 | 256 | Exams | Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m.
About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day.
On e... | The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects.
The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed t... | Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. | null | In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day.
In the second example Vasiliy should prepare for the exam number 3 during the first four d... | [{"input": "7 2\n0 1 0 2 1 0 2\n2 1", "output": "5"}, {"input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "output": "9"}, {"input": "5 1\n1 1 1 1 1\n5", "output": "-1"}] | 1,700 | ["binary search", "greedy", "sortings"] | 53 | [{"input": "7 2\r\n0 1 0 2 1 0 2\r\n2 1\r\n", "output": "5\r\n"}, {"input": "10 3\r\n0 0 1 2 3 0 2 0 1 2\r\n1 1 4\r\n", "output": "9\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "-1\r\n"}, {"input": "100 10\r\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8... | false | stdio | null | true |
19/A | 19 | A | PyPy 3 | TESTS | 3 | 122 | 0 | 164372330 | a = []
n = int(input())
for i in range(0, n):
a.append(input())
points = []
for j in range(0, n*(n-1)//2):
s = input()
teams = []
goals = []
d = ""
for k in range(0, len(s)):
if s[k] == "-" or s[k] == " ":
teams.append(d)
d = ""
if s[k] == " ":
... | 29 | 92 | 0 | 195020000 | d = {}
n = int(input())
for _ in range(n):
# idx 0: pts
# idx 1: diff
# idx 2: goals scored
d[input()] = [0, 0, 0]
for _ in range(n*(n-1) // 2):
pair, result = input().split()
team1, team2 = pair.split('-')
sc1, sc2 = map(int, result.split(':'))
d[team1][1] += sc1 - sc2
d[team... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
320/B | 320 | B | Python 3 | TESTS | 3 | 92 | 0 | 193923340 | def insert(a, b, num):
#who are my neighbors?
connections[num] = set()
for v in vertices:
if vertices[v][0]<a<vertices[v][1] or vertices[v][0]<b<vertices[v][1]:
connections[num].add(v)
connections[v].add(num)
vertices[num] = (a, b)
#who are my connections?
visited = [0]*(num+1)
queue = ... | 24 | 92 | 0 | 192405239 | import sys
intervals = []
def depth_first_search(z, temp):
if (temp[z] != -1):
return temp[z]
temp[z] = 0
for i in range(len(intervals)):
if ((intervals[z][0] > intervals[i][0]) and (intervals[z][0] < intervals[i][1])) or \
((intervals[z][1] > intervals[i][0]) and (intervals[z][1] ... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
320/B | 320 | B | PyPy 3-64 | TESTS | 3 | 92 | 0 | 222823967 | from collections import defaultdict
def insert(graph, intervals, count, a, b):
if count not in graph:
graph[count] = set()
for node in graph:
(x, y) = intervals[node]
if x < a < y or x < b < y:
graph[node].add(count)
graph[count].add(node)
def dfs(graph, src,... | 24 | 92 | 0 | 207542094 | # /**
# * author: brownfox2k6
# * created: 28/05/2023 14:35:05 Hanoi, Vietnam
# **/
intervals = [[-1, -1]]
size = 1
for _ in range(int(input())):
a, x, y = map(int, input().split())
if a == 1:
intervals.append([x, y])
size += 1
else:
vis = [False for _ in range(size)... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
320/B | 320 | B | PyPy 3-64 | TESTS | 3 | 92 | 0 | 223538769 | nodes = []
parents = []
ranks = []
def findParent(spot):
return spot if parents[spot] == spot else findParent(parents[spot])
def union(spot1, spot2):
parent1 = findParent(spot1)
parent2 = findParent(spot2)
if parent1 != parent2:
if ranks[parent1] >= ranks[parent2]:
parents[pare... | 24 | 92 | 0 | 224539159 | def add_interval(graph, intervals, x, y):
interval_id = len(intervals)
intervals.append((x, y))
graph.append([])
for i, interval in enumerate(intervals[:-1]):
if (x < interval[0] < y) or (x < interval[1] < y):
graph[i].append(interval_id)
if (interval[0] < x < interval[1]) o... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
959/D | 959 | D | PyPy 3 | TESTS | 2 | 234 | 26,009,600 | 177903058 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def fast_prime_factorization(n):
d = [(i + 1) % 2 * 2 for i in range(n + 1)]
d[0], d[1] = 0, 1
for i in range(3, n + 1):
if d[i]:
continue
for j in range(i, n + 1, 2 * i):
if not d[j]:
... | 55 | 1,091 | 127,283,200 | 201584351 | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().rstrip()
inp = lambda dtype: [dtype(x) for x in input().split()]
debug = lambda *x: print(*x, file=sys.stderr)
ceil_ = lambda a, b: (a + b - 1) // b
sum_n = lambda n: (n * (n + 1)) // 2
get_bit = lambda x, i: (x >> i) & 1
Mint, Mlo... | Codeforces Round 473 (Div. 2) | CF | 2,018 | 3 | 256 | Mahmoud and Ehab and another array construction task | Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:
- b is lexicographically greater than or equal to a.
- bi ≥ 2.
- b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divi... | The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b.
The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a. | Output n space-separated integers, the i-th of them representing bi. | null | Note that in the second sample, the array is already pairwise coprime so we printed it. | [{"input": "5\n2 3 5 4 13", "output": "2 3 5 7 11"}, {"input": "3\n10 3 7", "output": "10 3 7"}] | 1,900 | ["constructive algorithms", "greedy", "math", "number theory"] | 55 | [{"input": "5\r\n2 3 5 4 13\r\n", "output": "2 3 5 7 11 "}, {"input": "3\r\n10 3 7\r\n", "output": "10 3 7 "}, {"input": "5\r\n7 10 2 5 5\r\n", "output": "7 10 3 11 13 "}, {"input": "7\r\n20 9 7 6 7 9 15\r\n", "output": "20 9 7 11 13 17 19 "}, {"input": "10\r\n5 3 2 2 3 3 3 4 2 5\r\n", "output": "5 3 2 7 11 13 17 19 23... | false | stdio | null | true |
777/C | 777 | C | PyPy 3-64 | TESTS | 2 | 248 | 29,593,600 | 174562230 | import sys
input = sys.stdin.buffer.readline
def process(A, Q):
n = len(A)
m = len(A[0])
k = len(Q)
queries = [[] for i in range(n+1)]
answer = ['No' for i in range(k)]
for i in range(k):
l, r = Q[i]
if l==r:
answer[i] = 'Yes'
else:
queries[r].ap... | 114 | 264 | 34,099,200 | 230765900 | import sys
input = sys.stdin.readline
m, n = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(m)]
dp = [[0] * n for _ in range(m)]
mx = [0] * m
for i in range(m - 2,-1,-1):
for j in range(n):
if grid[i][j] <= grid[i + 1][j]:
dp[i][j] = dp[i + 1][j] + 1
mx[i] =... | Codeforces Round 401 (Div. 2) | CF | 2,017 | 1 | 256 | Alyona and Spreadsheet | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in... | The first line of the input contains two positive integers n and m (1 ≤ n·m ≤ 100 000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines co... | Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | null | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | [{"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "output": "Yes\nNo\nYes\nYes\nYes\nNo"}] | 1,600 | ["binary search", "data structures", "dp", "greedy", "implementation", "two pointers"] | 114 | [{"input": "5 4\r\n1 2 3 5\r\n3 1 3 2\r\n4 5 2 3\r\n5 5 3 2\r\n4 4 3 4\r\n6\r\n1 1\r\n2 5\r\n4 5\r\n3 5\r\n1 3\r\n1 5\r\n", "output": "Yes\r\nNo\r\nYes\r\nYes\r\nYes\r\nNo\r\n"}, {"input": "1 1\r\n1\r\n1\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "10 1\r\n523130301\r\n127101624\r\n15573616\r\n703140639\r\n628818570\r... | false | stdio | null | true |
652/F | 652 | F | PyPy 3-64 | TESTS | 3 | 62 | 0 | 176110242 | n,l,t=map(int,input().split())
ants=[]
last=[]
xwi=[]
for i in range(n):
x,w=input().split()
x=int(x)
if w=='L':
w=2
else:
w=1
xwi.append((x,w,i))
xwi.sort(key=lambda x:x[0])
for i in range(n):
x,w=xwi[i][:2]
ants.append((x,w))
if w==1:
last.append(((x+t)%l,1,i))
else:
last.append(((... | 30 | 1,357 | 45,772,800 | 144095748 | I = lambda: [int(i) for i in input().split()]
import sys
input = sys.stdin.readline
n, L, T = I()
a, b = [0]*n, [0]*n
ans = [0] * n
cnt = 0
for i in range(n):
x, ch = input().split()
a[i] = int(x) - 1
b[i] = (a[i], i)
if ch == "R":
w = a[i] + T
a[i] = (a[i] + T) % L
... | Educational Codeforces Round 10 | ICPC | 2,016 | 2 | 256 | Ants on a Circle | n ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the all ants are dis... | The first line contains three integers n, m and t (2 ≤ n ≤ 3·105, 2 ≤ m ≤ 109, 0 ≤ t ≤ 1018) — the number of ants, the length of the circle and the number of time units.
Each of the next n lines contains integer si and symbol di (1 ≤ si ≤ m and di is either L or R) — the position and the direction of the i-th ant at t... | Print n integers xj — the position of the j-th ant after t units of time. The ants are numbered from 1 to n in order of their appearing in input. | null | null | [{"input": "2 4 8\n1 R\n3 L", "output": "1 3"}, {"input": "4 8 6\n6 R\n5 L\n1 R\n8 L", "output": "7 4 2 7"}, {"input": "4 8 2\n1 R\n5 L\n6 L\n8 R", "output": "3 3 4 2"}] | 2,800 | ["constructive algorithms", "math"] | 30 | [{"input": "2 4 8\r\n1 R\r\n3 L\r\n", "output": "1 3\r\n"}, {"input": "4 8 6\r\n6 R\r\n5 L\r\n1 R\r\n8 L\r\n", "output": "7 4 2 7\r\n"}, {"input": "4 8 2\r\n1 R\r\n5 L\r\n6 L\r\n8 R\r\n", "output": "3 3 4 2\r\n"}, {"input": "10 10 90\r\n2 R\r\n1 R\r\n3 L\r\n4 R\r\n7 L\r\n8 L\r\n6 R\r\n9 R\r\n5 R\r\n10 L\r\n", "output":... | false | stdio | null | true |
626/D | 626 | D | Python 3 | TESTS | 4 | 249 | 0 | 20326015 | def main():
n = int(input())
a = list(map(int, input().split()))
max_element = max(a) + 1
diff_freq = [0 for i in range(max_element)]
a.sort()
for i in range(n):
for j in range(i):
diff_freq[a[i] - a[j]] += 1
largest = [0 for i in range(max_element)]
for i in range(ma... | 34 | 186 | 3,481,600 | 178622675 | n = int(input())
a = [int(x) for x in input().split()]
diff = [0] * 5000
for i in range(n):
for j in range(i + 1, n):
(A, B) = (a[i], a[j]) if a[i] < a[j] else (a[j], a[i])
diff[B - A] += 1
suff = [0] * 5000
suff[-1] = diff[-1]
for i in range(len(suff) - 2, -1, -1):
suff[i] = diff[i] + suff[i... | 8VC Venture Cup 2016 - Elimination Round | CF | 2,016 | 2 | 256 | Jerry's Protest | Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t... | The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar.
The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. | Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. 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. ... | null | In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.
In the second case, each game could've had three outcomes — 10 - 2, 10 ... | [{"input": "2\n1 2", "output": "0.0000000000"}, {"input": "3\n1 2 10", "output": "0.0740740741"}] | 1,800 | ["brute force", "combinatorics", "dp", "probabilities"] | 34 | [{"input": "2\r\n1 2\r\n", "output": "0.0000000000\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "0.0740740741\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "0.0000000000\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "0.0416666667\r\n"}, {"input": "11\r\n1 2 4 8 16 32 64 128 256 512 1024\r\n", "output": "0.2773433509\r... | false | stdio | import sys
def main():
if len(sys.argv) != 4:
print("Usage: checker.py input_path output_path submission_output_path")
sys.exit(1)
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read reference output
try:
with open(output_path, 'r') ... | true |
959/D | 959 | D | Python 3 | TESTS | 2 | 30 | 0 | 170709356 | import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------func-----------------------------------------#
####################... | 55 | 1,107 | 13,004,800 | 161949830 | def get_primes(n):
sieve = [True] * n
p = []
for i in range(2, n):
if sieve[i]:
p.append(i)
for j in range(i * i, n, i):
sieve[j] = False
return p
def prime_factors(a, p):
f = []
for x in p:
if x * x > a:
break
if a % ... | Codeforces Round 473 (Div. 2) | CF | 2,018 | 3 | 256 | Mahmoud and Ehab and another array construction task | Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:
- b is lexicographically greater than or equal to a.
- bi ≥ 2.
- b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divi... | The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b.
The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a. | Output n space-separated integers, the i-th of them representing bi. | null | Note that in the second sample, the array is already pairwise coprime so we printed it. | [{"input": "5\n2 3 5 4 13", "output": "2 3 5 7 11"}, {"input": "3\n10 3 7", "output": "10 3 7"}] | 1,900 | ["constructive algorithms", "greedy", "math", "number theory"] | 55 | [{"input": "5\r\n2 3 5 4 13\r\n", "output": "2 3 5 7 11 "}, {"input": "3\r\n10 3 7\r\n", "output": "10 3 7 "}, {"input": "5\r\n7 10 2 5 5\r\n", "output": "7 10 3 11 13 "}, {"input": "7\r\n20 9 7 6 7 9 15\r\n", "output": "20 9 7 11 13 17 19 "}, {"input": "10\r\n5 3 2 2 3 3 3 4 2 5\r\n", "output": "5 3 2 7 11 13 17 19 23... | false | stdio | null | true |
320/B | 320 | B | PyPy 3-64 | TESTS | 3 | 124 | 0 | 202099216 | import sys
input = lambda: sys.stdin.readline().rstrip()
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def merge(self, a,... | 24 | 92 | 0 | 224539518 | def add_interval(graph, intervals, x, y):
interval_id = len(intervals)
intervals.append((x, y))
graph.append([])
for i, interval in enumerate(intervals[:-1]):
if (x < interval[0] < y) or (x < interval[1] < y):
graph[i].append(interval_id)
if (interval[0] < x < interval[1]) o... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
320/B | 320 | B | PyPy 3-64 | TESTS | 3 | 124 | 0 | 210664775 | from collections import deque
def bfs(g, start, finish):
q = deque()
visited = []
q.append(start)
while q:
node = q.popleft()
if node == finish:
return True
if node not in visited:
visited.append(node)
for v in g[node]:
q.appen... | 24 | 92 | 0 | 225183589 | graph = []
def build_graph(interval_list):
graph = [[] for _ in range(len(interval_list))]
for i in range(len(interval_list)):
for j in range(len(interval_list)):
if i != j:
if (interval_list[j][0] < interval_list[i][0] and interval_list[i][0] < interval_list[j][1]) or (inte... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
320/B | 320 | B | PyPy 3 | TESTS | 3 | 122 | 0 | 146674497 | def DFS(a, b) -> bool:
# int_a = intervals[a - 1]
# int_b = intervals[b - 1]
visited = [False] * len(intervals)
return DFS_helper(a, b, visited)
def DFS_helper(a, b, visited) -> bool:
if visited[a - 1]: return False
interval_a = intervals[a - 1]
interval_b = intervals[b - 1]
a_start, a_... | 24 | 92 | 102,400 | 171021087 | s, t, i = {}, list(), 1
for n in range(int(input())):
c, a, b = map(int, input().split())
if c > 1:
if b in s[a]:
print('YES')
else:
print('NO')
else:
s[i] = {i}
for j, (x,y) in enumerate(t, 1):
if (x < a and a < y) or (x < b and b < y):
... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
320/B | 320 | B | PyPy 3-64 | TESTS | 3 | 92 | 1,638,400 | 224532290 | adjlist = {}
intervals = []
n = 0
def DFS(a, b, visited):
if a == b:
return True
if visited[a] or a not in adjlist:
return False
visited[a] = True
for u in adjlist[a]:
if u == b:
return True
if DFS(u,b,visited):
visited[u] = False
retu... | 24 | 92 | 102,400 | 172295999 | import sys
from collections import deque
input = sys.stdin.readline
def inlt():
return(list(map(int,input().split())))
n = int(input())
edges = []
for i in range(n):
query = inlt()
# print("QUERY", query, i)
if query[0] == 1:
edges.append((query[1], query[2]))
else:
start = query[1]
dest = query[2]
#... | Codeforces Round 189 (Div. 2) | CF | 2,013 | 2 | 256 | Ping-Pong (Easy Version) | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | null | null | [{"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "output": "NO\nYES"}] | 1,500 | ["dfs and similar", "graphs"] | 24 | [{"input": "5\r\n1 1 5\r\n1 5 11\r\n2 1 2\r\n1 2 9\r\n2 1 2\r\n", "output": "NO\r\nYES\r\n"}, {"input": "10\r\n1 -311 -186\r\n1 -1070 -341\r\n1 -1506 -634\r\n1 688 1698\r\n2 2 4\r\n1 70 1908\r\n2 1 2\r\n2 2 4\r\n1 -1053 1327\r\n2 5 4\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "10\r\n1 -1365 -865\r\n1 1244 ... | false | stdio | null | true |
989/D | 989 | D | Python 3 | TESTS | 3 | 77 | 0 | 39679237 | inp=input('')
[n,l,wm]=list(map(float,inp.split()))
li=[]
for i in range(int(n)):
lpos,v=list(map(float,input().split()))
li.append((lpos,v))
sl=set(li)
counter=0
for e1 in sl:
for e2 in sl:
r1=e1[0]+l
r2=e2[0]+l
v1=e1[1]
v2=e2[1]
if(v1==v2):
continue
... | 30 | 841 | 6,860,800 | 39193022 | # Codeforces Round #487 (Div. 2)import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
N,L,WM = getIntList()
z = {}
z[-1] = {1:[], -1:[]}
z[0] = {1:[],... | Codeforces Round 487 (Div. 2) | CF | 2,018 | 2 | 256 | A Shade of Moonlight | The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is $$$0$$$.
There are $$$n$$$ clouds floating in the sky. Each cloud has the same length $$$l$$$. The $$$i$$$-th initially covers the range of $$$(x_i, x_i + l)$$$ (endpoints excluded). Initially, it moves at a velocity of $$$v_i... | The first line contains three space-separated integers $$$n$$$, $$$l$$$, and $$$w_\mathrm{max}$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq l, w_\mathrm{max} \leq 10^8$$$) — the number of clouds, the length of each cloud and the maximum wind speed, respectively.
The $$$i$$$-th of the following $$$n$$$ lines contains two sp... | Output one integer — the number of unordered pairs of clouds such that it's possible that clouds from each pair cover the moon at the same future moment with a proper choice of wind velocity $$$w$$$. | null | In the first example, the initial positions and velocities of clouds are illustrated below.
The pairs are:
- $$$(1, 3)$$$, covering the moon at time $$$2.5$$$ with $$$w = -0.4$$$;
- $$$(1, 4)$$$, covering the moon at time $$$3.5$$$ with $$$w = -0.6$$$;
- $$$(1, 5)$$$, covering the moon at time $$$4.5$$$ with $$$w = -... | [{"input": "5 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7 -1", "output": "4"}, {"input": "4 10 1\n-20 1\n-10 -1\n0 1\n10 -1", "output": "1"}] | 2,500 | ["binary search", "geometry", "math", "sortings", "two pointers"] | 30 | [{"input": "5 1 2\r\n-2 1\r\n2 1\r\n3 -1\r\n5 -1\r\n7 -1\r\n", "output": "4\r\n"}, {"input": "4 10 1\r\n-20 1\r\n-10 -1\r\n0 1\r\n10 -1\r\n", "output": "1\r\n"}, {"input": "1 100000000 98765432\r\n73740702 1\r\n", "output": "0\r\n"}, {"input": "10 2 3\r\n-1 -1\r\n-4 1\r\n-6 -1\r\n1 1\r\n10 -1\r\n-8 -1\r\n6 1\r\n8 1\r\n... | false | stdio | null | true |
835/D | 835 | D | PyPy 3 | TESTS | 4 | 638 | 104,140,800 | 116519645 | st=input()
n=len(st)
dp=[[0]*(n) for i in range(n)]
for i in range(n):
for j in range(i+1):
dp[i][j]=1
pt=n-2
var=0
while pt>=0:
var=pt+1
while var<n:
if st[pt]==st[var]:
dp[pt][var]=dp[pt+1][var-1]
var+=1
pt-=1
ans=[0]*(n+1)
for i in range(n):
for j in range(i,n)... | 65 | 764 | 205,926,400 | 199901359 | s = input()
n = len(s)
res = [0] * n
res[0] = n
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for i in range(n - 1):
if s[i] == s[i + 1]:
dp[i][i + 1] = 2
res[1] += 1
for length in range(2, n):
for l in range(0, n - length):
r = l + length
if s[l] !... | Codeforces Round 427 (Div. 2) | CF | 2,017 | 3 | 256 | Palindromic characteristics | Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.
A string is 1-palindrome if and only if it reads the same backward as forward.
A string is k-palindrome (k > 1) if and only if:
1. Its lef... | The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters. | Print |s| integers — palindromic characteristics of string s. | null | In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here. | [{"input": "abba", "output": "6 1 0 0"}, {"input": "abacaba", "output": "12 4 1 0 0 0 0"}] | 1,900 | ["brute force", "dp", "hashing", "strings"] | 65 | [{"input": "abba\r\n", "output": "6 1 0 0 \r\n"}, {"input": "abacaba\r\n", "output": "12 4 1 0 0 0 0 \r\n"}, {"input": "qqqpvmgd\r\n", "output": "11 3 0 0 0 0 0 0 \r\n"}, {"input": "wyemcafatp\r\n", "output": "11 1 0 0 0 0 0 0 0 0 \r\n"}] | false | stdio | null | true |
835/D | 835 | D | PyPy 3-64 | TESTS | 5 | 2,698 | 206,028,800 | 186789017 | import random
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def is_Prime(n):
if n == 1:
return False
for i in range(2, min(int(n ** (1 / 2)) + 2, n)):
if n % i == 0:
return False
return True
def random_mod():
mod = random.randint(7 * pow(10... | 65 | 889 | 114,995,200 | 97046958 | def PanlidromicCharacteristics(string):
n = len(string)
res = [[0 for i in range (n)] for j in range (n)]
count = [0 for i in range (n + 1)]
# for i in range (n):
# res[i][i] = 1
# count[1] += 1
for length in range (1, n + 1):
for i in range (n-length + 1):
j = i + length - 1
if len... | Codeforces Round 427 (Div. 2) | CF | 2,017 | 3 | 256 | Palindromic characteristics | Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.
A string is 1-palindrome if and only if it reads the same backward as forward.
A string is k-palindrome (k > 1) if and only if:
1. Its lef... | The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters. | Print |s| integers — palindromic characteristics of string s. | null | In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here. | [{"input": "abba", "output": "6 1 0 0"}, {"input": "abacaba", "output": "12 4 1 0 0 0 0"}] | 1,900 | ["brute force", "dp", "hashing", "strings"] | 65 | [{"input": "abba\r\n", "output": "6 1 0 0 \r\n"}, {"input": "abacaba\r\n", "output": "12 4 1 0 0 0 0 \r\n"}, {"input": "qqqpvmgd\r\n", "output": "11 3 0 0 0 0 0 0 \r\n"}, {"input": "wyemcafatp\r\n", "output": "11 1 0 0 0 0 0 0 0 0 \r\n"}] | false | stdio | null | true |
379/B | 379 | B | PyPy 3-64 | TESTS | 0 | 46 | 0 | 212362250 | def get_run(start,right):
s = ''
current = start
if right:
for i in put_indeces:
s += 'R' * (i - current)
s += 'P'
current = i
else:
l = len(put_indeces)
for i in range(l):
s += 'L' * (current - put_indeces[l-i-1])
s += ... | 15 | 46 | 409,600 | 144292617 | n=int(input())
a=[*map(int,input().split())]
r='PRL'*a[0]
for i in range(1,n):r+='R'+'PLR'*a[i]
print(r) | Good Bye 2013 | CF | 2,013 | 1 | 256 | New Year Present | The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.
Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided t... | The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300).
It is guaranteed that at least one ai is positive. | Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot ... | null | null | [{"input": "2\n1 2", "output": "PRPLRP"}, {"input": "4\n0 2 0 2", "output": "RPRRPLLPLRRRP"}] | 1,200 | ["constructive algorithms", "implementation"] | 15 | [{"input": "2\r\n1 2\r\n", "output": "PRPLRP"}, {"input": "4\r\n0 2 0 2\r\n", "output": "RPRRPLLPLRRRP"}, {"input": "10\r\n2 3 4 0 0 1 1 3 4 2\r\n", "output": "PRPRPRRRPRPRPRPRPLPLPLLLLLPLPLPRPRPRRRRRPRPRPLPLLLLLLPLL"}, {"input": "10\r\n0 0 0 0 0 0 0 0 1 0\r\n", "output": "RRRRRRRRPR"}, {"input": "5\r\n2 2 2 2 2\r\n", ... | false | stdio | import sys
def main(input_path, output_path, sub_output_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
with open(sub_output_path) as f:
s = f.read().strip()
if len(s) < 1 or len(s) > 10**6:
print(0)
return
... | true |
106/D | 106 | D | PyPy 3 | TESTS | 2 | 248 | 0 | 91182293 | def main():
n, m = map(int, input().split())
island = []; features = []
for _ in range(n):
s = input()
for i in range(m):
if s[i] not in "#.":
features.append((i, _))
island.append(s)
k = int(input())
#maxes = [0, 0, 0, 0]
vector = [0, 0]
f... | 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 |
383/E | 383 | E | PyPy 3-64 | TESTS | 1 | 46 | 0 | 169196973 | l = []
for _ in range(int(input())):
a = input()
for i in ["a", "e", "i", "o", "u"]:
if a.__contains__(i):
break
else:
l.append(False)
continue
l.append(True)
for _ in range(len(l)-1):
l[0]=(l[0]==l[1])
l.pop(1)
print(1 if l[0] else 0) | 68 | 3,026 | 69,324,800 | 155280550 | import sys
readline=sys.stdin.readline
N=int(readline())
dp=[0]*(1<<24)
dp[-1]=N
for _ in range(N):
bit=(1<<24)-1
for a in readline().rstrip():
a=ord(a)-97
if bit&1<<a:
bit^=1<<a
dp[bit]-=1
for i in range(24):
for bit in range((1<<24)-1,-1,-1):
if not bit&1<<i:
... | Codeforces Round 225 (Div. 1) | CF | 2,014 | 4 | 256 | Vowels | Iahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of n 3-words. A 3-word is a sequence of exactly 3 lowercase letters of the first 24 letters of the English alphabet (a to x). She decided that some of the letters are vowels, and... | The first line contains one integer, n (1 ≤ n ≤ 104). Each of the next n lines contains a 3-word consisting of 3 lowercase letters. There will be no two identical 3-words. | Print one number, the xor of the squared answers to the queries. | null | null | [{"input": "5\nabc\naaa\nada\nbcd\ndef", "output": "0"}] | 2,700 | ["combinatorics", "divide and conquer", "dp"] | 68 | [{"input": "5\r\nabc\r\naaa\r\nada\r\nbcd\r\ndef\r\n", "output": "0\r\n"}, {"input": "100\r\namd\r\namj\r\natr\r\nbcp\r\nbjm\r\ncna\r\ncpj\r\ncse\r\ndij\r\ndjp\r\ndlv\r\nebk\r\nedf\r\nelw\r\nfbr\r\nfcl\r\nfhs\r\nflo\r\nfmj\r\ngcg\r\ngen\r\nghg\r\ngvb\r\ngxx\r\nhbe\r\nhbf\r\nhgu\r\nhlv\r\nhqa\r\nibg\r\nifp\r\nima\r\nitt... | false | stdio | null | true |
840/B | 840 | B | PyPy 3 | TESTS | 3 | 93 | 0 | 203369461 | import sys
input = sys.stdin.buffer.readline
def bfs(n, g, root, A):
parent = [None for i in range(n+1)]
parent[root] = [-1, None]
depth = [[root]]
odds = [root]
depth_count = [0 for i in range(n+1)]
while True:
next_s = []
for x in depth[-1]:
for y, i in g[x]:
... | 73 | 2,979 | 87,756,800 | 167362143 | import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush... | Codeforces Round 429 (Div. 1) | CF | 2,017 | 3 | 256 | Leha and another game about graph | Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say... | The first line contains two integers n, m (1 ≤ n ≤ 3·105, n - 1 ≤ m ≤ 3·105) — number of vertices and edges.
The second line contains n integers d1, d2, ..., dn ( - 1 ≤ di ≤ 1) — numbers on the vertices.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) — edges. It's guaranteed, that graph in the ... | Print - 1 in a single line, if solution doesn't exist. Otherwise in the first line k — number of edges in a subset. In the next k lines indexes of edges. Edges are numerated in order as they are given in the input, starting from 1. | null | In the first sample we have single vertex without edges. It's degree is 0 and we can not get 1. | [{"input": "1 0\n1", "output": "-1"}, {"input": "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4", "output": "0"}, {"input": "2 1\n1 1\n1 2", "output": "1\n1"}, {"input": "3 3\n0 -1 1\n1 2\n2 3\n1 3", "output": "1\n2"}] | 2,100 | ["constructive algorithms", "data structures", "dfs and similar", "dp", "graphs"] | 73 | [{"input": "1 0\r\n1\r\n", "output": "-1\r\n"}, {"input": "4 5\r\n0 0 0 -1\r\n1 2\r\n2 3\r\n3 4\r\n1 4\r\n2 4\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1 2\r\n", "output": "1\r\n1\r\n"}, {"input": "3 3\r\n0 -1 1\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "1\r\n2\r\n"}, {"input": "10 10\r\n-1 -1 -1 -1 -1 -1 -1 -1 -1 ... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
d = list(map(int, f.readline().split()))
edges = [tuple(map(int, f.readline().split())) for _ in range(m)]
# Read submission... | true |
261/A | 261 | A | Python 3 | TESTS | 3 | 186 | 8,089,600 | 127903476 | try:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as... | 45 | 404 | 9,216,000 | 118885816 | m=int(input())
lstm = list(map(int, input().strip().split(' ')))
n=int(input())
lstn = list(map(int, input().strip().split(' ')))
m1=min(lstm)
lstn.sort(reverse=True)
i=0
s=0
while(i<n):
if i+m1<=n:
s+=sum(lstn[i:i+m1])
i+=m1
if i+2<=n:
i+=2
elif i+1<=n:
i+=1
... | Codeforces Round 160 (Div. 1) | CF | 2,013 | 2 | 256 | Maxim and Discounts | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term... | The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105).
The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices... | In a single line print a single integer — the answer to the problem. | null | In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.
In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150. | [{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}] | 1,400 | ["greedy", "sortings"] | 45 | [{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46... | false | stdio | null | true |
1006/A | 1006 | A | Python 3 | TESTS | 1 | 31 | 4,505,600 | 157613253 | num = input()
input = input()
testcase_string = input.split(' ')
testcase = []
numbers = []
for i in testcase_string:
testcase.append(int(i))
numbers.append(int(i))
count = 0
i = 0
while i < len(testcase) + count:
while i in testcase:
index = testcase.index(i)
if i % 2 == 0:
tes... | 18 | 31 | 102,400 | 208969372 | def main():
size = input()
for i in input().split():
i = int(i)
if i & 1:
print(i, end=' ')
else:
print(i - 1, end=' ')
if __name__ == '__main__':
main() | Codeforces Round 498 (Div. 3) | ICPC | 2,018 | 1 | 256 | Adjacent Replacements | Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace ea... | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | null | The first example is described in the problem statement. | [{"input": "5\n1 2 4 5 10", "output": "1 1 3 5 9"}, {"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"}] | 800 | ["implementation"] | 18 | [{"input": "5\r\n1 2 4 5 10\r\n", "output": "1 1 3 5 9\r\n"}, {"input": "10\r\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\r\n", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\r\n"}, {"input": "1\r\n999999999\r\n", "output": "999999999\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "99... | false | stdio | null | true |
43/C | 43 | C | PyPy 3 | TESTS | 2 | 154 | 20,275,200 | 129770228 | import sys
from math import sqrt,ceil,floor,gcd
from collections import Counter
input = lambda:sys.stdin.readline()
def int_arr(): return list(map(int,input().split()))
def str_arr(): return list(map(str,input().split()))
def get_str(): return map(str,input().split())
def get_int(): return map(int,input().split())
de... | 21 | 92 | 409,600 | 192525785 | a = [0] * 3
_ = input()
for n in map(int, input().split()):
a[n % 3] += 1
print(a[0] // 2 + min(a[1], a[2])) | Codeforces Beta Round 42 (Div. 2) | CF | 2,010 | 2 | 256 | Lucky Tickets | Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid a... | The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai (1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to cou... | Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together. | null | null | [{"input": "3\n123 123 99", "output": "1"}, {"input": "6\n1 1 1 23 10 3", "output": "1"}] | 1,300 | ["greedy"] | 21 | [{"input": "3\r\n123 123 99\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 23 10 3\r\n", "output": "1\r\n"}, {"input": "3\r\n43440907 58238452 82582355\r\n", "output": "1\r\n"}, {"input": "4\r\n31450303 81222872 67526764 17516401\r\n", "output": "1\r\n"}, {"input": "5\r\n83280 20492640 21552119 7655071 47966344\r\n", ... | false | stdio | null | true |
627/D | 627 | D | PyPy 3 | TESTS | 2 | 139 | 0 | 80967206 | 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 |
545/B | 545 | B | Python 3 | TESTS | 2 | 61 | 307,200 | 198691333 | def girl(s, t):
distance = 0
ls = len(s)
mas_dif = []
for i in range(ls):
if s[i] != t[i]:
mas_dif.append(i)
distance += 1
if distance%2!=0:
print("impossible")
return 0
else:
gg = ""
for i in range(len(s)-1):
if mas_dif... | 54 | 93 | 1,126,400 | 11153223 | import operator
def gen(s, t, c):
for a, b, in zip(s, t):
if c and a != b:
c -= 1
yield a
else:
yield b
s = input()
t = input()
count = len(s) - sum(map(operator.eq, s, t))
if count & 1 == 0:
print(str.join("", gen(s, t, count // 2)))
else:
prin... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Equidistant String | Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the num... | The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one. | Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).
If there are multiple possible answers, print any of them. | null | In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101. | [{"input": "0001\n1011", "output": "0011"}, {"input": "000\n111", "output": "impossible"}] | 1,100 | ["greedy"] | 54 | [{"input": "0001\r\n1011\r\n", "output": "0011\r\n"}, {"input": "000\r\n111\r\n", "output": "impossible\r\n"}, {"input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\r\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
s = f.readline().strip()
t = f.readline().strip()
n = len(s)
assert len(t) == n
with open(submission_path, 'r') as f:
submission... | true |
314/C | 314 | C | Python 3 | TESTS | 3 | 436 | 5,017,600 | 16949569 | class FenwickTree(object):
"""Interface for Binary-Indexed Tree, which stores
cumulative frequency tables. Note that original data
is not preserved in this data structure.
Construction takes O(n lg n) time;
Item access takes O(lg n) time;
Item update takes O(lg n) time."""
def __init__(sel... | 24 | 1,402 | 41,267,200 | 169478092 | import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.bu... | Codeforces Round 187 (Div. 1) | CF | 2,013 | 2 | 256 | Sereja and Subsequences | Sereja has a sequence that consists of n positive integers, a1, a2, ..., an.
First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not excee... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106). | In the single line print the answer to the problem modulo 1000000007 (109 + 7). | null | null | [{"input": "1\n42", "output": "42"}, {"input": "3\n1 2 2", "output": "13"}, {"input": "5\n1 2 3 4 5", "output": "719"}] | 2,000 | ["data structures", "dp"] | 24 | [{"input": "1\r\n42\r\n", "output": "42\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "13\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "719\r\n"}, {"input": "4\r\n11479 29359 26963 24465\r\n", "output": "927446239\r\n"}, {"input": "5\r\n5706 28146 23282 16828 9962\r\n", "output": "446395832\r\n"}, {"input": "6\r\n49... | false | stdio | null | true |
28/A | 28 | A | PyPy 3 | TESTS | 0 | 122 | 0 | 218407688 | n, m = map(int, input().split())
nails = [list(map(int, input().split())) for _ in range(n)]
rod_lengths = list(map(int, input().split()))
result = [-1] * n
for i in range(n):
x1, y1 = nails[i]
x2, y2 = nails[(i + 1) % n]
dx = abs(x2 - x1)
dy = abs(y2 - y1)
if dx > dy:
direction = 0 ... | 51 | 778 | 9,625,600 | 93132115 | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... | 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 |
797/E | 797 | E | PyPy 3 | TESTS | 7 | 639 | 8,499,200 | 214253125 | n = int(input())
a = [int(i) for i in input().split(' ')]
q = int(input())
for test in range(n):
p, k = map(int, input().split())
ans = 0
while p <= n:
p += a[p-1] + k
ans += 1
print(ans) | 53 | 685 | 137,523,200 | 158654991 | import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import math
n = int(input())
A = list(map(int, input().split()))
limit = int(math.sqrt(n))
dp = [[-1]*n for i in range(limit+1)]
for k in range(1, limit+1):
for i in range(n-1, -1, -1):
... | Educational Codeforces Round 19 | ICPC | 2,017 | 2 | 256 | Array Queries | a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap + k. There operations are applied until p becomes greater than n. ... | The first line contains one integer n (1 ≤ n ≤ 100000).
The second line contains n integers — elements of a (1 ≤ ai ≤ n for each i from 1 to n).
The third line containts one integer q (1 ≤ q ≤ 100000).
Then q lines follow. Each line contains the values of p and k for corresponding query (1 ≤ p, k ≤ n). | Print q integers, ith integer must be equal to the answer to ith query. | null | Consider first example:
In first query after first operation p = 3, after second operation p = 5.
In next two queries p is greater than n after the first operation. | [{"input": "3\n1 1 1\n3\n1 1\n2 1\n3 1", "output": "2\n1\n1"}] | 2,000 | ["brute force", "data structures", "dp"] | 53 | [{"input": "3\r\n1 1 1\r\n3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "2\r\n1\r\n1\r\n"}, {"input": "10\r\n3 5 4 3 7 10 6 7 2 3\r\n10\r\n4 5\r\n2 10\r\n4 6\r\n9 9\r\n9 2\r\n5 1\r\n6 4\r\n1 1\r\n5 6\r\n6 4\r\n", "output": "1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n2\r\n1\r\n1\r\n"}, {"input": "50\r\n6 2 5 6 10 2 5 8 9 2 9 5 10 4 3 ... | false | stdio | null | true |
545/B | 545 | B | Python 3 | TESTS | 2 | 124 | 8,192,000 | 194939999 | # def GetHammingDistance(firstString: str, secondString: str, length: int) -> int:
# result = 0
# for index in range(0, length):
# if firstString[index] != secondString[index]:
# result += 1
# return result
def GetInfo(firstString: str, secondString: str, length : int) -> lis... | 54 | 93 | 2,355,200 | 208637051 | s1 = input()
s2 = input()
nd = 0
for i in range(len(s1)):
if s1[i] != s2[i]:
nd+=1
if nd%2 != 0:
print('impossible')
else:
sm = []
n2 = 0
for i in range(len(s1)):
if s1[i] != s2[i]:
if n2 < nd/2:
sm.append(s1[i])
n2 = n2+1
else:
sm.append(s2[i])
else:
sm.append(s1[i])
print(''.join(sm)) | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Equidistant String | Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the num... | The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one. | Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).
If there are multiple possible answers, print any of them. | null | In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101. | [{"input": "0001\n1011", "output": "0011"}, {"input": "000\n111", "output": "impossible"}] | 1,100 | ["greedy"] | 54 | [{"input": "0001\r\n1011\r\n", "output": "0011\r\n"}, {"input": "000\r\n111\r\n", "output": "impossible\r\n"}, {"input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\r\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
s = f.readline().strip()
t = f.readline().strip()
n = len(s)
assert len(t) == n
with open(submission_path, 'r') as f:
submission... | true |
19/A | 19 | A | PyPy 3-64 | TESTS | 3 | 124 | 0 | 227188826 | n = int(input())
teams_names = []
t_points ={}
for i in range(n):
teams_names.append(input())
t_points[teams_names[i]] = 0
for i in range((n*(n-1))//2):
t,s = input().split()
t1, t2 = t.split('-')
s1, s2 = s.split(':')
if s1>s2:
t_points[t1] += 3
elif s2>s1:
t_points[t2] += 3
else:
t_points[... | 29 | 92 | 0 | 226368602 | # LUOGU_RID: 127228014
a=int(input());b={}
for i in range(a):b[input()]=[0,0,0]
for i in range(a*(a-1)//2):
c=input().split();c[0]=c[0].split('-');c[1]=list(map(int,c[1].split(':')));b[c[0][0]][1]+=c[1][0]-c[1][1];b[c[0][0]][2]+=c[1][0];b[c[0][1]][1]+=c[1][1]-c[1][0];b[c[0][1]][2]+=c[1][1]
if c[1][0]>c[1][1]:b[... | Codeforces Beta Round 19 | ICPC | 2,010 | 2 | 64 | World Football Cup | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features n teams (n is always even)
- the first n / 2 teams (acco... | The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /... | Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | null | null | [{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}] | 1,400 | ["implementation"] | 29 | [{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE... | false | stdio | null | true |
28/A | 28 | A | Python 3 | TESTS | 3 | 216 | 307,200 | 67613492 | n,m = map(int,input().split())
x = 0
y = 0
sx = []
sy = []
for i in range(n):
A = map(int,input().split())
A = list(A)
if A[0] in sx:
sx = sx
else:
sx.append(A[0])
if A[1] in sy:
sy = sy
else:
sy.append(A[1])
q = 2 * sx[-1] + 2 * sy[-1]
ss = map(int,i... | 51 | 92 | 204,800 | 212540864 | def main():
n, m = map(int, input().split())
nails = []
for _ in range(n):
nails.append(tuple(map(int, input().split())))
rods = list(map(int, input().split()))
rods_count1, rods_count2 = {}, {}
for i, rod in enumerate(rods):
if rod not in rods_count1:
rods_count1[rod... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.