problem_name
stringlengths
9
76
problem_id
stringlengths
1
4
solution_id
stringlengths
4
9
description
stringlengths
164
3.45k
solution_code
stringlengths
37
12.2k
dataclass_code
stringlengths
3.26k
4k
inputs_example
stringlengths
1
103
time_complexity_inferred
stringclasses
11 values
time_curve_coefficient
float64
0
0.07
tests
dict
problem_time_curve_coefficient_list
sequencelengths
8
3.27k
1051_C. Vasya and Multisets
2005
2005_187
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
from collections import * n = int(input()) a = list(map(int,input().split())) ans = ["A"]*n num = 0 for i in range(n): if a.count(a[i])>1: continue if num<0: num+=1 ans[i] = "B" else: num-=1 if num<0: for i in range(n): if a.count(a[i])<=2: continue ans[i] = "B" num= 0 break if num==0: print("YES") print(*ans,sep = '') else: print("NO")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int numbers: List[int] @classmethod def from_str(cls, input_: str): n, numbers, _ = input_.split('\n') n = int(n) numbers = [int(x) for x in numbers.split()] assert n == len(numbers) return cls(n, numbers) def __repr__(self): return str(self.n) + '\n' + ' '.join([str(x) for x in self.numbers]) + '\n'
4 3 5 7 1
O(n**2)
0.000064
{ "public_tests": [ { "input": "4\n3 5 7 1\n", "output": "YES\nABAB" }, { "input": "3\n3 5 1\n", "output": "NO\n" } ], "private_tests": [ { "input": "8\n3 5 3 3 2 1 4 3\n", "output": "YES\nAAAABABA" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n", "output": "YES\nAAAAAAAABAAAAAAABAAAAAABAABAABABABAAAAABAAAAAAAAAAAAAAABABABAAAAAABAABAAAABAAAAAAAABAAAAAAABAAAAABAA" }, { "input": "9\n1 1 1 2 2 2 3 3 3\n", "output": "YES\nAAAAAAAAA\n" }, { "input": "7\n1 2 3 4 4 4 4\n", "output": "YES\nABABAAA" }, { "input": "8\n2 2 3 2 4 2 2 1\n", "output": "YES\nBAAABAAA" }, { "input": "4\n1 2 3 4\n", "output": "YES\nABAB" }, { "input": "15\n1 2 3 4 10 10 10 5 6 7 8 9 11 11 11\n", "output": "YES\nABABBAAABABAAAA" }, { "input": "40\n19 87 57 97 23 18 74 91 4 58 76 74 12 67 52 52 47 52 28 4 96 50 82 70 5 47 69 51 33 8 2 38 25 8 60 39 39 22 95 38\n", "output": "YES\nABABABAAABAABABAAABAABABAABABAAABAAAABAA" }, { "input": "9\n3 4 5 6 7 7 7 7 9\n", "output": "YES\nABABBAAAA" }, { "input": "7\n3 2 1 1 3 1 1\n", "output": "YES\nAABAAAA\n" }, { "input": "5\n1 4 4 4 4\n", "output": "YES\nABAAA\n" }, { "input": "11\n1 2 3 4 5 5 6 6 7 9 11\n", "output": "NO\n" }, { "input": "7\n3 3 1 2 1 3 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "9\n1 2 3 4 4 4 4 4 4\n", "output": "YES\nABABAAAAA" }, { "input": "13\n13 9 5 7 10 7 11 10 1 13 13 12 3\n", "output": "YES\nAABAAAAABAAAB" }, { "input": "7\n1 2 2 2 2 3 4\n", "output": "YES\nABAAABA" }, { "input": "7\n1 2 2 2 2 2 2\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n1 3 3 3 5 5 5\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n4 3 1 1 1\n", "output": "YES\nABAAA" }, { "input": "8\n5 1 6 2 4 4 4 3\n", "output": "YES\nABABBAAA" }, { "input": "7\n1 2 4 4 4 4 4\n", "output": "YES\nABAAAAA" }, { "input": "7\n1 2 3 1 1 4 5\n", "output": "YES\nAABAAAB" }, { "input": "7\n1 3 2 3 3 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n1 2 1 3 2 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "4\n1 2 2 2\n", "output": "YES\nABAA\n" }, { "input": "2\n100 99\n", "output": "YES\nAB" }, { "input": "7\n1 2 3 3 2 2 2\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n2 1 1 1 3 1 1\n", "output": "YES\nAAAABAA" }, { "input": "7\n1 4 3 1 1 1 2\n", "output": "YES\nBABAAAA" }, { "input": "6\n2 3 1 3 3 1\n", "output": "YES\nABAAAA\n" }, { "input": "6\n1 3 3 2 4 3\n", "output": "YES\nABABAA" }, { "input": "6\n3 4 4 5 5 5\n", "output": "YES\nAAABAA\n" }, { "input": "5\n1 2 2 2 2\n", "output": "YES\nABAAA\n" }, { "input": "5\n2 3 3 3 3\n", "output": "YES\nABAAA\n" }, { "input": "4\n1 1 2 1\n", "output": "YES\nBAAA\n" }, { "input": "5\n2 1 2 2 2\n", "output": "YES\nBAAAA\n" }, { "input": "9\n1 1 1 1 2 3 3 3 3\n", "output": "YES\nBAAAAAAAA\n" }, { "input": "9\n4 2 2 1 1 1 5 2 3\n", "output": "YES\nABAAAABAA" }, { "input": "2\n1 100\n", "output": "YES\nAB" }, { "input": "7\n1 3 3 2 3 3 3\n", "output": "YES\nAAABAAA" }, { "input": "8\n1 2 3 4 4 4 4 4\n", "output": "YES\nABABAAAA" }, { "input": "5\n2 4 4 4 4\n", "output": "YES\nABAAA\n" }, { "input": "9\n1 3 3 3 5 3 3 3 6\n", "output": "YES\nABAABAAAA" }, { "input": "12\n1 2 2 2 3 3 3 4 4 4 5 5\n", "output": "YES\nABAAAAAAAAAA\n" }, { "input": "5\n1 1 3 1 2\n", "output": "YES\nAAAAB" }, { "input": "7\n1 2 2 3 3 3 3\n", "output": "YES\nAAABAAA\n" }, { "input": "13\n1 2 2 2 3 3 3 4 4 4 5 5 5\n", "output": "YES\nABAAAAAAAAAAA\n" }, { "input": "8\n3 5 4 2 1 1 3 1\n", "output": "YES\nAABABAAA" }, { "input": "7\n1 3 3 3 4 4 4\n", "output": "YES\nABAAAAA\n" }, { "input": "10\n44 23 65 17 48 29 49 88 91 85\n", "output": "YES\nABABABABAB" }, { "input": "7\n1 2 3 6 6 6 6\n", "output": "YES\nABABAAA" }, { "input": "7\n4 4 4 1 2 3 4\n", "output": "YES\nBAAABAA" }, { "input": "5\n10 20 20 20 20\n", "output": "YES\nABAAA\n" }, { "input": "5\n2 1 1 1 1\n", "output": "YES\nABAAA\n" }, { "input": "5\n2 2 2 1 1\n", "output": "YES\nAAAAA\n" }, { "input": "7\n2 1 1 1 3 3 3\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n9 5 5 5 7\n", "output": "YES\nAAAAB" }, { "input": "9\n1 2 3 4 5 7 7 7 7\n", "output": "YES\nABABABAAA" }, { "input": "7\n1 1 1 2 2 2 3\n", "output": "YES\nBAAAAAA\n" }, { "input": "5\n1 1 1 2 2\n", "output": "YES\nAAAAA\n" }, { "input": "12\n1 2 3 4 5 5 6 6 6 7 9 11\n", "output": "YES\nABABAABAAABA" }, { "input": "7\n1 1 3 1 1 2 2\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n1 3 1 1 3 1 2\n", "output": "YES\nBAAAAAA\n" }, { "input": "5\n1 1 1 1 2\n", "output": "YES\nBAAAA\n" }, { "input": "5\n9 1 9 9 9\n", "output": "YES\nBAAAA\n" }, { "input": "11\n2 9 12 8 12 14 14 9 2 12 13\n", "output": "YES\nAAAAAAAAAAB" }, { "input": "4\n1 3 3 3\n", "output": "YES\nABAA\n" }, { "input": "7\n1 1 1 2 3 4 5\n", "output": "YES\nAAAABAB" }, { "input": "10\n1 1 1 1 2 2 3 4 5 6\n", "output": "YES\nAAAAAAABAB" }, { "input": "69\n41 98 42 76 42 54 24 30 45 59 53 34 17 11 60 71 28 51 73 1 41 81 75 81 39 32 72 100 80 64 20 20 62 13 47 55 18 70 84 63 29 88 96 97 51 55 67 30 57 39 30 97 19 56 30 9 88 1 8 19 16 79 38 29 91 36 83 9 6\n", "output": "YES\nAAABAABBABABABABAABAAAAAABABABAAABAABABAAABAAAAABAAAAAAAAABAABAABABAA" }, { "input": "7\n1 1 3 1 3 1 1\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 2 3 4 4 4 5\n", "output": "YES\nABAAAAB" }, { "input": "7\n1 1 3 1 2 2 3\n", "output": "YES\nAAAAAAA\n" }, { "input": "30\n81 52 47 3 77 8 32 8 5 17 64 69 19 45 32 3 75 90 16 77 4 82 71 69 85 1 72 49 6 42\n", "output": "YES\nABAAAAAABABAABAAABAABABAABABAB" }, { "input": "9\n1 2 3 4 4 4 5 5 5\n", "output": "YES\nABABAAAAA" }, { "input": "9\n1 1 3 3 4 4 7 7 7\n", "output": "YES\nAAAAAAAAA\n" }, { "input": "100\n4 3 4 3 1 3 2 1 2 4 1 3 3 3 4 1 4 4 4 2 2 2 1 1 4 4 3 1 2 1 2 2 1 1 2 1 1 1 3 4 2 3 3 4 4 3 3 4 3 4 2 1 3 1 2 4 1 1 4 2 4 3 4 1 1 2 3 4 3 3 3 3 4 2 3 4 2 4 1 3 3 4 2 3 2 1 1 3 4 2 4 3 4 2 1 4 2 4 2 3\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "100\n92 90 95 93 93 96 93 94 96 97 96 100 93 93 90 95 94 99 100 93 100 98 91 90 90 96 97 94 93 98 90 97 96 100 100 95 99 99 92 96 98 90 92 97 91 94 100 100 99 91 91 97 93 92 97 94 91 91 100 100 94 95 100 100 100 92 92 90 97 93 96 92 91 97 100 96 94 96 97 95 96 90 100 95 95 94 93 99 97 91 93 93 93 99 94 93 97 97 99 100\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "7\n1 1 3 3 3 3 2\n", "output": "YES\nAABAAAA\n" }, { "input": "7\n1 2 2 2 3 3 3\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n1 2 3 3 3\n", "output": "YES\nABAAA" }, { "input": "6\n1 2 2 2 3 3\n", "output": "YES\nABAAAA\n" }, { "input": "5\n1 1 1 1 3\n", "output": "YES\nBAAAA\n" }, { "input": "3\n2 1 2\n", "output": "NO\n" }, { "input": "9\n2 3 4 3 2 4 1 4 4\n", "output": "YES\nAABAAAAAA\n" }, { "input": "5\n1 3 3 3 3\n", "output": "YES\nABAAA\n" }, { "input": "3\n1 1 1\n", "output": "YES\nAAA\n" }, { "input": "7\n1 3 3 3 3 4 4\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n1 1 1 1 1\n", "output": "YES\nAAAAA\n" }, { "input": "7\n2 2 2 2 3 4 5\n", "output": "YES\nBAAAABA" }, { "input": "7\n2 3 2 2 2 3 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "6\n1 1 1 1 1 2\n", "output": "YES\nBAAAAA\n" }, { "input": "8\n1 2 3 4 5 5 6 6\n", "output": "YES\nABABAAAA" }, { "input": "2\n1 1\n", "output": "YES\nAA\n" }, { "input": "7\n2 3 3 2 2 1 3\n", "output": "YES\nBAAAAAA\n" }, { "input": "2\n1 2\n", "output": "YES\nAB" }, { "input": "17\n1 1 2 2 3 3 4 4 5 5 6 7 8 9 10 10 10\n", "output": "YES\nAAAAAAAAAAABABAAA" }, { "input": "8\n2 2 2 2 3 3 3 1\n", "output": "YES\nBAAAAAAA\n" }, { "input": "3\n2 2 2\n", "output": "YES\nAAA\n" }, { "input": "11\n1 8 3 3 3 3 2 2 2 2 4\n", "output": "YES\nABBAAAAAAAA" }, { "input": "100\n7 1 5 50 49 14 30 42 44 46 10 32 17 21 36 26 46 21 48 9 5 24 33 34 33 4 4 39 3 50 39 41 28 18 29 20 13 2 44 9 31 35 8 7 13 28 50 10 11 30 38 17 11 15 40 8 26 18 19 23 42 20 24 31 43 48 29 12 19 12 36 45 16 40 37 47 6 2 45 22 16 27 37 27 34 15 43 22 38 35 23 14 47 6 25 41 1 32 25 3\n", "output": "YES\nAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "5\n3 1 1 1 1\n", "output": "YES\nABAAA\n" }, { "input": "13\n25 10 44 46 14 45 88 46 46 21 46 38 97\n", "output": "YES\nABABBABAAAABA" }, { "input": "9\n3 4 5 6 7 7 7 7 8\n", "output": "YES\nABABBAAAA" }, { "input": "6\n2 2 2 2 3 1\n", "output": "YES\nAAAAAB" }, { "input": "9\n8 5 9 9 9 3 4 9 4\n", "output": "YES\nABBAAAAAA" }, { "input": "14\n4 2 4 1 2 3 4 1 2 2 4 1 1 2\n", "output": "YES\nBAAAAAAAAAAAAA\n" }, { "input": "5\n1 1 1 1 4\n", "output": "YES\nBAAAA\n" }, { "input": "85\n91 17 2 95 31 40 45 56 15 25 55 27 74 30 34 35 51 39 75 42 31 9 12 41 81 90 38 17 36 35 45 80 52 94 68 43 79 26 66 55 62 26 57 30 97 32 74 100 11 9 72 31 38 96 88 34 29 76 1 95 90 36 61 6 68 98 10 82 24 22 11 96 46 6 73 81 85 25 13 80 31 52 86 16 41\n", "output": "YES\nAABABAABAAABAAAAABABAAAAAAAAAAAAABAABAAABAAABAABAAAAAABAABAAAABAAABABAAABAAABAAAAABAA" }, { "input": "10\n10 4 11 3 5 3 5 3 11 4\n", "output": "YES\nAAABAAAAAA\n" }, { "input": "7\n4 1 2 3 4 4 4\n", "output": "YES\nBABAAAA" } ], "generated_tests": [ { "input": "8\n3 5 3 3 2 1 1 3\n", "output": "YES\nAAAABAAA\n" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 18 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n", "output": "YES\nBAAAAAAABAAAAAAABAAAAAABAABAABABAAABAAAAAAAAAAAABAAAAAAABABAABAAAAABAAABAAAAAAAAAABAABAAAAAAABAAAAAA\n" }, { "input": "15\n1 2 3 4 10 10 10 5 6 7 8 9 11 11 4\n", "output": "YES\nABAAAAABABABAAA\n" }, { "input": "40\n19 87 57 97 23 8 74 91 4 58 76 74 12 67 52 52 47 52 28 4 96 50 82 70 5 47 69 51 33 8 2 38 25 8 60 39 39 22 95 38\n", "output": "YES\nABABAAABAABAABAAAAAABABABAABAABAAABAAABA\n" }, { "input": "9\n6 4 5 6 7 7 7 7 9\n", "output": "YES\nAABABAAAA\n" }, { "input": "5\n1 8 4 4 4\n", "output": "YES\nABAAA\n" }, { "input": "11\n1 1 3 4 5 5 6 6 7 9 11\n", "output": "NO\n" }, { "input": "7\n3 3 2 2 1 3 1\n", "output": "YES\nAAAAAAA\n" }, { "input": "9\n1 2 3 4 4 4 1 4 4\n", "output": "YES\nAABAAAAAA\n" }, { "input": "7\n1 2 2 2 2 3 2\n", "output": "YES\nAAAAABA\n" }, { "input": "7\n1 3 4 4 4 4 4\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n1 3 2 1 3 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "4\n1 2 4 2\n", "output": "YES\nAABA\n" }, { "input": "7\n1 2 3 4 2 2 2\n", "output": "YES\nABBAAAA\n" }, { "input": "6\n2 6 1 3 3 1\n", "output": "YES\nABAAAA\n" }, { "input": "6\n1 5 3 2 4 3\n", "output": "YES\nABAABA\n" }, { "input": "6\n3 4 4 3 5 5\n", "output": "YES\nAAAAAA\n" }, { "input": "5\n2 2 2 2 2\n", "output": "YES\nAAAAA\n" }, { "input": "5\n2 3 1 3 3\n", "output": "YES\nAABAA\n" }, { "input": "4\n1 1 1 1\n", "output": "YES\nAAAA\n" }, { "input": "9\n1 1 1 1 2 3 5 3 3\n", "output": "YES\nAAAAAABAA\n" }, { "input": "9\n4 2 2 2 1 1 5 2 3\n", "output": "YES\nABAAAABAA\n" }, { "input": "8\n1 2 3 4 4 1 4 4\n", "output": "YES\nAABAAAAA\n" }, { "input": "5\n2 4 4 4 6\n", "output": "YES\nAAAAB\n" }, { "input": "9\n1 3 3 3 5 6 3 3 6\n", "output": "YES\nAAAABAAAA\n" }, { "input": "12\n1 2 2 2 3 3 3 4 7 4 5 5\n", "output": "YES\nAAAAAAAABAAA\n" }, { "input": "13\n1 2 2 2 3 3 3 4 4 4 5 10 5\n", "output": "YES\nAAAAAAAAAAABA\n" }, { "input": "8\n3 5 8 2 1 1 3 1\n", "output": "YES\nAABABAAA\n" }, { "input": "10\n44 32 65 17 48 29 49 88 91 85\n", "output": "YES\nABABABABAB\n" }, { "input": "7\n1 2 3 6 6 11 6\n", "output": "YES\nABAAABA\n" }, { "input": "5\n2 2 2 2 1\n", "output": "YES\nBAAAA\n" }, { "input": "9\n1 2 3 4 5 7 4 7 7\n", "output": "YES\nABAABAAAA\n" }, { "input": "12\n1 2 3 4 5 7 6 6 6 7 9 11\n", "output": "YES\nABABAABAAABA\n" }, { "input": "11\n2 9 12 8 12 14 19 9 2 12 13\n", "output": "YES\nAAAAABAAAAB\n" }, { "input": "7\n1 1 1 2 2 4 5\n", "output": "YES\nAAAAAAB\n" }, { "input": "69\n41 98 42 76 42 54 24 30 45 59 53 34 17 11 60 71 28 51 73 1 41 81 75 81 4 32 72 100 80 64 20 20 62 13 47 55 18 70 84 63 29 88 96 97 51 55 67 30 57 39 30 97 19 56 30 9 88 1 8 19 16 79 38 29 91 36 83 9 6\n", "output": "YES\nAAABAABBABABABABAABAAAAABABABAAABABAABABAAAAAABAABAAAAAAAABAABAABABAA\n" }, { "input": "30\n81 52 47 3 77 8 32 8 5 17 64 69 19 45 32 3 75 90 27 77 4 82 71 69 85 1 72 49 6 42\n", "output": "YES\nABAAAAAABABAABAAABAABABAABABAB\n" }, { "input": "100\n4 3 4 3 1 3 2 1 2 4 1 3 3 3 4 1 4 4 4 2 2 2 1 1 4 4 3 1 2 1 2 2 1 1 2 1 1 1 3 4 2 3 3 2 4 3 3 4 3 4 2 1 3 1 2 4 1 1 4 2 4 3 4 1 1 2 3 4 3 3 3 3 4 2 3 4 2 4 1 3 3 4 2 3 2 1 1 3 4 2 4 3 4 2 1 4 2 4 2 3\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "5\n1 3 3 4 3\n", "output": "YES\nAAABA\n" }, { "input": "7\n1 3 3 2 3 4 4\n", "output": "YES\nAAABAAA\n" }, { "input": "7\n1 2 2 2 3 4 5\n", "output": "YES\nAAAABAB\n" }, { "input": "2\n1 4\n", "output": "YES\nAB\n" }, { "input": "17\n1 1 2 2 3 5 4 4 5 5 6 7 8 9 10 10 10\n", "output": "YES\nAAAAABAAAABABAAAA\n" }, { "input": "8\n2 2 2 2 4 3 3 1\n", "output": "YES\nAAAAAAAB\n" }, { "input": "11\n1 8 3 3 3 3 2 2 2 1 4\n", "output": "YES\nAAAAAAAAAAB\n" }, { "input": "100\n7 1 5 50 49 14 30 42 44 46 10 32 17 21 36 26 46 21 48 9 5 24 33 34 33 4 4 39 3 50 39 41 28 18 53 20 13 2 44 9 31 35 8 7 13 28 50 10 11 30 38 17 11 15 40 8 26 18 19 23 42 20 24 31 43 48 29 12 19 12 36 45 16 40 37 47 6 2 45 22 16 27 37 27 34 15 43 22 38 35 23 14 47 6 25 41 1 32 25 3\n", "output": "YES\nAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "13\n25 10 44 46 25 45 88 46 46 21 46 38 97\n", "output": "YES\nAABBAABAAAABA\n" }, { "input": "9\n3 4 5 6 12 7 7 7 8\n", "output": "YES\nABABAAAAB\n" }, { "input": "9\n8 5 15 9 9 3 4 9 4\n", "output": "YES\nABAAABAAA\n" }, { "input": "10\n10 4 11 3 5 3 5 3 4 4\n", "output": "YES\nAABAAAAAAA\n" }, { "input": "7\n4 1 2 3 7 4 4\n", "output": "YES\nAABABAA\n" }, { "input": "4\n3 3 7 1\n", "output": "YES\nAAAB\n" }, { "input": "8\n3 5 3 2 2 1 1 3\n", "output": "YES\nBAAAAAAA\n" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 18 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 69 98 21 14\n", "output": "YES\nAAAAAAAABAAAAAAABAAAAAABAABAABABAAABAAAAAAAAAAAABAAAAAAABABAABAAAAABAAABAAAAABAAAAABAAAAAAABAAAAABAA\n" }, { "input": "8\n1 2 3 4 4 2 2 1\n", "output": "YES\nABAAAAAA\n" }, { "input": "9\n6 4 5 6 7 7 8 7 9\n", "output": "YES\nAABAAAAAB\n" }, { "input": "6\n2 6 1 3 2 1\n", "output": "YES\nAAABAA\n" }, { "input": "8\n1 2 3 2 4 2 2 1\n", "output": "YES\nAAAABAAA\n" }, { "input": "13\n13 9 5 7 10 7 11 10 1 13 18 12 3\n", "output": "NO\n" }, { "input": "7\n1 2 2 2 1 2 2\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 3 3 3 5 1 5\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 3 4 2 3 3 3\n", "output": "YES\nABBAAAA\n" }, { "input": "7\n1 3 3 3 4 4 3\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n4 4 2 1 2 3 4\n", "output": "YES\nAAAAABA\n" }, { "input": "5\n12 20 20 20 20\n", "output": "YES\nABAAA\n" }, { "input": "5\n9 8 5 5 7\n", "output": "NO\n" }, { "input": "7\n1 1 1 3 2 2 3\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 1 4 1 1 2 2\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n2 3 1 1 3 1 2\n", "output": "YES\nAAAAAAA\n" }, { "input": "5\n2 1 1 1 2\n", "output": "YES\nAAAAA\n" }, { "input": "5\n9 1 7 9 9\n", "output": "YES\nAABAA\n" }, { "input": "4\n1 1 3 3\n", "output": "YES\nAAAA\n" }, { "input": "7\n1 2 3 1 3 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n1 2 3 4 4 8 5\n", "output": "NO\n" }, { "input": "7\n1 1 3 1 2 2 5\n", "output": "YES\nAAAAAAB\n" }, { "input": "9\n1 1 3 3 4 4 7 8 7\n", "output": "NO\n" }, { "input": "100\n92 90 95 93 93 96 93 94 96 97 96 100 93 93 90 95 94 99 100 93 100 98 91 90 90 96 97 94 93 98 90 97 96 100 100 95 99 99 92 96 98 90 92 97 91 94 100 100 99 91 91 97 93 92 97 94 91 91 100 100 94 95 100 100 100 92 92 90 97 93 96 92 91 97 100 96 94 96 97 95 96 95 100 95 95 94 93 99 97 91 93 93 93 99 94 93 97 97 99 100\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "7\n1 1 2 3 3 3 2\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 2 2 2 3 3 2\n", "output": "YES\nABAAAAA\n" }, { "input": "6\n1 3 2 2 3 3\n", "output": "YES\nABAAAA\n" }, { "input": "5\n1 1 2 1 3\n", "output": "YES\nAAAAB\n" }, { "input": "3\n2 1 4\n", "output": "NO\n" }, { "input": "9\n2 3 4 3 3 4 1 4 4\n", "output": "YES\nAAAAAABAA\n" }, { "input": "3\n1 1 2\n", "output": "NO\n" }, { "input": "5\n1 1 2 1 1\n", "output": "YES\nBAAAA\n" }, { "input": "7\n2 3 2 3 2 3 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n2 4 3 2 2 1 3\n", "output": "YES\nAAAAABA\n" }, { "input": "3\n2 3 2\n", "output": "NO\n" }, { "input": "5\n3 1 2 1 1\n", "output": "YES\nAABAA\n" }, { "input": "5\n1 1 2 1 4\n", "output": "YES\nAAAAB\n" }, { "input": "3\n3 7 1\n", "output": "NO\n" }, { "input": "15\n1 2 3 4 10 3 10 5 6 7 8 9 11 11 4\n", "output": "NO\n" }, { "input": "40\n19 87 57 97 23 8 74 91 4 58 76 74 12 67 52 52 47 52 28 4 96 50 89 70 5 47 69 51 33 8 2 38 25 8 60 39 39 22 95 38\n", "output": "YES\nABABAAABAABAABAAAAAABABABAABAABAAABAAABA\n" }, { "input": "11\n1 1 3 4 8 5 6 6 7 9 11\n", "output": "NO\n" }, { "input": "7\n1 3 3 3 3 1 5\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n1 3 4 4 4 6 4\n", "output": "YES\nABBAAAA\n" }, { "input": "7\n1 3 1 1 3 1 1\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 2 3 4 2 2 3\n", "output": "YES\nAAABAAA\n" } ] }
[ 0.00006665693097911013, 0.00006464188871014623, 0.00006454980619530403, 0.00006447931050191517, 0.000007590628019894882, 0.0000025626874354565384, 6.835418166964035e-7, 2.6679270468268165e-7, 2.435289342763109e-7, 1.7511658825235177e-7, 1.7302063226605862e-7, 1.1650625885386189e-7, 7.879340414334592e-8, 6.082596635392622e-8, 5.43712020241408e-8, 4.6502835977235735e-8, 3.827575072123517e-8, 2.901361875137334e-8, 1.5961933090665897e-8, 1.3714349025778963e-8, 1.3220744099650355e-9, 1.226869809877622e-9, 1.0471891389860142e-9, 8.389149912587416e-10, 2.6681326486013984e-10 ]
1051_C. Vasya and Multisets
2005
2005_137
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
from collections import Counter n = int(input()) s = list(map(int,input().split())) c = Counter(s) singles = [i for i in c if c[i]==1] multis = [i for i in c if c[i]>2] if len(singles)&1 and not multis: print("NO") else: print("YES") sin,mul=len(singles)//2,len(singles)&1 ans = "" for x in s: if mul and c[x]>2: mul-=1 ans+="A" elif sin and c[x]==1: sin-=1 ans+="A" else:ans+="B" print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int numbers: List[int] @classmethod def from_str(cls, input_: str): n, numbers, _ = input_.split('\n') n = int(n) numbers = [int(x) for x in numbers.split()] assert n == len(numbers) return cls(n, numbers) def __repr__(self): return str(self.n) + '\n' + ' '.join([str(x) for x in self.numbers]) + '\n'
4 3 5 7 1
O(n)
0.000003
{ "public_tests": [ { "input": "4\n3 5 7 1\n", "output": "YES\nABAB" }, { "input": "3\n3 5 1\n", "output": "NO\n" } ], "private_tests": [ { "input": "8\n3 5 3 3 2 1 4 3\n", "output": "YES\nAAAABABA" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n", "output": "YES\nAAAAAAAABAAAAAAABAAAAAABAABAABABABAAAAABAAAAAAAAAAAAAAABABABAAAAAABAABAAAABAAAAAAAABAAAAAAABAAAAABAA" }, { "input": "9\n1 1 1 2 2 2 3 3 3\n", "output": "YES\nAAAAAAAAA\n" }, { "input": "7\n1 2 3 4 4 4 4\n", "output": "YES\nABABAAA" }, { "input": "8\n2 2 3 2 4 2 2 1\n", "output": "YES\nBAAABAAA" }, { "input": "4\n1 2 3 4\n", "output": "YES\nABAB" }, { "input": "15\n1 2 3 4 10 10 10 5 6 7 8 9 11 11 11\n", "output": "YES\nABABBAAABABAAAA" }, { "input": "40\n19 87 57 97 23 18 74 91 4 58 76 74 12 67 52 52 47 52 28 4 96 50 82 70 5 47 69 51 33 8 2 38 25 8 60 39 39 22 95 38\n", "output": "YES\nABABABAAABAABABAAABAABABAABABAAABAAAABAA" }, { "input": "9\n3 4 5 6 7 7 7 7 9\n", "output": "YES\nABABBAAAA" }, { "input": "7\n3 2 1 1 3 1 1\n", "output": "YES\nAABAAAA\n" }, { "input": "5\n1 4 4 4 4\n", "output": "YES\nABAAA\n" }, { "input": "11\n1 2 3 4 5 5 6 6 7 9 11\n", "output": "NO\n" }, { "input": "7\n3 3 1 2 1 3 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "9\n1 2 3 4 4 4 4 4 4\n", "output": "YES\nABABAAAAA" }, { "input": "13\n13 9 5 7 10 7 11 10 1 13 13 12 3\n", "output": "YES\nAABAAAAABAAAB" }, { "input": "7\n1 2 2 2 2 3 4\n", "output": "YES\nABAAABA" }, { "input": "7\n1 2 2 2 2 2 2\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n1 3 3 3 5 5 5\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n4 3 1 1 1\n", "output": "YES\nABAAA" }, { "input": "8\n5 1 6 2 4 4 4 3\n", "output": "YES\nABABBAAA" }, { "input": "7\n1 2 4 4 4 4 4\n", "output": "YES\nABAAAAA" }, { "input": "7\n1 2 3 1 1 4 5\n", "output": "YES\nAABAAAB" }, { "input": "7\n1 3 2 3 3 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n1 2 1 3 2 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "4\n1 2 2 2\n", "output": "YES\nABAA\n" }, { "input": "2\n100 99\n", "output": "YES\nAB" }, { "input": "7\n1 2 3 3 2 2 2\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n2 1 1 1 3 1 1\n", "output": "YES\nAAAABAA" }, { "input": "7\n1 4 3 1 1 1 2\n", "output": "YES\nBABAAAA" }, { "input": "6\n2 3 1 3 3 1\n", "output": "YES\nABAAAA\n" }, { "input": "6\n1 3 3 2 4 3\n", "output": "YES\nABABAA" }, { "input": "6\n3 4 4 5 5 5\n", "output": "YES\nAAABAA\n" }, { "input": "5\n1 2 2 2 2\n", "output": "YES\nABAAA\n" }, { "input": "5\n2 3 3 3 3\n", "output": "YES\nABAAA\n" }, { "input": "4\n1 1 2 1\n", "output": "YES\nBAAA\n" }, { "input": "5\n2 1 2 2 2\n", "output": "YES\nBAAAA\n" }, { "input": "9\n1 1 1 1 2 3 3 3 3\n", "output": "YES\nBAAAAAAAA\n" }, { "input": "9\n4 2 2 1 1 1 5 2 3\n", "output": "YES\nABAAAABAA" }, { "input": "2\n1 100\n", "output": "YES\nAB" }, { "input": "7\n1 3 3 2 3 3 3\n", "output": "YES\nAAABAAA" }, { "input": "8\n1 2 3 4 4 4 4 4\n", "output": "YES\nABABAAAA" }, { "input": "5\n2 4 4 4 4\n", "output": "YES\nABAAA\n" }, { "input": "9\n1 3 3 3 5 3 3 3 6\n", "output": "YES\nABAABAAAA" }, { "input": "12\n1 2 2 2 3 3 3 4 4 4 5 5\n", "output": "YES\nABAAAAAAAAAA\n" }, { "input": "5\n1 1 3 1 2\n", "output": "YES\nAAAAB" }, { "input": "7\n1 2 2 3 3 3 3\n", "output": "YES\nAAABAAA\n" }, { "input": "13\n1 2 2 2 3 3 3 4 4 4 5 5 5\n", "output": "YES\nABAAAAAAAAAAA\n" }, { "input": "8\n3 5 4 2 1 1 3 1\n", "output": "YES\nAABABAAA" }, { "input": "7\n1 3 3 3 4 4 4\n", "output": "YES\nABAAAAA\n" }, { "input": "10\n44 23 65 17 48 29 49 88 91 85\n", "output": "YES\nABABABABAB" }, { "input": "7\n1 2 3 6 6 6 6\n", "output": "YES\nABABAAA" }, { "input": "7\n4 4 4 1 2 3 4\n", "output": "YES\nBAAABAA" }, { "input": "5\n10 20 20 20 20\n", "output": "YES\nABAAA\n" }, { "input": "5\n2 1 1 1 1\n", "output": "YES\nABAAA\n" }, { "input": "5\n2 2 2 1 1\n", "output": "YES\nAAAAA\n" }, { "input": "7\n2 1 1 1 3 3 3\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n9 5 5 5 7\n", "output": "YES\nAAAAB" }, { "input": "9\n1 2 3 4 5 7 7 7 7\n", "output": "YES\nABABABAAA" }, { "input": "7\n1 1 1 2 2 2 3\n", "output": "YES\nBAAAAAA\n" }, { "input": "5\n1 1 1 2 2\n", "output": "YES\nAAAAA\n" }, { "input": "12\n1 2 3 4 5 5 6 6 6 7 9 11\n", "output": "YES\nABABAABAAABA" }, { "input": "7\n1 1 3 1 1 2 2\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n1 3 1 1 3 1 2\n", "output": "YES\nBAAAAAA\n" }, { "input": "5\n1 1 1 1 2\n", "output": "YES\nBAAAA\n" }, { "input": "5\n9 1 9 9 9\n", "output": "YES\nBAAAA\n" }, { "input": "11\n2 9 12 8 12 14 14 9 2 12 13\n", "output": "YES\nAAAAAAAAAAB" }, { "input": "4\n1 3 3 3\n", "output": "YES\nABAA\n" }, { "input": "7\n1 1 1 2 3 4 5\n", "output": "YES\nAAAABAB" }, { "input": "10\n1 1 1 1 2 2 3 4 5 6\n", "output": "YES\nAAAAAAABAB" }, { "input": "69\n41 98 42 76 42 54 24 30 45 59 53 34 17 11 60 71 28 51 73 1 41 81 75 81 39 32 72 100 80 64 20 20 62 13 47 55 18 70 84 63 29 88 96 97 51 55 67 30 57 39 30 97 19 56 30 9 88 1 8 19 16 79 38 29 91 36 83 9 6\n", "output": "YES\nAAABAABBABABABABAABAAAAAABABABAAABAABABAAABAAAAABAAAAAAAAABAABAABABAA" }, { "input": "7\n1 1 3 1 3 1 1\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 2 3 4 4 4 5\n", "output": "YES\nABAAAAB" }, { "input": "7\n1 1 3 1 2 2 3\n", "output": "YES\nAAAAAAA\n" }, { "input": "30\n81 52 47 3 77 8 32 8 5 17 64 69 19 45 32 3 75 90 16 77 4 82 71 69 85 1 72 49 6 42\n", "output": "YES\nABAAAAAABABAABAAABAABABAABABAB" }, { "input": "9\n1 2 3 4 4 4 5 5 5\n", "output": "YES\nABABAAAAA" }, { "input": "9\n1 1 3 3 4 4 7 7 7\n", "output": "YES\nAAAAAAAAA\n" }, { "input": "100\n4 3 4 3 1 3 2 1 2 4 1 3 3 3 4 1 4 4 4 2 2 2 1 1 4 4 3 1 2 1 2 2 1 1 2 1 1 1 3 4 2 3 3 4 4 3 3 4 3 4 2 1 3 1 2 4 1 1 4 2 4 3 4 1 1 2 3 4 3 3 3 3 4 2 3 4 2 4 1 3 3 4 2 3 2 1 1 3 4 2 4 3 4 2 1 4 2 4 2 3\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "100\n92 90 95 93 93 96 93 94 96 97 96 100 93 93 90 95 94 99 100 93 100 98 91 90 90 96 97 94 93 98 90 97 96 100 100 95 99 99 92 96 98 90 92 97 91 94 100 100 99 91 91 97 93 92 97 94 91 91 100 100 94 95 100 100 100 92 92 90 97 93 96 92 91 97 100 96 94 96 97 95 96 90 100 95 95 94 93 99 97 91 93 93 93 99 94 93 97 97 99 100\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "7\n1 1 3 3 3 3 2\n", "output": "YES\nAABAAAA\n" }, { "input": "7\n1 2 2 2 3 3 3\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n1 2 3 3 3\n", "output": "YES\nABAAA" }, { "input": "6\n1 2 2 2 3 3\n", "output": "YES\nABAAAA\n" }, { "input": "5\n1 1 1 1 3\n", "output": "YES\nBAAAA\n" }, { "input": "3\n2 1 2\n", "output": "NO\n" }, { "input": "9\n2 3 4 3 2 4 1 4 4\n", "output": "YES\nAABAAAAAA\n" }, { "input": "5\n1 3 3 3 3\n", "output": "YES\nABAAA\n" }, { "input": "3\n1 1 1\n", "output": "YES\nAAA\n" }, { "input": "7\n1 3 3 3 3 4 4\n", "output": "YES\nABAAAAA\n" }, { "input": "5\n1 1 1 1 1\n", "output": "YES\nAAAAA\n" }, { "input": "7\n2 2 2 2 3 4 5\n", "output": "YES\nBAAAABA" }, { "input": "7\n2 3 2 2 2 3 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "6\n1 1 1 1 1 2\n", "output": "YES\nBAAAAA\n" }, { "input": "8\n1 2 3 4 5 5 6 6\n", "output": "YES\nABABAAAA" }, { "input": "2\n1 1\n", "output": "YES\nAA\n" }, { "input": "7\n2 3 3 2 2 1 3\n", "output": "YES\nBAAAAAA\n" }, { "input": "2\n1 2\n", "output": "YES\nAB" }, { "input": "17\n1 1 2 2 3 3 4 4 5 5 6 7 8 9 10 10 10\n", "output": "YES\nAAAAAAAAAAABABAAA" }, { "input": "8\n2 2 2 2 3 3 3 1\n", "output": "YES\nBAAAAAAA\n" }, { "input": "3\n2 2 2\n", "output": "YES\nAAA\n" }, { "input": "11\n1 8 3 3 3 3 2 2 2 2 4\n", "output": "YES\nABBAAAAAAAA" }, { "input": "100\n7 1 5 50 49 14 30 42 44 46 10 32 17 21 36 26 46 21 48 9 5 24 33 34 33 4 4 39 3 50 39 41 28 18 29 20 13 2 44 9 31 35 8 7 13 28 50 10 11 30 38 17 11 15 40 8 26 18 19 23 42 20 24 31 43 48 29 12 19 12 36 45 16 40 37 47 6 2 45 22 16 27 37 27 34 15 43 22 38 35 23 14 47 6 25 41 1 32 25 3\n", "output": "YES\nAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "5\n3 1 1 1 1\n", "output": "YES\nABAAA\n" }, { "input": "13\n25 10 44 46 14 45 88 46 46 21 46 38 97\n", "output": "YES\nABABBABAAAABA" }, { "input": "9\n3 4 5 6 7 7 7 7 8\n", "output": "YES\nABABBAAAA" }, { "input": "6\n2 2 2 2 3 1\n", "output": "YES\nAAAAAB" }, { "input": "9\n8 5 9 9 9 3 4 9 4\n", "output": "YES\nABBAAAAAA" }, { "input": "14\n4 2 4 1 2 3 4 1 2 2 4 1 1 2\n", "output": "YES\nBAAAAAAAAAAAAA\n" }, { "input": "5\n1 1 1 1 4\n", "output": "YES\nBAAAA\n" }, { "input": "85\n91 17 2 95 31 40 45 56 15 25 55 27 74 30 34 35 51 39 75 42 31 9 12 41 81 90 38 17 36 35 45 80 52 94 68 43 79 26 66 55 62 26 57 30 97 32 74 100 11 9 72 31 38 96 88 34 29 76 1 95 90 36 61 6 68 98 10 82 24 22 11 96 46 6 73 81 85 25 13 80 31 52 86 16 41\n", "output": "YES\nAABABAABAAABAAAAABABAAAAAAAAAAAAABAABAAABAAABAABAAAAAABAABAAAABAAABABAAABAAABAAAAABAA" }, { "input": "10\n10 4 11 3 5 3 5 3 11 4\n", "output": "YES\nAAABAAAAAA\n" }, { "input": "7\n4 1 2 3 4 4 4\n", "output": "YES\nBABAAAA" } ], "generated_tests": [ { "input": "8\n3 5 3 3 2 1 1 3\n", "output": "YES\nAAAABAAA\n" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 18 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n", "output": "YES\nBAAAAAAABAAAAAAABAAAAAABAABAABABAAABAAAAAAAAAAAABAAAAAAABABAABAAAAABAAABAAAAAAAAAABAABAAAAAAABAAAAAA\n" }, { "input": "15\n1 2 3 4 10 10 10 5 6 7 8 9 11 11 4\n", "output": "YES\nABAAAAABABABAAA\n" }, { "input": "40\n19 87 57 97 23 8 74 91 4 58 76 74 12 67 52 52 47 52 28 4 96 50 82 70 5 47 69 51 33 8 2 38 25 8 60 39 39 22 95 38\n", "output": "YES\nABABAAABAABAABAAAAAABABABAABAABAAABAAABA\n" }, { "input": "9\n6 4 5 6 7 7 7 7 9\n", "output": "YES\nAABABAAAA\n" }, { "input": "5\n1 8 4 4 4\n", "output": "YES\nABAAA\n" }, { "input": "11\n1 1 3 4 5 5 6 6 7 9 11\n", "output": "NO\n" }, { "input": "7\n3 3 2 2 1 3 1\n", "output": "YES\nAAAAAAA\n" }, { "input": "9\n1 2 3 4 4 4 1 4 4\n", "output": "YES\nAABAAAAAA\n" }, { "input": "7\n1 2 2 2 2 3 2\n", "output": "YES\nAAAAABA\n" }, { "input": "7\n1 3 4 4 4 4 4\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n1 3 2 1 3 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "4\n1 2 4 2\n", "output": "YES\nAABA\n" }, { "input": "7\n1 2 3 4 2 2 2\n", "output": "YES\nABBAAAA\n" }, { "input": "6\n2 6 1 3 3 1\n", "output": "YES\nABAAAA\n" }, { "input": "6\n1 5 3 2 4 3\n", "output": "YES\nABAABA\n" }, { "input": "6\n3 4 4 3 5 5\n", "output": "YES\nAAAAAA\n" }, { "input": "5\n2 2 2 2 2\n", "output": "YES\nAAAAA\n" }, { "input": "5\n2 3 1 3 3\n", "output": "YES\nAABAA\n" }, { "input": "4\n1 1 1 1\n", "output": "YES\nAAAA\n" }, { "input": "9\n1 1 1 1 2 3 5 3 3\n", "output": "YES\nAAAAAABAA\n" }, { "input": "9\n4 2 2 2 1 1 5 2 3\n", "output": "YES\nABAAAABAA\n" }, { "input": "8\n1 2 3 4 4 1 4 4\n", "output": "YES\nAABAAAAA\n" }, { "input": "5\n2 4 4 4 6\n", "output": "YES\nAAAAB\n" }, { "input": "9\n1 3 3 3 5 6 3 3 6\n", "output": "YES\nAAAABAAAA\n" }, { "input": "12\n1 2 2 2 3 3 3 4 7 4 5 5\n", "output": "YES\nAAAAAAAABAAA\n" }, { "input": "13\n1 2 2 2 3 3 3 4 4 4 5 10 5\n", "output": "YES\nAAAAAAAAAAABA\n" }, { "input": "8\n3 5 8 2 1 1 3 1\n", "output": "YES\nAABABAAA\n" }, { "input": "10\n44 32 65 17 48 29 49 88 91 85\n", "output": "YES\nABABABABAB\n" }, { "input": "7\n1 2 3 6 6 11 6\n", "output": "YES\nABAAABA\n" }, { "input": "5\n2 2 2 2 1\n", "output": "YES\nBAAAA\n" }, { "input": "9\n1 2 3 4 5 7 4 7 7\n", "output": "YES\nABAABAAAA\n" }, { "input": "12\n1 2 3 4 5 7 6 6 6 7 9 11\n", "output": "YES\nABABAABAAABA\n" }, { "input": "11\n2 9 12 8 12 14 19 9 2 12 13\n", "output": "YES\nAAAAABAAAAB\n" }, { "input": "7\n1 1 1 2 2 4 5\n", "output": "YES\nAAAAAAB\n" }, { "input": "69\n41 98 42 76 42 54 24 30 45 59 53 34 17 11 60 71 28 51 73 1 41 81 75 81 4 32 72 100 80 64 20 20 62 13 47 55 18 70 84 63 29 88 96 97 51 55 67 30 57 39 30 97 19 56 30 9 88 1 8 19 16 79 38 29 91 36 83 9 6\n", "output": "YES\nAAABAABBABABABABAABAAAAABABABAAABABAABABAAAAAABAABAAAAAAAABAABAABABAA\n" }, { "input": "30\n81 52 47 3 77 8 32 8 5 17 64 69 19 45 32 3 75 90 27 77 4 82 71 69 85 1 72 49 6 42\n", "output": "YES\nABAAAAAABABAABAAABAABABAABABAB\n" }, { "input": "100\n4 3 4 3 1 3 2 1 2 4 1 3 3 3 4 1 4 4 4 2 2 2 1 1 4 4 3 1 2 1 2 2 1 1 2 1 1 1 3 4 2 3 3 2 4 3 3 4 3 4 2 1 3 1 2 4 1 1 4 2 4 3 4 1 1 2 3 4 3 3 3 3 4 2 3 4 2 4 1 3 3 4 2 3 2 1 1 3 4 2 4 3 4 2 1 4 2 4 2 3\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "5\n1 3 3 4 3\n", "output": "YES\nAAABA\n" }, { "input": "7\n1 3 3 2 3 4 4\n", "output": "YES\nAAABAAA\n" }, { "input": "7\n1 2 2 2 3 4 5\n", "output": "YES\nAAAABAB\n" }, { "input": "2\n1 4\n", "output": "YES\nAB\n" }, { "input": "17\n1 1 2 2 3 5 4 4 5 5 6 7 8 9 10 10 10\n", "output": "YES\nAAAAABAAAABABAAAA\n" }, { "input": "8\n2 2 2 2 4 3 3 1\n", "output": "YES\nAAAAAAAB\n" }, { "input": "11\n1 8 3 3 3 3 2 2 2 1 4\n", "output": "YES\nAAAAAAAAAAB\n" }, { "input": "100\n7 1 5 50 49 14 30 42 44 46 10 32 17 21 36 26 46 21 48 9 5 24 33 34 33 4 4 39 3 50 39 41 28 18 53 20 13 2 44 9 31 35 8 7 13 28 50 10 11 30 38 17 11 15 40 8 26 18 19 23 42 20 24 31 43 48 29 12 19 12 36 45 16 40 37 47 6 2 45 22 16 27 37 27 34 15 43 22 38 35 23 14 47 6 25 41 1 32 25 3\n", "output": "YES\nAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "13\n25 10 44 46 25 45 88 46 46 21 46 38 97\n", "output": "YES\nAABBAABAAAABA\n" }, { "input": "9\n3 4 5 6 12 7 7 7 8\n", "output": "YES\nABABAAAAB\n" }, { "input": "9\n8 5 15 9 9 3 4 9 4\n", "output": "YES\nABAAABAAA\n" }, { "input": "10\n10 4 11 3 5 3 5 3 4 4\n", "output": "YES\nAABAAAAAAA\n" }, { "input": "7\n4 1 2 3 7 4 4\n", "output": "YES\nAABABAA\n" }, { "input": "4\n3 3 7 1\n", "output": "YES\nAAAB\n" }, { "input": "8\n3 5 3 2 2 1 1 3\n", "output": "YES\nBAAAAAAA\n" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 18 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 69 98 21 14\n", "output": "YES\nAAAAAAAABAAAAAAABAAAAAABAABAABABAAABAAAAAAAAAAAABAAAAAAABABAABAAAAABAAABAAAAABAAAAABAAAAAAABAAAAABAA\n" }, { "input": "8\n1 2 3 4 4 2 2 1\n", "output": "YES\nABAAAAAA\n" }, { "input": "9\n6 4 5 6 7 7 8 7 9\n", "output": "YES\nAABAAAAAB\n" }, { "input": "6\n2 6 1 3 2 1\n", "output": "YES\nAAABAA\n" }, { "input": "8\n1 2 3 2 4 2 2 1\n", "output": "YES\nAAAABAAA\n" }, { "input": "13\n13 9 5 7 10 7 11 10 1 13 18 12 3\n", "output": "NO\n" }, { "input": "7\n1 2 2 2 1 2 2\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 3 3 3 5 1 5\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 3 4 2 3 3 3\n", "output": "YES\nABBAAAA\n" }, { "input": "7\n1 3 3 3 4 4 3\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n4 4 2 1 2 3 4\n", "output": "YES\nAAAAABA\n" }, { "input": "5\n12 20 20 20 20\n", "output": "YES\nABAAA\n" }, { "input": "5\n9 8 5 5 7\n", "output": "NO\n" }, { "input": "7\n1 1 1 3 2 2 3\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 1 4 1 1 2 2\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n2 3 1 1 3 1 2\n", "output": "YES\nAAAAAAA\n" }, { "input": "5\n2 1 1 1 2\n", "output": "YES\nAAAAA\n" }, { "input": "5\n9 1 7 9 9\n", "output": "YES\nAABAA\n" }, { "input": "4\n1 1 3 3\n", "output": "YES\nAAAA\n" }, { "input": "7\n1 2 3 1 3 1 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n1 2 3 4 4 8 5\n", "output": "NO\n" }, { "input": "7\n1 1 3 1 2 2 5\n", "output": "YES\nAAAAAAB\n" }, { "input": "9\n1 1 3 3 4 4 7 8 7\n", "output": "NO\n" }, { "input": "100\n92 90 95 93 93 96 93 94 96 97 96 100 93 93 90 95 94 99 100 93 100 98 91 90 90 96 97 94 93 98 90 97 96 100 100 95 99 99 92 96 98 90 92 97 91 94 100 100 99 91 91 97 93 92 97 94 91 91 100 100 94 95 100 100 100 92 92 90 97 93 96 92 91 97 100 96 94 96 97 95 96 95 100 95 95 94 93 99 97 91 93 93 93 99 94 93 97 97 99 100\n", "output": "YES\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" }, { "input": "7\n1 1 2 3 3 3 2\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 2 2 2 3 3 2\n", "output": "YES\nABAAAAA\n" }, { "input": "6\n1 3 2 2 3 3\n", "output": "YES\nABAAAA\n" }, { "input": "5\n1 1 2 1 3\n", "output": "YES\nAAAAB\n" }, { "input": "3\n2 1 4\n", "output": "NO\n" }, { "input": "9\n2 3 4 3 3 4 1 4 4\n", "output": "YES\nAAAAAABAA\n" }, { "input": "3\n1 1 2\n", "output": "NO\n" }, { "input": "5\n1 1 2 1 1\n", "output": "YES\nBAAAA\n" }, { "input": "7\n2 3 2 3 2 3 1\n", "output": "YES\nBAAAAAA\n" }, { "input": "7\n2 4 3 2 2 1 3\n", "output": "YES\nAAAAABA\n" }, { "input": "3\n2 3 2\n", "output": "NO\n" }, { "input": "5\n3 1 2 1 1\n", "output": "YES\nAABAA\n" }, { "input": "5\n1 1 2 1 4\n", "output": "YES\nAAAAB\n" }, { "input": "3\n3 7 1\n", "output": "NO\n" }, { "input": "15\n1 2 3 4 10 3 10 5 6 7 8 9 11 11 4\n", "output": "NO\n" }, { "input": "40\n19 87 57 97 23 8 74 91 4 58 76 74 12 67 52 52 47 52 28 4 96 50 89 70 5 47 69 51 33 8 2 38 25 8 60 39 39 22 95 38\n", "output": "YES\nABABAAABAABAABAAAAAABABABAABAABAAABAAABA\n" }, { "input": "11\n1 1 3 4 8 5 6 6 7 9 11\n", "output": "NO\n" }, { "input": "7\n1 3 3 3 3 1 5\n", "output": "YES\nABAAAAA\n" }, { "input": "7\n1 3 4 4 4 6 4\n", "output": "YES\nABBAAAA\n" }, { "input": "7\n1 3 1 1 3 1 1\n", "output": "YES\nAAAAAAA\n" }, { "input": "7\n1 2 3 4 2 2 3\n", "output": "YES\nAAABAAA\n" } ] }
[ 0.000014291718900240384, 0.000011677848516717658, 0.00000899332727819056, 0.000008741136459243883, 0.000008362311543924824, 0.000008354034200174827, 0.000007826823658763113, 0.000006999734074519232, 0.000006982595457277097, 0.000006924540496612763, 0.000006751966168597028, 0.000006490033025568182, 0.000006435812732189686, 0.000006413507477678572, 0.000006299248483937939, 0.000006093257320804197, 0.000006087365411931819, 0.000006060507839816434, 0.000005932715922749126, 0.0000058974586879009115, 0.000005493007539335665, 0.0000054043239046110135, 0.000005363435601507867, 0.000005302599445476399, 0.0000048066384806599646, 0.000004759130695476398, 0.000004722992925043707, 0.000004688450270432692, 0.000004401915127840909, 0.000004387712535511364, 0.0000043622388822115394, 0.00000408083351999563, 0.0000038318227709790215, 0.000003824756637893357, 0.000003713808880572553, 0.0000036030821814903846, 0.000003582613923186189, 0.0000035381005244755246, 0.0000034267311926354892, 0.0000033969228310751754, 0.0000030786680097246504, 0.0000030615809112762237, 0.0000030450320291522827, 0.0000030342398382867134, 0.0000029198381091564686, 0.000002915994960118007, 0.0000027629816706730772, 0.0000027363296274038462, 0.0000026830530894886365, 0.0000026779463914991257, 0.0000026327903463723776, 0.0000021263856670673076, 0.0000018021205747377623, 0.0000016187953862543708, 2.516600196678322e-8, 2.1556941105769233e-8, 3.4857817963286716e-10, 3.428485576923082e-10, 2.344569493006994e-10, 2.0097383085664353e-10, 1.7890215253496515e-10, 1.5592903190559453e-10 ]
621_B. Wet Shark and Bishops
750
750_51
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other. Input The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops. Each of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position. Output Output one integer — the number of pairs of bishops which attack each other. Examples Input 5 1 1 1 5 3 3 5 1 5 5 Output 6 Input 3 1 1 2 3 3 5 Output 0 Note In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
n = int(input()) a = [0] * 2001 b = [0] * 2001 for i in range(n): x, y = map(int, input().split()) a[x - y] += 1 b[x + y] += 1 ans = 0 for i in range(2001): ans += a[i] * (a[i] - 1) // 2 ans += b[i] * (b[i] - 1) // 2 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List, Tuple @dataclass class Input: n: int data_points: List[Tuple[int, int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) data_points = [tuple(map(int, line.split(' '))) for line in lines[1:-1]] assert len(data_points) == n return cls(n, data_points) def __repr__(self): data_points_str = '\n'.join([' '.join(map(str, point)) for point in self.data_points]) return str(self.n) + '\n' + data_points_str + '\n'
3 1 1 2 3 3 5
O(n)
0.000011
{ "public_tests": [ { "input": "3\n1 1\n2 3\n3 5\n", "output": "0\n" }, { "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "output": "6\n" } ], "private_tests": [ { "input": "1\n1 1\n", "output": "0\n" }, { "input": "2\n1000 1\n1000 1000\n", "output": "0\n" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n798 657\n", "output": "0\n" }, { "input": "3\n259 770\n448 54\n926 667\n", "output": "0\n" }, { "input": "3\n859 96\n634 248\n808 72\n", "output": "0\n" }, { "input": "3\n987 237\n891 429\n358 145\n", "output": "0\n" }, { "input": "2\n1 1\n1000 1\n", "output": "0\n" }, { "input": "1\n6 3\n", "output": "0\n" }, { "input": "3\n539 221\n895 89\n673 890\n", "output": "0\n" }, { "input": "1\n1 1000\n", "output": "0\n" }, { "input": "2\n1 1\n3 1\n", "output": "0\n" }, { "input": "3\n387 422\n898 532\n988 636\n", "output": "0\n" }, { "input": "3\n411 81\n149 907\n611 114\n", "output": "0\n" }, { "input": "10\n518 518\n71 971\n121 862\n967 607\n138 754\n513 337\n499 873\n337 387\n647 917\n76 417\n", "output": "0\n" }, { "input": "5\n1 1000\n2 999\n3 998\n4 997\n5 996\n", "output": "10\n" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n510 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n999 1\n1000 2\n", "output": "1\n" }, { "input": "2\n1 1\n1 1000\n", "output": "0\n" }, { "input": "2\n1 1\n1000 1000\n", "output": "1\n" }, { "input": "2\n1 1000\n1000 1000\n", "output": "0\n" }, { "input": "1\n1000 1000\n", "output": "0\n" }, { "input": "2\n1000 1\n1 1000\n", "output": "1\n" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n284 929\n816 602\n", "output": "0\n" }, { "input": "1\n1000 1\n", "output": "0\n" } ], "generated_tests": [ { "input": "1\n0 1\n", "output": "0\n" }, { "input": "3\n1 1\n2 6\n3 5\n", "output": "1\n" }, { "input": "5\n1 1\n1 5\n6 3\n5 1\n5 5\n", "output": "2\n" }, { "input": "5\n1 1\n1 5\n6 2\n5 1\n5 5\n", "output": "3\n" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n886 657\n", "output": "0\n" }, { "input": "3\n859 96\n634 248\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n891 572\n358 145\n", "output": "0\n" }, { "input": "2\n2 1\n1000 1\n", "output": "0\n" }, { "input": "1\n6 6\n", "output": "0\n" }, { "input": "3\n539 221\n895 43\n673 890\n", "output": "0\n" }, { "input": "2\n1 1\n6 1\n", "output": "0\n" }, { "input": "3\n387 249\n898 532\n988 636\n", "output": "0\n" }, { "input": "3\n411 81\n149 907\n606 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n1 2\n1 1000\n", "output": "0\n" }, { "input": "2\n1000 2\n1 1000\n", "output": "0\n" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n115 929\n816 602\n", "output": "0\n" }, { "input": "1\n1000 2\n", "output": "0\n" }, { "input": "3\n859 96\n634 359\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n891 36\n358 145\n", "output": "0\n" }, { "input": "2\n0 1\n1000 1\n", "output": "0\n" }, { "input": "1\n9 6\n", "output": "0\n" }, { "input": "2\n1 1\n6 0\n", "output": "0\n" }, { "input": "3\n387 249\n898 532\n183 636\n", "output": "0\n" }, { "input": "3\n411 81\n149 907\n970 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 563\n451 713\n262 709\n343 819\n855 779\n457 60\n650 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n2 2\n1 1000\n", "output": "0\n" }, { "input": "3\n1 1\n2 6\n3 10\n", "output": "0\n" }, { "input": "3\n859 96\n776 359\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n891 70\n358 145\n", "output": "0\n" }, { "input": "2\n0 2\n1000 1\n", "output": "0\n" }, { "input": "1\n9 11\n", "output": "0\n" }, { "input": "2\n1 2\n6 0\n", "output": "0\n" }, { "input": "3\n387 249\n750 532\n183 636\n", "output": "0\n" }, { "input": "3\n309 81\n149 907\n970 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n30 807\n11 665\n600 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n262 709\n343 819\n855 779\n457 60\n650 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n2 4\n1 1000\n", "output": "0\n" }, { "input": "3\n1 1\n4 6\n3 10\n", "output": "0\n" }, { "input": "5\n1 1\n1 5\n6 2\n5 1\n6 5\n", "output": "2\n" }, { "input": "3\n859 96\n776 630\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n146 70\n358 145\n", "output": "0\n" }, { "input": "1\n10 11\n", "output": "0\n" }, { "input": "2\n1 2\n2 0\n", "output": "0\n" }, { "input": "3\n387 413\n750 532\n183 636\n", "output": "0\n" }, { "input": "3\n309 81\n209 907\n970 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n30 807\n11 665\n223 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n262 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n0 4\n1 1000\n", "output": "0\n" }, { "input": "3\n1 1\n4 9\n3 10\n", "output": "1\n" }, { "input": "5\n1 1\n1 5\n6 2\n5 0\n6 5\n", "output": "0\n" }, { "input": "3\n859 96\n776 630\n808 202\n", "output": "0\n" }, { "input": "3\n987 237\n146 70\n478 145\n", "output": "0\n" }, { "input": "1\n10 3\n", "output": "0\n" }, { "input": "2\n1 4\n2 0\n", "output": "0\n" }, { "input": "3\n614 413\n750 532\n183 636\n", "output": "0\n" }, { "input": "3\n309 81\n209 907\n970 93\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n38 807\n11 665\n223 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n194 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "3\n1 1\n4 9\n1 10\n", "output": "0\n" }, { "input": "5\n2 1\n1 5\n6 2\n5 0\n6 5\n", "output": "1\n" }, { "input": "3\n859 96\n776 630\n808 127\n", "output": "0\n" }, { "input": "1\n10 4\n", "output": "0\n" }, { "input": "2\n1 4\n1 0\n", "output": "0\n" }, { "input": "3\n614 413\n750 532\n356 636\n", "output": "0\n" }, { "input": "3\n582 81\n209 907\n970 93\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n38 807\n11 665\n223 100\n445 912\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n194 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n591 709\n", "output": "0\n" }, { "input": "3\n1 1\n8 9\n1 10\n", "output": "0\n" }, { "input": "5\n2 1\n1 5\n6 2\n5 1\n6 5\n", "output": "3\n" }, { "input": "1\n18 4\n", "output": "0\n" }, { "input": "3\n614 413\n750 532\n582 636\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 169\n38 807\n11 665\n223 100\n445 912\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n891 713\n194 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n591 709\n", "output": "0\n" }, { "input": "3\n1 0\n8 9\n1 10\n", "output": "0\n" }, { "input": "5\n2 1\n1 8\n6 2\n5 1\n6 5\n", "output": "2\n" }, { "input": "1\n22 4\n", "output": "0\n" }, { "input": "3\n614 413\n750 97\n582 636\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 243\n38 807\n11 665\n223 100\n445 912\n658 959\n593 389\n729 950\n", "output": "0\n" } ] }
[ 0.000017075636146755727, 0.00001534040819421622, 0.000015043592102196042, 0.000014523477589218652, 0.000014369605196135706, 0.000014271737280892345, 0.000013969253622416827, 0.00001387832110944519, 0.000013710452480510177, 0.000013426834869592993, 0.000013246774223068933, 0.000013240382095548347, 0.000013231445306182354, 0.000013224670029842673, 0.000013087155558881001, 0.00001290521373050658, 0.000012859180417221839, 0.000012729767966755782, 0.000012679357683264794, 0.0000126151727277698, 0.000012532888074154865, 0.00001245107434167395, 0.000012366931597834753, 0.000012296089795648207, 0.000012270355709101583, 0.00001222520451870419, 0.000012181409094964158, 0.000012142350989527727, 0.000011964676415656325, 0.000011913585886171939, 0.000011836999038818496, 0.000011835660898618373, 0.000011775742682502179, 0.000011740959664910256, 0.000011739110058160114, 0.000011737372549922443, 0.000011704477747497043, 0.000011690815372572945, 0.000011558550414545497, 0.000011396293367559836, 0.000011376692991720602, 0.000011328695443596776, 0.000011310092402924984, 0.00001129684693328422, 0.000011260386374820499, 0.000011256074667111765, 0.000011219701322919574, 0.000011202331069472703, 0.0000111856842518756, 0.000011183580763707629, 0.000011175427858148027, 0.000011169842133132274, 0.000011159354992532141, 0.000011158636828791703, 0.000011148594113770508, 0.000011146715311851599, 0.000011135290835105572, 0.000011114579983826826, 0.000011094692770130854, 0.000010968256508839128, 0.000010967755577874409, 0.000010963464417578687, 0.000010945804454241718, 0.000010939544869046215, 0.000010931663333227814, 0.00001092158729053294, 0.0000109193097393011, 0.000010919039592620198, 0.000010886279257760678, 0.000010836411837497015, 0.000010818378319889263, 0.000010816059115540348, 0.000010800736705334557, 0.000010792837309958013, 0.000010777916322531074, 0.000010771873190230483, 0.000010758194578821201, 0.000010750015125658655, 0.00001066797010840631, 0.000010608778908109322, 0.000010557884353173771, 0.000010461118915994463, 0.000010455864818742466, 0.000010422090132349514, 0.00001042102953589383, 0.000010379201859627212, 0.000010266503207295771, 0.000010262551462060669, 0.000010250714022602154, 0.000010174876459398715, 0.000010116618111652456, 0.000010036564179960664, 0.000009901335437956309, 0.000009670999907910755, 0.000009665238505391538, 0.000009651109810670266, 0.000009633120412444712, 0.00000949364447507691, 0.000009468686424606246, 0.000009390782726935241, 0.000009373841396418303, 0.000009352698560242196, 0.000009347343947578198, 0.000009314475433754737, 0.000009310026582136414, 0.000009306914123900324, 0.000009270235849192348, 0.000009267048715211128, 0.000009259505616005111, 0.000009179786643605984, 0.0000091670608450915, 0.000009126813971089733, 0.000009123279205960478, 0.000009113530356356604, 0.000009027241354402588, 0.000008910331581719135, 0.000008831400800371493, 0.000008818577529072863, 0.000008791694606160195, 0.00000874525572032496, 0.000008683070649718409, 0.00000863807855500462, 0.000008500066327279425, 0.000008283894287301181, 3.08970716783217e-9, 1.723045509178322e-9, 6.642878605769236e-10, 5.841960773601398e-10, 1.179387019230769e-10 ]
621_B. Wet Shark and Bishops
750
750_14
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other. Input The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops. Each of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position. Output Output one integer — the number of pairs of bishops which attack each other. Examples Input 5 1 1 1 5 3 3 5 1 5 5 Output 6 Input 3 1 1 2 3 3 5 Output 0 Note In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
import sys n=int(sys.stdin.readline()) a=[] b=[] res=0 for i in range(n): _a, _b = list(map(int, sys.stdin.readline().split())) a.append(_a+_b) b.append(_a-_b) a.sort() b.sort() i=0 while i<n: cnt=1 while i+1<len(a) and a[i]==a[i+1]: cnt+=1 i+=1 res+=cnt*(cnt-1)//2 i+=1 i=0 while i<n: cnt=1 while i+1<len(b) and b[i]==b[i+1]: cnt+=1 i+=1 res+=cnt*(cnt-1)//2 i+=1 print(res)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List, Tuple @dataclass class Input: n: int data_points: List[Tuple[int, int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) data_points = [tuple(map(int, line.split(' '))) for line in lines[1:-1]] assert len(data_points) == n return cls(n, data_points) def __repr__(self): data_points_str = '\n'.join([' '.join(map(str, point)) for point in self.data_points]) return str(self.n) + '\n' + data_points_str + '\n'
3 1 1 2 3 3 5
O(nlogn)
0.000019
{ "public_tests": [ { "input": "3\n1 1\n2 3\n3 5\n", "output": "0\n" }, { "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "output": "6\n" } ], "private_tests": [ { "input": "1\n1 1\n", "output": "0\n" }, { "input": "2\n1000 1\n1000 1000\n", "output": "0\n" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n798 657\n", "output": "0\n" }, { "input": "3\n259 770\n448 54\n926 667\n", "output": "0\n" }, { "input": "3\n859 96\n634 248\n808 72\n", "output": "0\n" }, { "input": "3\n987 237\n891 429\n358 145\n", "output": "0\n" }, { "input": "2\n1 1\n1000 1\n", "output": "0\n" }, { "input": "1\n6 3\n", "output": "0\n" }, { "input": "3\n539 221\n895 89\n673 890\n", "output": "0\n" }, { "input": "1\n1 1000\n", "output": "0\n" }, { "input": "2\n1 1\n3 1\n", "output": "0\n" }, { "input": "3\n387 422\n898 532\n988 636\n", "output": "0\n" }, { "input": "3\n411 81\n149 907\n611 114\n", "output": "0\n" }, { "input": "10\n518 518\n71 971\n121 862\n967 607\n138 754\n513 337\n499 873\n337 387\n647 917\n76 417\n", "output": "0\n" }, { "input": "5\n1 1000\n2 999\n3 998\n4 997\n5 996\n", "output": "10\n" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n510 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n999 1\n1000 2\n", "output": "1\n" }, { "input": "2\n1 1\n1 1000\n", "output": "0\n" }, { "input": "2\n1 1\n1000 1000\n", "output": "1\n" }, { "input": "2\n1 1000\n1000 1000\n", "output": "0\n" }, { "input": "1\n1000 1000\n", "output": "0\n" }, { "input": "2\n1000 1\n1 1000\n", "output": "1\n" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n284 929\n816 602\n", "output": "0\n" }, { "input": "1\n1000 1\n", "output": "0\n" } ], "generated_tests": [ { "input": "1\n0 1\n", "output": "0\n" }, { "input": "3\n1 1\n2 6\n3 5\n", "output": "1\n" }, { "input": "5\n1 1\n1 5\n6 3\n5 1\n5 5\n", "output": "2\n" }, { "input": "5\n1 1\n1 5\n6 2\n5 1\n5 5\n", "output": "3\n" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n886 657\n", "output": "0\n" }, { "input": "3\n859 96\n634 248\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n891 572\n358 145\n", "output": "0\n" }, { "input": "2\n2 1\n1000 1\n", "output": "0\n" }, { "input": "1\n6 6\n", "output": "0\n" }, { "input": "3\n539 221\n895 43\n673 890\n", "output": "0\n" }, { "input": "2\n1 1\n6 1\n", "output": "0\n" }, { "input": "3\n387 249\n898 532\n988 636\n", "output": "0\n" }, { "input": "3\n411 81\n149 907\n606 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n1 2\n1 1000\n", "output": "0\n" }, { "input": "2\n1000 2\n1 1000\n", "output": "0\n" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n115 929\n816 602\n", "output": "0\n" }, { "input": "1\n1000 2\n", "output": "0\n" }, { "input": "3\n859 96\n634 359\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n891 36\n358 145\n", "output": "0\n" }, { "input": "2\n0 1\n1000 1\n", "output": "0\n" }, { "input": "1\n9 6\n", "output": "0\n" }, { "input": "2\n1 1\n6 0\n", "output": "0\n" }, { "input": "3\n387 249\n898 532\n183 636\n", "output": "0\n" }, { "input": "3\n411 81\n149 907\n970 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 563\n451 713\n262 709\n343 819\n855 779\n457 60\n650 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n2 2\n1 1000\n", "output": "0\n" }, { "input": "3\n1 1\n2 6\n3 10\n", "output": "0\n" }, { "input": "3\n859 96\n776 359\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n891 70\n358 145\n", "output": "0\n" }, { "input": "2\n0 2\n1000 1\n", "output": "0\n" }, { "input": "1\n9 11\n", "output": "0\n" }, { "input": "2\n1 2\n6 0\n", "output": "0\n" }, { "input": "3\n387 249\n750 532\n183 636\n", "output": "0\n" }, { "input": "3\n309 81\n149 907\n970 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n30 807\n11 665\n600 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n262 709\n343 819\n855 779\n457 60\n650 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n2 4\n1 1000\n", "output": "0\n" }, { "input": "3\n1 1\n4 6\n3 10\n", "output": "0\n" }, { "input": "5\n1 1\n1 5\n6 2\n5 1\n6 5\n", "output": "2\n" }, { "input": "3\n859 96\n776 630\n808 119\n", "output": "0\n" }, { "input": "3\n987 237\n146 70\n358 145\n", "output": "0\n" }, { "input": "1\n10 11\n", "output": "0\n" }, { "input": "2\n1 2\n2 0\n", "output": "0\n" }, { "input": "3\n387 413\n750 532\n183 636\n", "output": "0\n" }, { "input": "3\n309 81\n209 907\n970 114\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n30 807\n11 665\n223 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n262 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "2\n0 4\n1 1000\n", "output": "0\n" }, { "input": "3\n1 1\n4 9\n3 10\n", "output": "1\n" }, { "input": "5\n1 1\n1 5\n6 2\n5 0\n6 5\n", "output": "0\n" }, { "input": "3\n859 96\n776 630\n808 202\n", "output": "0\n" }, { "input": "3\n987 237\n146 70\n478 145\n", "output": "0\n" }, { "input": "1\n10 3\n", "output": "0\n" }, { "input": "2\n1 4\n2 0\n", "output": "0\n" }, { "input": "3\n614 413\n750 532\n183 636\n", "output": "0\n" }, { "input": "3\n309 81\n209 907\n970 93\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n38 807\n11 665\n223 100\n445 496\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n194 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n710 709\n", "output": "0\n" }, { "input": "3\n1 1\n4 9\n1 10\n", "output": "0\n" }, { "input": "5\n2 1\n1 5\n6 2\n5 0\n6 5\n", "output": "1\n" }, { "input": "3\n859 96\n776 630\n808 127\n", "output": "0\n" }, { "input": "1\n10 4\n", "output": "0\n" }, { "input": "2\n1 4\n1 0\n", "output": "0\n" }, { "input": "3\n614 413\n750 532\n356 636\n", "output": "0\n" }, { "input": "3\n582 81\n209 907\n970 93\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 771\n38 807\n11 665\n223 100\n445 912\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n451 713\n194 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n591 709\n", "output": "0\n" }, { "input": "3\n1 1\n8 9\n1 10\n", "output": "0\n" }, { "input": "5\n2 1\n1 5\n6 2\n5 1\n6 5\n", "output": "3\n" }, { "input": "1\n18 4\n", "output": "0\n" }, { "input": "3\n614 413\n750 532\n582 636\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 169\n38 807\n11 665\n223 100\n445 912\n658 959\n593 389\n729 950\n", "output": "0\n" }, { "input": "10\n515 488\n891 713\n194 709\n343 819\n855 779\n457 60\n382 359\n133 42\n788 639\n591 709\n", "output": "0\n" }, { "input": "3\n1 0\n8 9\n1 10\n", "output": "0\n" }, { "input": "5\n2 1\n1 8\n6 2\n5 1\n6 5\n", "output": "2\n" }, { "input": "1\n22 4\n", "output": "0\n" }, { "input": "3\n614 413\n750 97\n582 636\n", "output": "0\n" }, { "input": "10\n939 407\n197 220\n791 243\n38 807\n11 665\n223 100\n445 912\n658 959\n593 389\n729 950\n", "output": "0\n" } ] }
[ 0.00001907865187590094, 0.000017961286960828123, 0.000011504899760855738, 0.000011344483759198134, 0.000010860577434105828, 0.000010715660921640685, 0.000010086332914135412, 0.000009974320087830119, 0.00000993474547107966, 0.000008937960133989854, 0.0000029796656442268925, 0.0000024877907875504785, 0.000002107517232314705, 0.0000021060618491785296, 0.000001912334687439114, 0.0000018540448972251088, 0.0000018522379694574105, 0.0000017714903741591712, 0.0000017336149454327215, 0.0000017090671959882926, 0.0000016519108210629212, 0.0000016329597401024835, 0.0000016282923734238548, 0.0000016253962279393152, 0.0000016251911348347437, 0.0000016162703981141155, 0.0000016142869933064329, 0.0000016129504749670257, 0.0000015977571179541936, 0.0000015414585464645024, 0.0000015353308367022818, 1.6914335664335674e-9, 2.8540459424798228e-11 ]
24_A. Ring road
348
348_33
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 other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all n roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is 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? Input 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 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. Examples Input 3 1 3 1 1 2 1 3 2 1 Output 1 Input 3 1 3 1 1 2 5 3 2 1 Output 2 Input 6 1 5 4 5 3 8 2 4 15 1 6 16 2 3 23 4 6 42 Output 39 Input 4 1 2 9 2 3 8 3 4 7 4 1 5 Output 0
import sys,math n=int(sys.stdin.readline()) start =[] end=[] ans1=0 ans2=0 for i in range(n): a,b,c=map(int,sys.stdin.readline().split()) if (a in start) or (b in end): ans1+=c start.append(b) end.append(a) else: ans2+=c start.append(a) end.append(b) print(min(ans1,ans2))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int v_list: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) v_list = [list(map(int, line.split(' '))) for line in lines[1:-1]] assert n == len(v_list) return cls(n, v_list) def __repr__(self): return str(self.n) + '\n' + '\n'.join([' '.join(map(str, v)) for v in self.v_list]) + '\n'
3 1 3 1 1 2 1 3 2 1
O(n**2)
0
{ "public_tests": [ { "input": "3\n1 3 1\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "3\n1 3 1\n1 2 5\n3 2 1\n", "output": "2\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n", "output": "39\n" }, { "input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n", "output": "0\n" } ], "private_tests": [ { "input": "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54\n", "output": "143\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "267\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 93\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "413\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "3\n3 1 1\n2 1 1\n2 3 1\n", "output": "1\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "435\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "950\n" } ], "generated_tests": [ { "input": "5\n5 3 89\n2 3 43\n4 2 95\n1 4 69\n1 5 54\n", "output": "143\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "3\n1 3 2\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 27\n1 4 69\n1 5 54\n", "output": "139\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "267\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "413\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 33\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "422\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 96\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "992\n" }, { "input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 3\n", "output": "0\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "445\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "201\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 31\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "425\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 33\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "218\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 33\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 59\n", "output": "189\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 33\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 39\n", "output": "169\n" }, { "input": "10\n1 8 31\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "282\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 26\n8 16 40\n", "output": "435\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 5\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "947\n" }, { "input": "3\n1 3 1\n1 2 7\n3 2 1\n", "output": "2\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 15\n2 3 23\n4 6 42\n", "output": "38\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 86\n8 10 90\n", "output": "226\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 67\n", "output": "462\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 29\n2 3 23\n4 6 42\n", "output": "52\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 2\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "932\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 5\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "252\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 37\n20 22 2\n", "output": "383\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 179\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1166\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 30\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 41\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1094\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 62\n", "output": "467\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 53\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "431\n" }, { "input": "10\n1 8 31\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 72\n8 10 90\n", "output": "293\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 7\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 5\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "934\n" }, { "input": "3\n1 3 1\n1 2 7\n3 2 2\n", "output": "3\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 16\n1 4 72\n1 5 54\n", "output": "131\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 39\n8 10 90\n", "output": "179\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 33\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "446\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 3\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 67\n", "output": "441\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 187\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 30\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 41\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1179\n" }, { "input": "10\n1 8 31\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 30\n8 10 90\n", "output": "251\n" }, { "input": "10\n1 8 37\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 30\n8 10 90\n", "output": "257\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 25\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "272\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 40\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "911\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 17\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "264\n" }, { "input": "5\n5 3 89\n2 3 50\n4 2 27\n1 4 69\n1 5 61\n", "output": "146\n" }, { "input": "10\n1 8 23\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "274\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 4\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 62\n", "output": "403\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 1\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 73\n", "output": "203\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 16\n1 4 82\n1 5 54\n", "output": "141\n" }, { "input": "6\n1 5 4\n5 3 12\n2 4 15\n1 6 21\n2 3 32\n4 6 42\n", "output": "53\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 10\n6 9 91\n9 10 72\n14 10 7\n14 17 97\n17 16 67\n8 16 40\n", "output": "420\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 9\n15 6 10\n6 9 91\n9 10 72\n14 10 7\n14 17 97\n17 16 67\n8 16 40\n", "output": "371\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 27\n1 4 69\n1 5 61\n", "output": "139\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 30\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 173\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 96\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "992\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 40\n1 4 69\n1 5 54\n", "output": "143\n" }, { "input": "3\n3 1 2\n2 1 1\n2 3 1\n", "output": "1\n" }, { "input": "4\n1 2 3\n2 3 8\n3 4 7\n4 1 5\n", "output": "0\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 69\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "413\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 19\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 95\n1 4 72\n1 5 54\n", "output": "143\n" }, { "input": "3\n1 3 4\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 27\n1 4 69\n1 5 88\n", "output": "139\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 103\n3 2 57\n10 2 61\n8 10 90\n", "output": "267\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 10\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 69\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "3\n1 3 1\n1 2 14\n3 2 1\n", "output": "2\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 79\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 153\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 66\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 1\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "6\n1 5 4\n5 3 7\n2 4 15\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 19\n3 2 79\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 10\n1 6 29\n2 3 23\n4 6 42\n", "output": "52\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 16\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 37\n20 22 2\n", "output": "383\n" }, { "input": "6\n1 5 4\n5 3 12\n2 4 15\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "6\n1 5 4\n5 3 12\n2 4 11\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 61\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "17\n8 12 84\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "435\n" }, { "input": "3\n1 3 1\n1 2 1\n3 2 2\n", "output": "1\n" }, { "input": "3\n1 3 3\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 53\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "4\n1 2 9\n2 3 8\n3 4 12\n4 1 3\n", "output": "0\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 10\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "445\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 47\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 103\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 10\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 69\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 39\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 85\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "3\n1 3 2\n1 2 14\n3 2 1\n", "output": "3\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 2\n9 25 93\n25 10 28\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "932\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 4\n1 6 29\n2 3 23\n4 6 42\n", "output": "52\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 45\n5 7 86\n7 9 72\n4 9 25\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "272\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 61\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 10\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 100\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 85\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 4\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 147\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 62\n", "output": "403\n" } ] }
[ 0.000006256207725237769, 0.0000029232868991540122, 0.0000014474133228332133, 0.0000013929830762248932, 1.688286558635579e-8, 6.196111505681821e-9, 5.007532506555945e-9, 4.671383304195803e-9, 3.3908298732517487e-9, 3.3143097137237765e-9, 2.8571965144230795e-9, 2.6465458369755264e-9, 2.552119755244754e-9, 2.3572306599650324e-9, 2.0387893356643387e-9, 1.653511527534963e-9, 5.304731552285048e-12 ]
24_A. Ring road
348
348_21
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 other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all n roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is 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? Input 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 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. Examples Input 3 1 3 1 1 2 1 3 2 1 Output 1 Input 3 1 3 1 1 2 5 3 2 1 Output 2 Input 6 1 5 4 5 3 8 2 4 15 1 6 16 2 3 23 4 6 42 Output 39 Input 4 1 2 9 2 3 8 3 4 7 4 1 5 Output 0
source=set() dest=set() c1=0 c2=0 for i in range(int(input())): s,d,w=map(int,input().split()) if s in source or d in dest: c1=c1+w s,d=d,s else: c2=c2+w source.add(s) dest.add(d) print(min(c1,c2))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int v_list: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) v_list = [list(map(int, line.split(' '))) for line in lines[1:-1]] assert n == len(v_list) return cls(n, v_list) def __repr__(self): return str(self.n) + '\n' + '\n'.join([' '.join(map(str, v)) for v in self.v_list]) + '\n'
3 1 3 1 1 2 1 3 2 1
O(n)
0
{ "public_tests": [ { "input": "3\n1 3 1\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "3\n1 3 1\n1 2 5\n3 2 1\n", "output": "2\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n", "output": "39\n" }, { "input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n", "output": "0\n" } ], "private_tests": [ { "input": "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54\n", "output": "143\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "267\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 93\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "413\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "3\n3 1 1\n2 1 1\n2 3 1\n", "output": "1\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "435\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "950\n" } ], "generated_tests": [ { "input": "5\n5 3 89\n2 3 43\n4 2 95\n1 4 69\n1 5 54\n", "output": "143\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "3\n1 3 2\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 27\n1 4 69\n1 5 54\n", "output": "139\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "267\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "413\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 33\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "422\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 96\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "992\n" }, { "input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 3\n", "output": "0\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "445\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "201\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 31\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "425\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 33\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "218\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 33\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 59\n", "output": "189\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 33\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 39\n", "output": "169\n" }, { "input": "10\n1 8 31\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "282\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 26\n8 16 40\n", "output": "435\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 5\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "947\n" }, { "input": "3\n1 3 1\n1 2 7\n3 2 1\n", "output": "2\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 15\n2 3 23\n4 6 42\n", "output": "38\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 86\n8 10 90\n", "output": "226\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 67\n", "output": "462\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 29\n2 3 23\n4 6 42\n", "output": "52\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 2\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "932\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 5\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "252\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 37\n20 22 2\n", "output": "383\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 179\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1166\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 30\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 41\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1094\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 62\n", "output": "467\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 53\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "431\n" }, { "input": "10\n1 8 31\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 72\n8 10 90\n", "output": "293\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 7\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 5\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "934\n" }, { "input": "3\n1 3 1\n1 2 7\n3 2 2\n", "output": "3\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 16\n1 4 72\n1 5 54\n", "output": "131\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 39\n8 10 90\n", "output": "179\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 33\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "446\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 3\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 67\n", "output": "441\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 187\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 30\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 41\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1179\n" }, { "input": "10\n1 8 31\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 30\n8 10 90\n", "output": "251\n" }, { "input": "10\n1 8 37\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 30\n8 10 90\n", "output": "257\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 25\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "272\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 40\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "911\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 17\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "264\n" }, { "input": "5\n5 3 89\n2 3 50\n4 2 27\n1 4 69\n1 5 61\n", "output": "146\n" }, { "input": "10\n1 8 23\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "274\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 4\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 62\n", "output": "403\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 1\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 73\n", "output": "203\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 16\n1 4 82\n1 5 54\n", "output": "141\n" }, { "input": "6\n1 5 4\n5 3 12\n2 4 15\n1 6 21\n2 3 32\n4 6 42\n", "output": "53\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 10\n6 9 91\n9 10 72\n14 10 7\n14 17 97\n17 16 67\n8 16 40\n", "output": "420\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 9\n15 6 10\n6 9 91\n9 10 72\n14 10 7\n14 17 97\n17 16 67\n8 16 40\n", "output": "371\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 27\n1 4 69\n1 5 61\n", "output": "139\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 30\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 173\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 96\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45\n", "output": "992\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 40\n1 4 69\n1 5 54\n", "output": "143\n" }, { "input": "3\n3 1 2\n2 1 1\n2 3 1\n", "output": "1\n" }, { "input": "4\n1 2 3\n2 3 8\n3 4 7\n4 1 5\n", "output": "0\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 69\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "413\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 19\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 95\n1 4 72\n1 5 54\n", "output": "143\n" }, { "input": "3\n1 3 4\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "5\n5 3 89\n2 3 43\n4 2 27\n1 4 69\n1 5 88\n", "output": "139\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 103\n3 2 57\n10 2 61\n8 10 90\n", "output": "267\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 10\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 69\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "3\n1 3 1\n1 2 14\n3 2 1\n", "output": "2\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 79\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 153\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 54\n3 2 66\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 1\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "6\n1 5 4\n5 3 7\n2 4 15\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 120\n7 9 72\n4 9 20\n4 3 19\n3 2 79\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 10\n1 6 29\n2 3 23\n4 6 42\n", "output": "52\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 16\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 37\n20 22 2\n", "output": "383\n" }, { "input": "6\n1 5 4\n5 3 12\n2 4 15\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "6\n1 5 4\n5 3 12\n2 4 11\n1 6 15\n2 3 32\n4 6 42\n", "output": "47\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 61\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "17\n8 12 84\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "435\n" }, { "input": "3\n1 3 1\n1 2 1\n3 2 2\n", "output": "1\n" }, { "input": "3\n1 3 3\n1 2 1\n3 2 1\n", "output": "1\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 53\n24 26 2\n48 26 34\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "4\n1 2 9\n2 3 8\n3 4 12\n4 1 3\n", "output": "0\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 10\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40\n", "output": "445\n" }, { "input": "10\n1 8 16\n6 1 14\n6 5 2\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 47\n10 2 80\n8 10 90\n", "output": "220\n" }, { "input": "22\n18 22 46\n18 21 103\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 10\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 69\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 39\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "945\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 85\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "3\n1 3 2\n1 2 14\n3 2 1\n", "output": "3\n" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 2\n9 25 93\n25 10 28\n10 26 78\n20 26 63\n37 20 9\n29 37 28\n11 29 45\n", "output": "932\n" }, { "input": "6\n1 5 4\n5 3 8\n2 4 4\n1 6 29\n2 3 23\n4 6 42\n", "output": "52\n" }, { "input": "10\n1 8 16\n6 1 80\n6 5 45\n5 7 86\n7 9 72\n4 9 25\n4 3 54\n3 2 57\n10 2 61\n8 10 90\n", "output": "272\n" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 61\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 10\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99\n", "output": "1117\n" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 100\n10 12 81\n17 12 98\n16 17 17\n16 13 35\n4 13 64\n4 11 123\n15 11 18\n6 15 35\n6 7 61\n7 19 31\n19 1 65\n8 1 32\n8 2 85\n9 2 36\n9 3 58\n3 14 65\n20 14 67\n20 22 2\n", "output": "430\n" }, { "input": "17\n8 12 43\n13 12 70\n7 13 4\n11 7 19\n5 11 24\n5 1 100\n4 1 20\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 147\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 62\n", "output": "403\n" } ] }
[ 0.00004369608671875, 0.000014141263453343533, 0.000013194172489619757, 0.00001012090603146853, 7.973542668269233e-8, 3.5460964816433593e-9, 2.9987639313811232e-9, 2.9682309877622372e-9, 2.841551027097901e-9, 2.8166794143356696e-9, 2.7736082277097897e-9, 2.2434303977272726e-9, 2.210398000437068e-9, 2.1625600961538464e-9, 2.1293638002622412e-9, 2.1021771197552437e-9, 2.0926095388985986e-9, 1.9789663461538483e-9 ]
887_B. Cubes for Masha
1722
1722_4
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number. The number can't contain leading zeros. It's not required to use all cubes to build a number. Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations. Input In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday. Each of next n lines contains 6 integers aij (0 ≤ aij ≤ 9) — number on j-th face of i-th cube. Output Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1. Examples Input 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 Output 87 Input 3 0 1 3 5 6 8 1 2 4 5 7 8 2 3 4 6 7 9 Output 98 Note In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
def gen(cur, used, x): pos.add(cur) if x == n: return for j in range(n): if not used[j]: for i in a[j]: if i != 0 or x != 0: used[j] = True gen(cur * 10 + i, used, x + 1) used[j] = False n = int(input()) a = [] for i in range(n): a.append(list(map(int, input().split()))) pos = set() gen(0, [False] * n, 0) x = 1 while x in pos: x += 1 print(x - 1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int lists: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) lists = [list(map(int, line.split())) for line in lines[1:n+1]] return cls(n, lists) def __repr__(self): return str(self.n) + '\n' + '\n'.join(' '.join(map(str, lst)) for lst in self.lists) + '\n'
3 0 1 3 5 6 8 1 2 4 5 7 8 2 3 4 6 7 9
O(n**2)
0.009115
{ "public_tests": [ { "input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "output": "98\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "output": "87\n" } ], "private_tests": [ { "input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "output": "9\n" }, { "input": "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n", "output": "9\n" }, { "input": "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "output": "4\n" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7\n", "output": "2\n" }, { "input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7\n", "output": "10\n" }, { "input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0\n", "output": "10\n" }, { "input": "1\n1 9 8 3 7 8\n", "output": "1\n" }, { "input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 2\n", "output": "4\n" }, { "input": "1\n4 6 9 8 2 7\n", "output": "0\n" }, { "input": "2\n1 7 6 9 2 5\n1 6 7 0 9 2\n", "output": "2\n" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 7 2 2\n", "output": "5\n" }, { "input": "1\n7 6 5 8 9 0\n", "output": "0\n" }, { "input": "3\n3 8 3 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4\n", "output": "8\n" }, { "input": "1\n8 1 9 2 9 7\n", "output": "2\n" }, { "input": "2\n2 0 5 7 0 8\n4 5 1 5 4 9\n", "output": "2\n" }, { "input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4\n", "output": "10\n" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1\n", "output": "19\n" }, { "input": "1\n0 8 7 1 3 2\n", "output": "3\n" }, { "input": "2\n9 3 3 6 7 2\n6 2 9 1 5 9\n", "output": "3\n" }, { "input": "1\n8 2 7 4 1 0\n", "output": "2\n" }, { "input": "2\n3 6 8 9 5 0\n6 7 0 8 2 3\n", "output": "0\n" }, { "input": "1\n0 1 2 3 4 5\n", "output": "5\n" }, { "input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 5 7 0\n", "output": "19\n" }, { "input": "2\n2 3 5 1 9 6\n1 6 8 7 3 9\n", "output": "3\n" }, { "input": "2\n0 9 5 7 6 2\n8 6 2 7 1 4\n", "output": "2\n" }, { "input": "2\n4 3 8 6 0 1\n4 7 1 8 9 0\n", "output": "1\n" }, { "input": "1\n6 2 8 4 5 1\n", "output": "2\n" }, { "input": "1\n4 0 9 6 3 1\n", "output": "1\n" }, { "input": "2\n6 0 1 7 2 9\n1 3 4 6 7 0\n", "output": "4\n" }, { "input": "3\n5 0 7 6 2 1\n2 7 4 6 1 9\n0 2 6 1 7 5\n", "output": "2\n" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 8\n", "output": "9\n" }, { "input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5\n", "output": "5\n" }, { "input": "2\n2 4 0 3 7 6\n3 2 8 7 1 5\n", "output": "8\n" }, { "input": "1\n7 3 6 9 8 1\n", "output": "1\n" }, { "input": "3\n1 1 2 3 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8\n", "output": "10\n" }, { "input": "3\n9 4 3 0 2 6\n7 0 5 3 3 9\n1 0 7 4 6 7\n", "output": "7\n" }, { "input": "1\n3 7 7 6 4 2\n", "output": "0\n" }, { "input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 1\n", "output": "5\n" }, { "input": "2\n1 7 8 6 0 9\n3 2 1 7 4 9\n", "output": "4\n" }, { "input": "2\n0 8 6 2 1 3\n5 2 7 1 0 9\n", "output": "3\n" }, { "input": "2\n5 3 2 9 8 2\n0 7 4 8 1 8\n", "output": "5\n" }, { "input": "3\n3 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9\n", "output": "9\n" }, { "input": "2\n5 1 2 3 0 8\n3 6 7 4 9 2\n", "output": "9\n" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 1 2\n", "output": "29\n" }, { "input": "1\n5 3 8 0 2 6\n", "output": "0\n" }, { "input": "1\n0 7 6 3 2 4\n", "output": "0\n" }, { "input": "2\n8 0 6 5 1 4\n7 1 0 8 3 4\n", "output": "1\n" }, { "input": "2\n7 8 6 1 4 5\n8 6 4 3 2 5\n", "output": "8\n" }, { "input": "2\n0 1 2 3 4 5\n6 6 6 7 8 9\n", "output": "9\n" }, { "input": "3\n9 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3\n", "output": "21\n" }, { "input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 2\n", "output": "6\n" }, { "input": "3\n0 1 2 2 4 5\n6 7 8 9 0 1\n3 3 4 5 6 7\n", "output": "21\n" }, { "input": "1\n1 4 5 7 0 5\n", "output": "1\n" }, { "input": "2\n8 6 4 1 2 0\n7 8 5 3 2 1\n", "output": "8\n" }, { "input": "3\n5 6 2 9 3 5\n5 4 1 5 9 8\n4 4 2 0 3 5\n", "output": "6\n" }, { "input": "1\n9 8 1 6 5 7\n", "output": "1\n" }, { "input": "3\n7 2 1 3 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0\n", "output": "21\n" }, { "input": "3\n9 4 3 3 9 3\n1 0 3 4 5 3\n2 9 6 2 4 1\n", "output": "6\n" }, { "input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8\n", "output": "3\n" }, { "input": "3\n8 1 8 2 7 1\n9 1 9 9 4 7\n0 0 9 0 4 0\n", "output": "2\n" }, { "input": "1\n2 5 9 6 7 9\n", "output": "0\n" }, { "input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 3 2 5 7\n", "output": "0\n" }, { "input": "3\n8 6 0 5 4 9\n1 8 5 3 9 7\n7 4 5 1 6 8\n", "output": "1\n" }, { "input": "1\n8 6 0 9 4 2\n", "output": "0\n" }, { "input": "1\n7 9 2 5 0 4\n", "output": "0\n" }, { "input": "1\n6 0 7 5 4 8\n", "output": "0\n" }, { "input": "2\n5 8 4 7 1 2\n0 8 6 2 4 9\n", "output": "2\n" }, { "input": "1\n5 2 2 5 6 7\n", "output": "0\n" }, { "input": "2\n6 5 2 7 1 3\n3 7 8 1 0 9\n", "output": "3\n" }, { "input": "1\n8 3 5 4 2 9\n", "output": "0\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 7 8\n", "output": "98\n" }, { "input": "2\n6 6 4 7 9 0\n2 1 2 8 6 4\n", "output": "2\n" }, { "input": "3\n2 3 4 5 6 7\n3 4 5 6 7 8\n9 1 2 3 4 5\n", "output": "9\n" }, { "input": "2\n0 1 2 3 4 5\n4 5 6 7 8 9\n", "output": "9\n" }, { "input": "3\n2 7 3 6 4 5\n0 2 1 9 4 8\n8 6 9 5 4 0\n", "output": "10\n" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 6 6\n", "output": "9\n" }, { "input": "2\n1 7 2 0 4 3\n5 2 3 6 1 0\n", "output": "7\n" }, { "input": "1\n6 2 8 5 1 3\n", "output": "3\n" }, { "input": "3\n5 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3\n", "output": "21\n" }, { "input": "1\n6 3 1 9 4 9\n", "output": "1\n" }, { "input": "3\n0 1 9 1 0 8\n9 9 3 5 6 2\n9 3 9 9 7 3\n", "output": "3\n" }, { "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9\n", "output": "32\n" }, { "input": "3\n2 0 1 3 4 5\n6 7 8 9 1 1\n3 4 5 6 6 7\n", "output": "19\n" }, { "input": "3\n4 4 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9\n", "output": "1\n" }, { "input": "2\n0 1 2 3 4 5\n9 8 7 6 5 4\n", "output": "9\n" }, { "input": "2\n0 2 9 1 8 5\n0 7 4 3 2 5\n", "output": "5\n" }, { "input": "2\n2 3 9 1 6 7\n2 5 4 3 0 6\n", "output": "7\n" }, { "input": "2\n5 7 4 2 1 9\n2 2 7 1 1 8\n", "output": "2\n" }, { "input": "1\n3 9 1 7 4 5\n", "output": "1\n" }, { "input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 2 1 1 9 1\n", "output": "7\n" }, { "input": "1\n7 9 5 0 4 6\n", "output": "0\n" }, { "input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 5\n", "output": "65\n" }, { "input": "1\n4 3 8 9 2 3\n", "output": "0\n" } ], "generated_tests": [ { "input": "2\n2 8 8 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 3 7\n", "output": "5\n" }, { "input": "3\n9 4 6 3 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "output": "4\n" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 2 7 5 1 7\n", "output": "2\n" }, { "input": "1\n4 6 9 5 2 7\n", "output": "0\n" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 6 2 2\n", "output": "8\n" }, { "input": "1\n7 6 5 8 9 1\n", "output": "1\n" }, { "input": "3\n1 1 1 1 1 1\n0 2 3 3 5 6\n7 8 9 2 3 4\n", "output": "10\n" }, { "input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 7 7 0\n", "output": "19\n" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 8 5 6 7 8\n", "output": "9\n" }, { "input": "3\n9 4 3 0 2 6\n7 0 5 3 0 9\n1 0 7 4 6 7\n", "output": "7\n" }, { "input": "2\n0 1 2 3 4 5\n6 6 6 0 8 9\n", "output": "6\n" }, { "input": "3\n2 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3\n", "output": "43\n" }, { "input": "3\n0 1 2 2 4 0\n6 7 8 9 0 1\n3 3 4 5 6 7\n", "output": "21\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 9 8\n", "output": "76\n" }, { "input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 4\n", "output": "54\n" }, { "input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 2 7\n", "output": "2\n" }, { "input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 3\n", "output": "4\n" }, { "input": "3\n3 8 5 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4\n", "output": "8\n" }, { "input": "2\n2 0 5 7 0 8\n4 5 1 5 4 6\n", "output": "2\n" }, { "input": "2\n9 3 3 9 7 2\n6 2 9 1 5 9\n", "output": "3\n" }, { "input": "1\n8 2 7 4 2 0\n", "output": "0\n" }, { "input": "2\n3 6 8 9 5 0\n6 7 0 8 4 3\n", "output": "0\n" }, { "input": "1\n0 1 4 3 4 5\n", "output": "1\n" }, { "input": "2\n2 3 5 1 9 6\n1 6 5 7 3 9\n", "output": "3\n" }, { "input": "2\n4 3 8 6 0 1\n1 7 1 8 9 0\n", "output": "1\n" }, { "input": "1\n6 2 7 4 5 1\n", "output": "2\n" }, { "input": "1\n7 0 9 6 3 1\n", "output": "1\n" }, { "input": "2\n6 0 1 7 2 9\n1 3 4 7 7 0\n", "output": "4\n" }, { "input": "3\n0 1 2 3 4 5\n0 1 2 3 4 9\n0 1 2 3 4 5\n", "output": "5\n" }, { "input": "2\n2 4 0 6 7 6\n3 2 8 7 1 5\n", "output": "8\n" }, { "input": "1\n7 3 8 9 8 1\n", "output": "1\n" }, { "input": "3\n1 1 2 4 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8\n", "output": "10\n" }, { "input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 0\n", "output": "5\n" }, { "input": "2\n5 1 2 9 8 2\n0 7 4 8 1 8\n", "output": "2\n" }, { "input": "3\n4 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9\n", "output": "9\n" }, { "input": "2\n5 1 4 3 0 8\n3 6 7 4 9 2\n", "output": "9\n" }, { "input": "1\n5 3 8 0 4 6\n", "output": "0\n" }, { "input": "1\n1 7 6 3 2 4\n", "output": "4\n" }, { "input": "2\n8 0 6 5 1 1\n7 1 0 8 3 4\n", "output": "1\n" }, { "input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 0\n", "output": "6\n" }, { "input": "1\n1 2 5 7 0 5\n", "output": "2\n" }, { "input": "3\n5 6 2 9 3 5\n5 4 1 8 9 8\n4 4 2 0 3 5\n", "output": "6\n" }, { "input": "1\n9 8 1 6 5 2\n", "output": "2\n" }, { "input": "3\n7 2 1 5 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0\n", "output": "21\n" }, { "input": "3\n9 4 3 3 9 3\n0 0 3 4 5 3\n2 9 6 2 4 1\n", "output": "6\n" }, { "input": "3\n1 1 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8\n", "output": "3\n" }, { "input": "3\n8 1 8 2 7 1\n9 1 9 4 4 7\n0 0 9 0 4 0\n", "output": "2\n" }, { "input": "1\n3 5 9 6 7 9\n", "output": "0\n" }, { "input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 5 2 5 7\n", "output": "0\n" }, { "input": "3\n8 6 0 5 4 4\n1 8 5 3 9 7\n7 4 5 1 6 8\n", "output": "1\n" }, { "input": "1\n2 6 0 9 4 2\n", "output": "0\n" }, { "input": "1\n7 0 7 5 4 8\n", "output": "0\n" }, { "input": "2\n5 8 4 7 1 3\n0 8 6 2 4 9\n", "output": "10\n" }, { "input": "1\n5 2 2 5 3 7\n", "output": "0\n" }, { "input": "1\n8 3 5 4 2 3\n", "output": "0\n" }, { "input": "3\n2 3 4 5 6 7\n3 4 6 6 7 8\n9 1 2 3 4 5\n", "output": "9\n" }, { "input": "2\n0 1 2 3 4 5\n3 5 6 7 8 9\n", "output": "9\n" }, { "input": "2\n0 1 2 5 4 5\n6 7 8 9 6 6\n", "output": "2\n" }, { "input": "2\n1 3 2 0 4 3\n5 2 3 6 1 0\n", "output": "6\n" }, { "input": "1\n6 2 5 5 1 3\n", "output": "3\n" }, { "input": "3\n0 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3\n", "output": "21\n" }, { "input": "1\n6 1 1 9 4 9\n", "output": "1\n" }, { "input": "3\n0 1 9 1 1 8\n9 9 3 5 6 2\n9 3 9 9 7 3\n", "output": "3\n" }, { "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 0\n5 2 0 3 1 9\n", "output": "3\n" }, { "input": "3\n4 0 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9\n", "output": "1\n" }, { "input": "2\n0 1 2 3 4 5\n9 8 7 6 5 5\n", "output": "9\n" }, { "input": "2\n0 2 9 1 8 5\n0 7 4 0 2 5\n", "output": "2\n" }, { "input": "2\n2 3 9 1 6 5\n2 5 4 3 0 6\n", "output": "6\n" }, { "input": "2\n5 7 4 2 1 9\n2 2 7 1 2 8\n", "output": "2\n" }, { "input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 1 1 1 9 1\n", "output": "7\n" }, { "input": "1\n8 9 5 0 4 6\n", "output": "0\n" }, { "input": "1\n4 3 6 9 2 3\n", "output": "0\n" }, { "input": "3\n0 1 2 3 4 5\n6 4 8 9 0 1\n2 3 4 5 6 7\n", "output": "76\n" }, { "input": "2\n2 8 3 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 8 3 7\n", "output": "4\n" }, { "input": "3\n9 4 7 3 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "output": "4\n" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 2\n2 2 7 5 1 7\n", "output": "2\n" }, { "input": "3\n5 1 2 9 6 4\n9 1 6 4 2 8\n4 6 2 8 2 7\n", "output": "2\n" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n6 7 2 6 2 2\n", "output": "8\n" } ] }
[ 0.014782952877944327, 0.01350315644325482, 0.012996374319771593, 0.012571852147751606, 0.010349596398286937, 0.009887494713062099, 0.009114681620271237, 0.008957700438258389, 0.0074569165867237695, 0.007336192713775875, 0.006912358371877231, 0.005564451643112064, 0.004580531085653105, 0.0005670190990968464, 0.0005353614991248094, 0.00022555469850177656, 0.00018467904111467504, 7.94167531687063e-8 ]
887_B. Cubes for Masha
1722
1722_66
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number. The number can't contain leading zeros. It's not required to use all cubes to build a number. Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations. Input In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday. Each of next n lines contains 6 integers aij (0 ≤ aij ≤ 9) — number on j-th face of i-th cube. Output Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1. Examples Input 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 Output 87 Input 3 0 1 3 5 6 8 1 2 4 5 7 8 2 3 4 6 7 9 Output 98 Note In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
n = int(input()) a = [] a += [list(input())] if (n > 1): a += [list(input())] if (n > 2): a += [list(input())] i = 1 while (i < 1000): s = list(str(i)) if (n == 1): if (s[0] in a[0]): i += 1 continue if (n == 2): if (len(s) == 1 and (s[0] in a[0] or s[0] in a[1])): i += 1 continue if (len(s) == 2 and ( (s[0] in a[0] and s[1] in a[1]) or (s[0] in a[1] and s[1] in a[0]))): i += 1 continue if (n == 3): if (len(s) == 1 and (s[0] in a[0] or s[0] in a[1] or s[0] in a[2])): i += 1 continue if (len(s) == 2 and ( (s[0] in a[0] and s[1] in a[1]) or (s[0] in a[0] and s[1] in a[2]) or (s[0] in a[1] and s[1] in a[0]) or (s[0] in a[1] and s[1] in a[2]) or (s[0] in a[2] and s[1] in a[0]) or (s[0] in a[2] and s[1] in a[1]))): i += 1 continue if (len(s) == 3 and ( (s[0] in a[0] and s[1] in a[1] and s[2] in a[2]) or (s[0] in a[0] and s[1] in a[2] and s[2] in a[1]) or (s[0] in a[1] and s[1] in a[0] and s[2] in a[2]) or (s[0] in a[1] and s[1] in a[2] and s[2] in a[0]) or (s[0] in a[2] and s[1] in a[0] and s[2] in a[1]) or (s[0] in a[2] and s[1] in a[1] and s[2] in a[0]) )): i += 1 continue print (i-1) break
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int lists: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) lists = [list(map(int, line.split())) for line in lines[1:n+1]] return cls(n, lists) def __repr__(self): return str(self.n) + '\n' + '\n'.join(' '.join(map(str, lst)) for lst in self.lists) + '\n'
3 0 1 3 5 6 8 1 2 4 5 7 8 2 3 4 6 7 9
O(n)
0.000012
{ "public_tests": [ { "input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "output": "98\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "output": "87\n" } ], "private_tests": [ { "input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "output": "9\n" }, { "input": "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n", "output": "9\n" }, { "input": "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "output": "4\n" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7\n", "output": "2\n" }, { "input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7\n", "output": "10\n" }, { "input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0\n", "output": "10\n" }, { "input": "1\n1 9 8 3 7 8\n", "output": "1\n" }, { "input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 2\n", "output": "4\n" }, { "input": "1\n4 6 9 8 2 7\n", "output": "0\n" }, { "input": "2\n1 7 6 9 2 5\n1 6 7 0 9 2\n", "output": "2\n" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 7 2 2\n", "output": "5\n" }, { "input": "1\n7 6 5 8 9 0\n", "output": "0\n" }, { "input": "3\n3 8 3 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4\n", "output": "8\n" }, { "input": "1\n8 1 9 2 9 7\n", "output": "2\n" }, { "input": "2\n2 0 5 7 0 8\n4 5 1 5 4 9\n", "output": "2\n" }, { "input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4\n", "output": "10\n" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1\n", "output": "19\n" }, { "input": "1\n0 8 7 1 3 2\n", "output": "3\n" }, { "input": "2\n9 3 3 6 7 2\n6 2 9 1 5 9\n", "output": "3\n" }, { "input": "1\n8 2 7 4 1 0\n", "output": "2\n" }, { "input": "2\n3 6 8 9 5 0\n6 7 0 8 2 3\n", "output": "0\n" }, { "input": "1\n0 1 2 3 4 5\n", "output": "5\n" }, { "input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 5 7 0\n", "output": "19\n" }, { "input": "2\n2 3 5 1 9 6\n1 6 8 7 3 9\n", "output": "3\n" }, { "input": "2\n0 9 5 7 6 2\n8 6 2 7 1 4\n", "output": "2\n" }, { "input": "2\n4 3 8 6 0 1\n4 7 1 8 9 0\n", "output": "1\n" }, { "input": "1\n6 2 8 4 5 1\n", "output": "2\n" }, { "input": "1\n4 0 9 6 3 1\n", "output": "1\n" }, { "input": "2\n6 0 1 7 2 9\n1 3 4 6 7 0\n", "output": "4\n" }, { "input": "3\n5 0 7 6 2 1\n2 7 4 6 1 9\n0 2 6 1 7 5\n", "output": "2\n" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 8\n", "output": "9\n" }, { "input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5\n", "output": "5\n" }, { "input": "2\n2 4 0 3 7 6\n3 2 8 7 1 5\n", "output": "8\n" }, { "input": "1\n7 3 6 9 8 1\n", "output": "1\n" }, { "input": "3\n1 1 2 3 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8\n", "output": "10\n" }, { "input": "3\n9 4 3 0 2 6\n7 0 5 3 3 9\n1 0 7 4 6 7\n", "output": "7\n" }, { "input": "1\n3 7 7 6 4 2\n", "output": "0\n" }, { "input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 1\n", "output": "5\n" }, { "input": "2\n1 7 8 6 0 9\n3 2 1 7 4 9\n", "output": "4\n" }, { "input": "2\n0 8 6 2 1 3\n5 2 7 1 0 9\n", "output": "3\n" }, { "input": "2\n5 3 2 9 8 2\n0 7 4 8 1 8\n", "output": "5\n" }, { "input": "3\n3 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9\n", "output": "9\n" }, { "input": "2\n5 1 2 3 0 8\n3 6 7 4 9 2\n", "output": "9\n" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 1 2\n", "output": "29\n" }, { "input": "1\n5 3 8 0 2 6\n", "output": "0\n" }, { "input": "1\n0 7 6 3 2 4\n", "output": "0\n" }, { "input": "2\n8 0 6 5 1 4\n7 1 0 8 3 4\n", "output": "1\n" }, { "input": "2\n7 8 6 1 4 5\n8 6 4 3 2 5\n", "output": "8\n" }, { "input": "2\n0 1 2 3 4 5\n6 6 6 7 8 9\n", "output": "9\n" }, { "input": "3\n9 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3\n", "output": "21\n" }, { "input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 2\n", "output": "6\n" }, { "input": "3\n0 1 2 2 4 5\n6 7 8 9 0 1\n3 3 4 5 6 7\n", "output": "21\n" }, { "input": "1\n1 4 5 7 0 5\n", "output": "1\n" }, { "input": "2\n8 6 4 1 2 0\n7 8 5 3 2 1\n", "output": "8\n" }, { "input": "3\n5 6 2 9 3 5\n5 4 1 5 9 8\n4 4 2 0 3 5\n", "output": "6\n" }, { "input": "1\n9 8 1 6 5 7\n", "output": "1\n" }, { "input": "3\n7 2 1 3 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0\n", "output": "21\n" }, { "input": "3\n9 4 3 3 9 3\n1 0 3 4 5 3\n2 9 6 2 4 1\n", "output": "6\n" }, { "input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8\n", "output": "3\n" }, { "input": "3\n8 1 8 2 7 1\n9 1 9 9 4 7\n0 0 9 0 4 0\n", "output": "2\n" }, { "input": "1\n2 5 9 6 7 9\n", "output": "0\n" }, { "input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 3 2 5 7\n", "output": "0\n" }, { "input": "3\n8 6 0 5 4 9\n1 8 5 3 9 7\n7 4 5 1 6 8\n", "output": "1\n" }, { "input": "1\n8 6 0 9 4 2\n", "output": "0\n" }, { "input": "1\n7 9 2 5 0 4\n", "output": "0\n" }, { "input": "1\n6 0 7 5 4 8\n", "output": "0\n" }, { "input": "2\n5 8 4 7 1 2\n0 8 6 2 4 9\n", "output": "2\n" }, { "input": "1\n5 2 2 5 6 7\n", "output": "0\n" }, { "input": "2\n6 5 2 7 1 3\n3 7 8 1 0 9\n", "output": "3\n" }, { "input": "1\n8 3 5 4 2 9\n", "output": "0\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 7 8\n", "output": "98\n" }, { "input": "2\n6 6 4 7 9 0\n2 1 2 8 6 4\n", "output": "2\n" }, { "input": "3\n2 3 4 5 6 7\n3 4 5 6 7 8\n9 1 2 3 4 5\n", "output": "9\n" }, { "input": "2\n0 1 2 3 4 5\n4 5 6 7 8 9\n", "output": "9\n" }, { "input": "3\n2 7 3 6 4 5\n0 2 1 9 4 8\n8 6 9 5 4 0\n", "output": "10\n" }, { "input": "2\n0 1 2 3 4 5\n6 7 8 9 6 6\n", "output": "9\n" }, { "input": "2\n1 7 2 0 4 3\n5 2 3 6 1 0\n", "output": "7\n" }, { "input": "1\n6 2 8 5 1 3\n", "output": "3\n" }, { "input": "3\n5 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3\n", "output": "21\n" }, { "input": "1\n6 3 1 9 4 9\n", "output": "1\n" }, { "input": "3\n0 1 9 1 0 8\n9 9 3 5 6 2\n9 3 9 9 7 3\n", "output": "3\n" }, { "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9\n", "output": "32\n" }, { "input": "3\n2 0 1 3 4 5\n6 7 8 9 1 1\n3 4 5 6 6 7\n", "output": "19\n" }, { "input": "3\n4 4 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9\n", "output": "1\n" }, { "input": "2\n0 1 2 3 4 5\n9 8 7 6 5 4\n", "output": "9\n" }, { "input": "2\n0 2 9 1 8 5\n0 7 4 3 2 5\n", "output": "5\n" }, { "input": "2\n2 3 9 1 6 7\n2 5 4 3 0 6\n", "output": "7\n" }, { "input": "2\n5 7 4 2 1 9\n2 2 7 1 1 8\n", "output": "2\n" }, { "input": "1\n3 9 1 7 4 5\n", "output": "1\n" }, { "input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 2 1 1 9 1\n", "output": "7\n" }, { "input": "1\n7 9 5 0 4 6\n", "output": "0\n" }, { "input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 5\n", "output": "65\n" }, { "input": "1\n4 3 8 9 2 3\n", "output": "0\n" } ], "generated_tests": [ { "input": "2\n2 8 8 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 3 7\n", "output": "5\n" }, { "input": "3\n9 4 6 3 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "output": "4\n" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 2 7 5 1 7\n", "output": "2\n" }, { "input": "1\n4 6 9 5 2 7\n", "output": "0\n" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 6 2 2\n", "output": "8\n" }, { "input": "1\n7 6 5 8 9 1\n", "output": "1\n" }, { "input": "3\n1 1 1 1 1 1\n0 2 3 3 5 6\n7 8 9 2 3 4\n", "output": "10\n" }, { "input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 7 7 0\n", "output": "19\n" }, { "input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 8 5 6 7 8\n", "output": "9\n" }, { "input": "3\n9 4 3 0 2 6\n7 0 5 3 0 9\n1 0 7 4 6 7\n", "output": "7\n" }, { "input": "2\n0 1 2 3 4 5\n6 6 6 0 8 9\n", "output": "6\n" }, { "input": "3\n2 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3\n", "output": "43\n" }, { "input": "3\n0 1 2 2 4 0\n6 7 8 9 0 1\n3 3 4 5 6 7\n", "output": "21\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 9 8\n", "output": "76\n" }, { "input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 4\n", "output": "54\n" }, { "input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 2 7\n", "output": "2\n" }, { "input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 3\n", "output": "4\n" }, { "input": "3\n3 8 5 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4\n", "output": "8\n" }, { "input": "2\n2 0 5 7 0 8\n4 5 1 5 4 6\n", "output": "2\n" }, { "input": "2\n9 3 3 9 7 2\n6 2 9 1 5 9\n", "output": "3\n" }, { "input": "1\n8 2 7 4 2 0\n", "output": "0\n" }, { "input": "2\n3 6 8 9 5 0\n6 7 0 8 4 3\n", "output": "0\n" }, { "input": "1\n0 1 4 3 4 5\n", "output": "1\n" }, { "input": "2\n2 3 5 1 9 6\n1 6 5 7 3 9\n", "output": "3\n" }, { "input": "2\n4 3 8 6 0 1\n1 7 1 8 9 0\n", "output": "1\n" }, { "input": "1\n6 2 7 4 5 1\n", "output": "2\n" }, { "input": "1\n7 0 9 6 3 1\n", "output": "1\n" }, { "input": "2\n6 0 1 7 2 9\n1 3 4 7 7 0\n", "output": "4\n" }, { "input": "3\n0 1 2 3 4 5\n0 1 2 3 4 9\n0 1 2 3 4 5\n", "output": "5\n" }, { "input": "2\n2 4 0 6 7 6\n3 2 8 7 1 5\n", "output": "8\n" }, { "input": "1\n7 3 8 9 8 1\n", "output": "1\n" }, { "input": "3\n1 1 2 4 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8\n", "output": "10\n" }, { "input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 0\n", "output": "5\n" }, { "input": "2\n5 1 2 9 8 2\n0 7 4 8 1 8\n", "output": "2\n" }, { "input": "3\n4 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9\n", "output": "9\n" }, { "input": "2\n5 1 4 3 0 8\n3 6 7 4 9 2\n", "output": "9\n" }, { "input": "1\n5 3 8 0 4 6\n", "output": "0\n" }, { "input": "1\n1 7 6 3 2 4\n", "output": "4\n" }, { "input": "2\n8 0 6 5 1 1\n7 1 0 8 3 4\n", "output": "1\n" }, { "input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 0\n", "output": "6\n" }, { "input": "1\n1 2 5 7 0 5\n", "output": "2\n" }, { "input": "3\n5 6 2 9 3 5\n5 4 1 8 9 8\n4 4 2 0 3 5\n", "output": "6\n" }, { "input": "1\n9 8 1 6 5 2\n", "output": "2\n" }, { "input": "3\n7 2 1 5 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0\n", "output": "21\n" }, { "input": "3\n9 4 3 3 9 3\n0 0 3 4 5 3\n2 9 6 2 4 1\n", "output": "6\n" }, { "input": "3\n1 1 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8\n", "output": "3\n" }, { "input": "3\n8 1 8 2 7 1\n9 1 9 4 4 7\n0 0 9 0 4 0\n", "output": "2\n" }, { "input": "1\n3 5 9 6 7 9\n", "output": "0\n" }, { "input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 5 2 5 7\n", "output": "0\n" }, { "input": "3\n8 6 0 5 4 4\n1 8 5 3 9 7\n7 4 5 1 6 8\n", "output": "1\n" }, { "input": "1\n2 6 0 9 4 2\n", "output": "0\n" }, { "input": "1\n7 0 7 5 4 8\n", "output": "0\n" }, { "input": "2\n5 8 4 7 1 3\n0 8 6 2 4 9\n", "output": "10\n" }, { "input": "1\n5 2 2 5 3 7\n", "output": "0\n" }, { "input": "1\n8 3 5 4 2 3\n", "output": "0\n" }, { "input": "3\n2 3 4 5 6 7\n3 4 6 6 7 8\n9 1 2 3 4 5\n", "output": "9\n" }, { "input": "2\n0 1 2 3 4 5\n3 5 6 7 8 9\n", "output": "9\n" }, { "input": "2\n0 1 2 5 4 5\n6 7 8 9 6 6\n", "output": "2\n" }, { "input": "2\n1 3 2 0 4 3\n5 2 3 6 1 0\n", "output": "6\n" }, { "input": "1\n6 2 5 5 1 3\n", "output": "3\n" }, { "input": "3\n0 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3\n", "output": "21\n" }, { "input": "1\n6 1 1 9 4 9\n", "output": "1\n" }, { "input": "3\n0 1 9 1 1 8\n9 9 3 5 6 2\n9 3 9 9 7 3\n", "output": "3\n" }, { "input": "3\n8 1 6 8 6 8\n7 0 2 5 8 0\n5 2 0 3 1 9\n", "output": "3\n" }, { "input": "3\n4 0 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9\n", "output": "1\n" }, { "input": "2\n0 1 2 3 4 5\n9 8 7 6 5 5\n", "output": "9\n" }, { "input": "2\n0 2 9 1 8 5\n0 7 4 0 2 5\n", "output": "2\n" }, { "input": "2\n2 3 9 1 6 5\n2 5 4 3 0 6\n", "output": "6\n" }, { "input": "2\n5 7 4 2 1 9\n2 2 7 1 2 8\n", "output": "2\n" }, { "input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 1 1 1 9 1\n", "output": "7\n" }, { "input": "1\n8 9 5 0 4 6\n", "output": "0\n" }, { "input": "1\n4 3 6 9 2 3\n", "output": "0\n" }, { "input": "3\n0 1 2 3 4 5\n6 4 8 9 0 1\n2 3 4 5 6 7\n", "output": "76\n" }, { "input": "2\n2 8 3 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 8 3 7\n", "output": "4\n" }, { "input": "3\n9 4 7 3 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "output": "4\n" }, { "input": "3\n2 7 4 0 7 1\n5 5 4 9 1 2\n2 2 7 5 1 7\n", "output": "2\n" }, { "input": "3\n5 1 2 9 6 4\n9 1 6 4 2 8\n4 6 2 8 2 7\n", "output": "2\n" }, { "input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n6 7 2 6 2 2\n", "output": "8\n" } ] }
[ 0.005849447000000001, 0.000016723487366149474, 0.000016640169061407343, 0.000016640003537478148, 0.000014919842466127624, 0.000012939876393138112, 0.000012301240944602274, 0.000011666880750109266, 0.00001125980337631119, 0.000010597934467875874, 0.000010357546588177449, 0.000009252246325939686, 0.000009137068646197553, 0.000008987953288898602, 0.000008818455310314685, 0.000008370434741040211, 0.00000835540854458042, 0.000008103299019340037, 0.000007975758823208042, 0.00000783414571951486, 0.000007805592616368008, 0.00000760988192471591, 0.000007482569615930945, 0.000007298475060096155, 0.00000612101804250437, 0.000006065620506446678, 0.000006022855987762238, 0.000005766412396197553, 0.000005096227450284091, 0.000004495037082058566, 0.000004486675521743881, 0.000004461728146853147, 0.000004328516690340909, 0.000004310193345716783, 0.0000040848091947115385, 0.000003990508550043707, 0.000003967606848229895, 0.0000035513610822770993, 0.0000028399262729458043, 0.0000027334650349650354, 2.7285818673513995e-7, 1.9307099541083917e-7, 1.6599750054632867e-7 ]
1323_C. Unusual Competitions
661
661_99
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry's class a very strange task — she asked every student to come up with a sequence of arbitrary length, consisting only of opening and closing brackets. After that all the students took turns naming the sequences they had invented. When Dima's turn came, he suddenly realized that all his classmates got the correct bracketed sequence, and whether he got the correct bracketed sequence, he did not know. Dima suspects now that he simply missed the word "correct" in the task statement, so now he wants to save the situation by modifying his sequence slightly. More precisely, he can the arbitrary number of times (possibly zero) perform the reorder operation. The reorder operation consists of choosing an arbitrary consecutive subsegment (substring) of the sequence and then reordering all the characters in it in an arbitrary way. Such operation takes l nanoseconds, where l is the length of the subsegment being reordered. It's easy to see that reorder operation doesn't change the number of opening and closing brackets. For example for "))((" he can choose the substring ")(" and do reorder ")()(" (this operation will take 2 nanoseconds). Since Dima will soon have to answer, he wants to make his sequence correct as fast as possible. Help him to do this, or determine that it's impossible. Input The first line contains a single integer n (1 ≤ n ≤ 10^6) — the length of Dima's sequence. The second line contains string of length n, consisting of characters "(" and ")" only. Output Print a single integer — the minimum number of nanoseconds to make the sequence correct or "-1" if it is impossible to do so. Examples Input 8 ))((())( Output 6 Input 3 (() Output -1 Note In the first example we can firstly reorder the segment from first to the fourth character, replacing it with "()()", the whole sequence will be "()()())(". And then reorder the segment from the seventh to eighth character, replacing it with "()". In the end the sequence will be "()()()()", while the total time spent is 4 + 2 = 6 nanoseconds.
n=int(input()) brak=[i for i in input()] open_=0 close_=0 if brak.count('(')!=brak.count(')'): print(-1) else: count=0 for i in brak: if i=="(": open_+=1 else: close_+=1 if close_>open_: count+=2 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: n: int s: str @classmethod def from_str(cls, input_: str): n, s, _ = input_.split('\n') n = int(n) s = s.strip() return cls(n, s) def __repr__(self): return str(self.n) + '\n' + self.s + '\n'
8 ))((())(
O(n)
0.000003
{ "public_tests": [ { "input": "8\n))((())(\n", "output": "6\n" }, { "input": "3\n(()\n", "output": "-1\n" } ], "private_tests": [ { "input": "4\n))))\n", "output": "-1\n" }, { "input": "4\n))((\n", "output": "4\n" }, { "input": "4\n((()\n", "output": "-1\n" }, { "input": "4\n()()\n", "output": "0\n" }, { "input": "4\n((((\n", "output": "-1\n" }, { "input": "100\n)))))))(((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))\n", "output": "14\n" }, { "input": "51\n))((((((((()))(())()(()(()())()(()(())(())()())))))\n", "output": "-1\n" }, { "input": "100\n))()()(())()()(()()())((()()())())((())())((()))(())()((()))((())())()((()())())(()())(())(()(()))((\n", "output": "80\n" }, { "input": "10\n))))((((()\n", "output": "8\n" }, { "input": "10\n())(((()))\n", "output": "2\n" }, { "input": "100\n)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "100\n" }, { "input": "50\n(((((((((((((((((((((((()))))))))))))))))))))))))(\n", "output": "2\n" }, { "input": "10\n(())())()(\n", "output": "4\n" }, { "input": "100\n)(((((()())((())((())((()))())))))(())())()((())))(()()))(((((((()())())()(()())(((())())())())()))(\n", "output": "20\n" }, { "input": "100\n()()()()()()()()()()())(()()()()()()()()()()()()()()()()()()()())(()()()()()()()()()()()()()()()()()\n", "output": "4\n" }, { "input": "4\n)()(\n", "output": "4\n" }, { "input": "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "output": "44\n" }, { "input": "8\n)(((((((\n", "output": "-1\n" }, { "input": "10\n)()()()()(\n", "output": "10\n" }, { "input": "6\n((((()\n", "output": "-1\n" }, { "input": "11\n)(())(((())\n", "output": "-1\n" }, { "input": "50\n()())()))()())((())))(((((()))(((()))((((()(()))))\n", "output": "28\n" }, { "input": "1\n(\n", "output": "-1\n" }, { "input": "50\n)()()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "50\n" }, { "input": "101\n(())))))()))()())(()))((())))((())(()()()(()()((()()((()((())))((()))()(())(()(())((()))(()))()(((()(\n", "output": "-1\n" }, { "input": "2\n((\n", "output": "-1\n" } ], "generated_tests": [ { "input": "4\n))()\n", "output": "-1\n" }, { "input": "100\n)))))))((((((((((((((((((((((((((()(((((((((((((((((((((())))))))))))))))))))))))))))))))))))))())))\n", "output": "14\n" }, { "input": "100\n))()()(())()()(()()())((()()())())((())())((()))(())()((()()()())())()((()())())(()())(())(()(()))((\n", "output": "76\n" }, { "input": "10\n)((((())))\n", "output": "2\n" }, { "input": "100\n)()()()()()()()()()()()()()()()()((()()()()()()()()()()()()()()()()()))()()()()()()()()()()()()()()(\n", "output": "64\n" }, { "input": "50\n()))))))))))))))))))))))))((((((((((((((((((((((((\n", "output": "48\n" }, { "input": "100\n()))())())())())(((())()(()())())()(((((((()))()(())))((()())())(())))))()))((())((())((())()(((((()\n", "output": "80\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()()()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "0\n" }, { "input": "50\n()())(())()())((())))(((((()))((())))((((()(()))))\n", "output": "18\n" }, { "input": "10\n)()((())()\n", "output": "4\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()((()))()()()((()()()\n", "output": "24\n" }, { "input": "10\n)())((()()\n", "output": "6\n" }, { "input": "10\n))))((()((\n", "output": "10\n" }, { "input": "50\n)))))(()((((()))(((()))(((((())))((())()()))())()(\n", "output": "22\n" }, { "input": "100\n))))())))))))))))))))))))))))))))))))))))))(((((((((((((((((((((()((((((((((((((((((((((((((()))))))\n", "output": "86\n" }, { "input": "50\n()())(())()())((())))((((())))((())))(((((((()))))\n", "output": "26\n" }, { "input": "10\n()))()()((\n", "output": "8\n" }, { "input": "100\n)()()()()()()()()()()()()()()))()(())()()()()()()()()()()()))()((()()()()()(())()()()()()()()((()()(\n", "output": "100\n" }, { "input": "4\n)(((\n", "output": "-1\n" }, { "input": "10\n)))(((()))\n", "output": "-1\n" }, { "input": "100\n((()()))(()()))()))))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "output": "-1\n" }, { "input": "8\n((((((()\n", "output": "-1\n" }, { "input": "11\n)())((((())\n", "output": "-1\n" }, { "input": "101\n()(((()()))(()))((())(()(())(()()))((())))((()((()()((()()(()()()(())((())))((()))(())()()))())))))((\n", "output": "-1\n" }, { "input": "2\n)(\n", "output": "2\n" }, { "input": "8\n()((()))\n", "output": "0\n" }, { "input": "4\n(())\n", "output": "0\n" }, { "input": "10\n)()((())))\n", "output": "-1\n" }, { "input": "10\n())(()()))\n", "output": "-1\n" }, { "input": "50\n()))))))))))()))))))))))))((((((((((((((((((((((((\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "-1\n" }, { "input": "100\n())((()(())))())(())((())(()((())))()))((())())(((())(()((())()))(()))()((()((()))))()))()(()))()(((\n", "output": "-1\n" }, { "input": "11\n))((((())()\n", "output": "-1\n" }, { "input": "50\n()())(())))())((())))(((((()))((())))((((()(()))))\n", "output": "-1\n" }, { "input": "2\n()\n", "output": "0\n" }, { "input": "10\n))))((()()\n", "output": "-1\n" }, { "input": "10\n())(()))))\n", "output": "-1\n" }, { "input": "50\n()))))))))))()()))))))))))((((((((((((((((((((((((\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()()()))()()()((()()()\n", "output": "-1\n" }, { "input": "10\n())()())))\n", "output": "-1\n" }, { "input": "100\n()))((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()((()))()()()((()()()\n", "output": "-1\n" }, { "input": "100\n)()()((()()()()))((()()()()()))()(())()()()()()()()()()()()))()()()()()()()(())()()()()()()()((()))(\n", "output": "-1\n" }, { "input": "4\n(()(\n", "output": "-1\n" }, { "input": "51\n))))))()())(())(()(()())()(()(()())(()))((((((((())\n", "output": "-1\n" }, { "input": "100\n))()()(())()()(()()(()((()))())())((())())((()))(())()((()))((())())()((()())())(()())(())(()(()))((\n", "output": "76\n" }, { "input": "100\n)(((((()())((())((())((()))())))))(())())()((())()(()()))(((((((()())())()(()())(((())())())())()))(\n", "output": "-1\n" }, { "input": "100\n()((()()()()()()()()())(()()()()()()()()()()()()()()()()()()()())(()()()()()()()()()()()()()()()()()\n", "output": "-1\n" }, { "input": "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()()())(\n", "output": "-1\n" }, { "input": "6\n)(((((\n", "output": "-1\n" }, { "input": "11\n))())(((())\n", "output": "-1\n" }, { "input": "1\n)\n", "output": "-1\n" }, { "input": "50\n)((()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "-1\n" }, { "input": "4\n()((\n", "output": "-1\n" }, { "input": "10\n)))((())))\n", "output": "-1\n" }, { "input": "100\n()()((()()((()()()()())(()()()()()()()()()()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "-1\n" }, { "input": "100\n())((()(())))())(())((())(()((())))()))((())())(((())(())(())()))(()))()((()((()))))()))()(()))()(((\n", "output": "-1\n" }, { "input": "8\n((((()()\n", "output": "-1\n" }, { "input": "101\n()(((()()))(()))((())(()(())(()()))((())))((()((()()((()()(()()()(())((())))((()))(())()(())())))))((\n", "output": "-1\n" }, { "input": "2\n))\n", "output": "-1\n" }, { "input": "10\n(()((())))\n", "output": "0\n" }, { "input": "10\n()))()()))\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()((()()))()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "0\n" }, { "input": "100\n())((()(()))))))(())((())(()((())))()))((())())(((())(()((())()))(()))()((()((()))))()))()(()))()(((\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()())))(()()()()()()()()))()()()()()()()()()()())(()()))()()()()()()))()()()((()()()\n", "output": "-1\n" }, { "input": "10\n)())(())()\n", "output": "-1\n" }, { "input": "100\n)()()((()()()()))((()()()()()))()(())()()()()()()()()()()()))()()()()()()()(())()()()()()()()((()()(\n", "output": "76\n" }, { "input": "100\n)()()((()()()()))((((()()()()))())())()()()()()()()()()()()))()()()()()()()(())()()()()()()()((()))(\n", "output": "-1\n" }, { "input": "4\n())(\n", "output": "2\n" }, { "input": "51\n))))))()(()(())(()(()())()(()(()())(()))((((((((())\n", "output": "-1\n" }, { "input": "100\n(()))(()(())(())()(())())()((()())())((()))((()())(()))((())())((())())()))((()(()()(()()())(()()())\n", "output": "24\n" }, { "input": "100\n()))())())())())(((())()(()())())()(((((((()))()(()())((()())())(())))))()))((())((())((())()(((((()\n", "output": "-1\n" }, { "input": "100\n)()()()()()()()()()()()()()()()()(())()()()()()()()()()()()()()()()()()()()(())()()()()()()()()((()(\n", "output": "-1\n" }, { "input": "6\n))((((\n", "output": "-1\n" }, { "input": "11\n)))))(((())\n", "output": "-1\n" }, { "input": "50\n)((()()()()()()()()()()()((()()()()()()()()()()()(\n", "output": "-1\n" }, { "input": "100\n))))())))))))))))))))))))))))))))))))))))))(((((((((((((((((((((()(((((((((((((((((()(((((((()))))))\n", "output": "-1\n" }, { "input": "10\n))))(())))\n", "output": "-1\n" }, { "input": "100\n())((()(())))())(())((())(()((())))()))((())()((((())(())(())()))(()))()((()((()))))()))()(()))())((\n", "output": "-1\n" }, { "input": "50\n)))))(((((((())))((())))((((())))((())()())(())()(\n", "output": "24\n" }, { "input": "101\n(())))))())(()())(()))((())))((())(()()()(()()((()()((()((())))((()))()(())(()(())((()))(()))()(((()(\n", "output": "-1\n" }, { "input": "10\n()()()))))\n", "output": "-1\n" }, { "input": "100\n())((()(()))))))(())((())(()((())))()))((())())(((())(()((())()))(()))()((()((()))))()))()(())(()(((\n", "output": "-1\n" } ] }
[ 0.00001285687215909091, 0.000010526258448468873, 0.000010378088264664493, 0.000009977159305762197, 0.000008388352218094405, 0.000008385668870192306, 0.00000829345108766033, 0.000008176679258911794, 0.000007707009533435315, 0.000007702878715034967, 0.000007282843551882219, 0.000007156840922749127, 0.000007122540455638112, 0.000007038212795017483, 0.00000702968037041084, 0.000006512926460981499, 0.000006505730722411357, 0.000006426506337412587, 0.000006336659842469834, 0.000006006531280126853, 0.00000588223276333042, 0.000005102683040326457, 0.0000049630948563155595, 0.000004948449300699301, 0.000004895355878496504, 0.000004809076772836539, 0.000004800626884833917, 0.000004728262715799826, 0.000004530805329436189, 0.000004518039390297203, 0.000004182971741149476, 0.0000041721519886363635, 0.0000036121212986232524, 0.000003469091824191433, 0.0000034667259478802447, 0.0000034577748306381124, 0.000003392003168706294, 0.0000033910863609047202, 0.0000033420561899038464, 0.0000033225691378933575, 0.000003309100565450175, 0.000003246851002513112, 0.000003208139272836538, 0.0000031943120902534967, 0.0000031850400049169583, 0.0000031421922530594405, 0.0000031402461074082166, 0.000003129322497814686, 0.0000031148936571241257, 0.0000031067872186407343, 0.000003091429865056818, 0.000003034524284309441, 0.0000028977167012674826, 0.0000028468103283435313, 0.0000027246703862543706, 0.000002464129056490385, 0.000002275346713833042, 0.0000018330155430506994, 0.0000017555388576267483, 0.0000017441959680944058, 0.0000016846355441433566, 0.0000016726896853146855, 0.0000016434598311844407, 0.0000015634650622814685, 0.0000015611730905812937, 9.47242201158217e-7, 4.542477054195804e-9 ]
1323_C. Unusual Competitions
661
661_47
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry's class a very strange task — she asked every student to come up with a sequence of arbitrary length, consisting only of opening and closing brackets. After that all the students took turns naming the sequences they had invented. When Dima's turn came, he suddenly realized that all his classmates got the correct bracketed sequence, and whether he got the correct bracketed sequence, he did not know. Dima suspects now that he simply missed the word "correct" in the task statement, so now he wants to save the situation by modifying his sequence slightly. More precisely, he can the arbitrary number of times (possibly zero) perform the reorder operation. The reorder operation consists of choosing an arbitrary consecutive subsegment (substring) of the sequence and then reordering all the characters in it in an arbitrary way. Such operation takes l nanoseconds, where l is the length of the subsegment being reordered. It's easy to see that reorder operation doesn't change the number of opening and closing brackets. For example for "))((" he can choose the substring ")(" and do reorder ")()(" (this operation will take 2 nanoseconds). Since Dima will soon have to answer, he wants to make his sequence correct as fast as possible. Help him to do this, or determine that it's impossible. Input The first line contains a single integer n (1 ≤ n ≤ 10^6) — the length of Dima's sequence. The second line contains string of length n, consisting of characters "(" and ")" only. Output Print a single integer — the minimum number of nanoseconds to make the sequence correct or "-1" if it is impossible to do so. Examples Input 8 ))((())( Output 6 Input 3 (() Output -1 Note In the first example we can firstly reorder the segment from first to the fourth character, replacing it with "()()", the whole sequence will be "()()())(". And then reorder the segment from the seventh to eighth character, replacing it with "()". In the end the sequence will be "()()()()", while the total time spent is 4 + 2 = 6 nanoseconds.
n= int(input()) seq= list(input()) if seq.count(')')!=seq.count('('): print(-1) else: a,b=[],[] for i in range(len(seq)): if seq[i]==')': a.append(i) else: b.append(i) c=[] for i in range(len(a)): if b[i]>a[i]: c.append(a[i]) c.append(b[i]) c.sort() start=0 sum=0 for i in range(len(c)-1): if c[i]!=c[i+1]-1: sum+=c[i]-c[start]+1 start=i+1 else: if i==len(c)-2: sum+=c[i+1]-c[start]+1 print(sum)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: n: int s: str @classmethod def from_str(cls, input_: str): n, s, _ = input_.split('\n') n = int(n) s = s.strip() return cls(n, s) def __repr__(self): return str(self.n) + '\n' + self.s + '\n'
8 ))((())(
O(nlogn)
0.000016
{ "public_tests": [ { "input": "8\n))((())(\n", "output": "6\n" }, { "input": "3\n(()\n", "output": "-1\n" } ], "private_tests": [ { "input": "4\n))))\n", "output": "-1\n" }, { "input": "4\n))((\n", "output": "4\n" }, { "input": "4\n((()\n", "output": "-1\n" }, { "input": "4\n()()\n", "output": "0\n" }, { "input": "4\n((((\n", "output": "-1\n" }, { "input": "100\n)))))))(((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))\n", "output": "14\n" }, { "input": "51\n))((((((((()))(())()(()(()())()(()(())(())()())))))\n", "output": "-1\n" }, { "input": "100\n))()()(())()()(()()())((()()())())((())())((()))(())()((()))((())())()((()())())(()())(())(()(()))((\n", "output": "80\n" }, { "input": "10\n))))((((()\n", "output": "8\n" }, { "input": "10\n())(((()))\n", "output": "2\n" }, { "input": "100\n)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "100\n" }, { "input": "50\n(((((((((((((((((((((((()))))))))))))))))))))))))(\n", "output": "2\n" }, { "input": "10\n(())())()(\n", "output": "4\n" }, { "input": "100\n)(((((()())((())((())((()))())))))(())())()((())))(()()))(((((((()())())()(()())(((())())())())()))(\n", "output": "20\n" }, { "input": "100\n()()()()()()()()()()())(()()()()()()()()()()()()()()()()()()()())(()()()()()()()()()()()()()()()()()\n", "output": "4\n" }, { "input": "4\n)()(\n", "output": "4\n" }, { "input": "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "output": "44\n" }, { "input": "8\n)(((((((\n", "output": "-1\n" }, { "input": "10\n)()()()()(\n", "output": "10\n" }, { "input": "6\n((((()\n", "output": "-1\n" }, { "input": "11\n)(())(((())\n", "output": "-1\n" }, { "input": "50\n()())()))()())((())))(((((()))(((()))((((()(()))))\n", "output": "28\n" }, { "input": "1\n(\n", "output": "-1\n" }, { "input": "50\n)()()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "50\n" }, { "input": "101\n(())))))()))()())(()))((())))((())(()()()(()()((()()((()((())))((()))()(())(()(())((()))(()))()(((()(\n", "output": "-1\n" }, { "input": "2\n((\n", "output": "-1\n" } ], "generated_tests": [ { "input": "4\n))()\n", "output": "-1\n" }, { "input": "100\n)))))))((((((((((((((((((((((((((()(((((((((((((((((((((())))))))))))))))))))))))))))))))))))))())))\n", "output": "14\n" }, { "input": "100\n))()()(())()()(()()())((()()())())((())())((()))(())()((()()()())())()((()())())(()())(())(()(()))((\n", "output": "76\n" }, { "input": "10\n)((((())))\n", "output": "2\n" }, { "input": "100\n)()()()()()()()()()()()()()()()()((()()()()()()()()()()()()()()()()()))()()()()()()()()()()()()()()(\n", "output": "64\n" }, { "input": "50\n()))))))))))))))))))))))))((((((((((((((((((((((((\n", "output": "48\n" }, { "input": "100\n()))())())())())(((())()(()())())()(((((((()))()(())))((()())())(())))))()))((())((())((())()(((((()\n", "output": "80\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()()()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "0\n" }, { "input": "50\n()())(())()())((())))(((((()))((())))((((()(()))))\n", "output": "18\n" }, { "input": "10\n)()((())()\n", "output": "4\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()((()))()()()((()()()\n", "output": "24\n" }, { "input": "10\n)())((()()\n", "output": "6\n" }, { "input": "10\n))))((()((\n", "output": "10\n" }, { "input": "50\n)))))(()((((()))(((()))(((((())))((())()()))())()(\n", "output": "22\n" }, { "input": "100\n))))())))))))))))))))))))))))))))))))))))))(((((((((((((((((((((()((((((((((((((((((((((((((()))))))\n", "output": "86\n" }, { "input": "50\n()())(())()())((())))((((())))((())))(((((((()))))\n", "output": "26\n" }, { "input": "10\n()))()()((\n", "output": "8\n" }, { "input": "100\n)()()()()()()()()()()()()()()))()(())()()()()()()()()()()()))()((()()()()()(())()()()()()()()((()()(\n", "output": "100\n" }, { "input": "4\n)(((\n", "output": "-1\n" }, { "input": "10\n)))(((()))\n", "output": "-1\n" }, { "input": "100\n((()()))(()()))()))))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "output": "-1\n" }, { "input": "8\n((((((()\n", "output": "-1\n" }, { "input": "11\n)())((((())\n", "output": "-1\n" }, { "input": "101\n()(((()()))(()))((())(()(())(()()))((())))((()((()()((()()(()()()(())((())))((()))(())()()))())))))((\n", "output": "-1\n" }, { "input": "2\n)(\n", "output": "2\n" }, { "input": "8\n()((()))\n", "output": "0\n" }, { "input": "4\n(())\n", "output": "0\n" }, { "input": "10\n)()((())))\n", "output": "-1\n" }, { "input": "10\n())(()()))\n", "output": "-1\n" }, { "input": "50\n()))))))))))()))))))))))))((((((((((((((((((((((((\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "-1\n" }, { "input": "100\n())((()(())))())(())((())(()((())))()))((())())(((())(()((())()))(()))()((()((()))))()))()(()))()(((\n", "output": "-1\n" }, { "input": "11\n))((((())()\n", "output": "-1\n" }, { "input": "50\n()())(())))())((())))(((((()))((())))((((()(()))))\n", "output": "-1\n" }, { "input": "2\n()\n", "output": "0\n" }, { "input": "10\n))))((()()\n", "output": "-1\n" }, { "input": "10\n())(()))))\n", "output": "-1\n" }, { "input": "50\n()))))))))))()()))))))))))((((((((((((((((((((((((\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()()()))()()()((()()()\n", "output": "-1\n" }, { "input": "10\n())()())))\n", "output": "-1\n" }, { "input": "100\n()))((()()()()()()()())(()()()()()()()()))()()()()()()()()()()())(()()))()()()()((()))()()()((()()()\n", "output": "-1\n" }, { "input": "100\n)()()((()()()()))((()()()()()))()(())()()()()()()()()()()()))()()()()()()()(())()()()()()()()((()))(\n", "output": "-1\n" }, { "input": "4\n(()(\n", "output": "-1\n" }, { "input": "51\n))))))()())(())(()(()())()(()(()())(()))((((((((())\n", "output": "-1\n" }, { "input": "100\n))()()(())()()(()()(()((()))())())((())())((()))(())()((()))((())())()((()())())(()())(())(()(()))((\n", "output": "76\n" }, { "input": "100\n)(((((()())((())((())((()))())))))(())())()((())()(()()))(((((((()())())()(()())(((())())())())()))(\n", "output": "-1\n" }, { "input": "100\n()((()()()()()()()()())(()()()()()()()()()()()()()()()()()()()())(()()()()()()()()()()()()()()()()()\n", "output": "-1\n" }, { "input": "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()()())(\n", "output": "-1\n" }, { "input": "6\n)(((((\n", "output": "-1\n" }, { "input": "11\n))())(((())\n", "output": "-1\n" }, { "input": "1\n)\n", "output": "-1\n" }, { "input": "50\n)((()()()()()()()()()()()()()()()()()()()()()()()(\n", "output": "-1\n" }, { "input": "4\n()((\n", "output": "-1\n" }, { "input": "10\n)))((())))\n", "output": "-1\n" }, { "input": "100\n()()((()()((()()()()())(()()()()()()()()()()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "-1\n" }, { "input": "100\n())((()(())))())(())((())(()((())))()))((())())(((())(())(())()))(()))()((()((()))))()))()(()))()(((\n", "output": "-1\n" }, { "input": "8\n((((()()\n", "output": "-1\n" }, { "input": "101\n()(((()()))(()))((())(()(())(()()))((())))((()((()()((()()(()()()(())((())))((()))(())()(())())))))((\n", "output": "-1\n" }, { "input": "2\n))\n", "output": "-1\n" }, { "input": "10\n(()((())))\n", "output": "0\n" }, { "input": "10\n()))()()))\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()()())(()()()()()((()()))()()()()()()()()()()())(()()))()()()()()()()()()()()()()()\n", "output": "0\n" }, { "input": "100\n())((()(()))))))(())((())(()((())))()))((())())(((())(()((())()))(()))()((()((()))))()))()(()))()(((\n", "output": "-1\n" }, { "input": "100\n()()((()()()()()()())))(()()()()()()()()))()()()()()()()()()()())(()()))()()()()()()))()()()((()()()\n", "output": "-1\n" }, { "input": "10\n)())(())()\n", "output": "-1\n" }, { "input": "100\n)()()((()()()()))((()()()()()))()(())()()()()()()()()()()()))()()()()()()()(())()()()()()()()((()()(\n", "output": "76\n" }, { "input": "100\n)()()((()()()()))((((()()()()))())())()()()()()()()()()()()))()()()()()()()(())()()()()()()()((()))(\n", "output": "-1\n" }, { "input": "4\n())(\n", "output": "2\n" }, { "input": "51\n))))))()(()(())(()(()())()(()(()())(()))((((((((())\n", "output": "-1\n" }, { "input": "100\n(()))(()(())(())()(())())()((()())())((()))((()())(()))((())())((())())()))((()(()()(()()())(()()())\n", "output": "24\n" }, { "input": "100\n()))())())())())(((())()(()())())()(((((((()))()(()())((()())())(())))))()))((())((())((())()(((((()\n", "output": "-1\n" }, { "input": "100\n)()()()()()()()()()()()()()()()()(())()()()()()()()()()()()()()()()()()()()(())()()()()()()()()((()(\n", "output": "-1\n" }, { "input": "6\n))((((\n", "output": "-1\n" }, { "input": "11\n)))))(((())\n", "output": "-1\n" }, { "input": "50\n)((()()()()()()()()()()()((()()()()()()()()()()()(\n", "output": "-1\n" }, { "input": "100\n))))())))))))))))))))))))))))))))))))))))))(((((((((((((((((((((()(((((((((((((((((()(((((((()))))))\n", "output": "-1\n" }, { "input": "10\n))))(())))\n", "output": "-1\n" }, { "input": "100\n())((()(())))())(())((())(()((())))()))((())()((((())(())(())()))(()))()((()((()))))()))()(()))())((\n", "output": "-1\n" }, { "input": "50\n)))))(((((((())))((())))((((())))((())()())(())()(\n", "output": "24\n" }, { "input": "101\n(())))))())(()())(()))((())))((())(()()()(()()((()()((()((())))((()))()(())(()(())((()))(()))()(((()(\n", "output": "-1\n" }, { "input": "10\n()()()))))\n", "output": "-1\n" }, { "input": "100\n())((()(()))))))(())((())(()((())))()))((())())(((())(()((())()))(()))()((()((()))))()))()(())(()(((\n", "output": "-1\n" } ] }
[ 0.000015801057483138505, 0.0000014390343319001593, 0.0000013912232485212835, 0.0000012501579330693742, 0.0000011701936064044383, 0.0000011623206701571234, 9.202252202455725e-7, 8.299393138064738e-7, 5.709836159027591e-7, 5.631570162018291e-7, 5.21044069139501e-7, 4.815193201206476e-7, 4.779785118185904e-7, 4.6287629760899714e-7, 4.601422637162451e-7, 4.599635682699614e-7, 4.4646672873354635e-7, 4.3584111202757095e-7, 4.1609701648023147e-7, 4.063828943457227e-7, 4.0155724103431537e-7, 3.956319190004658e-7, 3.9233261903415686e-7, 3.890675700854718e-7, 3.867607515983645e-7, 3.842319990644223e-7, 3.776205298841517e-7, 3.760861731663283e-7, 3.6573017586295783e-7, 3.5225152738930627e-7, 3.381424395088938e-7 ]
886_C. Petya and Catacombs
2505
2505_30
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti: * If Petya has visited this room before, he writes down the minute he was in this room last time; * Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i. Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0. At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook? Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook. The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook. Output In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. Examples Input 2 0 0 Output 2 Input 5 0 1 0 1 3 Output 3 Note In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2. In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.
n = int(input()) data = list(map(int, input().split())) d = [False] * (n + 4) d[0] = True res = 1 for i in range(n): #print(d) if d[data[i]]: d[data[i]] = False d[i + 1] = True else: d[i + 1] = True res += 1 #print(d) print(res)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int coordinates: List[List[int]] @classmethod def from_str(cls, input_: str): n, *coordinates, _ = input_.split('\n') n = int(n) coordinates = [[int(x) for x in pair.split(' ')] for pair in coordinates] return cls(n, coordinates) def __repr__(self): return str(self.n) + '\n' + '\n'.join([' '.join([str(x) for x in pair]) for pair in self.coordinates]) + '\n'
2 0 0
O(n**2)
0
{ "public_tests": [ { "input": "2\n0 0\n", "output": "2\n" }, { "input": "5\n0 1 0 1 3\n", "output": "3\n" } ], "private_tests": [ { "input": "1\n0\n", "output": "1\n" }, { "input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6\n", "output": "8\n" }, { "input": "2\n0 1\n", "output": "1\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "7\n0 1 0 0 0 0 0\n", "output": "6\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "71\n" } ], "generated_tests": [ { "input": "14\n0 0 1 1 2 2 3 3 4 4 8 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 13 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "71\n" }, { "input": "5\n0 1 0 1 0\n", "output": "4\n" }, { "input": "14\n0 0 1 1 2 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 29 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "70\n" }, { "input": "5\n0 1 0 1 2\n", "output": "3\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "14\n0 0 1 1 4 2 4 1 4 1 4 5 6 6\n", "output": "9\n" }, { "input": "14\n0 0 1 1 4 2 4 1 4 1 4 4 6 6\n", "output": "10\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "64\n" }, { "input": "14\n0 0 1 1 2 2 4 3 4 4 8 5 6 6\n", "output": "7\n" }, { "input": "14\n0 0 1 1 4 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 2 4 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 2 4 2 4 3 4 4 4 5 6 3\n", "output": "8\n" }, { "input": "14\n0 0 1 1 2 2 3 6 4 4 5 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "14\n0 0 1 1 2 2 3 3 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 13 30 6 23 18 3 2 16 0 4 37 9 4 8 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "71\n" }, { "input": "5\n0 1 0 2 0\n", "output": "3\n" }, { "input": "14\n0 0 1 1 4 2 4 3 4 4 8 5 6 6\n", "output": "7\n" }, { "input": "14\n0 0 1 0 2 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 1 4 2 4 3 4 1 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 2 1 2 4 3 4 4 4 5 6 3\n", "output": "8\n" }, { "input": "14\n0 0 1 1 2 2 3 6 0 4 5 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "5\n0 1 1 1 2\n", "output": "3\n" }, { "input": "14\n0 0 1 1 1 2 3 3 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "5\n0 0 0 2 0\n", "output": "4\n" }, { "input": "14\n0 0 1 1 4 2 4 5 4 4 8 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 0 2 2 3 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 4 4 5 1 6\n", "output": "8\n" }, { "input": "14\n0 0 0 2 1 2 4 3 4 4 4 5 6 3\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 2 3 6 0 4 5 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "5\n0 0 1 1 2\n", "output": "3\n" }, { "input": "14\n0 0 1 1 1 2 3 5 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "14\n0 0 1 1 4 2 4 5 4 4 8 5 9 6\n", "output": "7\n" }, { "input": "14\n0 0 1 0 2 2 3 3 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 4 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 0 0 2 1 2 4 3 4 4 4 8 6 3\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 2 3 6 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "5\n0 0 1 1 3\n", "output": "3\n" }, { "input": "14\n0 1 1 1 1 2 3 5 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "14\n0 0 1 1 4 2 4 6 4 4 8 5 9 6\n", "output": "7\n" }, { "input": "14\n0 0 1 1 4 2 4 1 4 2 4 4 6 6\n", "output": "10\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 0 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 2 3 1 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "14\n0 1 1 1 1 2 1 5 4 4 10 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 9\n", "output": "66\n" }, { "input": "14\n0 0 1 0 4 2 4 1 4 2 4 4 6 6\n", "output": "10\n" }, { "input": "14\n0 1 1 3 4 2 4 3 4 0 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 4 3 1 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "66\n" }, { "input": "14\n0 1 1 3 4 3 4 3 4 0 4 5 0 6\n", "output": "9\n" }, { "input": "14\n0 1 1 1 2 4 3 1 0 4 4 10 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "14\n0 1 1 3 4 3 2 3 4 0 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 4 4 1 0 4 4 10 6 6\n", "output": "9\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 0 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "64\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 0 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 32 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "64\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 9 4 12 7 3 0 1 2 3 4 3 9 0 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 32 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 3 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 1 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 0 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 3 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 1 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 7 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 1 2 1 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 0 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 3 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 1 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 12 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 7 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" } ] }
[ 4.61255067031827e-9, 3.7200434325142267e-9, 2.844054241848428e-9, 1.9286925824925423e-9, 1.8449987155194102e-9, 1.8079277616417545e-9, 1.764178551086279e-9, 1.7301892751669527e-9, 1.4106774654701826e-9, 1.283846614454291e-9, 1.2135018004216294e-9, 1.1950930396267459e-9, 1.1771138792450705e-9, 1.1409863692168202e-9, 1.7631351670678403e-12 ]
886_C. Petya and Catacombs
2505
2505_87
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti: * If Petya has visited this room before, he writes down the minute he was in this room last time; * Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i. Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0. At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook? Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook. The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook. Output In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. Examples Input 2 0 0 Output 2 Input 5 0 1 0 1 3 Output 3 Note In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2. In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.
n = int(input()) arr = list(map(int, input().split())) arr.sort() cnt_total = 0 cnt_tmp = 0 for i in range(1,n): if arr[i] == arr[i-1]: cnt_total +=1 print(cnt_total+1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int coordinates: List[List[int]] @classmethod def from_str(cls, input_: str): n, *coordinates, _ = input_.split('\n') n = int(n) coordinates = [[int(x) for x in pair.split(' ')] for pair in coordinates] return cls(n, coordinates) def __repr__(self): return str(self.n) + '\n' + '\n'.join([' '.join([str(x) for x in pair]) for pair in self.coordinates]) + '\n'
2 0 0
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n0 0\n", "output": "2\n" }, { "input": "5\n0 1 0 1 3\n", "output": "3\n" } ], "private_tests": [ { "input": "1\n0\n", "output": "1\n" }, { "input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6\n", "output": "8\n" }, { "input": "2\n0 1\n", "output": "1\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "7\n0 1 0 0 0 0 0\n", "output": "6\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "71\n" } ], "generated_tests": [ { "input": "14\n0 0 1 1 2 2 3 3 4 4 8 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 13 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "71\n" }, { "input": "5\n0 1 0 1 0\n", "output": "4\n" }, { "input": "14\n0 0 1 1 2 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 29 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "70\n" }, { "input": "5\n0 1 0 1 2\n", "output": "3\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "14\n0 0 1 1 4 2 4 1 4 1 4 5 6 6\n", "output": "9\n" }, { "input": "14\n0 0 1 1 4 2 4 1 4 1 4 4 6 6\n", "output": "10\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "64\n" }, { "input": "14\n0 0 1 1 2 2 4 3 4 4 8 5 6 6\n", "output": "7\n" }, { "input": "14\n0 0 1 1 4 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 2 4 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 2 4 2 4 3 4 4 4 5 6 3\n", "output": "8\n" }, { "input": "14\n0 0 1 1 2 2 3 6 4 4 5 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "14\n0 0 1 1 2 2 3 3 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 13 30 6 23 18 3 2 16 0 4 37 9 4 8 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "71\n" }, { "input": "5\n0 1 0 2 0\n", "output": "3\n" }, { "input": "14\n0 0 1 1 4 2 4 3 4 4 8 5 6 6\n", "output": "7\n" }, { "input": "14\n0 0 1 0 2 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 1 4 2 4 3 4 1 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 2 1 2 4 3 4 4 4 5 6 3\n", "output": "8\n" }, { "input": "14\n0 0 1 1 2 2 3 6 0 4 5 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "5\n0 1 1 1 2\n", "output": "3\n" }, { "input": "14\n0 0 1 1 1 2 3 3 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "5\n0 0 0 2 0\n", "output": "4\n" }, { "input": "14\n0 0 1 1 4 2 4 5 4 4 8 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 0 2 2 3 3 4 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 4 4 5 1 6\n", "output": "8\n" }, { "input": "14\n0 0 0 2 1 2 4 3 4 4 4 5 6 3\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 2 3 6 0 4 5 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "5\n0 0 1 1 2\n", "output": "3\n" }, { "input": "14\n0 0 1 1 1 2 3 5 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "14\n0 0 1 1 4 2 4 5 4 4 8 5 9 6\n", "output": "7\n" }, { "input": "14\n0 0 1 0 2 2 3 3 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 4 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 0 0 2 1 2 4 3 4 4 4 8 6 3\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 2 3 6 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "5\n0 0 1 1 3\n", "output": "3\n" }, { "input": "14\n0 1 1 1 1 2 3 5 4 4 10 5 6 6\n", "output": "7\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "66\n" }, { "input": "14\n0 0 1 1 4 2 4 6 4 4 8 5 9 6\n", "output": "7\n" }, { "input": "14\n0 0 1 1 4 2 4 1 4 2 4 4 6 6\n", "output": "10\n" }, { "input": "14\n0 0 1 3 4 2 4 3 4 0 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 2 3 1 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "14\n0 1 1 1 1 2 1 5 4 4 10 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 9\n", "output": "66\n" }, { "input": "14\n0 0 1 0 4 2 4 1 4 2 4 4 6 6\n", "output": "10\n" }, { "input": "14\n0 1 1 3 4 2 4 3 4 0 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 4 3 1 0 4 4 5 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 1 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "66\n" }, { "input": "14\n0 1 1 3 4 3 4 3 4 0 4 5 0 6\n", "output": "9\n" }, { "input": "14\n0 1 1 1 2 4 3 1 0 4 4 10 6 6\n", "output": "8\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "14\n0 1 1 3 4 3 2 3 4 0 4 5 0 6\n", "output": "8\n" }, { "input": "14\n0 1 1 1 2 4 4 1 0 4 4 10 6 6\n", "output": "9\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 14 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 0 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "64\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 7 3 0 1 2 3 4 3 9 0 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 32 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "64\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 8 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 2 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 9 4 12 7 3 0 1 2 3 4 3 9 0 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 32 4 20 20 27 17 15 37 53 17 3 3 15 1 46 11 24 31 6 16 6 11 21 13 1 5 0 19 10 24 41 16 78 18 52 46 39 16 30 18 23 53 13\n", "output": "65\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 3 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 1 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 1 2 0 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 0 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 3 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 1 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 7 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" }, { "input": "100\n0 0 0 0 1 2 1 0 4 3 2 2 6 4 2 6 2 9 8 1 2 0 2 2 1 0 10 0 4 20 4 11 3 9 0 0 8 2 6 3 13 2 1 23 20 9 16 7 1 37 6 1 29 25 28 17 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 21 27 0 16 3 3 7 7 25 13 13 30 11 5 28 0 12\n", "output": "69\n" }, { "input": "100\n0 0 0 0 0 0 1 4 6 0 2 1 2 1 1 1 14 0 8 4 12 12 5 0 3 2 2 4 3 9 1 5 3 6 9 14 6 2 4 18 7 7 19 5 20 12 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 7 20 43 53 17 3 3 15 1 46 11 24 12 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 22 9\n", "output": "67\n" } ] }
[ 0.0000053624728791522934, 0.000005360939340687206, 0.0000034698345033872386, 0.0000032901314466783218, 0.0000026100686052229024, 0.0000024926629152097903, 0.0000022019864373907347, 0.0000021494221481643354, 0.0000019066879507211541, 0.0000017391441761363638, 0.0000017103755873033217, 0.0000016572267263986016, 0.000001621478529283217, 0.000001577373169798951, 0.0000012524764259178322, 0.0000011033504464285715, 9.239694465690561e-7, 9.001472628933565e-7, 8.336152343750001e-7, 3.853843340678887e-7, 3.388293672056793e-7, 3.229939220770846e-7, 2.809591591960149e-7, 2.495223135348621e-7, 2.1834955917913604e-7 ]
1131_B. Draw!
525
525_273
You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is «x:y», then after the goal it will change to "x+1:y" or "x:y+1". What is the largest number of times a draw could appear on the scoreboard? The pairs "a_i:b_i" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match. Input The first line contains a single integer n (1 ≤ n ≤ 10000) — the number of known moments in the match. Each of the next n lines contains integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team). All moments are given in chronological order, that is, sequences x_i and y_j are non-decreasing. The last score denotes the final result of the match. Output Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted. Examples Input 3 2 0 3 1 3 4 Output 2 Input 3 0 0 0 0 0 0 Output 1 Input 1 5 4 Output 5 Note In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.
n = int(input()) pair = [None] * n count = 0 add = 0 for i in range(n): pair[i] = list(map(int,input().split())) if(min(pair[0]) != 0): add += min(pair[0]) + 1 else: add += 1 #print(add) count+= add for i in range(1,n): if(min(pair[i]) - max(pair[i-1]) < 0): continue add = max( min(pair[i]) - max(pair[i-1]) + 1 , 0 ) if(pair[i-1][0] == pair[i-1][1]): add -= 1 #print('bc',add) count += add print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int points: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) points = [list(map(int, line.split())) for line in lines[1:-1]] assert len(points) == n return cls(n, points) def __repr__(self): points_str = '\n'.join([' '.join(map(str, point)) for point in self.points]) return str(self.n) + '\n' + points_str + '\n'
3 0 0 0 0 0 0
O(n*m)
0.000003
{ "public_tests": [ { "input": "3\n0 0\n0 0\n0 0\n", "output": "1\n" }, { "input": "1\n5 4\n", "output": "5\n" }, { "input": "3\n2 0\n3 1\n3 4\n", "output": "2\n" } ], "private_tests": [ { "input": "6\n0 0\n0 1\n1 1\n8 7\n8 8\n9 9\n", "output": "10\n" }, { "input": "1\n1000000000 0\n", "output": "1\n" }, { "input": "10\n0 1\n3 2\n3 3\n3 4\n3 4\n4 4\n6 5\n7 7\n8 7\n8 8\n", "output": "9\n" }, { "input": "7\n0 1\n1 1\n1 2\n1 2\n9 9\n9 9\n9 9\n", "output": "10\n" }, { "input": "9\n1 0\n4 2\n4 4\n4 5\n4 5\n7 6\n7 7\n9 9\n9 9\n", "output": "9\n" }, { "input": "1\n0 0\n", "output": "1\n" }, { "input": "1\n9 9\n", "output": "10\n" }, { "input": "5\n0 1\n3 2\n3 3\n5 4\n9 8\n", "output": "9\n" }, { "input": "6\n5 5\n6 5\n6 8\n6 8\n8 8\n8 9\n", "output": "8\n" }, { "input": "1\n1000000000 1000000000\n", "output": "1000000001\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 1\n2 2\n6 7\n7 7\n", "output": "8\n" }, { "input": "5\n0 0\n0 0\n2 2\n4 5\n9 9\n", "output": "10\n" }, { "input": "5\n0 0\n1 1\n2 4\n5 7\n9 9\n", "output": "8\n" }, { "input": "9\n0 0\n0 0\n1 2\n1 2\n2 4\n3 4\n7 8\n7 8\n8 9\n", "output": "8\n" }, { "input": "7\n1 1\n1 1\n4 4\n7 6\n8 7\n8 8\n8 8\n", "output": "9\n" }, { "input": "3\n5 4\n6 7\n9 9\n", "output": "10\n" }, { "input": "10\n0 0\n2 2\n4 5\n4 5\n6 5\n6 6\n6 6\n6 7\n9 9\n9 9\n", "output": "10\n" }, { "input": "2\n3 5\n9 9\n", "output": "9\n" }, { "input": "4\n7 7\n8 7\n8 8\n9 9\n", "output": "10\n" }, { "input": "1\n9 8\n", "output": "9\n" }, { "input": "9\n0 0\n3 3\n6 6\n6 6\n7 6\n7 8\n7 8\n8 8\n9 9\n", "output": "10\n" }, { "input": "6\n2 0\n5 4\n5 5\n6 7\n7 7\n9 9\n", "output": "9\n" }, { "input": "8\n0 0\n2 1\n3 3\n3 5\n5 7\n7 7\n9 9\n9 9\n", "output": "8\n" }, { "input": "11\n0 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 500000000\n600000000 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "11\n" }, { "input": "4\n0 0\n2 2\n6 5\n7 7\n", "output": "8\n" }, { "input": "8\n1 0\n2 3\n2 3\n5 4\n7 6\n8 7\n8 9\n8 9\n", "output": "9\n" }, { "input": "2\n1 0\n9 9\n", "output": "10\n" }, { "input": "2\n500000000 500000000\n500000000 1000000000\n", "output": "500000001\n" }, { "input": "4\n1 1\n6 5\n6 5\n8 9\n", "output": "9\n" }, { "input": "8\n0 0\n1 1\n3 4\n5 5\n5 5\n6 5\n8 9\n9 9\n", "output": "10\n" }, { "input": "10\n0 0\n0 1\n2 1\n2 3\n4 3\n5 4\n5 4\n5 5\n5 6\n7 8\n", "output": "8\n" }, { "input": "3\n0 0\n4 4\n8 8\n", "output": "9\n" } ], "generated_tests": [ { "input": "6\n0 0\n0 1\n0 1\n8 7\n8 8\n9 9\n", "output": "10\n" }, { "input": "1\n1000000010 0\n", "output": "1\n" }, { "input": "9\n1 0\n4 2\n4 5\n4 5\n4 5\n7 6\n7 7\n9 9\n9 9\n", "output": "9\n" }, { "input": "1\n1000000000 1000100000\n", "output": "1000000001\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 1\n4 2\n6 7\n7 7\n", "output": "7\n" }, { "input": "1\n9 5\n", "output": "6\n" }, { "input": "8\n0 0\n2 1\n3 3\n3 5\n5 7\n8 7\n9 9\n9 9\n", "output": "8\n" }, { "input": "11\n1 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 500000000\n600000000 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "12\n" }, { "input": "2\n500000000 516158428\n500000000 1000000000\n", "output": "500000001\n" }, { "input": "1\n1 1\n", "output": "2\n" }, { "input": "1\n1000010000 1000100000\n", "output": "1000010001\n" }, { "input": "1\n4 5\n", "output": "5\n" }, { "input": "11\n1 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 500000000\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "18182428\n" }, { "input": "11\n1 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "100000011\n" }, { "input": "1\n2 2\n", "output": "3\n" }, { "input": "1\n1000010010 1100100000\n", "output": "1000010011\n" }, { "input": "11\n1 100000000\n200000000 100000100\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "100000111\n" }, { "input": "11\n1 100000000\n200000000 100000100\n200000000 300000000\n400000000 300000000\n521768407 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "178231704\n" }, { "input": "11\n0 100000000\n200000000 100000100\n200000000 300000000\n400000000 300000000\n521768407 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "178231703\n" }, { "input": "3\n0 1\n4 3\n10 14\n", "output": "11\n" }, { "input": "1\n1000010010 0101100001\n", "output": "101100002\n" }, { "input": "1\n1000010011 1101100001\n", "output": "1000010012\n" }, { "input": "1\n1010010011 1101100001\n", "output": "1010010012\n" }, { "input": "1\n1010000011 1101100001\n", "output": "1010000012\n" }, { "input": "1\n3 12\n", "output": "4\n" }, { "input": "1\n1 0\n", "output": "1\n" }, { "input": "1\n15 9\n", "output": "10\n" }, { "input": "6\n5 5\n6 5\n6 8\n6 8\n8 8\n10 9\n", "output": "9\n" }, { "input": "5\n0 0\n0 0\n2 0\n4 5\n9 9\n", "output": "9\n" }, { "input": "5\n0 0\n1 1\n2 4\n5 4\n9 9\n", "output": "9\n" }, { "input": "2\n1 5\n9 9\n", "output": "7\n" }, { "input": "6\n2 0\n5 4\n5 5\n6 7\n7 7\n16 9\n", "output": "9\n" }, { "input": "4\n0 0\n2 2\n6 7\n7 7\n", "output": "8\n" }, { "input": "2\n1 0\n9 16\n", "output": "10\n" }, { "input": "3\n1 0\n4 4\n8 8\n", "output": "9\n" }, { "input": "1\n5 5\n", "output": "6\n" }, { "input": "1\n0000000010 0\n", "output": "1\n" }, { "input": "1\n15 8\n", "output": "9\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 1\n3 2\n6 7\n7 7\n", "output": "8\n" }, { "input": "4\n0 0\n2 2\n6 7\n13 7\n", "output": "8\n" }, { "input": "2\n1 0\n9 6\n", "output": "7\n" }, { "input": "2\n500000000 516158428\n500000000 1000001000\n", "output": "500000001\n" }, { "input": "3\n1 1\n4 4\n8 8\n", "output": "9\n" }, { "input": "1\n5 1\n", "output": "2\n" }, { "input": "1\n0010000010 0\n", "output": "1\n" }, { "input": "1\n1 2\n", "output": "2\n" }, { "input": "1\n9 12\n", "output": "10\n" }, { "input": "1\n1000010000 1100100000\n", "output": "1000010001\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 0\n3 2\n6 7\n7 7\n", "output": "7\n" }, { "input": "1\n4 8\n", "output": "5\n" }, { "input": "4\n0 0\n3 2\n6 7\n13 7\n", "output": "8\n" }, { "input": "2\n1 1\n9 6\n", "output": "7\n" }, { "input": "2\n500000000 516158428\n500000000 1001001000\n", "output": "500000001\n" }, { "input": "3\n1 1\n4 3\n8 8\n", "output": "9\n" }, { "input": "1\n5 0\n", "output": "1\n" }, { "input": "1\n0010000010 1\n", "output": "2\n" }, { "input": "1\n9 14\n", "output": "10\n" }, { "input": "1\n1 8\n", "output": "2\n" }, { "input": "2\n1 1\n9 11\n", "output": "10\n" }, { "input": "3\n1 1\n4 3\n10 8\n", "output": "9\n" }, { "input": "1\n9 0\n", "output": "1\n" }, { "input": "1\n0010001010 1\n", "output": "2\n" }, { "input": "1\n2 3\n", "output": "3\n" }, { "input": "1\n9 20\n", "output": "10\n" }, { "input": "1\n1000010010 1101100000\n", "output": "1000010011\n" }, { "input": "1\n1 11\n", "output": "2\n" }, { "input": "2\n1 2\n9 11\n", "output": "10\n" }, { "input": "3\n0 1\n4 3\n10 8\n", "output": "9\n" }, { "input": "1\n4 0\n", "output": "1\n" }, { "input": "1\n0010001000 1\n", "output": "2\n" }, { "input": "1\n1 3\n", "output": "2\n" }, { "input": "1\n9 31\n", "output": "10\n" }, { "input": "1\n1000010010 1101100001\n", "output": "1000010011\n" }, { "input": "1\n1 4\n", "output": "2\n" }, { "input": "2\n1 2\n4 11\n", "output": "5\n" }, { "input": "1\n6 0\n", "output": "1\n" }, { "input": "1\n0010001000 2\n", "output": "3\n" }, { "input": "1\n0 3\n", "output": "1\n" }, { "input": "1\n4 31\n", "output": "5\n" }, { "input": "1\n2 1\n", "output": "2\n" }, { "input": "2\n1 2\n4 19\n", "output": "5\n" }, { "input": "1\n12 0\n", "output": "1\n" }, { "input": "1\n0010011000 2\n", "output": "3\n" }, { "input": "1\n1 5\n", "output": "2\n" }, { "input": "1\n4 18\n", "output": "5\n" }, { "input": "1\n1000010010 1001100001\n", "output": "1000010011\n" }, { "input": "1\n3 1\n", "output": "2\n" }, { "input": "2\n1 2\n4 7\n", "output": "5\n" }, { "input": "1\n16 0\n", "output": "1\n" }, { "input": "1\n1010011000 2\n", "output": "3\n" }, { "input": "1\n1 9\n", "output": "2\n" }, { "input": "1\n4 4\n", "output": "5\n" }, { "input": "1\n0 1\n", "output": "1\n" }, { "input": "2\n1 2\n4 2\n", "output": "3\n" }, { "input": "1\n1010011000 0\n", "output": "1\n" }, { "input": "1\n2 9\n", "output": "3\n" }, { "input": "1\n4 1\n", "output": "2\n" }, { "input": "2\n1 0\n4 2\n", "output": "3\n" }, { "input": "1\n1000011000 0\n", "output": "1\n" }, { "input": "1\n2 12\n", "output": "3\n" } ] }
[ 0.0000035642755135489514, 0.000002896986013986014, 0.0000028930817444274473, 0.000002853064739947553, 0.0000028340379152097905, 0.000002780787396197553, 0.000002769261172421329, 0.000002731027712521853, 0.0000026837052966564687, 0.0000026701160402097904, 0.0000026596227600524477, 0.000002656567007211539, 0.0000026376690340909094, 0.000002635687978037587, 0.0000026275176190996504, 0.0000026266876638986016, 0.0000026134038051791957, 0.0000026113374945367133, 0.000002608983459899476, 0.0000026027809768356644, 0.000002548135284637238, 0.000002546917285839161, 0.0000025461011254370633, 0.0000025315651360358394, 0.0000025195203507430072, 0.0000024950469023164336, 0.0000024245053403627623, 0.0000023836898628715033, 0.0000023757674005681817, 0.000002371649762347028, 0.000002364633631993007, 0.0000023581466755900355, 0.0000023465252130681817, 0.000002345314193618881, 0.0000023452369564029723, 0.0000023411090335445803, 0.0000023172009533435316, 0.000001235927119755245, 0.0000011055213887674827, 0.000001093012155812937, 0.000001082911153299825, 0.0000010760629916958044, 0.0000010731588314029723, 0.0000010606220771416087, 0.0000010473102327360142, 0.0000010432399475524476, 9.692064985795455e-7, 7.731916520979026e-11 ]
1131_B. Draw!
525
525_234
You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is «x:y», then after the goal it will change to "x+1:y" or "x:y+1". What is the largest number of times a draw could appear on the scoreboard? The pairs "a_i:b_i" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match. Input The first line contains a single integer n (1 ≤ n ≤ 10000) — the number of known moments in the match. Each of the next n lines contains integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team). All moments are given in chronological order, that is, sequences x_i and y_j are non-decreasing. The last score denotes the final result of the match. Output Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted. Examples Input 3 2 0 3 1 3 4 Output 2 Input 3 0 0 0 0 0 0 Output 1 Input 1 5 4 Output 5 Note In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.
n=int(input()) count=1 a,b=0,0 for i in range(n): c,d=map(int,input().split(' ')) if min(c,d)>=max(a,b): if a!=b: count+=min(c,d)-max(a,b)+1 else: count+=min(c,d)-max(a,b) a,b=c,d print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int points: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) points = [list(map(int, line.split())) for line in lines[1:-1]] assert len(points) == n return cls(n, points) def __repr__(self): points_str = '\n'.join([' '.join(map(str, point)) for point in self.points]) return str(self.n) + '\n' + points_str + '\n'
3 0 0 0 0 0 0
O(n)
0
{ "public_tests": [ { "input": "3\n0 0\n0 0\n0 0\n", "output": "1\n" }, { "input": "1\n5 4\n", "output": "5\n" }, { "input": "3\n2 0\n3 1\n3 4\n", "output": "2\n" } ], "private_tests": [ { "input": "6\n0 0\n0 1\n1 1\n8 7\n8 8\n9 9\n", "output": "10\n" }, { "input": "1\n1000000000 0\n", "output": "1\n" }, { "input": "10\n0 1\n3 2\n3 3\n3 4\n3 4\n4 4\n6 5\n7 7\n8 7\n8 8\n", "output": "9\n" }, { "input": "7\n0 1\n1 1\n1 2\n1 2\n9 9\n9 9\n9 9\n", "output": "10\n" }, { "input": "9\n1 0\n4 2\n4 4\n4 5\n4 5\n7 6\n7 7\n9 9\n9 9\n", "output": "9\n" }, { "input": "1\n0 0\n", "output": "1\n" }, { "input": "1\n9 9\n", "output": "10\n" }, { "input": "5\n0 1\n3 2\n3 3\n5 4\n9 8\n", "output": "9\n" }, { "input": "6\n5 5\n6 5\n6 8\n6 8\n8 8\n8 9\n", "output": "8\n" }, { "input": "1\n1000000000 1000000000\n", "output": "1000000001\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 1\n2 2\n6 7\n7 7\n", "output": "8\n" }, { "input": "5\n0 0\n0 0\n2 2\n4 5\n9 9\n", "output": "10\n" }, { "input": "5\n0 0\n1 1\n2 4\n5 7\n9 9\n", "output": "8\n" }, { "input": "9\n0 0\n0 0\n1 2\n1 2\n2 4\n3 4\n7 8\n7 8\n8 9\n", "output": "8\n" }, { "input": "7\n1 1\n1 1\n4 4\n7 6\n8 7\n8 8\n8 8\n", "output": "9\n" }, { "input": "3\n5 4\n6 7\n9 9\n", "output": "10\n" }, { "input": "10\n0 0\n2 2\n4 5\n4 5\n6 5\n6 6\n6 6\n6 7\n9 9\n9 9\n", "output": "10\n" }, { "input": "2\n3 5\n9 9\n", "output": "9\n" }, { "input": "4\n7 7\n8 7\n8 8\n9 9\n", "output": "10\n" }, { "input": "1\n9 8\n", "output": "9\n" }, { "input": "9\n0 0\n3 3\n6 6\n6 6\n7 6\n7 8\n7 8\n8 8\n9 9\n", "output": "10\n" }, { "input": "6\n2 0\n5 4\n5 5\n6 7\n7 7\n9 9\n", "output": "9\n" }, { "input": "8\n0 0\n2 1\n3 3\n3 5\n5 7\n7 7\n9 9\n9 9\n", "output": "8\n" }, { "input": "11\n0 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 500000000\n600000000 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "11\n" }, { "input": "4\n0 0\n2 2\n6 5\n7 7\n", "output": "8\n" }, { "input": "8\n1 0\n2 3\n2 3\n5 4\n7 6\n8 7\n8 9\n8 9\n", "output": "9\n" }, { "input": "2\n1 0\n9 9\n", "output": "10\n" }, { "input": "2\n500000000 500000000\n500000000 1000000000\n", "output": "500000001\n" }, { "input": "4\n1 1\n6 5\n6 5\n8 9\n", "output": "9\n" }, { "input": "8\n0 0\n1 1\n3 4\n5 5\n5 5\n6 5\n8 9\n9 9\n", "output": "10\n" }, { "input": "10\n0 0\n0 1\n2 1\n2 3\n4 3\n5 4\n5 4\n5 5\n5 6\n7 8\n", "output": "8\n" }, { "input": "3\n0 0\n4 4\n8 8\n", "output": "9\n" } ], "generated_tests": [ { "input": "6\n0 0\n0 1\n0 1\n8 7\n8 8\n9 9\n", "output": "10\n" }, { "input": "1\n1000000010 0\n", "output": "1\n" }, { "input": "9\n1 0\n4 2\n4 5\n4 5\n4 5\n7 6\n7 7\n9 9\n9 9\n", "output": "9\n" }, { "input": "1\n1000000000 1000100000\n", "output": "1000000001\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 1\n4 2\n6 7\n7 7\n", "output": "7\n" }, { "input": "1\n9 5\n", "output": "6\n" }, { "input": "8\n0 0\n2 1\n3 3\n3 5\n5 7\n8 7\n9 9\n9 9\n", "output": "8\n" }, { "input": "11\n1 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 500000000\n600000000 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "12\n" }, { "input": "2\n500000000 516158428\n500000000 1000000000\n", "output": "500000001\n" }, { "input": "1\n1 1\n", "output": "2\n" }, { "input": "1\n1000010000 1000100000\n", "output": "1000010001\n" }, { "input": "1\n4 5\n", "output": "5\n" }, { "input": "11\n1 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 500000000\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "18182428\n" }, { "input": "11\n1 100000000\n200000000 100000000\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "100000011\n" }, { "input": "1\n2 2\n", "output": "3\n" }, { "input": "1\n1000010010 1100100000\n", "output": "1000010011\n" }, { "input": "11\n1 100000000\n200000000 100000100\n200000000 300000000\n400000000 300000000\n400000000 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "100000111\n" }, { "input": "11\n1 100000000\n200000000 100000100\n200000000 300000000\n400000000 300000000\n521768407 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "178231704\n" }, { "input": "11\n0 100000000\n200000000 100000100\n200000000 300000000\n400000000 300000000\n521768407 500000000\n600000000 639960479\n618182416 700000000\n800000000 700000000\n800000000 900000000\n1000000000 900000000\n1000000000 1000000000\n", "output": "178231703\n" }, { "input": "3\n0 1\n4 3\n10 14\n", "output": "11\n" }, { "input": "1\n1000010010 0101100001\n", "output": "101100002\n" }, { "input": "1\n1000010011 1101100001\n", "output": "1000010012\n" }, { "input": "1\n1010010011 1101100001\n", "output": "1010010012\n" }, { "input": "1\n1010000011 1101100001\n", "output": "1010000012\n" }, { "input": "1\n3 12\n", "output": "4\n" }, { "input": "1\n1 0\n", "output": "1\n" }, { "input": "1\n15 9\n", "output": "10\n" }, { "input": "6\n5 5\n6 5\n6 8\n6 8\n8 8\n10 9\n", "output": "9\n" }, { "input": "5\n0 0\n0 0\n2 0\n4 5\n9 9\n", "output": "9\n" }, { "input": "5\n0 0\n1 1\n2 4\n5 4\n9 9\n", "output": "9\n" }, { "input": "2\n1 5\n9 9\n", "output": "7\n" }, { "input": "6\n2 0\n5 4\n5 5\n6 7\n7 7\n16 9\n", "output": "9\n" }, { "input": "4\n0 0\n2 2\n6 7\n7 7\n", "output": "8\n" }, { "input": "2\n1 0\n9 16\n", "output": "10\n" }, { "input": "3\n1 0\n4 4\n8 8\n", "output": "9\n" }, { "input": "1\n5 5\n", "output": "6\n" }, { "input": "1\n0000000010 0\n", "output": "1\n" }, { "input": "1\n15 8\n", "output": "9\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 1\n3 2\n6 7\n7 7\n", "output": "8\n" }, { "input": "4\n0 0\n2 2\n6 7\n13 7\n", "output": "8\n" }, { "input": "2\n1 0\n9 6\n", "output": "7\n" }, { "input": "2\n500000000 516158428\n500000000 1000001000\n", "output": "500000001\n" }, { "input": "3\n1 1\n4 4\n8 8\n", "output": "9\n" }, { "input": "1\n5 1\n", "output": "2\n" }, { "input": "1\n0010000010 0\n", "output": "1\n" }, { "input": "1\n1 2\n", "output": "2\n" }, { "input": "1\n9 12\n", "output": "10\n" }, { "input": "1\n1000010000 1100100000\n", "output": "1000010001\n" }, { "input": "7\n0 0\n0 0\n0 0\n2 0\n3 2\n6 7\n7 7\n", "output": "7\n" }, { "input": "1\n4 8\n", "output": "5\n" }, { "input": "4\n0 0\n3 2\n6 7\n13 7\n", "output": "8\n" }, { "input": "2\n1 1\n9 6\n", "output": "7\n" }, { "input": "2\n500000000 516158428\n500000000 1001001000\n", "output": "500000001\n" }, { "input": "3\n1 1\n4 3\n8 8\n", "output": "9\n" }, { "input": "1\n5 0\n", "output": "1\n" }, { "input": "1\n0010000010 1\n", "output": "2\n" }, { "input": "1\n9 14\n", "output": "10\n" }, { "input": "1\n1 8\n", "output": "2\n" }, { "input": "2\n1 1\n9 11\n", "output": "10\n" }, { "input": "3\n1 1\n4 3\n10 8\n", "output": "9\n" }, { "input": "1\n9 0\n", "output": "1\n" }, { "input": "1\n0010001010 1\n", "output": "2\n" }, { "input": "1\n2 3\n", "output": "3\n" }, { "input": "1\n9 20\n", "output": "10\n" }, { "input": "1\n1000010010 1101100000\n", "output": "1000010011\n" }, { "input": "1\n1 11\n", "output": "2\n" }, { "input": "2\n1 2\n9 11\n", "output": "10\n" }, { "input": "3\n0 1\n4 3\n10 8\n", "output": "9\n" }, { "input": "1\n4 0\n", "output": "1\n" }, { "input": "1\n0010001000 1\n", "output": "2\n" }, { "input": "1\n1 3\n", "output": "2\n" }, { "input": "1\n9 31\n", "output": "10\n" }, { "input": "1\n1000010010 1101100001\n", "output": "1000010011\n" }, { "input": "1\n1 4\n", "output": "2\n" }, { "input": "2\n1 2\n4 11\n", "output": "5\n" }, { "input": "1\n6 0\n", "output": "1\n" }, { "input": "1\n0010001000 2\n", "output": "3\n" }, { "input": "1\n0 3\n", "output": "1\n" }, { "input": "1\n4 31\n", "output": "5\n" }, { "input": "1\n2 1\n", "output": "2\n" }, { "input": "2\n1 2\n4 19\n", "output": "5\n" }, { "input": "1\n12 0\n", "output": "1\n" }, { "input": "1\n0010011000 2\n", "output": "3\n" }, { "input": "1\n1 5\n", "output": "2\n" }, { "input": "1\n4 18\n", "output": "5\n" }, { "input": "1\n1000010010 1001100001\n", "output": "1000010011\n" }, { "input": "1\n3 1\n", "output": "2\n" }, { "input": "2\n1 2\n4 7\n", "output": "5\n" }, { "input": "1\n16 0\n", "output": "1\n" }, { "input": "1\n1010011000 2\n", "output": "3\n" }, { "input": "1\n1 9\n", "output": "2\n" }, { "input": "1\n4 4\n", "output": "5\n" }, { "input": "1\n0 1\n", "output": "1\n" }, { "input": "2\n1 2\n4 2\n", "output": "3\n" }, { "input": "1\n1010011000 0\n", "output": "1\n" }, { "input": "1\n2 9\n", "output": "3\n" }, { "input": "1\n4 1\n", "output": "2\n" }, { "input": "2\n1 0\n4 2\n", "output": "3\n" }, { "input": "1\n1000011000 0\n", "output": "1\n" }, { "input": "1\n2 12\n", "output": "3\n" } ] }
[ 0.00002156432348120629, 0.00002017521616859703, 0.00001884057659527972, 0.00001852067701048951, 0.000018078856165319056, 0.000017668022522399477, 0.000017630846618225526, 0.0000173518239729021, 0.000017344038871284967, 0.000017320103201486016, 0.000017319724035729895, 0.00001707389567854021, 0.000016995435014204545, 0.000016877563114619758, 0.000016795381733500876, 0.000016575926068072554, 0.000016467204627403848, 0.000016314596713833046, 0.000016201049743225526, 0.00001597225697934878, 0.00001591390090963724, 0.000015767128592111013, 0.000015724224185970278, 0.000015626944807145978, 0.000015597262920673077, 0.000015596382457386366, 0.000015461361027644232, 0.000015405367569930072, 0.00001532531284145542, 0.000015269255217438812, 0.000015226693427666083, 0.000015178897112652973, 0.000015166201854785841, 0.00001513593898874563, 0.000014803288010817309, 0.000014708163256665208, 0.00001433690294471154, 0.000014103409842111012, 0.000014062356493116259, 0.00001395322720443619, 0.000013920502772618008, 0.00001387019154283217, 0.000013778208875109267, 0.000013712429933347902, 0.000013658406359265734, 0.000013646761554851398, 0.000013578757798841784, 0.000013548178458260491, 0.000013503387483610142, 0.000013264672790100524, 0.000013169606711647727, 0.00001277154967493444, 0.00001273942217548077, 0.00001261499095826049, 0.000012479645678540211, 0.000012419246653736888, 0.000012361196323208042, 0.000012279751953125003, 0.000012194397221918709, 0.000012090853925371504, 0.000012051068222792833, 0.000012050530457823429, 0.000012049779160292834, 0.000012027341619318181, 0.000011875318414007869, 0.000011810227723448426, 0.000011718208123907343, 0.000011255109265734266, 0.00001116820584298514, 0.000010342741586538461, 0.000009785162669361888, 0.000008051709476070805, 6.491258741258741e-9, 5.927269995629373e-9, 5.841960773601398e-9, 5.6807528409090885e-9, 4.561769285402096e-9, 4.396306818181821e-9, 4.163427392919582e-9, 3.961511145104896e-9, 3.944595443618885e-9, 3.823686079545453e-9, 3.813640461101398e-9, 3.805520651223778e-9, 3.730004370629371e-9, 3.6458082932692307e-9, 3.6072989510489517e-9, 3.5997322989510476e-9, 3.588259396853147e-9, 3.4678553868006982e-9, 3.369475251311187e-9, 3.3526141826923084e-9, 3.2513521634615396e-9, 3.1816064794580434e-9, 3.1739715362762254e-9, 3.1157807036713282e-9, 3.1081184440559423e-9, 3.1031878277972014e-9, 3.0873716127622375e-9, 3.0181995738636342e-9, 3.0093558784965052e-9, 3.0083724868881124e-9, 2.9714748142482524e-9, 2.9588751092657365e-9, 2.956116149475525e-9, 2.9220730441433575e-9, 2.880135489510489e-9, 2.853351726398601e-9, 2.850271798513987e-9, 2.8418788243007e-9, 2.8395296110139875e-9, 2.816754534527974e-9, 2.7646825830419595e-9, 2.7446528081293694e-9, 2.736642263986014e-9, 2.7024352600524503e-9, 2.6913516171328646e-9, 2.6904023710664345e-9, 2.6679824082167826e-9, 2.6657834353146847e-9, 2.615596317744756e-9, 2.5911754261363653e-9, 2.5729075611888127e-9, 2.5108377950174798e-9, 2.4931572333916092e-9, 2.4930069930069912e-9, 2.438442416958039e-9, 2.435656140734263e-9, 2.434181053321679e-9, 2.4205433238636365e-9, 2.4167941433566436e-9, 2.397863854895106e-9, 2.3852436625874144e-9, 2.365862652972027e-9, 2.3570121284965017e-9, 2.3448153409090927e-9, 2.2953521088286718e-9, 2.281270487325175e-9, 2.2632757867132873e-9, 2.26018220061189e-9, 2.259417340472029e-9, 2.202633304195804e-9, 2.1812718531468527e-9, 2.1793665319055947e-9, 2.1378796984265718e-9, 2.108084298513983e-9, 2.1022727272727255e-9, 2.0685915646853153e-9, 2.0487461756993006e-9, 2.038126912150353e-9, 1.9963805725524506e-9, 1.9603775131118895e-9, 1.960077032342657e-9, 1.9042832167832185e-9, 1.897645323426575e-9, 1.8796711101398607e-9, 1.8708000983391618e-9, 1.8462835992132876e-9, 1.8089830091783204e-9, 1.808682528409092e-9, 1.8066884287587428e-9, 1.7918692635489524e-9, 1.7367242132867109e-9, 1.728228802447551e-9, 1.7082536604021015e-9, 1.6792640952797198e-9, 1.67127403846154e-9, 1.6700652862762257e-9, 1.666609757430068e-9, 1.6613923186188799e-9, 1.6565777972027963e-9, 1.6431381118881113e-9, 1.6371967875874139e-9, 1.5827619645978996e-9, 1.5531031468531486e-9, 1.537136691433568e-9, 1.5337289663461522e-9, 1.533551409527974e-9, 1.4967630026223756e-9, 1.4923445694930077e-9, 1.4886227054195784e-9, 1.4776619864510505e-9, 1.4727791739510489e-9, 1.4615999235139843e-9, 1.4554332386363623e-9, 1.446172967657342e-9, 1.4425945148601383e-9, 1.426675863199299e-9, 1.415455638111892e-9, 1.415059549825173e-9, 1.4049661276223776e-9, 1.3908640187937089e-9, 1.385714871066433e-9, 1.3825325065559444e-9, 1.3498005900349647e-9, 1.2989510489510505e-9, 1.2948126092657348e-9, 1.2675234921328654e-9, 1.2536672312062902e-9, 1.2420714051573421e-9, 1.2394490275349643e-9, 1.2360549606643349e-9, 1.2043132648601371e-9, 1.1299511035839134e-9, 1.4151278409090913e-10, 1.3301054414335673e-10 ]
399_A. Pages
2967
2967_293
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this: << p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >> When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page. There are some conditions in the navigation: * If page 1 is in the navigation, the button "<<" must not be printed. * If page n is in the navigation, the button ">>" must not be printed. * If the page number is smaller than 1 or greater than n, it must not be printed. You can see some examples of the navigations. Make a program that prints the navigation. Input The first and the only line contains three integers n, p, k (3 ≤ n ≤ 100; 1 ≤ p ≤ n; 1 ≤ k ≤ n) Output Print the proper navigation. Follow the format of the output from the test samples. Examples Input 17 5 2 Output &lt;&lt; 3 4 (5) 6 7 &gt;&gt; Input 6 5 2 Output &lt;&lt; 3 4 (5) 6 Input 6 1 2 Output (1) 2 3 &gt;&gt; Input 6 2 2 Output 1 (2) 3 4 &gt;&gt; Input 9 6 3 Output &lt;&lt; 3 4 5 (6) 7 8 9 Input 10 6 3 Output &lt;&lt; 3 4 5 (6) 7 8 9 &gt;&gt; Input 8 5 4 Output 1 2 3 4 (5) 6 7 8
n,p,k = map(int,input().split()) if((p-k)>1): print("<<",end=" ") for i in range(p-k,p+k+1): if(i<1) or (i>n): continue elif(i==p): print("(" + str(i) + ")",end=" ") else: print(str(i),end=" ") if((p+k)<n): print(">>")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: v_0: str v_1: str v_2: str @classmethod def from_str(cls, input_: str): v_0, v_1, v_2 = input_.split('\n')[0].split(' ') return cls(v_0, v_1, v_2) def __repr__(self): return self.v_0 + ' ' + self.v_1 + ' ' + self.v_2 + '\n'
6 5 2
O(n*m)
0.000005
{ "public_tests": [ { "input": "6 5 2\n", "output": "<< 3 4 (5) 6 \n" }, { "input": "6 1 2\n", "output": "(1) 2 3 >>\n" }, { "input": "8 5 4\n", "output": "1 2 3 4 (5) 6 7 8 \n" }, { "input": "6 2 2\n", "output": "1 (2) 3 4 >>\n" }, { "input": "9 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 \n" }, { "input": "17 5 2\n", "output": "<< 3 4 (5) 6 7 >>\n" }, { "input": "10 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 >>\n" } ], "private_tests": [ { "input": "79 35 12\n", "output": "<< 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 >>\n" }, { "input": "100 46 48\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 >>\n" }, { "input": "7 5 1\n", "output": "<< 4 (5) 6 >>\n" }, { "input": "100 46 38\n", "output": "<< 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 >>\n" }, { "input": "6 1 2\n", "output": "(1) 2 3 >>\n" }, { "input": "17 5 2\n", "output": "<< 3 4 (5) 6 7 >>\n" }, { "input": "6 2 2\n", "output": "1 (2) 3 4 >>\n" }, { "input": "100 10 20\n", "output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 >>\n" }, { "input": "100 100 17\n", "output": "<< 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 (100) \n" }, { "input": "3 1 3\n", "output": "(1) 2 3 \n" }, { "input": "100 99 15\n", "output": "<< 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 (99) 100 \n" }, { "input": "100 99 5\n", "output": "<< 94 95 96 97 98 (99) 100 \n" }, { "input": "9 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 \n" }, { "input": "10 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 >>\n" }, { "input": "17 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "3 1 1\n", "output": "(1) 2 >>\n" }, { "input": "5 2 1\n", "output": "1 (2) 3 >>\n" }, { "input": "6 5 2\n", "output": "<< 3 4 (5) 6 \n" }, { "input": "5 3 1\n", "output": "<< 2 (3) 4 >>\n" }, { "input": "100 25 11\n", "output": "<< 14 15 16 17 18 19 20 21 22 23 24 (25) 26 27 28 29 30 31 32 33 34 35 36 >>\n" }, { "input": "100 10 100\n", "output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n" }, { "input": "5 5 5\n", "output": "1 2 3 4 (5) \n" }, { "input": "3 2 1\n", "output": "1 (2) 3 \n" }, { "input": "5 3 5\n", "output": "1 2 (3) 4 5 \n" }, { "input": "100 35 28\n", "output": "<< 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 >>\n" } ], "generated_tests": [ { "input": "79 44 12\n", "output": "<< 32 33 34 35 36 37 38 39 40 41 42 43 (44) 45 46 47 48 49 50 51 52 53 54 55 56 >>\n" }, { "input": "100 45 48\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 (45) 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 >>\n" }, { "input": "10 5 1\n", "output": "<< 4 (5) 6 >>\n" }, { "input": "100 46 18\n", "output": "<< 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 >>\n" }, { "input": "6 1 3\n", "output": "(1) 2 3 4 >>\n" }, { "input": "17 10 3\n", "output": "<< 7 8 9 (10) 11 12 13 >>\n" }, { "input": "6 2 1\n", "output": "1 (2) 3 >>\n" }, { "input": "4 1 3\n", "output": "(1) 2 3 4\n" }, { "input": "9 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "100 24 11\n", "output": "<< 13 14 15 16 17 18 19 20 21 22 23 (24) 25 26 27 28 29 30 31 32 33 34 35 >>\n" }, { "input": "6 3 1\n", "output": "<< 2 (3) 4 >>\n" }, { "input": "100 35 41\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 >>\n" }, { "input": "6 5 3\n", "output": "<< 2 3 4 (5) 6\n" }, { "input": "6 1 1\n", "output": "(1) 2 >>\n" }, { "input": "8 5 8\n", "output": "1 2 3 4 (5) 6 7 8\n" }, { "input": "6 3 2\n", "output": "1 2 (3) 4 5 >>\n" }, { "input": "9 8 3\n", "output": "<< 5 6 7 (8) 9\n" }, { "input": "17 7 2\n", "output": "<< 5 6 (7) 8 9 >>\n" }, { "input": "16 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 >>\n" }, { "input": "79 47 12\n", "output": "<< 35 36 37 38 39 40 41 42 43 44 45 46 (47) 48 49 50 51 52 53 54 55 56 57 58 59 >>\n" }, { "input": "100 45 21\n", "output": "<< 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 (45) 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 >>\n" }, { "input": "10 7 1\n", "output": "<< 6 (7) 8 >>\n" }, { "input": "100 14 18\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 (14) 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 >>\n" }, { "input": "17 8 3\n", "output": "<< 5 6 7 (8) 9 10 11 >>\n" }, { "input": "18 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "100 24 3\n", "output": "<< 21 22 23 (24) 25 26 27 >>\n" }, { "input": "6 4 1\n", "output": "<< 3 (4) 5 >>\n" }, { "input": "100 26 41\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (26) 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 >>\n" }, { "input": "6 1 4\n", "output": "(1) 2 3 4 5 >>\n" }, { "input": "9 3 3\n", "output": "1 2 (3) 4 5 6 >>\n" }, { "input": "79 72 12\n", "output": "<< 60 61 62 63 64 65 66 67 68 69 70 71 (72) 73 74 75 76 77 78 79\n" }, { "input": "100 17 18\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (17) 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 >>\n" }, { "input": "4 1 2\n", "output": "(1) 2 3 >>\n" }, { "input": "17 8 4\n", "output": "<< 4 5 6 7 (8) 9 10 11 12 >>\n" }, { "input": "15 5 6\n", "output": "1 2 3 4 (5) 6 7 8 9 10 11 >>\n" }, { "input": "9 3 4\n", "output": "1 2 (3) 4 5 6 7 >>\n" }, { "input": "79 72 9\n", "output": "<< 63 64 65 66 67 68 69 70 71 (72) 73 74 75 76 77 78 79\n" }, { "input": "100 17 36\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (17) 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 >>\n" }, { "input": "4 2 2\n", "output": "1 (2) 3 4\n" }, { "input": "12 9 5\n", "output": "<< 4 5 6 7 8 (9) 10 11 12\n" }, { "input": "3 3 2\n", "output": "1 2 (3)\n" }, { "input": "9 6 4\n", "output": "<< 2 3 4 5 (6) 7 8 9\n" }, { "input": "79 29 9\n", "output": "<< 20 21 22 23 24 25 26 27 28 (29) 30 31 32 33 34 35 36 37 38 >>\n" }, { "input": "100 3 36\n", "output": "1 2 (3) 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 >>\n" }, { "input": "18 8 8\n", "output": "1 2 3 4 5 6 7 (8) 9 10 11 12 13 14 15 16 >>\n" }, { "input": "12 10 5\n", "output": "<< 5 6 7 8 9 (10) 11 12\n" }, { "input": "9 6 8\n", "output": "1 2 3 4 5 (6) 7 8 9\n" }, { "input": "79 29 8\n", "output": "<< 21 22 23 24 25 26 27 28 (29) 30 31 32 33 34 35 36 37 >>\n" }, { "input": "4 4 4\n", "output": "1 2 3 (4)\n" }, { "input": "18 4 8\n", "output": "1 2 3 (4) 5 6 7 8 9 10 11 12 >>\n" }, { "input": "26 9 5\n", "output": "<< 4 5 6 7 8 (9) 10 11 12 13 14 >>\n" }, { "input": "9 6 1\n", "output": "<< 5 (6) 7 >>\n" }, { "input": "79 6 8\n", "output": "1 2 3 4 5 (6) 7 8 9 10 11 12 13 14 >>\n" }, { "input": "46 9 9\n", "output": "1 2 3 4 5 6 7 8 (9) 10 11 12 13 14 15 16 17 18 >>\n" }, { "input": "46 9 17\n", "output": "1 2 3 4 5 6 7 8 (9) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 >>\n" }, { "input": "17 14 1\n", "output": "<< 13 (14) 15 >>\n" }, { "input": "79 15 8\n", "output": "<< 7 8 9 10 11 12 13 14 (15) 16 17 18 19 20 21 22 23 >>\n" }, { "input": "46 1 17\n", "output": "(1) 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 >>\n" }, { "input": "17 9 1\n", "output": "<< 8 (9) 10 >>\n" }, { "input": "79 14 8\n", "output": "<< 6 7 8 9 10 11 12 13 (14) 15 16 17 18 19 20 21 22 >>\n" }, { "input": "79 14 7\n", "output": "<< 7 8 9 10 11 12 13 (14) 15 16 17 18 19 20 21 >>\n" }, { "input": "79 12 7\n", "output": "<< 5 6 7 8 9 10 11 (12) 13 14 15 16 17 18 19 >>\n" }, { "input": "18 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "4 1 4\n", "output": "(1) 2 3 4\n" }, { "input": "8 2 1\n", "output": "1 (2) 3 >>\n" }, { "input": "4 1 1\n", "output": "(1) 2 >>\n" }, { "input": "15 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "12 3 2\n", "output": "1 2 (3) 4 5 >>\n" }, { "input": "26 7 2\n", "output": "<< 5 6 (7) 8 9 >>\n" }, { "input": "16 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "17 7 1\n", "output": "<< 6 (7) 8 >>\n" }, { "input": "5 1 1\n", "output": "(1) 2 >>\n" }, { "input": "12 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "23 3 2\n", "output": "1 2 (3) 4 5 >>\n" }, { "input": "16 5 1\n", "output": "<< 4 (5) 6 >>\n" }, { "input": "18 8 4\n", "output": "<< 4 5 6 7 (8) 9 10 11 12 >>\n" }, { "input": "10 1 1\n", "output": "(1) 2 >>\n" }, { "input": "15 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "4 2 4\n", "output": "1 (2) 3 4\n" }, { "input": "26 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "9 6 7\n", "output": "1 2 3 4 5 (6) 7 8 9\n" }, { "input": "79 4 8\n", "output": "1 2 3 (4) 5 6 7 8 9 10 11 12 >>\n" }, { "input": "46 9 5\n", "output": "<< 4 5 6 7 8 (9) 10 11 12 13 14 >>\n" }, { "input": "9 7 1\n", "output": "<< 6 (7) 8 >>\n" }, { "input": "79 8 8\n", "output": "1 2 3 4 5 6 7 (8) 9 10 11 12 13 14 15 16 >>\n" }, { "input": "11 9 1\n", "output": "<< 8 (9) 10 >>\n" } ] }
[ 0.00002433045940626158, 0.00001602412751311189, 0.000015851153204217658, 0.000012334103197943684, 0.000010272307173953316, 0.000008395704323360504, 0.000007568171765005557, 0.000007383613201648759, 0.000007316252443034457, 0.00000702743656215265, 0.000006686385212115599, 0.000006489693578789546, 0.000006430937673675436, 0.000006189406018432753, 0.000006056276653390144, 0.000006052752674601705, 0.000005950486835402001, 0.000005938307986727637, 0.000005923573059466469, 0.000005845330643559941, 0.000005789103614790684, 0.000005691221771952575, 0.000005534852827436088, 0.000005525285163486476, 0.000005281775031727623, 0.000005268585238669426, 0.000005197440261418348, 0.000005188478665511715, 0.000005120376725175991, 0.000005102938738884772, 0.000005092488479529456, 0.000005091455967487959, 0.00000509070302658392, 0.00000508153551335438, 0.0000050660369233975546, 0.0000050501399785316946, 0.000004993936330585402, 0.000004976929800389033, 0.000004951752199888848, 0.000004947146537012683, 0.000004946049485920712, 0.0000049322795942941835, 0.000004920311249536865, 0.000004918608801871064, 0.0000049145136740459435, 0.000004890688341213678, 0.00000487001091257565, 0.000004869765799780713, 0.000004868305992960356, 0.0000048347318764047205, 0.000004819727381298402, 0.0000048168651036435686, 0.000004811624953686551, 0.000004795197332865214, 0.000004769707587866091, 0.000004757104529455354, 0.000004747951996109671, 0.000004728465288069657, 0.000004710045248240088, 0.0000018681478209522041 ]
399_A. Pages
2967
2967_59
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this: << p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >> When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page. There are some conditions in the navigation: * If page 1 is in the navigation, the button "<<" must not be printed. * If page n is in the navigation, the button ">>" must not be printed. * If the page number is smaller than 1 or greater than n, it must not be printed. You can see some examples of the navigations. Make a program that prints the navigation. Input The first and the only line contains three integers n, p, k (3 ≤ n ≤ 100; 1 ≤ p ≤ n; 1 ≤ k ≤ n) Output Print the proper navigation. Follow the format of the output from the test samples. Examples Input 17 5 2 Output &lt;&lt; 3 4 (5) 6 7 &gt;&gt; Input 6 5 2 Output &lt;&lt; 3 4 (5) 6 Input 6 1 2 Output (1) 2 3 &gt;&gt; Input 6 2 2 Output 1 (2) 3 4 &gt;&gt; Input 9 6 3 Output &lt;&lt; 3 4 5 (6) 7 8 9 Input 10 6 3 Output &lt;&lt; 3 4 5 (6) 7 8 9 &gt;&gt; Input 8 5 4 Output 1 2 3 4 (5) 6 7 8
n,p,k=map(int,input().split(" ")) ans="" if p-k>1: ans+='<< ' for i in range(p-k, p+k+1): if i>0 and i<=n: if i==p: ans+='('+str(p)+') ' else: ans+=str(i)+' ' if p+k<n: ans+='>>' if ans[len(ans)-1]==" ": print(ans[0:len(ans)-1]) else: print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: v_0: str v_1: str v_2: str @classmethod def from_str(cls, input_: str): v_0, v_1, v_2 = input_.split('\n')[0].split(' ') return cls(v_0, v_1, v_2) def __repr__(self): return self.v_0 + ' ' + self.v_1 + ' ' + self.v_2 + '\n'
6 5 2
O(n+m)
0.000002
{ "public_tests": [ { "input": "6 5 2\n", "output": "<< 3 4 (5) 6 \n" }, { "input": "6 1 2\n", "output": "(1) 2 3 >>\n" }, { "input": "8 5 4\n", "output": "1 2 3 4 (5) 6 7 8 \n" }, { "input": "6 2 2\n", "output": "1 (2) 3 4 >>\n" }, { "input": "9 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 \n" }, { "input": "17 5 2\n", "output": "<< 3 4 (5) 6 7 >>\n" }, { "input": "10 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 >>\n" } ], "private_tests": [ { "input": "79 35 12\n", "output": "<< 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 >>\n" }, { "input": "100 46 48\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 >>\n" }, { "input": "7 5 1\n", "output": "<< 4 (5) 6 >>\n" }, { "input": "100 46 38\n", "output": "<< 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 >>\n" }, { "input": "6 1 2\n", "output": "(1) 2 3 >>\n" }, { "input": "17 5 2\n", "output": "<< 3 4 (5) 6 7 >>\n" }, { "input": "6 2 2\n", "output": "1 (2) 3 4 >>\n" }, { "input": "100 10 20\n", "output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 >>\n" }, { "input": "100 100 17\n", "output": "<< 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 (100) \n" }, { "input": "3 1 3\n", "output": "(1) 2 3 \n" }, { "input": "100 99 15\n", "output": "<< 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 (99) 100 \n" }, { "input": "100 99 5\n", "output": "<< 94 95 96 97 98 (99) 100 \n" }, { "input": "9 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 \n" }, { "input": "10 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 >>\n" }, { "input": "17 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "3 1 1\n", "output": "(1) 2 >>\n" }, { "input": "5 2 1\n", "output": "1 (2) 3 >>\n" }, { "input": "6 5 2\n", "output": "<< 3 4 (5) 6 \n" }, { "input": "5 3 1\n", "output": "<< 2 (3) 4 >>\n" }, { "input": "100 25 11\n", "output": "<< 14 15 16 17 18 19 20 21 22 23 24 (25) 26 27 28 29 30 31 32 33 34 35 36 >>\n" }, { "input": "100 10 100\n", "output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n" }, { "input": "5 5 5\n", "output": "1 2 3 4 (5) \n" }, { "input": "3 2 1\n", "output": "1 (2) 3 \n" }, { "input": "5 3 5\n", "output": "1 2 (3) 4 5 \n" }, { "input": "100 35 28\n", "output": "<< 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 >>\n" } ], "generated_tests": [ { "input": "79 44 12\n", "output": "<< 32 33 34 35 36 37 38 39 40 41 42 43 (44) 45 46 47 48 49 50 51 52 53 54 55 56 >>\n" }, { "input": "100 45 48\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 (45) 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 >>\n" }, { "input": "10 5 1\n", "output": "<< 4 (5) 6 >>\n" }, { "input": "100 46 18\n", "output": "<< 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 >>\n" }, { "input": "6 1 3\n", "output": "(1) 2 3 4 >>\n" }, { "input": "17 10 3\n", "output": "<< 7 8 9 (10) 11 12 13 >>\n" }, { "input": "6 2 1\n", "output": "1 (2) 3 >>\n" }, { "input": "4 1 3\n", "output": "(1) 2 3 4\n" }, { "input": "9 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "100 24 11\n", "output": "<< 13 14 15 16 17 18 19 20 21 22 23 (24) 25 26 27 28 29 30 31 32 33 34 35 >>\n" }, { "input": "6 3 1\n", "output": "<< 2 (3) 4 >>\n" }, { "input": "100 35 41\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 >>\n" }, { "input": "6 5 3\n", "output": "<< 2 3 4 (5) 6\n" }, { "input": "6 1 1\n", "output": "(1) 2 >>\n" }, { "input": "8 5 8\n", "output": "1 2 3 4 (5) 6 7 8\n" }, { "input": "6 3 2\n", "output": "1 2 (3) 4 5 >>\n" }, { "input": "9 8 3\n", "output": "<< 5 6 7 (8) 9\n" }, { "input": "17 7 2\n", "output": "<< 5 6 (7) 8 9 >>\n" }, { "input": "16 6 3\n", "output": "<< 3 4 5 (6) 7 8 9 >>\n" }, { "input": "79 47 12\n", "output": "<< 35 36 37 38 39 40 41 42 43 44 45 46 (47) 48 49 50 51 52 53 54 55 56 57 58 59 >>\n" }, { "input": "100 45 21\n", "output": "<< 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 (45) 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 >>\n" }, { "input": "10 7 1\n", "output": "<< 6 (7) 8 >>\n" }, { "input": "100 14 18\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 (14) 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 >>\n" }, { "input": "17 8 3\n", "output": "<< 5 6 7 (8) 9 10 11 >>\n" }, { "input": "18 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "100 24 3\n", "output": "<< 21 22 23 (24) 25 26 27 >>\n" }, { "input": "6 4 1\n", "output": "<< 3 (4) 5 >>\n" }, { "input": "100 26 41\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (26) 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 >>\n" }, { "input": "6 1 4\n", "output": "(1) 2 3 4 5 >>\n" }, { "input": "9 3 3\n", "output": "1 2 (3) 4 5 6 >>\n" }, { "input": "79 72 12\n", "output": "<< 60 61 62 63 64 65 66 67 68 69 70 71 (72) 73 74 75 76 77 78 79\n" }, { "input": "100 17 18\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (17) 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 >>\n" }, { "input": "4 1 2\n", "output": "(1) 2 3 >>\n" }, { "input": "17 8 4\n", "output": "<< 4 5 6 7 (8) 9 10 11 12 >>\n" }, { "input": "15 5 6\n", "output": "1 2 3 4 (5) 6 7 8 9 10 11 >>\n" }, { "input": "9 3 4\n", "output": "1 2 (3) 4 5 6 7 >>\n" }, { "input": "79 72 9\n", "output": "<< 63 64 65 66 67 68 69 70 71 (72) 73 74 75 76 77 78 79\n" }, { "input": "100 17 36\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (17) 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 >>\n" }, { "input": "4 2 2\n", "output": "1 (2) 3 4\n" }, { "input": "12 9 5\n", "output": "<< 4 5 6 7 8 (9) 10 11 12\n" }, { "input": "3 3 2\n", "output": "1 2 (3)\n" }, { "input": "9 6 4\n", "output": "<< 2 3 4 5 (6) 7 8 9\n" }, { "input": "79 29 9\n", "output": "<< 20 21 22 23 24 25 26 27 28 (29) 30 31 32 33 34 35 36 37 38 >>\n" }, { "input": "100 3 36\n", "output": "1 2 (3) 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 >>\n" }, { "input": "18 8 8\n", "output": "1 2 3 4 5 6 7 (8) 9 10 11 12 13 14 15 16 >>\n" }, { "input": "12 10 5\n", "output": "<< 5 6 7 8 9 (10) 11 12\n" }, { "input": "9 6 8\n", "output": "1 2 3 4 5 (6) 7 8 9\n" }, { "input": "79 29 8\n", "output": "<< 21 22 23 24 25 26 27 28 (29) 30 31 32 33 34 35 36 37 >>\n" }, { "input": "4 4 4\n", "output": "1 2 3 (4)\n" }, { "input": "18 4 8\n", "output": "1 2 3 (4) 5 6 7 8 9 10 11 12 >>\n" }, { "input": "26 9 5\n", "output": "<< 4 5 6 7 8 (9) 10 11 12 13 14 >>\n" }, { "input": "9 6 1\n", "output": "<< 5 (6) 7 >>\n" }, { "input": "79 6 8\n", "output": "1 2 3 4 5 (6) 7 8 9 10 11 12 13 14 >>\n" }, { "input": "46 9 9\n", "output": "1 2 3 4 5 6 7 8 (9) 10 11 12 13 14 15 16 17 18 >>\n" }, { "input": "46 9 17\n", "output": "1 2 3 4 5 6 7 8 (9) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 >>\n" }, { "input": "17 14 1\n", "output": "<< 13 (14) 15 >>\n" }, { "input": "79 15 8\n", "output": "<< 7 8 9 10 11 12 13 14 (15) 16 17 18 19 20 21 22 23 >>\n" }, { "input": "46 1 17\n", "output": "(1) 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 >>\n" }, { "input": "17 9 1\n", "output": "<< 8 (9) 10 >>\n" }, { "input": "79 14 8\n", "output": "<< 6 7 8 9 10 11 12 13 (14) 15 16 17 18 19 20 21 22 >>\n" }, { "input": "79 14 7\n", "output": "<< 7 8 9 10 11 12 13 (14) 15 16 17 18 19 20 21 >>\n" }, { "input": "79 12 7\n", "output": "<< 5 6 7 8 9 10 11 (12) 13 14 15 16 17 18 19 >>\n" }, { "input": "18 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "4 1 4\n", "output": "(1) 2 3 4\n" }, { "input": "8 2 1\n", "output": "1 (2) 3 >>\n" }, { "input": "4 1 1\n", "output": "(1) 2 >>\n" }, { "input": "15 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "12 3 2\n", "output": "1 2 (3) 4 5 >>\n" }, { "input": "26 7 2\n", "output": "<< 5 6 (7) 8 9 >>\n" }, { "input": "16 5 3\n", "output": "<< 2 3 4 (5) 6 7 8 >>\n" }, { "input": "17 7 1\n", "output": "<< 6 (7) 8 >>\n" }, { "input": "5 1 1\n", "output": "(1) 2 >>\n" }, { "input": "12 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "23 3 2\n", "output": "1 2 (3) 4 5 >>\n" }, { "input": "16 5 1\n", "output": "<< 4 (5) 6 >>\n" }, { "input": "18 8 4\n", "output": "<< 4 5 6 7 (8) 9 10 11 12 >>\n" }, { "input": "10 1 1\n", "output": "(1) 2 >>\n" }, { "input": "15 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "4 2 4\n", "output": "1 (2) 3 4\n" }, { "input": "26 5 5\n", "output": "1 2 3 4 (5) 6 7 8 9 10 >>\n" }, { "input": "9 6 7\n", "output": "1 2 3 4 5 (6) 7 8 9\n" }, { "input": "79 4 8\n", "output": "1 2 3 (4) 5 6 7 8 9 10 11 12 >>\n" }, { "input": "46 9 5\n", "output": "<< 4 5 6 7 8 (9) 10 11 12 13 14 >>\n" }, { "input": "9 7 1\n", "output": "<< 6 (7) 8 >>\n" }, { "input": "79 8 8\n", "output": "1 2 3 4 5 6 7 (8) 9 10 11 12 13 14 15 16 >>\n" }, { "input": "11 9 1\n", "output": "<< 8 (9) 10 >>\n" } ] }
[ 0.00000639189322006119, 0.000005355572702687938, 0.000005300907834353147, 0.000005039228925371505, 0.000004633065327250875, 0.00000413402186680507, 0.000003868271757539336, 0.000003848102976125437, 0.000003816026824737763, 0.00000381283972082605, 0.0000037118387237762233, 0.0000036627821172967658, 0.000003630505982298951, 0.000003594779993444056, 0.0000035455864565122385, 0.0000034081079818618883, 0.0000032361035429414337, 0.000003215918883850525, 0.0000030726845907998253, 0.000003063729738035402, 0.0000030215311817089163, 0.000003005202633304196, 0.0000030038265952797203, 0.0000030025197907561197, 0.0000029698554004589167, 0.0000028404843476835664, 0.0000028010722246503504, 0.0000027944946732954546, 0.000002747262067034528, 0.0000027035793678977275, 0.000002695408722137238, 0.0000026935183156687064, 0.000002689124822443182, 0.000002687376748251748, 0.0000026825095744099656, 0.000002656533981643357, 0.0000026422531004152103, 0.0000026368174032998247, 0.0000026271161494755246, 0.0000025763245943509616, 0.000002576081771743881, 0.000002543989920236014, 0.0000025140547694493005, 0.0000024787481629698427, 0.0000024554696924169585, 0.0000024482919034090905, 0.0000024181970744099654, 0.0000024063902835445803, 0.0000023847003933566435, 0.0000023807851699082167, 0.000002379585869208916, 0.000002373300699300699, 0.0000023635281495847905, 0.000002350005743280158, 0.000002347052447552448, 0.0000023460707154173954, 0.0000023022196924169588, 0.000002297686393684441, 0.000002295602149803322, 0.000002267721522618007, 0.0000022652138603583917, 0.00000219011281687063, 0.0000021470562581949303, 0.0000021458215417395105, 0.0000021301564958479022, 0.000002100641792777535, 0.0000020997436352709794, 0.000002081259273929196, 0.0000020744627745301576, 0.0000020659681900131123, 0.0000020643189057036715, 0.0000020614757839816434, 0.00000205332027152535, 0.000002049121107408217, 0.000002041878646743881, 0.000002019446541739511, 0.000002017409227491259, 0.0000020078329600087416, 0.0000020059087221372378, 0.0000019998293678977272, 0.000001999808033763112, 0.0000019937453971809443, 0.0000019728156140734264, 0.000001955894940996504, 0.0000019511996148382866, 0.0000019462380217438815, 0.000001944161535729895, 0.0000019435870984484268, 0.000001927558901059878, 0.0000019238095361669586, 0.0000019076032424606647, 0.0000018965493607954544, 0.0000018944782288024477, 0.0000018841543105332172, 0.0000018694464871066436, 0.0000018553065313592658, 0.0000018517382402753499, 0.0000018495538406905596, 0.0000018340800439794584, 0.000001821680691378934, 0.000001801593067089161, 0.000001788052939248252, 0.0000017043583506337412, 0.000001547653026660839, 0.000001544199287041084, 0.000001391627089707168, 0.0000012756603201486015, 0.00000121179063319493, 0.0000011636606889204547, 0.0000011583668460445802, 0.0000011563523137019233, 0.0000011395040155157341, 0.0000011311257238854896, 0.0000011212648328234269 ]
914_B. Conan and Agasa play a Card Game
565
565_118
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it. They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai. A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally. Input The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card. Output If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). Examples Input 3 4 5 7 Output Conan Input 2 1 1 Output Agasa Note In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn. In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.
from pprint import pprint as pp def GI(): return int(input()) def GIS(): return map(int, input().split()) def main(): GI() l = list(GIS()) s = [0] * (10 ** 5 + 1) for x in l: s[x] += 1 for x in reversed(s): if x % 2: return "Conan" return "Agasa" print(main())
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int numbers: List[int] @classmethod def from_str(cls, input_: str): n, numbers, _ = input_.split('\n') n = int(n) numbers = list(map(int, numbers.split(' '))) assert len(numbers) == n return cls(n, numbers) def __repr__(self): return str(self.n) + '\n' + ' '.join(map(str, self.numbers)) + '\n'
3 4 5 7
O(n)
0.000002
{ "public_tests": [ { "input": "3\n4 5 7\n", "output": "Conan" }, { "input": "2\n1 1\n", "output": "Agasa" } ], "private_tests": [ { "input": "5\n1 4 4 5 5\n", "output": "Conan" }, { "input": "4\n3 3 2 1\n", "output": "Conan" }, { "input": "1\n100000\n", "output": "Conan" }, { "input": "10\n50096 50096 50096 50096 50096 50096 28505 50096 50096 50096\n", "output": "Conan" }, { "input": "3\n4 4 100000\n", "output": "Conan" }, { "input": "1\n2\n", "output": "Conan" }, { "input": "10\n87900 87900 5761 87900 87900 87900 5761 87900 87900 87900\n", "output": "Agasa" }, { "input": "7\n7 7 7 7 6 6 6\n", "output": "Conan" }, { "input": "7\n7 7 6 6 5 5 4\n", "output": "Conan" }, { "input": "10\n53335 35239 26741 35239 35239 26741 35239 35239 53335 35239\n", "output": "Agasa" }, { "input": "10\n30757 30757 33046 41744 39918 39914 41744 39914 33046 33046\n", "output": "Conan" }, { "input": "3\n1 1 2\n", "output": "Conan" }, { "input": "3\n4 4 5\n", "output": "Conan" }, { "input": "3\n1 3 3\n", "output": "Conan" }, { "input": "4\n1 2 1 2\n", "output": "Agasa" }, { "input": "5\n1 1 1 2 2\n", "output": "Conan" }, { "input": "3\n2 3 3\n", "output": "Conan" }, { "input": "5\n100000 100000 100000 2 2\n", "output": "Conan" }, { "input": "5\n2 2 1 1 1\n", "output": "Conan" }, { "input": "4\n2 3 4 5\n", "output": "Conan" }, { "input": "10\n75994 64716 75994 64716 75994 75994 56304 64716 56304 64716\n", "output": "Agasa" }, { "input": "3\n1 2 2\n", "output": "Conan" }, { "input": "1\n485\n", "output": "Conan" }, { "input": "10\n54842 54842 54842 54842 57983 54842 54842 57983 57983 54842\n", "output": "Conan" }, { "input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282\n", "output": "Conan" }, { "input": "5\n1 1 2 2 2\n", "output": "Conan" }, { "input": "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846\n", "output": "Conan" }, { "input": "5\n3 3 3 4 4\n", "output": "Conan" }, { "input": "3\n2 2 2\n", "output": "Conan" }, { "input": "3\n1 1 100000\n", "output": "Conan" }, { "input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165\n", "output": "Agasa" }, { "input": "3\n1 1 1\n", "output": "Conan" }, { "input": "3\n97 97 100\n", "output": "Conan" }, { "input": "1\n1\n", "output": "Conan" }, { "input": "3\n1 2 3\n", "output": "Conan" }, { "input": "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176\n", "output": "Conan" }, { "input": "5\n100000 100000 100000 1 1\n", "output": "Conan" } ], "generated_tests": [ { "input": "4\n3 2 2 1\n", "output": "Conan\n" }, { "input": "4\n0 2 0 2\n", "output": "Agasa\n" }, { "input": "10\n50096 50096 50096 50096 50096 50096 55337 50096 50096 50096\n", "output": "Conan\n" }, { "input": "10\n87900 87900 5761 59670 87900 87900 5761 87900 87900 87900\n", "output": "Conan\n" }, { "input": "7\n7 7 6 6 5 7 4\n", "output": "Conan\n" }, { "input": "10\n53335 35239 26741 28797 35239 26741 35239 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 30757 5314 41744 39918 39914 41744 39914 33046 33046\n", "output": "Conan\n" }, { "input": "3\n4 6 5\n", "output": "Conan\n" }, { "input": "3\n2 6 3\n", "output": "Conan\n" }, { "input": "4\n0 2 1 2\n", "output": "Conan\n" }, { "input": "5\n1 1 1 1 2\n", "output": "Conan\n" }, { "input": "3\n2 3 5\n", "output": "Conan\n" }, { "input": "5\n2 2 1 2 1\n", "output": "Conan\n" }, { "input": "4\n2 3 5 5\n", "output": "Conan\n" }, { "input": "3\n1 2 0\n", "output": "Conan\n" }, { "input": "1\n147\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 38282 38282 38282 38282 38282 38282\n", "output": "Conan\n" }, { "input": "5\n1 1 2 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 36846 36846\n", "output": "Conan\n" }, { "input": "5\n3 4 3 4 4\n", "output": "Conan\n" }, { "input": "3\n2 2 3\n", "output": "Conan\n" }, { "input": "3\n0 1 100000\n", "output": "Conan\n" }, { "input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n1 0 2\n", "output": "Conan\n" }, { "input": "3\n150 97 100\n", "output": "Conan\n" }, { "input": "1\n4\n", "output": "Conan\n" }, { "input": "3\n2 2 4\n", "output": "Conan\n" }, { "input": "3\n4 2 7\n", "output": "Conan\n" }, { "input": "2\n0 1\n", "output": "Conan\n" }, { "input": "4\n3 4 2 1\n", "output": "Conan\n" }, { "input": "10\n50096 50096 50096 83009 50096 50096 55337 50096 50096 50096\n", "output": "Conan\n" }, { "input": "7\n7 5 6 6 5 7 4\n", "output": "Conan\n" }, { "input": "10\n53335 35239 36302 28797 35239 26741 35239 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 49832 5314 41744 39918 39914 41744 39914 33046 33046\n", "output": "Conan\n" }, { "input": "3\n4 1 5\n", "output": "Conan\n" }, { "input": "3\n2 6 5\n", "output": "Conan\n" }, { "input": "5\n1 0 1 1 2\n", "output": "Conan\n" }, { "input": "3\n2 3 4\n", "output": "Conan\n" }, { "input": "5\n2 2 1 2 2\n", "output": "Conan\n" }, { "input": "4\n2 6 5 5\n", "output": "Conan\n" }, { "input": "3\n1 2 1\n", "output": "Conan\n" }, { "input": "1\n225\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 38282 38282 38282 8227 38282 38282\n", "output": "Conan\n" }, { "input": "5\n1 1 3 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 36846 65962\n", "output": "Conan\n" }, { "input": "3\n4 2 3\n", "output": "Conan\n" }, { "input": "10\n50165 50165 50165 50165 50165 50165 50855 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n1 0 0\n", "output": "Conan\n" }, { "input": "3\n240 97 100\n", "output": "Conan\n" }, { "input": "3\n3 2 4\n", "output": "Conan\n" }, { "input": "3\n4 2 1\n", "output": "Conan\n" }, { "input": "2\n0 2\n", "output": "Conan\n" }, { "input": "4\n3 1 2 1\n", "output": "Conan\n" }, { "input": "7\n7 5 6 6 5 5 4\n", "output": "Conan\n" }, { "input": "10\n53335 35239 36302 28797 35239 26741 63400 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 49832 5314 41744 39918 39914 41744 52593 33046 33046\n", "output": "Conan\n" }, { "input": "3\n5 1 5\n", "output": "Conan\n" }, { "input": "3\n2 6 2\n", "output": "Conan\n" }, { "input": "4\n1 2 0 2\n", "output": "Conan\n" }, { "input": "5\n1 0 1 1 0\n", "output": "Conan\n" }, { "input": "3\n2 0 4\n", "output": "Conan\n" }, { "input": "4\n2 12 5 5\n", "output": "Conan\n" }, { "input": "1\n280\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 63357 38282 38282 8227 38282 38282\n", "output": "Conan\n" }, { "input": "5\n2 1 3 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 36846 76231\n", "output": "Conan\n" }, { "input": "3\n4 2 4\n", "output": "Conan\n" }, { "input": "10\n50165 50165 10543 50165 50165 50165 50855 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n2 0 0\n", "output": "Conan\n" }, { "input": "3\n94 97 100\n", "output": "Conan\n" }, { "input": "3\n3 3 4\n", "output": "Conan\n" }, { "input": "3\n6 2 1\n", "output": "Conan\n" }, { "input": "2\n1 0\n", "output": "Conan\n" }, { "input": "4\n3 0 2 1\n", "output": "Conan\n" }, { "input": "7\n7 5 6 6 5 0 4\n", "output": "Conan\n" }, { "input": "10\n84715 35239 36302 28797 35239 26741 63400 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 49832 5314 41744 39918 39914 41744 52593 33046 42822\n", "output": "Conan\n" }, { "input": "3\n5 1 8\n", "output": "Conan\n" }, { "input": "3\n2 6 1\n", "output": "Conan\n" }, { "input": "4\n1 0 0 2\n", "output": "Conan\n" }, { "input": "3\n1 0 4\n", "output": "Conan\n" }, { "input": "4\n3 12 5 5\n", "output": "Conan\n" }, { "input": "1\n16\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 63357 38282 38282 8227 38282 50884\n", "output": "Conan\n" }, { "input": "5\n2 1 2 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 8485 76231\n", "output": "Conan\n" }, { "input": "3\n6 2 4\n", "output": "Conan\n" }, { "input": "10\n50165 50165 10543 50165 14278 50165 50855 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n2 1 0\n", "output": "Conan\n" }, { "input": "3\n94 97 000\n", "output": "Conan\n" } ] }
[ 0.021078402, 0.020871779000000035, 0.019866684, 0.000003859382375437063, 0.0000032940068427666086, 0.0000028279427584134617, 0.000002783665906359266, 0.000002742524188701923, 0.0000026541961593094407, 0.0000024630657916302453, 0.000002332257935423951, 0.0000023172882703234267, 0.0000023099331566870633, 0.0000022953986150568184, 0.0000022948734429632864, 0.0000022619934167395105, 0.000002242212740384616, 0.000002114077537696678, 0.0000021002182583041956, 0.000002095239114401224, 0.0000020824317225743005, 0.000002076051259287588, 0.000002064892946896853, 0.0000020460087139423078, 0.0000020335187390734267, 0.00000202849252895542, 0.000002025408339707168, 0.0000020120550016389863, 0.0000020055784664554195, 0.0000019962763603583916, 0.0000019914469651442308, 0.00000197680082222465, 0.00000197298985194493, 0.0000019650187254152095, 0.0000019646476726398605, 0.0000019615958670236012, 0.000001957506829108392, 0.000001950937991695804, 0.0000019464808511800703, 0.000001943430643575175, 0.0000019417325311407345, 0.000001929234839379371, 0.0000019213420836975524, 0.0000019146217630026225, 0.000001909664690777971, 0.0000019095743689903845, 0.0000019086833205856645, 0.0000019078434222027974, 0.0000019066341373470283, 0.0000019017955091783219, 0.000001896418993116259, 0.0000018855717192963288, 0.0000018846054960664338, 0.0000018826145514641609, 0.0000018816152890078672, 0.0000018779658817744757, 0.0000018773712713068185, 0.000001872849254261364, 0.0000018663132375437063, 0.0000018430547284746505, 0.0000018417907834353148, 0.0000018255171000874129, 0.000001822052215362762, 0.0000018203017646416088, 0.0000018163094132430072, 0.0000018157810997596153, 0.000001815464474978147, 0.0000018097040810751751, 0.0000018095103939029722, 0.0000017948849431818185, 0.0000017398596071896858, 0.0000016592613909527976, 0.0000015756913652753496, 0.000001535944629589161, 0.0000014683723776223776, 0.0000014670034418706294, 0.0000013843412915209793, 0.0000013755769094187064, 0.0000013077325447989514, 0.0000012216293433129373, 0.0000012150657096809442, 0.0000011999997678103148, 0.0000011992230933129369, 9.901619045017482e-7, 7.897026606206295e-7, 3.3667231206293678e-9, 3.028709571678325e-11 ]
914_B. Conan and Agasa play a Card Game
565
565_158
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it. They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai. A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally. Input The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card. Output If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). Examples Input 3 4 5 7 Output Conan Input 2 1 1 Output Agasa Note In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn. In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.
n=int(input()) arr=list(map(int,input().split())) arrx=[] arr.sort(reverse=True) i=0 while(i<n): count=0 val=arr[i] while(i<n and arr[i]==val): i+=1 count+=1 arrx.append(count) flag=0 for i in range(len(arrx)): if(arrx[i]%2!=0): flag=1 break if(flag==0): print('Agasa') else: print('Conan')
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int numbers: List[int] @classmethod def from_str(cls, input_: str): n, numbers, _ = input_.split('\n') n = int(n) numbers = list(map(int, numbers.split(' '))) assert len(numbers) == n return cls(n, numbers) def __repr__(self): return str(self.n) + '\n' + ' '.join(map(str, self.numbers)) + '\n'
3 4 5 7
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n4 5 7\n", "output": "Conan" }, { "input": "2\n1 1\n", "output": "Agasa" } ], "private_tests": [ { "input": "5\n1 4 4 5 5\n", "output": "Conan" }, { "input": "4\n3 3 2 1\n", "output": "Conan" }, { "input": "1\n100000\n", "output": "Conan" }, { "input": "10\n50096 50096 50096 50096 50096 50096 28505 50096 50096 50096\n", "output": "Conan" }, { "input": "3\n4 4 100000\n", "output": "Conan" }, { "input": "1\n2\n", "output": "Conan" }, { "input": "10\n87900 87900 5761 87900 87900 87900 5761 87900 87900 87900\n", "output": "Agasa" }, { "input": "7\n7 7 7 7 6 6 6\n", "output": "Conan" }, { "input": "7\n7 7 6 6 5 5 4\n", "output": "Conan" }, { "input": "10\n53335 35239 26741 35239 35239 26741 35239 35239 53335 35239\n", "output": "Agasa" }, { "input": "10\n30757 30757 33046 41744 39918 39914 41744 39914 33046 33046\n", "output": "Conan" }, { "input": "3\n1 1 2\n", "output": "Conan" }, { "input": "3\n4 4 5\n", "output": "Conan" }, { "input": "3\n1 3 3\n", "output": "Conan" }, { "input": "4\n1 2 1 2\n", "output": "Agasa" }, { "input": "5\n1 1 1 2 2\n", "output": "Conan" }, { "input": "3\n2 3 3\n", "output": "Conan" }, { "input": "5\n100000 100000 100000 2 2\n", "output": "Conan" }, { "input": "5\n2 2 1 1 1\n", "output": "Conan" }, { "input": "4\n2 3 4 5\n", "output": "Conan" }, { "input": "10\n75994 64716 75994 64716 75994 75994 56304 64716 56304 64716\n", "output": "Agasa" }, { "input": "3\n1 2 2\n", "output": "Conan" }, { "input": "1\n485\n", "output": "Conan" }, { "input": "10\n54842 54842 54842 54842 57983 54842 54842 57983 57983 54842\n", "output": "Conan" }, { "input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282\n", "output": "Conan" }, { "input": "5\n1 1 2 2 2\n", "output": "Conan" }, { "input": "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846\n", "output": "Conan" }, { "input": "5\n3 3 3 4 4\n", "output": "Conan" }, { "input": "3\n2 2 2\n", "output": "Conan" }, { "input": "3\n1 1 100000\n", "output": "Conan" }, { "input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165\n", "output": "Agasa" }, { "input": "3\n1 1 1\n", "output": "Conan" }, { "input": "3\n97 97 100\n", "output": "Conan" }, { "input": "1\n1\n", "output": "Conan" }, { "input": "3\n1 2 3\n", "output": "Conan" }, { "input": "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176\n", "output": "Conan" }, { "input": "5\n100000 100000 100000 1 1\n", "output": "Conan" } ], "generated_tests": [ { "input": "4\n3 2 2 1\n", "output": "Conan\n" }, { "input": "4\n0 2 0 2\n", "output": "Agasa\n" }, { "input": "10\n50096 50096 50096 50096 50096 50096 55337 50096 50096 50096\n", "output": "Conan\n" }, { "input": "10\n87900 87900 5761 59670 87900 87900 5761 87900 87900 87900\n", "output": "Conan\n" }, { "input": "7\n7 7 6 6 5 7 4\n", "output": "Conan\n" }, { "input": "10\n53335 35239 26741 28797 35239 26741 35239 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 30757 5314 41744 39918 39914 41744 39914 33046 33046\n", "output": "Conan\n" }, { "input": "3\n4 6 5\n", "output": "Conan\n" }, { "input": "3\n2 6 3\n", "output": "Conan\n" }, { "input": "4\n0 2 1 2\n", "output": "Conan\n" }, { "input": "5\n1 1 1 1 2\n", "output": "Conan\n" }, { "input": "3\n2 3 5\n", "output": "Conan\n" }, { "input": "5\n2 2 1 2 1\n", "output": "Conan\n" }, { "input": "4\n2 3 5 5\n", "output": "Conan\n" }, { "input": "3\n1 2 0\n", "output": "Conan\n" }, { "input": "1\n147\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 38282 38282 38282 38282 38282 38282\n", "output": "Conan\n" }, { "input": "5\n1 1 2 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 36846 36846\n", "output": "Conan\n" }, { "input": "5\n3 4 3 4 4\n", "output": "Conan\n" }, { "input": "3\n2 2 3\n", "output": "Conan\n" }, { "input": "3\n0 1 100000\n", "output": "Conan\n" }, { "input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n1 0 2\n", "output": "Conan\n" }, { "input": "3\n150 97 100\n", "output": "Conan\n" }, { "input": "1\n4\n", "output": "Conan\n" }, { "input": "3\n2 2 4\n", "output": "Conan\n" }, { "input": "3\n4 2 7\n", "output": "Conan\n" }, { "input": "2\n0 1\n", "output": "Conan\n" }, { "input": "4\n3 4 2 1\n", "output": "Conan\n" }, { "input": "10\n50096 50096 50096 83009 50096 50096 55337 50096 50096 50096\n", "output": "Conan\n" }, { "input": "7\n7 5 6 6 5 7 4\n", "output": "Conan\n" }, { "input": "10\n53335 35239 36302 28797 35239 26741 35239 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 49832 5314 41744 39918 39914 41744 39914 33046 33046\n", "output": "Conan\n" }, { "input": "3\n4 1 5\n", "output": "Conan\n" }, { "input": "3\n2 6 5\n", "output": "Conan\n" }, { "input": "5\n1 0 1 1 2\n", "output": "Conan\n" }, { "input": "3\n2 3 4\n", "output": "Conan\n" }, { "input": "5\n2 2 1 2 2\n", "output": "Conan\n" }, { "input": "4\n2 6 5 5\n", "output": "Conan\n" }, { "input": "3\n1 2 1\n", "output": "Conan\n" }, { "input": "1\n225\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 38282 38282 38282 8227 38282 38282\n", "output": "Conan\n" }, { "input": "5\n1 1 3 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 36846 65962\n", "output": "Conan\n" }, { "input": "3\n4 2 3\n", "output": "Conan\n" }, { "input": "10\n50165 50165 50165 50165 50165 50165 50855 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n1 0 0\n", "output": "Conan\n" }, { "input": "3\n240 97 100\n", "output": "Conan\n" }, { "input": "3\n3 2 4\n", "output": "Conan\n" }, { "input": "3\n4 2 1\n", "output": "Conan\n" }, { "input": "2\n0 2\n", "output": "Conan\n" }, { "input": "4\n3 1 2 1\n", "output": "Conan\n" }, { "input": "7\n7 5 6 6 5 5 4\n", "output": "Conan\n" }, { "input": "10\n53335 35239 36302 28797 35239 26741 63400 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 49832 5314 41744 39918 39914 41744 52593 33046 33046\n", "output": "Conan\n" }, { "input": "3\n5 1 5\n", "output": "Conan\n" }, { "input": "3\n2 6 2\n", "output": "Conan\n" }, { "input": "4\n1 2 0 2\n", "output": "Conan\n" }, { "input": "5\n1 0 1 1 0\n", "output": "Conan\n" }, { "input": "3\n2 0 4\n", "output": "Conan\n" }, { "input": "4\n2 12 5 5\n", "output": "Conan\n" }, { "input": "1\n280\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 63357 38282 38282 8227 38282 38282\n", "output": "Conan\n" }, { "input": "5\n2 1 3 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 36846 76231\n", "output": "Conan\n" }, { "input": "3\n4 2 4\n", "output": "Conan\n" }, { "input": "10\n50165 50165 10543 50165 50165 50165 50855 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n2 0 0\n", "output": "Conan\n" }, { "input": "3\n94 97 100\n", "output": "Conan\n" }, { "input": "3\n3 3 4\n", "output": "Conan\n" }, { "input": "3\n6 2 1\n", "output": "Conan\n" }, { "input": "2\n1 0\n", "output": "Conan\n" }, { "input": "4\n3 0 2 1\n", "output": "Conan\n" }, { "input": "7\n7 5 6 6 5 0 4\n", "output": "Conan\n" }, { "input": "10\n84715 35239 36302 28797 35239 26741 63400 35239 53335 35239\n", "output": "Conan\n" }, { "input": "10\n30757 49832 5314 41744 39918 39914 41744 52593 33046 42822\n", "output": "Conan\n" }, { "input": "3\n5 1 8\n", "output": "Conan\n" }, { "input": "3\n2 6 1\n", "output": "Conan\n" }, { "input": "4\n1 0 0 2\n", "output": "Conan\n" }, { "input": "3\n1 0 4\n", "output": "Conan\n" }, { "input": "4\n3 12 5 5\n", "output": "Conan\n" }, { "input": "1\n16\n", "output": "Conan\n" }, { "input": "10\n38282 53699 38282 69689 63357 38282 38282 8227 38282 50884\n", "output": "Conan\n" }, { "input": "5\n2 1 2 2 1\n", "output": "Conan\n" }, { "input": "10\n32093 51620 32093 32093 36846 36846 36846 36846 8485 76231\n", "output": "Conan\n" }, { "input": "3\n6 2 4\n", "output": "Conan\n" }, { "input": "10\n50165 50165 10543 50165 14278 50165 50855 50165 50165 66719\n", "output": "Conan\n" }, { "input": "3\n2 1 0\n", "output": "Conan\n" }, { "input": "3\n94 97 000\n", "output": "Conan\n" } ] }
[ 0.0000152958554783254, 0.00000923839766847746, 0.000009162181092792281, 0.000009052681049339573, 0.000008967419748696283, 0.00000894620226527086, 0.000008941841959333326, 0.000008863107985069616, 0.000008766879229594996, 0.00000874518427244145, 0.00000872996885298179, 0.000008617621794247581, 0.000008582254428427298, 0.00000857061787088583, 0.000008350767406791221, 0.000008324202383648126, 0.000008254252941240504, 0.00000823970851611721, 0.000008233534847440477, 0.000008224817790284883, 0.000008202453941172328, 0.00000819151611538531, 0.000008169538777402146, 0.000008168410560403446, 0.000008160211518969091, 0.000008155124154716038, 0.000008150450968168978, 0.00000814033285693754, 0.000008136869232578458, 0.000008134659554446959, 0.000008124927451629683, 0.000008121674491308203, 0.000008098126156024528, 0.000008080294372814889, 0.000008066366039161733, 0.000008065695629912722, 0.000008065063775784892, 0.000008063697813688532, 0.000008063101873128506, 0.000008055853515840085, 0.00000805178235247098, 0.000008050970204567758, 0.000008048625939179364, 0.00000802741648556912, 0.000008024010821938677, 0.000008020051878594957, 0.000008018688565380422, 0.000008018211172431336, 0.000008014827759622554, 0.000007995917721444877, 0.000007994247984291373, 0.000007976933082060388, 0.000007968523570297972, 0.000007961542624078476, 0.000007941408611988818, 0.000007941340249400885, 0.000007938332594811397, 0.000007925905561265512, 0.00000790601005322054, 0.0000022209875197485177, 0.000001983012606534091, 0.000001926982244318182 ]
489_C. Given Length and Sum of Digits...
2282
2282_16
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers. Output In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Examples Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n=input().split() n[0]=int(n[0]) n[1]=int(n[1]) if n[1]==0: if n[0]==1: print('0 0') if n[0]!=1: print('-1 -1') elif n[0]*9<n[1]: print('-1 -1') else: i=(n[1]-1)//9 q=(n[1]-1)%9 mi=10**(n[0]-1)+q*10**i while i>0: mi+=9*10**(i-1) i=i-1 ii=n[1]//9 qq=n[1]%9 if qq==0: ma=ii*'9'+(n[0]-ii)*'0' else: ma=ii*'9'+str(qq)+'0'*(n[0]-ii-1) print(mi,ma)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: n: int k: int @classmethod def from_str(cls, input_: str): n, k = input_.split('\n')[0].split(' ') n = int(n) k = int(k) return cls(n, k) def __repr__(self): return str(self.n) + ' ' + str(self.k) + '\n'
2 15
O(n**2)
0.000006
{ "public_tests": [ { "input": "2 15\n", "output": "69 96" }, { "input": "3 0\n", "output": "-1 -1" } ], "private_tests": [ { "input": "1 10\n", "output": "-1 -1" }, { "input": "97 206\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 27\n", "output": "999 999" }, { "input": "100 301\n", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 9\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "96 364\n", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000" }, { "input": "1 0\n", "output": "0 0" }, { "input": "100 897\n", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996" }, { "input": "100 898\n", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997" }, { "input": "98 250\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 2\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 100\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 1\n", "output": "100 100" }, { "input": "1 9\n", "output": "9 9" }, { "input": "100 11\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2 19\n", "output": "-1 -1" }, { "input": "3 10\n", "output": "109 910" }, { "input": "99 891\n", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 296\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 100\n", "output": "-1 -1" }, { "input": "3 3\n", "output": "102 300" }, { "input": "3 26\n", "output": "899 998" }, { "input": "99 900\n", "output": "-1 -1" }, { "input": "100 215\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 298\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 1\n", "output": "1 1" }, { "input": "5 18\n", "output": "10089 99000" }, { "input": "100 297\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 2\n", "output": "2 2" }, { "input": "2 18\n", "output": "99 99" }, { "input": "3 28\n", "output": "-1 -1" }, { "input": "2 10\n", "output": "19 91" }, { "input": "2 900\n", "output": "-1 -1" }, { "input": "3 21\n", "output": "399 993" }, { "input": "2 11\n", "output": "29 92" }, { "input": "1 8\n", "output": "8 8" }, { "input": "100 896\n", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995" }, { "input": "2 0\n", "output": "-1 -1" }, { "input": "99 96\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 895\n", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994" }, { "input": "2 20\n", "output": "-1 -1" }, { "input": "100 300\n", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 899\n", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998" }, { "input": "3 20\n", "output": "299 992" }, { "input": "1 900\n", "output": "-1 -1" }, { "input": "2 8\n", "output": "17 80" }, { "input": "2 2\n", "output": "11 20" }, { "input": "100 900\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "2 1\n", "output": "10 10" }, { "input": "100 0\n", "output": "-1 -1" }, { "input": "1 11\n", "output": "-1 -1" }, { "input": "100 10\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 9\n", "output": "108 900" }, { "input": "2 16\n", "output": "79 97" }, { "input": "99 892\n", "output": "-1 -1" }, { "input": "3 2\n", "output": "101 200" }, { "input": "100 1\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 299\n", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2 17\n", "output": "89 98\n" } ], "generated_tests": [ { "input": "3 13\n", "output": "139 940\n" }, { "input": "97 29\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001999 9992000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 8\n", "output": "107 800\n" }, { "input": "100 110\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000001999999999999 9999999999992000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "4 1\n", "output": "1000 1000\n" }, { "input": "4 10\n", "output": "1009 9100\n" }, { "input": "99 1058\n", "output": "-1 -1\n" }, { "input": "99 752\n", "output": "100000000000000499999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999995000000000000000\n" }, { "input": "100 14\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049 9500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "101 298\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 99999999999999999999999999999999910000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "10 18\n", "output": "1000000089 9900000000\n" }, { "input": "3 22\n", "output": "499 994\n" }, { "input": "1 3\n", "output": "3 3\n" }, { "input": "2 13\n", "output": "49 94\n" }, { "input": "100 338\n", "output": "1000000000000000000000000000000000000000000000000000000000000049999999999999999999999999999999999999 9999999999999999999999999999999999999500000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "5 1\n", "output": "10000 10000\n" }, { "input": "5 9\n", "output": "10008 90000\n" }, { "input": "3 16\n", "output": "169 970\n" }, { "input": "99 394\n", "output": "100000000000000000000000000000000000000000000000000000069999999999999999999999999999999999999999999 999999999999999999999999999999999999999999970000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 6\n", "output": "105 600\n" }, { "input": "101 299\n", "output": "10000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 99999999999999999999999999999999920000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "5 6\n", "output": "10005 60000\n" }, { "input": "7 1\n", "output": "1000000 1000000\n" }, { "input": "4 7\n", "output": "1006 7000\n" }, { "input": "101 173\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000019999999999999999999 99999999999999999992000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "1 6\n", "output": "6 6\n" }, { "input": "100 451\n", "output": "1000000000000000000000000000000000000000000000000099999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999910000000000000000000000000000000000000000000000000\n" }, { "input": "5 2\n", "output": "10001 20000\n" }, { "input": "5 3\n", "output": "10002 30000\n" }, { "input": "4 16\n", "output": "1069 9700\n" }, { "input": "99 242\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999 999999999999999999999999998000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 14\n", "output": "149 950\n" }, { "input": "5 11\n", "output": "10019 92000\n" }, { "input": "7 2\n", "output": "1000001 2000000\n" }, { "input": "4 17\n", "output": "1079 9800\n" }, { "input": "99 238\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000399999999999999999999999999 999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "2 4\n", "output": "13 40\n" }, { "input": "4 21\n", "output": "1299 9930\n" }, { "input": "4 2\n", "output": "1001 2000\n" }, { "input": "4 3\n", "output": "1002 3000\n" }, { "input": "6 16\n", "output": "100069 970000\n" }, { "input": "31 242\n", "output": "1000799999999999999999999999999 9999999999999999999999999980000\n" }, { "input": "3 12\n", "output": "129 930\n" }, { "input": "6 11\n", "output": "100019 920000\n" }, { "input": "14 2\n", "output": "10000000000001 20000000000000\n" }, { "input": "5 17\n", "output": "10079 98000\n" }, { "input": "99 349\n", "output": "100000000000000000000000000000000000000000000000000000000000699999999999999999999999999999999999999 999999999999999999999999999999999999997000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "7 21\n", "output": "1000299 9930000\n" }, { "input": "5 4\n", "output": "10003 40000\n" }, { "input": "7 3\n", "output": "1000002 3000000\n" }, { "input": "9 16\n", "output": "100000069 970000000\n" }, { "input": "6 12\n", "output": "100029 930000\n" }, { "input": "7 11\n", "output": "1000019 9200000\n" }, { "input": "14 4\n", "output": "10000000000003 40000000000000\n" }, { "input": "5 28\n", "output": "10999 99910\n" }, { "input": "101 125\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000079999999999999 99999999999998000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "4 13\n", "output": "1039 9400\n" }, { "input": "7 36\n", "output": "1008999 9999000\n" }, { "input": "4 4\n", "output": "1003 4000\n" }, { "input": "3 000\n", "output": "-1 -1\n" }, { "input": "3 34\n", "output": "-1 -1\n" }, { "input": "2 26\n", "output": "-1 -1\n" }, { "input": "4 900\n", "output": "-1 -1\n" }, { "input": "100 1058\n", "output": "-1 -1\n" }, { "input": "100 996\n", "output": "-1 -1\n" }, { "input": "2 34\n", "output": "-1 -1\n" }, { "input": "2 22\n", "output": "-1 -1\n" }, { "input": "2 40\n", "output": "-1 -1\n" }, { "input": "100 000\n", "output": "-1 -1\n" }, { "input": "4 100\n", "output": "-1 -1\n" }, { "input": "99 970\n", "output": "-1 -1\n" }, { "input": "1 18\n", "output": "-1 -1\n" }, { "input": "4 1233\n", "output": "-1 -1\n" }, { "input": "2 21\n", "output": "-1 -1\n" }, { "input": "001 299\n", "output": "-1 -1\n" }, { "input": "2 52\n", "output": "-1 -1\n" }, { "input": "2 51\n", "output": "-1 -1\n" }, { "input": "4 110\n", "output": "-1 -1\n" }, { "input": "001 173\n", "output": "-1 -1\n" }, { "input": "4 233\n", "output": "-1 -1\n" }, { "input": "1 14\n", "output": "-1 -1\n" }, { "input": "1 52\n", "output": "-1 -1\n" }, { "input": "4 51\n", "output": "-1 -1\n" }, { "input": "5 110\n", "output": "-1 -1\n" }, { "input": "001 125\n", "output": "-1 -1\n" }, { "input": "4 123\n", "output": "-1 -1\n" }, { "input": "26 242\n", "output": "-1 -1\n" }, { "input": "3 52\n", "output": "-1 -1\n" }, { "input": "4 64\n", "output": "-1 -1\n" }, { "input": "1 110\n", "output": "-1 -1\n" }, { "input": "7 0\n", "output": "-1 -1\n" } ] }
[ 0.22671272950000004, 0.04386649527816902, 0.031079423147887326, 0.013905163000000002, 0.000605042440687354, 0.000489570832756595, 0.0003253772680745001, 0.00032084736042256514, 0.00027027742899125883, 0.00026493050643302006, 0.0002468118853728903, 0.0002149377644159226, 0.00020590882505580358, 0.00020567884951636905, 0.00020360534714471728, 0.00020291860365513395, 0.00020251967299107147, 0.00020244896826171875, 0.00020229604496837796, 0.00020194191350446426, 0.0002017090001395089, 0.00020126336951264878, 0.0002011856906156994, 0.0002010176044921875, 0.00020084345735677086, 0.00020083104706101194, 0.0002007747063802083, 0.00020044472251674105, 0.00020032266234188992, 0.00020031360453869052, 0.00020027038520740328, 0.00020022653817894343, 0.00020015039815848216, 0.0001999676484375, 0.00019990933909970235, 0.0001998512406994048, 0.00019983286351376488, 0.00019953359105282742, 0.000198046869187128, 0.00019796530333891367, 0.00019783920619419643, 0.00019782285249255954, 0.00019717693698846725, 0.00019708517978050594, 0.00019693642550223212, 0.00016334286617679196, 0.00014732370870535713, 0.000059763314125327804, 0.000057443847970389, 0.00003452357157919775, 0.000029863893834680945, 0.000026130662992931546, 0.00002567831682477679, 0.000025559466192336305, 0.000024967081240699403, 0.000024920434430803575, 0.00002490009361049107, 0.00002488725316220238, 0.000024715592494419642, 0.000024670940011160713, 0.000024593128255208337, 0.000024569806454613096, 0.000024445391462053573, 0.000024285387648809525, 0.000024201770833333335, 0.000024117613002232145, 0.000024073683872767858, 0.000024036617699032736, 0.000024035200799851193, 0.000023958868954613092, 0.000023902884951636906, 0.000023901338634672617, 0.00002386063355654762, 0.00002377831761532738, 0.000023743227167038692, 0.0000237229404296875, 0.000023398310918898807, 0.000023396297526041667, 0.000023252666062127975, 0.00002265051469494047, 0.000011504788271949404, 0.00001102430750109266, 0.000008925333984375, 0.000007063445614769345, 0.000006104917689732142, 0.000005620578746448863, 0.000005082281433170235, 0.000003012432883522727, 0.0000024199276515151514, 0.000002252910000298868, 0.0000021565520711190527, 0.0000017254783786757417, 0.0000013945982128519248, 9.310361702872507e-7, 7.780843600227032e-7, 7.506912165420822e-7, 5.002456006972491e-7, 4.913946411834675e-7, 4.6978292741541385e-7, 4.0774422429413483e-7, 3.437539884947914e-7, 3.2888901176245384e-7, 2.6453924563886504e-7, 2.0150146842510636e-7, 1.9227794944177382e-7, 1.7672212846206722e-7, 1.7327431527175787e-7, 1.723178511973539e-7, 1.6836530488850615e-7, 1.6592489769345237e-7, 1.6431421391800941e-7, 1.437498835964276e-7, 1.4092783974227933e-7, 1.3523122059462187e-7, 1.2671877103962476e-7, 9.801886341515207e-8, 9.676861877759226e-8, 9.426486048085964e-8, 8.352707043424587e-8, 8.333950287329441e-8, 7.738820066652098e-8, 4.579937448804655e-8, 4.0879557656355204e-8, 3.486247592403211e-8, 3.045680324339925e-8, 3.039803062229763e-8, 2.9973680089727244e-8, 2.941279634242185e-8, 2.863310945001579e-8, 2.8424546045961e-8, 2.718834185781749e-8, 2.694719833310786e-8, 2.5943206207844457e-8, 2.5546913255727508e-8, 2.539386265883715e-8, 2.4677596594107293e-8, 2.4614330873933794e-8, 2.3833631985157487e-8, 2.1899802809836644e-8, 2.0985672290761587e-8, 2.0804779189159132e-8, 2.0382230489313577e-8, 1.8989054499867186e-8, 1.7524474373435417e-8, 1.47803124946833e-8, 1.4497582270516012e-8, 1.2820591933075733e-8, 1.272697259261437e-8, 1.2718504345497351e-8, 1.2274462810535157e-8, 1.2223223067396333e-8, 1.2116060629743579e-8, 1.2021597426772113e-8, 1.1665301306842156e-8, 8.864987462642134e-9, 8.585757465938334e-9, 3.833525127940378e-9, 3.392137749117853e-9, 1.2553544078918405e-9, 1.1268939215097185e-9, 5.691290177581303e-10, 2.623961398743233e-10, 1.56746128055871e-10, 1.526663149565968e-10, 1.5056901747149892e-10, 1.4749106016062616e-10, 1.4265997028012104e-10, 1.3670881206566066e-10, 1.35517617808196e-10, 1.352150594344533e-10, 1.3481973230894051e-10, 1.3442504600469623e-10, 1.340876325638737e-10, 1.3389078124086038e-10, 1.3379556452899246e-10, 1.3294447125798381e-10, 1.3226307630892457e-10, 1.3218540646718174e-10, 1.315984168692674e-10, 1.2801706403747544e-10, 1.2729561737238887e-10, 1.2708440799941394e-10, 1.2645206034856992e-10, 1.2630319060568608e-10, 1.2387436760172533e-10, 1.2350245026357101e-10, 1.2265699423007494e-10, 1.225484063054599e-10, 1.2243484689177254e-10, 1.2158636271353522e-10, 1.2048288381411198e-10, 1.2008441934271167e-10, 1.1991505114162103e-10, 1.1974227019339133e-10, 1.197357493421917e-10, 1.197063867928904e-10, 1.1967152843177646e-10, 1.1960533402501598e-10, 6.283483087975345e-11 ]
489_C. Given Length and Sum of Digits...
2282
2282_437
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers. Output In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Examples Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(a) for a in input().split()] maxx="" minn="" s1 = s s2 = s-1 if s==0 and m==1: print(0, 0) elif s>9*m or s<1: print (-1, -1) elif m==1: print(s, s) else: for a in range(m): if s1>9: maxx+=str(9) s1-=9 elif s1==0: maxx+=str(0) else: maxx+=str(s1) s1=0 for a in range(m-1): if s2>9: minn=str(9)+minn s2-=9 elif s2==0: minn=str(0)+minn else: minn=str(s2)+minn s2=0 minn=str(s2+1)+minn print(minn, maxx)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: n: int k: int @classmethod def from_str(cls, input_: str): n, k = input_.split('\n')[0].split(' ') n = int(n) k = int(k) return cls(n, k) def __repr__(self): return str(self.n) + ' ' + str(self.k) + '\n'
2 15
O(n)
0.000005
{ "public_tests": [ { "input": "2 15\n", "output": "69 96" }, { "input": "3 0\n", "output": "-1 -1" } ], "private_tests": [ { "input": "1 10\n", "output": "-1 -1" }, { "input": "97 206\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 27\n", "output": "999 999" }, { "input": "100 301\n", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 9\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "96 364\n", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000" }, { "input": "1 0\n", "output": "0 0" }, { "input": "100 897\n", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996" }, { "input": "100 898\n", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997" }, { "input": "98 250\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 2\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 100\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 1\n", "output": "100 100" }, { "input": "1 9\n", "output": "9 9" }, { "input": "100 11\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2 19\n", "output": "-1 -1" }, { "input": "3 10\n", "output": "109 910" }, { "input": "99 891\n", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 296\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 100\n", "output": "-1 -1" }, { "input": "3 3\n", "output": "102 300" }, { "input": "3 26\n", "output": "899 998" }, { "input": "99 900\n", "output": "-1 -1" }, { "input": "100 215\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 298\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 1\n", "output": "1 1" }, { "input": "5 18\n", "output": "10089 99000" }, { "input": "100 297\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 2\n", "output": "2 2" }, { "input": "2 18\n", "output": "99 99" }, { "input": "3 28\n", "output": "-1 -1" }, { "input": "2 10\n", "output": "19 91" }, { "input": "2 900\n", "output": "-1 -1" }, { "input": "3 21\n", "output": "399 993" }, { "input": "2 11\n", "output": "29 92" }, { "input": "1 8\n", "output": "8 8" }, { "input": "100 896\n", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995" }, { "input": "2 0\n", "output": "-1 -1" }, { "input": "99 96\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 895\n", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994" }, { "input": "2 20\n", "output": "-1 -1" }, { "input": "100 300\n", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 899\n", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998" }, { "input": "3 20\n", "output": "299 992" }, { "input": "1 900\n", "output": "-1 -1" }, { "input": "2 8\n", "output": "17 80" }, { "input": "2 2\n", "output": "11 20" }, { "input": "100 900\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "2 1\n", "output": "10 10" }, { "input": "100 0\n", "output": "-1 -1" }, { "input": "1 11\n", "output": "-1 -1" }, { "input": "100 10\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 9\n", "output": "108 900" }, { "input": "2 16\n", "output": "79 97" }, { "input": "99 892\n", "output": "-1 -1" }, { "input": "3 2\n", "output": "101 200" }, { "input": "100 1\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 299\n", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2 17\n", "output": "89 98\n" } ], "generated_tests": [ { "input": "3 13\n", "output": "139 940\n" }, { "input": "97 29\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001999 9992000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 8\n", "output": "107 800\n" }, { "input": "100 110\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000001999999999999 9999999999992000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "4 1\n", "output": "1000 1000\n" }, { "input": "4 10\n", "output": "1009 9100\n" }, { "input": "99 1058\n", "output": "-1 -1\n" }, { "input": "99 752\n", "output": "100000000000000499999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999995000000000000000\n" }, { "input": "100 14\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049 9500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "101 298\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 99999999999999999999999999999999910000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "10 18\n", "output": "1000000089 9900000000\n" }, { "input": "3 22\n", "output": "499 994\n" }, { "input": "1 3\n", "output": "3 3\n" }, { "input": "2 13\n", "output": "49 94\n" }, { "input": "100 338\n", "output": "1000000000000000000000000000000000000000000000000000000000000049999999999999999999999999999999999999 9999999999999999999999999999999999999500000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "5 1\n", "output": "10000 10000\n" }, { "input": "5 9\n", "output": "10008 90000\n" }, { "input": "3 16\n", "output": "169 970\n" }, { "input": "99 394\n", "output": "100000000000000000000000000000000000000000000000000000069999999999999999999999999999999999999999999 999999999999999999999999999999999999999999970000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 6\n", "output": "105 600\n" }, { "input": "101 299\n", "output": "10000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 99999999999999999999999999999999920000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "5 6\n", "output": "10005 60000\n" }, { "input": "7 1\n", "output": "1000000 1000000\n" }, { "input": "4 7\n", "output": "1006 7000\n" }, { "input": "101 173\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000019999999999999999999 99999999999999999992000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "1 6\n", "output": "6 6\n" }, { "input": "100 451\n", "output": "1000000000000000000000000000000000000000000000000099999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999910000000000000000000000000000000000000000000000000\n" }, { "input": "5 2\n", "output": "10001 20000\n" }, { "input": "5 3\n", "output": "10002 30000\n" }, { "input": "4 16\n", "output": "1069 9700\n" }, { "input": "99 242\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999 999999999999999999999999998000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 14\n", "output": "149 950\n" }, { "input": "5 11\n", "output": "10019 92000\n" }, { "input": "7 2\n", "output": "1000001 2000000\n" }, { "input": "4 17\n", "output": "1079 9800\n" }, { "input": "99 238\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000399999999999999999999999999 999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "2 4\n", "output": "13 40\n" }, { "input": "4 21\n", "output": "1299 9930\n" }, { "input": "4 2\n", "output": "1001 2000\n" }, { "input": "4 3\n", "output": "1002 3000\n" }, { "input": "6 16\n", "output": "100069 970000\n" }, { "input": "31 242\n", "output": "1000799999999999999999999999999 9999999999999999999999999980000\n" }, { "input": "3 12\n", "output": "129 930\n" }, { "input": "6 11\n", "output": "100019 920000\n" }, { "input": "14 2\n", "output": "10000000000001 20000000000000\n" }, { "input": "5 17\n", "output": "10079 98000\n" }, { "input": "99 349\n", "output": "100000000000000000000000000000000000000000000000000000000000699999999999999999999999999999999999999 999999999999999999999999999999999999997000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "7 21\n", "output": "1000299 9930000\n" }, { "input": "5 4\n", "output": "10003 40000\n" }, { "input": "7 3\n", "output": "1000002 3000000\n" }, { "input": "9 16\n", "output": "100000069 970000000\n" }, { "input": "6 12\n", "output": "100029 930000\n" }, { "input": "7 11\n", "output": "1000019 9200000\n" }, { "input": "14 4\n", "output": "10000000000003 40000000000000\n" }, { "input": "5 28\n", "output": "10999 99910\n" }, { "input": "101 125\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000079999999999999 99999999999998000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "4 13\n", "output": "1039 9400\n" }, { "input": "7 36\n", "output": "1008999 9999000\n" }, { "input": "4 4\n", "output": "1003 4000\n" }, { "input": "3 000\n", "output": "-1 -1\n" }, { "input": "3 34\n", "output": "-1 -1\n" }, { "input": "2 26\n", "output": "-1 -1\n" }, { "input": "4 900\n", "output": "-1 -1\n" }, { "input": "100 1058\n", "output": "-1 -1\n" }, { "input": "100 996\n", "output": "-1 -1\n" }, { "input": "2 34\n", "output": "-1 -1\n" }, { "input": "2 22\n", "output": "-1 -1\n" }, { "input": "2 40\n", "output": "-1 -1\n" }, { "input": "100 000\n", "output": "-1 -1\n" }, { "input": "4 100\n", "output": "-1 -1\n" }, { "input": "99 970\n", "output": "-1 -1\n" }, { "input": "1 18\n", "output": "-1 -1\n" }, { "input": "4 1233\n", "output": "-1 -1\n" }, { "input": "2 21\n", "output": "-1 -1\n" }, { "input": "001 299\n", "output": "-1 -1\n" }, { "input": "2 52\n", "output": "-1 -1\n" }, { "input": "2 51\n", "output": "-1 -1\n" }, { "input": "4 110\n", "output": "-1 -1\n" }, { "input": "001 173\n", "output": "-1 -1\n" }, { "input": "4 233\n", "output": "-1 -1\n" }, { "input": "1 14\n", "output": "-1 -1\n" }, { "input": "1 52\n", "output": "-1 -1\n" }, { "input": "4 51\n", "output": "-1 -1\n" }, { "input": "5 110\n", "output": "-1 -1\n" }, { "input": "001 125\n", "output": "-1 -1\n" }, { "input": "4 123\n", "output": "-1 -1\n" }, { "input": "26 242\n", "output": "-1 -1\n" }, { "input": "3 52\n", "output": "-1 -1\n" }, { "input": "4 64\n", "output": "-1 -1\n" }, { "input": "1 110\n", "output": "-1 -1\n" }, { "input": "7 0\n", "output": "-1 -1\n" } ] }
[ 0.006108613626013212, 0.006097529471161506, 0.000058815127567744744, 0.000043647584821428566, 0.00003068576613035402, 0.00003061692825338724, 0.00002980220354840472, 0.000029785456198098778, 0.000027370512633850527, 0.000026596474172312062, 0.00002651186227054196, 0.000026366053757440476, 0.000026341517263986012, 0.00002623831932910839, 0.00002582382427338287, 0.000023624951062609268, 0.00002313224644886363, 0.000022850832099541085, 0.000022793067307692308, 0.00002248769906850962, 0.000022211972758686625, 0.00002200690017209353, 0.000021805282943618885, 0.000019175082700502623, 0.000019013683175223213, 0.000018851836490657783, 0.00001837115504807692, 0.00001741238794798951, 0.00001708397951267483, 0.00001692118651660839, 0.0000168235017892264, 0.000016049157319568453, 0.000015787890092329547, 0.000015503269112723212, 0.00001541356114783654, 0.000015342604990712414, 0.000015083595259232955, 0.000014656235909598215, 0.000014490196637347027, 0.000013905704938616071, 0.000013558682016225962, 0.0000131663759765625, 0.000013049560232736016, 0.000012831643275669644, 0.000012352184331293706, 0.000011958797680834791, 0.000011940632102272728, 0.000011329685205419581, 0.000010770205747377625, 0.000010633145569274477, 0.000010433590116914337, 0.000010251083957058567, 0.000010143701240166084, 0.000010143311448317309, 0.000010138521620957169, 0.000010137229817708334, 0.000009747080242023602, 0.000009645192243303572, 0.000009641810369318183, 0.000009513418515078672, 0.000009395359840029761, 0.000009373492466517857, 0.000009332806667941433, 0.000009252369031359269, 0.000009091846522618008, 0.00000902605417596726, 0.000009020448768028846, 0.000008953860085227272, 0.000008919919566761364, 0.000008915044539444932, 0.000008861578862543708, 0.000008823491231424826, 0.000008746647740930946, 0.000008716919197989511, 0.000008562064603365384, 0.000008552601985904722, 0.000008530742843094406, 0.000008483468982189687, 0.000008147665605878497, 0.000008103086429195805, 0.000008067335459462413, 0.00000799108768575175, 0.000007897660128933566, 0.000007773207673186189, 0.000007733902999344405, 0.00000770282124125874, 0.000007687341919798951, 0.000007674334680944055, 0.000007659904870520106, 0.000007626266321569056, 0.000007587598462084792, 0.0000075660136253720235, 0.000007531217643684441, 0.000007527271183894231, 0.000007474698938756557, 0.000007433797708151224, 0.000007413249153190561, 0.00000728831254097465, 0.000007278370124016609, 0.000007189884440104166, 0.000007066271757539337, 0.0000070555392127403856, 0.0000070486048268138116, 0.000007035895446350524, 0.000007029870793269231, 0.000007022710254589161, 0.000006998142209353148, 0.000006967435355659966, 0.000006952307989211309, 0.000006947313196569057, 0.000006944447893902973, 0.00000692651167777535, 0.000006922517263986016, 0.000006885579736669581, 0.000006884112420782343, 0.000006823046164772727, 0.0000068095704627403845, 0.0000067700224144345234, 0.000006766541439029721, 0.000006766256514969407, 0.000006763143383959791, 0.0000067480545509178325, 0.000006722106056053323, 0.000006677155293924826, 0.00000667247228422619, 0.000006657104403409092, 0.000006628071678321679, 0.000006609206034200175, 0.000006504532076322115, 0.000006494027760325612, 0.000006477222096263113, 0.0000064736710077032355, 0.000006436370356206294, 0.000006412411624508306, 0.000006397462986232518, 0.000006388781529017857, 0.000006384788188374126, 0.000006384046670126749, 0.000006349632996885927, 0.000006334427804129464, 0.0000062959433128720235, 0.000006269309706894669, 0.000006250459148273602, 0.000006204399134069057, 0.0000061800956484921336, 0.000006178536385489512, 0.000006170921601835665, 0.000006168821678321678, 0.0000061474333752185305, 0.0000061087957686844405, 0.000006100040284910401, 0.000006058183825939685, 0.00000603136748798077, 0.000006028597929414336, 0.000005973719508031032, 0.000005947889122596155, 0.000005923573317307692, 0.000005878248197115385, 0.000005842376256555945, 0.000005820899823809005, 0.000005785524789663461, 0.00000578079445749563, 0.0000057480649181547615, 0.000005747711237980769, 0.000005730472396743882, 0.000005713234771088287, 0.000005680461115056819, 0.000005662615384615385, 0.000005661571364182692, 0.000005658512251420455, 0.000005651724049388113, 0.000005636190709680944, 0.000005622682214270105, 0.000005615839461319931, 0.00000559542930506993, 0.00000553089025297619, 0.000005526517223011364, 0.000005506623880026225, 0.0000054920047433035716, 0.000005433056326486014, 0.0000054237428840690565, 0.000005415543037041085, 0.000005407690409200174, 0.000005397594999726836, 0.000005379584817526224, 0.000005369908681162588, 0.000005335055971372377, 0.000005310528771033654, 0.000005289333424388113, 0.000005263697456840035, 0.0000051746368143575185, 0.000005109489892919581, 0.000005046724562872024, 0.000005020519449300699, 0.000004992829094733391, 0.000004984426641717658, 0.0000049742736423732525, 0.000004964094912574405, 0.000004959403586647727, 0.000004958312267810315, 0.000004926204873251748, 0.000004887632484702798, 0.0000048804889778190566, 0.000004869804284582606, 0.000004848924688592658, 0.0000048451376679960675, 0.000004838558730332168, 0.000004814512788318452, 0.000004811322060751749, 0.000004800853440504808, 0.000004799438046328672, 0.0000047876104539991264, 0.000004747714481807255, 0.000004688348134287588, 0.000004680188087303322, 0.000004672740439248253, 0.000004661888569438375, 0.0000046544975353422624, 0.000004624543294270834, 0.000004620843353911713, 0.000004612856779938811, 0.0000046072302638767484, 0.0000046060724022071685, 0.0000046042696610030596, 0.000004598436616443452, 0.000004593446514423077, 0.000004574700009300595, 0.000004553870991313374, 0.000004541060806381119, 0.000004530480414117133, 0.000004526205543154761, 0.0000045177527436755956, 0.000004479920522836539, 0.000004479078015734265, 0.000004478774803321679, 0.000004454218149038462, 0.000004439574451264882, 0.000004416774011145106, 0.000004414406270487325, 0.00000440015514368444, 0.000004398777944711539, 0.000004332914035183566, 0.000004312475155703671, 0.0000043107844733391615, 0.000004303440708705357, 0.000004292616531905594, 0.000004271333765843532, 0.0000042524090362762245, 0.0000042466981807255245, 0.0000042165734281994044, 0.000004194833779501748, 0.000004184501734593532, 0.000004176582682291666, 0.0000041345315231643355, 0.000004124770951704546, 0.0000041224230359484265, 0.0000041174547913024475, 0.0000040887977901005246, 0.000004058724868881119, 0.0000040560300139313815, 0.000004045802898273602, 0.000004039582682291667, 0.000004032163543487763, 0.000004026086681547619, 0.000004024363855421687, 0.0000040036240439248255, 0.000003995288038133742, 0.000003991505381337412, 0.00000397655243389423, 0.000003971161522071679, 0.000003961945626638987, 0.000003959972369427449, 0.000003954371421547203, 0.000003918446591331845, 0.000003911167203889861, 0.000003895774735030594, 0.000003892450967001748, 0.000003857216086647727, 0.000003849714051573426, 0.000003843021115603147, 0.000003835098516717658, 0.000003831141881555944, 0.00000382901053048514, 0.000003815675013950893, 0.0000037621923145214166, 0.000003736369140625001, 0.0000037289664827360144, 0.0000037221706194196434, 0.000003707548951048951, 0.000003698842425152972, 0.000003693384765625001, 0.000003682546881829109, 0.0000036808657260708045, 0.0000036408969897290206, 0.000003640498156140734, 0.0000036389166302447552, 0.000003632028839324738, 0.000003630176368553322, 0.0000036239000186011905, 0.000003615512388002622, 0.0000035597344159746507, 0.000003556123744419643, 0.0000035195114455856647, 0.0000034999185697115387, 0.0000034938810642482523, 0.0000034920458642919584, 0.000003469822456840035, 0.0000034553876065340912, 0.0000034550410839160844, 0.0000034525658872377624, 0.000003451530649038462, 0.000003421567854020979, 0.0000034182763740166086, 0.000003406797202797203, 0.000003385989619755245, 0.0000033665336128715044, 0.0000033647418187281472, 0.0000033594664144449304, 0.0000033585508290537592, 0.000003336260598776224, 0.000003331895596590909, 0.0000032615866340690563, 0.000003251765276715472, 0.000003246846365548514, 0.0000032434598214285718, 0.000003224066392591783, 0.0000032073675426136366, 0.0000031652926432291666, 0.0000031347098721590915, 0.0000031320780840253497, 0.000003106785807291667, 0.000003102499863417832, 0.0000031006844773065477, 0.000003052842889532343, 0.0000030421623688811194, 0.0000030346207932692308, 0.0000030122046956949307, 0.000003002193441324301, 0.000003001385161713287, 0.0000029973807091346152, 0.000002997035934768357, 0.0000029309809337797626, 0.000002907948221700175, 0.000002889233336975525, 0.00000288513234812063, 0.000002878285923549107, 0.0000028765392332277102, 0.0000028712730414117138, 0.000002828159992351399, 0.000002811427911931819, 0.000002782954203999126, 0.0000027749039497727593, 0.0000027457663830310316, 0.000002740027480332168, 0.0000027202473912805948, 0.0000027049133044689684, 0.000002701940122377623, 0.000002700813947770979, 0.000002684525213068182, 0.000002629548688616071, 0.0000026248480659965034, 0.000002564186625874126, 0.0000025346218995847905, 0.0000025279002950174826, 0.0000025184105113636368, 0.0000025079972683566434, 0.000002507892031796329, 0.0000025049595853365385, 0.0000024777316979895104, 0.0000024723300781250005, 0.0000024659744249890733, 0.0000024345239155375874, 0.000002402000465029762, 0.0000023642744618662584, 0.0000022812549579326926, 0.0000022667554086538464, 0.000002250992214816434, 0.0000022392609538898602, 0.0000022336955446896854, 0.0000022077608173076927, 0.000002166398587740385, 0.000002157806135270979, 0.000002134034596263112, 0.0000021169619140625, 0.0000020864802092438815, 0.000002085685724431818, 0.0000020667783954326927, 0.0000020448886172421326, 0.0000020434071787587414, 0.0000020322325821112307, 0.0000020223604403409087, 0.000002012903135926574, 0.0000020116210239955357, 0.0000019977626342128813, 0.0000019899021525349652, 0.0000019037199928977276, 0.0000018885394312718533, 0.0000018644005135489512, 0.0000017995196951486014, 0.0000017915294539444933, 0.00000176356598284528, 0.000001624745533763112, 0.0000016231024229676575, 0.0000016184826130900351, 0.0000016024447079613093, 0.0000015872117979676576, 0.0000015791560109812063, 0.0000015743768028846154, 0.0000015717569247159092, 0.0000015389264641608391, 0.0000014980993362106643, 0.000001479155184659091, 0.0000014691595416302447, 0.000001466569370083042, 0.0000014658296888658215, 0.0000014338085118006994, 0.0000014101324027534964, 0.0000014090197361232518, 0.0000013365000877725627, 0.0000013267394900021854, 0.000001293466240530303, 0.0000012435995820585664, 0.0000011739107708697552, 0.000001099340103256119, 0.0000010888856943837411, 0.0000010756951076267485, 9.52461948208042e-7, 8.394368771385569e-7, 7.840534446022729e-7, 7.615822637648811e-7, 7.405735221809441e-7, 7.274554036458332e-7, 6.928206539554196e-7, 6.887538789335664e-7, 6.829586292613637e-7, 6.820978884396853e-7, 6.596765870847903e-7, 4.781141826923077e-7, 4.779008959790211e-7, 4.2162728092220286e-7, 4.078062308784965e-7, 3.67813633631993e-7, 6.188024475524476e-8, 4.762170836975525e-8, 4.11830201048951e-8, 3.8889163570804195e-8, 3.769564029720279e-8, 3.628997760052448e-8, 3.2216141280594405e-8, 2.1936598557692313e-8, 1.8125785347465032e-8, 1.2928895323426575e-8, 1.0645268793706292e-8, 1.0008112980769231e-8, 9.905758304195804e-9, 9.570046164772729e-9, 9.515604512674826e-9, 9.484388658216783e-9, 9.290988308566433e-9, 9.219316815996505e-9, 9.17556271853147e-9, 8.915776606206293e-9, 8.881781304632871e-9, 8.715342274912587e-9, 8.679455310314687e-9, 8.634745137674825e-9, 8.5597342111014e-9, 8.313913625437063e-9, 8.262347027972029e-9, 8.228044416520977e-9, 8.142175207604897e-9, 8.137661166958043e-9, 8.11520022945804e-9, 8.086982353583917e-9, 7.958082932692308e-9, 7.889887456293704e-9, 7.833513166520976e-9, 7.813169252622378e-9, 7.529433457167835e-9, 7.525656960227274e-9, 7.2967179305069936e-9, 7.254527698863636e-9, 7.240507539335666e-9, 7.1572197333916085e-9, 7.113964160839161e-9, 6.9292367788461534e-9, 6.842452469405595e-9, 6.810642482517482e-9, 6.66057965472028e-9, 6.62767701048951e-9, 6.547312062937062e-9, 6.506501311188811e-9, 6.4317225743007e-9, 6.427590963723776e-9, 6.269715635926571e-9, 6.23330965909091e-9, 6.215799825174827e-9, 6.2074341673951045e-9, 6.166070257867135e-9, 6.161467438811189e-9, 6.161187445367134e-9, 6.065791630244755e-9, 5.953698645104896e-9, 5.9110098885489515e-9, 5.867849923513987e-9, 5.7809085445804206e-9, 5.763036767919579e-9, 5.707481971153847e-9, 5.588163789335664e-9, 5.575366040209789e-9, 5.514177229020979e-9, 5.477279556381118e-9, 5.475510817307691e-9, 5.294477982954544e-9, 5.28872787368881e-9, 5.2489961210664365e-9, 5.097861123251749e-9, 5.0460008741258744e-9, 5.03716088854611e-9, 5.036173787150351e-9, 4.938558511800699e-9, 4.934638603583916e-9, 4.801307091346154e-9, 4.785245028409089e-9, 4.7188319493007e-9, 4.675357845279722e-9, 4.411918159965034e-9, 3.4757088614510486e-9 ]
489_C. Given Length and Sum of Digits...
2282
2282_1118
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers. Output In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Examples Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m,s=map(int,input().split()) def ismax(m,s): op1=str() if s==0: return(-1) elif s>m*9: return(-1) else: for i in range(m): if s>9: op1=op1+'9' s-=9 elif 0<s<=9: op1=op1+str(s) s=0 else: op1=op1+'0' return(int(op1)) def ismin(m,s): op2=str() lis=[] if s==0: return(-1) elif s>m*9: return(-1) else: l=max(1,s-9*(m-1)) op2=op2+str(l) s=s-l for i in range(m-1): if s>9: lis.append(9) s-=9 elif 0<s<=9: lis.append(s) s=0 else: lis.append(0) lis=sorted(lis) if len(lis)==1: op2=op2+str(*lis) elif len(lis)>1: st="".join(map(str,lis)) op2=op2+st return(int(op2)) if m==1 and s==0: print(0, 0) else: print(ismin(m,s),ismax(m,s))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: n: int k: int @classmethod def from_str(cls, input_: str): n, k = input_.split('\n')[0].split(' ') n = int(n) k = int(k) return cls(n, k) def __repr__(self): return str(self.n) + ' ' + str(self.k) + '\n'
2 15
O(nlogn)
0.00004
{ "public_tests": [ { "input": "2 15\n", "output": "69 96" }, { "input": "3 0\n", "output": "-1 -1" } ], "private_tests": [ { "input": "1 10\n", "output": "-1 -1" }, { "input": "97 206\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 27\n", "output": "999 999" }, { "input": "100 301\n", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 9\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "96 364\n", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000" }, { "input": "1 0\n", "output": "0 0" }, { "input": "100 897\n", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996" }, { "input": "100 898\n", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997" }, { "input": "98 250\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 2\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 100\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 1\n", "output": "100 100" }, { "input": "1 9\n", "output": "9 9" }, { "input": "100 11\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2 19\n", "output": "-1 -1" }, { "input": "3 10\n", "output": "109 910" }, { "input": "99 891\n", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 296\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 100\n", "output": "-1 -1" }, { "input": "3 3\n", "output": "102 300" }, { "input": "3 26\n", "output": "899 998" }, { "input": "99 900\n", "output": "-1 -1" }, { "input": "100 215\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 298\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 1\n", "output": "1 1" }, { "input": "5 18\n", "output": "10089 99000" }, { "input": "100 297\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 2\n", "output": "2 2" }, { "input": "2 18\n", "output": "99 99" }, { "input": "3 28\n", "output": "-1 -1" }, { "input": "2 10\n", "output": "19 91" }, { "input": "2 900\n", "output": "-1 -1" }, { "input": "3 21\n", "output": "399 993" }, { "input": "2 11\n", "output": "29 92" }, { "input": "1 8\n", "output": "8 8" }, { "input": "100 896\n", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995" }, { "input": "2 0\n", "output": "-1 -1" }, { "input": "99 96\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 895\n", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994" }, { "input": "2 20\n", "output": "-1 -1" }, { "input": "100 300\n", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 899\n", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998" }, { "input": "3 20\n", "output": "299 992" }, { "input": "1 900\n", "output": "-1 -1" }, { "input": "2 8\n", "output": "17 80" }, { "input": "2 2\n", "output": "11 20" }, { "input": "100 900\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "2 1\n", "output": "10 10" }, { "input": "100 0\n", "output": "-1 -1" }, { "input": "1 11\n", "output": "-1 -1" }, { "input": "100 10\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "3 9\n", "output": "108 900" }, { "input": "2 16\n", "output": "79 97" }, { "input": "99 892\n", "output": "-1 -1" }, { "input": "3 2\n", "output": "101 200" }, { "input": "100 1\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 299\n", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2 17\n", "output": "89 98\n" } ], "generated_tests": [ { "input": "3 13\n", "output": "139 940\n" }, { "input": "97 29\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001999 9992000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 8\n", "output": "107 800\n" }, { "input": "100 110\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000001999999999999 9999999999992000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "4 1\n", "output": "1000 1000\n" }, { "input": "4 10\n", "output": "1009 9100\n" }, { "input": "99 1058\n", "output": "-1 -1\n" }, { "input": "99 752\n", "output": "100000000000000499999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999995000000000000000\n" }, { "input": "100 14\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049 9500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "101 298\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 99999999999999999999999999999999910000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "10 18\n", "output": "1000000089 9900000000\n" }, { "input": "3 22\n", "output": "499 994\n" }, { "input": "1 3\n", "output": "3 3\n" }, { "input": "2 13\n", "output": "49 94\n" }, { "input": "100 338\n", "output": "1000000000000000000000000000000000000000000000000000000000000049999999999999999999999999999999999999 9999999999999999999999999999999999999500000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "5 1\n", "output": "10000 10000\n" }, { "input": "5 9\n", "output": "10008 90000\n" }, { "input": "3 16\n", "output": "169 970\n" }, { "input": "99 394\n", "output": "100000000000000000000000000000000000000000000000000000069999999999999999999999999999999999999999999 999999999999999999999999999999999999999999970000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 6\n", "output": "105 600\n" }, { "input": "101 299\n", "output": "10000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 99999999999999999999999999999999920000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "5 6\n", "output": "10005 60000\n" }, { "input": "7 1\n", "output": "1000000 1000000\n" }, { "input": "4 7\n", "output": "1006 7000\n" }, { "input": "101 173\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000019999999999999999999 99999999999999999992000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "1 6\n", "output": "6 6\n" }, { "input": "100 451\n", "output": "1000000000000000000000000000000000000000000000000099999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999910000000000000000000000000000000000000000000000000\n" }, { "input": "5 2\n", "output": "10001 20000\n" }, { "input": "5 3\n", "output": "10002 30000\n" }, { "input": "4 16\n", "output": "1069 9700\n" }, { "input": "99 242\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999 999999999999999999999999998000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "3 14\n", "output": "149 950\n" }, { "input": "5 11\n", "output": "10019 92000\n" }, { "input": "7 2\n", "output": "1000001 2000000\n" }, { "input": "4 17\n", "output": "1079 9800\n" }, { "input": "99 238\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000399999999999999999999999999 999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "2 4\n", "output": "13 40\n" }, { "input": "4 21\n", "output": "1299 9930\n" }, { "input": "4 2\n", "output": "1001 2000\n" }, { "input": "4 3\n", "output": "1002 3000\n" }, { "input": "6 16\n", "output": "100069 970000\n" }, { "input": "31 242\n", "output": "1000799999999999999999999999999 9999999999999999999999999980000\n" }, { "input": "3 12\n", "output": "129 930\n" }, { "input": "6 11\n", "output": "100019 920000\n" }, { "input": "14 2\n", "output": "10000000000001 20000000000000\n" }, { "input": "5 17\n", "output": "10079 98000\n" }, { "input": "99 349\n", "output": "100000000000000000000000000000000000000000000000000000000000699999999999999999999999999999999999999 999999999999999999999999999999999999997000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "7 21\n", "output": "1000299 9930000\n" }, { "input": "5 4\n", "output": "10003 40000\n" }, { "input": "7 3\n", "output": "1000002 3000000\n" }, { "input": "9 16\n", "output": "100000069 970000000\n" }, { "input": "6 12\n", "output": "100029 930000\n" }, { "input": "7 11\n", "output": "1000019 9200000\n" }, { "input": "14 4\n", "output": "10000000000003 40000000000000\n" }, { "input": "5 28\n", "output": "10999 99910\n" }, { "input": "101 125\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000079999999999999 99999999999998000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" }, { "input": "4 13\n", "output": "1039 9400\n" }, { "input": "7 36\n", "output": "1008999 9999000\n" }, { "input": "4 4\n", "output": "1003 4000\n" }, { "input": "3 000\n", "output": "-1 -1\n" }, { "input": "3 34\n", "output": "-1 -1\n" }, { "input": "2 26\n", "output": "-1 -1\n" }, { "input": "4 900\n", "output": "-1 -1\n" }, { "input": "100 1058\n", "output": "-1 -1\n" }, { "input": "100 996\n", "output": "-1 -1\n" }, { "input": "2 34\n", "output": "-1 -1\n" }, { "input": "2 22\n", "output": "-1 -1\n" }, { "input": "2 40\n", "output": "-1 -1\n" }, { "input": "100 000\n", "output": "-1 -1\n" }, { "input": "4 100\n", "output": "-1 -1\n" }, { "input": "99 970\n", "output": "-1 -1\n" }, { "input": "1 18\n", "output": "-1 -1\n" }, { "input": "4 1233\n", "output": "-1 -1\n" }, { "input": "2 21\n", "output": "-1 -1\n" }, { "input": "001 299\n", "output": "-1 -1\n" }, { "input": "2 52\n", "output": "-1 -1\n" }, { "input": "2 51\n", "output": "-1 -1\n" }, { "input": "4 110\n", "output": "-1 -1\n" }, { "input": "001 173\n", "output": "-1 -1\n" }, { "input": "4 233\n", "output": "-1 -1\n" }, { "input": "1 14\n", "output": "-1 -1\n" }, { "input": "1 52\n", "output": "-1 -1\n" }, { "input": "4 51\n", "output": "-1 -1\n" }, { "input": "5 110\n", "output": "-1 -1\n" }, { "input": "001 125\n", "output": "-1 -1\n" }, { "input": "4 123\n", "output": "-1 -1\n" }, { "input": "26 242\n", "output": "-1 -1\n" }, { "input": "3 52\n", "output": "-1 -1\n" }, { "input": "4 64\n", "output": "-1 -1\n" }, { "input": "1 110\n", "output": "-1 -1\n" }, { "input": "7 0\n", "output": "-1 -1\n" } ] }
[ 0.00007689578209680945, 0.00007673920989947553, 0.00004912688070913461, 0.0000444552125628278, 0.00004431688177447553, 0.00004168962521853147, 0.00004166294181599651, 0.0000415790821131993, 0.00004130604535893794, 0.00004117424399038462, 0.00004041248910074301, 0.00004039389197358631, 0.000040346875372023806, 0.000040225171151114516, 0.00004019102608816964, 0.000039941774461866256, 0.00003988278758741259, 0.00003714482345388986, 0.00003384445912388393, 0.000028635335841892483, 0.000022764936104910717, 0.00001481164758386145, 0.000013659562825520834, 0.000012923329978899338, 0.000009075147088913691, 0.000008707291899181548, 0.00000867171814546131, 0.000007376807198660715, 0.000006812580019460337, 0.000006416334428267046, 0.0000061811636937281465, 0.000006113026181175595, 0.000005807161411830358, 0.000005536978864397322, 0.000005382112489073427, 0.000005043392114937649, 0.000005014839716287164, 0.000004852361932663691, 0.000004814461356026786, 0.000004792269763764881, 0.000004772904228583917, 0.000004656498951903101, 0.000004488468563988095, 0.00000425584802827381, 0.00000406406482514881, 0.000004060354166666666, 0.0000038645447989510495, 0.000003846252278645833, 0.000003846239815848214, 0.000003442963880845717, 0.0000033316784319196427, 0.0000026132899693080358, 0.0000025463617466517857, 0.0000024158947172619045, 0.00000198250157069493, 0.0000019529691452752975, 0.0000018455244277207168, 0.000001831602957589286, 0.0000018016337685751749, 0.0000017682380285729892, 0.0000017249864211309523, 0.0000013333330078125, 0.00000121461181640625, 0.0000011576502743675596, 0.0000010431572202432503, 8.17848121279762e-7, 7.455681954763986e-7, 6.530783025568183e-7, 6.44261501518192e-7, 5.80541670710559e-7, 5.272722152462509e-7, 4.6963990041285304e-7, 4.015905372458825e-7, 3.9669948148481786e-7, 3.327199076852463e-7, 3.1681358768564996e-7, 2.7939913286774174e-7, 2.617895683836502e-7, 2.5817574002500627e-7, 1.9725683651141154e-7, 1.9541610108135177e-7, 1.9446829387344438e-7, 1.8473874587754874e-7, 1.6553034394161318e-7, 1.5992814313424926e-7, 1.4606549080664873e-7, 1.4219233661552842e-7, 1.0789179591370619e-7, 1.0181240981142958e-7, 1.0027702332989331e-7, 9.523896024387823e-8, 9.429338476424896e-8, 9.045826048005962e-8, 7.888781424810696e-8, 7.812536299583865e-8, 7.76994137878382e-8, 7.646375193053127e-8, 7.396238294860258e-8, 7.272211424799572e-8, 6.651755469317796e-8, 6.599447563045802e-8, 5.134752696939261e-8, 4.3772138818696056e-8, 3.373098880117363e-8, 3.0499348612173276e-8, 2.2949778300986846e-9, 1.295825166536901e-9, 7.615883041796982e-10 ]
p03687 AtCoder Grand Contest 016 - Shrinking
294
294_56
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations. Constraints * 1 ≤ |s| ≤ 100 * s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output Print the minimum necessary number of operations to achieve the objective. Examples Input serval Output 3 Input jackal Output 2 Input zzz Output 0 Input whbrjpjyhsrywlqjxdbrbaomnw Output 8
s = input() exitLower = list(set(list(s))) m = len(s) for alp in exitLower: SL = list(s) cnt = 0 while len(set(SL)) > 1: for i in range(len(SL)-1): if SL[i+1] == alp: SL[i] = alp SL.pop() cnt += 1 m = min(m,cnt) print(m)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: s: str @classmethod def from_str(cls, input_: str): s = input_.strip() return cls(s) def __repr__(self): return self.s
serval
O(n**2)
0.000029
{ "public_tests": [ { "input": "serval", "output": "3" }, { "input": "whbrjpjyhsrywlqjxdbrbaomnw", "output": "8" }, { "input": "jackal", "output": "2" }, { "input": "zzz", "output": "0" } ], "private_tests": [], "generated_tests": [ { "input": "resval", "output": "3\n" }, { "input": "whbrjpjyhsrywlqjxcbrbaomnw", "output": "8\n" }, { "input": "zzy", "output": "1\n" }, { "input": "lakjac", "output": "2\n" }, { "input": "xmboabrbnxjrlwyrthyjpjrchv", "output": "6\n" }, { "input": "whcrjpbyhtxywkrlxnbrbaojmr", "output": "10\n" }, { "input": "smjoabjdoxmrjwypugydyqrchv", "output": "11\n" }, { "input": "whdrpxdwhuozxkrmxodjaaojkt", "output": "9\n" }, { "input": "xwwwnajdrxmrqwzpugnhlojced", "output": "12\n" }, { "input": "wyeoqidphazibqrnvxibngzwpx", "output": "7\n" }, { "input": "xpwzglbjquntrci{axpdikofyw", "output": "13\n" }, { "input": "jackbl", "output": "3\n" }, { "input": "sesval", "output": "3\n" }, { "input": "whcrjpjyhsrywlqjxbbrbaomnw", "output": "8\n" }, { "input": "cajkbl", "output": "3\n" }, { "input": "yzz", "output": "1\n" }, { "input": "setval", "output": "3\n" }, { "input": "whcrjpjyhsrywlqjxnbrbaombw", "output": "8\n" }, { "input": "lbkjac", "output": "3\n" }, { "input": "zz{", "output": "1\n" }, { "input": "setv`l", "output": "3\n" }, { "input": "wbmoabrbnxjqlwyrshyjpjrchw", "output": "8\n" }, { "input": "{zz", "output": "1\n" }, { "input": "seuv`l", "output": "3\n" }, { "input": "whcrjpjyhtrywlqjxnbrbaombw", "output": "8\n" }, { "input": "alkjac", "output": "3\n" }, { "input": "{zy", "output": "1\n" }, { "input": "seuv_l", "output": "3\n" }, { "input": "wbmoabrbnxjqlwyrthyjpjrchw", "output": "8\n" }, { "input": "cajkla", "output": "3\n" }, { "input": "yz{", "output": "1\n" }, { "input": "reuv_l", "output": "3\n" }, { "input": "wmboabrbnxjqlwyrthyjpjrchw", "output": "8\n" }, { "input": "cakkla", "output": "2\n" }, { "input": "xz{", "output": "1\n" }, { "input": "l_vuer", "output": "3\n" }, { "input": "wmboabrbnxjqlwyrthyjpjrchv", "output": "8\n" }, { "input": "clkjaa", "output": "3\n" }, { "input": "{zx", "output": "1\n" }, { "input": "uerv_l", "output": "3\n" }, { "input": "xmboabrbnxjqlwyrthyjpjrchv", "output": "8\n" }, { "input": "aajklc", "output": "3\n" }, { "input": "zzx", "output": "1\n" }, { "input": "l_vreu", "output": "3\n" }, { "input": "bajklc", "output": "3\n" }, { "input": "zzw", "output": "1\n" }, { "input": "l_vseu", "output": "3\n" }, { "input": "vhcrjpjyhtrywlrjxnbrbaobmx", "output": "6\n" }, { "input": "b`jklc", "output": "3\n" }, { "input": "wzz", "output": "1\n" }, { "input": "l_vsdu", "output": "3\n" }, { "input": "vhcrjpjyhtrywkrjxnbrbaobmx", "output": "6\n" }, { "input": "clkj`b", "output": "3\n" }, { "input": "xzz", "output": "1\n" }, { "input": "m_vsdu", "output": "3\n" }, { "input": "vhcrjpjyhtrywkrkxnbrbaobmx", "output": "6\n" }, { "input": "cmkj`b", "output": "3\n" }, { "input": "xyz", "output": "1\n" }, { "input": "m_vtdu", "output": "3\n" }, { "input": "vhcrjpjyhtrywkrlxnbrbaobmx", "output": "6\n" }, { "input": "b`jkmc", "output": "3\n" }, { "input": "xxz", "output": "1\n" }, { "input": "m`vtdu", "output": "3\n" }, { "input": "whcrjpjyhtrywkrlxnbrbaobmx", "output": "6\n" }, { "input": "b`mkjc", "output": "3\n" }, { "input": "xx{", "output": "1\n" }, { "input": "m`vudt", "output": "3\n" }, { "input": "xmboabrbnxlrkwyrthyjpjrchw", "output": "6\n" }, { "input": "m`bkjc", "output": "3\n" }, { "input": "{xx", "output": "1\n" }, { "input": "tduv`m", "output": "3\n" }, { "input": "whcrjpbyhtrywkrlxnbrbaojmx", "output": "6\n" }, { "input": "n`bkjc", "output": "3\n" }, { "input": "{wx", "output": "1\n" }, { "input": "`duvtm", "output": "3\n" }, { "input": "cjkb`n", "output": "3\n" }, { "input": "{xw", "output": "1\n" }, { "input": "mtvud`", "output": "3\n" }, { "input": "whcrjxbyhtpywkrlxnbrbaojmr", "output": "10\n" }, { "input": "cikb`n", "output": "3\n" }, { "input": "{xv", "output": "1\n" }, { "input": "mtvuda", "output": "3\n" }, { "input": "whcrjxbyhtpywkrlxncrbaojmr", "output": "10\n" }, { "input": "n`bkic", "output": "3\n" }, { "input": "zxv", "output": "1\n" }, { "input": "mtvvda", "output": "2\n" }, { "input": "whcrjxbyhtpywkrlxncrbbojmr", "output": "10\n" }, { "input": "i`bknc", "output": "3\n" }, { "input": "vxz", "output": "1\n" }, { "input": "advvtm", "output": "2\n" }, { "input": "rmjobbrcnxlrkwypthybxjrchw", "output": "10\n" }, { "input": "i`bknd", "output": "3\n" }, { "input": "uxz", "output": "1\n" }, { "input": "aevvtm", "output": "2\n" }, { "input": "rmjobbrcnxlrkwypthybxjrchv", "output": "10\n" }, { "input": "i`bkne", "output": "3\n" }, { "input": "xuz", "output": "1\n" }, { "input": "mtvvea", "output": "2\n" }, { "input": "vhcrjxbyhtpywkrlxncrbbojmr", "output": "10\n" }, { "input": "enkb`i", "output": "3\n" } ] }
[ 0.00037000136455787424, 0.0003567679445443766, 0.00021885334843768295, 0.00015645579249962344, 0.00012763708793923234, 0.00011369894798329743, 0.00010818250941979613, 0.00010795661263413779, 0.00009858968018704395, 0.00009385720592898478, 0.00008964122173650202, 0.00008895879279518196, 0.000053735579804011056, 0.00005338900218496114, 0.00005258953771820493, 0.00004620863442679264, 0.0000410788964621997, 0.000040936934656302165, 0.00004015552193062965, 0.00004004706292373514, 0.00003942336732858281, 0.000039011795774985203, 0.00003867005404560998, 0.00003433714858514364, 0.000029363773950994872, 0.000028912951240007285, 0.000026148924758059006, 0.000025809592381739266, 0.0000233871496625502, 0.000023003698489435467, 0.000021855310507594653, 0.000021252767161990122, 0.000021005772492729868, 0.000018779488049098034, 0.0000186529406994028, 0.000018510700519559238, 0.00001829457670708545, 0.000017369750579353854, 0.000015319945435527704, 0.000012787366197726874, 0.000012746836215026315, 0.000012624359989926586, 0.000011562548466555095, 0.000011015675254352922, 0.000010990691489052079, 0.000010829917658989577, 0.000006817875010817652, 0.000004051076963489615, 0.0000019044261204342166, 0.0000015358234094486014, 0.0000014534519679827, 0.0000014339205698640277, 0.0000013993256832083883, 0.0000013957182404757241, 0.0000013956137277645253, 0.000001147394311629579 ]
p03687 AtCoder Grand Contest 016 - Shrinking
294
294_131
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations. Constraints * 1 ≤ |s| ≤ 100 * s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output Print the minimum necessary number of operations to achieve the objective. Examples Input serval Output 3 Input jackal Output 2 Input zzz Output 0 Input whbrjpjyhsrywlqjxdbrbaomnw Output 8
from sys import stdin s= (stdin.readline().rstrip()) f = lambda a, b: abs(a-b-1) diff = lambda ls: map(f, ls[1:], ls) ans = 100 for i in set(s): ans = min(ans,max([len(j) for j in s.split(i)])) print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: s: str @classmethod def from_str(cls, input_: str): s = input_.strip() return cls(s) def __repr__(self): return self.s
serval
O(n)
0.000002
{ "public_tests": [ { "input": "serval", "output": "3" }, { "input": "whbrjpjyhsrywlqjxdbrbaomnw", "output": "8" }, { "input": "jackal", "output": "2" }, { "input": "zzz", "output": "0" } ], "private_tests": [], "generated_tests": [ { "input": "resval", "output": "3\n" }, { "input": "whbrjpjyhsrywlqjxcbrbaomnw", "output": "8\n" }, { "input": "zzy", "output": "1\n" }, { "input": "lakjac", "output": "2\n" }, { "input": "xmboabrbnxjrlwyrthyjpjrchv", "output": "6\n" }, { "input": "whcrjpbyhtxywkrlxnbrbaojmr", "output": "10\n" }, { "input": "smjoabjdoxmrjwypugydyqrchv", "output": "11\n" }, { "input": "whdrpxdwhuozxkrmxodjaaojkt", "output": "9\n" }, { "input": "xwwwnajdrxmrqwzpugnhlojced", "output": "12\n" }, { "input": "wyeoqidphazibqrnvxibngzwpx", "output": "7\n" }, { "input": "xpwzglbjquntrci{axpdikofyw", "output": "13\n" }, { "input": "jackbl", "output": "3\n" }, { "input": "sesval", "output": "3\n" }, { "input": "whcrjpjyhsrywlqjxbbrbaomnw", "output": "8\n" }, { "input": "cajkbl", "output": "3\n" }, { "input": "yzz", "output": "1\n" }, { "input": "setval", "output": "3\n" }, { "input": "whcrjpjyhsrywlqjxnbrbaombw", "output": "8\n" }, { "input": "lbkjac", "output": "3\n" }, { "input": "zz{", "output": "1\n" }, { "input": "setv`l", "output": "3\n" }, { "input": "wbmoabrbnxjqlwyrshyjpjrchw", "output": "8\n" }, { "input": "{zz", "output": "1\n" }, { "input": "seuv`l", "output": "3\n" }, { "input": "whcrjpjyhtrywlqjxnbrbaombw", "output": "8\n" }, { "input": "alkjac", "output": "3\n" }, { "input": "{zy", "output": "1\n" }, { "input": "seuv_l", "output": "3\n" }, { "input": "wbmoabrbnxjqlwyrthyjpjrchw", "output": "8\n" }, { "input": "cajkla", "output": "3\n" }, { "input": "yz{", "output": "1\n" }, { "input": "reuv_l", "output": "3\n" }, { "input": "wmboabrbnxjqlwyrthyjpjrchw", "output": "8\n" }, { "input": "cakkla", "output": "2\n" }, { "input": "xz{", "output": "1\n" }, { "input": "l_vuer", "output": "3\n" }, { "input": "wmboabrbnxjqlwyrthyjpjrchv", "output": "8\n" }, { "input": "clkjaa", "output": "3\n" }, { "input": "{zx", "output": "1\n" }, { "input": "uerv_l", "output": "3\n" }, { "input": "xmboabrbnxjqlwyrthyjpjrchv", "output": "8\n" }, { "input": "aajklc", "output": "3\n" }, { "input": "zzx", "output": "1\n" }, { "input": "l_vreu", "output": "3\n" }, { "input": "bajklc", "output": "3\n" }, { "input": "zzw", "output": "1\n" }, { "input": "l_vseu", "output": "3\n" }, { "input": "vhcrjpjyhtrywlrjxnbrbaobmx", "output": "6\n" }, { "input": "b`jklc", "output": "3\n" }, { "input": "wzz", "output": "1\n" }, { "input": "l_vsdu", "output": "3\n" }, { "input": "vhcrjpjyhtrywkrjxnbrbaobmx", "output": "6\n" }, { "input": "clkj`b", "output": "3\n" }, { "input": "xzz", "output": "1\n" }, { "input": "m_vsdu", "output": "3\n" }, { "input": "vhcrjpjyhtrywkrkxnbrbaobmx", "output": "6\n" }, { "input": "cmkj`b", "output": "3\n" }, { "input": "xyz", "output": "1\n" }, { "input": "m_vtdu", "output": "3\n" }, { "input": "vhcrjpjyhtrywkrlxnbrbaobmx", "output": "6\n" }, { "input": "b`jkmc", "output": "3\n" }, { "input": "xxz", "output": "1\n" }, { "input": "m`vtdu", "output": "3\n" }, { "input": "whcrjpjyhtrywkrlxnbrbaobmx", "output": "6\n" }, { "input": "b`mkjc", "output": "3\n" }, { "input": "xx{", "output": "1\n" }, { "input": "m`vudt", "output": "3\n" }, { "input": "xmboabrbnxlrkwyrthyjpjrchw", "output": "6\n" }, { "input": "m`bkjc", "output": "3\n" }, { "input": "{xx", "output": "1\n" }, { "input": "tduv`m", "output": "3\n" }, { "input": "whcrjpbyhtrywkrlxnbrbaojmx", "output": "6\n" }, { "input": "n`bkjc", "output": "3\n" }, { "input": "{wx", "output": "1\n" }, { "input": "`duvtm", "output": "3\n" }, { "input": "cjkb`n", "output": "3\n" }, { "input": "{xw", "output": "1\n" }, { "input": "mtvud`", "output": "3\n" }, { "input": "whcrjxbyhtpywkrlxnbrbaojmr", "output": "10\n" }, { "input": "cikb`n", "output": "3\n" }, { "input": "{xv", "output": "1\n" }, { "input": "mtvuda", "output": "3\n" }, { "input": "whcrjxbyhtpywkrlxncrbaojmr", "output": "10\n" }, { "input": "n`bkic", "output": "3\n" }, { "input": "zxv", "output": "1\n" }, { "input": "mtvvda", "output": "2\n" }, { "input": "whcrjxbyhtpywkrlxncrbbojmr", "output": "10\n" }, { "input": "i`bknc", "output": "3\n" }, { "input": "vxz", "output": "1\n" }, { "input": "advvtm", "output": "2\n" }, { "input": "rmjobbrcnxlrkwypthybxjrchw", "output": "10\n" }, { "input": "i`bknd", "output": "3\n" }, { "input": "uxz", "output": "1\n" }, { "input": "aevvtm", "output": "2\n" }, { "input": "rmjobbrcnxlrkwypthybxjrchv", "output": "10\n" }, { "input": "i`bkne", "output": "3\n" }, { "input": "xuz", "output": "1\n" }, { "input": "mtvvea", "output": "2\n" }, { "input": "vhcrjxbyhtpywkrlxncrbbojmr", "output": "10\n" }, { "input": "enkb`i", "output": "3\n" } ] }
[ 0.00017448615963723776, 0.00008930180326704545, 0.00008143791694438374, 0.00007824102392919581, 0.000059918465581293704, 0.000059157254589160845, 0.00005841908728966346, 0.00005813987120301574, 0.000058105722560642484, 0.00005697677117023602, 0.000056728813524366256, 0.00005487784973229896, 0.000054257574464597906, 0.000054035470757757876, 0.00005332827948809004, 0.00004291538610413025, 0.0000398060091919799, 0.00003688173483937937, 0.000036046501133631994, 0.00003584126864346591, 0.000035594225401551575, 0.00003485824784200175, 0.00003380270980386801, 0.000032505287191324305, 0.000032463943345716786, 0.00003238091597465035, 0.00003237780194219842, 0.00003102986277589598, 0.000030589677952906475, 0.000030092727532233394, 0.000027569142291302452, 0.00002753001873907343, 0.000027448374699519237, 0.000027295755149147727, 0.000027294157151442307, 0.000027076595771416084, 0.000027062837439903846, 0.00002665005214707168, 0.000024807494809877623, 0.000021619073781687063, 0.000010344805493334792, 0.00000909528622159091, 0.00000818700871394231, 0.000008164915920017482, 0.000007790175945148602, 0.000007704929236778847, 0.000007534507648601399, 0.00000750375030048077, 0.000007494323330965908, 0.000007468803526551574, 0.000007456501119973776, 0.00000745570503715035, 0.000007455527398382869, 0.000007447775814029721, 0.0000074410334762893374, 0.000007380915510270981, 0.0000072160542094624136, 0.0000071556281413898605, 0.0000070840022399475525, 0.000006941407110467657, 0.000006742313783872378, 0.00000662326507867133, 0.000005902276660839161, 0.000005433659760161714, 0.000005430433784965036, 0.0000049099794717001746, 0.00000486721607298951, 0.0000047800997596153845, 0.00000465076248361014, 0.000004440439275568182, 0.0000043754530293924825, 0.0000043564690368225525, 0.000004050593736341783, 0.0000039909762483610146, 0.0000039593505244755246, 0.0000039176907233391606, 0.000003863908790428323, 0.00000386226787860577, 0.000003827937404392483, 0.0000037821823098776228, 0.0000037727074819711544, 0.0000037498526551573425, 0.00000374937504097465, 0.000003743747145432693, 0.0000037369880763767483, 0.0000036316630244755243, 0.0000036189895241477277, 0.0000028713292996066433, 0.0000028498509342220282, 0.0000026312298541302453, 0.0000024790872213723775, 0.0000024561535729895107, 0.0000023785881228146855, 0.0000023554792531687063, 0.000002338924511035839, 0.0000023368740302666087, 0.000002336487420782343, 0.0000023246932774256997, 0.0000023148719132430075, 0.000002305684030812937, 0.0000023025157888986017, 0.000001909447279283217, 0.0000019079801955856644, 0.0000019068284527972026, 0.0000018920632648601401, 0.0000018915897891171334, 0.0000018848233309659094, 0.0000018845389942089161, 0.0000018844891144012239, 0.0000018804340171547204, 0.0000018795384069055944, 0.0000018767484019886364, 0.0000018732328999125875, 0.0000018724246885926574, 0.000001864135407561189, 0.00000185943784145542, 0.0000018491875956075179, 0.0000018477159500655597, 0.0000015001125300480771, 0.0000014718941488199302, 0.0000013931209571678323, 0.0000013829562527316434, 0.000001378946514423077, 0.0000013782822333916084, 0.000001347687254152098, 0.0000013377305097246504, 0.0000013365657369973775, 0.0000013282997978583917, 0.0000013281974704982516, 0.0000013229151551573428, 0.0000012962274229676576, 0.000001294484197443182 ]
1150_C. Prefix Sum Primes
3034
3034_1
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) count = {1: 0, 2: 0} for i in a: count[i] += 1 if count[1] >= 1 and count[2] >= 1: ans = [2] + [1] + [2]*(count[2]-1) + [1]*(count[1] - 1) elif count[1] == 0: ans = [2] * count[2] elif count[2] == 0: ans = [1] * count[1] print(' '.join([str(x) for x in ans]))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int a_list: List[int] @classmethod def from_str(cls, input_: str): n, a_list, _ = input_.split('\n') n = int(n) a_list = [int(x) for x in a_list.split(' ')] assert n == len(a_list) return cls(n, a_list) def __repr__(self): return str(self.n) + '\n' + ' '.join([str(x) for x in self.a_list]) + '\n'
9 1 1 2 1 1 1 2 1 1
O(n)
0.000008
{ "public_tests": [ { "input": "9\n1 1 2 1 1 1 2 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "5\n1 2 1 2 1\n", "output": "2 1 2 1 1\n" } ], "private_tests": [ { "input": "5\n1 2 2 2 2\n", "output": "2 1 2 2 2\n" }, { "input": "2\n2 2\n", "output": "2 2\n" }, { "input": "3\n1 2 2\n", "output": "2 1 2\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "1\n2\n", "output": "2\n" }, { "input": "2\n1 1\n", "output": "1 1\n" }, { "input": "10\n1 1 1 2 1 1 1 2 2 2\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { "input": "41\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2\n", "output": "2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n" }, { "input": "10\n1 1 1 1 2 2 2 2 2 2\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "2\n1 2\n", "output": "2 1\n" }, { "input": "3\n1 1 2\n", "output": "2 1 1\n" }, { "input": "3\n1 1 1\n", "output": "1 1 1\n" }, { "input": "5\n2 1 1 2 2\n", "output": "2 1 2 2 1\n" }, { "input": "4\n1 1 1 1\n", "output": "1 1 1 1\n" }, { "input": "4\n1 2 2 2\n", "output": "2 1 2 2\n" }, { "input": "214\n1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 2 2 2 2 1 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 1 2 1 2 1\n", "output": "2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" }, { "input": "5\n2 2 2 2 2\n", "output": "2 2 2 2 2\n" }, { "input": "4\n1 2 2 1\n", "output": "2 1 2 1\n" }, { "input": "5\n2 1 1 1 1\n", "output": "2 1 1 1 1\n" }, { "input": "4\n2 1 1 1\n", "output": "2 1 1 1\n" } ], "generated_tests": [ { "input": "5\n2 1 2 2 2\n", "output": "2 1 2 2 2\n" }, { "input": "4\n1 1 2 1\n", "output": "2 1 1 1\n" }, { "input": "4\n2 2 2 1\n", "output": "2 1 2 2\n" }, { "input": "5\n2 1 1 2 1\n", "output": "2 1 2 1 1\n" }, { "input": "9\n1 1 2 1 1 1 1 1 1\n", "output": "2 1 1 1 1 1 1 1 1\n" }, { "input": "5\n1 1 2 2 2\n", "output": "2 1 2 2 1\n" }, { "input": "9\n1 1 2 1 1 1 1 2 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n1 1 1 2 1 1 2 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "10\n2 1 1 1 2 2 2 2 2 2\n", "output": "2 1 2 2 2 2 2 2 1 1\n" }, { "input": "3\n2 1 2\n", "output": "2 1 2\n" }, { "input": "10\n2 1 1 1 2 1 2 2 2 2\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "3\n2 1 1\n", "output": "2 1 1\n" }, { "input": "3\n2 2 2\n", "output": "2 2 2\n" }, { "input": "4\n2 2 1 1\n", "output": "2 1 2 1\n" }, { "input": "9\n1 2 2 2 2 1 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "10\n1 1 1 1 1 1 2 2 2 2\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { "input": "9\n1 2 2 2 2 1 1 2 2\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "2\n2 1\n", "output": "2 1\n" }, { "input": "4\n2 2 2 2\n", "output": "2 2 2 2\n" }, { "input": "214\n1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 1 2 1 2 1\n", "output": "2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" }, { "input": "4\n1 1 1 2\n", "output": "2 1 1 1\n" }, { "input": "4\n1 2 1 1\n", "output": "2 1 1 1\n" }, { "input": "9\n1 1 2 1 1 2 1 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n1 2 2 1 2 1 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n1 1 1 2 1 2 1 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "3\n1 2 1\n", "output": "2 1 1\n" }, { "input": "9\n1 1 2 1 1 1 2 1 2\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "5\n2 1 2 2 1\n", "output": "2 1 2 2 1\n" }, { "input": "4\n2 1 2 1\n", "output": "2 1 2 1\n" }, { "input": "5\n1 1 2 1 2\n", "output": "2 1 2 1 1\n" }, { "input": "9\n1 2 2 1 1 1 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "4\n2 1 1 2\n", "output": "2 1 2 1\n" }, { "input": "3\n2 2 1\n", "output": "2 1 2\n" }, { "input": "5\n1 2 2 1 2\n", "output": "2 1 2 2 1\n" }, { "input": "9\n1 2 2 2 1 1 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n2 2 2 2 1 1 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 2 2 1 1 1 2 1 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "4\n1 1 2 2\n", "output": "2 1 2 1\n" }, { "input": "9\n1 1 2 1 1 1 1 1 2\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 1 1 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 2 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 1 1 1 2 2 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "4\n2 1 2 2\n", "output": "2 1 2 2\n" }, { "input": "9\n2 2 2 2 2 1 1 2 1\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "9\n1 2 2 1 1 1 1 1 2\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 1 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 2 1 1 2 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 2 2 1 1 2 1 1 2\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 2 1 1 1 1 2 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 2 1 1 1 2 1 1 2\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 2 1 2 1 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n2 1 1 2 1 1 1 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "10\n1 1 1 1 2 2 2 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "5\n1 1 1 2 2\n", "output": "2 1 2 1 1\n" }, { "input": "5\n2 2 1 2 1\n", "output": "2 1 2 2 1\n" }, { "input": "9\n1 2 2 1 1 1 1 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 2 1 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n2 2 1 1 2 1 2 2 2 2\n", "output": "2 1 2 2 2 2 2 2 1 1\n" }, { "input": "9\n1 2 2 1 1 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 2 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "5\n1 2 2 1 1\n", "output": "2 1 2 1 1\n" }, { "input": "9\n2 1 1 1 1 1 1 2 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "10\n1 1 1 1 2 1 2 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "9\n2 2 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "9\n2 2 1 2 2 1 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 2 2 1 1 2 2 1 2\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n2 1 2 1 1 2 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 1 1 1 2 1 2 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n2 2 1 1 1 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 1 1 1 1 2 1 1 2\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n2 2 2 1 1 1 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "10\n1 1 1 1 2 2 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { "input": "5\n1 1 2 2 1\n", "output": "2 1 2 1 1\n" }, { "input": "9\n1 2 2 2 1 1 1 1 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "10\n2 2 1 1 2 1 2 2 1 2\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "9\n2 1 2 1 2 2 2 2 1\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "9\n1 2 2 1 1 1 2 1 2\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n1 2 1 1 2 2 2 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "10\n1 2 2 1 2 2 2 1 2 1\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "5\n1 2 2 2 1\n", "output": "2 1 2 2 1\n" }, { "input": "10\n1 1 1 1 2 2 2 2 1 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 2 1 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 1 1 1 1 1 1 2 1\n", "output": "2 1 1 1 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1\n" } ] }
[ 0.06858335400000001, 0.00003141408518629807, 0.00002402961229785839, 0.000020865091640310918, 0.000020742664690777976, 0.000018348201349431822, 0.000016565582304414334, 0.000016489538529829553, 0.000016108313005354023, 0.000014827594501201921, 0.000014095078493771854, 0.000013978175371503495, 0.000012872754466236888, 0.000012588347355769233, 0.00001144388365930944, 0.000011095533667504371, 0.000011087338655485142, 0.000011004639067963289, 0.000011003828343531469, 0.000010572461265297203, 0.000009403083916083915, 0.000009314628318946679, 0.000009137954326923078, 0.00000879742153354458, 0.000008744115111451048, 0.000008238601248361014, 0.000008007047653518357, 0.000007762549347137237, 0.00000770596713833042, 0.000007458139081621504, 0.000007347380545236015, 0.000007336410224541084, 0.0000053642175890515746, 0.00000454909073153409, 0.0000037014039963942307, 0.0000036778014231861884, 0.000003671444110576923, 0.000003624113117351399, 0.0000018247463942307695, 0.0000014762847738199303, 8.359614018793703e-9, 1.655075393356644e-9, 1.559372268356643e-9, 5.595088505244755e-10, 2.88973721590909e-10, 2.29806326486014e-10, 2.0022945804195812e-10, 1.7556271853146847e-10, 1.739783653846155e-10, 1.4208642919580425e-10, 1.1120520104895106e-10 ]
1150_C. Prefix Sum Primes
3034
3034_57
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
n=int(input()) y=list(map(int,input().split())) if n==1: print(y[0]) else: even=y.count(2) odd=y.count(1) if even==0 or odd==0: print(*y) else: y=sorted(y) y.reverse() i=0 while i<n: if y[i]==1: break i+=1 t=y[i] y[i]=y[1] y[1]=t print(*y)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int a_list: List[int] @classmethod def from_str(cls, input_: str): n, a_list, _ = input_.split('\n') n = int(n) a_list = [int(x) for x in a_list.split(' ')] assert n == len(a_list) return cls(n, a_list) def __repr__(self): return str(self.n) + '\n' + ' '.join([str(x) for x in self.a_list]) + '\n'
9 1 1 2 1 1 1 2 1 1
O(nlogn)
0.000029
{ "public_tests": [ { "input": "9\n1 1 2 1 1 1 2 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "5\n1 2 1 2 1\n", "output": "2 1 2 1 1\n" } ], "private_tests": [ { "input": "5\n1 2 2 2 2\n", "output": "2 1 2 2 2\n" }, { "input": "2\n2 2\n", "output": "2 2\n" }, { "input": "3\n1 2 2\n", "output": "2 1 2\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "1\n2\n", "output": "2\n" }, { "input": "2\n1 1\n", "output": "1 1\n" }, { "input": "10\n1 1 1 2 1 1 1 2 2 2\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { "input": "41\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2\n", "output": "2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n" }, { "input": "10\n1 1 1 1 2 2 2 2 2 2\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "2\n1 2\n", "output": "2 1\n" }, { "input": "3\n1 1 2\n", "output": "2 1 1\n" }, { "input": "3\n1 1 1\n", "output": "1 1 1\n" }, { "input": "5\n2 1 1 2 2\n", "output": "2 1 2 2 1\n" }, { "input": "4\n1 1 1 1\n", "output": "1 1 1 1\n" }, { "input": "4\n1 2 2 2\n", "output": "2 1 2 2\n" }, { "input": "214\n1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 2 2 2 2 1 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 1 2 1 2 1\n", "output": "2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" }, { "input": "5\n2 2 2 2 2\n", "output": "2 2 2 2 2\n" }, { "input": "4\n1 2 2 1\n", "output": "2 1 2 1\n" }, { "input": "5\n2 1 1 1 1\n", "output": "2 1 1 1 1\n" }, { "input": "4\n2 1 1 1\n", "output": "2 1 1 1\n" } ], "generated_tests": [ { "input": "5\n2 1 2 2 2\n", "output": "2 1 2 2 2\n" }, { "input": "4\n1 1 2 1\n", "output": "2 1 1 1\n" }, { "input": "4\n2 2 2 1\n", "output": "2 1 2 2\n" }, { "input": "5\n2 1 1 2 1\n", "output": "2 1 2 1 1\n" }, { "input": "9\n1 1 2 1 1 1 1 1 1\n", "output": "2 1 1 1 1 1 1 1 1\n" }, { "input": "5\n1 1 2 2 2\n", "output": "2 1 2 2 1\n" }, { "input": "9\n1 1 2 1 1 1 1 2 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n1 1 1 2 1 1 2 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "10\n2 1 1 1 2 2 2 2 2 2\n", "output": "2 1 2 2 2 2 2 2 1 1\n" }, { "input": "3\n2 1 2\n", "output": "2 1 2\n" }, { "input": "10\n2 1 1 1 2 1 2 2 2 2\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "3\n2 1 1\n", "output": "2 1 1\n" }, { "input": "3\n2 2 2\n", "output": "2 2 2\n" }, { "input": "4\n2 2 1 1\n", "output": "2 1 2 1\n" }, { "input": "9\n1 2 2 2 2 1 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "10\n1 1 1 1 1 1 2 2 2 2\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { "input": "9\n1 2 2 2 2 1 1 2 2\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "2\n2 1\n", "output": "2 1\n" }, { "input": "4\n2 2 2 2\n", "output": "2 2 2 2\n" }, { "input": "214\n1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 1 2 1 2 1\n", "output": "2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" }, { "input": "4\n1 1 1 2\n", "output": "2 1 1 1\n" }, { "input": "4\n1 2 1 1\n", "output": "2 1 1 1\n" }, { "input": "9\n1 1 2 1 1 2 1 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n1 2 2 1 2 1 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n1 1 1 2 1 2 1 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "3\n1 2 1\n", "output": "2 1 1\n" }, { "input": "9\n1 1 2 1 1 1 2 1 2\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "5\n2 1 2 2 1\n", "output": "2 1 2 2 1\n" }, { "input": "4\n2 1 2 1\n", "output": "2 1 2 1\n" }, { "input": "5\n1 1 2 1 2\n", "output": "2 1 2 1 1\n" }, { "input": "9\n1 2 2 1 1 1 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "4\n2 1 1 2\n", "output": "2 1 2 1\n" }, { "input": "3\n2 2 1\n", "output": "2 1 2\n" }, { "input": "5\n1 2 2 1 2\n", "output": "2 1 2 2 1\n" }, { "input": "9\n1 2 2 2 1 1 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n2 2 2 2 1 1 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 2 2 1 1 1 2 1 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "4\n1 1 2 2\n", "output": "2 1 2 1\n" }, { "input": "9\n1 1 2 1 1 1 1 1 2\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 1 1 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 2 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 1 1 1 2 2 1 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "4\n2 1 2 2\n", "output": "2 1 2 2\n" }, { "input": "9\n2 2 2 2 2 1 1 2 1\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "9\n1 2 2 1 1 1 1 1 2\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 1 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 2 1 1 2 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 2 2 1 1 2 1 1 2\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 2 1 1 1 1 2 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 2 1 1 1 2 1 1 2\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 2 1 2 1 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n2 1 1 2 1 1 1 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "10\n1 1 1 1 2 2 2 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "5\n1 1 1 2 2\n", "output": "2 1 2 1 1\n" }, { "input": "5\n2 2 1 2 1\n", "output": "2 1 2 2 1\n" }, { "input": "9\n1 2 2 1 1 1 1 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n2 1 2 1 2 1 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n2 2 1 1 2 1 2 2 2 2\n", "output": "2 1 2 2 2 2 2 2 1 1\n" }, { "input": "9\n1 2 2 1 1 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 2 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "5\n1 2 2 1 1\n", "output": "2 1 2 1 1\n" }, { "input": "9\n2 1 1 1 1 1 1 2 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "10\n1 1 1 1 2 1 2 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "9\n2 2 2 1 2 1 2 2 1\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "9\n2 2 1 2 2 1 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 2 2 1 1 2 2 1 2\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n2 1 2 1 1 2 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "9\n1 1 1 1 2 1 2 2 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n2 2 1 1 1 1 2 2 1\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "9\n1 1 1 1 1 2 1 1 2\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "9\n2 2 2 1 1 1 2 2 1\n", "output": "2 1 2 2 2 2 1 1 1\n" }, { "input": "10\n1 1 1 1 2 2 2 1 2 1\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { "input": "5\n1 1 2 2 1\n", "output": "2 1 2 1 1\n" }, { "input": "9\n1 2 2 2 1 1 1 1 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "10\n2 2 1 1 2 1 2 2 1 2\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "9\n2 1 2 1 2 2 2 2 1\n", "output": "2 1 2 2 2 2 2 1 1\n" }, { "input": "9\n1 2 2 1 1 1 2 1 2\n", "output": "2 1 2 2 2 1 1 1 1\n" }, { "input": "10\n1 2 1 1 2 2 2 1 2 1\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "10\n1 2 2 1 2 2 2 1 2 1\n", "output": "2 1 2 2 2 2 2 1 1 1\n" }, { "input": "5\n1 2 2 2 1\n", "output": "2 1 2 2 1\n" }, { "input": "10\n1 1 1 1 2 2 2 2 1 2\n", "output": "2 1 2 2 2 2 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 2 1 1\n", "output": "2 1 2 2 1 1 1 1 1\n" }, { "input": "9\n1 1 1 1 1 1 1 2 1\n", "output": "2 1 1 1 1 1 1 1 1\n" }, { "input": "9\n1 1 2 1 2 1 2 2 2\n", "output": "2 1 2 2 2 2 1 1 1\n" } ] }
[ 0.00022491686501584357, 0.000029177052013880916, 0.00002868214272733138, 0.00002861398696643131, 0.000028591280739083203, 0.00002854192315618242, 0.000028239937032475225, 0.00002820067467684289, 0.000028189648984889192, 0.000027698712882855037, 0.00002755862399527765, 1.1909405048076925e-7 ]
764_A. Taymyr is calling you
1738
1738_180
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1, 2, ..., z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. Input The only string contains three integers — n, m and z (1 ≤ n, m, z ≤ 104). Output Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Examples Input 1 1 10 Output 10 Input 1 2 5 Output 2 Input 2 3 9 Output 1 Note Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
abc= input().split() a= int(abc[0]) b= int(abc[1]) c= int(abc[2]) d= c//a e=c//b test=[] test2=[] count=0 for i in range(1,d+1): test.append(i*a) for i in range(1,e+1): if i*b in test: count=count+1 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: a: int b: int c: int @classmethod def from_str(cls, input_: str): a, b, c = input_.split('\n')[0].split(' ') a = int(a) b = int(b) c = int(c) return cls(a, b, c) def __repr__(self): return str(self.a) + ' ' + str(self.b) + ' ' + str(self.c) + '\n'
1 1 10
O(n**2)
0
{ "public_tests": [ { "input": "1 1 10\n", "output": "10\n" }, { "input": "2 3 9\n", "output": "1\n" }, { "input": "1 2 5\n", "output": "2\n" } ], "private_tests": [ { "input": "972 1 203\n", "output": "0\n" }, { "input": "6 4 36\n", "output": "3\n" }, { "input": "550 1 754\n", "output": "1\n" }, { "input": "10 20 10000\n", "output": "500\n" }, { "input": "4 8 9\n", "output": "1\n" }, { "input": "1 1 1\n", "output": "1\n" }, { "input": "1 2 10\n", "output": "5\n" }, { "input": "10000 1 10000\n", "output": "1\n" }, { "input": "3443 2 6701\n", "output": "0\n" }, { "input": "358 2 809\n", "output": "2\n" }, { "input": "860 1 884\n", "output": "1\n" }, { "input": "7 9 2\n", "output": "0\n" }, { "input": "10000 10000 10000\n", "output": "1\n" }, { "input": "2940 1 9311\n", "output": "3\n" }, { "input": "1 10000 10000\n", "output": "1\n" }, { "input": "2 2 1\n", "output": "0\n" }, { "input": "1 1 10000\n", "output": "10000\n" }, { "input": "33 6 3005\n", "output": "45\n" }, { "input": "8 12 12\n", "output": "0\n" }, { "input": "2 2 9999\n", "output": "4999\n" }, { "input": "3 613 2275\n", "output": "1\n" }, { "input": "33 27 216\n", "output": "0\n" }, { "input": "5 1 20\n", "output": "4\n" }, { "input": "34 27 10000\n", "output": "10\n" }, { "input": "2 1 100\n", "output": "50\n" }, { "input": "4624 1 1953\n", "output": "0\n" }, { "input": "74 8 417\n", "output": "1\n" }, { "input": "2696 2 7345\n", "output": "2\n" }, { "input": "24 22 9235\n", "output": "34\n" } ], "generated_tests": [ { "input": "972 1 134\n", "output": "0\n" }, { "input": "6 8 36\n", "output": "1\n" }, { "input": "550 1 1168\n", "output": "2\n" }, { "input": "10 20 10001\n", "output": "500\n" }, { "input": "358 2 1211\n", "output": "3\n" }, { "input": "2304 1 9311\n", "output": "4\n" }, { "input": "14 6 3005\n", "output": "71\n" }, { "input": "5 1 35\n", "output": "7\n" }, { "input": "34 27 10010\n", "output": "10\n" }, { "input": "2 2 100\n", "output": "50\n" }, { "input": "24 39 9235\n", "output": "29\n" }, { "input": "6 3 36\n", "output": "6\n" }, { "input": "3 20 10001\n", "output": "166\n" }, { "input": "184 3 6701\n", "output": "12\n" }, { "input": "14 12 3005\n", "output": "35\n" }, { "input": "3 1 35\n", "output": "11\n" }, { "input": "3 2 100\n", "output": "16\n" }, { "input": "184 3 7190\n", "output": "13\n" }, { "input": "14 12 5933\n", "output": "70\n" }, { "input": "14 12 6848\n", "output": "81\n" }, { "input": "12 8 216\n", "output": "9\n" }, { "input": "14 24 6848\n", "output": "40\n" }, { "input": "2 4 69\n", "output": "17\n" }, { "input": "14 9 6848\n", "output": "54\n" }, { "input": "21 14 216\n", "output": "5\n" }, { "input": "21 9 6848\n", "output": "108\n" }, { "input": "38 9 6848\n", "output": "20\n" }, { "input": "4 2 9\n", "output": "2\n" }, { "input": "1 4 10\n", "output": "2\n" }, { "input": "3443 3 6701\n", "output": "0\n" }, { "input": "860 1 1058\n", "output": "1\n" }, { "input": "7 1 2\n", "output": "0\n" }, { "input": "1 10001 10000\n", "output": "0\n" }, { "input": "2 3 1\n", "output": "0\n" }, { "input": "1 613 2275\n", "output": "3\n" }, { "input": "41 27 216\n", "output": "0\n" }, { "input": "4624 1 963\n", "output": "0\n" }, { "input": "108 8 417\n", "output": "1\n" }, { "input": "2696 2 219\n", "output": "0\n" }, { "input": "1 2 15\n", "output": "7\n" }, { "input": "2 3 7\n", "output": "1\n" }, { "input": "972 1 73\n", "output": "0\n" }, { "input": "510 1 1168\n", "output": "2\n" }, { "input": "1 2 9\n", "output": "4\n" }, { "input": "1 4 9\n", "output": "2\n" }, { "input": "358 2 1056\n", "output": "2\n" }, { "input": "1395 1 1058\n", "output": "0\n" }, { "input": "2 1 2\n", "output": "1\n" }, { "input": "1 378 2275\n", "output": "6\n" }, { "input": "41 28 216\n", "output": "0\n" }, { "input": "108 8 153\n", "output": "0\n" }, { "input": "2696 3 219\n", "output": "0\n" }, { "input": "19 39 9235\n", "output": "12\n" }, { "input": "1 2 12\n", "output": "6\n" }, { "input": "972 1 47\n", "output": "0\n" }, { "input": "2 3 36\n", "output": "6\n" }, { "input": "2 2 9\n", "output": "4\n" }, { "input": "1 6 9\n", "output": "1\n" }, { "input": "358 2 1630\n", "output": "4\n" }, { "input": "1609 1 1058\n", "output": "0\n" }, { "input": "1 586 2275\n", "output": "3\n" }, { "input": "41 8 216\n", "output": "0\n" }, { "input": "108 8 266\n", "output": "1\n" }, { "input": "4025 3 219\n", "output": "0\n" }, { "input": "1249 1 47\n", "output": "0\n" }, { "input": "2 5 36\n", "output": "3\n" }, { "input": "2 4 9\n", "output": "2\n" }, { "input": "1 12 9\n", "output": "0\n" }, { "input": "209 2 1630\n", "output": "3\n" }, { "input": "1 586 2421\n", "output": "4\n" }, { "input": "108 16 266\n", "output": "0\n" }, { "input": "4025 2 219\n", "output": "0\n" }, { "input": "1249 1 45\n", "output": "0\n" }, { "input": "2 5 69\n", "output": "6\n" }, { "input": "3 4 9\n", "output": "0\n" }, { "input": "1 12 4\n", "output": "0\n" }, { "input": "205 2 1630\n", "output": "3\n" }, { "input": "2 586 2421\n", "output": "4\n" }, { "input": "12 14 216\n", "output": "2\n" }, { "input": "108 16 477\n", "output": "1\n" }, { "input": "6961 2 219\n", "output": "0\n" }, { "input": "590 1 45\n", "output": "0\n" }, { "input": "6 4 9\n", "output": "0\n" }, { "input": "1 12 5\n", "output": "0\n" }, { "input": "205 2 2809\n", "output": "6\n" }, { "input": "4 586 2421\n", "output": "2\n" }, { "input": "28 16 477\n", "output": "4\n" }, { "input": "10687 2 219\n", "output": "0\n" }, { "input": "590 1 57\n", "output": "0\n" }, { "input": "2 7 69\n", "output": "4\n" }, { "input": "10 4 9\n", "output": "0\n" }, { "input": "278 2 2809\n", "output": "10\n" }, { "input": "4 213 2421\n", "output": "2\n" }, { "input": "21 14 282\n", "output": "6\n" }, { "input": "7 16 477\n", "output": "4\n" }, { "input": "10687 2 364\n", "output": "0\n" }, { "input": "679 1 57\n", "output": "0\n" }, { "input": "2 7 100\n", "output": "7\n" }, { "input": "2 6 9\n", "output": "1\n" }, { "input": "278 2 2670\n", "output": "9\n" } ] }
[ 0.000041613100034929575, 0.000001810399933779264, 0.0000015042247079138421, 3.472595783283769e-7, 2.2969974851433994e-7, 2.296041380063394e-7, 2.2441002528530197e-7, 2.2417579019533621e-7, 2.238768323645683e-7, 2.2284955451121041e-7, 2.2230823357623874e-7, 2.2171112075003545e-7, 2.2167334641139412e-7, 2.2113618591821403e-7, 2.209502301689008e-7, 2.2091797390864163e-7, 2.2088775900982512e-7, 2.1961510723974914e-7, 2.195536706563392e-7, 2.1870445460875176e-7, 2.1860101080174432e-7, 2.1847057950429102e-7, 2.1816205421833476e-7, 2.1775807140251157e-7, 2.1730583520432506e-7, 2.1726351245428736e-7, 2.1718196565999878e-7, 2.1714295594929272e-7, 2.1660017226129858e-7, 2.16591356632657e-7, 2.161404071667197e-7, 2.159562949000088e-7, 2.158206248183625e-7, 2.1525755440539326e-7, 2.1524427042751057e-7, 2.1522760747660668e-7, 2.1506977519041918e-7, 2.1495025428446474e-7, 2.1455405762441538e-7, 2.1450674316267927e-7, 2.142832821287994e-7, 2.1414073169637153e-7, 2.1374811728906303e-7, 2.1344370091523997e-7, 2.1323116560103764e-7, 1.8100835228035095e-7, 1.2890512392144199e-8, 1.2888748837891642e-8, 1.2837762011393127e-8, 1.2836074719473362e-8 ]
764_A. Taymyr is calling you
1738
1738_24
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1, 2, ..., z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. Input The only string contains three integers — n, m and z (1 ≤ n, m, z ≤ 104). Output Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Examples Input 1 1 10 Output 10 Input 1 2 5 Output 2 Input 2 3 9 Output 1 Note Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
m = [int(n) for n in input().split()] count = 0 for i in range(1,m[2]+1): if i%m[0] == 0 and i%m[1] == 0: count = count + 1 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: a: int b: int c: int @classmethod def from_str(cls, input_: str): a, b, c = input_.split('\n')[0].split(' ') a = int(a) b = int(b) c = int(c) return cls(a, b, c) def __repr__(self): return str(self.a) + ' ' + str(self.b) + ' ' + str(self.c) + '\n'
1 1 10
O(n)
0.000004
{ "public_tests": [ { "input": "1 1 10\n", "output": "10\n" }, { "input": "2 3 9\n", "output": "1\n" }, { "input": "1 2 5\n", "output": "2\n" } ], "private_tests": [ { "input": "972 1 203\n", "output": "0\n" }, { "input": "6 4 36\n", "output": "3\n" }, { "input": "550 1 754\n", "output": "1\n" }, { "input": "10 20 10000\n", "output": "500\n" }, { "input": "4 8 9\n", "output": "1\n" }, { "input": "1 1 1\n", "output": "1\n" }, { "input": "1 2 10\n", "output": "5\n" }, { "input": "10000 1 10000\n", "output": "1\n" }, { "input": "3443 2 6701\n", "output": "0\n" }, { "input": "358 2 809\n", "output": "2\n" }, { "input": "860 1 884\n", "output": "1\n" }, { "input": "7 9 2\n", "output": "0\n" }, { "input": "10000 10000 10000\n", "output": "1\n" }, { "input": "2940 1 9311\n", "output": "3\n" }, { "input": "1 10000 10000\n", "output": "1\n" }, { "input": "2 2 1\n", "output": "0\n" }, { "input": "1 1 10000\n", "output": "10000\n" }, { "input": "33 6 3005\n", "output": "45\n" }, { "input": "8 12 12\n", "output": "0\n" }, { "input": "2 2 9999\n", "output": "4999\n" }, { "input": "3 613 2275\n", "output": "1\n" }, { "input": "33 27 216\n", "output": "0\n" }, { "input": "5 1 20\n", "output": "4\n" }, { "input": "34 27 10000\n", "output": "10\n" }, { "input": "2 1 100\n", "output": "50\n" }, { "input": "4624 1 1953\n", "output": "0\n" }, { "input": "74 8 417\n", "output": "1\n" }, { "input": "2696 2 7345\n", "output": "2\n" }, { "input": "24 22 9235\n", "output": "34\n" } ], "generated_tests": [ { "input": "972 1 134\n", "output": "0\n" }, { "input": "6 8 36\n", "output": "1\n" }, { "input": "550 1 1168\n", "output": "2\n" }, { "input": "10 20 10001\n", "output": "500\n" }, { "input": "358 2 1211\n", "output": "3\n" }, { "input": "2304 1 9311\n", "output": "4\n" }, { "input": "14 6 3005\n", "output": "71\n" }, { "input": "5 1 35\n", "output": "7\n" }, { "input": "34 27 10010\n", "output": "10\n" }, { "input": "2 2 100\n", "output": "50\n" }, { "input": "24 39 9235\n", "output": "29\n" }, { "input": "6 3 36\n", "output": "6\n" }, { "input": "3 20 10001\n", "output": "166\n" }, { "input": "184 3 6701\n", "output": "12\n" }, { "input": "14 12 3005\n", "output": "35\n" }, { "input": "3 1 35\n", "output": "11\n" }, { "input": "3 2 100\n", "output": "16\n" }, { "input": "184 3 7190\n", "output": "13\n" }, { "input": "14 12 5933\n", "output": "70\n" }, { "input": "14 12 6848\n", "output": "81\n" }, { "input": "12 8 216\n", "output": "9\n" }, { "input": "14 24 6848\n", "output": "40\n" }, { "input": "2 4 69\n", "output": "17\n" }, { "input": "14 9 6848\n", "output": "54\n" }, { "input": "21 14 216\n", "output": "5\n" }, { "input": "21 9 6848\n", "output": "108\n" }, { "input": "38 9 6848\n", "output": "20\n" }, { "input": "4 2 9\n", "output": "2\n" }, { "input": "1 4 10\n", "output": "2\n" }, { "input": "3443 3 6701\n", "output": "0\n" }, { "input": "860 1 1058\n", "output": "1\n" }, { "input": "7 1 2\n", "output": "0\n" }, { "input": "1 10001 10000\n", "output": "0\n" }, { "input": "2 3 1\n", "output": "0\n" }, { "input": "1 613 2275\n", "output": "3\n" }, { "input": "41 27 216\n", "output": "0\n" }, { "input": "4624 1 963\n", "output": "0\n" }, { "input": "108 8 417\n", "output": "1\n" }, { "input": "2696 2 219\n", "output": "0\n" }, { "input": "1 2 15\n", "output": "7\n" }, { "input": "2 3 7\n", "output": "1\n" }, { "input": "972 1 73\n", "output": "0\n" }, { "input": "510 1 1168\n", "output": "2\n" }, { "input": "1 2 9\n", "output": "4\n" }, { "input": "1 4 9\n", "output": "2\n" }, { "input": "358 2 1056\n", "output": "2\n" }, { "input": "1395 1 1058\n", "output": "0\n" }, { "input": "2 1 2\n", "output": "1\n" }, { "input": "1 378 2275\n", "output": "6\n" }, { "input": "41 28 216\n", "output": "0\n" }, { "input": "108 8 153\n", "output": "0\n" }, { "input": "2696 3 219\n", "output": "0\n" }, { "input": "19 39 9235\n", "output": "12\n" }, { "input": "1 2 12\n", "output": "6\n" }, { "input": "972 1 47\n", "output": "0\n" }, { "input": "2 3 36\n", "output": "6\n" }, { "input": "2 2 9\n", "output": "4\n" }, { "input": "1 6 9\n", "output": "1\n" }, { "input": "358 2 1630\n", "output": "4\n" }, { "input": "1609 1 1058\n", "output": "0\n" }, { "input": "1 586 2275\n", "output": "3\n" }, { "input": "41 8 216\n", "output": "0\n" }, { "input": "108 8 266\n", "output": "1\n" }, { "input": "4025 3 219\n", "output": "0\n" }, { "input": "1249 1 47\n", "output": "0\n" }, { "input": "2 5 36\n", "output": "3\n" }, { "input": "2 4 9\n", "output": "2\n" }, { "input": "1 12 9\n", "output": "0\n" }, { "input": "209 2 1630\n", "output": "3\n" }, { "input": "1 586 2421\n", "output": "4\n" }, { "input": "108 16 266\n", "output": "0\n" }, { "input": "4025 2 219\n", "output": "0\n" }, { "input": "1249 1 45\n", "output": "0\n" }, { "input": "2 5 69\n", "output": "6\n" }, { "input": "3 4 9\n", "output": "0\n" }, { "input": "1 12 4\n", "output": "0\n" }, { "input": "205 2 1630\n", "output": "3\n" }, { "input": "2 586 2421\n", "output": "4\n" }, { "input": "12 14 216\n", "output": "2\n" }, { "input": "108 16 477\n", "output": "1\n" }, { "input": "6961 2 219\n", "output": "0\n" }, { "input": "590 1 45\n", "output": "0\n" }, { "input": "6 4 9\n", "output": "0\n" }, { "input": "1 12 5\n", "output": "0\n" }, { "input": "205 2 2809\n", "output": "6\n" }, { "input": "4 586 2421\n", "output": "2\n" }, { "input": "28 16 477\n", "output": "4\n" }, { "input": "10687 2 219\n", "output": "0\n" }, { "input": "590 1 57\n", "output": "0\n" }, { "input": "2 7 69\n", "output": "4\n" }, { "input": "10 4 9\n", "output": "0\n" }, { "input": "278 2 2809\n", "output": "10\n" }, { "input": "4 213 2421\n", "output": "2\n" }, { "input": "21 14 282\n", "output": "6\n" }, { "input": "7 16 477\n", "output": "4\n" }, { "input": "10687 2 364\n", "output": "0\n" }, { "input": "679 1 57\n", "output": "0\n" }, { "input": "2 7 100\n", "output": "7\n" }, { "input": "2 6 9\n", "output": "1\n" }, { "input": "278 2 2670\n", "output": "9\n" } ] }
[ 0.00010499856366777753, 0.0000357330649448208, 0.00003439385169225307, 0.00003426609898109703, 0.000033931730639477716, 0.00003340164967356862, 0.000023553137347027973, 0.000017930186339051576, 0.000017888827674278847, 0.0000177738280430507, 0.00001746245660784528, 0.000017461847178212416, 0.000017221877021416085, 0.00001721598102873689, 0.00001720044592711976, 0.000017037443687172204, 0.000016963712576486017, 0.00001688926864346591, 0.00001670077157998252, 0.000016365500819493007, 0.000015828842971481645, 0.000015079402179851397, 0.000014342932583041962, 0.000014298843599759615, 0.000014104204545454546, 0.000013959123989291959, 0.00001395897032069493, 0.000013957106930179196, 0.000013804013548951048, 0.000013763031195367136, 0.000013592577114291958, 0.000013445968517810315, 0.000013389334175590035, 0.000013105520842438813, 0.000013069920154064685, 0.00001266894565395542, 0.000012514063852163461, 0.00001189787041083916, 0.000011547192744755245, 0.000011268862024694057, 0.000010965402903736889, 0.000010656320845170455, 0.000010180296915974652, 0.000010174024065777972, 0.000010047917531687062, 0.000010022989715362764, 0.000009791787642045454, 0.00000969108823208042, 0.000009632691351617133, 0.000009056233132102273, 0.000009004826076267482, 0.000009002522358500873, 0.000008848188169252624, 0.000008822431749890735, 0.000008804341236888114, 0.000008774648901879371, 0.000008705935519558568, 0.000008654906632430071, 0.000007901671000874126, 0.000007770350579108392, 0.000007762747596153846, 0.000007726897085336539, 0.000007560017045454546, 0.000007437325229458042, 0.000007368317212084789, 0.000007273938319493008, 0.0000072530460145323425, 0.000007245309891280595, 0.0000071644122186407334, 0.000007147241313374127, 0.0000071054026715472034, 0.000007033229881446679, 0.000007002607380900352, 0.000006919123115166085, 0.000006884267209353148, 0.000006876056408435315, 0.000006825944615930945, 0.0000067444691870629385, 0.000006575241996284966, 0.000006297013057255245, 0.000006261563811188812, 0.000006247511595826049, 0.0000061650115411931825, 0.0000060055407834353145, 0.000005983225702032343, 0.000005863549210555071, 0.000005838245670345281, 0.00000580989996722028, 0.0000057788192335008746, 0.000005743205610795455, 0.000005737313292176574, 0.000005645836852600525, 0.000005639221959680945, 0.000005636148164335665, 0.000005556683743990385, 0.000005535656618771853, 0.000005524859552556819, 0.00000550412741750437, 0.000005489884096372378, 0.000005363810232736014, 0.000005362135858282342, 0.000005348928389969406, 0.000005161541616586538, 0.000005160111300808567, 0.000005129402507648602, 0.000005101178581184441, 0.000004803911508413462, 0.000004789956348339161, 0.000004753188483391608, 0.000004475855209243881, 0.0000044501113008085665, 0.0000044500129070148604, 0.000004442289212740385, 0.000004428345880681818, 0.000004419462617460664, 0.000004382374310260053, 0.000004331883454436189, 0.000004146185738090035, 0.000004025305179195804, 0.000004014658858719406, 0.000004002915278081294, 0.000003997254957932692, 0.000003973292818509616, 0.000003905289199082168, 0.000003900481779938811, 0.0000038990291193181826, 0.000003890150636472902, 0.000003864587890625, 0.000003858886978256119, 0.000003842880654501748, 0.000003817312568291084, 0.0000038068670372596153, 0.00000380527534965035, 0.0000037844196623688813, 0.00000377979139805507, 0.0000037734103064903843, 0.000003766554113854896, 0.000003759537218640734, 0.0000037520735631555944, 0.0000037519039144449303, 0.000003750916958041959, 0.0000037461943973994757, 0.000003738965881774475, 0.0000037384057173295457, 0.000003729888234812063, 0.000003718094569493007, 0.0000037107200748470284, 0.0000037102493034309444, 0.0000037023627349213284, 0.00000370157693673514, 0.000003691950939685315, 0.0000036169290182473777, 0.0000036100027726180067, 0.000003579844214379371, 0.000003566267482517483, 0.000003556424524694056, 0.0000035555732353583914, 0.0000035520559303977276, 0.000003533163557145979, 0.00000353203201486014, 0.000003526304236778846, 0.00000352531590089598, 0.0000035237575803103147, 0.0000035227653381774473, 0.0000035111943564248254, 0.0000035024605550699303, 0.0000035009349732298953, 0.0000034988581730769236, 0.0000034984245793269235, 0.0000034954033817744756, 0.000003464588723776224, 0.00000341715896798514, 0.0000034168476289335663, 0.0000033933384506118882, 0.000003358853406359266, 0.000003342514313811189, 0.0000032588031577797205, 0.0000031348455802010494, 0.0000031263439002403846, 0.000003126179550917832, 0.0000030548201076267486, 0.0000030467083697552444, 0.0000030406971427010497, 0.0000030356076404064686, 0.0000030310528436407345, 0.0000030285494017701053, 0.000003026846741149476, 0.000003025053157779721, 0.00000301884209735577, 0.0000030090181790865387, 0.0000030071016990821676, 0.0000030059028354458046, 0.0000030036460609702798, 0.000003001697088068182, 0.0000029996040209790212, 0.000002999501543378497, 0.0000029971292750218535, 0.0000029960801873907344, 0.0000029960374918050704, 0.0000029955419990166086, 0.0000029947868362106645, 0.0000029946574928977273, 0.000002993117720170455, 0.000002992843627076049, 0.0000029922426109047202, 0.000002992097533326049, 0.0000029920679632867135, 0.0000029910411248907343, 0.0000029903904611013985, 0.000002989733774038462, 0.000002989340731534091, 0.00000298868159965035, 0.0000029881329900568184, 0.000002987769722465035, 0.000002987442731097028, 0.00000298720699027535, 0.0000029871660565996507, 0.000002985018370301574, 0.000002984467111013986, 0.0000029843153135926574, 0.0000029841030102709795, 0.000002983339515952797, 0.000002982704163024476, 0.0000029806308457167837, 0.0000029805251447770983, 0.0000029805049715909093, 0.000002980210186298077, 0.0000029798069001311193, 0.000002979558361560315, 0.000002976917668269231, 0.000002975673800808566, 0.0000029748821569055944, 0.0000029734873661494756, 0.000002969180575284091, 0.0000029688200666520985, 0.0000029684897699956297, 0.0000029677426382211542, 0.0000029669861232517482, 0.0000029660788762019232, 0.0000029649616067526225, 0.0000029023439002403847, 0.0000025804110850087416, 0.0000019823856943837418, 0.0000018289528928103145, 5.001511964597902e-7, 3.2109993717220277e-7, 1.020451813811189e-8 ]
52_A. 123-sequence
2193
2193_138
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
import sys n_nums = int(sys.stdin.readline()) values = [int(x) for x in sys.stdin.readline().split()] one, two, three = 0, 0, 0 for i in values: if i == 1: one += 1 if i == 2: two += 1 if i == 3: three += 1 result = one + two + three - max(one, two, three) print(result)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int a_list: List[int] @classmethod def from_str(cls, input_: str): n, a_list, _ = input_.split('\n') n = int(n) a_list = [int(x) for x in a_list.split(' ')] assert n == len(a_list) return cls(n, a_list) def __repr__(self): return str(self.n) + '\n' + ' '.join([str(x) for x in self.a_list]) + '\n'
9 1 3 2 2 2 1 1 2 3
O(n)
0.000004
{ "public_tests": [ { "input": "9\n1 3 2 2 2 1 1 2 3\n", "output": "5\n" } ], "private_tests": [ { "input": "1\n1\n", "output": "0\n" }, { "input": "2\n3 2\n", "output": "1\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2\n", "output": "10\n" }, { "input": "6\n3 3 2 2 1 3\n", "output": "3\n" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1\n", "output": "7\n" }, { "input": "1\n3\n", "output": "0\n" }, { "input": "2\n2 1\n", "output": "1\n" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2\n", "output": "10\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "19\n" }, { "input": "1\n2\n", "output": "0\n" }, { "input": "2\n3 1\n", "output": "1\n" } ], "generated_tests": [ { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 3\n", "output": "9\n" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 2 1 2 3 3 3 2\n", "output": "10\n" }, { "input": "9\n1 3 2 2 3 1 1 2 3\n", "output": "6\n" }, { "input": "2\n1 2\n", "output": "1\n" }, { "input": "6\n3 3 3 2 1 3\n", "output": "2\n" }, { "input": "9\n1 3 2 2 3 1 2 2 3\n", "output": "5\n" }, { "input": "9\n1 3 2 2 3 2 2 2 3\n", "output": "4\n" }, { "input": "9\n2 3 2 2 3 2 2 2 3\n", "output": "3\n" }, { "input": "12\n2 1 3 1 2 1 3 2 2 1 2 1\n", "output": "7\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "19\n" }, { "input": "15\n3 2 1 1 1 1 3 2 3 3 3 1 1 3 3\n", "output": "8\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 3 2 1 3 1\n", "output": "18\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 1 1 2 3 2\n", "output": "9\n" }, { "input": "18\n2 3 2 1 3 3 2 1 2 3 3 3 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 2 2 2 3 3 1 1 3 3\n", "output": "10\n" }, { "input": "2\n2 3\n", "output": "1\n" }, { "input": "2\n1 3\n", "output": "1\n" }, { "input": "15\n3 2 2 1 1 1 3 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 2 3 2 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 2 3 1 2 3 2\n", "output": "9\n" }, { "input": "12\n3 1 3 1 2 2 3 2 2 1 2 1\n", "output": "7\n" }, { "input": "9\n1 3 2 2 2 1 1 3 3\n", "output": "6\n" }, { "input": "15\n3 1 1 1 1 1 3 2 2 3 3 1 2 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 1 1 2 3 2\n", "output": "9\n" }, { "input": "6\n3 3 3 3 1 3\n", "output": "1\n" }, { "input": "18\n2 3 2 1 3 2 2 1 2 3 3 3 1 2 3 3 3 2\n", "output": "10\n" }, { "input": "9\n1 1 2 2 3 1 2 2 3\n", "output": "5\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 3 3 1 1 3 3\n", "output": "8\n" }, { "input": "9\n1 3 2 2 3 2 2 2 1\n", "output": "4\n" }, { "input": "15\n3 2 1 1 2 1 2 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 2 1 1 1 3 2 2 3 2 1 1 3 3\n", "output": "10\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 3 3 1 1 2 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 3 1 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 3 2 3 2 1 3 3 2 1 3 3\n", "output": "8\n" }, { "input": "12\n2 1 3 1 2 2 3 2 2 1 2 1\n", "output": "6\n" }, { "input": "9\n1 2 2 2 2 1 1 3 3\n", "output": "5\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 1 1 1 3 2\n", "output": "9\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 3 3 1 2 3 3\n", "output": "8\n" }, { "input": "9\n1 3 2 2 3 2 1 2 1\n", "output": "5\n" }, { "input": "15\n2 2 1 1 2 1 2 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 2 2 1 3 1 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "9\n1 2 2 2 3 1 1 3 3\n", "output": "6\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 1 2 1 3 2\n", "output": "9\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 1 3 1 2 3 3\n", "output": "9\n" }, { "input": "9\n1 3 1 2 3 2 1 2 1\n", "output": "5\n" }, { "input": "15\n2 2 1 1 2 1 3 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 3 2 1 3 1 1 3 3 2 1 3 3\n", "output": "8\n" }, { "input": "9\n1 2 2 3 3 1 1 3 3\n", "output": "5\n" }, { "input": "15\n3 2 1 3 2 1 3 1 1 3 3 3 1 3 3\n", "output": "7\n" }, { "input": "15\n3 2 1 1 2 1 3 1 1 3 3 3 1 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 3 1 1 3 3 3 1 3 2\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 3 3 3 1 2 3 2\n", "output": "9\n" }, { "input": "18\n2 3 2 1 2 3 3 1 2 3 3 3 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 3 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "19\n" }, { "input": "9\n1 3 2 2 2 1 2 2 3\n", "output": "4\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 3 3 3\n", "output": "8\n" }, { "input": "18\n2 3 2 1 2 3 2 1 2 2 3 2 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 2 1 2 3 2\n", "output": "9\n" }, { "input": "18\n2 3 2 1 3 3 2 1 2 3 3 3 1 1 3 3 3 2\n", "output": "9\n" }, { "input": "9\n1 3 2 1 3 1 2 2 3\n", "output": "6\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 3 1 2 3 3\n", "output": "9\n" }, { "input": "12\n2 1 2 1 2 1 3 2 2 1 2 1\n", "output": "6\n" }, { "input": "15\n3 2 2 1 1 1 2 2 2 3 3 1 1 3 3\n", "output": "10\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 2 3 1 1 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 2 2 1 3 3 2 1 3 3\n", "output": "10\n" }, { "input": "15\n3 2 1 2 1 1 3 2 2 2 3 1 2 3 2\n", "output": "8\n" }, { "input": "12\n3 1 3 1 2 2 3 2 2 1 1 1\n", "output": "7\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 3 3 2 3 1\n", "output": "18\n" }, { "input": "9\n1 1 2 2 2 1 1 3 3\n", "output": "5\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 3 3 1 1 3 2\n", "output": "9\n" }, { "input": "15\n3 2 2 1 1 1 3 2 2 3 2 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 3 3 1 2 2 3\n", "output": "7\n" }, { "input": "15\n3 2 2 1 2 1 3 1 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 3 2 3 2 1 3 2 2 1 3 3\n", "output": "9\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 1 2 1 3 1\n", "output": "18\n" }, { "input": "9\n1 3 2 2 3 3 1 2 1\n", "output": "6\n" }, { "input": "15\n2 2 1 1 2 1 2 2 2 1 3 1 2 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 2 2 1 3 1 1 3 3 2 2 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 2 1 2 1 3 2\n", "output": "8\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 1 1 1 2 3 3\n", "output": "9\n" }, { "input": "15\n2 2 1 1 2 2 3 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 3 2 1 3 1 2 3 3 2 1 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 2 1 1 3 3 3 1 3 2\n", "output": "9\n" }, { "input": "18\n1 3 2 1 2 3 3 1 2 3 3 3 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "30\n2 1 3 2 3 2 3 2 2 3 2 2 3 3 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "18\n" }, { "input": "18\n2 3 1 1 3 3 2 1 2 3 3 3 1 1 3 3 3 2\n", "output": "9\n" }, { "input": "12\n2 2 2 1 2 1 3 2 2 1 2 1\n", "output": "5\n" } ] }
[ 0.000010213638562609267, 0.000009107361451048951, 0.000008560072101726398, 0.000008410704340581294, 0.000008404965676901224, 0.000008396724199628496, 0.000007263138385052447, 0.000006483129001857518, 0.000006359349281577797, 0.000006244130244755245, 0.000006161197497814685, 0.000006096963355004371, 0.000006008730837521853, 0.000005967456266389861, 0.000005962577223557693, 0.000005885444998361014, 0.000005820476617132867, 0.0000057059742132867135, 0.000005592249057583042, 0.000005590948098776224, 0.0000055814240329982524, 0.00000556901129534528, 0.0000055678392701048955, 0.000005537351357626748, 0.00000546407298951049, 0.000005393572415865384, 0.000004357865835336539, 0.000004302389655266609, 0.000004267356902862762, 0.000004221234224759616, 0.000004212214857408217, 0.000004172070681271853, 0.000004164424005681818, 0.000004144160128933567, 0.000004132722792832168, 0.000004069695667613637, 0.00000401032574847028, 0.000004007762510926573, 0.000004007642591783217, 0.000004002260434877623, 0.000003996924155922204, 0.000003995044061407343, 0.000003994651087194056, 0.00000398799291138549, 0.000003983666193181819, 0.0000039823385325611885, 0.000003974742132867133, 0.000003951832700502622, 0.000003949186871722029, 0.000003944231834571679, 0.000003922889177229022, 0.00000390664533708479, 0.000003865148737980769, 0.00000382068707659528, 0.000003813130354020979, 0.000003765782410948427, 0.0000037558661085008745, 0.00000374912330638112, 0.0000037454442471590913, 0.000003743903313483392, 0.000003733588846700175, 0.000003731395077578671, 0.000003721468067089161, 0.000003715785470388986, 0.0000037152712658435322, 0.0000037144740903627626, 0.0000037132331867351405, 0.0000037131287560096157, 0.0000037130695339816434, 0.000003708797079873252, 0.000003704898669689685, 0.000003702668419471154, 0.000003702289431271853, 0.0000036999269148819933, 0.0000036997575939685317, 0.0000036995760216346156, 0.000003695659063592657, 0.000003687598940122378, 0.0000036795329709353146, 0.0000036780484047202804, 0.000003673649229676574, 0.000003672180807473776, 0.0000036714758522727277, 0.00000366549689958479, 0.000003665117447006119, 0.0000036549944957386362, 0.0000036539595580201053, 0.000003651924142263986, 0.0000036506502950174826, 0.0000036480254725743016, 0.0000036398001802884614, 0.000003575930165537588, 0.0000031485612980769235, 0.000002134800248579546, 0.000001920642496175699, 0.0000015408466592001747, 0.0000015347115248033218, 0.0000015288482435533216, 0.0000015234980605332168, 0.000001514870219624126, 0.000001513936366368007, 0.000001513925030048077, 0.000001506293665319056, 0.0000015035064739947552, 3.0768821022727276e-9, 2.269947825611888e-9, 6.254507211538462e-10, 1.0303758741258742e-10, 8.236587631118883e-11 ]
52_A. 123-sequence
2193
2193_70
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
n = int(input()) l = list(map(int,input().split())) freq = {} for item in l: if (item in freq): freq[item] += 1 else: freq[item] = 1 l = list(sorted(freq.values(),reverse=True)) l.remove(l[0]) print(sum(l))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int a_list: List[int] @classmethod def from_str(cls, input_: str): n, a_list, _ = input_.split('\n') n = int(n) a_list = [int(x) for x in a_list.split(' ')] assert n == len(a_list) return cls(n, a_list) def __repr__(self): return str(self.n) + '\n' + ' '.join([str(x) for x in self.a_list]) + '\n'
9 1 3 2 2 2 1 1 2 3
O(nlogn)
0.000024
{ "public_tests": [ { "input": "9\n1 3 2 2 2 1 1 2 3\n", "output": "5\n" } ], "private_tests": [ { "input": "1\n1\n", "output": "0\n" }, { "input": "2\n3 2\n", "output": "1\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2\n", "output": "10\n" }, { "input": "6\n3 3 2 2 1 3\n", "output": "3\n" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1\n", "output": "7\n" }, { "input": "1\n3\n", "output": "0\n" }, { "input": "2\n2 1\n", "output": "1\n" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2\n", "output": "10\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "19\n" }, { "input": "1\n2\n", "output": "0\n" }, { "input": "2\n3 1\n", "output": "1\n" } ], "generated_tests": [ { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 3\n", "output": "9\n" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 2 1 2 3 3 3 2\n", "output": "10\n" }, { "input": "9\n1 3 2 2 3 1 1 2 3\n", "output": "6\n" }, { "input": "2\n1 2\n", "output": "1\n" }, { "input": "6\n3 3 3 2 1 3\n", "output": "2\n" }, { "input": "9\n1 3 2 2 3 1 2 2 3\n", "output": "5\n" }, { "input": "9\n1 3 2 2 3 2 2 2 3\n", "output": "4\n" }, { "input": "9\n2 3 2 2 3 2 2 2 3\n", "output": "3\n" }, { "input": "12\n2 1 3 1 2 1 3 2 2 1 2 1\n", "output": "7\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "19\n" }, { "input": "15\n3 2 1 1 1 1 3 2 3 3 3 1 1 3 3\n", "output": "8\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 3 2 1 3 1\n", "output": "18\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 1 1 2 3 2\n", "output": "9\n" }, { "input": "18\n2 3 2 1 3 3 2 1 2 3 3 3 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 2 2 2 3 3 1 1 3 3\n", "output": "10\n" }, { "input": "2\n2 3\n", "output": "1\n" }, { "input": "2\n1 3\n", "output": "1\n" }, { "input": "15\n3 2 2 1 1 1 3 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 3 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 2 3 2 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 2 3 1 2 3 2\n", "output": "9\n" }, { "input": "12\n3 1 3 1 2 2 3 2 2 1 2 1\n", "output": "7\n" }, { "input": "9\n1 3 2 2 2 1 1 3 3\n", "output": "6\n" }, { "input": "15\n3 1 1 1 1 1 3 2 2 3 3 1 2 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 1 1 2 3 2\n", "output": "9\n" }, { "input": "6\n3 3 3 3 1 3\n", "output": "1\n" }, { "input": "18\n2 3 2 1 3 2 2 1 2 3 3 3 1 2 3 3 3 2\n", "output": "10\n" }, { "input": "9\n1 1 2 2 3 1 2 2 3\n", "output": "5\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 3 3 1 1 3 3\n", "output": "8\n" }, { "input": "9\n1 3 2 2 3 2 2 2 1\n", "output": "4\n" }, { "input": "15\n3 2 1 1 2 1 2 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 2 1 1 1 3 2 2 3 2 1 1 3 3\n", "output": "10\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 3 3 1 1 2 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 3 1 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 3 2 3 2 1 3 3 2 1 3 3\n", "output": "8\n" }, { "input": "12\n2 1 3 1 2 2 3 2 2 1 2 1\n", "output": "6\n" }, { "input": "9\n1 2 2 2 2 1 1 3 3\n", "output": "5\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 1 1 1 3 2\n", "output": "9\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 3 3 1 2 3 3\n", "output": "8\n" }, { "input": "9\n1 3 2 2 3 2 1 2 1\n", "output": "5\n" }, { "input": "15\n2 2 1 1 2 1 2 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 2 2 1 3 1 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "9\n1 2 2 2 3 1 1 3 3\n", "output": "6\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 1 2 1 3 2\n", "output": "9\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 1 3 1 2 3 3\n", "output": "9\n" }, { "input": "9\n1 3 1 2 3 2 1 2 1\n", "output": "5\n" }, { "input": "15\n2 2 1 1 2 1 3 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 3 2 1 3 1 1 3 3 2 1 3 3\n", "output": "8\n" }, { "input": "9\n1 2 2 3 3 1 1 3 3\n", "output": "5\n" }, { "input": "15\n3 2 1 3 2 1 3 1 1 3 3 3 1 3 3\n", "output": "7\n" }, { "input": "15\n3 2 1 1 2 1 3 1 1 3 3 3 1 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 3 1 1 3 3 3 1 3 2\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 3 3 3 1 2 3 2\n", "output": "9\n" }, { "input": "18\n2 3 2 1 2 3 3 1 2 3 3 3 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 3 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "19\n" }, { "input": "9\n1 3 2 2 2 1 2 2 3\n", "output": "4\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 3 3 3\n", "output": "8\n" }, { "input": "18\n2 3 2 1 2 3 2 1 2 2 3 2 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 2 1 2 3 2\n", "output": "9\n" }, { "input": "18\n2 3 2 1 3 3 2 1 2 3 3 3 1 1 3 3 3 2\n", "output": "9\n" }, { "input": "9\n1 3 2 1 3 1 2 2 3\n", "output": "6\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 3 3 1 2 3 3\n", "output": "9\n" }, { "input": "12\n2 1 2 1 2 1 3 2 2 1 2 1\n", "output": "6\n" }, { "input": "15\n3 2 2 1 1 1 2 2 2 3 3 1 1 3 3\n", "output": "10\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 2 3 1 1 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 2 2 1 3 3 2 1 3 3\n", "output": "10\n" }, { "input": "15\n3 2 1 2 1 1 3 2 2 2 3 1 2 3 2\n", "output": "8\n" }, { "input": "12\n3 1 3 1 2 2 3 2 2 1 1 1\n", "output": "7\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 3 3 2 3 1\n", "output": "18\n" }, { "input": "9\n1 1 2 2 2 1 1 3 3\n", "output": "5\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 3 3 1 1 3 2\n", "output": "9\n" }, { "input": "15\n3 2 2 1 1 1 3 2 2 3 2 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 2 1 2 1 2 2 2 3 3 1 2 2 3\n", "output": "7\n" }, { "input": "15\n3 2 2 1 2 1 3 1 1 3 3 2 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 3 2 3 2 1 3 2 2 1 3 3\n", "output": "9\n" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 1 2 1 1 3 1 3 2 1 2 3 1 1 1 2 1 3 1\n", "output": "18\n" }, { "input": "9\n1 3 2 2 3 3 1 2 1\n", "output": "6\n" }, { "input": "15\n2 2 1 1 2 1 2 2 2 1 3 1 2 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 2 2 1 3 1 1 3 3 2 2 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 1 2 1 3 2 2 2 1 2 1 3 2\n", "output": "8\n" }, { "input": "15\n3 3 1 1 2 1 3 2 2 1 1 1 2 3 3\n", "output": "9\n" }, { "input": "15\n2 2 1 1 2 2 3 2 2 1 3 1 1 3 3\n", "output": "9\n" }, { "input": "15\n3 2 1 3 2 1 3 1 2 3 3 2 1 3 3\n", "output": "8\n" }, { "input": "15\n3 2 1 1 2 1 2 1 1 3 3 3 1 3 2\n", "output": "9\n" }, { "input": "18\n1 3 2 1 2 3 3 1 2 3 3 3 1 2 3 3 3 2\n", "output": "9\n" }, { "input": "30\n2 1 3 2 3 2 3 2 2 3 2 2 3 3 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1\n", "output": "18\n" }, { "input": "18\n2 3 1 1 3 3 2 1 2 3 3 3 1 1 3 3 3 2\n", "output": "9\n" }, { "input": "12\n2 2 2 1 2 1 3 2 2 1 2 1\n", "output": "5\n" } ] }
[ 0.000028065074117242925, 0.000027826829105092145, 0.000027610124015678537, 0.000023872956337746405, 0.000023658734971269225, 0.000023564148328234268, 0.00002328495278956579, 0.000020411168241298573, 0.000008429863294908216, 0.0000011598156727295213, 3.494198262674825e-7, 3.490392127403846e-7, 3.4871984265734264e-7, 3.4836306271853145e-7, 3.4813617242132867e-7, 3.4793363472465036e-7, 3.4757828889860145e-7, 3.471474677666084e-7, 3.4704350142045457e-7, 3.4656319656905595e-7, 3.45724295236014e-7, 3.451914335664336e-7, 2.3137627021416087e-7, 1.3474337576486015e-7 ]
1494_A. ABC String
1414
1414_23
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'. A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not. You want to find a string b that consists of n characters such that: * b is a regular bracket sequence; * if for some i and j (1 ≤ i, j ≤ n) a_i=a_j, then b_i=b_j. In other words, you want to replace all occurrences of 'A' with the same type of bracket, then all occurrences of 'B' with the same type of bracket and all occurrences of 'C' with the same type of bracket. Your task is to determine if such a string b exists. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases. Then the descriptions of t testcases follow. The only line of each testcase contains a string a. a consists only of uppercase letters 'A', 'B' and 'C'. Let n be the length of a. It is guaranteed that n is even and 2 ≤ n ≤ 50. Output For each testcase print "YES" if there exists such a string b that: * b is a regular bracket sequence; * if for some i and j (1 ≤ i, j ≤ n) a_i=a_j, then b_i=b_j. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 4 AABBAC CACA BBBBAC ABCA Output YES YES NO NO Note In the first testcase one of the possible strings b is "(())()". In the second testcase one of the possible strings b is "()()".
def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() import string import sys from heapq import heappop , heappush, heapify from bisect import * from collections import deque , Counter , defaultdict from math import * from itertools import permutations , accumulate dx = [-1 , 1 , 0 , 0 ] dy = [0 , 0 , 1 , - 1] def helper(s): if s[0]==s[-1]: print('NO') return a=[] start=s[0] end=s[-1] flag=0 for i in s: if i==start: a.append('(') elif i==end: if len(a)==0: flag=1 break a.pop() else: a.append('(') if len(a)==0 and flag==0: print('YES') return a=[] for i in s: if i==s[0]: a.append('(') elif i==end: if len(a)==0: print('NO') return a.pop() else: if len(a)==0: print('NO') return a.pop() if len(a)==0: print('YES') else: print("NO") for tt in range(INT()): s=STRING() helper(s)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int strings: List[str] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) strings = lines[1:-1] # exclude the first line and the last empty line assert len(strings) == n return cls(n, strings) def __repr__(self): return str(self.n) + '\n' + '\n'.join(self.strings) + '\n'
4 AABBAC CACA BBBBAC ABCA
O(n**2)
0.00003
{ "public_tests": [ { "input": "4\nAABBAC\nCACA\nBBBBAC\nABCA\n", "output": "\nYES\nYES\nNO\nNO\n" } ], "private_tests": [ { "input": "12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nCAAB\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "1\nAAAAABBBBBCCCCCCCCCC\n", "output": "YES\n" }, { "input": "28\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nAABBAC\nCACA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "19\nCA\nBA\nCC\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nCA\nAB\nAA\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "28\nBA\nCABC\nAB\nAB\nBC\nAC\nCBCA\nCCAABC\nCBAA\nBACA\nABCBAA\nCCABAB\nBC\nABAA\nAABC\nACACAC\nABAA\nABBB\nBBBCAB\nAC\nCB\nBBCC\nCB\nBC\nCBABAB\nBAAABC\nBC\nCA\n", "output": "YES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" } ], "generated_tests": [ { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nBAAC\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nCA\nBA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nBC\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "1\nAABAABBBABCCCCCCCCCC\n", "output": "YES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nAB\nCA\nCA\nAA\nAA\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "19\nCA\nBA\nCC\nAC\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nCA\nAB\nAA\nAC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "4\nAABBAC\nCACA\nBABBAC\nABCA\n", "output": "YES\nYES\nYES\nNO\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nAB\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "3\nAAAB\nBAAC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nCA\nBA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "19\nCA\nAA\nCC\nAC\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nAB\nBB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCCAAAB\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nABBAAC\nCACA\nBBBBAC\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "1\nAABAABBAACCCCCCCCCCB\n", "output": "NO\n" }, { "input": "10\nAC\nBA\nCC\nAC\nCA\nCC\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nAABC\nABCA\n", "output": "NO\nYES\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nAC\nBB\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nBB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBABAC\nABCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nBB\nBB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAA\nCB\nBA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAABBCABAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nACAB\nABCA\n", "output": "YES\nYES\nNO\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nAACC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBC\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAB\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "4\nAABBAC\nCACA\nBBBBAC\nACBA\n", "output": "YES\nYES\nNO\nNO\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCC\nAB\nCA\nCA\nAA\nAA\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "4\nAABAAC\nCACA\nBABBAC\nABCA\n", "output": "NO\nYES\nYES\nNO\n" }, { "input": "8\nCB\nCA\nBB\nAB\nBA\nAB\nAA\nAC\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nBB\nAC\nAB\nBB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "15\nCA\nCA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCC\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "15\nCA\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "10\nCA\nAB\nCC\nBB\nAB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "14\nCC\nAC\nCA\nBB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAB\nCB\n", "output": "NO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCCBBBA\nABBBCCCC\nABBCCCCB\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "4\nAABBAC\nCACA\nBBBBAC\nCABA\n", "output": "YES\nYES\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nBC\nAB\nBB\nBB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBA\nAACBBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBACCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBBCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "4\nAABAAC\nCACA\nBBBBAC\nABCA\n", "output": "NO\nYES\nNO\nNO\n" }, { "input": "3\nBAAA\nAABB\nBACA\n", "output": "NO\nYES\nYES\n" }, { "input": "15\nCA\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAB\nCA\nAA\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBCBAC\nBBCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBAC\nCBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCB\nCA\nBB\nAC\nBA\n", "output": "YES\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "9\nAABBAC\nCCAA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nBBCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAA\nCC\nAC\nCA\nCB\nCA\nBC\nAB\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBCCCCB\nABBBCCCC\nCCCCBBBA\nABBBCCCC\nABBCCCCB\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABCCB\nBACCBB\nABCCBB\nBBCCAA\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCB\nAC\nAC\nCC\nBC\nBB\nAC\nCA\n", "output": "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nAABBAC\nCCAA\nBBBAAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nBBCA\n", "output": "YES\nYES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCBCA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nAACB\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nBACC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "10\nCA\nAA\nCC\nAC\nCA\nCB\nCA\nBC\nAB\nBB\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\n" }, { "input": "10\nCB\nBA\nCC\nAC\nCA\nCA\nBC\nBB\nAA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBA\nAACBBB\nAACCBB\nAACCBB\nAACCBB\nAACBBC\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\n" }, { "input": "9\nAABBAC\nCACA\nCABBBB\nABCB\nAABBBC\nCACA\nBBBCAB\nAACA\nABCA\n", "output": "YES\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "15\nCA\nCB\nCC\nCA\nAC\nCB\nAC\nBB\nAB\nCC\nAB\nCA\nAA\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "1\nAABAABBAABCCCCCCCCCC\n", "output": "YES\n" }, { "input": "10\nAC\nBA\nCC\nAC\nCA\nCB\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nACBBBCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nBA\nAB\nAA\nAC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "3\nBAAA\nBAAC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nCA\nCA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCBBBCA\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nCA\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "1\nAABAABAAACCCCCCCCCCB\n", "output": "NO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCCAA\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nABBC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nAABBBC\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nBC\nBB\nAC\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCCAA\nCACABB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBABA\nABBC\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nAC\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBABA\nABBC\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nACBA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBABA\nCBBA\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAB\nCA\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nBA\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAAAABBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBBBAC\nABCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBABAC\nACCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCC\nCA\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nAABBAC\nAACC\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "1\nCCCCCCCCCCBBBBBAAAAA\n", "output": "YES\n" }, { "input": "17\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCCBBBA\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "19\nAC\nBA\nCC\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nAC\nAB\nAA\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nAC\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nCA\nAB\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nBC\nAB\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAAABAC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nBC\nBB\nAB\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBA\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBACCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nBC\nAC\nAB\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "9\nAABBAC\nCACA\nCABBBB\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nBA\nCC\nCA\nCA\nCB\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBA\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "19\nCA\nAA\nCC\nAC\nBA\nCC\nCA\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCAAACB\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nCAAB\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "9\nABBAAC\nCACA\nBBBBAC\nABCA\nAABBBC\nBACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "17\nAABCCB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCBABCA\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAC\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nAABB\nABCA\n", "output": "NO\nYES\nNO\n" }, { "input": "1\nAABAABAAACCBCCCCCCCB\n", "output": "NO\n" }, { "input": "10\nAC\nBA\nCC\nAC\nAC\nCC\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCACA\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCAABCA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABA\nABBC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nAC\nAC\nCB\nAB\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAC\nAC\nCC\nBC\nBB\nAC\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCCAA\nBBACAC\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nAABCACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nABAB\nABBC\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nAC\nBC\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nCABBBB\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nAC\nBC\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nCA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABCBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBBAA\nCBBA\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAAAACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBCBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nAB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nCBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nBC\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAAAABBBBAA\nBABACCAAAB\nAABBCCABBA\nAAAAACBBBB\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nACBA\nCBBAAB\nCBCA\nBBBBAC\nABCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBACAC\nACCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCC\nCA\nBB\nAC\nBA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABCCBAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAABBCABAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nBACA\nABCA\n", "output": "YES\nYES\nNO\n" }, { "input": "9\nAABBAC\nCCAA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nBACC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "1\nAABAABABBBCCCCCCCCCC\n", "output": "YES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nCA\nBC\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nCACABB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "19\nAC\nBA\nCC\nCA\nBA\nCC\nAC\nCA\nCB\nCA\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nAC\nBA\nAA\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nBC\nAC\nBB\nAB\nCB\nBA\nAC\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAABBACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nCA\nAB\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nAC\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAAABAC\nCACA\nCBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCA\nBC\nBB\nAB\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nAA\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "9\nAABBAC\nCACA\nCABBBB\nABCA\nAABBBC\nCACA\nBBBCAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "17\nAACCBB\nBABCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBA\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "19\nCA\nAA\nCC\nAC\nBA\nCC\nCA\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nAB\nAC\nAB\nBB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCAAACB\nAABBCCABBA\nABBBCAAAAA\nBABBBAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nABBAAC\nCACA\nCBBBAC\nABCA\nAABBBC\nBACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "17\nAABCCB\nBACCBB\nABCCBB\nBBCCAA\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABCBCCBC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCBABCA\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAC\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAB\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "1\nAABAABAAABCBCCCCCCCB\n", "output": "NO\n" }, { "input": "3\nABBA\nABBC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nCA\nAC\nCB\nAB\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAC\nAC\nCC\nBC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nAABCACAAAB\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nABAB\nABBC\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nAC\nBC\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nBC\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBABBBC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nAC\nCC\nAC\nBB\nAC\nBC\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBCCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nBC\nCA\nCC\nAC\nBB\nCA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAABBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABCBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" } ] }
[ 0.00010357873204331648, 0.00009257215106089689, 0.00007834430611616484, 0.00006360504422010482, 0.00005802288230418805, 0.00005729638184518072, 0.00005646676174785389, 0.00005413071178368237, 0.0000513293290147314, 0.000049417497897775185, 0.000048207961998797084, 0.000037264686053371476, 0.00003492654200564623, 0.00003129924792151694, 0.00003089342008236232, 0.00002978619327518281, 0.000029499821211606695, 0.000028174576585158092, 0.00002806456856763811, 0.000025854383448109148, 0.00002552723180877668, 0.000025368764320597202, 0.000024220119212406723, 0.0000234839410283491, 0.000022895411402950884, 0.00002142564940760715, 0.00002051202972755972, 0.000015133724667543435, 0.000012105093096472117, 0.000011447871618957722, 1.3597226452568923e-11 ]
1494_A. ABC String
1414
1414_8
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'. A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not. You want to find a string b that consists of n characters such that: * b is a regular bracket sequence; * if for some i and j (1 ≤ i, j ≤ n) a_i=a_j, then b_i=b_j. In other words, you want to replace all occurrences of 'A' with the same type of bracket, then all occurrences of 'B' with the same type of bracket and all occurrences of 'C' with the same type of bracket. Your task is to determine if such a string b exists. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases. Then the descriptions of t testcases follow. The only line of each testcase contains a string a. a consists only of uppercase letters 'A', 'B' and 'C'. Let n be the length of a. It is guaranteed that n is even and 2 ≤ n ≤ 50. Output For each testcase print "YES" if there exists such a string b that: * b is a regular bracket sequence; * if for some i and j (1 ≤ i, j ≤ n) a_i=a_j, then b_i=b_j. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 4 AABBAC CACA BBBBAC ABCA Output YES YES NO NO Note In the first testcase one of the possible strings b is "(())()". In the second testcase one of the possible strings b is "()()".
def solve(n, a): cnt = {"A": 0, "B": 0, "C": 0} for i in range(n): cnt[a[i]] += 1 vs = sorted(cnt.values()) if vs[0] + vs[1] != vs[2]: return False first = a[0] last = a[-1] if first == last: return False other = first if cnt[first] == vs[2]: other = last num_open = 0 for i in range(n): if a[i] == first: num_open += 1 elif a[i] == last: num_open -= 1 elif other == first: num_open += 1 else: num_open -= 1 if num_open < 0: return False return num_open == 0 def main(): t = int(input()) for _ in range(t): a = input(); n = len(a) if solve(n, a): print("YES") else: print("NO") main()
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int strings: List[str] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) strings = lines[1:-1] # exclude the first line and the last empty line assert len(strings) == n return cls(n, strings) def __repr__(self): return str(self.n) + '\n' + '\n'.join(self.strings) + '\n'
4 AABBAC CACA BBBBAC ABCA
O(n)
0.000079
{ "public_tests": [ { "input": "4\nAABBAC\nCACA\nBBBBAC\nABCA\n", "output": "\nYES\nYES\nNO\nNO\n" } ], "private_tests": [ { "input": "12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nCAAB\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "1\nAAAAABBBBBCCCCCCCCCC\n", "output": "YES\n" }, { "input": "28\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nAABBAC\nCACA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "19\nCA\nBA\nCC\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nCA\nAB\nAA\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "28\nBA\nCABC\nAB\nAB\nBC\nAC\nCBCA\nCCAABC\nCBAA\nBACA\nABCBAA\nCCABAB\nBC\nABAA\nAABC\nACACAC\nABAA\nABBB\nBBBCAB\nAC\nCB\nBBCC\nCB\nBC\nCBABAB\nBAAABC\nBC\nCA\n", "output": "YES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" } ], "generated_tests": [ { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nBAAC\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nCA\nBA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nBC\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "1\nAABAABBBABCCCCCCCCCC\n", "output": "YES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nAB\nCA\nCA\nAA\nAA\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "19\nCA\nBA\nCC\nAC\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nCA\nAB\nAA\nAC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "4\nAABBAC\nCACA\nBABBAC\nABCA\n", "output": "YES\nYES\nYES\nNO\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nAB\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "3\nAAAB\nBAAC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nCA\nBA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "19\nCA\nAA\nCC\nAC\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nAB\nBB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCCAAAB\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nABBAAC\nCACA\nBBBBAC\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "1\nAABAABBAACCCCCCCCCCB\n", "output": "NO\n" }, { "input": "10\nAC\nBA\nCC\nAC\nCA\nCC\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nAABC\nABCA\n", "output": "NO\nYES\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nAC\nBB\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nBB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBABAC\nABCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nBB\nBB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAA\nCB\nBA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAABBCABAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nACAB\nABCA\n", "output": "YES\nYES\nNO\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nAACC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBC\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAB\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "4\nAABBAC\nCACA\nBBBBAC\nACBA\n", "output": "YES\nYES\nNO\nNO\n" }, { "input": "14\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCC\nAB\nCA\nCA\nAA\nAA\nCB\n", "output": "NO\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "4\nAABAAC\nCACA\nBABBAC\nABCA\n", "output": "NO\nYES\nYES\nNO\n" }, { "input": "8\nCB\nCA\nBB\nAB\nBA\nAB\nAA\nAC\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nBB\nAC\nAB\nBB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "15\nCA\nCA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCC\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "15\nCA\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "10\nCA\nAB\nCC\nBB\nAB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "14\nCC\nAC\nCA\nBB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAB\nCB\n", "output": "NO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCCBBBA\nABBBCCCC\nABBCCCCB\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "4\nAABBAC\nCACA\nBBBBAC\nCABA\n", "output": "YES\nYES\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nBC\nAB\nBB\nBB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBA\nAACBBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBACCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBBCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "4\nAABAAC\nCACA\nBBBBAC\nABCA\n", "output": "NO\nYES\nNO\nNO\n" }, { "input": "3\nBAAA\nAABB\nBACA\n", "output": "NO\nYES\nYES\n" }, { "input": "15\nCA\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAB\nCA\nAA\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBCBAC\nBBCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBAC\nCBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCB\nCA\nBB\nAC\nBA\n", "output": "YES\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "9\nAABBAC\nCCAA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nBBCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAA\nCC\nAC\nCA\nCB\nCA\nBC\nAB\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBCCCCB\nABBBCCCC\nCCCCBBBA\nABBBCCCC\nABBCCCCB\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABCCB\nBACCBB\nABCCBB\nBBCCAA\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCB\nAC\nAC\nCC\nBC\nBB\nAC\nCA\n", "output": "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nAABBAC\nCCAA\nBBBAAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nBBCA\n", "output": "YES\nYES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCBCA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nAACB\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nBACC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "10\nCA\nAA\nCC\nAC\nCA\nCB\nCA\nBC\nAB\nBB\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\n" }, { "input": "10\nCB\nBA\nCC\nAC\nCA\nCA\nBC\nBB\nAA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBA\nAACBBB\nAACCBB\nAACCBB\nAACCBB\nAACBBC\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\n" }, { "input": "9\nAABBAC\nCACA\nCABBBB\nABCB\nAABBBC\nCACA\nBBBCAB\nAACA\nABCA\n", "output": "YES\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "15\nCA\nCB\nCC\nCA\nAC\nCB\nAC\nBB\nAB\nCC\nAB\nCA\nAA\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "1\nAABAABBAABCCCCCCCCCC\n", "output": "YES\n" }, { "input": "10\nAC\nBA\nCC\nAC\nCA\nCB\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nACBBBCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nBA\nAB\nAA\nAC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "3\nBAAA\nBAAC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nCA\nCA\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCBBBCA\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nCA\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "1\nAABAABAAACCCCCCCCCCB\n", "output": "NO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCCAA\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nABBC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nAC\nAC\nCB\nAC\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nAABBBC\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nBC\nBB\nAC\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCCAA\nCACABB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBABA\nABBC\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nAC\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBABA\nABBC\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nACBA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBABA\nCBBA\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAB\nCA\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nBA\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAAAABBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBBBAC\nABCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBABAC\nACCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCC\nCA\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nAABBAC\nAACC\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "1\nCCCCCCCCCCBBBBBAAAAA\n", "output": "YES\n" }, { "input": "17\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCCBBBA\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "19\nAC\nBA\nCC\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nAC\nAB\nAA\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nAC\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nCA\nAB\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "16\nCA\nBA\nCC\nAC\nCA\nBC\nAB\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAAABAC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nBC\nBB\nAB\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBA\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBACCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nBC\nAC\nAB\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "9\nAABBAC\nCACA\nCABBBB\nABCA\nAABBBC\nCACA\nBBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nBA\nCC\nCA\nCA\nCB\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBA\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "19\nCA\nAA\nCC\nAC\nBA\nCC\nCA\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCAAACB\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nCAAB\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "9\nABBAAC\nCACA\nBBBBAC\nABCA\nAABBBC\nBACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "17\nAABCCB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCBABCA\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAC\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBAAA\nAABB\nABCA\n", "output": "NO\nYES\nNO\n" }, { "input": "1\nAABAABAAACCBCCCCCCCB\n", "output": "NO\n" }, { "input": "10\nAC\nBA\nCC\nAC\nAC\nCC\nBC\nBB\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCACA\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCAABCA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABA\nABBC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nAC\nAC\nCB\nAB\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAC\nAC\nCC\nBC\nBB\nAC\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAACCBB\nBACCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nBBCCAA\nBBACAC\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nAABCACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nABAB\nABBC\nABCA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nAC\nBC\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nCABBBB\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nAC\nBC\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nCA\nCC\nAC\nBB\nCA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABCBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nBBAA\nCBBA\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAAAACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBBAA\nCBCA\nBBCBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nAB\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nCBBBAC\nABCA\nACBB\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAB\nBC\nCC\nAC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAAAABBBBAA\nBABACCAAAB\nAABBCCABBA\nAAAAACBBBB\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nACBA\nCBBAAB\nCBCA\nBBBBAC\nABCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBBBBAC\nABCA\nCBBAAB\nCBCA\nBBACAC\nACCA\nBBCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nCA\nAB\nCC\nAB\nBB\nCC\nCA\nBB\nAC\nBA\n", "output": "YES\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABCCBAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAABBCABAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nAABB\nBACA\nABCA\n", "output": "YES\nYES\nNO\n" }, { "input": "9\nAABBAC\nCCAA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nNO\n" }, { "input": "26\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nCACA\nBBBBAC\nABCA\nAABBAC\nBACC\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nYES\n" }, { "input": "1\nAABAABABBBCCCCCCCCCC\n", "output": "YES\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCB\nCA\nBC\nAB\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nCACABB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "19\nAC\nBA\nCC\nCA\nBA\nCC\nAC\nCA\nCB\nCA\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "8\nCB\nCA\nBB\nAA\nAC\nBA\nAA\nCA\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nBC\nAC\nBB\nAB\nCB\nBA\nAC\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABACCBBAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAABBACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "15\nCA\nAB\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nAC\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "9\nAABBAC\nCACA\nBBBBAC\nABCA\nAAABAC\nCACA\nCBBBAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nCA\nBA\nCC\nAC\nCA\nCA\nBC\nBB\nAB\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nCB\nAC\nAA\nAB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n" }, { "input": "9\nAABBAC\nCACA\nCABBBB\nABCA\nAABBBC\nCACA\nBBBCAB\nABCA\nABCA\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "17\nAACCBB\nBABCBB\nABCCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBA\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "19\nCA\nAA\nCC\nAC\nBA\nCC\nCA\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\nCA\nAA\nAA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n" }, { "input": "12\nCA\nAA\nCC\nAC\nCA\nAB\nAC\nAB\nBB\nCB\nBA\nCA\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABBCAAACB\nAABBCCABBA\nABBBCAAAAA\nBABBBAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "9\nABBAAC\nCACA\nCBBBAC\nABCA\nAABBBC\nBACA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "17\nAABCCB\nBACCBB\nABCCBB\nBBCCAA\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBC\nAACCBB\nAACCBB\nAACCBB\nAACCBB\nAACCBB\n", "output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "17\nABBBCCCC\nABBBCCCC\nABCBCCBC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nABCBBCCC\nABBBCCCC\nABBBCCCC\nABBBCCCC\nCCCBABCA\nABBBCCCC\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAC\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAB\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "1\nAABAABAAABCBCCCCCCCB\n", "output": "NO\n" }, { "input": "3\nABBA\nABBC\nABCA\n", "output": "NO\nNO\nNO\n" }, { "input": "15\nAC\nCB\nCC\nCA\nAC\nCB\nAB\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nCB\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "10\nAC\nAB\nCC\nAC\nAC\nCC\nBC\nBB\nAC\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nAABCACAAAB\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "3\nABAB\nABBC\nACBA\n", "output": "YES\nNO\nNO\n" }, { "input": "15\nAC\nBC\nCC\nAC\nAC\nCB\nCA\nBB\nAB\nCB\nAA\nCA\nAA\nAA\nBC\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nYES\n" }, { "input": "9\nCAABBA\nCACA\nBABBBC\nABCA\nCBBBAA\nCBCA\nBBBBAB\nABCA\nABCA\n", "output": "NO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nAC\nAC\nCC\nAC\nBB\nAC\nBC\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCABAA\nAABBCCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAACBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABBBACACCA\nAABACCAACA\nBAAACABBAA\nAAAACCABAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "10\nAC\nAB\nCC\nBC\nCA\nCC\nAC\nBB\nCA\nCA\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nYES\n" }, { "input": "17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCBAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAAAABBBBAA\nBABACCAAAB\nAABBCCABBA\nBBBBCAAAAA\nBABBCAAAAA\nABCBACACCA\nAABACCAACA\nBAAACABBAA\nAABACCAAAA\nAAABACAAAB\n", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" } ] }
[ 0.00016107011699938704, 0.00015751137316864707, 0.0001367679870269275, 0.00012702445430502835, 0.00012117255597155594, 0.00010542552182946798, 0.00010331776608755961, 0.00009338167759267199, 0.00007949805453122257, 0.00007915984591742474, 0.00006411538490714814, 0.0000625753629611297, 0.00005951563698419231, 0.00005615790766326417, 0.00005445831712946309, 0.00005006301894736236, 0.00004335503510039167, 0.00004187989517941575, 0.00004166645591946796, 0.00004089524670421222, 0.00004036237232257712, 0.000040195117822434674, 0.00003993368317846033, 0.000037347315031554954, 0.00003354487122470064, 0.0000329459064833707, 0.000030297613682735286, 0.00002820076413641871, 0.00002734997044222983, 0.00002678616926003413, 0.00002668087212257079, 0.000026115554984474328, 0.00002561965525527427, 0.000024792848703124413, 0.000024118945765189693, 0.00002400262540684741, 0.000021335113871230457, 0.00002040915991873124, 0.000019683254943321948, 0.000017727504392944815, 0.000017558753128876026, 0.00001748895304311791, 0.00001688419214708955, 0.000014587367991504767, 0.000013075722704891379, 1.0712105277534976e-8, 5.288488854895102e-9, 5.120312500000001e-9, 2.664453125e-9, 2.1632812499999996e-9 ]
1008_B. Turn the Rectangles
396
396_361
There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles. Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). Input The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of rectangles. Each of the next n lines contains two integers w_i and h_i (1 ≤ w_i, h_i ≤ 10^9) — the width and the height of the i-th rectangle. Output Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower). Examples Input 3 3 4 4 6 3 5 Output YES Input 2 3 4 5 5 Output NO Note In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3]. In the second test, there is no way the second rectangle will be not higher than the first one.
n = int(input()) dimensions = [] flag = 1 while n > 0: dimensions.append(list(map(int, input().split()))) n -= 1 maximum = max(dimensions[0]) for i in range(1, len(dimensions)): if maximum >= max(dimensions[i]): maximum = max(dimensions[i]) continue elif maximum >= min(dimensions[i]): maximum = min(dimensions[i]) continue else: flag = 0 break if flag: print("YES") else: print("NO")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int rectangles: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) rectangles = [list(map(int, line.split())) for line in lines[1:-1]] assert len(rectangles) == n return cls(n, rectangles) def __repr__(self): return str(self.n) + '\n' + '\n'.join([' '.join(map(str, rectangle)) for rectangle in self.rectangles]) + '\n'
3 3 4 4 6 3 5
O(n*m)
0.000002
{ "public_tests": [ { "input": "3\n3 4\n4 6\n3 5\n", "output": "YES\n" }, { "input": "2\n3 4\n5 5\n", "output": "NO\n" } ], "private_tests": [ { "input": "4\n10 10\n8 8\n8 15\n9 9\n", "output": "NO\n" }, { "input": "3\n10 10\n1 100\n20 20\n", "output": "NO\n" }, { "input": "3\n1 60\n70 55\n56 80\n", "output": "NO\n" }, { "input": "3\n5 7\n3 9\n8 10\n", "output": "NO\n" }, { "input": "3\n200 200\n300 20\n50 50\n", "output": "NO\n" }, { "input": "3\n5 5\n4 6\n5 5\n", "output": "NO\n" }, { "input": "1\n1 1\n", "output": "YES\n" }, { "input": "4\n1 3\n2 4\n3 5\n4 6\n", "output": "NO\n" }, { "input": "3\n3 4\n4 5\n5 5\n", "output": "NO\n" }, { "input": "4\n5 5\n4 6\n4 4\n5 5\n", "output": "NO\n" }, { "input": "3\n5 6\n5 7\n6 8\n", "output": "NO\n" }, { "input": "3\n10 10\n1 1\n2 2\n", "output": "NO\n" }, { "input": "3\n3 5\n1 2\n3 4\n", "output": "NO\n" }, { "input": "3\n5 3\n6 4\n5 5\n", "output": "NO\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n553496707 152702033\n105991807 76314740\n61409204 244301685\n", "output": "YES\n" }, { "input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n6 6\n5 7\n6 6\n", "output": "NO\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 10\n6 6\n", "output": "NO\n" }, { "input": "3\n10 10\n5 5\n10 10\n", "output": "NO\n" }, { "input": "3\n4 8\n6 25\n12 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 8\n8 9\n9 9\n", "output": "NO\n" } ], "generated_tests": [ { "input": "4\n10 10\n8 8\n2 15\n9 9\n", "output": "NO\n" }, { "input": "3\n5 13\n3 9\n8 10\n", "output": "YES\n" }, { "input": "3\n10 10\n0 100\n20 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 55\n56 80\n", "output": "NO\n" }, { "input": "3\n200 200\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n1 2\n", "output": "YES\n" }, { "input": "4\n1 3\n2 4\n0 5\n4 6\n", "output": "NO\n" }, { "input": "3\n3 4\n3 5\n5 5\n", "output": "NO\n" }, { "input": "4\n5 5\n4 6\n2 4\n5 5\n", "output": "NO\n" }, { "input": "3\n5 6\n5 3\n6 8\n", "output": "NO\n" }, { "input": "3\n10 10\n1 1\n1 2\n", "output": "YES\n" }, { "input": "3\n3 8\n1 2\n3 4\n", "output": "NO\n" }, { "input": "3\n5 3\n6 5\n5 5\n", "output": "YES\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 76314740\n61409204 244301685\n", "output": "YES\n" }, { "input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 7\n7 9\n9 2\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n7 6\n5 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 10\n11 6\n", "output": "NO\n" }, { "input": "3\n10 10\n5 5\n15 10\n", "output": "NO\n" }, { "input": "3\n4 10\n6 25\n12 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 8\n8 9\n15 9\n", "output": "NO\n" }, { "input": "3\n1 4\n4 6\n3 5\n", "output": "YES\n" }, { "input": "2\n3 4\n5 2\n", "output": "YES\n" }, { "input": "4\n10 10\n8 8\n2 21\n9 9\n", "output": "NO\n" }, { "input": "3\n10 16\n0 100\n20 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n56 80\n", "output": "NO\n" }, { "input": "3\n5 13\n3 9\n8 8\n", "output": "YES\n" }, { "input": "3\n200 251\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n2 2\n", "output": "YES\n" }, { "input": "3\n4 4\n3 5\n5 5\n", "output": "NO\n" }, { "input": "4\n5 5\n4 9\n2 4\n5 5\n", "output": "NO\n" }, { "input": "3\n5 6\n5 2\n6 8\n", "output": "NO\n" }, { "input": "3\n10 10\n1 2\n1 2\n", "output": "YES\n" }, { "input": "3\n3 6\n1 2\n3 4\n", "output": "NO\n" }, { "input": "3\n5 3\n6 5\n5 3\n", "output": "YES\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "YES\n" }, { "input": "10\n0 3\n1 1\n6 5\n4 5\n2 4\n9 7\n7 9\n9 2\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n7 6\n7 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n611931853 374099541\n916667853 659758645\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 0\n11 6\n", "output": "NO\n" }, { "input": "3\n10 3\n5 5\n15 10\n", "output": "NO\n" }, { "input": "3\n4 10\n6 25\n19 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 16\n8 9\n15 9\n", "output": "NO\n" }, { "input": "3\n1 4\n4 6\n3 6\n", "output": "YES\n" }, { "input": "4\n10 10\n8 4\n2 21\n9 9\n", "output": "NO\n" }, { "input": "3\n10 16\n0 100\n23 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n56 149\n", "output": "NO\n" }, { "input": "3\n5 24\n3 9\n8 8\n", "output": "YES\n" }, { "input": "3\n157 251\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n3 2\n", "output": "YES\n" }, { "input": "3\n7 4\n3 5\n5 5\n", "output": "YES\n" }, { "input": "4\n5 5\n4 9\n2 4\n5 8\n", "output": "NO\n" }, { "input": "3\n5 6\n5 0\n6 8\n", "output": "NO\n" }, { "input": "3\n10 8\n1 2\n1 2\n", "output": "YES\n" }, { "input": "3\n3 6\n1 2\n2 4\n", "output": "YES\n" }, { "input": "3\n5 3\n2 5\n5 3\n", "output": "YES\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 212520125\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "NO\n" }, { "input": "10\n0 3\n1 1\n6 5\n4 5\n2 4\n9 7\n7 9\n9 3\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n7 6\n4 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n1193600684 374099541\n916667853 659758645\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 0\n11 12\n", "output": "NO\n" }, { "input": "3\n10 3\n5 0\n15 10\n", "output": "NO\n" }, { "input": "3\n4 6\n6 25\n19 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 16\n8 9\n29 9\n", "output": "NO\n" }, { "input": "3\n1 4\n3 6\n3 6\n", "output": "YES\n" }, { "input": "4\n10 10\n8 4\n2 20\n9 9\n", "output": "NO\n" }, { "input": "3\n7 16\n0 100\n23 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n56 63\n", "output": "NO\n" }, { "input": "3\n5 24\n1 9\n8 8\n", "output": "YES\n" }, { "input": "3\n157 283\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n4 2\n", "output": "YES\n" }, { "input": "3\n2 4\n3 5\n5 5\n", "output": "NO\n" }, { "input": "4\n10 5\n4 9\n2 4\n5 8\n", "output": "NO\n" }, { "input": "3\n5 6\n0 0\n6 8\n", "output": "NO\n" }, { "input": "3\n10 8\n1 1\n1 2\n", "output": "YES\n" }, { "input": "3\n3 6\n1 2\n2 0\n", "output": "YES\n" }, { "input": "3\n5 3\n2 5\n1 3\n", "output": "YES\n" }, { "input": "10\n706794178 36042507\n431808055 641644550\n715688799 406274173\n767234853 212520125\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "NO\n" }, { "input": "10\n0 3\n1 1\n8 5\n4 5\n2 4\n9 7\n7 9\n9 3\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n9 6\n4 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n1193600684 374099541\n916667853 659758645\n680184710 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n6 5\n4 0\n11 12\n", "output": "NO\n" }, { "input": "3\n10 4\n5 0\n15 10\n", "output": "NO\n" }, { "input": "3\n4 9\n6 25\n19 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 16\n8 9\n29 16\n", "output": "NO\n" }, { "input": "3\n1 4\n1 6\n3 6\n", "output": "NO\n" }, { "input": "4\n10 10\n8 4\n0 20\n9 9\n", "output": "NO\n" }, { "input": "3\n7 16\n0 110\n23 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n95 63\n", "output": "NO\n" }, { "input": "3\n5 4\n1 9\n8 8\n", "output": "NO\n" }, { "input": "3\n157 283\n492 20\n50 39\n", "output": "NO\n" }, { "input": "1\n0 2\n", "output": "YES\n" }, { "input": "3\n2 4\n5 5\n5 5\n", "output": "NO\n" }, { "input": "4\n10 3\n4 9\n2 4\n5 8\n", "output": "NO\n" }, { "input": "3\n5 6\n-1 0\n6 8\n", "output": "NO\n" }, { "input": "3\n10 15\n1 1\n1 2\n", "output": "YES\n" }, { "input": "3\n5 3\n2 5\n2 3\n", "output": "YES\n" }, { "input": "10\n706794178 36042507\n431808055 641644550\n715688799 406274173\n767234853 212520125\n241724251 408945969\n808703176 213953908\n185314264 725573\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "NO\n" }, { "input": "10\n0 3\n1 1\n8 5\n4 5\n2 4\n9 11\n7 9\n9 3\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n9 6\n4 6\n6 6\n", "output": "YES\n" } ] }
[ 0.000003908446937827797, 0.0000035921687609265743, 0.0000029231363499781473, 0.0000027698642100087413, 0.000002714620684003497, 0.000002704055916739511, 0.0000026699717274912587, 0.000002656705337631119, 0.0000026360405649038464, 0.0000026190070886145107, 0.0000026185014887456294, 0.000002613757471044581, 0.000002610647495083042, 0.0000026090401141826927, 0.000002608309003496504, 0.0000026046448317307693, 0.0000025973051791958047, 0.0000025838321405157345, 0.000002568672380354021, 0.0000025523684303977277, 0.000002549782424606643, 0.0000025329257129589163, 0.0000024706715608610137, 0.0000024648651387674824, 0.0000024620452633304202, 0.0000024455108582823427, 0.0000024450847765515734, 0.0000024283931244536712, 0.000002405644012237763, 0.0000024035206375655602, 0.0000024020102026879373, 0.000002401514832823427, 0.0000023927289253715033, 0.000002383311448317308, 0.0000023829129288680067, 0.0000023728693591564687, 0.0000023690012292395106, 0.0000023581377977491262, 0.000002352092916848776, 0.000002347409227491259, 0.000002340325529938811, 0.0000012379276114510488, 0.0000012150196951486015, 0.0000011380148464816435, 0.0000011187537969842655, 0.000001116555889423077, 0.0000011051484648164335, 0.000001094722738199301, 0.000001094719378277972, 0.0000010898963068181818, 0.0000010559711128715035, 9.85572839270105e-7, 9.323712166739512e-7, 1.4622077141608399e-9 ]
1008_B. Turn the Rectangles
396
396_58
There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles. Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). Input The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of rectangles. Each of the next n lines contains two integers w_i and h_i (1 ≤ w_i, h_i ≤ 10^9) — the width and the height of the i-th rectangle. Output Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower). Examples Input 3 3 4 4 6 3 5 Output YES Input 2 3 4 5 5 Output NO Note In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3]. In the second test, there is no way the second rectangle will be not higher than the first one.
from math import inf n = int(input()) last = inf flag = True for _ in range(n): w, h = map(int, input().split(" ")) if h < w: w, h = h, w if h <= last: last = h elif w <= last: last = w else: flag = False break if flag: print("YES") else: print("NO")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int rectangles: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) rectangles = [list(map(int, line.split())) for line in lines[1:-1]] assert len(rectangles) == n return cls(n, rectangles) def __repr__(self): return str(self.n) + '\n' + '\n'.join([' '.join(map(str, rectangle)) for rectangle in self.rectangles]) + '\n'
3 3 4 4 6 3 5
O(n)
0
{ "public_tests": [ { "input": "3\n3 4\n4 6\n3 5\n", "output": "YES\n" }, { "input": "2\n3 4\n5 5\n", "output": "NO\n" } ], "private_tests": [ { "input": "4\n10 10\n8 8\n8 15\n9 9\n", "output": "NO\n" }, { "input": "3\n10 10\n1 100\n20 20\n", "output": "NO\n" }, { "input": "3\n1 60\n70 55\n56 80\n", "output": "NO\n" }, { "input": "3\n5 7\n3 9\n8 10\n", "output": "NO\n" }, { "input": "3\n200 200\n300 20\n50 50\n", "output": "NO\n" }, { "input": "3\n5 5\n4 6\n5 5\n", "output": "NO\n" }, { "input": "1\n1 1\n", "output": "YES\n" }, { "input": "4\n1 3\n2 4\n3 5\n4 6\n", "output": "NO\n" }, { "input": "3\n3 4\n4 5\n5 5\n", "output": "NO\n" }, { "input": "4\n5 5\n4 6\n4 4\n5 5\n", "output": "NO\n" }, { "input": "3\n5 6\n5 7\n6 8\n", "output": "NO\n" }, { "input": "3\n10 10\n1 1\n2 2\n", "output": "NO\n" }, { "input": "3\n3 5\n1 2\n3 4\n", "output": "NO\n" }, { "input": "3\n5 3\n6 4\n5 5\n", "output": "NO\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n553496707 152702033\n105991807 76314740\n61409204 244301685\n", "output": "YES\n" }, { "input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n6 6\n5 7\n6 6\n", "output": "NO\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 10\n6 6\n", "output": "NO\n" }, { "input": "3\n10 10\n5 5\n10 10\n", "output": "NO\n" }, { "input": "3\n4 8\n6 25\n12 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 8\n8 9\n9 9\n", "output": "NO\n" } ], "generated_tests": [ { "input": "4\n10 10\n8 8\n2 15\n9 9\n", "output": "NO\n" }, { "input": "3\n5 13\n3 9\n8 10\n", "output": "YES\n" }, { "input": "3\n10 10\n0 100\n20 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 55\n56 80\n", "output": "NO\n" }, { "input": "3\n200 200\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n1 2\n", "output": "YES\n" }, { "input": "4\n1 3\n2 4\n0 5\n4 6\n", "output": "NO\n" }, { "input": "3\n3 4\n3 5\n5 5\n", "output": "NO\n" }, { "input": "4\n5 5\n4 6\n2 4\n5 5\n", "output": "NO\n" }, { "input": "3\n5 6\n5 3\n6 8\n", "output": "NO\n" }, { "input": "3\n10 10\n1 1\n1 2\n", "output": "YES\n" }, { "input": "3\n3 8\n1 2\n3 4\n", "output": "NO\n" }, { "input": "3\n5 3\n6 5\n5 5\n", "output": "YES\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 76314740\n61409204 244301685\n", "output": "YES\n" }, { "input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 7\n7 9\n9 2\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n7 6\n5 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 10\n11 6\n", "output": "NO\n" }, { "input": "3\n10 10\n5 5\n15 10\n", "output": "NO\n" }, { "input": "3\n4 10\n6 25\n12 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 8\n8 9\n15 9\n", "output": "NO\n" }, { "input": "3\n1 4\n4 6\n3 5\n", "output": "YES\n" }, { "input": "2\n3 4\n5 2\n", "output": "YES\n" }, { "input": "4\n10 10\n8 8\n2 21\n9 9\n", "output": "NO\n" }, { "input": "3\n10 16\n0 100\n20 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n56 80\n", "output": "NO\n" }, { "input": "3\n5 13\n3 9\n8 8\n", "output": "YES\n" }, { "input": "3\n200 251\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n2 2\n", "output": "YES\n" }, { "input": "3\n4 4\n3 5\n5 5\n", "output": "NO\n" }, { "input": "4\n5 5\n4 9\n2 4\n5 5\n", "output": "NO\n" }, { "input": "3\n5 6\n5 2\n6 8\n", "output": "NO\n" }, { "input": "3\n10 10\n1 2\n1 2\n", "output": "YES\n" }, { "input": "3\n3 6\n1 2\n3 4\n", "output": "NO\n" }, { "input": "3\n5 3\n6 5\n5 3\n", "output": "YES\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "YES\n" }, { "input": "10\n0 3\n1 1\n6 5\n4 5\n2 4\n9 7\n7 9\n9 2\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n7 6\n7 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n611931853 374099541\n916667853 659758645\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 0\n11 6\n", "output": "NO\n" }, { "input": "3\n10 3\n5 5\n15 10\n", "output": "NO\n" }, { "input": "3\n4 10\n6 25\n19 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 16\n8 9\n15 9\n", "output": "NO\n" }, { "input": "3\n1 4\n4 6\n3 6\n", "output": "YES\n" }, { "input": "4\n10 10\n8 4\n2 21\n9 9\n", "output": "NO\n" }, { "input": "3\n10 16\n0 100\n23 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n56 149\n", "output": "NO\n" }, { "input": "3\n5 24\n3 9\n8 8\n", "output": "YES\n" }, { "input": "3\n157 251\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n3 2\n", "output": "YES\n" }, { "input": "3\n7 4\n3 5\n5 5\n", "output": "YES\n" }, { "input": "4\n5 5\n4 9\n2 4\n5 8\n", "output": "NO\n" }, { "input": "3\n5 6\n5 0\n6 8\n", "output": "NO\n" }, { "input": "3\n10 8\n1 2\n1 2\n", "output": "YES\n" }, { "input": "3\n3 6\n1 2\n2 4\n", "output": "YES\n" }, { "input": "3\n5 3\n2 5\n5 3\n", "output": "YES\n" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 212520125\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "NO\n" }, { "input": "10\n0 3\n1 1\n6 5\n4 5\n2 4\n9 7\n7 9\n9 3\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n7 6\n4 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n1193600684 374099541\n916667853 659758645\n677773241 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n3 5\n4 0\n11 12\n", "output": "NO\n" }, { "input": "3\n10 3\n5 0\n15 10\n", "output": "NO\n" }, { "input": "3\n4 6\n6 25\n19 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 16\n8 9\n29 9\n", "output": "NO\n" }, { "input": "3\n1 4\n3 6\n3 6\n", "output": "YES\n" }, { "input": "4\n10 10\n8 4\n2 20\n9 9\n", "output": "NO\n" }, { "input": "3\n7 16\n0 100\n23 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n56 63\n", "output": "NO\n" }, { "input": "3\n5 24\n1 9\n8 8\n", "output": "YES\n" }, { "input": "3\n157 283\n492 20\n50 50\n", "output": "NO\n" }, { "input": "1\n4 2\n", "output": "YES\n" }, { "input": "3\n2 4\n3 5\n5 5\n", "output": "NO\n" }, { "input": "4\n10 5\n4 9\n2 4\n5 8\n", "output": "NO\n" }, { "input": "3\n5 6\n0 0\n6 8\n", "output": "NO\n" }, { "input": "3\n10 8\n1 1\n1 2\n", "output": "YES\n" }, { "input": "3\n3 6\n1 2\n2 0\n", "output": "YES\n" }, { "input": "3\n5 3\n2 5\n1 3\n", "output": "YES\n" }, { "input": "10\n706794178 36042507\n431808055 641644550\n715688799 406274173\n767234853 212520125\n241724251 408945969\n808703176 213953908\n185314264 16672343\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "NO\n" }, { "input": "10\n0 3\n1 1\n8 5\n4 5\n2 4\n9 7\n7 9\n9 3\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n9 6\n4 7\n6 6\n", "output": "YES\n" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 224263830\n103578427 56645210\n1193600684 374099541\n916667853 659758645\n680184710 808703176\n575586508 440395988\n450102404 244301685\n", "output": "NO\n" }, { "input": "3\n6 5\n4 0\n11 12\n", "output": "NO\n" }, { "input": "3\n10 4\n5 0\n15 10\n", "output": "NO\n" }, { "input": "3\n4 9\n6 25\n19 12\n", "output": "NO\n" }, { "input": "4\n10 10\n8 16\n8 9\n29 16\n", "output": "NO\n" }, { "input": "3\n1 4\n1 6\n3 6\n", "output": "NO\n" }, { "input": "4\n10 10\n8 4\n0 20\n9 9\n", "output": "NO\n" }, { "input": "3\n7 16\n0 110\n23 20\n", "output": "NO\n" }, { "input": "3\n0 60\n70 24\n95 63\n", "output": "NO\n" }, { "input": "3\n5 4\n1 9\n8 8\n", "output": "NO\n" }, { "input": "3\n157 283\n492 20\n50 39\n", "output": "NO\n" }, { "input": "1\n0 2\n", "output": "YES\n" }, { "input": "3\n2 4\n5 5\n5 5\n", "output": "NO\n" }, { "input": "4\n10 3\n4 9\n2 4\n5 8\n", "output": "NO\n" }, { "input": "3\n5 6\n-1 0\n6 8\n", "output": "NO\n" }, { "input": "3\n10 15\n1 1\n1 2\n", "output": "YES\n" }, { "input": "3\n5 3\n2 5\n2 3\n", "output": "YES\n" }, { "input": "10\n706794178 36042507\n431808055 641644550\n715688799 406274173\n767234853 212520125\n241724251 408945969\n808703176 213953908\n185314264 725573\n1017427585 152702033\n105991807 4754153\n61409204 244301685\n", "output": "NO\n" }, { "input": "10\n0 3\n1 1\n8 5\n4 5\n2 4\n9 11\n7 9\n9 3\n4 10\n10 1\n", "output": "NO\n" }, { "input": "3\n9 6\n4 6\n6 6\n", "output": "YES\n" } ] }
[ 0.00003298833911986451, 0.00003091843393520542, 0.0000305915152152535, 0.00003050219501201923, 0.000030130276496940565, 0.000019073780730987762, 0.000014753088505244755, 0.00001353199160019668, 0.000012574050111997377, 0.000012293328930834792, 0.000011974346959680946, 0.000011963545236013987, 0.000011776317362325175, 0.000011765737270541959, 0.000011693000641936189, 0.000011077552789007867, 0.00001092273858173077, 0.000010890823836319932, 0.000010841250478037588, 0.000010815371230332169, 0.000010598777944711538, 0.00001058378511527535, 0.000010490172407670456, 0.000010402708287805944, 0.000010401571050043706, 0.000010392469405594404, 0.000010333535647945806, 0.000010315557951813812, 0.000010276260598776224, 0.000010194350961538461, 0.000010169793105332169, 0.000010061348625983392, 0.000009971794157014862, 0.00000990407888986014, 0.000009615306531359266, 0.000009497441269667832, 0.000009428898792613635, 0.000008392041671219406, 0.000008290861847137238, 0.000008161029460773602, 0.000008137777999344407, 0.000008087773901879371, 0.000008078358883304195, 0.000008018866777753496, 0.00000779287403026661, 0.000005158609798404721, 0.0000029802286248907347, 0.0000028953494591346156, 0.0000028458154638330423, 0.000002787992501638986, 0.000002774239633413462, 0.000002773350264969406, 0.0000027403549770541962, 0.000002731100893247378, 0.000002706398246284965, 0.0000027008501557036717, 0.000002694214980332168, 0.0000026833273601398603, 0.000002679426095388986, 0.00000267342884069056, 0.0000026541042668269233, 0.000002649363690996504, 0.000002649044935533217, 0.0000026389493826486015, 0.0000026387474185970283, 0.0000026216096481643357, 0.0000025902761145104894, 0.0000024996591455419583, 0.0000024217251010708047, 0.000001243132115930944, 0.000001095718504152098, 5.3786877185314715e-9, 5.085923841783218e-9, 4.531434385926572e-9, 3.2660620629370605e-9, 3.172872049825175e-9, 3.06207659527972e-9, 3.016908872377618e-9, 2.989490002185318e-9, 2.78010270979021e-9, 2.767564466783218e-9, 2.697183675699304e-9, 2.649407233391606e-9, 2.5725934222028e-9, 2.566624781468535e-9, 2.4991053868006958e-9, 2.458479020979022e-9, 2.4535688920454535e-9, 2.4355537041083892e-9, 2.382832987325172e-9, 2.3694889095279724e-9, 2.3568140843531453e-9, 2.3365930944055933e-9, 2.2466947115384607e-9, 2.2326404064685325e-9, 2.2098243553321695e-9, 2.179619208916082e-9, 2.178253387237759e-9, 2.1704818618881127e-9, 2.156898765297203e-9, 2.1544949191433553e-9, 2.1480072661713283e-9, 2.1164021525349675e-9, 2.108739892919579e-9, 2.1071418815559436e-9, 2.097977218094409e-9, 2.0655730987762257e-9, 2.0535880135489487e-9, 2.010755845716783e-9, 2.0091441761363617e-9, 1.9654925152972037e-9, 1.9528108610139854e-9, 1.937158544580421e-9, 1.9121708369755254e-9, 1.9110372049825183e-9, 1.8407178758741258e-9, 1.7993266499125885e-9, 1.77849786931818e-9, 1.72962194055944e-9, 1.7262415319055954e-9, 1.7162027425699314e-9, 1.7100019121503467e-9, 1.697388548951048e-9, 1.6953329873251778e-9, 1.6858405266608366e-9, 1.662594241695802e-9, 1.5867501638986013e-9, 1.570292012674828e-9, 1.5499139532342666e-9, 1.5175576376748275e-9, 1.5001160948426569e-9, 1.498463450611887e-9, 1.469583151223774e-9, 1.4543815559440586e-9, 1.4423145214160855e-9, 1.4413379589160837e-9, 1.4265939138985998e-9, 1.4232544798951018e-9, 1.4094801682692295e-9, 1.373463450611889e-9, 1.3458260489510474e-9, 1.3363062718531475e-9, 1.3167818509615363e-9, 1.306026005244755e-9, 1.3052952906468523e-9, 1.2822538789335689e-9, 1.2784090909090895e-9, 1.2730755572552462e-9, 1.2453971809440533e-9, 1.231288243006994e-9, 1.22583861451049e-9, 1.1478433675699305e-9, 1.0384478802447558e-9, 7.836948208041941e-10, 1.4382785183566435e-10, 1.4035183566433573e-10, 1.1896989729020985e-10, 1.1543924825174825e-10 ]
1285_D. Dr. Evil Underscores
1870
1870_81
Today, as a friendship gift, Bakry gave Badawy n integers a_1, a_2, ..., a_n and challenged him to choose an integer X such that the value \underset{1 ≤ i ≤ n}{max} (a_i ⊕ X) is minimum possible, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of \underset{1 ≤ i ≤ n}{max} (a_i ⊕ X). Input The first line contains integer n (1≤ n ≤ 10^5). The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30}-1). Output Print one integer — the minimum possible value of \underset{1 ≤ i ≤ n}{max} (a_i ⊕ X). Examples Input 3 1 2 3 Output 2 Input 2 1 5 Output 4 Note In the first sample, we can choose X = 3. In the second sample, we can choose X = 5.
n=int(input()) arr=list(map(int,input().split())) def solve(arr,bit): if len(arr)==0 or bit <0: return 0 l=[] r=[] for i in arr: if (i>>bit)&1==0: l.append(i) else: r.append(i) if len(l)==0: return solve(r,bit-1) if len(r)==0: return solve(l,bit-1) return min(solve(r,bit-1),solve(l,bit-1))+(1<<bit) print(solve(arr,30))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int values: List[int] @classmethod def from_str(cls, input_: str): n, values, _ = input_.split('\n') n = int(n) values = [int(x) for x in values.split()] return cls(n, values) def __repr__(self): return str(self.n) + '\n' + ' '.join(map(str, self.values)) + '\n'
2 1 5
O(n)
0.000096
{ "public_tests": [ { "input": "2\n1 5\n", "output": "4" }, { "input": "3\n1 2 3\n", "output": "2" } ], "private_tests": [ { "input": "1\n1073741823\n", "output": "0" }, { "input": "2\n0 1073741823\n", "output": "536870912" }, { "input": "5\n1073741823 1073741823 1073741823 1073741823 1073741823\n", "output": "0" } ], "generated_tests": [ { "input": "5\n1073741823 29972487 1073741823 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "2\n1 0\n", "output": "1\n" }, { "input": "3\n1 1 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 708682461\n", "output": "671088640\n" }, { "input": "5\n219338430 29972487 1073741823 949313050 57010828\n", "output": "603979776\n" }, { "input": "1\n406883574\n", "output": "0\n" }, { "input": "2\n0 5\n", "output": "4\n" }, { "input": "3\n0 1 9\n", "output": "8\n" }, { "input": "5\n219338430 40120893 66201891 455530188 57010828\n", "output": "268435456\n" }, { "input": "5\n520863927 57348107 723662390 949313050 24781190\n", "output": "805306368\n" }, { "input": "5\n520863927 57348107 972949765 949313050 24781190\n", "output": "553648128\n" }, { "input": "5\n297067041 63386418 103793936 455530188 42547678\n", "output": "335544320\n" }, { "input": "5\n297067041 63386418 197640691 455530188 42547678\n", "output": "402653184\n" }, { "input": "3\n1 2 18\n", "output": "16\n" }, { "input": "5\n519891911 63386418 17305630 455530188 42547678\n", "output": "301989888\n" }, { "input": "5\n609773094 29128028 17305630 724019232 42547678\n", "output": "570425344\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "3\n2 1 3\n", "output": "2\n" }, { "input": "3\n2 0 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 57010828\n", "output": "536870912\n" }, { "input": "5\n219338430 57348107 1073741823 949313050 57010828\n", "output": "603979776\n" }, { "input": "5\n1073741823 1073741823 181085488 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "5\n684690029 29972487 1073741823 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "2\n1 1\n", "output": "0\n" }, { "input": "3\n0 1 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 811236584 1073741823\n", "output": "671088640\n" }, { "input": "3\n0 0 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 214077518\n", "output": "536870912\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 1073741823 949313050 57010828\n", "output": "603979776\n" }, { "input": "5\n219338430 57348107 723662390 949313050 57010828\n", "output": "671088640\n" }, { "input": "1\n509419106\n", "output": "0\n" }, { "input": "3\n0 2 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 153925473 1073741823\n", "output": "536870912\n" }, { "input": "3\n0 1 5\n", "output": "4\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 256835840\n", "output": "536870912\n" }, { "input": "5\n219338430 3399800 1073741823 1073741823 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 1073741823 455530188 57010828\n", "output": "536870912\n" }, { "input": "5\n264882479 57348107 723662390 949313050 57010828\n", "output": "671088640\n" }, { "input": "1\n72881523\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 153925473 1073741823\n", "output": "536870912\n" }, { "input": "5\n78610785 3399800 1073741823 1073741823 86420704\n", "output": "536870912\n" }, { "input": "5\n264882479 57348107 723662390 949313050 66826716\n", "output": "671088640\n" }, { "input": "1\n38957962\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 79309577 1073741823\n", "output": "536870912\n" }, { "input": "3\n1 1 9\n", "output": "8\n" }, { "input": "5\n78610785 3399800 1073741823 276753816 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 66201891 455530188 42547678\n", "output": "268435456\n" }, { "input": "5\n264882479 57348107 723662390 949313050 24781190\n", "output": "671088640\n" }, { "input": "1\n15453690\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 79309577 293486783\n", "output": "536870912\n" }, { "input": "3\n1 2 9\n", "output": "8\n" }, { "input": "5\n78610785 3399800 1073741823 136306232 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 103793936 455530188 42547678\n", "output": "268435456\n" }, { "input": "1\n18081291\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 39709943 293486783\n", "output": "536870912\n" }, { "input": "3\n1 4 9\n", "output": "8\n" }, { "input": "5\n78610785 5765920 1073741823 136306232 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 63386418 103793936 455530188 42547678\n", "output": "268435456\n" }, { "input": "1\n26340260\n", "output": "0\n" }, { "input": "3\n1 4 12\n", "output": "8\n" }, { "input": "5\n78610785 5765920 1073741823 136306232 93017120\n", "output": "536870912\n" }, { "input": "5\n520863927 57348107 912336312 949313050 24781190\n", "output": "671088640\n" }, { "input": "1\n18330946\n", "output": "0\n" }, { "input": "3\n1 1 12\n", "output": "8\n" }, { "input": "5\n520863927 57348107 912336312 220860018 24781190\n", "output": "536870912\n" }, { "input": "1\n23912722\n", "output": "0\n" }, { "input": "3\n1 2 12\n", "output": "8\n" }, { "input": "5\n519891911 63386418 197640691 455530188 42547678\n", "output": "335544320\n" }, { "input": "1\n45253579\n", "output": "0\n" }, { "input": "1\n56071777\n", "output": "0\n" }, { "input": "3\n2 2 18\n", "output": "16\n" }, { "input": "5\n519891911 29128028 17305630 455530188 42547678\n", "output": "301989888\n" }, { "input": "1\n67649815\n", "output": "0\n" }, { "input": "3\n2 2 2\n", "output": "0\n" }, { "input": "5\n519891911 29128028 17305630 724019232 42547678\n", "output": "536870912\n" }, { "input": "1\n74171479\n", "output": "0\n" }, { "input": "1\n79508322\n", "output": "0\n" } ] }
[ 0.0001439889064275568, 0.00014237925012292396, 0.0001343755467793925, 0.00013299873470279722, 0.00013135862934331294, 0.0001297048765433785, 0.00011975839465417397, 0.00011637659827086977, 0.00011526023072825614, 0.00011316269966947116, 0.00011311568101234704, 0.00011112696256282782, 0.0001106928365794362, 0.00011002450217165647, 0.00010730166768192745, 0.00010680047515570368, 0.00010561942886800699, 0.0001044995337631119, 0.00010380420925753934, 0.00010320883876475088, 0.00010079979713450613, 0.00009633336490657779, 0.00009613172589324738, 0.00009582888432856206, 0.00009559113992843094, 0.00009395592601343968, 0.00009367675747104458, 0.00009229428302556819, 0.00009077601831566871, 0.00009029718281523166, 0.00009020378868006993, 0.00008978839637510926, 0.00008977598660128934, 0.00008917339048841784, 0.00008912946911877184, 0.00008808550031413899, 0.0000862345438565341, 0.00008597016575611888, 0.0000859197725360577, 0.00008562296429742135, 0.0000784644582468313, 0.00007765346506228147, 0.0000691948288625437, 0.00006800703858446242, 0.00006374140126475088, 0.00006342981072443182, 0.00004967812215909091, 0.000037855460046217297, 0.000027100116544696384, 0.000026355502582815576, 0.0000243891845382156, 0.000023847931080638113, 0.000023823346167504372, 0.00002358544659637238, 0.00002321105811119201, 1.1074205091783218e-8, 1.0619434276660833e-8, 2.2161617679195764e-9, 2.185157615821674e-9, 5.901169143356632e-10, 3.40997869318182e-10 ]
1285_D. Dr. Evil Underscores
1870
1870_58
Today, as a friendship gift, Bakry gave Badawy n integers a_1, a_2, ..., a_n and challenged him to choose an integer X such that the value \underset{1 ≤ i ≤ n}{max} (a_i ⊕ X) is minimum possible, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of \underset{1 ≤ i ≤ n}{max} (a_i ⊕ X). Input The first line contains integer n (1≤ n ≤ 10^5). The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30}-1). Output Print one integer — the minimum possible value of \underset{1 ≤ i ≤ n}{max} (a_i ⊕ X). Examples Input 3 1 2 3 Output 2 Input 2 1 5 Output 4 Note In the first sample, we can choose X = 3. In the second sample, we can choose X = 5.
n = int(input()) seq = sorted(list(map(int, input().split()))) #Left (inc), Right(exc), bit to check, value to add queue = [(0,n,30,0)] best = 2 ** 30 while queue: l, r, b, v = queue.pop() if b >= 0: mask = 1 << b if not mask & seq[l] and mask & seq[r - 1]: for i in range(l, r): if mask & seq[i]: queue.append((l,i,b - 1, v + mask)) queue.append((i,r,b - 1, v + mask)) break else: queue.append((l, r, b - 1, v)) else: best = min(best, v) print(best)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int values: List[int] @classmethod def from_str(cls, input_: str): n, values, _ = input_.split('\n') n = int(n) values = [int(x) for x in values.split()] return cls(n, values) def __repr__(self): return str(self.n) + '\n' + ' '.join(map(str, self.values)) + '\n'
2 1 5
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n1 5\n", "output": "4" }, { "input": "3\n1 2 3\n", "output": "2" } ], "private_tests": [ { "input": "1\n1073741823\n", "output": "0" }, { "input": "2\n0 1073741823\n", "output": "536870912" }, { "input": "5\n1073741823 1073741823 1073741823 1073741823 1073741823\n", "output": "0" } ], "generated_tests": [ { "input": "5\n1073741823 29972487 1073741823 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "2\n1 0\n", "output": "1\n" }, { "input": "3\n1 1 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 708682461\n", "output": "671088640\n" }, { "input": "5\n219338430 29972487 1073741823 949313050 57010828\n", "output": "603979776\n" }, { "input": "1\n406883574\n", "output": "0\n" }, { "input": "2\n0 5\n", "output": "4\n" }, { "input": "3\n0 1 9\n", "output": "8\n" }, { "input": "5\n219338430 40120893 66201891 455530188 57010828\n", "output": "268435456\n" }, { "input": "5\n520863927 57348107 723662390 949313050 24781190\n", "output": "805306368\n" }, { "input": "5\n520863927 57348107 972949765 949313050 24781190\n", "output": "553648128\n" }, { "input": "5\n297067041 63386418 103793936 455530188 42547678\n", "output": "335544320\n" }, { "input": "5\n297067041 63386418 197640691 455530188 42547678\n", "output": "402653184\n" }, { "input": "3\n1 2 18\n", "output": "16\n" }, { "input": "5\n519891911 63386418 17305630 455530188 42547678\n", "output": "301989888\n" }, { "input": "5\n609773094 29128028 17305630 724019232 42547678\n", "output": "570425344\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "3\n2 1 3\n", "output": "2\n" }, { "input": "3\n2 0 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 57010828\n", "output": "536870912\n" }, { "input": "5\n219338430 57348107 1073741823 949313050 57010828\n", "output": "603979776\n" }, { "input": "5\n1073741823 1073741823 181085488 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "5\n684690029 29972487 1073741823 1073741823 1073741823\n", "output": "536870912\n" }, { "input": "2\n1 1\n", "output": "0\n" }, { "input": "3\n0 1 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 811236584 1073741823\n", "output": "671088640\n" }, { "input": "3\n0 0 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 214077518\n", "output": "536870912\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 1073741823 949313050 57010828\n", "output": "603979776\n" }, { "input": "5\n219338430 57348107 723662390 949313050 57010828\n", "output": "671088640\n" }, { "input": "1\n509419106\n", "output": "0\n" }, { "input": "3\n0 2 3\n", "output": "2\n" }, { "input": "5\n219338430 29972487 1073741823 153925473 1073741823\n", "output": "536870912\n" }, { "input": "3\n0 1 5\n", "output": "4\n" }, { "input": "5\n219338430 29972487 1073741823 1073741823 256835840\n", "output": "536870912\n" }, { "input": "5\n219338430 3399800 1073741823 1073741823 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 1073741823 455530188 57010828\n", "output": "536870912\n" }, { "input": "5\n264882479 57348107 723662390 949313050 57010828\n", "output": "671088640\n" }, { "input": "1\n72881523\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 153925473 1073741823\n", "output": "536870912\n" }, { "input": "5\n78610785 3399800 1073741823 1073741823 86420704\n", "output": "536870912\n" }, { "input": "5\n264882479 57348107 723662390 949313050 66826716\n", "output": "671088640\n" }, { "input": "1\n38957962\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 79309577 1073741823\n", "output": "536870912\n" }, { "input": "3\n1 1 9\n", "output": "8\n" }, { "input": "5\n78610785 3399800 1073741823 276753816 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 66201891 455530188 42547678\n", "output": "268435456\n" }, { "input": "5\n264882479 57348107 723662390 949313050 24781190\n", "output": "671088640\n" }, { "input": "1\n15453690\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 79309577 293486783\n", "output": "536870912\n" }, { "input": "3\n1 2 9\n", "output": "8\n" }, { "input": "5\n78610785 3399800 1073741823 136306232 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 40120893 103793936 455530188 42547678\n", "output": "268435456\n" }, { "input": "1\n18081291\n", "output": "0\n" }, { "input": "5\n252157883 29972487 1073741823 39709943 293486783\n", "output": "536870912\n" }, { "input": "3\n1 4 9\n", "output": "8\n" }, { "input": "5\n78610785 5765920 1073741823 136306232 86420704\n", "output": "536870912\n" }, { "input": "5\n219338430 63386418 103793936 455530188 42547678\n", "output": "268435456\n" }, { "input": "1\n26340260\n", "output": "0\n" }, { "input": "3\n1 4 12\n", "output": "8\n" }, { "input": "5\n78610785 5765920 1073741823 136306232 93017120\n", "output": "536870912\n" }, { "input": "5\n520863927 57348107 912336312 949313050 24781190\n", "output": "671088640\n" }, { "input": "1\n18330946\n", "output": "0\n" }, { "input": "3\n1 1 12\n", "output": "8\n" }, { "input": "5\n520863927 57348107 912336312 220860018 24781190\n", "output": "536870912\n" }, { "input": "1\n23912722\n", "output": "0\n" }, { "input": "3\n1 2 12\n", "output": "8\n" }, { "input": "5\n519891911 63386418 197640691 455530188 42547678\n", "output": "335544320\n" }, { "input": "1\n45253579\n", "output": "0\n" }, { "input": "1\n56071777\n", "output": "0\n" }, { "input": "3\n2 2 18\n", "output": "16\n" }, { "input": "5\n519891911 29128028 17305630 455530188 42547678\n", "output": "301989888\n" }, { "input": "1\n67649815\n", "output": "0\n" }, { "input": "3\n2 2 2\n", "output": "0\n" }, { "input": "5\n519891911 29128028 17305630 724019232 42547678\n", "output": "536870912\n" }, { "input": "1\n74171479\n", "output": "0\n" }, { "input": "1\n79508322\n", "output": "0\n" } ] }
[ 0.001185442030172414, 0.00010921770804195807, 0.00010216088098229895, 0.00008306292998798076, 0.00008197568213232082, 0.00006122550693837414, 0.00003042770276988636, 0.000009841181169435163, 0.000007838349212944684, 0.000005893743751900934, 0.000005539913474224657, 0.000004900571918634675, 0.000004891719686413038, 0.000004866617236379398 ]
279_A. Point on Spiral
2847
2847_21
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane. Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y). Input The first line contains two space-separated integers x and y (|x|, |y| ≤ 100). Output Print a single integer, showing how many times Valera has to turn. Examples Input 0 0 Output 0 Input 1 0 Output 0 Input 0 1 Output 2 Input -1 -1 Output 3
x, y = map(int, input().split()) cur_x, cur_y = 0, 0 i = 1 pos = 0 sign = [(1, 0), (0, 1), (-1, 0), (0, -1)] ans = 0 j = 0 while cur_x != x or cur_y != y: if j == i: j = 0 if pos % 2 == 1: i += 1 pos = (pos + 1) % 4 ans += 1 cur_x = cur_x + sign[pos][0] cur_y = cur_y + sign[pos][1] j += 1 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: a: int b: int @classmethod def from_str(cls, input_: str): a, b = input_.split('\n')[0].split(' ') a = int(a) b = int(b) return cls(a, b) def __repr__(self): return str(self.a) + ' ' + str(self.b) + '\n'
1 0
O(n**2)
0.000002
{ "public_tests": [ { "input": "1 0\n", "output": "0\n" }, { "input": "0 0\n", "output": "0\n" }, { "input": "0 1\n", "output": "2\n" }, { "input": "-1 -1\n", "output": "3\n" } ], "private_tests": [ { "input": "17 25\n", "output": "98\n" }, { "input": "3 -5\n", "output": "20\n" }, { "input": "0 -1\n", "output": "4\n" }, { "input": "100 100\n", "output": "397\n" }, { "input": "37 -100\n", "output": "400\n" }, { "input": "10 10\n", "output": "37\n" }, { "input": "1 -84\n", "output": "336\n" }, { "input": "2 -1\n", "output": "4\n" }, { "input": "-1 0\n", "output": "3\n" }, { "input": "0 99\n", "output": "394\n" }, { "input": "94 -94\n", "output": "376\n" }, { "input": "-96 -96\n", "output": "383\n" }, { "input": "-97 0\n", "output": "387\n" }, { "input": "1 -1\n", "output": "4\n" }, { "input": "-5 44\n", "output": "174\n" }, { "input": "0 6\n", "output": "22\n" }, { "input": "11 -15\n", "output": "60\n" }, { "input": "-98 98\n", "output": "390\n" }, { "input": "0 -95\n", "output": "380\n" }, { "input": "100 99\n", "output": "397\n" }, { "input": "42 9\n", "output": "165\n" }, { "input": "-1 1\n", "output": "2\n" }, { "input": "1 1\n", "output": "1\n" }, { "input": "-7 -13\n", "output": "52\n" }, { "input": "99 100\n", "output": "398\n" }, { "input": "16 -32\n", "output": "128\n" }, { "input": "93 0\n", "output": "369\n" }, { "input": "-81 3\n", "output": "323\n" } ], "generated_tests": [ { "input": "17 18\n", "output": "70\n" }, { "input": "6 -5\n", "output": "20\n" }, { "input": "0 -2\n", "output": "8\n" }, { "input": "56 -100\n", "output": "400\n" }, { "input": "18 10\n", "output": "69\n" }, { "input": "2 -84\n", "output": "336\n" }, { "input": "-2 0\n", "output": "7\n" }, { "input": "0 21\n", "output": "82\n" }, { "input": "78 -94\n", "output": "376\n" }, { "input": "-97 1\n", "output": "387\n" }, { "input": "-4 44\n", "output": "174\n" }, { "input": "2 1\n", "output": "5\n" }, { "input": "-98 71\n", "output": "391\n" }, { "input": "0 -14\n", "output": "56\n" }, { "input": "100 2\n", "output": "397\n" }, { "input": "68 9\n", "output": "269\n" }, { "input": "1 2\n", "output": "6\n" }, { "input": "-7 -4\n", "output": "27\n" }, { "input": "3 -32\n", "output": "128\n" }, { "input": "93 1\n", "output": "369\n" }, { "input": "-81 6\n", "output": "323\n" }, { "input": "-1 -4\n", "output": "16\n" }, { "input": "56 -83\n", "output": "332\n" }, { "input": "-4 -1\n", "output": "15\n" }, { "input": "3 0\n", "output": "9\n" }, { "input": "-47 71\n", "output": "282\n" }, { "input": "0 -28\n", "output": "112\n" }, { "input": "-3 1\n", "output": "11\n" }, { "input": "3 -49\n", "output": "196\n" }, { "input": "18 30\n", "output": "118\n" }, { "input": "2 -3\n", "output": "12\n" }, { "input": "-8 -1\n", "output": "31\n" }, { "input": "-47 97\n", "output": "386\n" }, { "input": "0 -56\n", "output": "224\n" }, { "input": "56 7\n", "output": "221\n" }, { "input": "2 4\n", "output": "14\n" }, { "input": "3 -75\n", "output": "300\n" }, { "input": "14 28\n", "output": "110\n" }, { "input": "18 26\n", "output": "102\n" }, { "input": "-2 27\n", "output": "106\n" }, { "input": "0 -97\n", "output": "388\n" }, { "input": "2 3\n", "output": "10\n" }, { "input": "0 -9\n", "output": "36\n" }, { "input": "-13 -2\n", "output": "51\n" }, { "input": "-2 12\n", "output": "46\n" }, { "input": "-2 7\n", "output": "26\n" }, { "input": "1 -2\n", "output": "8\n" }, { "input": "-2 1\n", "output": "7\n" }, { "input": "2 2\n", "output": "5\n" }, { "input": "-2 -1\n", "output": "7\n" }, { "input": "2 0\n", "output": "5\n" }, { "input": "18 18\n", "output": "69\n" }, { "input": "18 17\n", "output": "69\n" }, { "input": "4 -84\n", "output": "336\n" }, { "input": "2 -2\n", "output": "8\n" }, { "input": "1 21\n", "output": "82\n" }, { "input": "82 -94\n", "output": "376\n" }, { "input": "-1 44\n", "output": "174\n" }, { "input": "3 -2\n", "output": "8\n" }, { "input": "100 0\n", "output": "397\n" }, { "input": "68 7\n", "output": "269\n" }, { "input": "0 2\n", "output": "6\n" }, { "input": "0 -4\n", "output": "16\n" }, { "input": "-2 -4\n", "output": "16\n" }, { "input": "14 18\n", "output": "70\n" }, { "input": "-2 -2\n", "output": "7\n" }, { "input": "26 -83\n", "output": "332\n" }, { "input": "-1 21\n", "output": "82\n" }, { "input": "3 1\n", "output": "9\n" }, { "input": "-2 44\n", "output": "174\n" }, { "input": "-3 2\n", "output": "11\n" }, { "input": "0 -5\n", "output": "20\n" }, { "input": "-4 -2\n", "output": "15\n" }, { "input": "45 -83\n", "output": "332\n" }, { "input": "2 -5\n", "output": "20\n" }, { "input": "-8 -2\n", "output": "31\n" }, { "input": "-2 21\n", "output": "82\n" }, { "input": "3 2\n", "output": "9\n" }, { "input": "-33 97\n", "output": "386\n" }, { "input": "56 8\n", "output": "221\n" }, { "input": "-2 2\n", "output": "6\n" }, { "input": "13 28\n", "output": "110\n" }, { "input": "-3 -2\n", "output": "11\n" }, { "input": "49 -83\n", "output": "332\n" }, { "input": "23 26\n", "output": "102\n" }, { "input": "-4 0\n", "output": "15\n" }, { "input": "3 4\n", "output": "14\n" } ] }
[ 0.000008876592166491679, 0.0000045314848342209015, 0.000002099150327619131, 0.0000019010815506947797, 0.0000017912231345749714, 0.0000016725701359763711, 0.0000015904809859372214, 0.0000010588019060589478, 0.0000010196365537908407, 9.830537548770238e-7, 7.424034445716105e-7, 5.855186676583469e-7, 2.409700268755387e-7 ]
279_A. Point on Spiral
2847
2847_36
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane. Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y). Input The first line contains two space-separated integers x and y (|x|, |y| ≤ 100). Output Print a single integer, showing how many times Valera has to turn. Examples Input 0 0 Output 0 Input 1 0 Output 0 Input 0 1 Output 2 Input -1 -1 Output 3
U=1 D=-1 x,y=map(int,input().split()) k=A=B=0 while 1: a,b=U,B;k+=1 if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break A=a;b=U;k+=1 if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break B=b;a=D;k+=1 if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break A=a;b=D;k+=1 if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break A,B=a,b U+=1;D-=1 if k<1:k=1 print(k-1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: a: int b: int @classmethod def from_str(cls, input_: str): a, b = input_.split('\n')[0].split(' ') a = int(a) b = int(b) return cls(a, b) def __repr__(self): return str(self.a) + ' ' + str(self.b) + '\n'
1 0
O(n)
0.000001
{ "public_tests": [ { "input": "1 0\n", "output": "0\n" }, { "input": "0 0\n", "output": "0\n" }, { "input": "0 1\n", "output": "2\n" }, { "input": "-1 -1\n", "output": "3\n" } ], "private_tests": [ { "input": "17 25\n", "output": "98\n" }, { "input": "3 -5\n", "output": "20\n" }, { "input": "0 -1\n", "output": "4\n" }, { "input": "100 100\n", "output": "397\n" }, { "input": "37 -100\n", "output": "400\n" }, { "input": "10 10\n", "output": "37\n" }, { "input": "1 -84\n", "output": "336\n" }, { "input": "2 -1\n", "output": "4\n" }, { "input": "-1 0\n", "output": "3\n" }, { "input": "0 99\n", "output": "394\n" }, { "input": "94 -94\n", "output": "376\n" }, { "input": "-96 -96\n", "output": "383\n" }, { "input": "-97 0\n", "output": "387\n" }, { "input": "1 -1\n", "output": "4\n" }, { "input": "-5 44\n", "output": "174\n" }, { "input": "0 6\n", "output": "22\n" }, { "input": "11 -15\n", "output": "60\n" }, { "input": "-98 98\n", "output": "390\n" }, { "input": "0 -95\n", "output": "380\n" }, { "input": "100 99\n", "output": "397\n" }, { "input": "42 9\n", "output": "165\n" }, { "input": "-1 1\n", "output": "2\n" }, { "input": "1 1\n", "output": "1\n" }, { "input": "-7 -13\n", "output": "52\n" }, { "input": "99 100\n", "output": "398\n" }, { "input": "16 -32\n", "output": "128\n" }, { "input": "93 0\n", "output": "369\n" }, { "input": "-81 3\n", "output": "323\n" } ], "generated_tests": [ { "input": "17 18\n", "output": "70\n" }, { "input": "6 -5\n", "output": "20\n" }, { "input": "0 -2\n", "output": "8\n" }, { "input": "56 -100\n", "output": "400\n" }, { "input": "18 10\n", "output": "69\n" }, { "input": "2 -84\n", "output": "336\n" }, { "input": "-2 0\n", "output": "7\n" }, { "input": "0 21\n", "output": "82\n" }, { "input": "78 -94\n", "output": "376\n" }, { "input": "-97 1\n", "output": "387\n" }, { "input": "-4 44\n", "output": "174\n" }, { "input": "2 1\n", "output": "5\n" }, { "input": "-98 71\n", "output": "391\n" }, { "input": "0 -14\n", "output": "56\n" }, { "input": "100 2\n", "output": "397\n" }, { "input": "68 9\n", "output": "269\n" }, { "input": "1 2\n", "output": "6\n" }, { "input": "-7 -4\n", "output": "27\n" }, { "input": "3 -32\n", "output": "128\n" }, { "input": "93 1\n", "output": "369\n" }, { "input": "-81 6\n", "output": "323\n" }, { "input": "-1 -4\n", "output": "16\n" }, { "input": "56 -83\n", "output": "332\n" }, { "input": "-4 -1\n", "output": "15\n" }, { "input": "3 0\n", "output": "9\n" }, { "input": "-47 71\n", "output": "282\n" }, { "input": "0 -28\n", "output": "112\n" }, { "input": "-3 1\n", "output": "11\n" }, { "input": "3 -49\n", "output": "196\n" }, { "input": "18 30\n", "output": "118\n" }, { "input": "2 -3\n", "output": "12\n" }, { "input": "-8 -1\n", "output": "31\n" }, { "input": "-47 97\n", "output": "386\n" }, { "input": "0 -56\n", "output": "224\n" }, { "input": "56 7\n", "output": "221\n" }, { "input": "2 4\n", "output": "14\n" }, { "input": "3 -75\n", "output": "300\n" }, { "input": "14 28\n", "output": "110\n" }, { "input": "18 26\n", "output": "102\n" }, { "input": "-2 27\n", "output": "106\n" }, { "input": "0 -97\n", "output": "388\n" }, { "input": "2 3\n", "output": "10\n" }, { "input": "0 -9\n", "output": "36\n" }, { "input": "-13 -2\n", "output": "51\n" }, { "input": "-2 12\n", "output": "46\n" }, { "input": "-2 7\n", "output": "26\n" }, { "input": "1 -2\n", "output": "8\n" }, { "input": "-2 1\n", "output": "7\n" }, { "input": "2 2\n", "output": "5\n" }, { "input": "-2 -1\n", "output": "7\n" }, { "input": "2 0\n", "output": "5\n" }, { "input": "18 18\n", "output": "69\n" }, { "input": "18 17\n", "output": "69\n" }, { "input": "4 -84\n", "output": "336\n" }, { "input": "2 -2\n", "output": "8\n" }, { "input": "1 21\n", "output": "82\n" }, { "input": "82 -94\n", "output": "376\n" }, { "input": "-1 44\n", "output": "174\n" }, { "input": "3 -2\n", "output": "8\n" }, { "input": "100 0\n", "output": "397\n" }, { "input": "68 7\n", "output": "269\n" }, { "input": "0 2\n", "output": "6\n" }, { "input": "0 -4\n", "output": "16\n" }, { "input": "-2 -4\n", "output": "16\n" }, { "input": "14 18\n", "output": "70\n" }, { "input": "-2 -2\n", "output": "7\n" }, { "input": "26 -83\n", "output": "332\n" }, { "input": "-1 21\n", "output": "82\n" }, { "input": "3 1\n", "output": "9\n" }, { "input": "-2 44\n", "output": "174\n" }, { "input": "-3 2\n", "output": "11\n" }, { "input": "0 -5\n", "output": "20\n" }, { "input": "-4 -2\n", "output": "15\n" }, { "input": "45 -83\n", "output": "332\n" }, { "input": "2 -5\n", "output": "20\n" }, { "input": "-8 -2\n", "output": "31\n" }, { "input": "-2 21\n", "output": "82\n" }, { "input": "3 2\n", "output": "9\n" }, { "input": "-33 97\n", "output": "386\n" }, { "input": "56 8\n", "output": "221\n" }, { "input": "-2 2\n", "output": "6\n" }, { "input": "13 28\n", "output": "110\n" }, { "input": "-3 -2\n", "output": "11\n" }, { "input": "49 -83\n", "output": "332\n" }, { "input": "23 26\n", "output": "102\n" }, { "input": "-4 0\n", "output": "15\n" }, { "input": "3 4\n", "output": "14\n" } ] }
[ 0.00005443138786604021, 0.000008423445107626747, 0.000008240645856097028, 0.000006365983282342657, 0.000004833793993116259, 0.000003063761431927448, 0.0000028709705802010485, 0.000002102293815559441, 0.0000014267415592220282 ]
279_A. Point on Spiral
2847
2847_45
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane. Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y). Input The first line contains two space-separated integers x and y (|x|, |y| ≤ 100). Output Print a single integer, showing how many times Valera has to turn. Examples Input 0 0 Output 0 Input 1 0 Output 0 Input 0 1 Output 2 Input -1 -1 Output 3
'''l = [[(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), (-1, 1)], [(-1, 1), (-1, -1)], [(-1, - 1), (2, -1)], [(2, -1), (2, 2)]] ''' ''' pattern er shudhone na paria last e net theke copy marcha pattern copy marcha re. ''' x,y = map(int, input().split()) if y >= x and y < -x: print(-4*x-1) elif y > x and y >= -x: print(4*y-2) elif y <= x and y > 1-x: print(4*x-3) elif y < x and y <= 1-x: print(-4*y) else: print(0)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass @dataclass class Input: a: int b: int @classmethod def from_str(cls, input_: str): a, b = input_.split('\n')[0].split(' ') a = int(a) b = int(b) return cls(a, b) def __repr__(self): return str(self.a) + ' ' + str(self.b) + '\n'
1 0
O(1)
0.000002
{ "public_tests": [ { "input": "1 0\n", "output": "0\n" }, { "input": "0 0\n", "output": "0\n" }, { "input": "0 1\n", "output": "2\n" }, { "input": "-1 -1\n", "output": "3\n" } ], "private_tests": [ { "input": "17 25\n", "output": "98\n" }, { "input": "3 -5\n", "output": "20\n" }, { "input": "0 -1\n", "output": "4\n" }, { "input": "100 100\n", "output": "397\n" }, { "input": "37 -100\n", "output": "400\n" }, { "input": "10 10\n", "output": "37\n" }, { "input": "1 -84\n", "output": "336\n" }, { "input": "2 -1\n", "output": "4\n" }, { "input": "-1 0\n", "output": "3\n" }, { "input": "0 99\n", "output": "394\n" }, { "input": "94 -94\n", "output": "376\n" }, { "input": "-96 -96\n", "output": "383\n" }, { "input": "-97 0\n", "output": "387\n" }, { "input": "1 -1\n", "output": "4\n" }, { "input": "-5 44\n", "output": "174\n" }, { "input": "0 6\n", "output": "22\n" }, { "input": "11 -15\n", "output": "60\n" }, { "input": "-98 98\n", "output": "390\n" }, { "input": "0 -95\n", "output": "380\n" }, { "input": "100 99\n", "output": "397\n" }, { "input": "42 9\n", "output": "165\n" }, { "input": "-1 1\n", "output": "2\n" }, { "input": "1 1\n", "output": "1\n" }, { "input": "-7 -13\n", "output": "52\n" }, { "input": "99 100\n", "output": "398\n" }, { "input": "16 -32\n", "output": "128\n" }, { "input": "93 0\n", "output": "369\n" }, { "input": "-81 3\n", "output": "323\n" } ], "generated_tests": [ { "input": "17 18\n", "output": "70\n" }, { "input": "6 -5\n", "output": "20\n" }, { "input": "0 -2\n", "output": "8\n" }, { "input": "56 -100\n", "output": "400\n" }, { "input": "18 10\n", "output": "69\n" }, { "input": "2 -84\n", "output": "336\n" }, { "input": "-2 0\n", "output": "7\n" }, { "input": "0 21\n", "output": "82\n" }, { "input": "78 -94\n", "output": "376\n" }, { "input": "-97 1\n", "output": "387\n" }, { "input": "-4 44\n", "output": "174\n" }, { "input": "2 1\n", "output": "5\n" }, { "input": "-98 71\n", "output": "391\n" }, { "input": "0 -14\n", "output": "56\n" }, { "input": "100 2\n", "output": "397\n" }, { "input": "68 9\n", "output": "269\n" }, { "input": "1 2\n", "output": "6\n" }, { "input": "-7 -4\n", "output": "27\n" }, { "input": "3 -32\n", "output": "128\n" }, { "input": "93 1\n", "output": "369\n" }, { "input": "-81 6\n", "output": "323\n" }, { "input": "-1 -4\n", "output": "16\n" }, { "input": "56 -83\n", "output": "332\n" }, { "input": "-4 -1\n", "output": "15\n" }, { "input": "3 0\n", "output": "9\n" }, { "input": "-47 71\n", "output": "282\n" }, { "input": "0 -28\n", "output": "112\n" }, { "input": "-3 1\n", "output": "11\n" }, { "input": "3 -49\n", "output": "196\n" }, { "input": "18 30\n", "output": "118\n" }, { "input": "2 -3\n", "output": "12\n" }, { "input": "-8 -1\n", "output": "31\n" }, { "input": "-47 97\n", "output": "386\n" }, { "input": "0 -56\n", "output": "224\n" }, { "input": "56 7\n", "output": "221\n" }, { "input": "2 4\n", "output": "14\n" }, { "input": "3 -75\n", "output": "300\n" }, { "input": "14 28\n", "output": "110\n" }, { "input": "18 26\n", "output": "102\n" }, { "input": "-2 27\n", "output": "106\n" }, { "input": "0 -97\n", "output": "388\n" }, { "input": "2 3\n", "output": "10\n" }, { "input": "0 -9\n", "output": "36\n" }, { "input": "-13 -2\n", "output": "51\n" }, { "input": "-2 12\n", "output": "46\n" }, { "input": "-2 7\n", "output": "26\n" }, { "input": "1 -2\n", "output": "8\n" }, { "input": "-2 1\n", "output": "7\n" }, { "input": "2 2\n", "output": "5\n" }, { "input": "-2 -1\n", "output": "7\n" }, { "input": "2 0\n", "output": "5\n" }, { "input": "18 18\n", "output": "69\n" }, { "input": "18 17\n", "output": "69\n" }, { "input": "4 -84\n", "output": "336\n" }, { "input": "2 -2\n", "output": "8\n" }, { "input": "1 21\n", "output": "82\n" }, { "input": "82 -94\n", "output": "376\n" }, { "input": "-1 44\n", "output": "174\n" }, { "input": "3 -2\n", "output": "8\n" }, { "input": "100 0\n", "output": "397\n" }, { "input": "68 7\n", "output": "269\n" }, { "input": "0 2\n", "output": "6\n" }, { "input": "0 -4\n", "output": "16\n" }, { "input": "-2 -4\n", "output": "16\n" }, { "input": "14 18\n", "output": "70\n" }, { "input": "-2 -2\n", "output": "7\n" }, { "input": "26 -83\n", "output": "332\n" }, { "input": "-1 21\n", "output": "82\n" }, { "input": "3 1\n", "output": "9\n" }, { "input": "-2 44\n", "output": "174\n" }, { "input": "-3 2\n", "output": "11\n" }, { "input": "0 -5\n", "output": "20\n" }, { "input": "-4 -2\n", "output": "15\n" }, { "input": "45 -83\n", "output": "332\n" }, { "input": "2 -5\n", "output": "20\n" }, { "input": "-8 -2\n", "output": "31\n" }, { "input": "-2 21\n", "output": "82\n" }, { "input": "3 2\n", "output": "9\n" }, { "input": "-33 97\n", "output": "386\n" }, { "input": "56 8\n", "output": "221\n" }, { "input": "-2 2\n", "output": "6\n" }, { "input": "13 28\n", "output": "110\n" }, { "input": "-3 -2\n", "output": "11\n" }, { "input": "49 -83\n", "output": "332\n" }, { "input": "23 26\n", "output": "102\n" }, { "input": "-4 0\n", "output": "15\n" }, { "input": "3 4\n", "output": "14\n" } ] }
[ 0.0037606989999999924, 0.000340458, 0.000008769999999999999, 0.000008268000000000003, 0.000008193000000000001, 0.000007788999999999996, 0.0000058910000000000085, 0.000005725499999999998, 0.000004618000000000002, 0.000003237000000000003, 0.0000031035000000000017, 0.0000029064999999999967, 0.0000027790000000000017, 0.0000026404999999999995, 0.0000026034999999999997, 0.000002536499999999985, 0.000002516500000000002, 0.0000024834999999999975, 0.000002415000000000003, 0.0000023329999999999995, 0.000002327, 0.000002324, 0.0000023124999999999952, 0.000002259, 0.000002229000000000002, 0.000002192500000000003, 0.0000021820000000000005, 0.0000021639999999999983, 0.000002092999999999995, 0.0000020770000000000006, 0.000002019000000000002, 0.0000018435000000000002, 0.0000018255000000000014, 0.0000017139999999999975, 0.0000014589999999999974, 8.145000000000004e-7, 3.3300000000000003e-7, 2.2850000000000001e-7, 2.1649999999999996e-7 ]
1422_A. Fence
2577
2577_283
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to a, b, c, and d. Help Yura, find any possible length of the fourth side. A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself. Input The first line contains a single integer t — the number of test cases (1 ≤ t ≤ 1000). The next t lines describe the test cases. Each line contains three integers a, b, and c — the lengths of the three fence segments (1 ≤ a, b, c ≤ 10^9). Output For each test case print a single integer d — the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists. Example Input 2 1 2 3 12 34 56 Output 4 42 Note We can build a quadrilateral with sides 1, 2, 3, 4. We can build a quadrilateral with sides 12, 34, 56, 42.
import sys import math input = sys.stdin.readline def inInt(): return int(input()) def inStr(): return input().strip("\n") def inIList(): return (list(map(int, input().split()))) def inSList(): return (input().split()) ######################################### def solve(l): print(sum(l) - 1) tasks = inInt() for t in range(tasks): l = inIList() solve(l)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int mat: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) mat = [list(map(int, line.split())) for line in lines[1:-1]] assert len(mat) == n return cls(n, mat) def __repr__(self): return str(self.n) + '\n' + '\n'.join(' '.join(map(str, row)) for row in self.mat) + '\n'
2 1 2 3 12 34 56
O(n*m)
0.000003
{ "public_tests": [ { "input": "2\n1 2 3\n12 34 56\n", "output": "5\n101\n" } ], "private_tests": [ { "input": "1\n5 4 3\n", "output": "11\n" }, { "input": "1\n2434 2442 14\n", "output": "4889\n" }, { "input": "1\n3 4 5\n", "output": "11\n" }, { "input": "1\n10 20 10\n", "output": "39\n" }, { "input": "2\n1 2 3\n12 34 56\n", "output": "5\n101\n" }, { "input": "1\n2 1 2\n", "output": "4\n" } ], "generated_tests": [ { "input": "1\n6 4 3\n", "output": "12\n" }, { "input": "1\n4647 2442 14\n", "output": "7102\n" }, { "input": "1\n3 1 5\n", "output": "8\n" }, { "input": "1\n9 20 10\n", "output": "38\n" }, { "input": "2\n1 2 6\n12 34 56\n", "output": "8\n101\n" }, { "input": "1\n2 0 2\n", "output": "3\n" }, { "input": "2\n1 2 3\n12 15 56\n", "output": "5\n82\n" }, { "input": "1\n6 4 6\n", "output": "15\n" }, { "input": "1\n4647 2825 14\n", "output": "7485\n" }, { "input": "1\n3 1 2\n", "output": "5\n" }, { "input": "1\n9 22 10\n", "output": "40\n" }, { "input": "2\n1 2 6\n12 16 56\n", "output": "8\n83\n" }, { "input": "1\n4 1 2\n", "output": "6\n" }, { "input": "2\n1 2 3\n12 23 56\n", "output": "5\n90\n" }, { "input": "1\n8 4 6\n", "output": "17\n" }, { "input": "1\n4647 5545 14\n", "output": "10205\n" }, { "input": "1\n9 22 20\n", "output": "50\n" }, { "input": "2\n1 2 6\n18 16 56\n", "output": "8\n89\n" }, { "input": "2\n1 2 3\n12 39 56\n", "output": "5\n106\n" }, { "input": "1\n4647 5545 21\n", "output": "10212\n" }, { "input": "1\n9 31 20\n", "output": "59\n" }, { "input": "2\n1 2 6\n18 16 53\n", "output": "8\n86\n" }, { "input": "1\n4 0 1\n", "output": "4\n" }, { "input": "2\n1 2 6\n12 39 56\n", "output": "8\n106\n" }, { "input": "1\n1398 5545 21\n", "output": "6963\n" }, { "input": "1\n2 31 20\n", "output": "52\n" }, { "input": "2\n1 2 6\n18 16 28\n", "output": "8\n61\n" }, { "input": "1\n7 0 1\n", "output": "7\n" }, { "input": "2\n1 2 6\n12 8 56\n", "output": "8\n75\n" }, { "input": "1\n5 6 4\n", "output": "14\n" }, { "input": "1\n1812 5545 21\n", "output": "7377\n" }, { "input": "1\n2 39 20\n", "output": "60\n" }, { "input": "2\n1 1 6\n18 16 28\n", "output": "7\n61\n" }, { "input": "2\n1 2 6\n12 8 14\n", "output": "8\n33\n" }, { "input": "1\n5 11 4\n", "output": "19\n" }, { "input": "1\n1812 5545 4\n", "output": "7360\n" }, { "input": "1\n-2 0 5\n", "output": "2\n" }, { "input": "1\n0 39 20\n", "output": "58\n" }, { "input": "2\n1 4 6\n18 16 28\n", "output": "10\n61\n" }, { "input": "2\n2 2 6\n12 8 14\n", "output": "9\n33\n" }, { "input": "1\n7 11 4\n", "output": "21\n" }, { "input": "1\n1812 5545 8\n", "output": "7364\n" }, { "input": "1\n-2 -1 5\n", "output": "1\n" }, { "input": "1\n0 17 20\n", "output": "36\n" }, { "input": "2\n1 4 6\n2 16 28\n", "output": "10\n45\n" }, { "input": "2\n2 2 6\n12 8 23\n", "output": "9\n42\n" }, { "input": "1\n7 11 5\n", "output": "22\n" }, { "input": "1\n1812 5545 1\n", "output": "7357\n" }, { "input": "1\n0 17 12\n", "output": "28\n" }, { "input": "2\n0 4 6\n2 16 28\n", "output": "9\n45\n" }, { "input": "1\n13 -2 1\n", "output": "11\n" }, { "input": "2\n2 2 6\n6 8 23\n", "output": "9\n36\n" }, { "input": "1\n1812 4018 1\n", "output": "5830\n" }, { "input": "1\n0 7 12\n", "output": "18\n" }, { "input": "2\n0 4 6\n4 16 28\n", "output": "9\n47\n" }, { "input": "2\n2 4 6\n6 8 23\n", "output": "11\n36\n" }, { "input": "1\n1812 7912 1\n", "output": "9724\n" }, { "input": "1\n0 14 12\n", "output": "25\n" }, { "input": "2\n0 4 6\n1 16 28\n", "output": "9\n44\n" }, { "input": "2\n2 4 6\n6 8 0\n", "output": "11\n13\n" }, { "input": "1\n4 11 6\n", "output": "20\n" }, { "input": "1\n1860 7912 1\n", "output": "9772\n" }, { "input": "1\n-1 -2 1\n", "output": "-3\n" }, { "input": "1\n-1 14 12\n", "output": "24\n" }, { "input": "2\n0 7 6\n1 16 28\n", "output": "12\n44\n" }, { "input": "2\n2 4 6\n4 8 0\n", "output": "11\n11\n" }, { "input": "1\n1860 7912 2\n", "output": "9773\n" }, { "input": "1\n-1 -2 2\n", "output": "-2\n" }, { "input": "1\n-1 19 12\n", "output": "29\n" }, { "input": "2\n0 7 12\n1 16 28\n", "output": "18\n44\n" }, { "input": "1\n19 -2 0\n", "output": "16\n" }, { "input": "2\n2 4 6\n5 8 0\n", "output": "11\n12\n" }, { "input": "1\n1860 7912 3\n", "output": "9774\n" }, { "input": "2\n0 10 12\n1 16 28\n", "output": "21\n44\n" }, { "input": "2\n2 4 6\n5 16 0\n", "output": "11\n20\n" }, { "input": "1\n11 11 2\n", "output": "23\n" }, { "input": "1\n1860 555 3\n", "output": "2417\n" }, { "input": "2\n0 7 11\n1 16 28\n", "output": "17\n44\n" }, { "input": "1\n37 -2 0\n", "output": "34\n" }, { "input": "2\n2 5 6\n5 16 0\n", "output": "12\n20\n" }, { "input": "1\n19 11 2\n", "output": "31\n" }, { "input": "1\n3 1 3\n", "output": "6\n" }, { "input": "1\n4 0 2\n", "output": "5\n" }, { "input": "1\n8 4 4\n", "output": "15\n" }, { "input": "1\n0 1 5\n", "output": "5\n" }, { "input": "1\n5 4 4\n", "output": "12\n" }, { "input": "1\n0 0 5\n", "output": "4\n" }, { "input": "1\n-1 0 5\n", "output": "3\n" }, { "input": "1\n7 -1 1\n", "output": "6\n" }, { "input": "1\n7 -2 1\n", "output": "5\n" }, { "input": "1\n7 -2 2\n", "output": "6\n" }, { "input": "1\n-1 -1 5\n", "output": "2\n" }, { "input": "1\n4 11 5\n", "output": "19\n" }, { "input": "1\n-1 -1 6\n", "output": "3\n" }, { "input": "1\n5 -2 1\n", "output": "3\n" }, { "input": "1\n4 11 4\n", "output": "18\n" }, { "input": "1\n-1 -2 6\n", "output": "2\n" }, { "input": "1\n10 -2 1\n", "output": "8\n" }, { "input": "1\n19 -2 1\n", "output": "17\n" }, { "input": "1\n6 11 6\n", "output": "22\n" } ] }
[ 0.00017808333442143794, 0.000007093000519012237, 0.000003641117911385489, 0.0000036113323453889863, 0.0000033805921383304194, 0.0000032591316788680074, 0.0000032536617952360146, 0.0000031862634943181827, 0.0000031039679031905595, 0.0000030228281796328674, 0.000002999139341127623, 0.0000029904806326486015, 0.000002989011909965035, 0.0000029854794990166085, 0.000002984452100633742, 0.0000029731496940559436, 0.000002925323604130245, 0.0000028964882949082173, 0.0000028635368225524473, 0.000002838271320476399, 0.0000028358634041739514, 0.0000028312738062718535, 0.000002820581348339161, 0.0000028166495984484264, 0.000002811560437609266, 0.0000028096890843531473, 0.000002802520350743007, 0.0000028001422776442313, 0.000002799898628715035, 0.000002796476343968532, 0.000002789405635380245, 0.000002787876584353147, 0.000002787386472902098, 0.0000027833866914335665, 0.0000027800417668269233, 0.0000027784867925043705, 0.0000027781277726180068, 0.000002775598161604021, 0.0000027755742187500003, 0.0000027754211237980776, 0.000002775043678977273, 0.0000027747246640078672, 0.0000027736367460664337, 0.000002773348475743007, 0.0000027710068973994753, 0.0000027705559030812944, 0.0000027664570858828673, 0.000002765558866914336, 0.0000027648792203889867, 0.0000027646679550917835, 0.0000027636548295454547, 0.0000027634733255026226, 0.00000276221832659528, 0.000002761763699191434, 0.000002761496325939686, 0.0000027611035292832166, 0.0000027606335910183568, 0.000002758994809877622, 0.000002757349104020979, 0.0000027569455446896854, 0.0000027557566788680073, 0.000002755133891499126, 0.000002754210732626748, 0.000002751993321131993, 0.000002749367474322553, 0.000002748787560096154, 0.000002748570517373252, 0.0000027484917640952796, 0.000002745086019449301, 0.0000027405621585445806, 0.0000027398842329545454, 0.000002738546519886364, 0.0000027366626830201054, 0.000002731970948972903, 0.000002730908025568182, 0.000002729116094842658, 0.000002726121148382867, 0.0000027221536139641612, 0.000002720666862434441, 0.000002718869017701049, 0.000002717176464160839, 0.000002700682979130245, 0.0000026875681681599648, 0.0000026801025595498252, 0.0000026676328125, 0.0000026542355496066433, 0.0000026513633358828673, 0.0000026498869645979023, 0.000002642103679523602, 0.000002638497760052448, 0.0000026347368334790213, 0.000002633025103802448, 0.000002626640351835664, 0.0000026243549907124125, 0.0000026233408817744756, 0.000002623034787478147, 0.0000026221484511582172, 0.0000026178824027534967, 0.000002615794607736014, 0.000002614971140187937, 0.0000026128319356424827, 0.000002612569752513112, 0.0000026107351398601403, 0.000002607219596809441, 0.000002605134533435315, 0.0000026041920208697553, 0.0000026020164171765733, 0.000002600577237215909, 0.0000025984766717657343, 0.0000025976048131555943, 0.0000025949640105987767, 0.0000025946579436188816, 0.000002593942471590909, 0.0000025932724131337414, 0.0000025877863445148605, 0.000002586614442198427, 0.000002586551996831294, 0.0000025859492733828674, 0.0000025854079845935317, 0.0000025852743116258745, 0.0000025841381801791957, 0.0000025834551190996507, 0.000002582542722902098, 0.000002581531454873252, 0.0000025796186762456296, 0.000002577342589051574, 0.0000025768380681818182, 0.0000025764380463286714, 0.000002576366340690559, 0.0000025758692362325177, 0.000002575296752076049, 0.000002574322757320804, 0.0000025722459161931818, 0.0000025717090936407344, 0.000002571655498798077, 0.0000025712542613636366, 0.000002571214393028846, 0.0000025699678895323423, 0.0000025690885598776225, 0.000002568055698208042, 0.0000025676114920236013, 0.000002566596331402972, 0.0000025661582440996507, 0.0000025641866531905597, 0.0000025636145651223777, 0.000002562597082604895, 0.0000025603303103146854, 0.0000025569477573208044, 0.0000025567883249562937, 0.0000025564979512674827, 0.000002556050234921329, 0.0000025553483391608393, 0.0000025541566734047207, 0.0000025526453234265735, 0.000002552260462194056, 0.000002551691351617133, 0.0000025515343094405595, 0.000002551186680506993, 0.0000025499813838505245, 0.000002549237161276224, 0.0000025488654392482518, 0.000002548721345061189, 0.0000025477025923295452, 0.0000025467395241477275, 0.0000025455222082604894, 0.0000025381375792176578, 0.0000025372652562281466, 0.000002537112543706294, 0.0000025364352873688813, 0.0000025347376119973777, 0.0000025341981670673082, 0.000002532314466783217, 0.000002529434809331294, 0.0000025282129315996504, 0.000002527879575502623, 0.00000252644446569056, 0.00000252541168597028, 0.0000025249885817307696, 0.000002524273000437063, 0.000002524236205201049, 0.0000025220532124125873, 0.000002521466605659965, 0.0000025201973065996504, 0.0000025198906250000004, 0.000002519320981752622, 0.0000025176413898601403, 0.0000025168031577797206, 0.0000025143331512237762, 0.0000025142495492788467, 0.00000251326167777535, 0.000002501290155157343, 0.0000024967240630463288, 0.000002492995342548077, 0.0000024917283653846157, 0.0000024898888767482515, 0.0000024898016553758743, 0.0000024877000792176573, 0.000002486127622377623, 0.0000024842128223339156, 0.0000024754585336538464, 0.000002473846454326923, 0.00000247137419416521, 0.0000024690903354458044, 0.0000024611818454982522, 0.000002451829135708042, 0.0000012606758358828673, 0.000001129185546875, 0.0000011213702742569931, 0.000001093039636145105, 0.0000010902663352272726, 0.000001090012920673077, 0.0000010871724623033216, 0.0000010859867242132867, 0.0000010841813947770979, 0.0000010822976125437062, 0.0000010794407916302449, 0.0000010761914335664335, 0.0000010738684167395106, 0.0000010658523546765735, 0.0000010653032670454546, 1.2971618225524465e-9, 3.455050808566435e-10, 2.5715690559440536e-10, 2.3119263548951066e-10 ]
1422_A. Fence
2577
2577_822
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to a, b, c, and d. Help Yura, find any possible length of the fourth side. A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself. Input The first line contains a single integer t — the number of test cases (1 ≤ t ≤ 1000). The next t lines describe the test cases. Each line contains three integers a, b, and c — the lengths of the three fence segments (1 ≤ a, b, c ≤ 10^9). Output For each test case print a single integer d — the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists. Example Input 2 1 2 3 12 34 56 Output 4 42 Note We can build a quadrilateral with sides 1, 2, 3, 4. We can build a quadrilateral with sides 12, 34, 56, 42.
import math T = int(input()) #lets = 'abcdefghijklmnopqrstuvwxyz' #key = {lets[i]:i for i in range(26)} for t in range(T): #n = int(input()) a,b,c = map(int,input().split()) #a = list(map(int,input().split())) #a = input() d = False print(a+b+c-1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, log2 import fractions from typing import List, Tuple import numpy as np import random import heapq from heapq import * from dataclasses import dataclass import builtins import re def strip(s, characters = None): if characters is None: characters = [' ', '\t', '\n', '\r', '\v', '\f'] else: characters = list(characters) characters = [x for x in characters if len(x) > 0] i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in characters: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True i += len(sep_candidate) break if not found_sep_candidate: break j = len(s) - 1 while j >= 0: found_sep_candidate = False for sep_candidate in characters: if s[j + 1 - len(sep_candidate):j+1] == sep_candidate: found_sep_candidate = True j -= len(sep_candidate) break if not found_sep_candidate: break return s[i:j+1] def split(s, sep=None, maxsplit=-1): if sep == '': raise builtins.ValueError('empty separator') if type(sep) == list and '' in sep: raise builtins.ValueError('empty separator') if sep is None: sep = [' ', '\t', '\n', '\r', '\v', '\f'] result = [] word = '' count_split = 0 if maxsplit == -1: maxsplit = len(s) * 1000 i = 0 while i < len(s): found_sep_candidate = False for sep_candidate in sep: if s[i:i + len(sep_candidate)] == sep_candidate: found_sep_candidate = True if word: result.append(word) count_split += 1 word = '' i += len(sep_candidate) break if not found_sep_candidate and count_split < maxsplit: word += s[i] i += 1 elif not found_sep_candidate and count_split >= maxsplit: word += s[i:] i = len(s) if word: result.append(word) return result if type(sep) == str: sep = [sep] if maxsplit == -1: maxsplit = 0 elif maxsplit == 0: maxsplit = -1 return re.split(re.compile("|".join([re.escape(x) for x in sep])), s, maxsplit=maxsplit) class str_escaped(str): def split(self, sep=None, maxsplit=-1): return split(self, sep=sep, maxsplit=maxsplit) def strip(self, chars=None): return strip(self, characters = chars) from dataclasses import dataclass from typing import List @dataclass class Input: n: int mat: List[List[int]] @classmethod def from_str(cls, input_: str): lines = input_.split('\n') n = int(lines[0]) mat = [list(map(int, line.split())) for line in lines[1:-1]] assert len(mat) == n return cls(n, mat) def __repr__(self): return str(self.n) + '\n' + '\n'.join(' '.join(map(str, row)) for row in self.mat) + '\n'
2 1 2 3 12 34 56
O(n)
0.000009
{ "public_tests": [ { "input": "2\n1 2 3\n12 34 56\n", "output": "5\n101\n" } ], "private_tests": [ { "input": "1\n5 4 3\n", "output": "11\n" }, { "input": "1\n2434 2442 14\n", "output": "4889\n" }, { "input": "1\n3 4 5\n", "output": "11\n" }, { "input": "1\n10 20 10\n", "output": "39\n" }, { "input": "2\n1 2 3\n12 34 56\n", "output": "5\n101\n" }, { "input": "1\n2 1 2\n", "output": "4\n" } ], "generated_tests": [ { "input": "1\n6 4 3\n", "output": "12\n" }, { "input": "1\n4647 2442 14\n", "output": "7102\n" }, { "input": "1\n3 1 5\n", "output": "8\n" }, { "input": "1\n9 20 10\n", "output": "38\n" }, { "input": "2\n1 2 6\n12 34 56\n", "output": "8\n101\n" }, { "input": "1\n2 0 2\n", "output": "3\n" }, { "input": "2\n1 2 3\n12 15 56\n", "output": "5\n82\n" }, { "input": "1\n6 4 6\n", "output": "15\n" }, { "input": "1\n4647 2825 14\n", "output": "7485\n" }, { "input": "1\n3 1 2\n", "output": "5\n" }, { "input": "1\n9 22 10\n", "output": "40\n" }, { "input": "2\n1 2 6\n12 16 56\n", "output": "8\n83\n" }, { "input": "1\n4 1 2\n", "output": "6\n" }, { "input": "2\n1 2 3\n12 23 56\n", "output": "5\n90\n" }, { "input": "1\n8 4 6\n", "output": "17\n" }, { "input": "1\n4647 5545 14\n", "output": "10205\n" }, { "input": "1\n9 22 20\n", "output": "50\n" }, { "input": "2\n1 2 6\n18 16 56\n", "output": "8\n89\n" }, { "input": "2\n1 2 3\n12 39 56\n", "output": "5\n106\n" }, { "input": "1\n4647 5545 21\n", "output": "10212\n" }, { "input": "1\n9 31 20\n", "output": "59\n" }, { "input": "2\n1 2 6\n18 16 53\n", "output": "8\n86\n" }, { "input": "1\n4 0 1\n", "output": "4\n" }, { "input": "2\n1 2 6\n12 39 56\n", "output": "8\n106\n" }, { "input": "1\n1398 5545 21\n", "output": "6963\n" }, { "input": "1\n2 31 20\n", "output": "52\n" }, { "input": "2\n1 2 6\n18 16 28\n", "output": "8\n61\n" }, { "input": "1\n7 0 1\n", "output": "7\n" }, { "input": "2\n1 2 6\n12 8 56\n", "output": "8\n75\n" }, { "input": "1\n5 6 4\n", "output": "14\n" }, { "input": "1\n1812 5545 21\n", "output": "7377\n" }, { "input": "1\n2 39 20\n", "output": "60\n" }, { "input": "2\n1 1 6\n18 16 28\n", "output": "7\n61\n" }, { "input": "2\n1 2 6\n12 8 14\n", "output": "8\n33\n" }, { "input": "1\n5 11 4\n", "output": "19\n" }, { "input": "1\n1812 5545 4\n", "output": "7360\n" }, { "input": "1\n-2 0 5\n", "output": "2\n" }, { "input": "1\n0 39 20\n", "output": "58\n" }, { "input": "2\n1 4 6\n18 16 28\n", "output": "10\n61\n" }, { "input": "2\n2 2 6\n12 8 14\n", "output": "9\n33\n" }, { "input": "1\n7 11 4\n", "output": "21\n" }, { "input": "1\n1812 5545 8\n", "output": "7364\n" }, { "input": "1\n-2 -1 5\n", "output": "1\n" }, { "input": "1\n0 17 20\n", "output": "36\n" }, { "input": "2\n1 4 6\n2 16 28\n", "output": "10\n45\n" }, { "input": "2\n2 2 6\n12 8 23\n", "output": "9\n42\n" }, { "input": "1\n7 11 5\n", "output": "22\n" }, { "input": "1\n1812 5545 1\n", "output": "7357\n" }, { "input": "1\n0 17 12\n", "output": "28\n" }, { "input": "2\n0 4 6\n2 16 28\n", "output": "9\n45\n" }, { "input": "1\n13 -2 1\n", "output": "11\n" }, { "input": "2\n2 2 6\n6 8 23\n", "output": "9\n36\n" }, { "input": "1\n1812 4018 1\n", "output": "5830\n" }, { "input": "1\n0 7 12\n", "output": "18\n" }, { "input": "2\n0 4 6\n4 16 28\n", "output": "9\n47\n" }, { "input": "2\n2 4 6\n6 8 23\n", "output": "11\n36\n" }, { "input": "1\n1812 7912 1\n", "output": "9724\n" }, { "input": "1\n0 14 12\n", "output": "25\n" }, { "input": "2\n0 4 6\n1 16 28\n", "output": "9\n44\n" }, { "input": "2\n2 4 6\n6 8 0\n", "output": "11\n13\n" }, { "input": "1\n4 11 6\n", "output": "20\n" }, { "input": "1\n1860 7912 1\n", "output": "9772\n" }, { "input": "1\n-1 -2 1\n", "output": "-3\n" }, { "input": "1\n-1 14 12\n", "output": "24\n" }, { "input": "2\n0 7 6\n1 16 28\n", "output": "12\n44\n" }, { "input": "2\n2 4 6\n4 8 0\n", "output": "11\n11\n" }, { "input": "1\n1860 7912 2\n", "output": "9773\n" }, { "input": "1\n-1 -2 2\n", "output": "-2\n" }, { "input": "1\n-1 19 12\n", "output": "29\n" }, { "input": "2\n0 7 12\n1 16 28\n", "output": "18\n44\n" }, { "input": "1\n19 -2 0\n", "output": "16\n" }, { "input": "2\n2 4 6\n5 8 0\n", "output": "11\n12\n" }, { "input": "1\n1860 7912 3\n", "output": "9774\n" }, { "input": "2\n0 10 12\n1 16 28\n", "output": "21\n44\n" }, { "input": "2\n2 4 6\n5 16 0\n", "output": "11\n20\n" }, { "input": "1\n11 11 2\n", "output": "23\n" }, { "input": "1\n1860 555 3\n", "output": "2417\n" }, { "input": "2\n0 7 11\n1 16 28\n", "output": "17\n44\n" }, { "input": "1\n37 -2 0\n", "output": "34\n" }, { "input": "2\n2 5 6\n5 16 0\n", "output": "12\n20\n" }, { "input": "1\n19 11 2\n", "output": "31\n" }, { "input": "1\n3 1 3\n", "output": "6\n" }, { "input": "1\n4 0 2\n", "output": "5\n" }, { "input": "1\n8 4 4\n", "output": "15\n" }, { "input": "1\n0 1 5\n", "output": "5\n" }, { "input": "1\n5 4 4\n", "output": "12\n" }, { "input": "1\n0 0 5\n", "output": "4\n" }, { "input": "1\n-1 0 5\n", "output": "3\n" }, { "input": "1\n7 -1 1\n", "output": "6\n" }, { "input": "1\n7 -2 1\n", "output": "5\n" }, { "input": "1\n7 -2 2\n", "output": "6\n" }, { "input": "1\n-1 -1 5\n", "output": "2\n" }, { "input": "1\n4 11 5\n", "output": "19\n" }, { "input": "1\n-1 -1 6\n", "output": "3\n" }, { "input": "1\n5 -2 1\n", "output": "3\n" }, { "input": "1\n4 11 4\n", "output": "18\n" }, { "input": "1\n-1 -2 6\n", "output": "2\n" }, { "input": "1\n10 -2 1\n", "output": "8\n" }, { "input": "1\n19 -2 1\n", "output": "17\n" }, { "input": "1\n6 11 6\n", "output": "22\n" } ] }
[ 0.0000405888535975743, 0.00004007272373524913, 0.00003804945838341347, 0.000037967302447552453, 0.000037733148888221155, 0.000037728556435751746, 0.00003721507685478584, 0.00003682368692635489, 0.00003614325706129808, 0.00003593210661604021, 0.000035812551819274474, 0.00003577688262128497, 0.000035748957249781466, 0.000035695739373907344, 0.00003566928813374126, 0.00003523365204326923, 0.000035188060505900355, 0.00003491657079053759, 0.00003483441814630682, 0.000034807327305507, 0.00003476684799770542, 0.00003461141269667832, 0.0000345505234375, 0.00003402114521416084, 0.00003402023636909965, 0.00003391815698754371, 0.000033715641144012235, 0.00003338672964925699, 0.00003336747526496941, 0.00003329342101453234, 0.000033289822634396853, 0.000033264013562609266, 0.000032967414554195806, 0.00003264959224759616, 0.0000326044064958479, 0.00003259427980222903, 0.00003255288517537151, 0.00003248476012073864, 0.00003246149452305507, 0.000032279937499999995, 0.00003217806595552885, 0.00003130086695531032, 0.00003061162599704983, 0.000029637255039881996, 0.000021770219610467656, 0.000021739088040865386, 0.00001835655022126311, 0.00001791926425917832, 0.000017047598639641613, 0.000016290084653627622, 0.000016262493471372378, 0.0000161988217739292, 0.00001591184493826486, 0.000015785455610795455, 0.000015762244222574302, 0.000014449468463177447, 0.000014277507853474652, 0.000014008013945039334, 0.00001392542990603147, 0.000013719294785292836, 0.000013711407001201923, 0.000013711286631337412, 0.00001346934689138986, 0.000013458764136254371, 0.00001334121433839598, 0.000013339952168924827, 0.00001301283899694056, 0.00001278461612215909, 0.000012710377076048952, 0.000012693360276442308, 0.000012635958834134617, 0.000012496576718203672, 0.000012192828903518357, 0.000012155816611123253, 0.000011931677543159966, 0.000011821238021743883, 0.000011774739933894232, 0.000011640052502185317, 0.000011631146839488637, 0.000011624132539335665, 0.000011623918050699301, 0.00001158780303485577, 0.000011576643534200176, 0.000011564419361888112, 0.000011537821500764861, 0.000011473957932692308, 0.000011462462808675699, 0.00001144266889750874, 0.00001143358670236014, 0.000011432670113090035, 0.000011421548896416083, 0.00001137540060915647, 0.000011308902029611015, 0.000011217630026223777, 0.000011156368553321679, 0.000011130697716346155, 0.000011100530061735141, 0.00001109540179742133, 0.0000110905663243007, 0.000011082190846263113, 0.000011079604676573427, 0.000011048434058129371, 0.000011040557719624128, 0.000011024581252731644, 0.000010998722041630247, 0.000010881583451704547, 0.00001079319671929633, 0.000010773097902097902, 0.00001074497941706731, 0.000010724018465909092, 0.000010710970921656468, 0.000010664564999453673, 0.000010641890351835665, 0.000010624279392482516, 0.000010593251256555946, 0.000010563478993662587, 0.00001055270054359703, 0.000010543181626966783, 0.000010536946104676574, 0.000010515850319602272, 0.000010504992214816434, 0.000010495692225743008, 0.000010469411959134617, 0.000010432694137893357, 0.00001040229081075175, 0.000010383902548623251, 0.000010356644804414336, 0.00001035537648874563, 0.000010346061530266607, 0.000010344012797749125, 0.000010340575133850525, 0.000010320536904501748, 0.000010299767823972903, 0.000010271863417832169, 0.000010271553908981644, 0.000010256545632102274, 0.000010227302693400349, 0.000010171556367460666, 0.000010161175030048079, 0.000010137580282998252, 0.000010121277575939684, 0.0000101190917149257, 0.000009920847219187065, 0.00000986583291903409, 0.000009845007471044582, 0.00000980439440832605, 0.000009791980482408215, 0.000009782549825174826, 0.000009777843340253497, 0.00000976784791575612, 0.000009764994987434441, 0.000009761682828889862, 0.000009734972219187064, 0.000009717374685861014, 0.0000096585546055507, 0.000009649760953889861, 0.000009649477914663463, 0.000009648166493662588, 0.000009647884219296328, 0.000009640779105659966, 0.000009634221112871505, 0.000009630968941215034, 0.000009621437185861015, 0.000009603476412259616, 0.000009568999617569931, 0.000009560913202032343, 0.000009558532902644232, 0.00000955687673459353, 0.000009541995151333042, 0.000009538516922530594, 0.000009534449546547203, 0.000009505868416739511, 0.000009502050125655594, 0.000009498099609375001, 0.000009445393616149474, 0.000009443898710664338, 0.000009441569452032344, 0.000009440258713942308, 0.000009434809932255246, 0.000009433062513658217, 0.000009432242173841784, 0.000009423743703562063, 0.00000941953396798514, 0.00000941807858937937, 0.000009413867119208918, 0.000009410122978583917, 0.000009408992856752624, 0.000009405898710664336, 0.000009401485576923077, 0.000009363433935205419, 0.000009357225387893357, 0.000009348033052884615, 0.000009342457099541082, 0.000009319862516389862, 0.000009202392605441434, 0.000009201873538570804, 0.0000091631912423514, 0.000009161098407451925, 0.000009150044498470281, 0.00000914779381555944, 0.000009128821896853147, 0.000009028818168159967, 0.000009023278504698427, 0.00000902190719241696, 0.000009020238103693183, 0.000008999716250546328, 0.000008813206020541959, 0.000008795681531359266, 0.000008774611601289337, 0.000008767537956184442, 0.000008755325898710665, 0.000008736859497923953, 0.000008692870643028847, 0.000008670258440777972, 0.000008663905485139861, 0.00000866125734812063, 0.000008651903682255245, 0.000008648239974868882, 0.000008647726453234265, 0.000008643952332823427, 0.000008643634888548952, 0.000008639476357626748, 0.00000863187071131993, 0.000008627808429851398, 0.000008625615712412588, 0.00000862356878277972, 0.00000861881747159091, 0.000008618311776114513, 0.00000861785967548077, 0.000008617708916083916, 0.000008607549183238637, 0.000008607195148601398, 0.00000860275177556818, 0.0000086010096836757, 0.000008598725183020104, 0.000008594020842438812, 0.000008592493389423078, 0.000008590817608173077, 0.000008590700885052449, 0.000008589097546984266, 0.000008587276360358393, 0.000008584249549278847, 0.000008582492583588287, 0.000008572604908763112, 0.000008568007744208915, 0.00000856600980659965, 0.000008561493403081296, 0.000008556214652534965, 0.00000855415888603584, 0.000008551773109702799, 0.000008551122514204548, 0.000008549236874453672, 0.00000854892255791084, 0.000008547202100633742, 0.000008542866449956293, 0.000008541676341236888, 0.000008538009069055945, 0.000008537595648492133, 0.00000853662983500874, 0.000008536476002513113, 0.000008528397098994756, 0.000008527177242679197, 0.000008526530963177447, 0.000008526381405703672, 0.000008524155348557694, 0.0000084943435041521, 0.000008481371517154721, 0.000008467320244208915, 0.000008150535839160838, 0.000008132818099868881, 0.000008064792996066435, 0.000007988626242897727, 0.000007947888262128497, 0.000007908908517263986, 0.000007871071077360141, 0.000007855017523492133, 0.000003665336156031469, 8.255082901074473e-8, 3.3592384178321675e-8, 2.813718312937063e-8, 2.660805015297203e-8, 2.6445490056818186e-8, 2.612786822552448e-8, 2.4826144558566434e-8, 9.931688428758735e-9, 8.247794197989512e-9, 5.216373470279722e-9, 5.204996175699302e-9, 5.0767523492132886e-9, 5.05422312062937e-9, 4.950700666520983e-9, 4.824696787587413e-9, 4.385626092657341e-9, 4.34587385270979e-9, 4.215499344405601e-9, 4.1845498251748295e-9, 4.036146470716784e-9, 4.0091441761363664e-9, 3.994126966783223e-9, 3.6832386363636354e-9, 3.621633249562937e-9, 3.6004561844405588e-9, 3.5434672749125893e-9, 3.4979376092657336e-9, 3.4035251857517472e-9, 3.3265611341783254e-9, 3.324396306818182e-9, 3.3148082386363635e-9, 3.307746940559439e-9, 3.2855659965034987e-9, 3.271716564685318e-9, 3.2142701048951047e-9, 3.1731793597027916e-9, 3.1036931818181837e-9, 3.0610453999125874e-9, 3.0055042613636382e-9, 2.9601180069930073e-9, 2.959346317744756e-9, 2.9266280594405574e-9, 2.9239783653846135e-9, 2.8820339816433582e-9, 2.805083588286714e-9, 2.7706307364510473e-9, 2.7700297749125886e-9, 2.7607217001748247e-9, 2.7543774584790204e-9, 2.7445572006118848e-9, 2.7398792613636373e-9, 2.718688538024473e-9, 2.679086538461537e-9, 2.6312691215034987e-9, 2.6274243334790216e-9, 2.598598666958042e-9, 2.581956129807691e-9, 2.581744427447555e-9, 2.575844077797205e-9, 2.5421287696678335e-9, 2.515625e-9, 2.515522563374125e-9, 2.5112407124125886e-9, 2.4947347574300688e-9, 2.4930138221153832e-9, 2.4854676573426567e-9, 2.480284364073426e-9, 2.4519162478146848e-9, 2.4379712084790223e-9, 2.436475633741259e-9, 2.435772235576923e-9, 2.429783107517482e-9, 2.4244768902972042e-9, 2.4134410511363636e-9, 2.4121571787587397e-9, 2.404556381118883e-9, 2.3908913352272733e-9, 2.3878523819930053e-9, 2.382225196678326e-9, 2.3199027534965035e-9, 2.318939849213287e-9, 2.303444602272727e-9, 2.2972369427447576e-9, 2.2932145979021012e-9, 2.2898068728146875e-9, 2.2823016826923078e-9, 2.270063920454547e-9, 2.2520077578671358e-9, 2.2408285074300696e-9, 2.238329053758741e-9, 2.2344706075174834e-9, 2.228187827797203e-9, 2.221201649912588e-9, 2.2186680506992976e-9, 2.2153969077797183e-9, 2.1934754698426554e-9, 2.1857722355769226e-9, 2.1854922421328704e-9, 2.1845566542832164e-9, 2.176061243444058e-9, 2.1743198208041966e-9, 2.137531413898604e-9, 2.1346836756993004e-9, 2.1099008413461545e-9, 2.105994591346152e-9, 2.105236560314685e-9, 2.079538625437065e-9, 2.079094733391609e-9, 2.0689398492132913e-9, 2.063681435751748e-9, 2.063531195367132e-9, 2.0546601835664343e-9, 2.0517236669580437e-9, 2.0505695476398607e-9, 2.0388507976398623e-9, 2.0354635598776216e-9, 2.0349377185314696e-9, 2.030908544580421e-9, 2.0184590799825172e-9, 2.016758631993006e-9, 2.0145186844405583e-9, 1.9986136909965033e-9, 1.9830569820804206e-9, 1.9711538461538444e-9, 1.964652534965035e-9, 1.9356424825174812e-9, 1.927816324300701e-9, 1.925822224650353e-9, 1.8891567416958035e-9, 1.8802310970279754e-9, 1.877526770104896e-9, 1.8672148164335663e-9, 1.8667231206293717e-9, 1.865159254807694e-9, 1.8650773055069945e-9, 1.8650295017482532e-9, 1.864018793706296e-9, 1.853071732954544e-9, 1.8529351507867149e-9, 1.8473899147727262e-9, 1.8294225305944068e-9, 1.8244714270104956e-9, 1.8167545345279729e-9, 1.810779064685312e-9, 1.8026387674825178e-9, 1.767366422639857e-9, 1.758099322552447e-9, 1.7508672967657328e-9, 1.746353256118882e-9, 1.7352559549825197e-9, 1.7320940777972051e-9, 1.7146252185314687e-9, 1.7122145432692308e-9, 1.6814220935314658e-9, 1.653292996066434e-9, 1.6310642482517501e-9, 1.624091728583918e-9, 1.6158558238636347e-9, 1.6138822115384616e-9, 1.610098885489512e-9, 1.6081662478146807e-9, 1.6034609921328685e-9, 1.5980728256118894e-9, 1.5863950502622377e-9, 1.5761582167832154e-9, 1.569424715909094e-9, 1.5589010598776205e-9, 1.5519968312937065e-9, 1.5271320476398605e-9, 1.5270705856643352e-9, 1.512210445804194e-9, 1.5095197770979032e-9, 1.5084817526223769e-9, 1.4965649584790194e-9, 1.4896197552447536e-9, 1.4712835992132838e-9, 1.390631829108392e-9, 1.3787082058566413e-9, 1.3610822770979043e-9, 1.3288693728146854e-9, 1.3154160292832156e-9, 1.3144667832167834e-9, 1.2785046984265742e-9, 1.2767837631118876e-9, 1.235406195367132e-9, 1.230707768793707e-9, 1.1726876638986008e-9, 1.097533326048952e-9, 1.0911959134615371e-9, 1.0892632757867143e-9, 1.0794498470279723e-9, 9.410716236888108e-10, 4.3754780375874135e-10, 1.2238445148601401e-10, 1.0714871066433565e-10, 9.766307910839157e-11 ]