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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
66/C | 66 | C | Python 3 | TESTS | 6 | 216 | 0 | 66515077 | import sys
filePaths = sys.stdin.readlines()
foldercount,filecount = 0,0
directory = {}
for line in filePaths:
path = list(map(str,line.split('\\')))
newFolder = False
for i in range(1,len(path)-1):
if path[i] not in directory.keys():
if i == 1:
foldercount -= 1
... | 100 | 340 | 15,564,800 | 180697838 | import sys
sys.setrecursionlimit(int(1e4))
class TrieVertex:
def __init__(self, folder):
self.child = dict()
self.files = set()
self.folder = folder
def add(v, path, k):
if k==len(path)-1:
v.files.add(path[k])
return
if path[k] not in v.child:
v.child[path[k]] = TrieVertex(path[k])
add(v.child[path... | Codeforces Beta Round 61 (Div. 2) | CF | 2,011 | 3 | 256 | Petya and File System | Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo... | Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file... | Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as fol... | null | In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1.
In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder ... | [{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfi... | 1,800 | ["data structures", "implementation"] | 100 | [{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4... | false | stdio | null | true |
358/C | 358 | C | Python 3 | TESTS | 0 | 31 | 0 | 208016548 | n = int(input())
stack, queue, deck = 0, 0, 0
for i in range(n):
inna_command = int(input())
if inna_command > 0:
if stack == 0:
print('pushStack')
stack = 1
elif queue == 0:
print('pushQueue')
queue = 1
else:
print('pushFron... | 26 | 187 | 4,300,800 | 231249531 | i, n = 0, int(input())
s = ['pushQueue'] * n
a, b, c = ' popQueue', ' popStack', ' popBack'
p = ['0', '1' + a, '2' + a + b, '3' + a + b + c]
t = []
for j in range(n):
x = int(input())
if x:
t.append((x, j))
continue
t = sorted(k for x, k in sorted(t)[-3:])
k = len(t)
if k > 0: s[i: t... | 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 |
653/D | 653 | D | PyPy 3-64 | TESTS | 43 | 311 | 11,161,600 | 206974008 | import sys
input = sys.stdin.buffer.readline
INF = float("inf")
class Dinic:
def __init__(self, n):
self.lvl = [0] * n
self.ptr = [0] * n
self.q = [0] * n
self.adj = [[] for _ in range(n)]
def add_edge(self, a, b, c, rcap=0):
self.adj[a].append([b, len(self.adj[b]),... | 47 | 1,637 | 10,342,400 | 201896750 | from collections import defaultdict, deque
def bfs(graph, start, end, parent):
parent.clear()
queue = deque()
queue.append([start, float("Inf")])
parent[start] = -2
while queue:
current, flow = queue.popleft()
for neighbor in graph[current]:
if parent[neighbor] == -1 ... | IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) | CF | 2,016 | 2 | 256 | Delivery Bears | Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.
In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge ... | The first line contains three integers n, m and x (2 ≤ n ≤ 50, 1 ≤ m ≤ 500, 1 ≤ x ≤ 100 000) — the number of nodes, the number of directed edges and the number of bears, respectively.
Each of the following m lines contains three integers ai, bi and ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 1 000 000). This represents a di... | Print one real value on a single line — the maximum amount of weight Niwel can deliver if he uses exactly x bears. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consi... | null | In the first sample, Niwel has three bears. Two bears can choose the path $$1 \rightarrow 3 \rightarrow 4$$, while one bear can choose the path $$1 \rightarrow 2 \rightarrow 4$$. Even though the bear that goes on the path $$1 \rightarrow 2 \rightarrow 4$$ can carry one unit of weight, in the interest of fairness, he is... | [{"input": "4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2", "output": "1.5000000000"}, {"input": "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30", "output": "10.2222222222"}] | 2,200 | ["binary search", "flows", "graphs"] | 47 | [{"input": "4 4 3\r\n1 2 2\r\n2 4 1\r\n1 3 1\r\n3 4 2\r\n", "output": "1.5000000000\n"}, {"input": "5 11 23\r\n1 2 3\r\n2 3 4\r\n3 4 5\r\n4 5 6\r\n1 3 4\r\n2 4 5\r\n3 5 6\r\n1 4 2\r\n2 5 3\r\n1 5 2\r\n3 2 30\r\n", "output": "10.2222222222\n"}, {"input": "10 16 63\r\n1 2 1\r\n2 10 1\r\n1 3 1\r\n3 10 1\r\n1 4 1\r\n4 10 1... | false | stdio | import sys
def main():
input_path = sys.argv[1]
correct_output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read correct output
with open(correct_output_path, 'r') as f:
correct_line = f.readline().strip()
correct = float(correct_line.split()[0])
# Read submission... | true |
877/E | 877 | E | PyPy 3 | TESTS | 3 | 108 | 20,480,000 | 123887692 | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
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.... | 57 | 1,544 | 90,316,800 | 209145397 | import math
import sys
from bisect import *
from collections import *
from functools import *
from heapq import *
from itertools import *
from random import *
from string import *
from types import GeneratorType
# region fastio
input = lambda: sys.stdin.readline().rstrip()
sint = lambda: int(input())
mint = lambda: ma... | Codeforces Round 442 (Div. 2) | CF | 2,017 | 2 | 256 | Danil and a Part-time Job | Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher.
Danil works in a rooted tree (undirected connected acyclic graph) with n vertices, vertex 1 is the root of the tree. There is a room in each vertex, light can be switched on or off in each ro... | The first line contains a single integer n (1 ≤ n ≤ 200 000) — the number of vertices in the tree.
The second line contains n - 1 space-separated integers p2, p3, ..., pn (1 ≤ pi < i), where pi is the ancestor of vertex i.
The third line contains n space-separated integers t1, t2, ..., tn (0 ≤ ti ≤ 1), where ti is 1,... | For each task get v print the number of rooms in the subtree of v, in which the light is turned on. | null | The tree before the task pow 1. The tree after the task pow 1. | [{"input": "4\n1 1 1\n1 0 0 1\n9\nget 1\nget 2\nget 3\nget 4\npow 1\nget 1\nget 2\nget 3\nget 4", "output": "2\n0\n0\n1\n2\n1\n1\n0"}] | 2,000 | ["bitmasks", "data structures", "trees"] | 57 | [{"input": "4\r\n1 1 1\r\n1 0 0 1\r\n9\r\nget 1\r\nget 2\r\nget 3\r\nget 4\r\npow 1\r\nget 1\r\nget 2\r\nget 3\r\nget 4\r\n", "output": "2\r\n0\r\n0\r\n1\r\n2\r\n1\r\n1\r\n0\r\n"}, {"input": "1\r\n\r\n1\r\n4\r\npow 1\r\nget 1\r\npow 1\r\nget 1\r\n", "output": "0\r\n1\r\n"}, {"input": "10\r\n1 2 1 3 4 5 6 8 5\r\n1 0 0 0... | false | stdio | null | true |
10/A | 10 | A | Python 3 | TESTS | 5 | 216 | 0 | 55691746 | """
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 m... | 30 | 92 | 0 | 14124795 | # import sys
# n = int(input())
# s = input().strip()
# a = [int(tmp) for tmp in input().split()]
# for i in range(n):
n, p1, p2, p3, t1, t2 = [int(tmp) for tmp in input().split()]
l = [0] * n
r = [0] * n
for i in range(n):
l[i], r[i] = [int(tmp) for tmp in input().split()]
all = 0
for i in range(n - 1):
all ... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | Power Consumption Calculation | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut... | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a... | Output the answer to the problem. | null | null | [{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}] | 900 | ["implementation"] | 30 | [{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ... | false | stdio | null | true |
10/A | 10 | A | PyPy 3 | TESTS | 5 | 186 | 1,228,800 | 106342722 | import sys
# import logging
# logging.root.setLevel(logging.INFO)
n,p1,p2,p3,t1,t2 = list(map(int,sys.stdin.readline().strip().split()))
cost = [p3] * 2000
periods = []
for _ in range(n):
period = list(map(int,sys.stdin.readline().strip().split()))
periods.append(period)
normal_end = period[1]+t1
for t... | 30 | 92 | 0 | 136566367 | if __name__ == "__main__":
n, P1, P2, P3, T1, T2 = map(int, input().split())
work_periods = []
for _ in range(n):
work_periods.append(tuple(map(int, input().split())))
result = 0
for ((start1, end1), (start2, end2)) in zip(work_periods, work_periods[1:]):
result += (end1 - start1)... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | Power Consumption Calculation | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut... | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a... | Output the answer to the problem. | null | null | [{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}] | 900 | ["implementation"] | 30 | [{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ... | false | stdio | null | true |
10/A | 10 | A | Python 3 | TESTS | 5 | 186 | 6,963,200 | 87614808 | # -*- coding: utf-8 -*-
lista,power = [],0
n,p1,p2,p3,t1,t2 = map(int,input().split())
for i in range(n):
work = list(map(int,input().split()))
lista.append(work); power += (work[1]-work[0])*p1
if len(lista) > 1:
descanso = lista[i][0]-lista[i-1][1]
if descanso <= t1: power += p1*descanso
... | 30 | 92 | 0 | 136613965 | n,p1,p2,p3,t1,t2=[int(x) for x in input().split()]
lst=[]
for i in range(n):
lst.append([int(x) for x in input().split()])
res=(lst[0][1]-lst[0][0])*p1
for i in range(1,n):
if lst[i][0]-lst[i-1][1]<=t1:
res+=(lst[i][0]-lst[i-1][1])*p1
else:
if lst[i][0]-lst[i-1][1]<t1+t2:
res+=t1*p1+(lst[i][... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | Power Consumption Calculation | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut... | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a... | Output the answer to the problem. | null | null | [{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}] | 900 | ["implementation"] | 30 | [{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ... | false | stdio | null | true |
298/A | 298 | A | Python 3 | TESTS | 9 | 62 | 0 | 149564768 | n = int(input())
data = input()
first_index = 0
last_index = 0
#get first move
for i, ch in enumerate(data):
if ch != '.':
first_index = i
break
#get last move
for j in range(n-1, 1, -1):
#print(data[j], j)
if data[j] != '.':
last_index = j
break
#print(first_index,... | 23 | 62 | 0 | 216285938 | input()
s = ' ' + input()
if 'R' in s:
if 'L' in s:
print(s.find('R'), s.find('RL'))
else:
print(s.find('R'), s.find('R.') + 1)
else:
print(s.find('L.'), s.find('.L')) | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Snow Footprints | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed t... | Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them. | null | The first test sample is the one in the picture. | [{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}] | 1,300 | ["greedy", "implementation"] | 23 | [{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
road = f.readline().strip()
with open(submission_path) as f:
line = f.readline().strip()
try:
s, t = map(int, l... | true |
298/A | 298 | A | Python 3 | TESTS | 10 | 92 | 0 | 177886782 | non=int(input())
tx=input()
if len(tx)==3:
if tx[1]=='R':
print(f'2 3')
if tx[1]=='L':
print('2 1')
else:
if 'RL' in tx:
print(tx.find('R')+1,end=' ')
print(tx.find('RL')+1)
elif "R" in tx:
print(tx.find('RR.')+2,tx.find('R.')+2)
elif "L" in tx:
... | 23 | 92 | 0 | 4611320 | n=int(input())
s=input()
if 'R' in s and 'L' in s:
print(s.index('R')+1,s.index('L'))
elif 'R' in s:
print(s.index('R')+1,n-s[::-1].index('R')+1)
else:
print(s.index('L')+1,s.index('L')) | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Snow Footprints | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed t... | Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them. | null | The first test sample is the one in the picture. | [{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}] | 1,300 | ["greedy", "implementation"] | 23 | [{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
road = f.readline().strip()
with open(submission_path) as f:
line = f.readline().strip()
try:
s, t = map(int, l... | true |
731/C | 731 | C | PyPy 3 | TESTS | 5 | 1,918 | 35,635,200 | 127828826 | class dsu():
def __init__(self,n):
self.parent=[0]*(n)
self.sz=[0]*(n)
def make_set(self,v):
self.parent[v]=v
self.sz[v]=1
def find_set(self,v):
if v==self.parent[v]:
return v
self.parent[v]=self.find_set(self.parent[v])
return self.parent[v]
def union(self,a,b):
a=self.find_set(a)
b=self.fi... | 70 | 1,107 | 31,948,800 | 132050753 | n, m, k = map(int, input().split())
lst = list(input().split())
lsta = [[] for i in range(n)]
for i in range(m):
li, ri = map(int, input().split())
lsta[li - 1].append(ri - 1)
lsta[ri - 1].append(li - 1)
visited = [False for i in range(n)]
ans = 0
for i in range(n):
if visited[i]:
continue
... | Codeforces Round 376 (Div. 2) | CF | 2,016 | 2 | 256 | Socks | Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.
Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clot... | The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively.
The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks.
Each of the fol... | Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors. | null | In the first sample, Arseniy can repaint the first and the third socks to the second color.
In the second sample, there is no need to change any colors. | [{"input": "3 2 3\n1 2 3\n1 2\n2 3", "output": "2"}, {"input": "3 2 2\n1 1 2\n1 2\n2 1", "output": "0"}] | 1,600 | ["dfs and similar", "dsu", "graphs", "greedy"] | 70 | [{"input": "3 2 3\r\n1 2 3\r\n1 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "3 2 2\r\n1 1 2\r\n1 2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1 2 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "4 2 4\r\n1 2 3 4\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "10 3 2\r\n2 1 1 2 1 1 2 1 2 2\r\n4 ... | false | stdio | null | true |
731/C | 731 | C | Python 3 | TESTS | 5 | 873 | 24,371,200 | 127332714 | n,m,k=map(int,input().split())
c=[*map(int,input().split())]
q={}
z=[*c]
l=[]
for i in range(m):
x,y=map(int,input().split())
l+=[[x,y]]
if c[x-1]!=c[y-1]:
q[c[x-1]]=q.get(c[x-1],0)+1
q[c[y-1]]=q.get(c[y-1],0)+1
if q:
for i in l:
if q[c[i[0]-1]]>q[c[i[1]-1]]:
q[c[i[0]... | 70 | 1,138 | 46,489,600 | 162030654 | import collections
n, m, k = map(int, input().split())
c = list(map(int, input().split()))
g = [set() for _ in range(n)]
for _ in range(m):
l, r = map(int, input().split())
l -= 1
r -= 1
g[l].add(r)
g[r].add(l)
total = 0
visited = [False] * n
counter = collections.Counter()
for i in range(n):
i... | Codeforces Round 376 (Div. 2) | CF | 2,016 | 2 | 256 | Socks | Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.
Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clot... | The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively.
The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks.
Each of the fol... | Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors. | null | In the first sample, Arseniy can repaint the first and the third socks to the second color.
In the second sample, there is no need to change any colors. | [{"input": "3 2 3\n1 2 3\n1 2\n2 3", "output": "2"}, {"input": "3 2 2\n1 1 2\n1 2\n2 1", "output": "0"}] | 1,600 | ["dfs and similar", "dsu", "graphs", "greedy"] | 70 | [{"input": "3 2 3\r\n1 2 3\r\n1 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "3 2 2\r\n1 1 2\r\n1 2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1 2 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "4 2 4\r\n1 2 3 4\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "10 3 2\r\n2 1 1 2 1 1 2 1 2 2\r\n4 ... | false | stdio | null | true |
10/A | 10 | A | PyPy 3 | TESTS | 5 | 154 | 0 | 139704512 | n,p1,p2,p3,t1,t2=list(map(int,input().split()))
l,r=list(map(int,input().split()))
x=r
s=(r-l)*p1
for i in range(n-1):
x=r
l,r=list(map(int,input().split()))
s=s+(r-l)*p1
t=l-x
if t>=t1+t2:
s=s+(t1*p1)+(t2*p2)+(t-(t1+t2))*p3
elif t>t1 and t<t2:
s=s+(t1*p1)+(t-t1)*p2
else:
... | 30 | 92 | 0 | 137928771 | I=lambda:map(int,input().split())
n,a,b,c,u,v=I()
exec('x=['+n*'[*I()],'+']')
r=0
for i in range(n):
r+=a*(x[i][1]-x[i][0])
if i:
t=x[i][0]-x[i-1][1]
s=min(t,u);r+=s*a;t-=s
s=min(t,v);r+=s*b;t-=s
r+=t*c
print(r) | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | Power Consumption Calculation | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut... | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a... | Output the answer to the problem. | null | null | [{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}] | 900 | ["implementation"] | 30 | [{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ... | false | stdio | null | true |
24/A | 24 | A | PyPy 3-64 | TESTS | 5 | 92 | 0 | 165467439 | n = int(input())
f = [0]*(n)
b = [0]*(n)
def find_cost(n, forward: list, backward:list):
cost = 0
node = forward[0][0]
visited = [0]*(n+1)
# visited[node] = 1
for i in range(n):
for f in range(n):
if forward[f][0] == node and not visited[forward[f][1]]:
visited[f... | 21 | 92 | 0 | 142011358 | def dfs(road):
global visited, pos, neg, roads
visited[road[0]] = True
if road[1] >= 0:
pos += road[1]
else:
neg -= road[1]
for childRoad in roads[road[0]]:
if not visited[childRoad[0]]:
dfs(childRoad)
n = int(input())
dic = {}
roads = [[] for _ in range(n)]
v... | 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 |
825/F | 825 | F | Python 3 | TESTS | 4 | 62 | 4,608,000 | 28700153 | # D
# s = input()
# t = input()
#
# count_q = s.count('?')
# set_t = set(t)
#
# c_s = {i: s.count(i) for i in set_t}
# c_s['?'] = s.count('?')
#
# c_t = {i: t.count(i) for i in set_t}
#
# max_n = sum(c_s.values()) // sum(c_t.values())
# for i in set_t:
# c_s[i] -= (c_t[i] * max_n)
#
# while True:
# ss = c_s['?... | 63 | 1,778 | 12,288,000 | 65988119 | def prefix(s):
p = [0]
for i in range(1, len(s)):
j = p[-1]
while j > 0 and s[j] != s[i]:
j = p[j - 1]
if s[i] == s[j]:
j += 1
p.append(j)
return p
s = input()
n = len(s)
ans = [0] * (n + 1)
i = n - 1
while i >= 0:
p = prefix(s[i:])
ans[i] =... | Educational Codeforces Round 25 | ICPC | 2,017 | 2 | 512 | String Compression | Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.
Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of... | The only line of input contains one string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 8000). | Output one integer number — the minimum possible length of a compressed version of s. | null | In the first example Ivan will choose this compressed version: c1 is 10, s1 is a.
In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab.
In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab. | [{"input": "aaaaaaaaaa", "output": "3"}, {"input": "abcab", "output": "6"}, {"input": "cczabababab", "output": "7"}] | 2,400 | ["dp", "hashing", "string suffix structures", "strings"] | 63 | [{"input": "aaaaaaaaaa\r\n", "output": "3\r\n"}, {"input": "abcab\r\n", "output": "6\r\n"}, {"input": "cczabababab\r\n", "output": "7\r\n"}, {"input": "kbyjorwqjk\r\n", "output": "11\r\n"}, {"input": "baaabbbaba\r\n", "output": "9\r\n"}, {"input": "aaaaaaaaaa\r\n", "output": "3\r\n"}, {"input": "cbbbcccbbc\r\n", "outpu... | false | stdio | null | true |
10/A | 10 | A | Python 3 | TESTS | 5 | 154 | 5,120,000 | 17563218 | a = list(map(int, input().split()))
n,p1,p2,p3,t1,t2 = map(int, a)
output = 0
prev = 0
for index in range(n):
safe_mode = 0
line = list(map(int, input().split()))
output += (line[1] - line[0]) * p1
if prev != 0:
safe_mode = line[0] - prev
if safe_mode > t1:
output += p1 * t1
... | 30 | 92 | 0 | 143546211 | n, p1, p2, p3, t1, t2 = map(int, input().split())
nums = []
for i in range(n):
l = list(map(int, input().split()))
nums.append(l)
ans = 0
start = 1
for i in range(n):
if start == 0:
idle = nums[i][0] - prev
if idle > t1:
ans += t1 * p1
idle -= t1
else:... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | Power Consumption Calculation | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut... | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a... | Output the answer to the problem. | null | null | [{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}] | 900 | ["implementation"] | 30 | [{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ... | false | stdio | null | true |
732/D | 732 | D | PyPy 3-64 | TESTS | 3 | 78 | 13,721,600 | 218601791 | import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
N,M = map(int, input().split())
D = list(map(int, input().split()))
A = list(map(int, input().split()))
def check(m):
seen = set()
fo... | 53 | 155 | 8,601,600 | 199733993 | n,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sums = sum(B)+len(B)
last = [-1] * m
cou = 0
ans = 0
per = 0
for j in range(n):
if A[j] == 0:
cou +=1
else:
if last[A[j]-1] == -1:
if j >= B[A[j]-1]:
... | 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 |
731/F | 731 | F | PyPy 3-64 | TESTS | 3 | 62 | 3,379,200 | 188223710 | n = int(input())
mas = [int(i) for i in input().split()]
nmax = 200001
p = [0] * (nmax + 1)
for i in range(n):
p[mas[i]] += 1
for i in range(1, nmax):
p[i] += p[i - 1]
ans = 0
for i in range(1, nmax + 1):
ma = 0
if p[i] - p[i - 1] == 0:
continue
for j in range(i, nmax - i + 1, i):
ma... | 51 | 764 | 21,299,200 | 230899484 | from bisect import bisect_left
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for k in set(a):
r = sum(n - bisect_left(a, j) for j in range(k, a[-1] + 1, k))
ans = max(ans, k * r)
print(ans) | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Video Cards | Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.
There are n video cards in the shop, the power of the i-th video card is equal to in... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards. | The only line of the output should contain one integer value — the maximum possible total power of video cards working together. | null | In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as t... | [{"input": "4\n3 2 15 9", "output": "27"}, {"input": "4\n8 2 2 7", "output": "18"}] | 1,900 | ["brute force", "data structures", "implementation", "math", "number theory"] | 51 | [{"input": "4\r\n3 2 15 9\r\n", "output": "27\r\n"}, {"input": "4\r\n8 2 2 7\r\n", "output": "18\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n123819\r\n", "output": "123819\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "52\r\n"}, {"input": "100\r\n17 23 71 25 50 71 85 46 78 72 89 26 ... | false | stdio | null | true |
491/B | 491 | B | Python 3 | TESTS | 0 | 15 | 0 | 227285235 | # LUOGU_RID: 128400103
a=[];b=[];c=0;d=1<<63;input()
for i in range(int(input())):e,f=map(int,input().split());a.append(e);b.append(f)
for i in range(int(input())):
e,f=map(int,input().split())
if sum(abs(j-e)for j in a)+sum(abs(k-f)for k in b)<d:d=sum(abs(j-e)for j in a)+sum(abs(k-f)for k in b);c=i+1
print(d);... | 28 | 1,747 | 10,035,200 | 72031483 | N, M = input().split()
a, b, c, d = [int(1e10) for _ in range(4)]
for i in range(int(input())):
x, y = list(map(int, input().split()))
a, b, c, d = min(a, x + y), min(b, x - y), min(c, - x + y), min(d, - x - y)
res, pos = int(1e10), 0
for i in range(int(input())):
x, y = list(map(int, input().split()))
... | Testing Round 11 | CF | 2,014 | 2 | 256 | New York Hotel | Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street... | The first line contains two integers N и M — size of the city (1 ≤ N, M ≤ 109). In the next line there is a single integer C (1 ≤ C ≤ 105) — the number of hotels friends stayed at. Following C lines contain descriptions of hotels, each consisting of two coordinates x and y (1 ≤ x ≤ N, 1 ≤ y ≤ M). The next line contains... | In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them. | null | null | [{"input": "10 10\n2\n1 1\n3 3\n2\n1 10\n4 4", "output": "6\n2"}] | 2,100 | ["greedy", "math"] | 28 | [{"input": "10 10\r\n2\r\n1 1\r\n3 3\r\n2\r\n1 10\r\n4 4\r\n", "output": "6\r\n2\r\n"}, {"input": "100 100\r\n10\r\n53 20\r\n97 6\r\n12 74\r\n48 92\r\n97 13\r\n47 96\r\n75 32\r\n69 21\r\n95 75\r\n1 54\r\n10\r\n36 97\r\n41 1\r\n1 87\r\n39 23\r\n27 44\r\n73 97\r\n1 1\r\n6 26\r\n48 3\r\n5 69\r\n", "output": "108\r\n4\r\n"... | false | stdio | null | true |
731/F | 731 | F | PyPy 3 | TESTS | 5 | 93 | 3,072,000 | 193084428 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
m = max(a) + 5
cnt = [0] * (m + 1)
for i in a:
cnt[i] += 1
for i in range(1, m + 1):
cnt[i] += cnt[i - 1]
ans = 0
for i in range(1, m + 1):
if not cnt[min(2 * i - 1, m)] - cn... | 51 | 155 | 32,358,400 | 215746255 | import sys
from itertools import accumulate
def main():
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().split()))
max_val = max(a)
C = [0] * (max_val + 1)
for x in a:
C[x] += 1
ans=0
C_sum = list(accumulate(C))
for x in set(a):
cnt = 0
... | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Video Cards | Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.
There are n video cards in the shop, the power of the i-th video card is equal to in... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards. | The only line of the output should contain one integer value — the maximum possible total power of video cards working together. | null | In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as t... | [{"input": "4\n3 2 15 9", "output": "27"}, {"input": "4\n8 2 2 7", "output": "18"}] | 1,900 | ["brute force", "data structures", "implementation", "math", "number theory"] | 51 | [{"input": "4\r\n3 2 15 9\r\n", "output": "27\r\n"}, {"input": "4\r\n8 2 2 7\r\n", "output": "18\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n123819\r\n", "output": "123819\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "52\r\n"}, {"input": "100\r\n17 23 71 25 50 71 85 46 78 72 89 26 ... | false | stdio | null | true |
743/E | 743 | E | Python 3 | TESTS | 5 | 46 | 0 | 23007595 | in1 = input()
in2 = input()
cards = in2.split(" ")
case = int(in1)
current = int(cards[0])
count = 1
dls = False
for i in range(0, len(cards), 1) :
if i == 0 :
continue
elif int(cards[i]) == current :
if int(cards[i-1]) == current:
if dls :
count = count + 1
dls = False
continue
else:
count =... | 41 | 233 | 24,780,800 | 192171052 | import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return (m + 1) * u + v
n = int(input())
a = list(map(int, input().split()))
m = 8
x = [[] for _ in range(m)]
for i in range(n):
x[a[i] - 1].append(i)
s = 0
for y in x:
s += min(len(y), 1)
if s < m:
... | Codeforces Round 384 (Div. 2) | CF | 2,016 | 2 | 256 | Vladik and cards | Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
- the number of occur... | The first line contains single integer n (1 ≤ n ≤ 1000) — the number of cards in Vladik's sequence.
The second line contains the sequence of n positive integers not exceeding 8 — the description of Vladik's sequence. | Print single integer — the length of the longest subsequence of Vladik's sequence that satisfies both conditions. | null | In the first sample all the numbers written on the cards are equal, so you can't take more than one card, otherwise you'll violate the first condition. | [{"input": "3\n1 1 1", "output": "1"}, {"input": "8\n8 7 6 5 4 3 2 1", "output": "8"}, {"input": "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8", "output": "17"}] | 2,200 | ["binary search", "bitmasks", "brute force", "dp"] | 41 | [{"input": "3\r\n1 1 1\r\n", "output": "1"}, {"input": "8\r\n8 7 6 5 4 3 2 1\r\n", "output": "8"}, {"input": "24\r\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\r\n", "output": "17"}, {"input": "1\r\n8\r\n", "output": "1"}, {"input": "2\r\n5 4\r\n", "output": "2"}, {"input": "3\r\n3 3 2\r\n", "output": "2"}, {"input... | false | stdio | null | true |
612/F | 612 | F | PyPy 3 | TESTS | 7 | 77 | 409,600 | 167715885 | from collections import defaultdict
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, s = map(int, input().split())
a = list(map(int, input().split()))
x = defaultdict(lambda : [])
for i in range(n):
x[a[i]].append(i)
y = list(x.keys())
m = len(y)
dp = []
inf = pow(10, 9) + 1
dp0 =... | 27 | 140 | 8,704,000 | 165028661 | import os
from re import M
import sys
from io import BytesIO, IOBase
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... | Educational Codeforces Round 4 | ICPC | 2,015 | 1 | 256 | Simba on the Circle | You are given a circular array with n elements. The elements are numbered from some element with values from 1 to n in clockwise order. The i-th cell contains the value ai. The robot Simba is in cell s.
Each moment of time the robot is in some of the n cells (at the begin he is in s). In one turn the robot can write o... | The first line contains two integers n and s (1 ≤ s ≤ n ≤ 2000) — the number of cells in the circular array and the starting position of Simba.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the number written in the i-th cell. The numbers are given for cells in order from 1 to n. Some of numbers ai can ... | In the first line print the number t — the least number of time units.
Each of the next n lines should contain the direction of robot movement and the number of cells to move in that direction. After that movement the robot writes out the number from the cell in which it turns out. The direction and the number of cell... | null | null | [{"input": "9 1\n0 1 2 2 2 1 0 1 1", "output": "12\n+0\n-3\n-1\n+2\n+1\n+2\n+1\n+1\n+1"}, {"input": "8 1\n0 1 0 1 0 1 0 1", "output": "13\n+0\n+2\n+2\n+2\n-1\n+2\n+2\n+2"}, {"input": "8 1\n1 2 3 4 5 6 7 8", "output": "7\n+0\n+1\n+1\n+1\n+1\n+1\n+1\n+1"}, {"input": "8 1\n0 0 0 0 0 0 0 0", "output": "7\n+0\n+1\n+1\n+1\n+... | 2,600 | ["dp"] | 27 | [{"input": "9 1\r\n0 1 2 2 2 1 0 1 1\r\n", "output": "12\r\n+0\r\n-3\r\n-1\r\n+2\r\n+1\r\n+2\r\n+1\r\n+1\r\n+1\r\n"}, {"input": "8 1\r\n0 1 0 1 0 1 0 1\r\n", "output": "13\r\n+0\r\n+2\r\n+2\r\n+2\r\n-1\r\n+2\r\n+2\r\n+2\r\n"}, {"input": "8 1\r\n1 2 3 4 5 6 7 8\r\n", "output": "7\r\n+0\r\n+1\r\n+1\r\n+1\r\n+1\r\n+1\r\n+... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
lines = f.read().splitlines()
n, s = map(int, lines[0].split())
a = list(map(int, lines[1].split()))
# Read reference output
wit... | true |
489/A | 489 | A | PyPy 3-64 | TESTS | 0 | 31 | 0 | 201605435 | n=int(input())
x = list(map(lambda q:int(q), input().split(" ")))
y=x.copy()
qq=x.copy()
qq.sort()
y.sort()
y.reverse()
t=0
a=[]
for i in range(n):
for j in range(n):
if y[i]==x[j]:
t+=1
m=x[n-1-i]
p=x[j]
x[n-i-1]=p
f=(j,(n-... | 22 | 140 | 5,632,000 | 197497947 | n=int(input())
lst = list(map(int, input().strip().split(' ')))
print(n)
for i in range(n):
j=lst[i:].index(min(lst[i:]))
lst[i],lst[j+i]=lst[j+i],lst[i]
print(i,j+i,end=" ")
print() | Codeforces Round 277.5 (Div. 2) | CF | 2,014 | 1 | 256 | SwapSort | In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of sw... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr... | In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per... | null | null | [{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}] | 1,200 | ["greedy", "implementation", "sortings"] | 22 | [{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
sub_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
arr = list(map(int, f.readline().split()))
with open(sub_path) as f:
lines = f.readlines()
if not lines:
... | true |
358/D | 358 | D | Python 3 | TESTS | 3 | 31 | 0 | 5353788 | n, u, v = int(input()), 0, 0
a, b, c = (list(map(int, input().split())) for i in range(3))
for i in range(n): u, v = max(v + a[i], u + b[i]), max(v + b[i], u + c[i])
print(u) | 29 | 62 | 921,600 | 4892437 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
fed_left = {0 : a[0]}
not_fed_left = {0 : b[0]}
for i in range(1, n):
fed_left[i] = max(fed_left[i-1] + b[i], not_fed_left[i-1] + a[i]) # max(fed left, fed right)
not_fed_left[i] = max(fed_le... | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Hares | Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with ca... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 1... | In a single line, print the maximum possible total joy of the hares Inna can get by feeding them. | null | null | [{"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "output": "13"}, {"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "output": "44"}, {"input": "3\n1 1 1\n1 2 1\n1 1 1", "output": "4"}] | 1,800 | ["dp", "greedy"] | 29 | [{"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n0 1 1 0\r\n", "output": "13\r\n"}, {"input": "7\r\n8 5 7 6 1 8 9\r\n2 7 9 5 4 3 1\r\n2 3 3 4 1 1 3\r\n", "output": "44\r\n"}, {"input": "3\r\n1 1 1\r\n1 2 1\r\n1 1 1\r\n", "output": "4\r\n"}, {"input": "7\r\n1 3 8 9 3 4 4\r\n6 0 6 6 1 8 4\r\n9 6 3 7 8 8 2\r\n", "output": "42\r\n"}... | false | stdio | null | true |
651/B | 651 | B | Python 3 | TESTS | 5 | 62 | 0 | 109991907 | n=int(input())
arr=sorted(list(map(int,input().split())))
t=0
i=0
j=n-1
while i<j:
if arr[i]<arr[j]:
t+=1
i+=1
else:
j-=1
print(t) | 31 | 46 | 0 | 229111689 | n = int(input())
beauty_values = list(map(int, input().split()))
def frequency_dict(arr):
freq_dict = {}
for element in arr:
if element in freq_dict:
freq_dict[element] += 1
else:
freq_dict[element] = 1
return freq_dict
beauty_values_dict = frequency_dict(beauty... | Codeforces Round 345 (Div. 2) | CF | 2,016 | 1 | 256 | Beautiful Paintings | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement. | null | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | [{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}] | 1,200 | ["greedy", "sortings"] | 31 | [{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67... | false | stdio | null | true |
388/C | 388 | C | Python 3 | TESTS | 0 | 93 | 307,200 | 69243958 | def main(args):
nPiles = int(input())
piles = []
for i in range (nPiles):
line = list(map(int, input().split(' ')))
piles.append(line[1:])
ciel = 0
jiro = 0
turn = 1
while piles:
if turn%2 != 0:
ciel += piles[0][-1]
del piles[0][-1]
turn += 1
if not piles[0]:
del piles[0]
elif... | 43 | 109 | 307,200 | 54056488 | n = int(input())
c = [list(map(int, input().split())) for _ in range(n)]
a, b = 0, 0
d = []
for i in range(n):
if len(c[i]) % 2:
a += sum(c[i][1:c[i][0]//2+1])
b += sum(c[i][c[i][0]//2+1:])
else:
a += sum(c[i][1:c[i][0]//2+1])
b += sum(c[i][c[i][0]//2+2:])
d.append(c[i][c... | Codeforces Round 228 (Div. 1) | CF | 2,014 | 1 | 256 | Fox and Card Game | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards... | Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally. | null | In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3. | [{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}] | 2,000 | ["games", "greedy", "sortings"] | 43 | [{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7... | false | stdio | null | true |
613/B | 613 | B | PyPy 3 | TESTS | 4 | 78 | 0 | 117529605 | from bisect import bisect_left,bisect_right
n,max_lim,cf,cm,cost=map(int,input().split())
arr=list(map(int,input().split()))
r_arr=arr[::]
arr.sort()
arr.append(max_lim)
pre_arr=[0]
count=1
for i in range(1,n):
pre_arr.append((arr[i]-arr[i-1]) * count + pre_arr[-1])
count+=1
pt=n
dec_cost=0
maxi=0
r_cost,col_mi... | 35 | 920 | 20,684,800 | 197615001 | f = lambda: map(int, input().split())
g = lambda: m - l * p[l - 1] + s[l]
n, A, x, y, m = f()
t = sorted((q, i) for i, q in enumerate(f()))
p = [q for q, i in t]
s = [0] * (n + 1)
for j in range(n): s[j + 1] = p[j] + s[j]
l = r = n
F = L = R = B = -1
while 1:
if p:
while l > r or g() < 0: l -= 1
b... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Skills | Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.
Along with... | The first line of the input contains five space-separated integers n, A, cf, cm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000, 0 ≤ m ≤ 1015).
The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills. | On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.
On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers s... | null | In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.
In the second test one should increase all skills to maximum. | [{"input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2"}, {"input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5"}] | 1,900 | ["binary search", "brute force", "dp", "greedy", "sortings", "two pointers"] | 35 | [{"input": "3 5 10 1 5\r\n1 3 1\r\n", "output": "12\r\n2 5 2 \r\n"}, {"input": "3 5 10 1 339\r\n1 3 1\r\n", "output": "35\r\n5 5 5 \r\n"}, {"input": "2 6 0 1 4\r\n5 1\r\n", "output": "5\r\n5 5 \r\n"}, {"input": "1 1000000000 1000 1000 1000000000000000\r\n0\r\n", "output": "1000000001000\r\n1000000000 \r\n"}, {"input": ... | false | stdio | null | true |
484/D | 484 | D | PyPy 3-64 | TESTS | 6 | 46 | 0 | 170278982 | import sys
input = sys.stdin.buffer.readline
def process(A):
n = len(A)
A.sort()
answer = 0
i1 = 0
i2 = n-1
while i1 < i2:
answer+=(A[i2]-A[i1])
i1+=1
i2-=1
print(answer)
n = int(input())
A = [int(x) for x in input().split()]
process(A) | 71 | 1,840 | 133,529,600 | 231875215 | n=int(input())
a=input().split(' ')
a+=[0]
m1=int(a[0])
m2=-int(a[0])
f=[0]*n
for i in range(0,n):
f[i]=max(m1-int(a[i]),m2+int(a[i]))
m1=max(m1,f[i]+int(a[i+1]))
m2=max(m2,f[i]-int(a[i+1]))
print(f[n-1]) | 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 |
30/C | 30 | C | Python 3 | TESTS | 7 | 186 | 0 | 51459232 | I = lambda : map(float , input().split())
n = int(input())
li = sorted ((list(I()) for i in range(n) ) ,key = lambda x : x[2] )
#print(li)
d = {}
for i in range (n) :
x1 = li[i][0] ; y1 = li[i][1] ; t1 = li[i][2] ; p1 = li[i][3] ;
#print(p1)
d[i] = p1
for j in range (i) :
x = li[j][0] ; y = li[... | 50 | 218 | 2,252,800 | 162584254 | import sys
input = sys.stdin.readline
from operator import itemgetter
n=int(input())
T=[tuple(map(float,input().split())) for i in range(n)]
T.sort(key=itemgetter(2))
DP=[0]*n
for i in range(n):
x,y,t,p=T[i]
DP[i]=p
for j in range(i):
x2,y2,t2,p2=T[j]
if (x2-x)**2+(y2-y)**2<=(t2-t)**2:... | 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 |
746/E | 746 | E | PyPy 3-64 | TESTS | 8 | 187 | 17,408,000 | 162953459 | import sys
from array import array
def solve():
global ans
mem[a[i]] -= 1
par = parity[1] < parity[0]
while be[par] <= m and be[par] in mem:
be[par] += 2
if be[par] > m:
exit(print(-1))
a[i] = be[par]
ans += 1
mem[a[i]] = 1
parity[par] += 1
input = lambda: sys.... | 19 | 374 | 34,406,400 | 191738808 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = set(a)
x = [[] for _ in range(2)]
for i in range(1, min(m, 6 * n) + 1):
if not i in s:
x[i % 2].append(i)
n2 = n // 2
c = [n2] * 2
s = set()
for i in rang... | Codeforces Round 386 (Div. 2) | CF | 2,016 | 1 | 256 | Numbers Exchange | Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written o... | The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards. | If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th num... | null | null | [{"input": "6 2\n5 6 7 9 4 5", "output": "1\n5 6 7 9 4 2"}, {"input": "8 6\n7 7 7 7 8 8 8 8", "output": "6\n7 2 4 6 8 1 3 5"}, {"input": "4 1\n4 2 1 10", "output": "-1"}] | 1,900 | ["greedy", "implementation", "math"] | 19 | [{"input": "6 2\r\n5 6 7 9 4 5\r\n", "output": "1\r\n5 6 7 9 4 2 \r\n"}, {"input": "8 6\r\n7 7 7 7 8 8 8 8\r\n", "output": "6\r\n7 2 4 6 8 1 3 5 \r\n"}, {"input": "4 1\r\n4 2 1 10\r\n", "output": "-1\r\n"}, {"input": "10 10\r\n12 13 10 20 13 10 19 15 21 11\r\n", "output": "2\r\n12 13 10 20 2 4 19 15 21 11 \r\n"}, {"inp... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
return lines
def main(input_path, correct_output_path, submission_output_path):
input_lines = read_file(input_path)
correct_lines = read_file(correct_output_path)
sub... | true |
298/A | 298 | A | PyPy 3 | TESTS | 4 | 280 | 0 | 77177368 | n=int(input())
x=input()
a=list(x)
s=0
t=0
l=[]
r=[]
for i in range(n):
if a[i]=="R":
r.append(i+1)
if a[i]=="L":
l.append(i+1)
if len(l)==0:
s=max(r)
t=s+1
elif len(r)==0:
s=min(l)
t=s-1
else:
if a.count("R")==a.count("L"):
s=a.index("R")+1
t=s+1
... | 23 | 92 | 0 | 4724497 | n = int(input())
t = input()
r, l = t.find('R'), t.find('L')
if r > 0:
if l > 0: print(r + 1, l)
else: print(r + 1, r + t[r:].find('.') + 1)
else: print(l + t[l:].find('.'), l) | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Snow Footprints | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed t... | Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them. | null | The first test sample is the one in the picture. | [{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}] | 1,300 | ["greedy", "implementation"] | 23 | [{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
road = f.readline().strip()
with open(submission_path) as f:
line = f.readline().strip()
try:
s, t = map(int, l... | true |
298/A | 298 | A | Python 3 | TESTS | 3 | 62 | 0 | 232566637 | n,rl=int(input()),input()
if "L" not in rl:print(rl.find("R")+1,rl.find(".",rl.find("R"))+1)
elif "R" not in rl:print(rl.find(".",rl.find("L")),rl.find("L")+1)
else:print(rl.find("R")+1,rl.find("L")) | 23 | 92 | 0 | 142945428 | n=int(input())
s=input()
l=n-s[::-1].find('L')
r=s.find('R')+1
if(r):
print(r,r+s.count('R'))
else:
print(l,l-s.count('L')) | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Snow Footprints | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed t... | Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them. | null | The first test sample is the one in the picture. | [{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}] | 1,300 | ["greedy", "implementation"] | 23 | [{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
road = f.readline().strip()
with open(submission_path) as f:
line = f.readline().strip()
try:
s, t = map(int, l... | true |
384/B | 384 | B | Python 3 | TESTS | 1 | 31 | 0 | 162931539 | nmk = [int(i) for i in input().split()]
n = nmk[0]
m = nmk[1]
k = nmk[2]
g = []
ans = []
anslen = 0
for z in range(n):
g.append([y for y in input().split()])
ans.append([])
if k == 0:
for i in range(m):
for j in range(i+1, m):
if g[z][i] > g[z][j]:
g[z... | 31 | 78 | 409,600 | 5775338 | n, m, k = map(int, input().split())
print(str(m * (m - 1) // 2))
for i in range(1, m):
for j in range(i + 1, m + 1):
if k == 0:
print (str(i) + " " + str(j))
else:
print(str(j) + " " + str(i)) | Codeforces Round 225 (Div. 2) | CF | 2,014 | 1 | 256 | Multitasking | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ... | The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each elemen... | On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.
If there are multiple correct answers, you can print any. | null | Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5]. | [{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}] | 1,500 | ["greedy", "implementation", "sortings", "two pointers"] | 31 | [{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2... | 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:
lines = f.read().splitlines()
n, m, k = map(int, lines[0].split())
arrays = [list(map(int, line.split())) for line in lines[1:n+1]]
try:
with... | true |
613/B | 613 | B | Python 3 | TESTS | 2 | 61 | 0 | 15396093 | __author__ = 'abdujabbor'
import operator
def calculate_strength(aa, a, cf, cm):
c = 0
_min = aa[0]
for k, v in aa.items():
if v == a:
c += 1
if v < _min:
_min = v
return c * cf + _min * cm
n, a, cf, cm, m = [int(x) for x in input().split()]
aa = [int(x) for x ... | 35 | 1,045 | 16,486,400 | 15377652 | import itertools
import bisect
n, A, cf, cm, m = [int(x) for x in input().split()]
skills = [int(x) for x in input().split()]
sorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))
bottom_lift = [0 for i in range(n)]
for i in range(1, n):
bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills[i][0] - s... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Skills | Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.
Along with... | The first line of the input contains five space-separated integers n, A, cf, cm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000, 0 ≤ m ≤ 1015).
The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills. | On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.
On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers s... | null | In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.
In the second test one should increase all skills to maximum. | [{"input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2"}, {"input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5"}] | 1,900 | ["binary search", "brute force", "dp", "greedy", "sortings", "two pointers"] | 35 | [{"input": "3 5 10 1 5\r\n1 3 1\r\n", "output": "12\r\n2 5 2 \r\n"}, {"input": "3 5 10 1 339\r\n1 3 1\r\n", "output": "35\r\n5 5 5 \r\n"}, {"input": "2 6 0 1 4\r\n5 1\r\n", "output": "5\r\n5 5 \r\n"}, {"input": "1 1000000000 1000 1000 1000000000000000\r\n0\r\n", "output": "1000000001000\r\n1000000000 \r\n"}, {"input": ... | false | stdio | null | true |
1004/D | 1004 | D | PyPy 3 | TESTS | 3 | 951 | 64,614,400 | 110583728 | def get(n,m,a,b,t):
freq=[0]*(t+1)
for i in range(n):
for j in range(m):
val=abs(i-a)+abs(j-b)
freq[val]+=1
return freq
t=int(input())
a=list(map(int,input().split()))
mx=max(a)
f=[0]*(t+1)
for i in a:
f[i]+=1
b=-1
for i in range(1,mx+1):
if f[i]==4*i:
b=i
... | 47 | 514 | 107,110,400 | 223052621 | import collections
dd = lambda: collections.defaultdict(int)
t = int(input())
cnt = [0] * t
for i in map(int, input().split()):
cnt[i] += 1
ds = [c - 2 * b + a for a, b, c in zip([0, 0] + cnt, [0] + cnt + [0], cnt + [0, 0])]
ds[0] -= 1; ds[1] -= 2; ds[2] -= 1;
def bop(D):
while D:
i = min(D)
... | Codeforces Round 495 (Div. 2) | CF | 2,018 | 2 | 256 | Sonya and Matrix | Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ... | The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^6$$$) — the number of cells in the matrix.
The second line contains $$$t$$$ integers $$$a_1, a_2, \ldots, a_t$$$ ($$$0\leq a_i< t$$$) — the values in the cells in arbitrary order. | In the first line, print two positive integers $$$n$$$ and $$$m$$$ ($$$n \times m = t$$$) — the size of the matrix.
In the second line, print two integers $$$x$$$ and $$$y$$$ ($$$1\leq x\leq n$$$, $$$1\leq y\leq m$$$) — the row number and the column number where the cell with $$$0$$$ is located.
If there are multiple... | null | You can see the solution to the first example in the legend. You also can choose the cell $$$(2, 2)$$$ for the cell where $$$0$$$ is located. You also can choose a $$$5\times 4$$$ matrix with zero at $$$(4, 2)$$$.
In the second example, there is a $$$3\times 6$$$ matrix, where the zero is located at $$$(2, 3)$$$ there... | [{"input": "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4", "output": "4 5\n2 2"}, {"input": "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1", "output": "3 6\n2 3"}, {"input": "6\n2 1 0 2 1 2", "output": "-1"}] | 2,300 | ["brute force", "constructive algorithms", "implementation"] | 47 | [{"input": "20\r\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\r\n", "output": "4 5\r\n2 2\r\n"}, {"input": "18\r\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\r\n", "output": "3 6\r\n2 3\r\n"}, {"input": "6\r\n2 1 0 2 1 2\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1 1\r\n1 1\r\n"}, {"input": "7\r\n0 1 2 3 4 2 6\r... | false | stdio | import sys
from collections import defaultdict
def read_ints(file):
return list(map(int, file.read().split()))
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
input_lines = f.read().splitlines()
t = int(input_lines[0])
a = list(map(int, input_lines[1].spl... | true |
298/A | 298 | A | Python 3 | TESTS | 7 | 218 | 307,200 | 92173839 | #
# Author: eloyhz
# Date: Sep/07/2020
#
if __name__ == '__main__':
n = int(input())
road = input()
s = t = None
for i in range(n - 1):
if road[i] == 'R' and road[i + 1] == 'L':
s = i
t = i + 1
break
if s == t == None:
right = True
if road... | 23 | 92 | 0 | 144176599 | n = input()
p = input()
s = []
t = []
for i in range(int(n)):
if p[i] == "R":
s.append(i+1)
elif p[i] == "L":
t.append(i+1)
if len(s) != 0:
if len(t) != 0:
print(str(s[0]) + " " + str(s[-1]))
else:
print(str(s[0]) + " " + str(s[-1]+1))
else:
print(str(t[-1]) + " " + s... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Snow Footprints | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed t... | Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them. | null | The first test sample is the one in the picture. | [{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}] | 1,300 | ["greedy", "implementation"] | 23 | [{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
road = f.readline().strip()
with open(submission_path) as f:
line = f.readline().strip()
try:
s, t = map(int, l... | true |
614/B | 614 | B | PyPy 3-64 | TESTS | 22 | 187 | 12,697,600 | 140157473 | from math import log10
n = int(input())
arr = list(map(int, input().split()))
zeros = 0
num = 1
for i in range(n):
if arr[i] == 0:
num=0
zeros=0
break
if (log10(arr[i]))%1==0:
zeros += (int(log10(arr[i])))
else:
num = arr[i]
ans = str(num)+'0'*zeros
if ans.count('0')... | 32 | 62 | 12,492,800 | 222637044 | n = int(input())
numbers = list(map(str, input().split()))
# Initialize the product to 1
count = 0
n = '1'
# Count the number of '1's in each beautiful number
for num in numbers:
if num == '0':
break
# Convert the number to a string and count '1's
if "1"+"0"*(len(num)-1) == num:
count ... | Codeforces Round 339 (Div. 2) | CF | 2,016 | 0.5 | 256 | Gena's Code | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en... | The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country.
It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these numbe... | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | null | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | [{"input": "3\n5 10 1", "output": "50"}, {"input": "4\n1 1 10 11", "output": "110"}, {"input": "5\n0 3 1 100 1", "output": "0"}] | 1,400 | ["implementation", "math"] | 32 | [{"input": "3\r\n5 10 1\r\n", "output": "50"}, {"input": "4\r\n1 1 10 11\r\n", "output": "110"}, {"input": "5\r\n0 3 1 100 1\r\n", "output": "0"}, {"input": "40\r\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100\r\n", "output": ... | false | stdio | null | true |
659/D | 659 | D | Python 3 | TESTS | 1 | 93 | 307,200 | 98591160 | n=int(input())
dan = 0
for i in range(n+1):
if i==0:
xa,ya = map(int,input().split())
elif i==1:
xaa,yaa = map(int,input().split())
else:
x,y=map(int,input().split())
if (xaa>xa and yaa==ya) and (y>ya and x==xa):
dan+=1
if (xaa==xa and yaa<ya) and (y==ya and x<xa):
... | 22 | 46 | 4,915,200 | 17055097 | n = int(input())
points = []
ans = 0
for i in range(n):
x1,y1 = (int(i) for i in input().split())
points+=[[x1,y1]]
for i in range(n):
x1 = points[i][0]
y1 = points[i][1]
x2 = points[(i+1)%n][0]
y2 = points[(i+1)%n][1]
x3 = points[(i+2)%n][0]
y3 = points[(i+2)%n][1]
if y1 == ... | Codeforces Round 346 (Div. 2) | CF | 2,016 | 1 | 256 | Bicycle Race | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the Ox axis from west to east, and th... | The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.
The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the poin... | Print a single integer — the number of dangerous turns on the track. | null | The first sample corresponds to the picture:
The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1. | [{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}] | 1,500 | ["geometry", "implementation", "math"] | 22 | [{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -1... | false | stdio | null | true |
651/B | 651 | B | PyPy 3-64 | TESTS | 5 | 62 | 2,048,000 | 161510050 | n=int(input())
a=[int(x) for x in input().split()]
a.sort()
l,r=0,1
for i in range(n-1):
if a[i]==a[i+1]:
for j in range(i+2,n):
if a[j]>a[i+1]:
a[i+1],a[j]=a[j],a[i+1]
ans = 0
for i in range(1,n):
if a[i]>a[i-1]:
ans+=1
print(ans) | 31 | 46 | 0 | 230732367 | def maximum_number_of_indices(nums):
n = len(nums)
count_map = {}
for x in nums:
if x not in count_map:
count_map[x] = 0
count_map[x] += 1
max_count = 0
for k in count_map:
max_count = max(max_count, count_map[k])
return n - max_count
#t = int(... | Codeforces Round 345 (Div. 2) | CF | 2,016 | 1 | 256 | Beautiful Paintings | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement. | null | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | [{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}] | 1,200 | ["greedy", "sortings"] | 31 | [{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67... | false | stdio | null | true |
358/D | 358 | D | Python 3 | TESTS | 3 | 46 | 204,800 | 5056478 | '''
Created on Nov 11, 2013
@author: Ismael
'''
import sys
def solve():
bbCum = lBB[0]
baCum = lBA[0]
abCum = lAB[0]
aaCum = lAA[0]
for i in range(1,len(lBB)):
m1 = max(baCum,aaCum)
m2 = max(bbCum,abCum)
bbCum = lBB[i] + m1
baCum = lBA[i] + m1
abCum = lAB[i... | 29 | 62 | 7,577,600 | 131618904 | n=int(input())
a=[int(v) for v in input().split()]
b=[int(v) for v in input().split()]
c=[int(v) for v in input().split()]
f=[[-100000000, -100000000] for v in range(3010)]
f[0][1]=0
for i in range(1,n+1):
f[i][1]=max(f[i-1][1] + b[i-1], f[i-1][0] + c[i-1])
f[i][0]=max(f[i-1][1] + a[i-1], f[i-1][0] + b[i-1])
pr... | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Hares | Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with ca... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 1... | In a single line, print the maximum possible total joy of the hares Inna can get by feeding them. | null | null | [{"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "output": "13"}, {"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "output": "44"}, {"input": "3\n1 1 1\n1 2 1\n1 1 1", "output": "4"}] | 1,800 | ["dp", "greedy"] | 29 | [{"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n0 1 1 0\r\n", "output": "13\r\n"}, {"input": "7\r\n8 5 7 6 1 8 9\r\n2 7 9 5 4 3 1\r\n2 3 3 4 1 1 3\r\n", "output": "44\r\n"}, {"input": "3\r\n1 1 1\r\n1 2 1\r\n1 1 1\r\n", "output": "4\r\n"}, {"input": "7\r\n1 3 8 9 3 4 4\r\n6 0 6 6 1 8 4\r\n9 6 3 7 8 8 2\r\n", "output": "42\r\n"}... | false | stdio | null | true |
652/F | 652 | F | PyPy 3-64 | TESTS | 3 | 61 | 0 | 176110805 | from sys import stdin
input=lambda :stdin.readline()[:-1]
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... | 30 | 888 | 55,091,200 | 193624502 | import os
import sys
from io import BytesIO, IOBase
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.buffer.wri... | 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 |
651/B | 651 | B | PyPy 3-64 | TESTS | 5 | 61 | 0 | 137589890 | def main_function():
n = int(input())
a = sorted([int(i) for i in input().split(" ")])
hash_a = {}
for i in a:
if i in hash_a:
hash_a[i] += 1
else:
hash_a[i] = 1
counter = 0
is_there_non_zero = True
while is_there_non_zero:
internal_counter = -... | 31 | 46 | 102,400 | 132050929 | from collections import Counter
no=int(input())
List=list(map(int,input().split()))
dic=Counter(List)
ans = 0
while dic:
ans += len(dic)-1
for i in list(dic):
dic[i] -= 1
if not dic[i]:
del dic[i]
print(ans) | Codeforces Round 345 (Div. 2) | CF | 2,016 | 1 | 256 | Beautiful Paintings | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement. | null | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | [{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}] | 1,200 | ["greedy", "sortings"] | 31 | [{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67... | false | stdio | null | true |
651/B | 651 | B | PyPy 3-64 | TESTS | 5 | 61 | 0 | 160774827 | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = []
c = 1
for i in range(1, n):
if(a[i] == a[i - 1]):
c += 1
else:
l.append(c)
c = 1
l.append(c)
c = 0
for i in range(1, len(l)):
c += min(l[i], l[i - 1])
print(c) | 31 | 46 | 102,400 | 178405122 | from heapq import heappush,heappop
from collections import deque
#t = int(input())
t = 1
for tc in range(1,t+1):
n = int(input())
#n,l = map(int,input().split())
a = list(map(int,input().split()))
#b = list(map(int,input().split()))
#s = input()
#p = input()
a.sort()
maxlowers = 0
... | Codeforces Round 345 (Div. 2) | CF | 2,016 | 1 | 256 | Beautiful Paintings | There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement. | null | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | [{"input": "5\n20 30 10 50 40", "output": "4"}, {"input": "4\n200 100 100 200", "output": "2"}] | 1,200 | ["greedy", "sortings"] | 31 | [{"input": "5\r\n20 30 10 50 40\r\n", "output": "4\r\n"}, {"input": "4\r\n200 100 100 200\r\n", "output": "2\r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 2 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n444 333\r\n", "output": "1\r\n"}, {"input": "100\r\n9 9 72 55 14 8 55 58 35 67... | false | stdio | null | true |
24/A | 24 | A | Python 3 | TESTS | 4 | 92 | 102,400 | 203464182 | from collections import defaultdict
n = int(input())
roads = defaultdict(list)
for _ in range(n):
start,end,weight = map(int,input().split())
roads[start].append((end,weight))
roads[end].append((start,-weight))
ans = [0,0]
# print(roads,"roads")
visited = set()
def dfs(start):
visited.add(start)
... | 21 | 92 | 0 | 146940370 | def findNextPath(matrix, path, index):
for i in range(len(matrix)):
if matrix[index][i] != 0 and i not in path or \
matrix[i][index] != 0 and i not in path:
return i
return -1
n = int(input())
matrix = [[0] * n for i in range(n)]
for i in range(n):
city1, city2, price =... | 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 | Python 3 | TESTS | 5 | 92 | 307,200 | 109813897 | l, a, b, p, s, n = [], {0}, {0}, [], 0, int(input())
for i in range(n):
q, w, e = map(int, input().split())
l += [[q, w]]
a.add(q)
b.add(w)
p += [e]
t = a & b
m =set(a)
k = []
a -= t
b -= t
v = []
x=set()
def cc(z):
q = l[z][1]
b=p[z]
while q in m:
for i in range(n):
... | 21 | 92 | 0 | 158971756 | def main():
n = int(input())
graph = {}
for _ in range(n):
inp = input().split()
u = int(inp[0])
v = int(inp[1])
w = int(inp[2])
if u not in graph:
graph[u] = []
if v not in graph:
graph[v] = []
graph[u].append([v,0])
... | 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 | TESTS | 6 | 248 | 0 | 56998659 | n = int(input())
e = [ [] for i in range(n)]
e2 = [ [] for i in range(n)]
C = 0
for i in range(n):
a,b,c = map(int,input().split())
a-=1
b-=1
e[a].append((b,c))
e[b].append((a,c))
e2[a].append(b)
C += c
col = [ -1 for i in range(n)]
col[0] = 0
od = 0
def dfs(n):
global od
for v in... | 21 | 92 | 0 | 165506594 | def findNextPath(cont, path, ind):
for i in range(len(cont)):
if cont[ind][i] != 0 and i not in path or \
cont[i][ind] != 0 and i not in path:
return i
return -1
N = int(input())
cont = [[0] * N for i in range(N)]
for i in range(N):
city1, city2, price = [int(item) for ... | 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 | Python 3 | TESTS | 5 | 216 | 409,600 | 73869176 | from collections import defaultdict
class Graph:
def __init__(self):
self.ActualConfig = defaultdict(int)
self.undirGraph = defaultdict(list)
self.Visited = defaultdict(bool)
self.Clock = 0
self.Total = 0
self.flag = False
def addEdge(self,fr,to,w):
self.u... | 21 | 92 | 0 | 187196677 | s, e = [0] * 101, [0] * 101
sum, val = (0, 0)
for _ in range(int(input())):
a, b, c = map(int,input().split())
if s[a] or e[b]: val += c; s[b] = e[a] = 1
else: s[a] = e[b] = 1
sum += c
print(min(val, sum - val)) | 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 |
231/A | 231 | A | Python 3 | TESTS | 4 | 92 | 0 | 226442888 | n=int(input())
count=0
sure=0
for i in range(0,n):
view=input()
for a in view:
if a=="1":
sure=sure+1
if sure>2:
count=count+1
print(count) | 21 | 62 | 0 | 226183655 | n=int(input())
t=0
while (n>0):
a1, a2 ,a3=input().split()
if int(a1)+int(a2)+int(a3)>=2:
t=t+1
n=n-1
print(t) | Codeforces Round 143 (Div. 2) | CF | 2,012 | 2 | 256 | Team | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va... | Print a single integer — the number of problems the friends will implement on the contest. | null | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | [{"input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2"}, {"input": "2\n1 0 0\n0 1 1", "output": "1"}] | 800 | ["brute force", "greedy"] | 21 | [{"input": "3\r\n1 1 0\r\n1 1 1\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "2\r\n1 0 0\r\n0 1 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1 0 0\r\n", "output": "0\r\n"}, {"input": "2\r\n1 0 0\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 0 0\r\n0 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
237/B | 237 | B | Python 3 | TESTS | 0 | 62 | 0 | 142703507 | import math
import sys
def solve():
n = int(input())
rows = list(map(int, input().split()))
r = []
cords = {}
for i in range(n):
r.append(list(map(int, input().split())))
for j in range(rows[i]):
cords[r[i][j]] = [i, j]
it = 1
ans = []
for i in range(n):... | 55 | 124 | 0 | 184964582 | n=int(input())
p=[[0,0]]
l=[0]
v=[]
for i, c in enumerate(map(int, input().split())):
p.extend([[i + 1, j + 1] for j in range(c)])
l.extend(list(map(int, input().split())))
for i in range(1, len(l)):
if l[i] != i:
j = l.index(i)
v.append(p[i] + p[j])
l[i], l[j] = l[j], l[i]
print(len... | Codeforces Round 147 (Div. 2) | CF | 2,012 | 2 | 256 | Young Table | You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1.
Let's denote s as the total number of cells of table a, that is, $$s = \sum_{i=1}^{n} c_i$$. We know that each cell of the table contains a single integer from 1 ... | The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows.
Next n lines contain table а. The i-th of them contains ci space-separated integers: th... | In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps.
In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping t... | null | null | [{"input": "3\n3 2 1\n4 3 5\n6 1\n2", "output": "2\n1 1 2 2\n2 1 3 1"}, {"input": "1\n4\n4 3 2 1", "output": "2\n1 1 1 4\n1 2 1 3"}] | 1,500 | ["implementation", "sortings"] | 55 | [{"input": "3\r\n3 2 1\r\n4 3 5\r\n6 1\r\n2\r\n", "output": "2\r\n1 1 2 2\r\n2 1 3 1\r\n"}, {"input": "1\r\n4\r\n4 3 2 1\r\n", "output": "2\r\n1 1 1 4\r\n1 2 1 3\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n14 13 4 15\r\n11 1 2 5\r\n7 6 10\r\n8 9 3\r\n12\r\n", "output": "13\r\n1 1 2 2\r\n1 2 2 3\r\n1 3 4 3\r\n1 4 4 3\r\n2 1 2 4... | 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:
lines = f.read().splitlines()
ptr = 0
n = int(lines[ptr])
ptr += 1
c = list(map(int, lines[ptr].split()))
ptr += 1
s = sum(c)
table = ... | true |
583/A | 583 | A | Python 3 | TESTS | 5 | 108 | 0 | 58902651 | R = lambda:list(map(int,input().split()))
n = int(input())
c,v,l,k = 0,0,[],[]
for i in range(n*n):
n,m = R()
if i==0:c=n;v=m
if n==m:l.append(i+1);
else:k.append(i+1)
if c==v : print(*l)
else:print(*k) | 39 | 46 | 0 | 165528867 | num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
n=int(input())
r=[0]*(n+1)
c=[0]*(n+1)
for i in range(n*n):
a,b=map(int,input().split())
if r[a]==0 and c[b]==0:
print(i+1)
r[a]=c[b]=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 |
231/A | 231 | A | Python 3 | TESTS | 4 | 92 | 0 | 232220033 | count=0
for _ in range(int(input())):
a,b,c=map(int,input().split())
if a==1 and b==1 or c!=0:
count=count+1
elif a!=1 or b==1 and c==1:
count=count+1
elif b!=0 or a==1 and c==1:
count=count+1
print(count) | 21 | 62 | 0 | 226202143 | def solve(word):
if len(word) <= 10 : return word
return f"{word[0]}{len(word)-2}{word[-1]}"
n = int(input())
p = 0
for _ in range(n):
s = sum(map(int, input().split()))
if s >= 2:
p += 1
print(p) | Codeforces Round 143 (Div. 2) | CF | 2,012 | 2 | 256 | Team | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va... | Print a single integer — the number of problems the friends will implement on the contest. | null | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | [{"input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2"}, {"input": "2\n1 0 0\n0 1 1", "output": "1"}] | 800 | ["brute force", "greedy"] | 21 | [{"input": "3\r\n1 1 0\r\n1 1 1\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "2\r\n1 0 0\r\n0 1 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1 0 0\r\n", "output": "0\r\n"}, {"input": "2\r\n1 0 0\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 0 0\r\n0 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
231/A | 231 | A | PyPy 3-64 | TESTS | 2 | 124 | 0 | 231059587 | a = []
l = 0
for d in range(int(input())):
a.append([int(i) for i in input('').split(' ')])
for x in a:
l += 1; p = 0
for b in x:
p = p + b
if p==3:
print(l)
break
elif x[0]==1 and x[1]==0 and x[2]==0:
print(l)
break | 21 | 62 | 0 | 226206112 | a=input()
b=[]
for i in range(int(a)):
c=input()
b.append(c)
d=0
for i in range(int(a)):
k=b[i]
n=k.count("1")
if(n>=2):
d+=1
print(d) | Codeforces Round 143 (Div. 2) | CF | 2,012 | 2 | 256 | Team | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va... | Print a single integer — the number of problems the friends will implement on the contest. | null | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | [{"input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2"}, {"input": "2\n1 0 0\n0 1 1", "output": "1"}] | 800 | ["brute force", "greedy"] | 21 | [{"input": "3\r\n1 1 0\r\n1 1 1\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "2\r\n1 0 0\r\n0 1 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1 0 0\r\n", "output": "0\r\n"}, {"input": "2\r\n1 0 0\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 0 0\r\n0 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
583/A | 583 | A | Python 3 | TESTS | 5 | 61 | 0 | 13402525 | n=int(input())
hor=[False]*n
ver=[False]*n
for i in range(n*n):
k=list(map(int,input().split()))
if (hor[k[0]-1]==True and ver[k[1]-1]==True):
break
if not(hor[k[0]-1]==True or ver[k[1]-1]==True):
ver[k[1]-1]=True
hor[k[0]-1]=True
print(i+1,end=' ') | 39 | 46 | 0 | 173958781 | # -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
n = int(input())
hzt = list(0 for x in range(n))
lzt = list(0 for x in range(n))
hgj = list(0 for x in range(n*n))
lgj = list(0 for x in range(n*n))
out = ""
for i in range(n*n):
inp = input().split()
hgj[i] = int(inp[0])-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,899 | 120,832,000 | 71106127 | from typing import List, Set
from random import randrange
from sys import stdin
from functools import reduce, lru_cache
def read_integers():
return list(map(int, stdin.readline().strip().split()))
@lru_cache(None)
def decompose(num: int) -> List[int]:
if num <= 1:
return []
i = 2
while 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 |
355/B | 355 | B | Python 3 | TESTS | 0 | 92 | 0 | 48968117 | s=input().split();c1,c2,c3,c4=int(s[0]),int(s[1]),int(s[2]),int(s[3])
s=input().split();n,m=int(s[0]),int(s[1]);a,b,c,d=0,0,0,0
x=input().split();y=input().split();xx=[];yy=[]
a=c1*(n+m);b=c2*(n+m);c=c3*2;d=c4
print(min(a,b,c,d)) | 27 | 46 | 307,200 | 4771087 | #PublicTransport:
costs = input().split(" ")
costs = [int(x) for x in costs]
data = input().split(" ")
totalBuses = int(data[0])
totalTrolleys = int(data[1])
buses = input().split(" ")
trolleys = input().split(" ")
buses = [int(x) for x in buses]
trolleys = [int(x) for x in trolleys]
possibleCosts = [0,0,0,0]
totalB... | Codeforces Round 206 (Div. 2) | CF | 2,013 | 1 | 256 | Vasya and Public Transport | Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m.
Public transport is not free. There are 4 types of tickets:
1. A ticket for one ride... | The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.
The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use.
The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is go... | Print a single number — the minimum sum of burles Vasya will have to spend on the tickets. | null | In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles.
In the second sample the profitable strategy is to buy one ticket of t... | [{"input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12"}, {"input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1"}, {"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16"}] | 1,100 | ["greedy", "implementation"] | 27 | [{"input": "1 3 7 19\r\n2 3\r\n2 5\r\n4 4 4\r\n", "output": "12\r\n"}, {"input": "4 3 2 1\r\n1 3\r\n798\r\n1 2 3\r\n", "output": "1\r\n"}, {"input": "100 100 8 100\r\n3 5\r\n7 94 12\r\n100 1 47 0 42\r\n", "output": "16\r\n"}, {"input": "3 103 945 1000\r\n7 9\r\n34 35 34 35 34 35 34\r\n0 0 0 0 0 0 0 0 0\r\n", "output": ... | false | stdio | null | true |
358/D | 358 | D | Python 3 | TESTS | 3 | 46 | 0 | 5348404 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
def f(i, j):
if j - i == 1: return max(a[i], b[i])
k = (i + j) // 2
u, v = a[k], a[k - 1]
a[k], b[k] = b[k], c[k]
x = f(i, k) + f(k, j)
a[k], b[k], c[k] = u, a[k], b[k]
... | 29 | 78 | 3,072,000 | 154457435 | I = lambda:list(map(int, input().split()))
n,= I()
a = I()
b = I()
c = I()
before = a[0] # choosing this before the next element
after = b[0] # choosing this after the next element
for i in range(1,n):
before, after = max(after + a[i], before + b[i]), max(after + b[i], before + c[i])
print(before) | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Hares | Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with ca... | The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 1... | In a single line, print the maximum possible total joy of the hares Inna can get by feeding them. | null | null | [{"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "output": "13"}, {"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "output": "44"}, {"input": "3\n1 1 1\n1 2 1\n1 1 1", "output": "4"}] | 1,800 | ["dp", "greedy"] | 29 | [{"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n0 1 1 0\r\n", "output": "13\r\n"}, {"input": "7\r\n8 5 7 6 1 8 9\r\n2 7 9 5 4 3 1\r\n2 3 3 4 1 1 3\r\n", "output": "44\r\n"}, {"input": "3\r\n1 1 1\r\n1 2 1\r\n1 1 1\r\n", "output": "4\r\n"}, {"input": "7\r\n1 3 8 9 3 4 4\r\n6 0 6 6 1 8 4\r\n9 6 3 7 8 8 2\r\n", "output": "42\r\n"}... | false | stdio | null | true |
245/A | 245 | A | Python 3 | TESTS | 6 | 218 | 0 | 57454249 | m=n=0
n=int(input())
for i in range(n):
count1, x, y = map(int, input().split())
if count1==1:
m+=(x-y)
else:
n+=(x-y)
if m>=0:
print('LIVE')
else:
print('DEAD')
if n>=0:
print('LIVE')
else:
print('DEAD') | 13 | 62 | 0 | 146715578 | n = int(input())
x = 0
xa = 0
y = 0
ya = 0
for i in range(n):
s = input()
s = s.split()
if s[0] == "1":
x = x + int(s[1])
xa = xa + int(s[1]) + int(s[2])
elif s[0] == "2":
y = y + int(s[1])
ya = ya + int(s[1]) + int(s[2])
if x >= xa//2:
print("LIVE")
else:
print("... | CROC-MBTU 2012, Elimination Round (ACM-ICPC) | ICPC | 2,012 | 2 | 256 | System Administrator | Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re... | The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =... | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server b in the similar format. | null | Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ... | [{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}] | 800 | ["implementation"] | 23 | [{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1... | false | stdio | null | true |
245/A | 245 | A | PyPy 3-64 | TESTS | 6 | 124 | 0 | 193245929 | n = int(input())
ping_a = 0
ping_b = 0
for _ in range(n):
t, x, y = map(int, input().split())
if t == 1:
if x >= y:
ping_a += x
else:
ping_a -= y
else:
if x >= y:
ping_b += x
else:
ping_b -= y
if ping_a >= 0:
prin... | 13 | 62 | 0 | 149083102 | a=b=0;
for _ in [0]*int(input()):
l,x,y=map(int,input().split())
if l==1:a+=x-y
else:b+=x-y
print('DLEIAVDE'[a>=0::2])
print('DLEIAVDE'[b>=0::2]) | CROC-MBTU 2012, Elimination Round (ACM-ICPC) | ICPC | 2,012 | 2 | 256 | System Administrator | Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re... | The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =... | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server b in the similar format. | null | Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ... | [{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}] | 800 | ["implementation"] | 23 | [{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1... | false | stdio | null | true |
67/A | 67 | A | PyPy 3 | TESTS | 6 | 312 | 66,457,600 | 78491182 | import sys
from math import log2,floor,ceil,sqrt,gcd
import bisect
# from collections import deque
sys.setrecursionlimit(10**5)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b ... | 43 | 186 | 7,065,600 | 36777991 | n=int(input())
s=input()
w=[1]*n
for i in range(n-1):
if s[i]=='=':
w[i+1]=w[i]
elif s[i]=='R':
if w[i+1]<=w[i]:
w[i+1]=w[i]+1
else:
if w[i]<=w[i+1]:
w[i]=w[i+1]+1
for i in range(n-2,-1,-1):
if s[i]=='=':
w[i]=w[i+1]
elif s[i]=='R':
if ... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
43/C | 43 | C | PyPy 3 | TESTS | 3 | 154 | 102,400 | 116967416 | from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())
def sm(x):
ans = 0
while x:
ans += (x % 10)
x //= 10
return ans
def solve():
n = int(input())
A = list(ri())
ans = 0
cnt = defaultdic... | 21 | 92 | 409,600 | 138404090 | def r(a):#SHIT Luogu's robot can't catch my AC
return int(a)%3
a=input();a=list(map(r,input().split()));print(a.count(0)//2+min(a.count(1),a.count(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 |
67/A | 67 | A | PyPy 3 | TESTS | 6 | 310 | 204,800 | 41874586 | n = int(input())
s = input()
ans = [1]
now = 1
d = 1
i = 0
for el in s:
if el == 'L':
now -= 1
elif el == '=':
pass
else:
now += 1
ans.append(now)
d = min(now, d)
i += 1
for el in ans:
print(el - d + 1) | 43 | 216 | 2,048,000 | 105218138 | n = int(input())
s = input()
ans = [0 for i in range(n)]
for i in range(n):
min_val = 1
if i > 0:
if s[i - 1] == '=':
ans[i] = ans[i - 1]
continue
if s[i - 1] == 'R':
min_val = ans[i - 1] + 1
cnt_low = 0
for j in range(i, n - 1):
if... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
67/A | 67 | A | PyPy 3 | TESTS | 6 | 218 | 2,150,400 | 105213737 | n = int(input())
s = input()
ans = []
best_val = 10 ** 9
cur = [0 for i in range(n)]
for fs in range(1, n + 8):
cur[0] = fs
bad = False
for i, c in enumerate(s):
if c == '=':
cur[i + 1] = cur[i]
elif c == 'L':
cur[i + 1] = cur[i] - 1
else:
c... | 43 | 218 | 0 | 41982823 | n = int(input())
p = 'R' + input() + 'R'
t = [0] * n
i = t[0] = l = r = 1
L = R = 0
while i < n + 1:
if p[i] == 'L':
if r > 1:
t[R] = r
L, r = i, 1
l += 1
elif p[i] == 'R':
if l > 1:
if t[R] < l: t[R] = l
else: t[L] = l - 1
... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
840/B | 840 | B | PyPy 3 | TESTS | 6 | 2,932 | 75,673,600 | 75710122 | # https://codeforces.com/problemset/problem/840/B
n, m = map(int, input().split())
d = list(map(int, input().split()))
g={}
def push(g, u, v, i):
if u not in g:
g[u]=[]
if v not in g:
g[v]=[]
g[u].append([v, i+1])
g[v].append([u, i+1])
for i in range(m):
u, v = map(int,... | 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 |
367/A | 367 | A | PyPy 3 | TESTS | 2 | 93 | 21,401,600 | 37013331 | s = input()
px, py, pz = ([0], [0], [0])
for i in range(len(s)):
if s[i] == 'x':
px.append(px[-1] + 1)
py.append(py[-1])
pz.append(pz[-1])
elif s[i] == 'y':
px.append(px[-1])
py.append(py[-1] + 1)
pz.append(pz[-1])
else:
px.append(px[-1])
py.ap... | 38 | 436 | 10,752,000 | 103951315 | import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
s = input().strip()
x_c, y_c, z_c = [0], [0], [0]
for el in s:
x_c.append(x_c[-1]+int(el=="x"))
y_c.append(y_c[-1]+int(el=="y"))
z_c.append(z_c[-1]+int(el=="z"))
for _ in range(int(input(... | 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 |
641/B | 641 | B | PyPy 3-64 | TESTS | 5 | 61 | 3,379,200 | 167458638 | import sys
input = sys.stdin.readline
n, m, q = map(int, input().split())
d1 = [0]*n
d2 = [0]*m
d = [[0]*m for i in range(m)]
for _ in range(q):
w = list(map(int, input().split()))
if w[0] == 1:
d1[w[1]-1] += 1
elif w[0] == 2:
d2[w[1]-1] += 1
else:
a, b, c = w[1]-1, w[2]-1, w[3... | 26 | 202 | 1,843,200 | 22010274 | import sys
import time
from pprint import pprint
from sys import stderr
from itertools import combinations
INF = 10 ** 18 + 3
EPS = 1e-10
MAX_CACHE = 10 ** 9
# Decorators
def time_it(function, output=stderr):
def wrapped(*args, **kwargs):
start = time.time()
res = function(*args, **kwargs)
... | VK Cup 2016 - Round 2 | CF | 2,016 | 2 | 256 | Little Artem and Matrix | Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There a... | The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the... | Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them. | null | null | [{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}] | 1,400 | ["implementation"] | 26 | [{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu... | false | stdio | null | true |
415/B | 415 | B | Python 3 | TESTS | 3 | 109 | 7,577,600 | 206730855 | n, a, b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = []
for i in range(n):
ans.append((c[i] * a) % b)
print(*ans) | 47 | 77 | 11,571,200 | 227718511 | i=input;d=int;n,a,b=map(d,i().split());print("".join(f'{(x*a%b)//a} 'for x in map(d,i().split()))) | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
415/B | 415 | B | Python 3 | TESTS | 3 | 109 | 10,035,200 | 24410593 | n, a, b = map(int, input().split())
x = list(map(int, input().split()))
print(' '.join( str( ( xi * a ) % b ) for xi in x ) ) | 47 | 93 | 18,227,200 | 172591635 | n, a, b = map(int, input().split())
tokens = list(map(int, input().split()))
ans = []
for t in tokens:
ans.append(((t * a) % b) // a)
print(' '.join(map(str, ans))) | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
415/B | 415 | B | Python 3 | PRETESTS | 3 | 109 | 6,246,400 | 6278757 | def main():
N, A, B = map(int, input().split())
numbers = list(map(int, input().split()))
result = []
for i in range(N):
result += [(numbers[i] * A) % B]
print(' '.join(map(str, result)))
main() | 47 | 124 | 17,510,400 | 168750648 | n, a, b = map(int, input().split(' '))
d = b/a
arr = list(map(int, input().split(' ')))
res = []
for x in arr:
q = x//d
r = x - q*d
res.append(int(r))
print(' '.join([str(x) for x in res])) | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
415/B | 415 | B | Python 3 | PRETESTS | 3 | 109 | 6,860,800 | 6280784 | import math
def f2(x, a, b):
t = math.floor(x * a / b)
r = x % t if t > 0 else x
#print(x, a, b, r)
return r
def f(x, a, b):
r = (x * a) % b
#print(x, a, b, r)
return r
n, a, b = map(int, input().split(" "))
x = list(map(int, input().split(" ")))
#r = [f(x[i], a, b) for i in range(l... | 47 | 139 | 13,619,200 | 177516683 | import sys
input = sys.stdin.readline
n, a, b = map(int, input().split())
w = list(map(int, input().split()))
for i in w:
print((i*a) % b // a, end=' ') | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
67/A | 67 | A | PyPy 3 | TESTS | 6 | 186 | 307,200 | 14437589 | n = int(input())
result = n * [ None ]
result[0] = 1
min_value = 1
for i, ch in enumerate(input().strip()):
if ch == 'L':
result[i + 1] = result[i] - 1
min_value = min(min_value, result[i + 1])
elif ch == 'R':
result[i + 1] = result[i] + 1
else:
result[i + 1] = result[i]
delt... | 43 | 248 | 921,600 | 52528999 | from collections import defaultdict
class PartialTeacher():
def __init__(self, n, prefs):
self.prefs = prefs
def create_graph(self):
num_nodes = len(list(filter(lambda x: x != '=',list(self.prefs))))+1
node_cntr = 0
node_cnts = defaultdict(lambda: 1)
edge_map = ... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
67/A | 67 | A | PyPy 3 | TESTS | 6 | 154 | 1,433,600 | 140588190 | n = int(input())
s = str(input())
res = [2000 for i in range(n)]
for i in range(n - 1):
if s[i] == "R":
res[i + 1] = 1 + res[i]
elif s[i] == "L":
res[i + 1] = res[i] - 1
else:
res[i + 1] = res[i]
d = min(res) - 1
for i in range(n):
print(res[i] - d, end=" ") | 43 | 248 | 7,065,600 | 87914373 | from collections import deque
n = int(input())
s = input()
ans = [1]*n
for i in range(1,n):
if s[i-1]=='R':
ans[i]=ans[i-1]+1
elif s[i-1]=='=':
ans[i]=ans[i-1]
for i in range(n-2, -1, -1):
if s[i]=='L':
ans[i]=max(ans[i+1]+1, ans[i])
elif s[i]=='=':
ans[i]=max(ans[i... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
415/B | 415 | B | PyPy 3-64 | TESTS | 3 | 93 | 11,059,200 | 175167120 | n,a,b = map(int,input().split())
arr = list(map(int,input().split()))
for x in arr :
print(x- (x//b) * b,end = ' ') | 47 | 140 | 14,233,600 | 177031617 | '''
# Submitted By M7moud Ala3rj
Don't Copy This Code, CopyRight . [email protected] © 2022-2023 :)
'''
# Problem Name = "Mashmokh and Tokens"
# Class: B
import sys
#sys.setrecursionlimit(2147483647)
input = sys.stdin.readline
def print(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.join(map(str, args)) ... | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
415/B | 415 | B | PyPy 3-64 | TESTS | 3 | 46 | 8,908,800 | 227717754 | n,a,b=map(int,input().split());print("".join(f'{(i*a)%b} 'for i in map(int,input().split()))) | 47 | 155 | 9,011,200 | 113085923 | n, a, b = map(int, input().split())
x = list(map(int, input().split()))
print(' '.join( str( ( ( xi * a ) % b ) // a ) for xi in x ) ) | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
415/B | 415 | B | PyPy 3-64 | TESTS | 3 | 108 | 11,571,200 | 194727465 | a,b,c=list(map(int,input().split()))
aa=list(map(int,input().split()))
from math import gcd,floor
for i in aa:
dd=(i*b/c)-floor(i*b/c)
x=(dd*c)/b
if x-floor(x)>=0.99:
print(round(x),end=" ")
else:
print(floor(x),end=" ")
print() | 47 | 155 | 9,113,600 | 15143719 | def main():
n, a, b = list(map(int, input().split()))
x_list = list(map(int, input().split()))
res = list()
for x in x_list:
res.append(str(x * a % b // a))
print(' '.join(res))
if __name__ == '__main__':
main() | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
415/B | 415 | B | Python 3 | TESTS | 3 | 93 | 5,529,600 | 158774961 | n, a, b = map(int, input().strip().split(' '));
x = map(int, input().strip().split(' '))
ans = []
for i in x:
choco = i * a // b;
i -= choco * b // a;
ans.append(str(i))
print(' '.join(ans)) | 47 | 155 | 13,926,400 | 216898932 | n,a,b = map(int,input().split())
x = list(map(int,input().split()))
for i in range(n):
Max_money = (x[i] * a)//b
Mn = (Max_money*b + (a- 1))//a
print(x[i] - Mn, end = " ")# 1691004971.4493392 | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
641/B | 641 | B | PyPy 3-64 | TESTS | 5 | 280 | 4,505,600 | 162482009 | #I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collections import defaultdict
... | 26 | 217 | 6,656,000 | 34251994 | f = lambda: map(int, input().split())
n, m, q = f()
p = [[0] * m for j in range(n)]
for t in [list(f()) for k in range(q)][::-1]:
j = t[1] - 1
if t[0] == 1: p[j].insert(0, p[j].pop())
elif t[0] == 2:
s = p[-1][j]
for i in range(n - 1, 0, -1): p[i][j] = p[i - 1][j]
p[0][j] = s
el... | VK Cup 2016 - Round 2 | CF | 2,016 | 2 | 256 | Little Artem and Matrix | Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There a... | The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the... | Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them. | null | null | [{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}] | 1,400 | ["implementation"] | 26 | [{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu... | false | stdio | null | true |
415/B | 415 | B | PyPy 3-64 | TESTS | 3 | 108 | 11,059,200 | 222464498 | n, a, b = map(int, input().split())
tokens = list(map(int, input().split()))
for i in range(n):
# Calculate the number of tokens Mashmokh can save on the i-th day
saved_tokens = (tokens[i] * a) % b #// a
print(saved_tokens, end=" ") | 47 | 155 | 15,052,800 | 115461157 | def tokens(n, a, b, arr):
arrs = []
for t in arr:
c = (t * a) % b
arrs.append(int(c / a))
arr_aux = " ".join(map(str, arrs))
return arr_aux
n, a, b = map(int, input().split())
arr = map(int, input().split())
print(tokens(n, a, b, arr)) | Codeforces Round 240 (Div. 2) | CF | 2,014 | 1 | 256 | Mashmokh and Tokens | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | null | null | [{"input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1"}, {"input": "3 1 2\n1 2 3", "output": "1 0 1"}, {"input": "1 1 1\n1", "output": "0"}] | 1,500 | ["binary search", "greedy", "implementation", "math"] | 47 | [{"input": "5 1 4\r\n12 6 11 9 1\r\n", "output": "0 2 3 1 1 "}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "1 0 1 "}, {"input": "1 1 1\r\n1\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n1000000000\r\n", "output": "0 "}, {"input": "1 1 1000000000\r\n999999999\r\n", "output": "999999999 "}, {"input": "10 1 100000000... | false | stdio | null | true |
67/D | 67 | D | Python 3 | TESTS | 2 | 122 | 0 | 27763140 | t=int(input())
a=str(input())
b=str(input())
if a[0]==b[2*t-2]:
print(a[0])
elif b[0]==a[2*t-2]:
print(b[0]) | 59 | 4,210 | 90,214,400 | 89108504 | from bisect import bisect_left as bl
I=10000000
n=int(input())+1
c=[0]*n
for i,x in enumerate(map(int,input().split())): c[x]=i
d = [n-c[int(x)] for x in input().split()]
c=[I]*n
for i in d: c[bl(c,i)]=i
print( c.index(I)) | Manthan 2011 | CF | 2,011 | 5 | 256 | Optical Experiment | Professor Phunsuk Wangdu has performed some experiments on rays. The setup for n rays is as follows.
There is a rectangular box having exactly n holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each... | The first line contains n (1 ≤ n ≤ 106), the number of rays. The second line contains n distinct integers. The i-th integer xi (1 ≤ xi ≤ n) shows that the xi-th ray enters from the i-th hole. Similarly, third line contains n distinct integers. The i-th integer yi (1 ≤ yi ≤ n) shows that the yi-th ray exits from the i-t... | Output contains the only integer which is the number of rays in the largest group of rays all of which intersect each other. | null | For the first test case, the figure is shown above. The output of the first test case is 3, since the rays number 1, 4 and 3 are the ones which are intersected by each other one i.e. 1 is intersected by 4 and 3, 3 is intersected by 4 and 1, and 4 is intersected by 1 and 3. Hence every ray in this group is intersected b... | [{"input": "5\n1 4 5 2 3\n3 4 2 1 5", "output": "3"}, {"input": "3\n3 1 2\n2 3 1", "output": "2"}] | 1,900 | ["binary search", "data structures", "dp"] | 59 | [{"input": "5\r\n1 4 5 2 3\r\n3 4 2 1 5\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 2\r\n2 3 1\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 4 5 3\r\n1 5 4 2 3\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 2\r\n1 3 2\r\n", "output": "2\r\n"}, {"input": "7\r\n1 5 2 7 4 3 6\r\n6 3 1 2 5 4 7\r\n", "output": "4\r\n"}, {"... | false | stdio | null | true |
67/A | 67 | A | Python 3 | TESTS | 6 | 124 | 4,710,400 | 10782101 | from array import array
import io
import sys
def main():
f = sys.stdin
n = int(f.readline())
s = f.readline()
k = 0
m = 0
b = {'L': -1, '=': 0, 'R': 1}
a = [0 for _ in range(n)]
for i in range(1, n):
a[i] = a[i - 1] + b[s[i - 1]]
m = min(m, a[i])
m = 1 - m
[p... | 43 | 278 | 0 | 212205722 | def ans():
n=int(input())
k=n+1
s=input()
a=[]
for i in range(n):
a.append(0)
a[n-1]=1
for i in range(len(s)-1,-1,-1):
if(s[i]=='L'):
a[i]=a[i+1]+1
elif(s[i]=='R'):
if(a[i+1]==1):
a[i+1]=2
for j in range(i+1,n-1)... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
67/A | 67 | A | Python 3 | TESTS | 6 | 124 | 5,529,600 | 26240203 | n = int(input())
difference = input()
answer = [0]
flag = ''
for i in range(1, n):
flag = difference[i - 1]
if flag == "=":
answer.append(answer[i - 1])
if flag == 'L':
answer.append(answer[i - 1] - 1)
if flag == 'R':
answer.append(answer[i - 1] + 1)
minimal = min(answer)
f... | 43 | 310 | 1,945,600 | 103730144 | n=int(input())
r=[1]*n
s=input()
y=1
while y:
y=0
for i in range(n-1):
if s[i]=='=' and r[i]!=r[i+1]:r[i]=r[i+1]=max(r[i:i+2]);y=1
if s[i]=='L' and r[i]<=r[i+1]:r[i]=r[i+1]+1;y=1
if s[i]=='R' and r[i]>=r[i+1]:r[i+1]=r[i]+1;y=1
print(*r) | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
67/A | 67 | A | Python 3 | TESTS | 6 | 122 | 409,600 | 109165110 | toffees = [1]
minimo = 1
numero_alumnos = int(input())
reglas = input()
for i in range(numero_alumnos-1):
if reglas[i] == 'L':
toffees.append(toffees[i] - 1)
if toffees[i+1] < minimo:
minimo = toffees[i+1]
elif reglas[i] == 'R':
toffees.append(toffees[i] + 1)
else:
... | 43 | 342 | 716,800 | 41874869 | n = int(input())
s = input()
ans = [1] * n
t = True
while t:
t = False
for i in range(n - 1):
if s[i] == '=' and ans[i] != ans[i + 1]:
ans[i] = ans[i + 1] = max(ans[i], ans[i + 1])
t = True
elif s[i] == 'R' and ans[i] >= ans[i + 1]:
ans[i + 1] += 1
... | Manthan 2011 | CF | 2,011 | 1 | 256 | Partial Teacher | A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks... | The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar... | Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | null | null | [{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}] | 1,800 | ["dp", "graphs", "greedy", "implementation"] | 43 | [{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=... | false | stdio | null | true |
353/B | 353 | B | Python 3 | TESTS | 5 | 124 | 4,608,000 | 16872038 | #!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
c = [0] * 100
for i in a:
c[i] += 1
x = [0] * 100
y = [0] * 100
xk = 0
yk = 0
j = 0
for i in range(100):
x[i] += c[i] // 2
y[i] += c[i] // 2
if c[i] % 2 == 1:
[x, y][j][i] += 1
j = 1 - j
if x[i]:
xk +=... | 40 | 124 | 0 | 4734405 | N = int(input())
Nums = list(map(int, input().split()))
Good = [1] * (N * 2)
Amounts = [0] * 100
Mono, Duo = 0, 0
for Num in Nums:
if Amounts[Num] == 0:
Mono += 1
elif Amounts[Num] == 1:
Duo += 1
Mono -= 1
Amounts[Num] += 1
Flag = Mono % 2
Duo_Flag = False
Counts = [0] * 100
for i in... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
353/B | 353 | B | PyPy 3 | TESTS | 10 | 280 | 0 | 82437310 | n=int(input())
arr=list(map(int,input().split()))
g=[[] for i in range(100)]
for i in range(2*n):
g[arr[i]].append(i)
x=0
y=0
curr=1
flip=1
for i in range(10,100):
if len(g[i])==1:
arr[g[i][0]]=curr
if curr==1:
x+=1
else:
y+=1
curr=3-curr
if len(g[i])>... | 40 | 124 | 0 | 170345321 | R,P=lambda:map(int,input().split()),print;n,=R();n*=2;a=[*R()]
c,C,z=[0]*100,[0,0],[0]*n
for x in a:c[x]+=1
for v in c:
if v:C[v==1]+=1
tar1=C[1]//2;P((C[0]+tar1)*(C[0]+C[1]-tar1))
s=sorted([(c[x],x,i)for i,x in enumerate(a)])
for i,v in enumerate(s):z[v[2]]=[1,2][i&1>0]
P(*z) | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
353/B | 353 | B | Python 3 | TESTS | 5 | 124 | 5,632,000 | 28011152 | from collections import defaultdict as defdict
n = int(input())
d = defdict(int)
a = list(map(int, input().split()))
for i in a:
d[i] += 1
b = [i for i in a if d[i] > 1]
d = defdict(int)
v = []
u = []
answ = []
for i, x in enumerate(a):
if x in b:
if d[x] == 0:
u.append(x)
an... | 40 | 154 | 28,979,200 | 135058301 | n=int(input())
arr=list(map(int,input().split()))
g=[[] for i in range(100)]
for i in range(2*n):
g[arr[i]].append(i)
x=0
y=0
curr=1
r=[]
for i in range(10,100):
if len(g[i])==1:
arr[g[i][0]]=curr
if curr==1:
x+=1
else:
y+=1
curr=3-curr
if len(g[i])>1:... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
353/B | 353 | B | Python 3 | PRETESTS | 5 | 92 | 0 | 4735486 | n = int(input())
set1 = set()
set2 = set()
res = [0] * (2 * n)
S = list(map(int, input().split()))
#A = [[S[i], i] for i in range(2 * n)]
c = 0
for i in sorted([[S[i], i] for i in range(2 * n)]):
if c == 0:
set1.add(i[0])
res[i[1]] = 1
c = 1
else:
set2.add(i[0])
res[i[1]]... | 40 | 156 | 921,600 | 4735879 | from math import*
from random import*
n = int(input()) * 2
A = list(map(int, input().split()))
amount = [0] * 101
B = []
for i in range(n):
if amount[A[i]] < 2:
amount[A[i]] += 1
B += [(A[i], i)]
B.sort()
x, y = [], []
for i in range(len(B)):
if(i % 2 == 0):
x.append(B[i][1])
else:... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
353/B | 353 | B | Python 3 | TESTS | 5 | 218 | 307,200 | 63354989 | n = int(input())
num = list(map(int, input().split(" ")))
initial = list(enumerate(num))
initial = [list(x) for x in initial]
sorted_init = sorted(initial, key = lambda x: x[1])
# sorted_init = list(enumerate(sorted_init))
left = sorted_init[::2]
left_places = [[i[0],1] for i in left]
right = sorted_init[1::2]
right_... | 40 | 184 | 7,372,800 | 36673593 | n = int(input())
a = list(map(int, input().split()))
R = range(100)
c = [[] for _ in [0]*100]
for i in range(n*2):
c[a[i]].append(i)
d = [0]*200
heap = 1
z = [0, 0, 0]
for i in R:
if len(c[i]) == 1:
z[heap]+=1
d[c[i][0]] = heap
heap = 3 - heap;
for i in R:
if len(c[i]) > 1:
z[1]+=1
z[2]+=1
while len(c[i]... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
353/B | 353 | B | Python 3 | PRETESTS | 5 | 62 | 0 | 4731845 | m = int(input())
n = 2 * m
C = list(map(int, input().split()))
A = [[C[i], i] for i in range(n)]
A.sort()
B = [0 for q in range(n)]
i = 0
count = 0
diff = 0
while i < n - 1:
if A[i][0] == A[i + 1][0]:
B[A[i][1]] = 1
B[A[i + 1][1]] = 2
count += 1
while i < n - 1 and A[i][0] == A[i + 1... | 40 | 248 | 0 | 42125110 | n = int(input())
a = list(map(int, input().split()))
R = range(100)
c = [[] for _ in [0]*100]
for i in range(n*2):
c[a[i]].append(i)
d = [0]*200
heap = 1
z = [0, 0, 0]
for i in R:
if len(c[i]) == 1:
z[heap]+=1
d[c[i][0]] = heap
heap = 3 - heap;
for i in R:
if len(c[i]) > 1:
z[1]+=1
z[2]+=1
while len(c[i]... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
904/C | 906 | A | Python 3 | TESTS | 7 | 77 | 5,939,200 | 33661546 | n = int(input())
no = set()
yes = set()
ls = []
count = 0
for i in range(n):
x = input().split()
if x[0] != '.':
count += 1
ls.append(x)
count -= 1
act = 0
for i in range(n - 1):
x = ls[i]
if x[0] == '.':
no |= set(x[1])
elif x[0] == '!':
act += 1
if len(yes) == 0:
yes |= set(x[1])
yes &= set(x[1... | 38 | 202 | 3,891,200 | 77132636 | input=__import__('sys').stdin.readline
left,bad=set([chr(i+ord('a')) for i in range(26)]),0
q=int(input())
for i in range(q-1):
op,s = input().split()
bad += len(left)==1and op!='.'
if op=='!': left=left&set(s)
else: left=left-set(s)
print(bad) | Технокубок 2018 - Отборочный Раунд 4 | CF | 2,017 | 2 | 256 | Shockers | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | null | In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ... | [{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}] | 1,600 | ["strings"] | 38 | [{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\... | false | stdio | null | true |
246/B | 246 | B | Python 3 | TESTS | 6 | 186 | 3,276,800 | 96334672 | n=int(input())
m=list(map(int,input().split()))
a=n-(m.count(max(m)))
print([(n),(n)-1][a%2!=0]) | 30 | 92 | 2,560,000 | 156293637 | I=input
n=int(I())
if sum(map(int,I().split()))%n:n-=1
print(n) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
246/B | 246 | B | PyPy 3 | TESTS | 12 | 280 | 25,292,800 | 122638865 | n=int(input());l=list(map(int,input().split()));l.sort()
print(n if n%2 else n-1) | 30 | 92 | 2,969,600 | 153579057 | n=int(input())
l=list(map(int,input().split(" ")))
s=sum(l)
val=n if s%n==0 else n-1
print(val) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
904/C | 906 | A | Python 3 | TESTS | 7 | 124 | 307,200 | 43946102 | m = int(input())
goodSet = set()
badSet = set()
count = 0
for i in range(m-1):
mode,word = input().split(' ')
if(len(goodSet)==1):
count += int(mode!='.')
continue
word = set(word)
if(mode=='!'):
if(len(goodSet)==0):
goodSet |= word;
goodSet -= badSet;
else:
goodSet &= word;... | 38 | 218 | 34,508,800 | 80300935 | from sys import stdin, stdout
input = stdin.readline
n = int(input())
queries = list(input().split() for _ in range(n))
chars = [chr(ord('a')+i) for i in range(26)]
chars_set = set(list(chars))
res, cnt = '', 0
for c, f in queries:
if c == '.':
for q in f:
if q in chars_set:
c... | Технокубок 2018 - Отборочный Раунд 4 | CF | 2,017 | 2 | 256 | Shockers | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | null | In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ... | [{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}] | 1,600 | ["strings"] | 38 | [{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\... | false | stdio | null | true |
353/B | 353 | B | PyPy 3-64 | TESTS | 5 | 154 | 0 | 170339955 | R,P,G=lambda:map(int,input().split()),print,range;n,=R();n*=2;a=[*R()];z=[0]*n
from collections import Counter as CT;cnt=CT(a);c=[0,0];i1,i2,h1=0,{},0
for x in cnt:
if cnt[x]>1:c[1]+=1;i2[x]=0
else:c[0]+=1
for i,x in enumerate(a):
if cnt[x]>1 and i2[x]<2:
if i2[x]==0:z[i]=1;h1+=1
else:z[i]=2
i2[x]+=1
... | 40 | 248 | 0 | 54372401 | n = int(input())
arr = list(map(int, input().split()))
adj = [[] for i in range(100)]
for i in range(2*n):
adj[arr[i]].append(i)
res = [0] * (2 * n)
mul, curr = [], 1
x = [0, 0]
for i in range(10, 100):
if len(adj[i]) == 1 :
res[adj[i][0]] = curr
x[curr-1] += 1
curr = 3 - curr
if len(adj[i]) > 1:
res[adj[i]... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
246/B | 246 | B | PyPy 3-64 | TESTS | 15 | 154 | 7,680,000 | 151045036 | n = int(input())
if n == 1:
print(1)
else:
arr = [int(x) for x in input().split()]
arr.sort()
for i in range(n-1):
if arr[i] >= 0:
arr[-1] += arr[i]
else:
arr[-1] -= arr[i]
arr[i] = 0
q,r = divmod(arr[-1], n)
# print(arr)
if r == 0:
pr... | 30 | 92 | 2,969,600 | 189736051 | n=int(input()) ; print(n-1 if sum(list(map(int,input().split())))%n else n) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
904/C | 906 | A | Python 3 | TESTS | 36 | 670 | 5,939,200 | 33572160 | l=['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
n=int(input())
shok=0
z=0
j=0
for i in range(n):
if len(l)==1 and z==0:
z=shok
j=0
s=input()
if s[0]=='.' or s[0]=='?':
if s[0]=='?':
shok+=1
for j in range(2,... | 38 | 233 | 26,828,800 | 33568040 | def main():
from sys import stdin, stdout
n = int(stdin.readline().strip())
alphas = list(map(lambda i: chr(i + ord('a')), range(0, 26)))
se = set(alphas)
count = 0
excess = 0
found = False
for i in range(n):
(a, b) = stdin.readline().strip().split(' ')
if a == '!':
... | Технокубок 2018 - Отборочный Раунд 4 | CF | 2,017 | 2 | 256 | Shockers | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | null | In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ... | [{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}] | 1,600 | ["strings"] | 38 | [{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\... | false | stdio | null | true |
904/C | 906 | A | PyPy 3 | TESTS | 7 | 93 | 22,016,000 | 126446311 | n = int(input())
ans = 0
wshot = False
a = set()
for i in range(n):
b = list(input().split())
if i == n - 1:
break
if b[0] == '!':
if wshot == False:
s = set(b[1])
s.difference_update(a)
wshot = True
if len(s) <= 1:
ans += 1
... | 38 | 249 | 409,600 | 109740860 | s,a=set('abcdefghijklmnopqrstuvwxyz'),0
for _ in range(int(input())-1):
c,w=input().split()
if len(s)==1 and c!='.':a+=1
w=set(w)
if c=='!':s&=w
else:s-=w
print(a) | Технокубок 2018 - Отборочный Раунд 4 | CF | 2,017 | 2 | 256 | Shockers | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | null | In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ... | [{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}] | 1,600 | ["strings"] | 38 | [{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\... | false | stdio | null | true |
353/B | 353 | B | Python 3 | TESTS | 10 | 92 | 204,800 | 5178022 | n, t = 2 * int(input()), map(int, input().split())
d = [[] for i in range(100)]
for i, j in enumerate(t):
d[j].append(i)
y, x = [], False
p, q = [], ['1'] * n
for i in d[10: 100]:
if i:
if len(i) == 1:
if x: y.append(i[0])
x = not x
else:
y.append(i[0])
... | 40 | 248 | 23,040,000 | 20167729 | def s():
input()
l = [[]for _ in range(100)]
a = list(map(int,input().split()))
for i,v in enumerate(a):
l[v].append(i)
c = 0
cc = 0
fs = [0,0]
for i in l:
if len(i) == 0:
continue
if len(i) == 1:
a[i[0]] = c+1
fs[c]+=1
c = 1 - c
continue
fs[c] += 1
fs[c-1] += 1
for e in i[:len(i)//2]... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Two Heaps | Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro... | The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes. | In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps,... | null | In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal... | [{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}] | 1,900 | ["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"] | 40 | [{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
cubes = list(map(int, f.readline().split()))
# Read reference output (to get the expected maximum)
with open(output_path) as f:
expected_max = int(f... | true |
904/C | 906 | A | Python 3 | TESTS | 7 | 61 | 5,939,200 | 33650047 | n = int(input().strip())
shocks = 0
limit = 0
letters = set([chr(x) for x in range(65, 123)])
while n:
action, val = input().strip().split(' ')
if action == '.':
letters = letters.difference(val)
elif action == '!':
letters = letters.intersection(val)
shocks += 1
elif action == ... | 38 | 249 | 5,939,200 | 33563803 | n = int(input().strip())
#print(n)
alpha = set(())
for i in range(ord("a"), ord("z")+1):
alpha.add(chr(i))
#print(alpha)
def noshock(s):
global alpha
letters = set(s)
alpha = alpha - letters
def shock(s):
global alpha
letters = set(s)
alpha = alpha&letters
def ask(c):
global alpha
if c in alpha:... | Технокубок 2018 - Отборочный Раунд 4 | CF | 2,017 | 2 | 256 | Shockers | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | null | In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ... | [{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}] | 1,600 | ["strings"] | 38 | [{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\... | false | stdio | null | true |
172/C | 172 | C | Python 3 | TESTS | 3 | 92 | 0 | 5356158 | from collections import defaultdict
n, m = map(int, input().split())
d = j = 0
r = [0] * n
p = defaultdict(list)
for i in range(n):
t, x = map(int, input().split())
p[x].append(i)
j += 1
if j == m:
d = max(t, d)
y = sorted(p.keys())
for x in y:
d += x
for ... | 66 | 546 | 8,294,400 | 154860930 | n, m = map(int, input().split())
w, T = [0]*n, 0
for i in range(0, n, m):
l = dict()
mt = 0
for s in range(i, min(n, m+i)):
t, x = map(int, input().split())
l.setdefault(x, []).append(s)
mt = max(mt, t)
T = max(T, mt)
p = 0
for x in sorted(l):
T += (x-p)
p = x
for s in l[x]:
w[s] = T
T += 1+len(l... | Croc Champ 2012 - Qualification Round | CF | 2,012 | 1 | 256 | Bus | There is a bus stop near the university. The lessons are over, and n students come to the stop. The i-th student will appear at the bus stop at time ti (all ti's are distinct).
We shall assume that the stop is located on the coordinate axis Ox, at point x = 0, and the bus goes along the ray Ox, that is, towards the po... | The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of students and the number of passengers the bus can transport, correspondingly. Next n lines contain descriptions of the students, one per line. Each line contains a pair of integers ti, xi (1 ≤ ti ≤ 105, 1 ≤ xi ≤ 104). The lines a... | Print n numbers w1, w2, ..., wn, wi — the moment of time when the i-th student got off the bus. Print the numbers on one line and separate them with single spaces. | null | In the first sample the bus waits for the first student for 3 units of time and drives him to his destination in additional 5 units of time. So the student leaves the bus at the moment of time 3 + 5 = 8.
In the second sample the capacity of the bus equals 1, that's why it will drive the first student alone. This stude... | [{"input": "1 10\n3 5", "output": "8"}, {"input": "2 1\n3 5\n4 5", "output": "8 19"}, {"input": "5 4\n3 5\n4 5\n5 5\n6 5\n7 1", "output": "11 11 11 11 20"}, {"input": "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2", "output": "5... | 1,500 | ["*special", "implementation", "sortings"] | 66 | [{"input": "1 10\r\n3 5\r\n", "output": "8\r\n"}, {"input": "2 1\r\n3 5\r\n4 5\r\n", "output": "8 19\r\n"}, {"input": "5 4\r\n3 5\r\n4 5\r\n5 5\r\n6 5\r\n7 1\r\n", "output": "11 11 11 11 20\r\n"}, {"input": "20 4\r\n28 13\r\n31 13\r\n35 6\r\n36 4\r\n52 6\r\n53 4\r\n83 2\r\n84 4\r\n87 1\r\n93 6\r\n108 4\r\n113 6\r\n116 ... | false | stdio | null | true |
246/B | 246 | B | PyPy 3 | TESTS | 12 | 216 | 5,120,000 | 108964044 | n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
if n%2 == 0:
ans = n-1
else:
ans = n
print(ans) | 30 | 92 | 3,072,000 | 176975299 | n = int(input())
a = [int(i) for i in input().split()]
if sum(a) % n == 0:
print(n)
else:
print(n - 1) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
246/B | 246 | B | PyPy 3 | TESTS | 15 | 248 | 25,292,800 | 125184248 | def main():
n = int(input())
arr = list(map(int, input().split()))
for i in range(n - 1):
if arr[i] < 0:
arr[n - 1] -= arr[i]
arr[i] = 0
elif arr[i] > 0:
arr[n - 1] += arr[i]
arr[i] = 0
else:
pass
if arr[n - 1] % n == ... | 30 | 92 | 3,174,400 | 146273371 | n = int(input())
numbers = input().split()
lst = [int(x) for x in numbers]
print(n if sum(lst) % n == 0 else n-1) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
246/B | 246 | B | PyPy 3 | TESTS | 15 | 216 | 5,734,400 | 108964064 | n = int(input())
a = list(map(int, input().split()))
ans = 1
if n%2 == 0:
if len(set(a)) != 1:
ans = n-1
else:
ans = n
else:
ans = n
print(ans) | 30 | 92 | 3,174,400 | 158395722 | i=int(input())
l=list(map(int,input().split()))
if sum(l)%i==0:
print(i)
else:
print(i-1) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.