info
large_stringlengths 120
50k
| question
large_stringlengths 504
10.4k
| avg@8_qwen3_4b_instruct_2507
float64 0
0.88
|
|---|---|---|
{"tests": "{\"inputs\": [\"\\\"51230100\\\"\", \"\\\"123\\\"\", \"\\\"61\\\"\", \"\\\"680\\\"\", \"\\\"561\\\"\", \"\\\"563000\\\"\", \"\\\"2400000\\\"\", \"\\\"231400\\\"\", \"\\\"68085000000\\\"\", \"\\\"601626560\\\"\", \"\\\"8438682911711716633214751365219626743737461956719455758661336162737333413873348734551161599324912798322447411666496112476637129667878555487737651293339367483498778388235348974166686842242267642926851212816853579599653537439649939813454662191849584693244738618891949195675475188525272221657313886414153236446678596241289683355186973262952237356811623969952182165623695552275386999277843719864343848326968554621399713172649929749583848512694461848161436925113181956836998515495533497882489698864759185363739311519827143861335862599593742665921765397191587722734249485997968165743416899758865452884847332233851817489812116496352985521932483656841125364558794279786971515185365255795342319358899976742643713118418446786382213128993318768963593658823516978221761293515473623751419957163862824599271112164587195815237768427853158556166278468783487884925216324537615276225839231641479177451513458214125142776274972854781932188687326358493263383925695762938216592987496241000\\\"\", \"\\\"217713289649867213128525236262454849287848244213913498569126651489678929965745115679668139865535623154814991531936523664757594645668758544483389632363888788676138636569484152586827534473978562358919715675213282195328514177465635957781655627279816458866164454162169269522741296926282785461835869197254484253821152963637744444369613434698646723422413112433564651639447775866655484635948247386832248661548829516236395846557431476672129289982471475172859828386669616227375836128279817767831678459693314934212795389659875328557315749291857319895737398246482686525849265272391491962965842784891232133743288372328343429794298958528821642634858279453937675284574761343153721151899552431379889529597239114594224267684276549847128753971679634577583541677319654668355472126378691997982443628199242871532432279549125954915878854384812469518544265787389543817888847143677952742138314598258842615525416731215761318228631755666493697443889942812655289392784655329795825542327256169343769900000\\\"\", \"\\\"6366892379879341266175971392763237547472738561527667982974273946743179299871941623952895728865533121594714388854377159674956252335759634244713378498166337899887168278882434762795355424462184128765516185127488651658526632463576537882461972564687383746939462674382258785546641785164646252929465288454418177641692985721257781466164143769775883171728515591451759288246944687187337181379578631617241389378168236712827847194569338556155695623821979168775518566627496949193699381932364776758189358717631174917888418671824137486958829415377895683899762118768694193214849557868547891512373573164153572223627555282147296826467963414457873163212336316391161448876377442212291827463816845962539221946123489732451174746593916243475757991776162591557486825542943455938313253363248432852937225971528327482292258455468931852559262249438514311858742381121768296379523856863845261493613164227729689285565599286168713813764296523948963943949449666514294655459861243458858382466569385676495777911991617997420000\\\"\", \"\\\"2347248044825683197915953242753954136458468135530569596982564376806744232209586209443445904032329604876884740433578422331078288115913718059342924039781204839817655684095045956571844017964775643167168509507529491151625647547059794026193209204187771685529561846011947466949469151855872764134740448092086421466303240286031787348599364594219758570296607102572895692336968744005418980079071338502828269187198732756344305624075593509647974954842933881932249995269911945145179349263872264263635770261555444608168918497546812202606961070408779649318783080756109336598467771235683764279754722087525787987268899831900032130693909300858560377702942440948716534165610989430321615777735800689004612218660748216666610743824770768611373885717471123628716599613929028217054104863827926901655975184640556799057114943769023042099081763608325332176623680868432607751543651130464150931513090745304939249935435592410530051296008520443540505526867599223436323905541239913543808338015806772635369022898357997364078491421063000\\\"\"], \"outputs\": [\"\\\"512301\\\"\", \"\\\"123\\\"\", \"\\\"61\\\"\", \"\\\"68\\\"\", \"\\\"561\\\"\", \"\\\"563\\\"\", \"\\\"24\\\"\", \"\\\"2314\\\"\", \"\\\"68085\\\"\", \"\\\"60162656\\\"\", \"\\\"8438682911711716633214751365219626743737461956719455758661336162737333413873348734551161599324912798322447411666496112476637129667878555487737651293339367483498778388235348974166686842242267642926851212816853579599653537439649939813454662191849584693244738618891949195675475188525272221657313886414153236446678596241289683355186973262952237356811623969952182165623695552275386999277843719864343848326968554621399713172649929749583848512694461848161436925113181956836998515495533497882489698864759185363739311519827143861335862599593742665921765397191587722734249485997968165743416899758865452884847332233851817489812116496352985521932483656841125364558794279786971515185365255795342319358899976742643713118418446786382213128993318768963593658823516978221761293515473623751419957163862824599271112164587195815237768427853158556166278468783487884925216324537615276225839231641479177451513458214125142776274972854781932188687326358493263383925695762938216592987496241\\\"\", \"\\\"2177132896498672131285252362624548492878482442139134985691266514896789299657451156796681398655356231548149915319365236647575946456687585444833896323638887886761386365694841525868275344739785623589197156752132821953285141774656359577816556272798164588661644541621692695227412969262827854618358691972544842538211529636377444443696134346986467234224131124335646516394477758666554846359482473868322486615488295162363958465574314766721292899824714751728598283866696162273758361282798177678316784596933149342127953896598753285573157492918573198957373982464826865258492652723914919629658427848912321337432883723283434297942989585288216426348582794539376752845747613431537211518995524313798895295972391145942242676842765498471287539716796345775835416773196546683554721263786919979824436281992428715324322795491259549158788543848124695185442657873895438178888471436779527421383145982588426155254167312157613182286317556664936974438899428126552893927846553297958255423272561693437699\\\"\", \"\\\"636689237987934126617597139276323754747273856152766798297427394674317929987194162395289572886553312159471438885437715967495625233575963424471337849816633789988716827888243476279535542446218412876551618512748865165852663246357653788246197256468738374693946267438225878554664178516464625292946528845441817764169298572125778146616414376977588317172851559145175928824694468718733718137957863161724138937816823671282784719456933855615569562382197916877551856662749694919369938193236477675818935871763117491788841867182413748695882941537789568389976211876869419321484955786854789151237357316415357222362755528214729682646796341445787316321233631639116144887637744221229182746381684596253922194612348973245117474659391624347575799177616259155748682554294345593831325336324843285293722597152832748229225845546893185255926224943851431185874238112176829637952385686384526149361316422772968928556559928616871381376429652394896394394944966651429465545986124345885838246656938567649577791199161799742\\\"\", \"\\\"2347248044825683197915953242753954136458468135530569596982564376806744232209586209443445904032329604876884740433578422331078288115913718059342924039781204839817655684095045956571844017964775643167168509507529491151625647547059794026193209204187771685529561846011947466949469151855872764134740448092086421466303240286031787348599364594219758570296607102572895692336968744005418980079071338502828269187198732756344305624075593509647974954842933881932249995269911945145179349263872264263635770261555444608168918497546812202606961070408779649318783080756109336598467771235683764279754722087525787987268899831900032130693909300858560377702942440948716534165610989430321615777735800689004612218660748216666610743824770768611373885717471123628716599613929028217054104863827926901655975184640556799057114943769023042099081763608325332176623680868432607751543651130464150931513090745304939249935435592410530051296008520443540505526867599223436323905541239913543808338015806772635369022898357997364078491421063\\\"\"], \"fn_name\": \"removeTrailingZeros\"}", "source": "lcbv5"}
|
Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.
Example 1:
Input: num = "51230100"
Output: "512301"
Explanation: Integer "51230100" has 2 trailing zeros, we remove them and return integer "512301".
Example 2:
Input: num = "123"
Output: "123"
Explanation: Integer "123" has no trailing zeros, we return integer "123".
Constraints:
1 <= num.length <= 1000
num consists of only digits.
num doesn't have any leading zeros.
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def removeTrailingZeros(self, num: str) -> str:
```
| 0.375
|
{"tests": "{\"inputs\": [\"[2, 1, 3]\", \"[1, 3, 3, 2]\", \"[1, 1]\", \"[3, 4, 4, 1, 2, 1]\", \"[1, 1]\", \"[1, 2, 2]\", \"[1, 4, 2, 3]\", \"[1, 3, 4, 4, 2]\", \"[3, 2, 5, 5, 1, 4]\", \"[4, 1, 2, 6, 6, 5, 3]\", \"[3, 7, 7, 6, 5, 4, 1, 2]\", \"[10, 9, 2, 7, 1, 4, 8, 5, 11, 3, 6, 11]\", \"[18, 14, 16, 20, 33, 3, 24, 11, 22, 2, 46, 17, 29, 28, 38, 40, 48, 21, 19, 4, 15, 8, 39, 27, 51, 12, 44, 7, 30, 23, 26, 13, 32, 42, 52, 9, 47, 6, 34, 10, 50, 45, 36, 31, 49, 35, 1, 5, 37, 25, 41, 52, 43]\", \"[83, 132, 194, 188, 59, 167, 116, 199, 164, 94, 12, 163, 128, 30, 92, 9, 151, 169, 121, 58, 170, 62, 186, 29, 189, 75, 100, 74, 89, 173, 162, 126, 2, 108, 86, 182, 122, 64, 43, 47, 37, 49, 197, 21, 144, 18, 112, 150, 40, 157, 97, 20, 129, 95, 68, 66, 142, 76, 48, 172, 84, 139, 99, 25, 1, 119, 41, 143, 180, 90, 24, 161, 73, 196, 82, 35, 135, 153, 8, 134, 13, 146, 5, 39, 133, 55, 198, 178, 171, 53, 137]\", \"[106, 78, 121, 76, 160, 104, 82, 47, 158, 151, 62, 134, 113, 74, 51, 121, 67, 87, 37, 199, 41, 90, 58, 48, 198, 101, 44, 177, 107, 112, 167, 20, 66, 35, 131, 102, 181, 191, 73, 83, 88, 135, 183, 50, 30, 186, 40, 38, 60, 17, 57, 133, 153, 174, 122, 86, 196, 95, 103, 69, 64, 123, 111, 89, 147, 19, 56, 164, 16, 184, 189, 25, 125, 129, 195, 139, 68, 55, 45, 99, 23, 180, 77, 144, 32, 152, 27, 175, 81, 193, 143, 182]\", \"[95, 53, 23, 8, 119, 1, 148, 179, 70, 185, 132, 161, 87, 80, 99, 60, 10, 115, 124, 73, 79, 71, 89, 58, 77, 111, 50, 167, 141, 189, 74, 82, 40, 22, 68, 13, 190, 30, 52, 45, 103, 177, 25, 158, 153, 15, 186, 3, 118, 105, 32, 91, 137, 108, 90, 112, 168, 156, 46, 191, 93, 139, 195, 135, 28, 155, 131, 17, 67, 169, 138, 144, 110, 78, 150, 154, 38, 64, 163, 55, 25, 48, 147, 11, 81, 33, 128, 198, 26, 140, 188, 182, 199, 171, 62, 6, 146, 37]\"], \"outputs\": [\"false\", \"true\", \"true\", \"false\", \"true\", \"true\", \"false\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"false\", \"false\", \"false\"], \"fn_name\": \"isGood\"}", "source": "lcbv5"}
|
You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].
base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].
Return true if the given array is good, otherwise return false.
Note: A permutation of integers represents an arrangement of these numbers.
Example 1:
Input: nums = [2, 1, 3]
Output: false
Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.
Example 2:
Input: nums = [1, 3, 3, 2]
Output: true
Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.
Example 3:
Input: nums = [1, 1]
Output: true
Explanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.
Example 4:
Input: nums = [3, 4, 4, 1, 2, 1]
Output: false
Explanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.
Constraints:
1 <= nums.length <= 100
1 <= num[i] <= 200
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def isGood(self, nums: List[int]) -> bool:
```
| 0.75
|
{"tests": "{\"inputs\": [\"[2, 2, 1]\\n4\", \"[2, 1, 3]\\n5\", \"[2, 3, 3, 2, 3]\\n6\", \"[2]\\n114\", \"[17, 17]\\n3\", \"[25, 81]\\n48\", \"[20, 33, 1]\\n4\", \"[33, 89, 9]\\n200\", \"[14, 5, 7, 20]\\n5\", \"[47, 27, 74]\\n200\", \"[68, 46, 28]\\n200\", \"[2, 4, 26, 20, 49, 13, 47, 22, 3, 3, 28, 18, 11, 20, 39, 5, 8, 7, 10, 9, 32, 4, 35]\\n73\", \"[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, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]\\n150\", \"[50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150, 50, 150]\\n200\", \"[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]\\n201\"], \"outputs\": [\"true\", \"false\", \"true\", \"true\", \"true\", \"true\", \"true\", \"false\", \"true\", \"false\", \"false\", \"false\", \"true\", \"true\", \"false\"], \"fn_name\": \"canSplitArray\"}", "source": "lcbv5"}
|
You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n non-empty arrays by performing a series of steps.
In each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:
The length of the subarray is one, or
The sum of elements of the subarray is greater than or equal to m.
Return true if you can split the given array into n arrays, otherwise return false.
Note: A subarray is a contiguous non-empty sequence of elements within an array.
Example 1:
Input: nums = [2, 2, 1], m = 4
Output: true
Explanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.
Example 2:
Input: nums = [2, 1, 3], m = 5
Output: false
Explanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.
Example 3:
Input: nums = [2, 3, 3, 2, 3], m = 6
Output: true
Explanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.
Constraints:
1 <= n == nums.length <= 100
1 <= nums[i] <= 100
1 <= m <= 200
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def canSplitArray(self, nums: List[int], m: int) -> bool:
```
| 0
|
{"tests": "{\"inputs\": [\"5\\n2\", \"3\\n3\", \"2\\n5\", \"1\\n7\", \"1\\n4\", \"6\\n2\", \"6\\n1\", \"1\\n1\", \"1\\n3\", \"2\\n1\", \"48\\n42\", \"49\\n41\", \"50\\n49\", \"49\\n48\"], \"outputs\": [\"3\", \"10\", \"6\", \"3\", \"3\", \"1\", \"0\", \"3\", \"3\", \"3\", \"1162\", \"1167\", \"1323\", \"1272\"], \"fn_name\": \"distributeCandies\"}", "source": "lcbv5"}
|
You are given two positive integers n and limit.
Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.
Example 1:
Input: n = 5, limit = 2
Output: 3
Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).
Example 2:
Input: n = 3, limit = 3
Output: 10
Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
Constraints:
1 <= n <= 50
1 <= limit <= 50
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def distributeCandies(self, n: int, limit: int) -> int:
```
| 0.125
|
{"tests": "{\"inputs\": [\"\\\"aaaaa\\\"\", \"\\\"abddez\\\"\", \"\\\"zyxyxyz\\\"\", \"\\\"\\\"\", \"\\\"x\\\"\", \"\\\"k\\\"\", \"\\\"e\\\"\", \"\\\"a\\\"\", \"\\\"i\\\"\", \"\\\"d\\\"\", \"\\\"s\\\"\", \"\\\"b\\\"\", \"\\\"tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno\\\"\", \"\\\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\\"\", \"\\\"cxyayzaxybxzbyxcyybyycyzczzayxazyaxxczybxzczxbyxcyybxxaxzbzyczzayybyyayybxzczzbxxbyyaxzcxzczxcyyczzb\\\"\"], \"outputs\": [\"2\", \"2\", \"3\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"49\", \"50\", \"25\"], \"fn_name\": \"removeAlmostEqualCharacters\"}", "source": "lcbv5"}
|
You are given a 0-indexed string word.
In one operation, you can pick any index i of word and change word[i] to any lowercase English letter.
Return the minimum number of operations needed to remove all adjacent almost-equal characters from word.
Two characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.
Example 1:
Input: word = "aaaaa"
Output: 2
Explanation: We can change word into "acaca" which does not have any adjacent almost-equal characters.
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
Example 2:
Input: word = "abddez"
Output: 2
Explanation: We can change word into "ybdoez" which does not have any adjacent almost-equal characters.
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
Example 3:
Input: word = "zyxyxyz"
Output: 3
Explanation: We can change word into "zaxaxaz" which does not have any adjacent almost-equal characters.
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.
Constraints:
1 <= word.length <= 100
word consists only of lowercase English letters.
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def removeAlmostEqualCharacters(self, word: str) -> int:
```
| 0
|
{"tests": "{\"inputs\": [\"\\\"accca\\\"\\n2\", \"\\\"aabaab\\\"\\n3\", \"\\\"xxyz\\\"\\n1\", \"\\\"abcde\\\"\\n5\", \"\\\"aaaaaa\\\"\\n2\", \"\\\"wjlcta\\\"\\n5\", \"\\\"eictzzwx\\\"\\n1\", \"\\\"fvcalcqn\\\"\\n3\", \"\\\"zcjvkodq\\\"\\n5\", \"\\\"eifhjtmuj\\\"\\n7\", \"\\\"cxdzvmcbcv\\\"\\n3\", \"\\\"rnqrabcxrh\\\"\\n1\", \"\\\"xpfcubkanivkyjzrknwyapagrimbfidmckcyeupxioksdbcmucufydzepdedezeygezuvfmzyiodsenwqdldxjmwsvomyztnqpyxcqbwxnzhbfbogvdcnqjwqwedxmjblupctwicfofzczzyebagxmowivzpwlbucpyyevzidluoyltxsmvbfdeyvbentyozwebujyxfvvdewmvuxsxdviymdpjvlepegctykwxxbnyzccaemyqmlvzeitmvfjjlzqluvazjdvnovddnbtykyjdoisjibvgbniuqdxmxuvdhyawjkwqiphhjuvqxaxdbrdsrwsbevchsuwxpneazufmwueqguozujzczmuhpkjjaddhsvjwtzvlxmcymrgoxcsxbpwdmhovjpxpkgdfhlhullzdomxuvqoopacvcmjmobfwoemcyceajvycgrczyqvdchwplzvndodyhnbhthgwwzcmoykpycnosntzcrcznbsyynsdtadpdfgylycvemzuvqldvvqicckcaocbhcqipvqunnlwfdqrostrcltuouoqsqzepivyqqlcswvgnvxlditnftdxnlbxqarzjynpbsqcxgnfshgdvdimiiwrohuhmympmmtvhexqwdbqsdpitohxlarqlbabrlwodttiibbkbmczplsiwxyqegcneqyofppsiumftmvacspqcdfjppimtgrhuqdyrkntvcsrpaqovqjmyhoccqkdgxikxshdwrgudcconsqzbklbofdxyaxtkjajyndcudxbyfgcltuxzplllfrfwwwbdaibouxggxxdckpbfsfvvcbmcvczbpqtmxgysinelmbvlsclhloybhkhtscenkpakwhodfdgdrxgcguqomlxayakwaxwlqukkrvkqslefmfumnakskifztetyyrfgvzjiaepqqqwkdldjgplqriawrrukbwbqnhpcvdmkmjhlqpzwvgjjndzgqjoqevhyieipaffepwrthzehdquownsakrocpmdmepyfdulicftrefkhqvzgoohpykpydcxizcftnsgpghuxugvqttyyaydnhjusathtjisrtpwocwxtersgordudklpsvbpzewzvlypcgihdvpeikeovhihcbbndlgqzupxdjkbpdeuftmdbdrhtqesmezjcokbyzgwoqhawekinuidpbmzslspadbmvxgfiseyuibdrxpgoilysyqqshtnlfvrjgmwceopbxxmkzwssgrsqhlaoyebbhuhiiemjhximuqoykypklmmplgbzascuznhqidnkqnxcujseugybfadydqsgqufgzepqxbepvxzhnsbwbfbttoiylukopowsetqomnpdszmtjuaigjyqvqaaeqirxfeplubcvcjlttruulzsfedpsflgwxdckwnemdlhngcwmuwtsjwiaxjwlhriwhepscgpoitqycwjjmfecffcbivtnarupmgbqhpiiofqufosiulrarzxbeppwtjlyhlzmiwwqzdlfjebljjympzzaowppxrsphvftpeikuluyvivsjyhxzwolgijqfxeehmczwfptjfikgqpgjrhznbdnikqqilxfvuufoljxjjcvhdjarfslgwlkzczxqjtqnjgelxuakkjlrbhankcgwpdjhnljlnhajnqohuxapzptofyazrgmnlxtmrzkzvwhggzdmqvjhbwuiebtbaduukrapbdklxnjagptorxuvughpdmkabacnjzhduyuqjuutixfzupogfnwxrmnnqznwczpruxtsphfmcddhernkowdzvywlqhnkhsixidvovkyphdkfglhpkduodcltexgdphzfiwqvsacpcgirwrflyterhlrwioqabukywobwmkbvcadwqnxiblakmwesreitxfwnvsfftxcfozltwwnjyaixanvzbrntsrnatmfxulresfljxuthkjnovjaoaqivvwhjjxdmnlozliouvntwxrpuvfactvovpbhixihmoysolwburzvaoykjmhnwmtenkuiivbrhvniudaaigrsrutqnxlfqeuyvtqxozerlvotdgnkzgkbpgxzuoarjawxexgxokeoelyvdnxzpnkfsiaxatkpkkezenyewrnfwejyborcjqzhxybaykdtrntzvexlpfvzguhczemaxdjuvuxtlzpjcmqbvidbcxsktwrkxkocllaedcplpdpwfktzsvxqpagajtmeqkffeuckyhrshfdayxbjdjuivfmfkzbohobwsvahkpgcxauaeadvaxgxpkslbivlzmsqocqfoknlojgiwmletbtasyjmmfovjdotpediffjgtldzlgfbbumgaqmupfkweljgvdjfrqlabfqsjpfisbtumlqyqfdeaubsaajppbmkqrdwjzyzmhbrnqxcrjjufsltqqpyvmzgzcazyooosdfnymifvrjxezijteufhbmcxhvoxdbrmzioizmjmdvpdshqtheyrzmlfuivhwtkoorjbivqvwwokyxrwzwuxfdnaejlchkaksynqkmbwqmwmhsntqwhbrbrkafhfpjumnkbybkzabcmptpccgzdacmvsbwkheejololwsnuwfpuodanaihzvmothxyxslhhptcdijldyfpfhiuiihxpuursgxpuqixwcbqcrxjksfpyzxtkxmdtfveoosronvfpmnsxxsgjsetyvkxddbympmfpykydwofvnltihwgoejsgrfodohcaivptiaieuelhrcuoyrerkbuohdsjbbfntafpzztlzoseaxkxbnjbrxemfsvpwvzalmpvyjppzddnflitdejvqcrzyzntknvnejwnguynlrfewsnxcbovofulxuhgikxcsoiezvihrzvsfyxdsrufykenhrwfvnjnnncaxkzzjuimqnnqgtukxkvnvcfkairsemscrzjemrfwkwkkfwwphcnvqimmvvczcscqpnzdqfjvwajvtqoegqhedcynvishixmxedywrlbwmtorwwlowwuvzpsbscdcyjtoncbfjnfxpfevllncmmlifnucsiguwonhyccqcqtglbxxesjealqibehjedqbrnjohufapsqssqwvvzooqfwluedcbwmacheceplxmghogvunjrsketeienfidlixfdnqewyffpoteztkxipfdtatxetjbclqmcphpasbtkocvlhuffvqtfdhmdcmrswbctqafbnnntrppyywffdjhnuizkxhndadsloifxjaxheudjpuogwmakbbrdrvskhpciebuuwcbupoveclpvftbehyxjnclenbiibcjeideayphxtumesaoaeymhrvisgaaevwhjfvhdfdzsfuxrfxliignqauahcbfcgoxxxdlnwwovyeywyxlgvsizqfiausvoqilgvcbxkmfylmkphdvxrrfyfffgadhcypisptnvecwflhrsqwuzemwnubdisijkpaatfbriivthssajxbjmnxjrewdoyjvwmtokqeuldzppcnprarubqgpxktyzeleckfjpudmvywhjqnjfalpmieariepgptgbkwtgcasnhvnqvvurwhnlxmaiuuykfvncjzickxcwyidpwrehxcvvoanzxbdnjxixipfsmrmajddlhgvxmauftfuqdekhutmpoyunvxlyqaojobklnmgynyiiyfeorfvrajhgnmsrpdilotlbegewudpajhfpvrghwkyhuwvjzgplilzcintgpqwnqyjgtypadrviztlaxewjcncyskpsrxxgsplbbooqacnpjlfhghuqaxenhqnqcuqvpyfkfihiofvjwuygtntxnxiywvtbvdbrqbmfwtraposwyqamvcmderlchhgbbniyoxrhfuhtrzqjnqkphtvvzxleakbpsppibnkbfqvtokzmwvkxhlcgifrqsoynhxmycuhhcgzqdxtudfkdofqssqdzoipielydbdhaemzihwekzhcapwsvelpjdeludtlvcrwoenwsatlfxpirsxsqnaahwkygdaqhjzynlrtfiznuxagwfczcfxzpnxlxghgvwkcyhmtkuliqswdkvvhbzvjmrtliemukvgmfzaxeesowmajwcjmzebtfylwzijtptigfyznnftfzhjdcstaknwpyfwnvfdxlbaursomisixddklsqdtvrfrqcfddvqfbpqlskdyynjlegfzecjkyakkijwjkajfwsskpwsofbtqhjgexrsbhktzshkszbugpppytjsklckggawbnmuiwaehvszkuzprjyelldewdndjesigqrhgicyqaejauynyjoewytyoojeotssllkwuhgnmgpqyegehehwzhofszwyjftrsusucssjgaovyhnktywmxrnsriidbzulmapbjkxapmzqhqktilqxpjmhjpeaysegcnqtnjndfknnctmjkafdtgzyltupfonmsrmgtardlcgwntsxbcyjdohxwvghsegwkuhievlarsbdlgduohbxivjmrsolhtubqxzzvueyznhtrzkgimhpuhiunipyzbcrigdgeksgbtoqedkskorghkikbszycyuzfhinaxycvcfvurtoevqyufwjnvindcbwtwpqjwmvipafnlcodvndwlwwaaqgnblqpmvwjlpfzjudigkvvqpueecuutcwtdqqwjgcfvgphonspqehpeklgpzgkfamiwomgixdyxnsepajkshqghaqikdjqqpxbbkmjccgbkqvqfpigjypcgpfjkizbfcgxnngodlenqvgpvgickijvbiazwnmpxjjdesknldksyelesjwwzujbwnnrvceenajgtjywtghqagfzegkxecngokderlavngytjascyjnemnvxnlkriumxpatoazikjgtyeenykuayienfapxpurqnkmpuvimtzqowncffnrcswbcfhruwwmduepyzsqkuxgavwnbajosbldkaxgtzcreoaisxtxdzophtgfqcrrtmhmdrkcbzzwddjfpxqfvpvkoktevextftmuvakmteenblhmyyoaxvguyogvsotoqqciyysgrihgmfgccglzeckjxlfedxkfgutbpqolkbejqddjtsxlowhwmokwomkuyejtlaowtajpjmnzvmbmakyehyvfuunsxfjdcoypfmaqnwbdwxbgtzgmnmjbygarrmrjgixzmolzepgcypeuxlxycpnlrjtwvaedoogcobaamvppcwiyltwlxtyvdhzwqihsdepemdjedvzvvkqflsrudhngmoaeemvxsctapkzvanwgndhveptosrmqptyxmczzoxlawzidbumsrjxtkydodtezxiiutiotpsnkwzkcstgfkkxyiagtnbxwnztbnctpoatffiwoapkvsaryyxiezqlzdreshtllfwwycwjuspgnzjgfdajjkkqftewawzljyurxctoccjdzwnfiuvuohfeluparlazzulyeuzcatnexqpcsshjnvadbltwchxcowezlbybhhrgguhqnkmcukhlljunkuaanxrxoxafnzrlpgmhhfnvzwwybivqsrnspcswbufjztavsamlpbpwdedyplrzozmxvvhhuxuvvduqjsmrzafvrcniqxfktwiisvvhhbkzebielxhxlbnaycpgtuovinhekngbgkxlmxhtpvbmrbpguhthtefdokmfotgratwmatxnacxzdmxkqubnrorihqawbzktigvwopvdfauxupczvxtkuyyaeiwrrkjukrahxtkahxmusxotjrxnnzimghvlfgszrtiygqrnchpzqorsbaemnfptdxjtswgfdozecqbpxaujhuayhclbeipgzpvuusxwitlzzyqxygnhdlkiofrtsscgevehtolzodatycpejpusvgszlfstbqvcyjtnfmutmfemntzlrhsxtmogietnjxmfmznciqjdsudbsmkyhcnempgkgckqswbqaqcmwjgstlyryywkltdgzsshfoplzamqllwueovaagayzwaiaazjfsrfwtpivijqgubmbwhctrmtkoynfspqjmpwpaonlrlsaexwxpsahfbtfjsiybyfjaeqyrdiqrlfjbptgwbsgbwgwjitosjuxadckavzfgkrnvzbnbeziiaudmstuaeuftpyrqjbsggvjzebgduotnsboknhqhdowcomzdmdaeuiinjpyzwimhlipikgtzbmqeollckyratikhztwbmaiuzrwofkivrlebtapmktkbqpjatkvjiyccqswcufywgwkusflwusminggdmdtuvoxvilvukrayjlucbylzogndptfmnlllmiqethcnnginbtwrzcybylglqqovageizbaomcaqtgvsgehosyoxltplzhwyfjmbeuixbsooeponklcmggqfkovtzbbmnwluhhmcypxqdxkumcyqlvmnhadkelioqeznymbydnffioukljvvhyqwyvcfegrrytluagcpomwcyeckesbvyhewuhzlzptfflrsztsmzhgpradovzoperksqlkyntbzjcmylwmwqtinxhnoconwxcwfekpqxbkhqyatprwihjlrvimsncixjsoznavhbdchiuqyrlbelzcxdtmxjvpiibfihufucndkkvjkgdvzecnanleietqceyueqkgmpyfxdwtnjyhoaqbascgommlrdqdejhtydpqegawsemdnxlxbxgzruqrqlfglxrzudebmelidkezewdyovcuurxocpkajrirruyxbckdthlfdcrirheqjgnlpyequhjbqudfrrqiavtzklizwsejeuhzfhlozpwqsqmpiswvhjoyfazeebkjqvelninlvyucuffkgptyafokhgslpgsvsykgwualnrxjwurduoemlyehwvbxniwnjvijinjiajmvsneakmugjmkaerljtmqrhyideqkriodhvzhqvlhvxwzpyltwmbsnahcgdgsryhqbucjyzdjrpyqvtkkhjxsbbmevuedqkxajvvncowdtccbrmgdrwooranxobnwmmccvdiiaykktulxrtlxqhyzaqmzeijgbqwmvtqguripkngmicnccqesqqusezakzybniuuzvriijuosdpyuefvwdkupnqpishmyioltjkvhsmtnfqkysnfgiglvnyekzgcozdtqtffudcftjocyjfjpdyqmifvewcoxsvkgenmdbchbtoupjzqapsojjihbwhbudqnndzoxieahecwpshgjtzmhycjbltzjyixfjhezbdevgiojqiyphqknlypfmwqenudwqnbjtwsapnlupoupmenfbjcbbgepqcjxetcjmutlxpzobwwoblqhydaztngrdyhfkhwuhriamepvprnrsikmebpxmoaqcdnhiklohbdecalrfylkdxqiwqofvjeqvyzcfkfngdqkfgtjgpjdbfjgjadeuarqmzfcsytilaakzdkugakscjbxomkykicuwqrhcijsrxctrnemaqqdwwnfglsveypgzsirxfefxlltnaaqxeqbwwgwfnljkzzzelpplflchqcikqpiqloflqisrfsuiiaslauvcelgyjciwnoteftlzjiubliiaijzjbpcfnsvisfgoinuunuejetmznunmdrefhnmcrtdivhbcatconvofpoxdzzcbdnwekywlwqgsxwstcbqjpfyqcbfcaacpmymdlmkzmgoaranllybudylvhnpnzinjvmstxtbennsqihmlsmgriipzjyofxvygzahzzyuaeianzpzahtbkfrpiujepbhcqkpqcglosgalbrbibbjuphtuoolptvpxbeexoycqfsmlypswijisbyuvqqzlzmvjyigropakttrlgrvtimcnshwatqzwdfczonwouztyqiubrmxiirllzzjazedhwltpucdsexsbgbozdiztkxegztckjcqlwbosentzelgbcyrbezdoivvdgzbxlyunokjmpqzrqocugznspqcxzdggejpwominbcjntrjhafxbxbfsyzyqyxrwtukaurvizwioptncqmzmqcwnrfjfilanjyxlrgcasepeqimyvjmqmiweohrcucujginiovdowaorzkihsdhrccftjeliavyjvawtpsepmhchcdvpyzhjyglqjxwplsjcmploojnonjjbgygstfkgcxvntsaaaorjdtxeyqoqggwmdxddtomjckbnlvchuvemmcegebwkjwiyjwbcfyaetsrvodkjvrjhpfpsolrqxokfpycnwkerdtqsdvneothvcbadgcyjeesbzahxghdweuytouvjxyzpcjosewiujvmqhclalwwfegrldgcqbhkwevldzgxaksglfhbjetvpqslwwzhjttbvnhklhshjjwypoctubogkgcwcsicpyrzrqdkcgzymribpssojnrfcxjdwusqjcftcmiqjxxqcjizptwsshvwxggbpaokdbszgmeoionlypqgmejnjtllpynqwkkpybiyzwmlhrfohmcnwnaueozdyrckmkfmwnajtrmwxvaqasmkbcgcpdpvjgzyeceppeypahejhrhoudlhrdvzsfiocinxhntziyxssfwaqifntwhkhxjdydvzdwfmqfikecjvaesutwjqjhqewlvcmqekrbbwgfphefegnnuenwobbzchpzuvjuxbzhsdtlpjxsetwxfsuyitjblixyeomzdeylbumsmtgmbtnuiurksgrpbegpktwoxpxawfwmcimexvmmomqnqsjcluyaqialpwjtbptncawqrsxnvylxyqyyyarkoimeexlvikhvckkghhlormamwtzpzkrnudwzkubdlposzopqysdlefiqghfabvryozfrsvvtjwhcnetdfhohdfsmtjhneubshmseadxxkayqokzfbdlncgclnlapewefmcrwckuxjebdxfreazyjanmnicjnksdoalchzsjkjkzfqifrqhjrskhecbstynwcuhixdujjjqfreutsctkeswtprrmcwommwytbsmbejbzkdllqqgzydxpakkmnmfuaoxppbbyfpgbdgawxjxcjdgpbqkxbtpjhpixetotyxruayddfrlmoimmnvstukdrtmfhnnuwirkxshjvrldfxpqmkhwjbonuuntmezjnxuvliakgdvzfqytvbhxdampjhelcwwiqcnnpimpuouxfboujvzvwxrpikamrnnffavcyssaicjdwmtwtxmpbiyvxduvakewqnppovodjowaiypfnxxkpcqmjcmmlivkzcivzsdnayfshmblwsmgzulahirptppmeygjkrjyitzzmqcsmrbpkjbauitviezosypsxgoxumpqcwvicyverberyklkwmvsejjqkwlmplyzukvxclckhdrlkidqfgcbkiizkfzqdikjakqkwcuqrzzdwmkgsqxcpmgntxvvlwqqfpypplfqfyypggqobrzuhtvuuxrcrtstflymedmjcowoerofviozphlprvytzweeteawrdkfvnmnrgxkzdcijecuvjpfjullxcyvhhenvuvmftzxtnunxrdknutwhpsnmskaettcartezyzojkzxalqgorqifajrwtytizfzledygleyjflexbkducuraxgsiwfjxbcgyfnotusnmdmtpfjrcavjdepvsoztsrovfogsvffptwrfmqrpwhuabrvpojrfazfkftrvlpckmcnsltzgungznjsqqpzlyncpwmqlnwszwgpczoblnldpzvpvmckeggvawiwqlzeztdpeyawfvxszqpdrqnvlqixraaadfxpczddkduytpivpnvxvbgadpfkzigixcfsdmgepmajecgjshhkpt\\\"\\n5\", \"\\\"kqcqmheihegwnowzuewkstuahjozvinliwlwggkbvtkqvapvpppoqwxfhoefbubqbhpyswisbkalbvjgrjoyxijpghimeqrcxepaogezptdrxyxfwuiexwyywwwuqsottrvgtvzcgejdyxsfceninnigetacaohfsmkbgmyqymczxxqnhvixpyigssrhzhzkaqcahpvuopnsrffxezdpfxrlmsboymumocgdrigifnolrdlxsxgjczuhmqpnxljygjwjxipkwjynbsuzivynffwrxqfzchizgnuwswuvewthrlesncnpwtjczbsyotsxdebnasfotwewpajhxefwbnisnxtnobqyswwzuygpgrpvblbqtecluzpgebpvtqevvniphdvcqjinyrysdnqsojjnlcekwstjiwmyehwfjudaalgvdngffkrimyrglavkjtelnvltvsrftseiqmwwyrhilfohbotyiagufapsyebagpsqpkbjchnjoofgtwgjzqtlivqmaxtsjdnnguysmvydydzrcifrdlarmylwyzdxjqhuaukdhoaqxsxjfhmrvycjdzuqfbgvlgcakjndknxttoalrhdaexytsntgvxprtytplykqfbdwzlnuicnempnmgmwdzaderlmetvweixnsbxljrbvxshqhcdevfjaymqfmksmkctijchdavltldkmjvivkuqcgrmnxwaaruhanfmxaxciqyewsiexattmenfewqyokotzujkmzqlnbegrtitkrwarxnjaodfeobdglqgcfdurteeqivkbmsrdycbzygtoqarpqzcowveihygzptzgpvcjrgftfjigikwanrxttvnqtedbnztdmdlclachtquhablqzjjtyvcxkdeveizgdjpgqdeiqmuswngxzyjwnwleqrifvlysgzkzshdngxbhtkquyphqhkgftcwvxbcpptdakdvshqdmbhqrlksrjilhlixrbptnfhywhiczaiuqbcnizqqeivuynhpevmffkhiecfjtufhjakzosriwgqhpfapitlgsmmtoecoohpihdhbtmfwtewyfvaqjughqmjnnmbxrwcvsopxfqcktswvrdkqxkdpjyvklqxkqgzbdetgjmrfwwthmcpshwjaofatjbilfkefpjmspqcisaeobrzvbwfefgqpgvnkzklxiproipnemyqbruepcnobetlqkdcczxzxzzjovptgmywswuontmgeibzjvxhtkzdmecgereantfzbanhshjgthhhonrrhhbjddqytkjdntwvgjjoqkxlbnhtwwiasdnaeekjobrppbixcbwjabplcbruugxtjvdmjuqanldjnfhvwhhunjixtigppxvprsiomedqwnhmcxnzwaokanypzeknxzhykdrayyzmqhqwryomjgfoycqfqlpwcehdbwpqgzsdcwqkjluwzqpiflcrgrildsjxloiibubxgvcwytcjdvoyadfqwlxbemtoicxtixbffiyotmejykecajvegkskpifdzyppbrxlayebljarfooagugryhkskwhryfpabxggzwyoynonnpygpibtfvlvrzgkxqwtymewxqhjbvtipcbulehdbyeqtknrwuloyfnxpvomdhmgifavduhxpniizlungoybvptvcnuwowbbkitdckjoqoliycswkvbzmgazjmielztjgrsaiphgomxufdhtuqgdapmgfvkurlsbtokoeddduachorypdfytezrvhdzzcqxusavmyufwqxuevgxmetknrpoashmhmvjgvtzdilndbftcmcicgjxwhvamrvkqsvblclwviqgqmdfhandwervaylklcnjemmivtgtxtcytscquzdsibvekilvtiefwjftuhyustoybmtysgffqvponenlgaqcwwfzlzqalizvtwwdmmncrcgpnypnlvrmjvketnjrmpvtgzkkyqvyhdkpttmnyznyzkmhwlvzpsoxoulhvoqomtdllmiuuzogickiwoktlsbjwjftlxcoochmrsxqztakquwglwfplphbtnpnkilexztrjoniorurkamyujdhqainpuysxxoijtpissufzjewirrknfcjnwnsqeyowdmcuyhzktsotcxtjeqqqadpyakrqdjmxstxqbplogkqbsfasemlwijrmihypcuzdjeeyalewctlsxefmjjllddehbucezvdqiexbmaiaspgtlnyqccxpianxdnqyukfvdseuoomnstbrinbcgusuzsydywudijquqamodgasoxdiymcyknaoifvxyagbvtovcvxwgltuehdquaoalznskxxkygxbvumuyeplnchurhlkqutvejwyxqwzsdipddbsrnszxrzuktabpjddwgecjrzdcmfvmqjmdwjcsvlobzlbpcmztdasyfbeaefhdmapisvuysornwfpwslmyftvrwhjrcaesabbxcvtsuccihvozrnptzjyooawnvydbhhpusiwcwkwcsocjepztnhouqsyqzaqxwocxnereldxmyfvgpkfojtpycmpdpxxpcyfmyvukkurriupbizialnozyjnolemqqmftdnmwykzitupxehotywqonmqsjgidrubugycugbaexofhkmmsmrtitszcdovlhhuhjygjsozzrodgekwvarzszrinkfrlrdfnmjimmrvyqcdmanjufbtjutbitajdwbgneqpulxulkglpeicntktuymihmzknewapkmywzwtuzgafsdzqvuxertqdmthhgexujbtvwcilrgelhloxwhbmjcpjmuteykgwubqogzkauheirmxyvnbvyyucrzhmtcspgdphcmlkxqpajeypwsmokydijqxmbkdtiosqhzunpqxyfyrhqzmvejzezdektwoipsydjtfzylbfjyaneeqsxbohulxoeasycshtfdoicjpgrwjsntszidrtnbauxtslsionqlnvnhmyczpsdguifxsytciqnbvvoirsytcbytqwmuvlodhklqtwrvezoiudexryigmygdankvkpgijddnpsircgdxvbykdocjyloayzegyflvktpkorohlpxnbfivshhawszimqgqvnwvqfhkfhnkwenwamkpccrgmeyjdoscxsaszsmbodoezkvvvhldhgwltyvklkwxqxfzorttaqnajkbevjongldrrzkorgefzivewomdukdpqdmnvxrikhtusehhqdirmioeowgfbgktvqygzhspskvdngpwuyrbdxvhvoaemrzrlygcecdisvkyeyqlenznqyituuqvqyedzibueuwepdsiqlogwoojuelkssboqjhqcrhpfnuszogtljenlhrufidqnfukiniiwgpzgzmtxtuzcirifmevmfrfpvcfunwdqbupllnrwymfipzcxojmdfzhwluowvjqwxdmwlazzqlyutjgafgfyqariprmrnydywutycubfernqjaamstbqnwnzvodzozwjlisrgaselsrwiirvbrrgcgszzncmoltepnwyfsdwebkzvaaxkhybxdanpxlzrvoyyhoaxaokoldwarkbfgygvkbpftpuxhuqwotmhozgjaufxqrqidzzgbcwcvmofqmxqmmrqepsitbghnyrmxoizmbhqbxavbkvtyhstgroczwmixzkggaimfuhrnqkdywqixszebsqugiieagbvppkvpwcdcoivjranyfzozionhenhyvcokearpxwmwjlwpoltyzkpsjgiuwreszasywhuopxpjtawoimiyaphehibulkflkubdlylcgbqomnctvlxzowmhhreqyuqepsmkaiwmglqzsrsmvquiwjacticlrjnhyliqqxbgnxryblnevkugfricwvblfvhruojehaodbfcqebkuxlpaaxylrzoqdfsqcwvovkugeyzmxhwrnpyjhysgkxcoyrjjzxsyoopwfpynsknppfmhvrlbiwgdoopdfpgilqpgfzgqqyhwvoxryjrzqxiaezputvlkawwouvyxhigidmzvmzfnumsjugkwcqlutqvlfvvjkkbmwhkccsxucevyhfafovwtsbnkfbgjocmxchlvhsognmyqomlcgrypdsjxhynjxcwcczquaxulsvxcjdunhchulnpmefwlisjqvxkififzrpmreladkjmortwixvnmnmhhcerojlwntpdbpolllqadxivqiucgmmefhnahfycqnzdjscryehqzjexicinvtqbgvmgqfxlvsaeyrcpfcmeaidrifhayplqjvrxykolnbmvdgdzhpcpjwzbzlshgvoxkugyyyxtswfatbjofyyubvmvdzueyawvaujiuqlqjcinwkcuzukiumulfqcjxpttncwicfewflzchowksflzcrxaebkkebyautalkofbptdvgvpquxadaburdojzmivanvufigsxollgekonymbadxurtlgkkfodtmaaiqyblqjttvbgznvnawuegjrelqhzjyehboyreybvjllspjukzxgskbhqppvxrygziqtordmkskpafxaoesjzrhnojctizwocdvyhfntnkqkwppykqiofswbdbhnvoyvlxeimksyffgwjsdlezxynlhjydsqmnxvcejkpnohnyumagamquesizwvzlvorrjaxemtyobrtyqbasmlotvsaarrujjdmhtsmgvkhotsvbkskouamnzhgyvldhfsguryoqkxcapetonlmbqubqfakxedbhcyxsohgjosoosxlhrpryekbqjahwlljqyvbwxblcimjqcvfeuuycxblmxgzqcevjvofwajgkpqndiywshkdweosanlfnmfxnmavyhzjdezcquvozsjquwjdlubryrfbdcfzxasgvnjjlwjlmksxqatbjgnloitqcclnexfqldyomkyrwyoyaapryhzqjsyovcpinrdlqsrotsyhacrujptgyklkiejfvmslmrmoekecbfidntxdmhlnkirrjhzotnapgpxawizypeerkircjvifirzgxnvxkbygthpgjvobycygirbiptexjsoambtxkjbycswzradntgkoubmwwzsqrdfmcoxcndwsnquppbgqrzqigufdecsjtlyciizbknscmpzdjewonmobfcmbqcngxsnwoscdqpqnwsxtxfejdxrilgmmexpybhqobtqxzxudzcparldmsnnhtpptaejkrabtaqraybobwnpucumqzwvsecbvqviisrgrdebcnwdfjilbqukflacfmpeirtsmafqipsvaqrqjqhlqcuhkyhrwyujdfczrubrcekuamtqnrvvkroevhbssvrvybihnbtyxymdgndrcpospdvivyszmubwgdommmpdtogsomxgomukjkhyzhiqqyszowvplbxgyevomrzgulxdbfmixgmbqsgzresgfqiyzltvihedxnxcokvjmbwtbgvmkaohtfhvzrpyvmpgvmwhvygejgeywdbhfpgeyhfvqqedozcaxfvnjfdtwfllffjbhpjlvcqexuhuurtvhttromxtrxfsvbjkjzlainvynhgjduwmybxxciknpmbixooaornnxqolodqghegdkcmksfnihswlgpvhvesvcrypespbxwyyotzphmqctvlqnrfqedcdoozlrkhnzvebkqwimpnacifttfzqbbiwpnduixlvspmnfzbymxrunfniiloijgpwlbswxeuwuevkrugyphmgqrswmspljbmpjgzgehkljevjrnvfkaeyiqklcpswgifxnqpkpuvfizhviyfejecocfxrazmfqkiywqdfkxpclcudwientjzidmssnoeyhqscgyjzkbeffradnprizfyodcwylxteeibiutwprmwwtmvetfpcidqsjhguikalvdjvintrhqysmywqrqveagxduwaigpcmwydljaizbdgbhrsjrsugebyitcgrnhkffstvwathdwydwckxlsfjepiorevduwfvwwyerqzcgwlazhxgxixrmbcdqkwswtkmmdzcokxkxwwltukyisjeprtaxwsmmkbkeezjolbwfpplkdfpjodqfcsizhlnfsalsdescboxogtidkzlurzgeaykworwvtqqelydcifxnsdnebgakpihejzwwbbdhkoayvknznodvgweeblobcsqgrhlootngibfhwvlkeqloscrlinrnfajdcmamtvmsbxmifqedtduqmraakxztobcejczwwbehfgvwmlixwtujhjsdfjtinqhotmzdjudggkqsorsyrmbanyaifkfkhruyxalbsjeectphhkybpewghwemdkdzwahhoaqgzrhllafezgwpzgcxaicoqoncjgbweeoaefhtjtwkechbgdgclmuieyabrtajjbsepcaoopzskwjbaxtioopeuvsuhcszztjvkycqzshlycmsaudtcvaytamzxkpeivmxxrnyneafqpomcflcgvbmtmbfrmuprlzdtkmcysutswhqeaxrlqucsqiexlfhdldbuxxgzudobzlwoeszeoumfnryutxrdhosujdoxysppddxvwkroafsbdmtcehsmvmzcfmvujhdwsxidvvcyecerwnrgmmflxypqhkmabjbuahyhcdlbvnjswszvchjkftrlfsbtjgukldmxgwbsbttolkxxpaslmfsledvqejrojlywpdmzutrvwbuuldfoqrsfxamgmbfpxykisxpiwgsjsdbbwqaksdgisnwcckasgnbiuyjmxivlkahdpmecmxoodgvvobavbqkbfaxemadyjkclhieuylqudldcljrtbcvbiqxettsaaxjecjjuynstugyahuzaonzozziieuwxadvhbhrnucjzysrxrjutmpwdwraqtrakqtmivpyggormdkypbevjshggkehoiywieocplpeezmghckkklogocebzauvywqekosbbnkwfucihqkphhgyxvfhpfhjacxicgjqwjzbalablyrrzxcjbmeatdfweqdlxntogeojejujzafzxwpgfepkxhotuxuxtxsjhsbeuytuzgbkcfxdwlpaxowlmyffoocadrwcxmidvbqhrvyuexypyychcvvbwsxrkizatevjlkwspakiltgbuhgzrnvjqvcrxikjtdlzpflvwjpcpectxcdbndkmbedhnnxmkxwfrxnhyrfjnocxoozerpxjhbfpxiveyjgawxfoxpveutkyxbfcrnbrlfbvbbrqrlcjcvmqfjfnnntenzbtkegluelqwhwsmvsfmwomdfhxrgjlcvzakfqyopdsuknjyqadbgaabhxlfwjqpiuqeqjqvmyttschlatqtqgrvzcrxuzdvlrwcvxpgjekdlvprsvgqnjoyyskzggecssgwdkxtrehkygbvnfbhcwtlcekxygempbelldacfgscrqvsxewhtfqbkdnmvnldtbwkqebraxsjkgtwpucgtywfgrebaempnnzcvgnioiwixzevzagugdxvwsvpfwhwvineiyaptoaotsytuhvhlljzuryzgneevedecmqbcbjowyapvdeinukadfbwmohrpdffauegzslbmgbwphvteeoaoxcqdohdfqizxqgecqwhyldfpqcwrwompnqfsfnzmrbtdjzndojdashwwircatzsbxekyhzvoptuxslssynmublhduwjweaohgwegfvmarttfvaiddkgfxcptfkqwrtlieshuydgbxqqivljmuzdnuyaikmoaxlminabpvapknrsynoplvpheedjmtoavtmupvgaacelhmxdzutsombxjeoxsmqmthdtovzgmilauxkhdmdzftbnbpgnuxksifimxzyfvasgluboprinubqwijjzptmyynznqdgzgddupcprrxldqplblbyzyjjfsyhndekkhdepythnlctxheuihclivvqlwlyfnucbrefhchelfbrsunegpqpetymfkpnldewemapknpdnnyxzhvsnekdhjdvtsoonmpwhnukfkiklipvdvcytbolqskqglfmpyptjiybydhhpgbtutitbeyypoecxnxddyrgbgsocakebfkioqbgmxfnflgqsvcervjunqqtqrrksdhibcqxgslseqcxmoliayllawfjxqeoyrwakvhppogjogvplbefveftxeyedrochojzdmegwldjurwggxwmrsosipzwmhrkadkwrrpcfkdagyjnhggdjfrabuxjeltxkabnfcqcgmixdsaccdhpsqjkcicxfsjuyeiybotplvhpwrbjlapsthabbgtnruixjreouznrawhmdeuvkmorvbuorssyzbjhprfspvuldctleqvaqcyjpinuttjjtyaagqdnrxnydqdknutwbhwqcchpaaigrzfdqmlzfwjstpylcqgffhvpcipgifdptawkhxmbdvcgnwziniomzzrhrkmaarndqurrauxupqhqbwoicsssxldvoxyqdmrwfdhhgaldzyezrfksavgsowfdzmpriytfblsyvvkjzztqsgepllijssnpberntnyzihkybrvxkzrwpvsxyddukmpnmxcxycpsdvfiinpcnduezprgqvdyjrzucgfyqbijaspjmvzxezxpgkjqhabfnydzmehjcyqlwobakrcrstergxtflcfmkabxixhigltgczbqrtzobzulwosfwkkjhnrakpxreyeyzynixkmzkzksjgwyqxeyqazwetqbsqkiwwyfihsymgkxlkwhyawupjazayisulbbbqvpqdetubdymtzetqfvemzhwzmnsmbogegfknxmguagtqoohiltlviupsuzmshqnrtmjnmuzcykhkawmcyyyzkjvhjwkqjnvcyiciysbjutzxfwegfewjyubakpdaemifvoxrdryircqullhdwrqmmgzfmjeshrwfdubvzlqcezsuvdqyfibelpciihmyaxthtbzekaosvtslqyuqxtqbeygthigrtpqhqoppgdfupusfikisxujrfgrbhqgfmqyqpbqnefmqrrijtezxxthhujppemhadtnumohljsnpeafgxycvxwdtofqdhazvgooboepxxezcsmphkwlkubmxtiuroutleymalsjtawesvqieewbunliqktkiezpshbipjliqzsuxuqjbtduasxtawseldmkuvnzsisjzpyokaxrcbyjfotbeoygymmdfhaqqawgqplarzvodapjremumscxdnnodfmwbpaavozgkauxvvfnpxxsntthcxuafomjahtyikqyonutmgsiqwirhmehidvxkbsivmnroyzpbkiayfjibgarokkhgiktykwlicpyxaspgyhvwvmeylsjfqqqnnhmhoeheiccpobrprbjxzkjxkvsrataeftrnecyzgwntpesnkjahswgwarvmvshzznktnxslkmniazwgqmvwpeqkyqnzkgwxdoitxnvkbrujhpxsrspwwjrhmxazxshsahanslklpozztyrdqwevcjyybjebadslqvsgjpkpqsvjrmbixyuubopsbhpbqlzypbpqvimoqquvyfbepfsyyymjzulnxqzxkpvqotbqdjxctwehnvetiorummcmcumlzmkgrlpuwwmepaulbuuwcsqutnrnzfeiflydpptqgzvetkwxdgcbhqisuauipsxwdnyfkrzyihzttvtylujdswmbwfbpmjoarhzowmayommviocuzhszqwsgkwazfnyvprnvppbtayladdapwgkdvsjdztmzdaazhjieodyybefabuvbsnlktmltahpabtyltpbdouxtkesgulgkgylprptcwvfcpykn\\\"\\n20\", \"\\\"vzfqqpmafndvsempwivhsfpmtwqctwfvzpllpmacwkoloywxymnsleeoedjfpmsejzvcofniqxaxvyxtvjpqbqznfbjfqtzvtdowzerwjxpzcufprwgoyddfgljpjomomkyvxxjvqtrxqafjmppnaldjndonveerwsnahwckutdssqtuaggckuejfzxlcyhrrwjlyjvzsxwdhhcusmzyqgbkzbbmeglrrhmhwpzrlichzlxkcawanmpajdcokzqudckirmuvvtisncnerdjzctadfhtpwyefwokpegwbpwcxijahsqvhmqlmczhmpakzlxiihsjcgucaxdtsvfdrfwmvskgaofcrtkiulvcyucovcexqhlbwovohkqphnmfnogmuwrvlshhxficuhoxdygatqxsnmneagciyswlejfaxsaulxhngtzqqbifppddjghmodtcqbawijstmvgcpciimnlxwdeeozedezxvoimbwnlyqdkiunduprubxlrbunlyhptfcfaqckwhxxrzyrdhjutwxjmhjlzfwaulnvgitdajmbwxjmxuxdkuotvmeyoixnbnmypnkfsrkjgfnmmwybqqkxgotnegqdpwjzutsxgkksteelpkbwlwqqztbqlzvmombzseetikglbuhsiexiqbgaurpfpvavizqclwtqfegnhfmochdbpvrezuppvxrmdkxxdsxdpxoyrvtsqcjknllpyojsbvybyhilirofvtueefpnbkathdclflxpidharqvuraaimoagkxtxhvrjopgnnaguccjehxxyaejtlggptfszgyfyqhjnewmmkcajhkupfgcsooodfjfnbogqwfqnvfoqfyymowaqvjjlnmifaecgqlipjqflwxdsoqywlozxrpfksfqffykdlmasypzlwsirswxoqrzkxqnheldktrubkoiuxplmxceicswbhvxauqxgetdxfxrmvmdcpwpgjnaduhyaryhdjtkvrtrsunmpioqfjnzncjidlboqqrswrhssokoycmrjfhsdfwdbvaoyddlnlgxzqleszzduhdruzfqymxcgavxcydmnyzyrscrtzrulgfywswilfglexwqossrjpvqslolvwzhyopfesjinpyxvbhfjfynurhgpvhadhvjrpkzxgfdfyjekjzohizcjyqvnihcildfiaxxocwmzadbwstmgkimbecrgsevpqxppiwfnfieqcxlbrcfadpuphqsqgqomrhxdeajukbtccznzvpdzviimytqztsxiffyvqwmikkdvrmtnwbgkhwcujqkudjkvpwtavfjikfqkqpophtbqsqqseyanssxaawhrhnrtluzumpyfzhstxynldrqycxyhxvadgcbclzuwpuhhwcegapzsjxkfwihzcucpanvumebeomlicoudgtlxpptaystnxekwbkabvxkusnjbtimegyvswccngwuferkacicygtqibnmpxwqlqknwdyfcbubwrtvkccixjinbodbwgwsqlcfqgasmfzvjzdzzpbvpbfbztrwetbhvimpmawkrswygkcemxhjxcpgntblobrmreaayjnredmeyssfwvzuovpgqrgrhdmmcfbrlbcfmoxdlgbshufaoztdwukuwayhlcifngxyglcptazkixoisdohuqaxqrqdxwscisrdalznhynemlzllwfwwlcohxftytvcidilgviumgcqrccgvqdjufaltpoywfuupfbzebakkrmcjzjaqfurjotsfpxpsreporlupqtrcfxytfpjcyemixjqaaekozhguawbgywohqgyxnwgitwrozbhpzctybzdxtgtwxnlomyviqighhogxmmvuiojwtscvptfjeqvpxikfwpewuzuxbghaiyfwvpbgnhjtzurdumgmkgrrappfoddjncceydcriseypfbalphrlqjrlwrswkgskdusxphtviasvfwkjmzpkvxniewyvfchlxkuitdatgonllgtdjmhyndquzvrznxrrpjkbsqqooldcqdmnrqpnexzqljtwjsoqcljwxhsxogpwwbhgrbfwteqqwbtvrthwpsiqstwifylfyyocsafdliqppexiftzjqcykakchyzqeriazvhckadvhqrvloqfdnkrjbyrjeywvmgbaszdnlohcdnnpvfcotyahjfvzdixfwxghnrzgdazvepezsyesgkxzahhszptmsdvvyrwdkjfwrqievuiqxwnikqevgtbiemchkwekotveaciguksmqqbfcccvejmlynvpebubmhqfmarajtwwebubienyehgdsfyfosjqduaoqtrymmobmohagxitumuuybfmbudsuzdmqlxzpdsufgisnuoanojoflabuelcuptynyirstqhmscgbimdqqcjmcldrfaqyfcqshzmyiapszrtwiwimyaaolioilqfopgilqpnozbwgdmvdgyhbccykmlmhpkdyiglxdokloxsideopoyffzarnbihpwiiqqsguavlggkxewnpajtrnklpwbkwwggcdkinoxzdyavyvntgmchqpcqmndwspqyyaatsyotngmqlwoclcmxgsborqtedwecigcxfeqqlpfpnmuavcbnnfksytmnwcerwqdturzynsovyugxgajxhgdljiouzminjkoiwlpjelwyrvxcbckjcghlwhcznhlnwzhvcgwgzaeebhjfsnzmvhgjgusutgunzstfvliwcndvicreskbvkxdocvqiwdtutvfftgvgzgzsstttmctrzklpfozvmtiughcaplrunygxjgshugbfozctsgazgxiqpjotgyywocvticlxyogyhrmjqtiuargimwmlorvznnsdbmhvvsmangnepicaoblfbdjaegaalpahfegurlraxyphmpqzpjgluahczftxywerbdrdxawetsszyfobgqemdghhibmbkrxaftzdhiwfdqeqddxubtwtjdxcenswhtbfpnouyhuaqiquenucsqmofdqzyiuinincliwsdedsymbllkfbmzxpojmwfdjkahrahobzltumcsicqaibsvseoukxidikfrlawzgcybzzhlsbusfapdtwawtgbwpddvijvlyksrwwvgirpzbzckfrbqzawildvdehkggfieyzwdsmtzueipbxdlaujllueoijkepsnusonuwqgsicmrjvylyzibspizcbtlfoldfymlmolujkycdljbjcamrdpmceerktgxqpmnmkqdqjoajjacdjrqwddrcaukdnfteptemxvxkvwxglzatjtjcbhixwrxtmemzvgohyucvcxkxwsnkbwfjotnjlztiwhjtjeaibcntqdjbgbixfrkxayklefrfptoivtfuwrrqqbwofegpccbtbohzngomalvcgtpzfjgunqngrqdidmbdzpvikffsenducryjyvhgrqzywikqcfgqcgayjbueukamasnwbdiumzoykbsbbgapjsiwowehqvjzotymhhpaxhptfyhdopcjevsqjeitlmbxgdrfodqsobfchwpbizczgpkejmjjotorqyyjrgifuoislcawhtysgdmkqollapcraakvvlbsfgyvbdjygrgevfaetfltrwhtxdnjesmmlvquoofpahdcuumjxkxfbpgbjabczupzhhfaraedkntysajrlcawlovtkqzukdaxkuxqgjorkeymyzzqwwkihlrukekghmnhlsldmhvnuhbyzgemttxyprstiimevblpihttefedcfjvvgosocpfsghtyehmkmlwcdmafufpmhtjylunuyehasjopcwcvxsvmjgvifbjlggtzzcypeubbsqkvmymmyirldaoibdzjazzqsdrfarvdnpdgciqmbzzkpxrznwlxnbuawsdvlzacamzefhanekcjmmmbtkyjruncrlmlqydmddrryteqtvrcuodciqjuwupagxfjixinnmkfrndxhvgrrliuxsdcojgilpxhyhbnfwbypuxkzzgfrdwjtjxdpacgjoosigwqvforbivpeqrgxubwfwxtqbbvmosritpdoiijutjiqufizzjzmdxijwydhzmmwhrmisyzgydggfsicuoihtosfqowdygjcmrzokwsxaletyfyjgfqmneispuopuxgmamicinchfmityyegpuiismbpkzmnjqggztyhnbhflqhklftsbttxvlnoccurpqkvjafcuvjpgdzpxatntpjluxvnrdquyvgfxdwapecbktvortgvimytlgilchfxbfcyqgsxwcugqsvjqehonolyutgdbogjtlptraejlinfbbcuezfebcakmqjqivcfhytfgaiiatuvogzsbfbvvlhvgtcnrzfcvneuqgbiyiyyxvlgkeotgmafrhbciqrlpjkphqzhrmofnuokfiapjhatrunligksmtmekclwhljbilcpqndsglhtmxgkuadsokjsgchngfuztyjhgdikymdxpkychefbqzkcxndkrnalyshzexrwunwcgwhkamphojmnwplckmbbtykbcjhxwhwsgsidrbnsjxikpjkiyjeciafsrokankzhuciywcoiqzrrtklfdendphydixgylwryimdgaafvwlwmrblfwsyrqzibtwvuyfgvluwurhqsyqzpfxzgnwjimrjcoykspqflqaghsmzdfngexlyeqkpbruntsaqfiekcxwcpcjvgcdkehjndiwfdcaicsdaxifzvixubtzmekvfmqtydpopganrbnwbrisihzigdszzawyphdafcdcumriuqockpgfvhpgwylgojudoyyllmxebloowjvxjouvmagajmkehltwtkutclowitsiaikgvdynemdnaiuboglgevrlnfamwrtoordkbbgjqxfvnaqodycfefgvawcsqkzkjlqqgjkwkhkihvnbswicljzchpyikqosnfrxolronoikeayeidhcpbbeltthmewgeiuqqjsuiavtmghlfeaxvxouxlcfnwrrpdfbooqfprpggigqkolnjmxjkmzlzodlhqicgcpgrzvklcslfgqpeoerzjvbqqawnequcftgjkhnzpydylehuuwdlsoxeqdtkwulczebvsjefugjxyctaiqgdlstsnlfmewxzamaxrwattjnpnromifrskhqcxylxmtzhgasionpktrokvxuiohxjdxqfzvvzkljyjrjspggwgwhrqzpliuapgdocsxbblmdbtoubbylbzwmdqdokigylibpgpxsolkaatyoixptzwpmpvcesrhwyltkjkvsdknddalbkrnewtkiqrptxysbagesezclpissqoykejjletohcvsublpvoymewzpqwkvenmpjpqwbgjonzisorjfvimieqsntyzeoisyulcmqvkubajulvusqniykqwtjoygowwxdgvrrdovlkbazrfgiojcdbiqearycppmsfqaogllorzeuzlpxvfepwbhpxpuncsepffgmflfyihoqjmhjveshrvnunjvdplpmngslpdhdxioefoinzbgirvtqycfvlaajyfhpqrnsqtmrgmtkwmhhvlfdrlixwfqdlxntwlwdwielkqbmqlizvmkoeasrcgbcnxtwhwqcbwboetevmnfdutatmhrvacmzrcvjayxfgoliecrklytobchqqgmqvyeczzhnqmqikpzlfsxnmipelerpubdubnbhxubkyrspczypjdhyrfyjrljaflysrtdoybtwlxxsyjmgazgevbsjmzclyaqjnylgouanvjzfjegwwkcwtsmykhnkdxjsiklszzslllozfcwcnbpxgkdflnuvwwkqjdouajxmtffbcjjgjnqrxzofhuiecthyxfpevotheasyplzghthsylsbhvlhtcxuyplgelgbeezansrgikwetdvleibocxjxpoemlqzemnqgkbkxetlzufuuvvjigqfeamkrlnakjheyoernhvqwtinxyltzupfrxhexjzeotgmpmneaardnjbwcdpxnqbsnlnlpwsqukbclncrawwlhkeylruyqgbxnnukuudmxbihgcoysqsmyknkxcwlepmqvxhmeuiomoyzsydylpzagiqlyifarkfcafhhflhgmxgsdinmbzbmamdjuqchvuyniqhoxgzobuolgqwoesdpjljpzuosyxlgxgzovkwyafrabiwldcteceiodkrccofwiujgqtbgbyzaryzcjgdyvbdjtwnwhonluypdsmkpwwhxkahowwcvfjslxyxdwdxpmpaiimsicvjfpyyelnsdranlfdezvegbjjbfgcwitvcnrxiajxxmvpqhkhurpdclfoeszlzaapqrifmyjmjqowkqmrngmhozmccvrpnqrwkbvvygsdokejhwqqripgtfluzbrbruorqedjvodsfmctexltwlzlipegzhlestmtcidoilkafrvhcoatpvxygmlfkozdifocsxxxitfyepneffrfytjaiuikuogckodtakvfgkpnntcdbqqeipsdwbkftzztdnwruaigyasbommhzcqrfaguwdbshpdsfnkymglivltwujdaydxkesntgfrqbdzdcspxbmjtorjiouzkmqkbvakyteoplkaadgheikvlvdsykozurhllbraqqjidbidczbxejqaljragxxyicjhohcsmcfqfwurbyzqialayezypawblrmpovmkysimjigqzkenxaqwxmggxiirppculyflhqoofhzjboflarpenlbgoamcilglfxxgkpitspaonxlxdnfttiadgnduwjzmitibilxoxxcuexhzcfckqkmyukwxinbgvzejbmffwmntdmmpzmkgodrxwrlcfbyegmmwpcaiexdpxvmiquuydycefzhkuwlewamkzpvggakaqfcjztkkzdzhqqeqfujppfbajfsypaadhwgavezduxuipsfigehzinzpyowvbsfczvhrkhzhmccnwmfgcxoxbktxwkwsrmwixadjoomdsqigexuhzvmuflnhajnkwoxwhucugfsondvrogdsbfgnlwlyannugbthciiegdsxrffcqzqqzruosffwrbakumcksfdatwbsglcjjjvcrmbugxdoncqnedljgnvgxhzpcsmowfcqamxdjieiaftihtuktlykdafhmaznmywwoofxsqywysundvyvouxemxsbwdejzmoqgdppikxbefwifbwptrjtephbzpzpfpztdtdhxybaacjbvhiwilpqlroyctaycouxnbnqdadbjzulzqbjcqcoxtypamlbxqworidhpfaljkwranvpwkhdmaijuuzqchenqfeojltlycbdmsotfgdodbophvvlggyijxebhnjeumcgujogkfszaskbbhtuysbekpiogxolupbqjmzrgyhnofewtzaxjplrmndscktixhvaemghlsgnfuhkuhxsswhunijccflsavtyawbqavacobnmfwkkqqdthqkbearlntdgnbfugavyevolwswunkmfbczyqxnkpuhwpwzypgmbalsexyytjodpdrlxwvatnuguqcbwgkzbszjfkxljnzujqcftgnyjdgiaqmnyqeokhurvnzgzjphqrjnpjwyoommkevsgjbvzvcuyajatvqbwrheancfbkkkygeegkenkphljnhxczusnucyrdjtgggmbklaectokoylltbfcbigifjwisgrwhzdvauipjkerxzmdksefbvxybvhagfpnugkloldohdryrhwjmecfrchilxxcxlbuwoqinlhsgeazferfkgfeprpedfjkhicvozwqdnhhtpoxezmkmdmyxojxdzomznwzjkzryoxgeifamgckcekkrccihpndosevccwrhmaluhqdfuoiyigovxjfqoekjkxibnddakhpjvujtwwdbednjzdjqmhslaprgcscbzrwdxngsmlcdyxewwvrtfhevwycyklhnnxvediemimfolwzrojrralzuzrhzzawhujvseivhhdcwtsesmptcguuytbiditqhgbjguhbnqevwtwfgzsrvprzjmtdxmqjgsaseqxahzxtocvtuhxqymaymmloyritrxrbbbmdocewhzstjgfjqkdsndcxgoeahnfosaefzvsimxjhiecfjnsgtjcgllfhvxtpcfecitsqbbuamwktiipaqseuexbiotvajglnnzqzbkcraejcnroiygjwmryybkdkrjvwpjubctvioarzbcosbgzinfucnizlhnbbsjmbmusyxxrtvxzysbjasstbqpyyyqqgxajbowegezgrapvxiziecpbvbqecwukqthrolhiqtrcudhgufqimxgzterbttdnomsiyycbiqsfvfxmsxgsqrezvtaawmkhxnendkivysapqviwplvwiiytsoxxqryjinrknelabyiokwhvflyjlzghazpprzqjmigosxlctflwredmdikvqnolwmvawizmefcymkhcpyagaehnftzgltqbraxoizpqfnhgnmbzrllsmmirqokqmhynqnuepkbutgqxnchappspfcodqzkigwtlaazxbmcfzbwrsxszodiyfiisktsflmqmrfoynneiamwxmhrucfahosunwlfmnauojhnxidriteheuutewpqxfcgnfqjymzqgvratjeylvzuhbxksstexwkjuphwzylheowxewvkjctsiumtqykresmpmsofnjnwrayomwfrpbawxpvcmadxnwlxjsimsngzajrrxrtiiunkmjqwtxysktblxaqdiwnydbjveplfmnzgxqzslriiksettlsnvkfyxtukiupfmqczqoyaksmilxhsrvbixvlfefxpkjgeknxstfozlnthgqdwujtumtxrgzxoenmbdewoutxghwzctucksbhaczmvnevlyioomlzvxdxdcstyyytsxsvisjdedjgzrrkxxayqosrsibolspkxtqqdgsmlmzsiwawnttjiuwpjxnkoaqgxlqfqdcyobfbiuqxuawdmmuokdcjyylfqekrmmnxcgnrkchxmmephnuwkcslgtofipalnrleetgusqxrrkybjhbwsnlokhcqfqmxmnvcmekrontesnojojprxmuokaepzllkugsbqlbehqmxzfedweqvriytyzbabciygippabexrdbcvkvrbarjbaeeohniuqmfmzbebxiksvpvtsvfumsdvskhdkdwxjpmmrutwrghzzqfeotyprdvulawllldocsfgwefctzlpvffpsbajjjxicojoxtijajpaaasyzvjvsmgktagzegocwsgxlxsyohrcneklyvdkwmgakvufzvwcbkvlowpdgyhucfmtczbvfmwakicerxqneduiaxtlcywfkhmmwgwpuelbdjiwtdikdmpxynbnujlljgucpvzwbewqkgrmnasfeuhqgbzzjrjisckasjfujertkcmzfyrjkkxldpbtodtxkryvqzsrhmcvggkucrqptwxhjgyegajfyccmuxpqpjyyeevhweekzglyqlembuofztjysnoefiqftefhfqpbawisumzcvrmaxinrmnabffdpslbaghrydxkjdcxhcpshpthqksqbmfqdazrdxsridixpoyssphqaninoitzentgktdabvvklcfhnklgwjhbozllwliiusxvxhgsqwhdncqzymyrjmiglbeqdxnrezsldygnmehdizqwqrasxtkcnivnizhtzsnefjhorkugnaogppftyifocxxcprakiqmbypvhglkzsnlwddkinwdsqwnztddrbxiavdaizcdijomqckkefwcsvlmyuytzxbb\\\"\\n10\"], \"outputs\": [\"3\", \"1\", \"4\", \"1\", \"1\", \"2\", \"8\", \"3\", \"2\", \"2\", \"4\", \"10\", \"1754\", \"251\", \"777\"], \"fn_name\": \"maxPartitionsAfterOperations\"}", "source": "lcbv5"}
|
You are given a 0-indexed string s and an integer k.
You are to perform the following partitioning operations until s is empty:
Choose the longest prefix of s containing at most k distinct characters.
Delete the prefix from s and increase the number of partitions by one. The remaining characters (if any) in s maintain their initial order.
Before the operations, you are allowed to change at most one index in s to another lowercase English letter.
Return an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.
Example 1:
Input: s = "accca", k = 2
Output: 3
Explanation: In this example, to maximize the number of resulting partitions, s[2] can be changed to 'b'.
s becomes "acbca".
The operations can now be performed as follows until s becomes empty:
- Choose the longest prefix containing at most 2 distinct characters, "acbca".
- Delete the prefix, and s becomes "bca". The number of partitions is now 1.
- Choose the longest prefix containing at most 2 distinct characters, "bca".
- Delete the prefix, and s becomes "a". The number of partitions is now 2.
- Choose the longest prefix containing at most 2 distinct characters, "a".
- Delete the prefix, and s becomes empty. The number of partitions is now 3.
Hence, the answer is 3.
It can be shown that it is not possible to obtain more than 3 partitions.
Example 2:
Input: s = "aabaab", k = 3
Output: 1
Explanation: In this example, to maximize the number of resulting partitions we can leave s as it is.
The operations can now be performed as follows until s becomes empty:
- Choose the longest prefix containing at most 3 distinct characters, "aabaab".
- Delete the prefix, and s becomes empty. The number of partitions becomes 1.
Hence, the answer is 1.
It can be shown that it is not possible to obtain more than 1 partition.
Example 3:
Input: s = "xxyz", k = 1
Output: 4
Explanation: In this example, to maximize the number of resulting partitions, s[1] can be changed to 'a'.
s becomes "xayz".
The operations can now be performed as follows until s becomes empty:
- Choose the longest prefix containing at most 1 distinct character, "xayz".
- Delete the prefix, and s becomes "ayz". The number of partitions is now 1.
- Choose the longest prefix containing at most 1 distinct character, "ayz".
- Delete the prefix, and s becomes "yz". The number of partitions is now 2.
- Choose the longest prefix containing at most 1 distinct character, "yz".
- Delete the prefix, and s becomes "z". The number of partitions is now 3.
- Choose the longest prefix containing at most 1 distinct character, "z".
- Delete the prefix, and s becomes empty. The number of partitions is now 4.
Hence, the answer is 4.
It can be shown that it is not possible to obtain more than 4 partitions.
Constraints:
1 <= s.length <= 10^4
s consists only of lowercase English letters.
1 <= k <= 26
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def maxPartitionsAfterOperations(self, s: str, k: int) -> int:
```
| 0
|
{"tests": "{\"inputs\": [\"[1, 2, 3, 4, 5, 6]\\n[1, 1]\", \"[1, 4, 4, 1, 3, 5, 5, 3]\\n[1, 0, -1]\", \"[81, 50]\\n[-1]\", \"[7, 57, 88]\\n[-1]\", \"[28, 53, 21]\\n[0]\", \"[5, 47, 63, 48]\\n[-1, 0]\", \"[46, 60, 80, 98, 90]\\n[0, 1]\", \"[9, 83, 77, 75, 39, 32, 68, 60]\\n[0]\", \"[73, 26, 7, 20, 30, 48, 97]\\n[-1, 1]\", \"[17, 19, 71, 21, 2, 24, 29]\\n[0, -1, 0]\", \"[88, 35, 41, 84, 38, 30, 87, 7]\\n[0, 1, 0, 1, -1, 1]\", \"[73, 34, 14, 60, 77, 97, 54, 63]\\n[-1, 1, 0, -1, -1, 0]\", \"[501399232, 959315981, 630569939, 369992778, 762747706, 678500115, 290334310, 666493456, 207228447, 367090709, 710041308, 135377803, 814213426, 969179920, 869845371, 276379138, 120760857, 852013521, 967284240, 76906837, 464555393, 865016650, 788827506, 750075661, 847293256, 74072686, 273445644, 611123245, 679977255, 717345474, 672117374, 280314168, 18176283, 651591389, 946339492, 884013286, 863214339, 121877045, 936428905, 749504839, 49112178, 961728742, 118501222, 442201631, 950793264, 180831825, 51869751, 502194993, 826181405, 198659336, 587636696, 222864939, 623098844, 210888296, 398223150, 59909422, 352052866, 429669422, 64797567, 780553664, 286945028, 289350308, 607115484, 416826628, 227986024, 665979338, 938728931, 385600482, 799076139, 408699336, 456756072, 482748621, 879865330, 493872639, 393551506, 925116932, 981007406, 454780366, 652424028, 991421291, 166830803, 484315076, 907419950, 875405057, 939199322, 153628762, 967592872, 419748504, 797841033, 533613156, 763571640, 462980381, 865162358, 906034855, 973792201, 150079861, 982936258, 499336540, 384170831, 15599924]\\n[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, -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]\", \"[131844005, 503539488, 895277194, 759135098, 222859496, 417206297, 93592988, 652746849, 668575746, 426968159, 90365765, 524804995, 424162038, 852071046, 595357210, 495180102, 671676834, 876299439, 994737405, 627163327, 244830313, 602073054, 300741633, 718338014, 289606104, 39647787, 321603458, 111918550, 601078319, 225088907, 103288961, 512810211, 257054465, 258736734, 792225867, 940177318, 176181969, 463804773, 936882278, 82890317, 212577344, 883127335, 158830242, 839256780, 413346255, 235128553, 309360347, 183335816, 935094040, 716290736, 242939618, 768597219, 867126752, 588146428, 708144623, 744416831, 646490848, 591132747, 896874946, 708473731, 653644741, 988864797, 684605163, 632823994, 860471013, 156163540, 457954345, 621980039, 553883429, 973856399, 847853262, 301416141, 67641836, 343357596, 428499293, 259578322, 344728849, 561456318, 273243699, 788203584, 350552917, 808682861, 788006599, 961916298, 480628920, 117333757, 572805397, 941296324, 914575507, 789429393, 373909251, 1504179, 335023081, 404799938, 519327858, 749008948, 355046964, 375123262, 858160530, 666369522]\\n[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, -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]\"], \"outputs\": [\"4\", \"2\", \"1\", \"0\", \"0\", \"0\", \"0\", \"0\", \"1\", \"0\", \"0\", \"0\", \"0\", \"0\"], \"fn_name\": \"countMatchingSubarrays\"}", "source": "lcbv5"}
|
You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.
A subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:
nums[i + k + 1] > nums[i + k] if pattern[k] == 1.
nums[i + k + 1] == nums[i + k] if pattern[k] == 0.
nums[i + k + 1] < nums[i + k] if pattern[k] == -1.
Return the count of subarrays in nums that match the pattern.
Example 1:
Input: nums = [1,2,3,4,5,6], pattern = [1,1]
Output: 4
Explanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.
Hence, there are 4 subarrays in nums that match the pattern.
Example 2:
Input: nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1]
Output: 2
Explanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.
Hence, there are 2 subarrays in nums that match the pattern.
Constraints:
2 <= n == nums.length <= 100
1 <= nums[i] <= 10^9
1 <= m == pattern.length < n
-1 <= pattern[i] <= 1
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int:
```
| 0.75
|
{"tests": "{\"inputs\": [\"[8, 4, 2, 30, 15]\", \"[1, 2, 3, 4, 5]\", \"[3, 16, 8, 4, 2]\", \"[29]\", \"[14]\", \"[34]\", \"[99]\", \"[206]\", \"[159]\", \"[249]\", \"[6, 31]\", \"[47, 247]\", \"[9, 148, 121]\", \"[73786976294838206463, 4294967295, 1048575, 4194303, 281474976710655, 75557863725914323419135, 3, 36028797018963967, 1180591620717411303423, 17179869183, 140737488355327, 511, 604462909807314587353087, 34359738367, 137438953471, 39614081257132168796771975167, 134217727, 309485009821345068724781055, 562949953421311, 1073741823, 1, 9007199254740991, 16383, 9444732965739290427391, 151115727451828646838271, 2361183241434822606847, 2305843009213693951, 77371252455336267181195263, 8388607, 31, 2199023255551, 4095, 4835703278458516698824703, 33554431, 4611686018427387903, 4951760157141521099596496895, 36893488147419103231, 131071, 2047, 274877906943, 68719476735, 79228162514264337593543950335, 262143, 618970019642690137449562111, 2417851639229258349412351, 4722366482869645213695, 524287, 9903520314283042199192993791, 2251799813685247, 144115188075855871, 147573952589676412927, 1023, 576460752303423487, 2097151, 8191, 9671406556917033397649407, 1208925819614629174706175, 15, 590295810358705651711, 70368744177663, 536870911, 4503599627370495, 32767, 65535, 35184372088831, 255, 72057594037927935, 18889465931478580854783, 63, 1267650600228229401496703205375, 1099511627775, 9223372036854775807, 295147905179352825855, 2147483647, 268435455, 8796093022207, 1152921504606846975, 316912650057057350374175801343, 633825300114114700748351602687, 18446744073709551615, 7, 18014398509481983, 8589934591, 16777215, 158456325028528675187087900671, 302231454903657293676543, 154742504910672534362390527, 2475880078570760549798248447, 549755813887, 1237940039285380274899124223, 37778931862957161709567, 19807040628566084398385987583, 127, 19342813113834066795298815, 17592186044415, 38685626227668133590597631, 4398046511103, 67108863, 288230376151711743, 1125899906842623]\", \"[158456325028528675187087900671, 72057594037927935, 2417851639229258349412351, 9007199254740991, 2147483647, 1, 288230376151711743, 19807040628566084398385987583, 9671406556917033397649407, 633825300114114700748351602687, 590295810358705651711, 7, 268435455, 35184372088831, 75557863725914323419135, 536870911, 4835703278458516698824703, 4503599627370495, 4095, 17179869183, 1208925819614629174706175, 524287, 34359738367, 8796093022207, 131071, 2047, 9903520314283042199192993791, 33554431, 1237940039285380274899124223, 281474976710655, 2475880078570760549798248447, 2097151, 19342813113834066795298815, 262143, 4722366482869645213695, 4194303, 1152921504606846975, 309485009821345068724781055, 18889465931478580854783, 63, 302231454903657293676543, 295147905179352825855, 562949953421311, 127, 144115188075855871, 67108863, 255, 39614081257132168796771975167, 549755813887, 4398046511103, 31, 147573952589676412927, 1180591620717411303423, 32767, 511, 576460752303423487, 151115727451828646838271, 73786976294838206463, 4611686018427387903, 68719476735, 1267650600228229401496703205375, 18014398509481983, 2361183241434822606847, 9444732965739290427391, 140737488355327, 15, 16777215, 2251799813685247, 16383, 1099511627775, 9223372036854775807, 154742504910672534362390527, 37778931862957161709567, 65535, 134217727, 4294967295, 604462909807314587353087, 4951760157141521099596496895, 2305843009213693951, 36893488147419103231, 79228162514264337593543950335, 8191, 8589934591, 1125899906842623, 618970019642690137449562111, 316912650057057350374175801343, 36028797018963967, 274877906943, 77371252455336267181195263, 137438953471, 18446744073709551615, 3, 70368744177663, 1073741823, 17592186044415, 1048575, 2199023255551, 1023, 8388607, 38685626227668133590597631]\"], \"outputs\": [\"true\", \"true\", \"false\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"false\", \"false\", \"false\"], \"fn_name\": \"canSortArray\"}", "source": "lcbv5"}
|
You are given a 0-indexed array of positive integers nums.
In one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).
Return true if you can sort the array, else return false.
Example 1:
Input: nums = [8,4,2,30,15]
Output: true
Explanation: Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation "10", "100", and "1000" respectively. The numbers 15 and 30 have four set bits each with binary representation "1111" and "11110".
We can sort the array using 4 operations:
- Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].
- Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].
- Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].
- Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].
The array has become sorted, hence we return true.
Note that there may be other sequences of operations which also sort the array.
Example 2:
Input: nums = [1,2,3,4,5]
Output: true
Explanation: The array is already sorted, hence we return true.
Example 3:
Input: nums = [3,16,8,4,2]
Output: false
Explanation: It can be shown that it is not possible to sort the input array using any number of operations.
Constraints:
1 <= nums.length <= 100
1 <= nums[i] <= 2^8
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def canSortArray(self, nums: List[int]) -> bool:
```
| 0.5
|
{"tests": "{\"inputs\": [\"[1, 1, 2, 2, 3, 4]\", \"[1, 1, 1, 1]\", \"[5, 9]\", \"[5, 3]\", \"[24, 32]\", \"[2, 1, 1, 2]\", \"[9, 7, 7, 9]\", \"[4, 1, 3, 2]\", \"[1, 1, 3, 2]\", \"[1, 1, 1, 1]\", \"[10, 4, 4, 6]\", \"[1, 1, 1, 2, 3, 4]\", \"[5, 84, 22, 86, 87, 78, 53, 86, 49, 6, 31, 75, 96, 86, 37, 5, 84, 1, 96, 9, 17, 34, 7, 38, 32, 91, 60, 43, 34, 94, 51, 92, 41, 46, 87, 44, 39, 35, 10, 84, 55, 96, 32, 69, 3, 30, 51, 93, 27, 66, 11, 47, 75, 25, 26, 21, 92, 32, 76, 83, 5, 82, 28, 39, 27, 67, 13, 57, 74, 27, 49, 26, 70, 19, 52, 9, 95, 21, 63, 21, 87, 35, 32, 90, 65, 91, 33, 39, 75, 42, 10, 35, 71, 49, 87, 25, 43, 24, 74, 88]\", \"[99, 51, 47, 70, 75, 71, 90, 94, 40, 87, 3, 82, 80, 22, 60, 66, 98, 74, 18, 62, 38, 77, 33, 79, 17, 11, 78, 20, 68, 34, 23, 92, 52, 86, 6, 12, 29, 30, 46, 54, 76, 14, 88, 53, 97, 91, 39, 55, 8, 5, 13, 21, 64, 42, 93, 26, 37, 31, 1, 27, 41, 73, 4, 69, 32, 45, 81, 7, 43, 50, 84, 83, 65, 61, 10, 48, 44, 19, 85, 35, 9, 58, 24, 96, 15, 2, 16, 67, 56, 89, 63, 49, 36, 25, 28, 100, 95, 57, 59, 72]\"], \"outputs\": [\"true\", \"false\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"true\", \"false\", \"true\", \"false\", \"false\", \"true\"], \"fn_name\": \"isPossibleToSplit\"}", "source": "lcbv5"}
|
You are given an integer array nums of even length. You have to split the array into two parts nums1 and nums2 such that:
nums1.length == nums2.length == nums.length / 2.
nums1 should contain distinct elements.
nums2 should also contain distinct elements.
Return true if it is possible to split the array, and false otherwise.
Example 1:
Input: nums = [1,1,2,2,3,4]
Output: true
Explanation: One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].
Example 2:
Input: nums = [1,1,1,1]
Output: false
Explanation: The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.
Constraints:
1 <= nums.length <= 100
nums.length % 2 == 0
1 <= nums[i] <= 100
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def isPossibleToSplit(self, nums: List[int]) -> bool:
```
| 0.125
|
{"tests": "{\"inputs\": [\"3\\n3 5 10\\n4 3 3\\n2 2 6\\n\", \"3\\n3 5 10\\n4 3 3\\n2 2 3\\n\", \"2\\n4 8\\n3 1 100\\n4 10000 100\\n\", \"1\\n1\\n1 1 1\\n1 1 1\\n\", \"1\\n1328\\n1 73192516 779\\n1 468279677 682\\n\", \"1\\n1093\\n1 150127956 237\\n1 905660966 894\\n\", \"1\\n14807\\n43 583824808 729\\n15 917174828 159\\n\", \"1\\n81883\\n122 466242496 601\\n73 329962136 145\\n\", \"1\\n2000\\n1 1000000000 1000\\n1 1000000000 1000\\n\", \"2\\n73635 21285\\n95 53716031 932\\n96 616431960 280\\n\", \"2\\n29639 89817\\n69 81424660 968\\n167 134991649 635\\n\", \"100\\n58954 39221 58132 3060 25623 10982 4181 49064 43736 84365 62371 87894 44458 43175 41956 12310 64254 91429 76274 10995 97816 30126 93883 84364 6352 62715 19140 29335 80180 62362 27874 44345 48612 88045 28607 16654 7221 96520 65211 64807 86703 86613 52552 76263 94351 18291 47725 8774 29542 94643 66181 63342 61719 19130 89629 73953 157 16803 3001 53040 48643 1338 46671 4773 60906 93889 72778 67931 16678 55919 78952 78656 30049 33547 11261 77434 80951 67318 8430 67391 43993 77823 64503 11963 82346 24972 62406 43854 30661 43031 40989 55851 78228 65263 51412 77499 89178 40819 72436 43672\\n11102 1000000000 830\\n11162 166366019 1\\n\", \"100\\n53894 17107 83881 72499 20113 32342 20464 23094 37965 38545 99605 54495 175 37350 99700 42733 15901 43246 94877 84944 58481 8693 99509 66639 5306 25976 72245 97571 17338 13614 82346 83130 24265 66620 54355 29493 50576 82015 21927 96618 40911 63847 95180 16738 90041 10614 23265 17436 69875 93764 18101 99016 91064 81662 45933 54637 75351 49507 59778 98501 79539 54822 58784 24091 27778 57679 23977 18420 5807 50298 31536 56547 10873 5238 46911 93746 61009 56998 41297 98624 11360 60772 30424 3614 5471 29241 26424 32977 85724 46823 54602 21715 50812 21599 40634 53714 34003 23179 97674 57808\\n2608 450391205 969\\n2725 325822234 925\\n\", \"100\\n11933 20251 91386 38326 35702 71071 16831 74338 54255 28030 33765 80628 48113 86938 73167 3637 90102 39494 98385 37220 51183 66284 78967 30005 43870 78471 93660 8557 83964 58569 60723 18952 83060 39702 48546 76436 57158 49927 93186 51091 50533 43273 40640 37693 75673 33531 98591 13371 51166 21108 39444 95117 77764 48250 15337 65894 36877 35659 76026 56586 78641 12056 77691 62551 55293 77605 83024 78425 23919 15659 33811 74612 50908 5623 38641 60734 93579 15432 74317 93985 30200 49556 53564 85374 26674 94339 10600 77509 17884 40275 43022 17535 144 89267 51679 14660 65207 1224 94018 29221\\n4398 636075462 520\\n4434 636075462 988\\n\", \"100\\n65972 86203 11302 64714 43133 26247 84809 50171 63933 70661 70411 63569 60113 80112 13299 70340 46505 99483 37243 66399 43659 27884 62962 70114 50830 3612 96891 29120 18112 87032 53516 51265 62945 59619 90672 77537 89030 95538 68069 80175 68631 61646 58655 76879 2737 52950 10499 83609 40068 77818 53997 81912 90805 48065 24042 34987 41886 740 28446 86087 90090 39632 34368 42579 66201 89640 18009 73130 69250 68513 65609 25373 87500 59301 41090 38607 24339 27665 88779 90199 13386 55894 20222 97249 57843 53563 67978 22253 88168 16889 9425 59055 50166 63230 92427 72077 69597 12875 71170 96356\\n2882 162604618 992\\n2961 892174686 994\\n\"], \"outputs\": [\"17\\n\", \"-1\\n\", \"5\\n\", \"1\\n\", \"314102512637\\n\", \"810826112468\\n\", \"201419558760\\n\", \"319010991784\\n\", \"2000000000000\\n\", \"91364282212\\n\", \"101597505815\\n\", \"505166366019\\n\", \"720699778305\\n\", \"780464591874\\n\", \"1024036702418\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
As the factory manager of Keyence, you want to monitor several sections on a conveyor belt. There are a total of N sections you want to monitor, and the length of the i-th section is D_i meters.
There are two types of sensors to choose from, and below is some information about each sensor.
- Type-j sensor (1\leq j \leq 2): Can monitor a section of length L_j meters.
The price is C_j per sensor, and you can use at most K_j sensors of this type in total.
You can divide one section into several sections for monitoring.
It is fine if the sections monitored by the sensors overlap, or if they monitor more than the length of the section you want to monitor.
For example, when L_1=4 and L_2=2, you can use one type-1 sensor to monitor a section of length 3 meters, or use one type-1 and one type-2 sensor to monitor a section of length 5 meters.
Determine whether it is possible to monitor all N sections, and if it is possible, find the minimum total cost of the necessary sensors.
Input
The input is given from Standard Input in the following format:
N
D_1 D_2 \dots D_N
L_1 C_1 K_1
L_2 C_2 K_2
Output
If it is impossible to monitor all N sections, print -1. Otherwise, print the minimum total cost of the necessary sensors.
Constraints
- 1\leq N \leq 100
- 1\leq D_i,L_j \leq 10^5
- 1\leq C_j \leq 10^9
- 1\leq K_j \leq 10^3
- All input values are integers.
Sample Input 1
3
3 5 10
4 3 3
2 2 6
Sample Output 1
17
You can monitor all sections by using three type-1 sensors and four type-2 sensors as follows.
- Use one type-1 sensor to monitor the first section.
- Use one type-1 and one type-2 sensor to monitor the second section.
- Use one type-1 and three type-2 sensors to monitor the third section.
In this case, the total cost of the necessary sensors is 3\times 3 + 2\times 4 = 17, which is the minimum.
Sample Input 2
3
3 5 10
4 3 3
2 2 3
Sample Output 2
-1
Sample Input 3
2
4 8
3 1 100
4 10000 100
Sample Output 3
5
It is fine if one type of sensor is not used at all.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 5\\n1 2 3 4 5\\n6 7 8 9 10\\n11 12 13 14 15\\n16 17 18 19 20\\n1 3 2 5 4\\n11 13 12 15 14\\n6 8 7 10 9\\n16 18 17 20 19\\n\", \"2 2\\n1 1\\n1 1\\n1 1\\n1 1000000000\\n\", \"3 3\\n8 1 6\\n3 5 7\\n4 9 2\\n8 1 6\\n3 5 7\\n4 9 2\\n\", \"5 5\\n710511029 136397527 763027379 644706927 447672230\\n979861204 57882493 442931589 951053644 152300688\\n43971370 126515475 962139996 541282303 834022578\\n312523039 506696497 664922712 414720753 304621362\\n325269832 191410838 286751784 732741849 806602693\\n806602693 732741849 286751784 191410838 325269832\\n304621362 414720753 664922712 506696497 312523039\\n834022578 541282303 962139996 126515475 43971370\\n152300688 951053644 442931589 57882493 979861204\\n447672230 644706927 763027379 136397527 710511029\\n\", \"2 2\\n2 1\\n1 2\\n1 2\\n2 1\\n\", \"2 2\\n2 1\\n1 2\\n1 2\\n1 2\\n\", \"2 2\\n254208919 254208919\\n254208919 254208919\\n254208919 254208919\\n254208919 254208919\\n\", \"2 2\\n499230390 378102308\\n982788305 450344438\\n876231318 411707321\\n653563363 590784525\\n\", \"2 3\\n817686100 817686100 817686100\\n870092517 870092517 817686100\\n870092517 817686100 870092517\\n817686100 817686100 817686100\\n\", \"3 2\\n472677680 257011103\\n837159242 108282356\\n728499571 592954537\\n574707751 292193816\\n178355736 834362104\\n37342128 249908918\\n\", \"4 2\\n934191141 286715729\\n106777755 395337472\\n801612932 573117835\\n262052718 214166693\\n262052718 214166693\\n106777755 395337472\\n934191141 286715729\\n801612932 573117835\\n\", \"2 5\\n656388039 656388039 656388039 656388039 656388039\\n656388039 656388039 656388039 656388039 656388039\\n656388039 656388039 656388039 656388039 656388039\\n656388039 656388039 656388039 656388039 656388039\\n\", \"5 5\\n925234815 195202420 985293702 925234815 584979839\\n985293702 925234815 925234815 195202420 973719359\\n720510553 985293702 973719359 584979839 720510553\\n797707590 643037195 985293702 720510553 925234815\\n195202420 720510553 797707590 195202420 720510553\\n195202420 195202420 720510553 797707590 720510553\\n720510553 797707590 643037195 985293702 925234815\\n195202420 985293702 925234815 925234815 973719359\\n925234815 925234815 195202420 985293702 584979839\\n584979839 720510553 985293702 973719359 720510553\\n\", \"5 5\\n428393184 141412421 141412421 141412421 428393184\\n141412421 141412421 428393184 428393184 428393184\\n428393184 428393184 141412421 141412421 428393184\\n141412421 141412421 428393184 141412421 428393184\\n428393184 428393184 141412421 428393184 141412421\\n428393184 428393184 141412421 141412421 141412421\\n141412421 428393184 428393184 141412421 428393184\\n141412421 428393184 428393184 141412421 141412421\\n428393184 428393184 141412421 428393184 141412421\\n141412421 141412421 428393184 428393184 428393184\\n\", \"5 5\\n374880163 658612467 822885194 262520417 758392492\\n758392492 262520417 658612467 658612467 979031027\\n822885194 907152740 907152740 907152740 758392492\\n262520417 658612467 979031027 262520417 937442242\\n374880163 758392492 374880163 374880163 979031027\\n374880163 658612467 822885194 262520417 758392492\\n758392492 374880163 658612467 658612467 979031027\\n822885194 907152740 907152740 907152740 758392492\\n262520417 658612467 979031027 262520417 937442242\\n262520417 758392492 374880163 374880163 979031027\\n\", \"5 5\\n332975784 601519183 192097996 385881505 875309998\\n576958202 311665235 890210331 146980141 221794399\\n440995448 620517553 366805840 345853512 977641254\\n565246972 182676863 507026115 872981141 351163999\\n757388200 757490809 436013419 645484799 220662217\\n220662217 645484799 436013419 757490809 757388200\\n351163999 872981141 507026115 182676863 565246972\\n977641254 345853512 366805840 620517553 440995448\\n221794399 146980141 192097996 311665235 576958202\\n875309998 385881505 890210331 601519183 332975784\\n\"], \"outputs\": [\"3\\n\", \"-1\\n\", \"0\\n\", \"20\\n\", \"1\\n\", \"-1\\n\", \"0\\n\", \"-1\\n\", \"2\\n\", \"-1\\n\", \"4\\n\", \"0\\n\", \"11\\n\", \"11\\n\", \"-1\\n\", \"-1\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
You are given two grids, A and B, each with H rows and W columns.
For each pair of integers (i, j) satisfying 1 \leq i \leq H and 1 \leq j \leq W, let (i, j) denote the cell in the i-th row and j-th column. In grid A, cell (i, j) contains the integer A_{i, j}. In grid B, cell (i, j) contains the integer B_{i, j}.
You will repeat the following operation any number of times, possibly zero. In each operation, you perform one of the following:
- Choose an integer i satisfying 1 \leq i \leq H-1 and swap the i-th and (i+1)-th rows in grid A.
- Choose an integer i satisfying 1 \leq i \leq W-1 and swap the i-th and (i+1)-th columns in grid A.
Determine whether it is possible to make grid A identical to grid B by repeating the above operation. If it is possible, print the minimum number of operations required to do so.
Here, grid A is identical to grid B if and only if, for all pairs of integers (i, j) satisfying 1 \leq i \leq H and 1 \leq j \leq W, the integer written in cell (i, j) of grid A is equal to the integer written in cell (i, j) of grid B.
Input
The input is given from Standard Input in the following format:
H W
A_{1, 1} A_{1, 2} \cdots A_{1, W}
A_{2, 1} A_{2, 2} \cdots A_{2, W}
\vdots
A_{H, 1} A_{H, 2} \cdots A_{H, W}
B_{1, 1} B_{1, 2} \cdots B_{1, W}
B_{2, 1} B_{2, 2} \cdots B_{2, W}
\vdots
B_{H, 1} B_{H, 2} \cdots B_{H, W}
Output
If it is impossible to make grid A identical to grid B, output -1. Otherwise, print the minimum number of operations required to make grid A identical to grid B.
Constraints
- All input values are integers.
- 2 \leq H, W \leq 5
- 1 \leq A_{i, j}, B_{i, j} \leq 10^9
Sample Input 1
4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
1 3 2 5 4
11 13 12 15 14
6 8 7 10 9
16 18 17 20 19
Sample Output 1
3
Swapping the fourth and fifth columns of the initial grid A yields the following grid:
1 2 3 5 4
6 7 8 10 9
11 12 13 15 14
16 17 18 20 19
Then, swapping the second and third rows yields the following grid:
1 2 3 5 4
11 12 13 15 14
6 7 8 10 9
16 17 18 20 19
Finally, swapping the second and third columns yields the following grid, which is identical to grid B:
1 3 2 5 4
11 13 12 15 14
6 8 7 10 9
16 18 17 20 19
You can make grid A identical to grid B with the three operations above and cannot do so with fewer operations, so print 3.
Sample Input 2
2 2
1 1
1 1
1 1
1 1000000000
Sample Output 2
-1
There is no way to perform the operation to make grid A match grid B, so print -1.
Sample Input 3
3 3
8 1 6
3 5 7
4 9 2
8 1 6
3 5 7
4 9 2
Sample Output 3
0
Grid A is already identical to grid B at the beginning.
Sample Input 4
5 5
710511029 136397527 763027379 644706927 447672230
979861204 57882493 442931589 951053644 152300688
43971370 126515475 962139996 541282303 834022578
312523039 506696497 664922712 414720753 304621362
325269832 191410838 286751784 732741849 806602693
806602693 732741849 286751784 191410838 325269832
304621362 414720753 664922712 506696497 312523039
834022578 541282303 962139996 126515475 43971370
152300688 951053644 442931589 57882493 979861204
447672230 644706927 763027379 136397527 710511029
Sample Output 4
20
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.625
|
{"tests": "{\"inputs\": [\"3 1\\n\", \"2 1\\n\", \"2 2\\n\", \"3 1\\n\", \"3 3\\n\", \"4 1\\n\", \"4 2\\n\", \"4 3\\n\", \"4 4\\n\", \"100 30\\n\", \"100 93\\n\", \"100 89\\n\", \"100 100\\n\"], \"outputs\": [\"2\\n1 2 \\n1 3 \\n2\\n\", \"1\\n1 2 \\n2\\n\", \"1\\n1 2 \\n1\\n\", \"2\\n1 2 \\n1 3 \\n2\\n\", \"2\\n1 2 \\n1 3 \\n1\\n\", \"2\\n2 2 4 \\n2 3 4 \\n2\\n\", \"2\\n2 2 4 \\n2 3 4 \\n1\\n\", \"2\\n2 2 4 \\n2 3 4 \\n1\\n\", \"2\\n2 2 4 \\n2 3 4 \\n1\\n\", \"7\\n50 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 \\n50 3 4 7 8 11 12 15 16 19 20 23 24 27 28 31 32 35 36 39 40 43 44 47 48 51 52 55 56 59 60 63 64 67 68 71 72 75 76 79 80 83 84 87 88 91 92 95 96 99 100 \\n48 5 6 7 8 13 14 15 16 21 22 23 24 29 30 31 32 37 38 39 40 45 46 47 48 53 54 55 56 61 62 63 64 69 70 71 72 77 78 79 80 85 86 87 88 93 94 95 96 \\n48 9 10 11 12 13 14 15 16 25 26 27 28 29 30 31 32 41 42 43 44 45 46 47 48 57 58 59 60 61 62 63 64 73 74 75 76 77 78 79 80 89 90 91 92 93 94 95 96 \\n48 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 \\n36 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 97 98 99 100 \\n36 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 \\n1\\n\", \"7\\n50 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 \\n50 3 4 7 8 11 12 15 16 19 20 23 24 27 28 31 32 35 36 39 40 43 44 47 48 51 52 55 56 59 60 63 64 67 68 71 72 75 76 79 80 83 84 87 88 91 92 95 96 99 100 \\n48 5 6 7 8 13 14 15 16 21 22 23 24 29 30 31 32 37 38 39 40 45 46 47 48 53 54 55 56 61 62 63 64 69 70 71 72 77 78 79 80 85 86 87 88 93 94 95 96 \\n48 9 10 11 12 13 14 15 16 25 26 27 28 29 30 31 32 41 42 43 44 45 46 47 48 57 58 59 60 61 62 63 64 73 74 75 76 77 78 79 80 89 90 91 92 93 94 95 96 \\n48 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 \\n36 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 97 98 99 100 \\n36 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 \\n1\\n\", \"7\\n50 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 \\n50 3 4 7 8 11 12 15 16 19 20 23 24 27 28 31 32 35 36 39 40 43 44 47 48 51 52 55 56 59 60 63 64 67 68 71 72 75 76 79 80 83 84 87 88 91 92 95 96 99 100 \\n48 5 6 7 8 13 14 15 16 21 22 23 24 29 30 31 32 37 38 39 40 45 46 47 48 53 54 55 56 61 62 63 64 69 70 71 72 77 78 79 80 85 86 87 88 93 94 95 96 \\n48 9 10 11 12 13 14 15 16 25 26 27 28 29 30 31 32 41 42 43 44 45 46 47 48 57 58 59 60 61 62 63 64 73 74 75 76 77 78 79 80 89 90 91 92 93 94 95 96 \\n48 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 \\n36 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 97 98 99 100 \\n36 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 \\n1\\n\", \"7\\n50 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 \\n50 3 4 7 8 11 12 15 16 19 20 23 24 27 28 31 32 35 36 39 40 43 44 47 48 51 52 55 56 59 60 63 64 67 68 71 72 75 76 79 80 83 84 87 88 91 92 95 96 99 100 \\n48 5 6 7 8 13 14 15 16 21 22 23 24 29 30 31 32 37 38 39 40 45 46 47 48 53 54 55 56 61 62 63 64 69 70 71 72 77 78 79 80 85 86 87 88 93 94 95 96 \\n48 9 10 11 12 13 14 15 16 25 26 27 28 29 30 31 32 41 42 43 44 45 46 47 48 57 58 59 60 61 62 63 64 73 74 75 76 77 78 79 80 89 90 91 92 93 94 95 96 \\n48 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 \\n36 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 97 98 99 100 \\n36 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 \\n2\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).
There are N bottles of juice, numbered 1 to N. It has been discovered that exactly one of these bottles has gone bad. Even a small sip of the spoiled juice will cause stomach upset the next day.
Takahashi must identify the spoiled juice by the next day. To do this, he decides to call the minimum necessary number of friends and serve them some of the N bottles of juice. He can give any number of bottles to each friend, and each bottle of juice can be given to any number of friends.
Print the number of friends to call and how to distribute the juice, then receive information on whether each friend has an upset stomach the next day, and print the spoiled bottle's number.
Input/Output
This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).
Before the interaction, the judge secretly selects an integer X between 1 and N as the spoiled bottle's number. The value of X is not given to you. Also, the value of X may change during the interaction as long as it is consistent with the constraints and previous outputs.
First, the judge will give you N as input.
N
You should print the number of friends to call, M, followed by a newline.
M
Next, you should perform the following procedure to print M outputs.
For i = 1, 2, \ldots, M, the i-th output should contain the number K_i of bottles of juice you will serve to the i-th friend, and the K_i bottles' numbers in ascending order, A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i}, separated by spaces, followed by a newline.
K_i A_{i, 1} A_{i, 2} \ldots A_{i, K_i}
Then, the judge will inform you whether each friend has a stomach upset the next day by giving you a string S of length M consisting of 0 and 1.
S
For i = 1, 2, \ldots, M, the i-th friend has a stomach upset if and only if the i-th character of S is 1.
You should respond by printing the number of the spoiled juice bottle X', followed by a newline.
X'
Then, terminate the program immediately.
If the M you printed is the minimum necessary number of friends to identify the spoiled juice out of the N bottles, and the X' you printed matches the spoiled bottle's number X, then your program is considered correct.
Input/Output
This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).
Before the interaction, the judge secretly selects an integer X between 1 and N as the spoiled bottle's number. The value of X is not given to you. Also, the value of X may change during the interaction as long as it is consistent with the constraints and previous outputs.
First, the judge will give you N as input.
N
You should print the number of friends to call, M, followed by a newline.
M
Next, you should perform the following procedure to print M outputs.
For i = 1, 2, \ldots, M, the i-th output should contain the number K_i of bottles of juice you will serve to the i-th friend, and the K_i bottles' numbers in ascending order, A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i}, separated by spaces, followed by a newline.
K_i A_{i, 1} A_{i, 2} \ldots A_{i, K_i}
Then, the judge will inform you whether each friend has a stomach upset the next day by giving you a string S of length M consisting of 0 and 1.
S
For i = 1, 2, \ldots, M, the i-th friend has a stomach upset if and only if the i-th character of S is 1.
You should respond by printing the number of the spoiled juice bottle X', followed by a newline.
X'
Then, terminate the program immediately.
If the M you printed is the minimum necessary number of friends to identify the spoiled juice out of the N bottles, and the X' you printed matches the spoiled bottle's number X, then your program is considered correct.
Constraints
- N is an integer.
- 2 \leq N \leq 100
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 4\\n1 2 5\\n2 1 -3\\n2 3 -4\\n3 1 100\\n\", \"3 2\\n1 2 0\\n2 1 0\\n\", \"5 9\\n1 2 -246288\\n4 5 -222742\\n3 1 246288\\n3 4 947824\\n5 2 -178721\\n4 3 -947824\\n5 4 756570\\n2 5 707902\\n5 1 36781\\n\", \"2 1\\n2 1 0\\n\", \"6 8\\n1 5 -4\\n2 1 -803\\n3 1 -1595\\n3 4 -5960\\n3 5 -1599\\n5 2 863633\\n2 3 -862034\\n2 4 -94503\\n\", \"20 19\\n5 2 1000000\\n1 12 1000000\\n10 14 1000000\\n3 7 1000000\\n7 17 1000000\\n13 11 1000000\\n17 1 1000000\\n8 19 1000000\\n12 4 1000000\\n2 20 1000000\\n16 13 1000000\\n4 10 1000000\\n11 6 1000000\\n20 9 1000000\\n19 15 1000000\\n14 18 1000000\\n9 3 1000000\\n18 8 1000000\\n6 5 1000000\\n\", \"20 19\\n4 19 -1000000\\n16 17 -1000000\\n1 20 -1000000\\n5 1 -1000000\\n7 10 -1000000\\n19 9 -1000000\\n10 18 -1000000\\n6 12 -1000000\\n11 2 -1000000\\n14 13 -1000000\\n15 5 -1000000\\n12 11 -1000000\\n2 16 -1000000\\n18 4 -1000000\\n3 8 -1000000\\n8 7 -1000000\\n13 3 -1000000\\n9 6 -1000000\\n17 15 -1000000\\n\", \"20 35\\n2 5 56298\\n1 3 -5979\\n12 13 -26500\\n1 15 -92762\\n12 5 -151519\\n18 10 -379\\n2 20 -814\\n8 5 445536\\n4 9 86028\\n5 2 -56298\\n10 14 -86028\\n17 10 86028\\n17 4 0\\n11 3 -276\\n5 20 -243551\\n2 15 -140\\n5 11 -7\\n20 5 243551\\n14 17 0\\n6 1 -1\\n9 14 -196\\n11 17 -169\\n14 15 0\\n15 3 20362\\n3 16 497204\\n3 9 -19890\\n8 19 -2911\\n6 9 -102767\\n19 4 -341\\n1 4 -9412\\n6 19 -326\\n16 3 -174459\\n5 8 -445536\\n13 4 -3506\\n7 12 -3091\\n\", \"20 38\\n5 18 585530\\n15 16 701301\\n16 20 432683\\n19 9 679503\\n9 1 -138951\\n11 15 455543\\n15 12 -619560\\n5 8 638549\\n16 10 326741\\n13 2 -145022\\n9 5 69552\\n4 3 -898380\\n15 11 -331111\\n13 9 -142793\\n8 5 -327527\\n9 17 -57231\\n4 8 681970\\n12 15 716887\\n9 19 -10446\\n4 6 645112\\n14 8 711527\\n5 9 -61467\\n16 15 -43333\\n8 20 456620\\n6 4 26742\\n12 7 793084\\n9 13 648469\\n8 14 121457\\n1 9 548488\\n7 12 -55460\\n20 16 662039\\n3 4 985310\\n8 4 471060\\n17 9 590861\\n18 5 58422\\n10 16 61811\\n20 8 39294\\n2 13 181323\\n\", \"20 38\\n2 11 447719\\n1 19 954933\\n8 15 -424553\\n18 15 552542\\n15 19 -667745\\n4 6 673083\\n2 14 699336\\n17 8 233989\\n15 18 -112865\\n3 4 791729\\n12 13 -193357\\n4 12 588867\\n19 15 849244\\n2 9 602174\\n15 6 855173\\n19 1 -8841\\n9 2 -302315\\n6 20 500136\\n6 15 -396427\\n10 8 931923\\n13 12 865090\\n12 16 462477\\n2 12 451903\\n16 5 -702090\\n14 2 -688608\\n4 3 10689\\n16 12 774469\\n20 6 299194\\n12 4 -181784\\n6 4 447472\\n8 10 -724890\\n15 8 605833\\n5 16 973255\\n4 7 951348\\n11 2 -273026\\n7 4 916821\\n12 2 -304230\\n8 17 939233\\n\", \"20 38\\n12 16 -303463\\n5 8 -511686\\n12 2 -339099\\n1 4 469940\\n19 15 967952\\n9 14 635045\\n2 12 781120\\n5 4 -636174\\n4 1 865062\\n1 3 823767\\n16 12 913518\\n17 6 967168\\n3 9 -14139\\n8 5 703131\\n5 19 429992\\n14 9 -600129\\n19 13 294059\\n3 1 -450235\\n6 17 447807\\n20 11 -139613\\n15 19 622889\\n9 3 115321\\n2 18 798341\\n5 18 38979\\n19 6 -206008\\n2 20 407070\\n18 5 398053\\n20 2 -202724\\n18 7 -373855\\n13 19 382318\\n18 2 -119735\\n11 20 481296\\n20 10 699206\\n7 18 405603\\n4 5 902553\\n10 20 -69724\\n6 19 390982\\n19 5 -81181\\n\", \"20 374\\n1 4 650604\\n8 19 -1181\\n1 3 645979\\n8 9 374112\\n18 12 -377137\\n14 2 376250\\n9 4 -2\\n3 16 922\\n14 16 -68\\n11 20 4728\\n20 3 254455\\n1 10 650604\\n3 2 626680\\n19 14 249513\\n9 1 372523\\n15 6 4625\\n14 8 2138\\n15 16 -49\\n18 11 0\\n15 19 377137\\n12 16 -285\\n17 1 0\\n12 19 624513\\n7 15 376264\\n9 7 372523\\n13 16 -9988\\n13 19 -206\\n8 6 374112\\n19 15 625763\\n17 3 -298\\n17 4 372749\\n5 20 377137\\n7 8 376264\\n10 4 625758\\n8 18 374112\\n13 9 375436\\n13 1 -4978\\n15 12 4625\\n11 9 4717\\n12 4 248519\\n14 7 -14\\n14 4 3738\\n18 4 0\\n18 16 -1068\\n18 9 -372523\\n18 2 0\\n8 4 1600\\n20 17 626978\\n16 2 253009\\n13 14 375436\\n10 11 625758\\n16 4 253246\\n1 12 650604\\n18 1 0\\n10 6 253246\\n3 17 626680\\n10 15 625758\\n19 13 625763\\n20 6 626978\\n11 6 4728\\n7 10 -2800\\n18 15 -3\\n15 1 377137\\n7 16 -249494\\n6 14 -5\\n12 9 624513\\n4 6 375994\\n2 20 625911\\n7 19 3741\\n10 5 248621\\n15 2 377137\\n16 13 625758\\n20 13 254455\\n7 13 828\\n7 11 376264\\n17 9 226\\n2 17 253399\\n11 15 103\\n11 10 -24\\n19 17 253240\\n5 7 377137\\n6 18 372512\\n19 7 250327\\n5 4 3025\\n4 19 3482\\n4 12 -2920\\n13 15 -156\\n7 17 376264\\n14 1 376250\\n16 3 625758\\n10 2 -153\\n8 11 374112\\n5 19 -144\\n1 5 645979\\n7 20 3752\\n2 5 253388\\n11 4 4491\\n12 14 624513\\n11 19 4717\\n10 19 -5\\n2 19 253399\\n13 8 375436\\n8 14 374112\\n12 6 624513\\n2 12 625911\\n17 6 237\\n4 8 3482\\n20 19 249841\\n3 1 626680\\n19 20 248523\\n4 7 3471\\n20 16 1220\\n13 10 375436\\n13 17 2924\\n6 8 -2\\n13 2 -69\\n14 5 3738\\n5 10 377137\\n3 5 252568\\n1 16 397358\\n15 3 -2318\\n19 4 625763\\n4 10 -37\\n19 5 248626\\n19 2 625763\\n2 3 -769\\n19 9 625763\\n6 20 372512\\n16 9 253235\\n2 11 250475\\n9 8 -1589\\n17 12 372749\\n10 7 251646\\n3 20 -298\\n9 2 372523\\n1 9 650593\\n17 14 372749\\n8 15 -810\\n2 8 251799\\n13 11 -1804\\n16 12 1245\\n2 13 253388\\n11 16 -9030\\n8 10 374112\\n11 17 4728\\n17 13 -892\\n14 10 3727\\n7 12 -248249\\n4 3 3471\\n1 13 647680\\n4 20 1882\\n4 17 375994\\n14 12 376250\\n11 8 3128\\n5 13 4625\\n3 14 250430\\n15 13 377137\\n12 11 247273\\n5 3 377137\\n13 6 2924\\n8 3 -1324\\n8 12 -6\\n17 2 372749\\n6 15 372512\\n16 15 253246\\n12 2 624513\\n5 6 377137\\n13 18 375436\\n11 5 103\\n5 9 4614\\n17 19 372749\\n5 2 -2\\n5 17 4625\\n7 4 376264\\n19 16 5\\n18 3 0\\n4 2 3471\\n12 18 624513\\n9 3 372523\\n16 6 253246\\n6 19 -9\\n8 5 -3025\\n3 9 254157\\n10 12 248621\\n6 17 -237\\n14 20 376250\\n20 12 626978\\n13 4 -558\\n20 14 254466\\n9 20 0\\n20 18 626978\\n20 8 254455\\n9 16 -4\\n3 10 922\\n4 13 558\\n14 18 376250\\n4 15 375994\\n13 7 -89\\n17 5 372749\\n12 1 251990\\n18 14 -7146\\n15 8 377137\\n16 19 0\\n12 8 624513\\n1 6 650604\\n10 17 253009\\n5 14 4625\\n14 15 376250\\n4 14 -256\\n8 16 -20010\\n19 6 625763\\n12 13 249077\\n4 18 375994\\n20 11 254455\\n10 3 253246\\n4 9 375994\\n16 5 249508\\n6 13 0\\n12 17 624513\\n10 14 625758\\n12 5 624513\\n9 10 -173003\\n9 5 -1643\\n3 18 626680\\n9 18 372523\\n3 15 249543\\n2 6 253399\\n16 11 625758\\n20 7 626978\\n6 10 372512\\n18 6 -209014\\n16 1 253235\\n1 15 645979\\n7 14 14\\n6 7 -2924\\n6 9 -11\\n15 11 -103\\n9 19 -337\\n14 19 376250\\n20 2 254466\\n19 8 625763\\n10 9 625758\\n8 2 374112\\n3 4 254168\\n12 7 248249\\n15 7 2410\\n4 16 -112\\n2 16 153\\n19 12 625763\\n5 1 4614\\n16 10 0\\n13 5 375436\\n8 7 -2152\\n17 20 372749\\n7 6 3752\\n5 18 377137\\n18 17 0\\n15 9 377137\\n12 10 -1245\\n17 8 372749\\n3 13 251244\\n10 20 253235\\n5 16 -111\\n9 12 372523\\n9 13 -2913\\n5 15 4614\\n9 11 0\\n8 17 374112\\n20 9 626978\\n4 1 -21\\n10 1 -397358\\n18 7 0\\n11 7 377240\\n15 17 377137\\n18 10 0\\n5 11 377137\\n16 8 251646\\n11 18 377240\\n4 11 3482\\n19 3 -917\\n5 12 4625\\n20 15 254229\\n15 18 377137\\n19 10 253240\\n6 4 0\\n13 20 -814\\n11 13 377240\\n17 18 372749\\n1 14 646866\\n4 5 -405\\n11 12 377240\\n14 17 3501\\n6 5 -11\\n2 9 253399\\n6 3 372512\\n14 9 3727\\n9 15 -111\\n13 12 375436\\n8 1 1600\\n17 11 372749\\n7 18 376264\\n9 6 11\\n15 14 377137\\n17 7 372749\\n15 5 4614\\n2 4 625911\\n2 18 625911\\n17 15 372749\\n7 3 376264\\n20 4 626978\\n6 1 -253246\\n10 13 253246\\n20 5 626978\\n14 13 3727\\n14 3 0\\n11 2 -37\\n19 11 625763\\n8 13 -1324\\n7 5 -229\\n17 10 372749\\n10 16 0\\n18 13 -375436\\n2 7 253388\\n19 18 625763\\n11 3 0\\n3 12 626680\\n12 15 624513\\n3 6 254168\\n11 14 4717\\n16 7 625758\\n18 8 -1\\n2 15 248774\\n7 9 376264\\n18 19 -83\\n20 10 1220\\n2 1 251799\\n7 2 3752\\n6 12 -219\\n13 3 375436\\n8 20 -1\\n1 20 650604\\n16 18 625758\\n10 18 625758\\n2 14 249661\\n3 8 254168\\n15 10 377137\\n9 17 0\\n5 8 377137\\n6 2 372512\\n11 1 377240\\n16 17 625758\\n3 19 922\\n6 16 -89\\n1 11 645876\\n15 20 -17\\n7 1 3741\\n16 14 625758\\n3 7 254168\\n14 11 376250\\n3 11 626680\\n18 20 -2\\n6 11 -101\\n18 5 -3407\\n16 20 625758\\n20 1 254466\\n2 10 253388\\n15 4 1480\\n9 14 -3727\\n17 16 -66\\n12 20 252001\\n19 1 625763\\n12 3 624513\\n10 8 625758\\n14 6 376250\\n\", \"20 380\\n7 15 -1477\\n16 5 755272\\n2 12 322329\\n16 13 755272\\n3 14 789625\\n5 17 -26\\n1 5 979038\\n12 1 258265\\n20 2 148009\\n16 15 -25582\\n17 7 322329\\n16 3 0\\n8 18 786658\\n1 17 192381\\n3 15 789625\\n15 7 322329\\n20 11 -100354\\n20 16 148009\\n8 19 -2966\\n13 14 979177\\n16 8 755272\\n4 10 42832\\n13 10 255789\\n2 11 786657\\n8 3 322330\\n13 12 514849\\n15 20 174320\\n3 9 325297\\n20 8 148009\\n2 7 322329\\n3 20 789625\\n13 8 979177\\n7 8 -565\\n15 10 31385\\n10 4 785372\\n11 10 743825\\n13 6 979177\\n9 10 723388\\n18 8 0\\n17 10 786657\\n9 14 723388\\n5 4 -67\\n17 6 786657\\n20 6 148009\\n4 16 322329\\n12 2 -192\\n1 19 514710\\n9 1 -4\\n20 4 148009\\n4 14 786657\\n13 15 256584\\n3 10 789625\\n10 11 785372\\n8 11 322330\\n4 17 0\\n18 20 0\\n12 7 258265\\n2 15 42832\\n9 20 259060\\n14 3 142438\\n12 20 110256\\n1 2 192381\\n4 8 786657\\n4 1 0\\n18 1 0\\n20 10 612337\\n5 12 63834\\n5 2 322099\\n6 11 786657\\n8 9 322330\\n15 9 63269\\n2 16 322329\\n8 7 322330\\n18 17 -445\\n14 9 63269\\n12 18 722593\\n2 17 0\\n19 20 789624\\n10 5 -1055\\n19 15 789624\\n11 2 743825\\n13 2 979177\\n6 13 0\\n11 12 743825\\n11 19 -33\\n2 18 786657\\n18 13 0\\n4 20 786657\\n3 11 45800\\n3 18 789625\\n19 1 -189414\\n9 13 723388\\n3 17 2968\\n18 4 -44\\n4 15 786657\\n7 4 -20\\n14 15 322329\\n13 9 979177\\n19 7 789624\\n6 10 786657\\n2 13 322329\\n9 11 259060\\n17 14 0\\n1 18 979038\\n18 19 -11863\\n14 17 0\\n12 14 722593\\n8 5 231\\n18 6 -18437\\n3 1 -104406\\n7 13 -23117\\n1 12 514710\\n8 4 142439\\n14 20 786657\\n8 17 1\\n12 19 258265\\n9 12 259060\\n7 14 0\\n1 10 235213\\n7 11 -10384\\n19 13 34352\\n16 11 290944\\n13 1 979177\\n18 15 0\\n9 3 -42\\n16 17 -31385\\n14 4 786657\\n18 9 -199\\n10 16 290948\\n1 3 979038\\n14 16 322329\\n16 4 290944\\n5 7 322099\\n11 13 -50113\\n17 1 31385\\n19 2 325296\\n14 12 322329\\n7 18 464328\\n6 4 31385\\n6 15 786657\\n9 4 723388\\n3 13 325297\\n17 11 322329\\n11 17 -9800\\n3 8 325297\\n20 17 -96\\n19 3 -1\\n10 8 785372\\n2 6 322329\\n16 14 290944\\n16 20 755272\\n16 10 -4\\n7 3 -200\\n2 5 230\\n17 9 322329\\n8 6 42833\\n15 17 0\\n13 3 334958\\n7 17 -14325\\n10 13 173035\\n17 3 786657\\n13 4 514849\\n11 4 743825\\n17 13 322329\\n11 3 -38\\n15 16 31385\\n13 19 979177\\n2 9 786657\\n3 7 789625\\n2 3 0\\n11 1 279497\\n19 10 145405\\n18 16 -755272\\n9 6 -17\\n20 1 -1688\\n5 18 786427\\n14 1 -2057\\n3 4 325297\\n16 12 755272\\n5 6 786427\\n7 12 464328\\n19 14 325296\\n2 10 786657\\n4 12 786657\\n7 20 0\\n2 8 0\\n18 7 -1176\\n5 11 322099\\n1 15 192381\\n14 19 786657\\n19 8 325296\\n10 15 -1\\n15 11 322329\\n13 16 514849\\n6 19 42832\\n9 15 259060\\n4 9 322329\\n19 17 2967\\n15 19 786657\\n13 18 979177\\n7 6 464328\\n16 7 290944\\n8 20 322330\\n18 2 -65\\n9 18 723388\\n6 2 322329\\n15 1 322329\\n17 20 786657\\n3 16 789625\\n6 3 42832\\n7 2 -32203\\n17 4 0\\n2 14 322329\\n19 11 789624\\n2 19 0\\n7 19 -796\\n7 9 0\\n5 10 31155\\n10 17 -3\\n4 2 0\\n19 6 789624\\n17 5 786657\\n3 2 325297\\n1 11 514710\\n17 19 322329\\n15 18 786657\\n8 16 322330\\n1 13 -139\\n8 15 322330\\n8 2 786658\\n14 18 786657\\n10 9 785372\\n12 4 258265\\n7 5 -3830\\n16 9 755272\\n9 17 -1353\\n7 16 -290944\\n15 3 786657\\n10 6 785372\\n4 11 42832\\n14 6 0\\n11 6 743825\\n4 6 322329\\n20 9 612337\\n5 19 786427\\n13 20 979177\\n4 18 786657\\n9 16 -2\\n17 12 786657\\n12 5 258265\\n16 18 755272\\n8 13 1\\n6 14 786657\\n20 7 148009\\n20 18 612337\\n4 13 786657\\n5 20 322099\\n16 6 290944\\n20 19 -4209\\n18 11 -3302\\n17 2 0\\n5 16 63834\\n7 1 -181285\\n3 5 325297\\n1 6 192381\\n5 3 786427\\n9 5 -1036\\n10 14 -1285\\n2 4 786657\\n10 3 61984\\n12 8 258265\\n15 14 322329\\n15 4 322329\\n13 17 192520\\n2 1 322329\\n20 14 -174320\\n14 8 -1\\n10 2 785372\\n17 15 322329\\n5 9 786427\\n18 5 -2\\n5 1 -9\\n18 12 -722593\\n20 12 -2\\n14 10 1285\\n1 7 514710\\n10 12 785372\\n6 9 63269\\n15 6 42832\\n17 8 786657\\n19 16 789624\\n8 1 786658\\n11 16 -11447\\n10 20 321044\\n12 10 722593\\n14 2 174320\\n20 3 -7163\\n8 14 63270\\n11 9 131488\\n10 1 785372\\n10 18 785372\\n6 20 174320\\n12 16 258265\\n9 19 -66236\\n16 19 -6620\\n6 1 -540\\n12 3 258265\\n1 14 192381\\n14 13 786657\\n8 10 1286\\n10 19 -780\\n1 9 255650\\n4 19 142438\\n15 12 64064\\n1 4 979038\\n18 10 -751\\n19 9 325296\\n19 12 789624\\n6 16 31385\\n6 12 64064\\n12 11 722593\\n20 5 612337\\n11 20 743825\\n5 8 786427\\n15 2 786657\\n6 17 0\\n15 8 0\\n10 7 785372\\n9 7 723388\\n13 5 514849\\n6 5 230\\n4 5 230\\n11 14 131488\\n17 18 786657\\n3 6 45800\\n1 20 514710\\n12 17 -20\\n20 15 612337\\n13 7 979177\\n18 14 0\\n11 18 743825\\n16 1 -31385\\n3 19 789625\\n20 13 -5157\\n7 10 0\\n11 5 743825\\n12 9 -795\\n5 15 786427\\n14 7 322329\\n1 8 514710\\n2 20 786657\\n15 13 142438\\n17 16 786657\\n15 5 230\\n6 7 322329\\n16 2 11447\\n11 15 279497\\n8 12 64065\\n19 4 325296\\n12 13 258265\\n19 18 789624\\n12 6 -14317\\n18 3 0\\n1 16 514710\\n19 5 789624\\n13 11 979177\\n12 15 722593\\n4 7 322329\\n9 8 723388\\n6 18 786657\\n14 11 322329\\n5 13 786427\\n14 5 786657\\n4 3 322329\\n5 14 -230\\n11 8 21232\\n9 2 723388\\n3 12 789625\\n6 8 142438\\n11 7 279497\\n\", \"20 380\\n12 11 886655\\n13 2 886651\\n17 3 886650\\n12 13 886637\\n17 11 886654\\n17 16 886643\\n18 5 886650\\n8 19 886653\\n10 2 886656\\n13 1 886639\\n13 14 886645\\n5 14 886653\\n1 20 886652\\n14 15 886650\\n20 8 886650\\n15 3 886639\\n9 18 886655\\n16 5 886651\\n18 17 886656\\n9 3 886644\\n2 11 886644\\n14 12 886644\\n19 10 886655\\n3 20 886655\\n10 14 886640\\n20 10 886656\\n13 4 886642\\n17 6 886651\\n12 5 886647\\n20 17 886646\\n13 10 886655\\n8 18 886654\\n5 1 886644\\n14 8 886648\\n14 7 886643\\n6 14 886636\\n7 1 886640\\n19 11 886648\\n16 9 886648\\n7 14 886641\\n9 10 886653\\n10 12 886655\\n6 8 886655\\n11 8 886638\\n7 12 886643\\n4 8 886641\\n12 6 886651\\n14 10 886649\\n11 14 886652\\n16 6 886653\\n17 8 886656\\n5 4 886641\\n2 17 886647\\n14 9 886653\\n2 20 886640\\n2 5 886637\\n17 5 886650\\n17 13 886638\\n11 16 886639\\n20 19 886655\\n10 16 886655\\n4 2 886649\\n13 20 886653\\n4 1 886649\\n4 13 886647\\n8 3 886636\\n8 1 886651\\n9 8 886655\\n14 17 886653\\n4 6 886648\\n17 9 886647\\n16 3 886641\\n4 14 886651\\n1 18 886642\\n6 7 886652\\n12 8 886652\\n13 9 886654\\n18 10 886642\\n9 6 886640\\n4 7 886640\\n1 2 886649\\n3 4 886652\\n19 5 886642\\n12 14 886655\\n6 5 886643\\n18 9 886637\\n7 9 886650\\n13 19 886652\\n4 5 886641\\n16 14 886646\\n9 1 886650\\n1 3 886652\\n5 10 886656\\n6 12 886643\\n10 15 886653\\n3 5 886654\\n18 6 886647\\n19 4 886649\\n12 19 886651\\n15 6 886644\\n15 18 886650\\n10 4 886643\\n11 5 886646\\n3 7 886655\\n14 6 886656\\n18 3 886649\\n1 9 886637\\n5 13 886648\\n15 19 886650\\n13 18 886654\\n15 9 886649\\n11 18 886652\\n17 20 886638\\n11 10 886646\\n6 11 886651\\n15 1 886648\\n8 4 886636\\n10 3 886656\\n10 5 886652\\n15 11 886638\\n11 6 886650\\n16 10 886654\\n8 9 886643\\n2 4 886641\\n17 2 886637\\n11 1 886646\\n6 20 886644\\n8 6 886652\\n19 12 886652\\n3 15 886644\\n19 9 886655\\n8 20 886652\\n17 4 886648\\n14 16 886649\\n16 18 886650\\n9 14 886639\\n14 1 886637\\n2 18 886640\\n17 1 886649\\n15 7 886655\\n3 19 886636\\n5 11 886648\\n12 9 886637\\n2 12 886654\\n12 7 886649\\n2 3 886637\\n15 12 886650\\n8 7 886636\\n3 11 886649\\n12 20 886638\\n10 9 886654\\n15 2 886656\\n18 13 886641\\n14 3 886655\\n12 15 886647\\n20 4 886653\\n1 4 886647\\n11 15 886640\\n15 5 886638\\n20 5 886643\\n18 14 886648\\n11 17 886648\\n9 2 886655\\n11 12 886639\\n11 13 886651\\n17 18 886649\\n3 8 886650\\n3 17 886656\\n11 9 886654\\n2 15 886637\\n19 16 886637\\n15 10 886640\\n14 19 886648\\n3 9 886643\\n2 1 886638\\n10 8 886653\\n3 1 886655\\n13 7 886654\\n6 10 886652\\n19 18 886636\\n12 18 886637\\n7 20 886636\\n16 2 886643\\n14 5 886649\\n16 8 886651\\n12 10 886646\\n15 16 886652\\n12 17 886641\\n7 4 886647\\n1 10 886638\\n12 16 886654\\n5 17 886646\\n9 19 886656\\n16 13 886636\\n17 14 886655\\n1 13 886637\\n2 10 886652\\n1 16 886656\\n14 13 886646\\n13 8 886648\\n11 2 886639\\n16 1 886644\\n13 3 886654\\n2 19 886639\\n2 16 886647\\n6 18 886645\\n1 17 886644\\n4 12 886641\\n18 1 886648\\n16 19 886653\\n11 3 886640\\n14 18 886648\\n8 16 886640\\n10 18 886640\\n16 17 886650\\n20 16 886636\\n3 6 886639\\n10 13 886654\\n9 20 886649\\n7 17 886654\\n10 19 886644\\n15 17 886646\\n7 19 886640\\n6 15 886653\\n18 2 886652\\n5 6 886642\\n15 13 886648\\n4 15 886646\\n10 20 886636\\n3 18 886646\\n14 11 886652\\n16 11 886651\\n12 2 886639\\n18 19 886639\\n2 7 886640\\n16 12 886653\\n20 3 886642\\n16 15 886638\\n1 5 886651\\n7 10 886639\\n2 14 886655\\n13 6 886637\\n19 13 886637\\n6 1 886651\\n13 15 886645\\n5 16 886646\\n13 17 886653\\n14 2 886649\\n6 17 886644\\n20 9 886648\\n9 16 886642\\n1 11 886642\\n9 17 886649\\n4 16 886643\\n7 6 886639\\n5 12 886646\\n19 2 886637\\n5 9 886645\\n16 20 886644\\n5 3 886655\\n11 19 886636\\n19 15 886638\\n19 14 886637\\n17 15 886639\\n9 4 886644\\n9 15 886649\\n19 17 886643\\n8 10 886650\\n8 11 886645\\n3 14 886652\\n18 15 886654\\n5 20 886645\\n6 3 886640\\n3 13 886641\\n12 3 886641\\n20 7 886646\\n9 13 886642\\n19 7 886652\\n20 15 886656\\n12 4 886645\\n14 4 886643\\n13 16 886650\\n4 17 886650\\n12 1 886653\\n17 10 886637\\n15 8 886640\\n7 3 886640\\n11 20 886636\\n18 11 886644\\n5 15 886638\\n19 1 886639\\n9 11 886640\\n1 15 886643\\n11 7 886648\\n15 14 886639\\n8 14 886639\\n20 18 886641\\n8 15 886647\\n6 4 886651\\n5 2 886638\\n18 16 886646\\n5 7 886647\\n9 12 886652\\n9 7 886637\\n4 18 886644\\n8 5 886652\\n18 4 886648\\n3 16 886641\\n1 19 886648\\n5 18 886653\\n9 5 886646\\n1 8 886655\\n6 9 886654\\n10 7 886638\\n16 4 886653\\n18 7 886645\\n20 6 886654\\n8 12 886647\\n11 4 886637\\n14 20 886653\\n7 16 886641\\n5 8 886649\\n20 12 886656\\n7 11 886646\\n16 7 886651\\n7 13 886639\\n4 10 886647\\n8 13 886648\\n13 12 886645\\n8 2 886653\\n17 12 886644\\n20 13 886652\\n4 9 886645\\n10 1 886646\\n3 10 886650\\n7 5 886644\\n10 6 886638\\n10 11 886649\\n20 14 886650\\n18 20 886646\\n20 1 886653\\n4 11 886640\\n4 3 886655\\n2 6 886638\\n10 17 886651\\n13 5 886655\\n13 11 886653\\n6 13 886653\\n4 20 886652\\n19 8 886652\\n1 14 886650\\n20 11 886653\\n8 17 886641\\n7 2 886642\\n1 12 886656\\n2 9 886641\\n2 8 886639\\n1 6 886656\\n19 6 886639\\n17 7 886651\\n4 19 886655\\n7 15 886647\\n15 4 886642\\n20 2 886643\\n3 12 886641\\n6 19 886643\\n19 3 886642\\n7 8 886646\\n3 2 886643\\n17 19 886642\\n1 7 886644\\n6 16 886642\\n7 18 886647\\n5 19 886644\\n2 13 886640\\n18 12 886652\\n15 20 886637\\n18 8 886637\\n19 20 886639\\n6 2 886656\\n\", \"20 380\\n10 20 954882\\n11 18 954885\\n10 6 954887\\n17 19 954888\\n2 12 954876\\n1 18 954892\\n13 18 954891\\n14 16 954884\\n20 4 954884\\n6 13 954885\\n8 7 954880\\n5 17 954875\\n17 13 954888\\n6 10 954890\\n9 17 954888\\n2 16 954881\\n19 13 954876\\n17 15 954889\\n1 15 954876\\n13 3 954873\\n15 19 954880\\n13 6 954886\\n11 3 954888\\n13 7 954874\\n12 2 954875\\n16 12 954878\\n12 15 954887\\n16 20 954875\\n19 3 954889\\n11 20 954874\\n18 11 954892\\n4 2 954882\\n14 15 954887\\n15 5 954881\\n17 10 954876\\n20 11 954891\\n12 17 954887\\n20 6 954886\\n10 16 954877\\n20 15 954874\\n18 16 954883\\n4 18 954889\\n10 2 954891\\n18 13 954892\\n1 12 954887\\n6 14 954884\\n9 2 954885\\n14 17 954880\\n16 17 954890\\n7 13 954888\\n18 4 954890\\n2 10 954883\\n12 11 954875\\n15 3 954887\\n19 9 954880\\n17 20 954879\\n7 16 954885\\n19 5 954874\\n6 11 954876\\n16 1 954882\\n6 12 954879\\n10 15 954878\\n11 16 954873\\n11 1 954878\\n12 1 954881\\n10 14 954890\\n17 6 954877\\n20 13 954889\\n19 15 954874\\n15 16 954889\\n16 4 954885\\n8 17 954885\\n10 3 954891\\n3 15 954882\\n14 11 954878\\n20 7 954878\\n17 9 954872\\n3 18 954887\\n14 20 954882\\n13 16 954880\\n2 17 954884\\n18 15 954886\\n5 6 954885\\n15 9 954883\\n7 8 954890\\n5 15 954873\\n7 20 954886\\n18 10 954878\\n3 20 954887\\n7 5 954883\\n16 2 954889\\n2 7 954873\\n5 3 954883\\n20 18 954889\\n9 10 954884\\n4 20 954880\\n3 9 954882\\n15 10 954889\\n15 1 954882\\n13 20 954876\\n20 5 954885\\n18 5 954880\\n1 4 954885\\n10 5 954872\\n17 8 954872\\n8 6 954880\\n7 3 954875\\n14 13 954876\\n5 13 954876\\n2 6 954887\\n17 3 954873\\n18 12 954877\\n19 20 954888\\n16 6 954881\\n4 3 954890\\n18 20 954874\\n2 9 954878\\n10 1 954881\\n17 14 954887\\n5 4 954890\\n10 4 954883\\n1 2 954874\\n4 13 954876\\n3 16 954891\\n13 19 954890\\n13 11 954877\\n8 12 954872\\n15 2 954882\\n13 17 954882\\n5 8 954892\\n12 9 954891\\n13 12 954885\\n9 18 954889\\n9 15 954879\\n4 11 954876\\n5 14 954877\\n16 7 954889\\n8 20 954885\\n15 7 954892\\n12 8 954888\\n10 7 954888\\n5 20 954886\\n2 18 954886\\n9 11 954889\\n3 12 954875\\n4 12 954884\\n6 7 954874\\n17 18 954878\\n6 9 954877\\n17 1 954874\\n12 19 954878\\n8 19 954878\\n14 4 954882\\n12 7 954877\\n2 5 954878\\n20 9 954880\\n6 20 954874\\n8 5 954874\\n13 4 954880\\n19 12 954884\\n17 5 954880\\n9 8 954886\\n6 16 954886\\n20 1 954886\\n5 18 954875\\n20 3 954874\\n9 12 954876\\n3 8 954884\\n4 1 954882\\n13 1 954889\\n7 1 954883\\n14 10 954890\\n20 19 954889\\n7 10 954879\\n2 4 954881\\n14 9 954884\\n10 13 954873\\n1 17 954881\\n14 5 954879\\n10 9 954880\\n1 13 954883\\n19 4 954878\\n9 13 954889\\n16 11 954892\\n12 6 954888\\n16 5 954878\\n1 5 954874\\n6 15 954878\\n5 2 954889\\n4 7 954873\\n19 14 954879\\n10 11 954887\\n8 4 954882\\n19 1 954874\\n3 10 954878\\n11 15 954880\\n6 1 954878\\n3 14 954886\\n6 2 954886\\n20 10 954872\\n14 18 954891\\n9 16 954873\\n11 12 954874\\n6 5 954875\\n12 18 954879\\n4 17 954878\\n16 13 954884\\n15 20 954880\\n8 13 954892\\n1 19 954891\\n17 11 954887\\n1 3 954873\\n11 7 954876\\n12 14 954890\\n20 12 954888\\n17 7 954883\\n3 5 954883\\n17 4 954887\\n20 14 954882\\n1 6 954882\\n15 12 954882\\n13 14 954891\\n3 1 954883\\n8 14 954881\\n8 10 954890\\n2 1 954889\\n2 14 954889\\n3 7 954888\\n7 4 954887\\n5 1 954876\\n2 20 954885\\n10 18 954875\\n11 5 954884\\n12 10 954885\\n3 19 954884\\n9 7 954872\\n8 3 954889\\n15 8 954875\\n5 7 954881\\n13 9 954886\\n10 17 954891\\n17 2 954884\\n11 13 954882\\n7 15 954877\\n12 13 954872\\n9 14 954891\\n8 18 954883\\n7 11 954888\\n6 18 954879\\n9 20 954879\\n18 2 954875\\n14 12 954879\\n5 19 954878\\n11 19 954874\\n7 12 954875\\n10 12 954876\\n13 15 954873\\n18 6 954885\\n13 10 954886\\n13 2 954874\\n11 2 954873\\n14 6 954883\\n14 8 954872\\n18 3 954890\\n19 8 954887\\n8 11 954883\\n18 19 954877\\n3 17 954876\\n9 1 954878\\n16 3 954878\\n20 16 954884\\n2 15 954881\\n12 3 954891\\n9 6 954873\\n11 9 954877\\n13 5 954873\\n7 6 954891\\n7 9 954880\\n1 16 954874\\n4 8 954877\\n6 3 954884\\n19 18 954891\\n11 8 954892\\n16 10 954890\\n14 19 954881\\n14 1 954881\\n19 10 954890\\n15 11 954872\\n14 7 954880\\n15 14 954889\\n1 9 954881\\n18 9 954873\\n5 10 954891\\n1 11 954883\\n8 2 954892\\n9 3 954888\\n3 6 954872\\n19 11 954873\\n1 14 954873\\n20 2 954873\\n16 18 954886\\n11 10 954874\\n3 2 954889\\n2 13 954877\\n16 9 954874\\n20 17 954879\\n7 18 954880\\n14 3 954876\\n4 15 954884\\n11 6 954886\\n3 4 954889\\n7 19 954892\\n5 11 954892\\n7 17 954891\\n11 4 954881\\n17 16 954886\\n1 7 954891\\n1 8 954873\\n18 17 954880\\n19 17 954883\\n3 11 954877\\n9 19 954878\\n12 16 954881\\n16 19 954883\\n12 4 954878\\n18 14 954891\\n19 2 954889\\n18 7 954874\\n11 17 954878\\n18 1 954889\\n15 13 954888\\n12 5 954873\\n5 12 954884\\n18 8 954875\\n4 16 954877\\n6 8 954881\\n16 14 954886\\n8 9 954876\\n6 4 954874\\n9 5 954873\\n15 4 954891\\n7 2 954883\\n6 19 954878\\n4 10 954890\\n13 8 954890\\n4 5 954883\\n15 6 954877\\n3 13 954878\\n20 8 954881\\n19 7 954872\\n10 8 954876\\n1 10 954882\\n16 8 954873\\n2 8 954881\\n4 14 954890\\n11 14 954877\\n4 19 954890\\n5 16 954890\\n4 9 954883\\n15 17 954875\\n19 6 954882\\n5 9 954875\\n8 15 954876\\n4 6 954872\\n7 14 954872\\n8 1 954883\\n12 20 954886\\n1 20 954881\\n6 17 954885\\n17 12 954875\\n2 19 954886\\n8 16 954888\\n9 4 954873\\n19 16 954885\\n10 19 954880\\n2 11 954880\\n14 2 954887\\n2 3 954883\\n15 18 954872\\n16 15 954892\\n\"], \"outputs\": [\"-2\\n\", \"No\\n\", \"-449429\\n\", \"0\\n\", \"No\\n\", \"19000000\\n\", \"-19000000\\n\", \"No\\n\", \"6345917\\n\", \"7239735\\n\", \"6449033\\n\", \"-1023116\\n\", \"-979177\\n\", \"16846104\\n\", \"18142585\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
There is a weighted simple directed graph with N vertices and M edges.
The vertices are numbered 1 to N, and the i-th edge has a weight of W_i and extends from vertex U_i to vertex V_i.
The weights can be negative, but the graph does not contain negative cycles.
Determine whether there is a walk that visits each vertex at least once. If such a walk exists, find the minimum total weight of the edges traversed.
If the same edge is traversed multiple times, the weight of that edge is added for each traversal.
Here, "a walk that visits each vertex at least once" is a sequence of vertices v_1,v_2,\dots,v_k that satisfies both of the following conditions:
- For every i (1\leq i\leq k-1), there is an edge extending from vertex v_i to vertex v_{i+1}.
- For every j\ (1\leq j\leq N), there is i (1\leq i\leq k) such that v_i=j.
Input
The input is given from Standard Input in the following format:
N M
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
Output
If there is a walk that visits each vertex at least once, print the minimum total weight of the edges traversed. Otherwise, print No.
Constraints
- 2\leq N \leq 20
- 1\leq M \leq N(N-1)
- 1\leq U_i,V_i \leq N
- U_i \neq V_i
- (U_i,V_i) \neq (U_j,V_j) for i\neq j
- -10^6\leq W_i \leq 10^6
- The given graph does not contain negative cycles.
- All input values are integers.
Sample Input 1
3 4
1 2 5
2 1 -3
2 3 -4
3 1 100
Sample Output 1
-2
By following the vertices in the order 2\rightarrow 1\rightarrow 2\rightarrow 3, you can visit all vertices at least once, and the total weight of the edges traversed is (-3)+5+(-4)=-2.
This is the minimum.
Sample Input 2
3 2
1 2 0
2 1 0
Sample Output 2
No
There is no walk that visits all vertices at least once.
Sample Input 3
5 9
1 2 -246288
4 5 -222742
3 1 246288
3 4 947824
5 2 -178721
4 3 -947824
5 4 756570
2 5 707902
5 1 36781
Sample Output 3
-449429
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 5\\n\", \"0 0\\n\", \"7 1\\n\", \"1 0\\n\", \"2 0\\n\", \"2 1\\n\", \"1 3\\n\", \"2 3\\n\", \"0 6\\n\", \"3 4\\n\", \"0 8\\n\", \"5 4\\n\"], \"outputs\": [\"2\\n\", \"9\\n\", \"4\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"0\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
You are given two integers A and B, each between 0 and 9, inclusive.
Print any integer between 0 and 9, inclusive, that is not equal to A + B.
Input
The input is given from Standard Input in the following format:
A B
Output
Print any integer between 0 and 9, inclusive, that is not equal to A + B.
Constraints
- 0 \leq A \leq 9
- 0 \leq B \leq 9
- A + B \leq 9
- A and B are integers.
Sample Input 1
2 5
Sample Output 1
2
When A = 2, B = 5, we have A + B = 7. Thus, printing any of 0, 1, 2, 3, 4, 5, 6, 8, 9 is correct.
Sample Input 2
0 0
Sample Output 2
9
Sample Input 3
7 1
Sample Output 3
4
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"840 84 7\\n\", \"343 34 3\\n\", \"0 0 0\\n\", \"951 154 495\\n\", \"744 621 910\\n\", \"866 178 386\\n\", \"1029 1029 1029\\n\", \"0 0 343\\n\", \"915 51 4\\n\", \"596 176 27\\n\", \"339 210 90\\n\", \"359 245 60\\n\", \"546 210 21\\n\", \"343 343 0\\n\"], \"outputs\": [\"Yes\\n0 0 0 0 6 0 6 0 0\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n0 0 0 0 0 0 0 0 0\\n\", \"Yes\\n0 0 0 0 3 6 6 0 6\\n\", \"Yes\\n0 0 0 0 2 3 4 4 4\\n\", \"Yes\\n0 0 0 -1 -1 4 0 1 1\\n\", \"Yes\\n0 0 0 -1 2 3 -1 2 5\\n\", \"Yes\\n0 0 0 -1 0 3 5 0 -1\\n\", \"Yes\\n0 0 0 -1 -1 7 -1 -1 7\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
In a coordinate space, we want to place three cubes with a side length of 7 so that the volumes of the regions contained in exactly one, two, three cube(s) are V_1, V_2, V_3, respectively.
For three integers a, b, c, let C(a,b,c) denote the cubic region represented by (a\leq x\leq a+7) \land (b\leq y\leq b+7) \land (c\leq z\leq c+7).
Determine whether there are nine integers a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3 that satisfy all of the following conditions, and find one such tuple if it exists.
- |a_1|, |b_1|, |c_1|, |a_2|, |b_2|, |c_2|, |a_3|, |b_3|, |c_3| \leq 100
- Let C_i = C(a_i, b_i, c_i)\ (i=1,2,3).
- The volume of the region contained in exactly one of C_1, C_2, C_3 is V_1.
- The volume of the region contained in exactly two of C_1, C_2, C_3 is V_2.
- The volume of the region contained in all of C_1, C_2, C_3 is V_3.
Input
The input is given from Standard Input in the following format:
V_1 V_2 V_3
Output
If no nine integers a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3 satisfy all of the conditions in the problem statement, print No. Otherwise, print such integers in the following format. If multiple solutions exist, you may print any of them.
Yes
a_1 b_1 c_1 a_2 b_2 c_2 a_3 b_3 c_3
Constraints
- 0 \leq V_1, V_2, V_3 \leq 3 \times 7^3
- All input values are integers.
Sample Input 1
840 84 7
Sample Output 1
Yes
0 0 0 0 6 0 6 0 0
Consider the case (a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3) = (0, 0, 0, 0, 6, 0, 6, 0, 0).
The figure represents the positional relationship of C_1, C_2, and C_3, corresponding to the orange, cyan, and green cubes, respectively.
Here,
- All of |a_1|, |b_1|, |c_1|, |a_2|, |b_2|, |c_2|, |a_3|, |b_3|, |c_3| are not greater than 100.
- The region contained in all of C_1, C_2, C_3 is (6\leq x\leq 7)\land (6\leq y\leq 7) \land (0\leq z\leq 7), with a volume of (7-6)\times(7-6)\times(7-0)=7.
- The region contained in exactly two of C_1, C_2, C_3 is ((0\leq x < 6)\land (6\leq y\leq 7) \land (0\leq z\leq 7))\lor((6\leq x\leq 7)\land (0\leq y < 6) \land (0\leq z\leq 7)), with a volume of (6-0)\times(7-6)\times(7-0)\times 2=84.
- The region contained in exactly one of C_1, C_2, C_3 has a volume of 840.
Thus, all conditions are satisfied.
(a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3) = (-10, 0, 0, -10, 0, 6, -10, 6, 1) also satisfies all conditions and would be a valid output.
Sample Input 2
343 34 3
Sample Output 2
No
No nine integers a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3 satisfy all of the conditions.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 2 10 20\\n\", \"3 2 20 20\\n\", \"314159265358979323 4 223606797 173205080\\n\", \"1000000000000000000 5 678409449 462213765\\n\", \"1000000000000000000 4 19417779 15359224\\n\", \"1000000000000000000 2 1000000000 1000000000\\n\", \"1000000000000000000 6 1000000000 1\\n\", \"1000000000000000000 2 130683535 206738146\\n\", \"1000000000000000000 6 1 1000000000\\n\", \"84324828731963982 2 270618380 428111662\\n\", \"676105575462224593 5 91212587 62144929\\n\", \"1000000000000000000 2 333504646 527596179\\n\", \"1000000000000000000 3 470762436 469875243\\n\", \"316222891501899080 6 906216946 554597231\\n\", \"1000000000000000000 6 1 1\\n\", \"1 2 2 1\\n\", \"1000000000000000000 4 403501668 319164880\\n\", \"594688604155374934 4 529780857 419050176\\n\", \"760713016476190629 5 323538049 220432874\\n\", \"1000000000000000000 6 1000000000 1000000000\\n\", \"931356503492686568 3 179340970 179002984\\n\", \"1000000000000000000 6 957841525 586191038\\n\", \"615812229161735902 4 380558657 301017246\\n\"], \"outputs\": [\"20.000000000000000\\n\", \"32.000000000000000\\n\", \"6418410657.7408381\\n\", \"17514316337.980957\\n\", \"581674678.60634942\\n\", \"38338820718.424062\\n\", \"38.444112237638366\\n\", \"7821404130.3928607\\n\", \"24.000000000000000\\n\", \"15230823973.616135\\n\", \"2331939775.4906148\\n\", \"19960239385.275657\\n\", \"17782248938.321699\\n\", \"20437022568.848955\\n\", \"24.000000000000000\\n\", \"1.2000000000000000\\n\", \"12087206958.733502\\n\", \"15673746668.153448\\n\", \"8299986920.1098969\\n\", \"24000000000.000000\\n\", \"6765346049.1048723\\n\", \"22214240820.660535\\n\", \"11268823355.662118\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
You are given an integer N. You can perform the following two types of operations:
- Pay X yen to replace N with \displaystyle\left\lfloor\frac{N}{A}\right\rfloor.
- Pay Y yen to roll a die (dice) that shows an integer between 1 and 6, inclusive, with equal probability. Let b be the outcome of the die, and replace N with \displaystyle\left\lfloor\frac{N}{b}\right\rfloor.
Here, \lfloor s \rfloor denotes the greatest integer less than or equal to s. For example, \lfloor 3 \rfloor=3 and \lfloor 2.5 \rfloor=2.
Determine the minimum expected cost paid before N becomes 0 when optimally choosing operations.
The outcome of the die in each operation is independent of other rolls, and the choice of operation can be made after observing the results of the previous operations.
Input
The input is given from Standard Input in the following format:
N A X Y
Output
Print the answer.
Your output will be considered correct if the absolute or relative error from the true answer is at most 10^{-6}.
Constraints
- 1 \leq N \leq 10^{18}
- 2 \leq A \leq 6
- 1 \leq X, Y \leq 10^9
- All input values are integers.
Sample Input 1
3 2 10 20
Sample Output 1
20.000000000000000
The available operations are as follows:
- Pay 10 yen. Replace N with \displaystyle\left\lfloor\frac{N}{2}\right\rfloor.
- Pay 20 yen. Roll a die. Let b be the outcome, and replace N with \displaystyle\left\lfloor\frac{N}{b}\right\rfloor.
The optimal strategy is to perform the first operation twice.
Sample Input 2
3 2 20 20
Sample Output 2
32.000000000000000
The available operations are as follows:
- Pay 20 yen. Replace N with \displaystyle\left\lfloor\frac{N}{2}\right\rfloor.
- Pay 20 yen. Roll a die. Let b be the outcome, and replace N with \displaystyle\left\lfloor\frac{N}{b}\right\rfloor.
The optimal strategy is as follows:
- First, perform the second operation to roll the die.
- If the outcome is 4 or greater, then N becomes 0.
- If the outcome is 2 or 3, then N becomes 1. Now, perform the first operation to make N = 0.
- If the outcome is 1, restart from the beginning.
Sample Input 3
314159265358979323 4 223606797 173205080
Sample Output 3
6418410657.7408381
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"0 0 3 3\\n\", \"-1 -2 1 3\\n\", \"-1000000000 -1000000000 1000000000 1000000000\\n\", \"593578395 -294607744 709130348 746175204\\n\", \"-678601079 -990141434 909949145 506736933\\n\", \"-420376129 -732520502 229097481 -243073819\\n\", \"-1 -1 0 0\\n\", \"-880976965 -698845539 -841240811 799247965\\n\", \"-706598544 47244307 -105634155 938741675\\n\", \"-691190744 -116861609 811710484 485546180\\n\", \"-470155176 -912361742 613356520 -773960622\\n\", \"-783899500 -317830601 -527458492 809390604\\n\", \"732193159 -597820905 914896137 -111527557\\n\", \"-929230299 -627268345 351001781 125422425\\n\", \"-770839702 -423993261 244950137 238497609\\n\", \"-61652596 28031419 688518481 862969889\\n\", \"-620080807 -705946951 512308373 -660949591\\n\", \"831487082 -595066332 976979640 562333390\\n\", \"-352155706 -373998982 -312914223 905871545\\n\", \"-306066545 -373037535 401042272 -215006244\\n\", \"-909441412 354830537 562133121 780454045\\n\", \"-115999220 -237739026 -29789995 608949093\\n\", \"-347229815 -995449898 664318316 648408554\\n\", \"-50494404 -97049623 897901965 31953859\\n\", \"167613753 -384539113 690525808 665282346\\n\", \"656514665 -507396307 664618976 668272152\\n\", \"-627922034 -560879852 -425448520 201579460\\n\", \"526190055 355420081 536853464 678001336\\n\"], \"outputs\": [\"10\\n\", \"11\\n\", \"4000000000000000000\\n\", \"120264501770105970\\n\", \"2377866465198604208\\n\", \"317882704110535631\\n\", \"0\\n\", \"59528474181343616\\n\", \"535758171500976836\\n\", \"905359405844864892\\n\", \"149959232259499520\\n\", \"289065742049174640\\n\", \"88847242861190344\\n\", \"963618870073901600\\n\", \"672951493845024495\\n\", \"626346691686101425\\n\", \"50954523592564800\\n\", \"168393045024869154\\n\", \"50224016887536278\\n\", \"111745319148977101\\n\", \"626336715231733518\\n\", \"72992326979041835\\n\", \"1662841943927223986\\n\", \"122346433981658599\\n\", \"548964295983877516\\n\", \"9527982236792520\\n\", \"154377815420203056\\n\", \"3439815696507667\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
The pattern of AtCoder's wallpaper can be represented on the xy-plane as follows:
-
The plane is divided by the following three types of lines:
-
x = n (where n is an integer)
-
y = n (where n is an even number)
-
x + y = n (where n is an even number)
-
Each region is painted black or white. Any two regions adjacent along one of these lines are painted in different colors.
-
The region containing (0.5, 0.5) is painted black.
The following figure shows a part of the pattern.
You are given integers A, B, C, D. Consider a rectangle whose sides are parallel to the x- and y-axes, with its bottom-left vertex at (A, B) and its top-right vertex at (C, D). Calculate the area of the regions painted black inside this rectangle, and print twice that area.
It can be proved that the output value will be an integer.
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print the answer on a single line.
Constraints
- -10^9 \leq A, B, C, D \leq 10^9
- A < C and B < D.
- All input values are integers.
Sample Input 1
0 0 3 3
Sample Output 1
10
We are to find the area of the black-painted region inside the following square:
The area is 5, so print twice that value: 10.
Sample Input 2
-1 -2 1 3
Sample Output 2
11
The area is 5.5, which is not an integer, but the output value is an integer.
Sample Input 3
-1000000000 -1000000000 1000000000 1000000000
Sample Output 3
4000000000000000000
This is the case with the largest rectangle, where the output still fits into a 64-bit signed integer.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"[1, 2, 3, 4]\\n3\", \"[2, 2]\\n2\", \"[4, 3, -1]\\n2\", \"[100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991]\\n10\", \"[3,369009,745365,1129173,1520619,1919958,2327340,2742999,3167043,3599574,4040745,4490808,4950051,5418543,5896347,6383565,6880464,7387122,7903764,8430489,8967414,9514824,10072869,10641870,11222115,11813976,12417723,13033512,13661502,14301930,14954877,15620388,16298655,16989921,17694516,18412806,19145004,19891263,20651886,21426927,22216536,23020893,23840205,24674739,25524606,26389845,27270591,28167033,29079246,30007425]\\n46\", \"[67108864,33554432,16777216,8388608,4194304,2097152,1048576,524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1,4782969,1594323,531441,177147,59049,19683,6561,2187,729,243,81,27,9,3,40353607,5764801,823543,117649,16807,2401,343,49,7]\\n25\", \"[13032777, 61685942, 9497687, 58215199, -19957868, -80994822, -82803055, 51532525, 96981229, 43011901, 59923753, 26537601, 67492136, -83570884, 57685185, 31499600, 36534575, -66724170, -91828854, 28165307, -49620372, 40749623, -34221492, -48337531, -38333831, -32365880, 47399424, -7774444, 55630368, -47529263, -17325682, -12090121, -64060583, 40715973, -28821797, 99809586, 91521402, 98211553, 39589417, 27678346, -49982292, -61516711, -40552442, 7715871, 81482656]\\n30\", \"[100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000, -100000000, 100000000]\\n9\", \"[0, 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]\\n9\", \"[-74734189, 46517681, 67401411, -71678642, 31014137, 99597446, 42250937, -78218996, 33342871, 25336031]\\n7\", \"[31334526, 32848186, 24863830, 94655058, 38185138, 77253119, 11724618, 85564863, -90453589, 27232706, 49150423, 92901432, 76311284, -88078583, -73879121, -28030716, 15864157, -89337929, -25628470, 34840511, -13324067, 49718941, 59912714, -37385645, -71557484, -45470977, -35517455, -18331713, -32835771, -22848607, -36728023, 29498887, 29842907, -42511374, 20749826, 26569938, 80105501, 78899304, -58310239, -95896883, -43840493, 94517504, -19407418, -20868377, -76485322, -65699788, 24699402, -42993351, 53432591, -71644687]\\n7\", \"[69621247,98882443,-76176786,6317545,-81283488,69940953,9316771,-27734967,9575160,19393030,27667783,-35415797,32430446,95633190,-60415849,20380682,-37357251,-67904335,98893803,-17116474]\\n16\", \"[74791920,83502926,82994322,64324901,55339064,92679328,89131059,83869848,8741920,461604,20929306,90864395,83783822,17289611,74314004,61266226,52491812,57881617,35565357,47377556]\\n10\", \"[28843452, -82658889, 28024895, 2020227, -27534195, 41997714, -44821600, -92218663, 38213358, 49888787, 14317456, 43022108, 83156091, 40626920, 22206172, -60693938, 96083163, -4277641, -62760313, -46808472, -89592346, 11948007, 51163, -21609887, 26552062, 17166707, -93994387, -37911505, -25992403, 47045313, -13854364, -75487140, 56845554, 72336493, -41802309, -92924713, 11471616, 77716620, -18500899, -48338519, 949085, -14969190, -16477797, -53542437, -31798720, 3230018, -35087642, -75885628, 94938466, -94805360]\\n7\", \"[87781054,87612607,52532162,89494243,7813307,8283555,48336937,11769990,96273386,9374450,72562908,68090720,64335955,11733225,69176351,61301780,27025912,25156523,38762973,96568028]\\n12\", \"[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]\\n15\", \"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\\n3\", \"[8051, -8450, 4437, -4640, 6699, -475, 6471, 7054, -191, -1856, 8884, -2660, 474, 5343, 7124, 7058, 6720, 2522, 3332, -303, 1495, -6021, 5250, -7348, -3006, 1187, -5141]\\n19\", \"[0, 2040816, 4081632, 6122448, 8163264, 10204080, 12244896, 14285712, 16326528, 18367344, 20408160, 22448976, 24489792, 26530608, 28571424, 30612240, 32653056, 34693872, 36734688, 38775504, 40816320, 42857136, 44897952, 46938768, 48979584, 51020400, 53061216, 55102032, 57142848, 59183664, 61224480, 63265296, 65306112, 67346928, 69387744, 71428560, 73469376, 75510192, 77551008, 79591824, 81632640, 83673456, 85714272, 87755088, 89795904, 91836720, 93877536, 95918352, 97959168, 99999984]\\n25\", \"[2714096, -87752299, 41870704, -88296063, 40344645, -16637822, 45597073, -94802376, 61018267, -62427155, 51605380, -23940335, 22584376, -15418177, 78100999, -19071090, 15637477, -6668203, 54029038, -36183161]\\n2\", \"[-45868249, 94083487, 18255574, -23318720, -48608103, -71503288, -27032105, 46845855, 64382381, 52532524, 3670998, 30012285, -47761362, 98566272, 70392765, 72942632, 69580625, 66270743, 95178395, -6046985, -75068616, -90331986, 67408066, -58031030, 4292125, -71522366, 76927853, -56548548, 40546396, 1899669, -97679532, 76486554, 3093375, -35911000, -55652986, 2246894, -38044816, -74902981, 76213635, -74627883, 92607207, -33219044, 69475307, 87939580, 1894301, -27057139, -99424145, 37760438]\\n38\", \"[6,738018,1490730,2258772,3042408,3842244,4658364,5491344,6341316,7208862,8094180,8997648,9919602,10860426,11820252,12799560,13798482,14817654,15857328,16917948,17999964,19103508,20228772,21376368,22546968,23740842,24958596,26200638,27467316,28759188,30076824,31420794,32791794,34190520,35617296,37072716,38557308,40071558,41615832,43190712,44796402,46433112,48101148,49800642,51532176,53295876,55092324,56921802,58784718,60681360]\\n28\", \"[50729612,99503496,17602790,31966232,13372079,50153456,50385174,71698340,47504392,11494184,53800036,86341847,67405255,27308886,39701633,57744370,1267328,54622528,51878660,70322819]\\n10\", \"[83112871,66651018,17955046,25736310,43362717,5750045,21577689,81645911,91032402,46042051,51584235,326652,35874916,43855127,13347500,58497081,48794022,93660942,17549215,26430109]\\n20\", \"[100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991, 99999990, 99999989, 99999988, 99999987, 99999986, 99999985, 99999984, 99999983, 99999982, 99999981]\\n6\", \"[2,246006,496910,752786,1013762,1279948,1551454,1828436,2110982,2399316,2693558,2993942,3300640,3613766,3933442,4259696,4592656,4932556,5279494,5633522,5994678,6363102,6739028,7122528,7513792,7913044,8320394,8736004,9160062,9592750,10034184,10484602,10944108,11412852,11891048,12378822,12876346,13383746,13901098,14428528,14966126,15514010,16072380,16641300,17220904,17811360,18412850,19025600,19649778,20285440]\\n37\", \"[-74130616, -67011334, -15495753, -61534681, 69503864, -67268571, -15465209, 70859849, -83593715, 89539516, 20583740, 15582622, 33952933, 55071014, -97243336, 60259478, -17133628, 66736122, -29303586, 32498217]\\n5\", \"[34965628, 83250625, 28246824, -57158385, 41192855, 11844683, -11472735, 37273355, -4914297, -61322341, 49005332, 69998672, 9039844, 44178853, 99584176, -60654481, -71109250, 77620955, -64953795, -73160829, 1216326, -601838, 74753699, 8174597, -44232458, 65533234, -51165625, -94400965, 12103937, -95505138, -33117287, 59695089, 41289219, -9820983, 72309652, -57249414, 95731733, -89647657, -24139155, -82352707, 76905436, -76751201, -61487995, -75902628, -53067983, 7121401, -15975347, -2097604, 29400209, -92299819]\\n50\"], \"outputs\": [\"4\", \"0\", \"10\", \"1\", \"427073221\", \"817691423\", \"901671303\", \"0\", \"14806572\", \"358646265\", \"179535186\", \"627489866\", \"122777274\", \"807554832\", \"5976432\", \"0\", \"200\", \"63221450\", \"54842174\", \"639102989\", \"976956357\", \"78733672\", \"857769049\", \"405831\", \"43975\", \"273504325\", \"710272387\", \"91029\"], \"fn_name\": \"sumOfPowers\"}", "source": "lcbv5"}
|
You are given an integer array nums of length n, and a positive integer k.
The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence.
Return the sum of powers of all subsequences of nums which have length equal to k.
Since the answer may be large, return it modulo 10^9 + 7.
Example 1:
Input: nums = [1,2,3,4], k = 3
Output: 4
Explanation:
There are 4 subsequences in nums which have length 3: [1,2,3], [1,3,4], [1,2,4], and [2,3,4]. The sum of powers is |2 - 3| + |3 - 4| + |2 - 1| + |3 - 4| = 4.
Example 2:
Input: nums = [2,2], k = 2
Output: 0
Explanation:
The only subsequence in nums which has length 2 is [2,2]. The sum of powers is |2 - 2| = 0.
Example 3:
Input: nums = [4,3,-1], k = 2
Output: 10
Explanation:
There are 3 subsequences in nums which have length 2: [4,3], [4,-1], and [3,-1]. The sum of powers is |4 - 3| + |4 - (-1)| + |3 - (-1)| = 10.
Constraints:
2 <= n == nums.length <= 50
-10^8 <= nums[i] <= 10^8
2 <= k <= n
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def sumOfPowers(self, nums: List[int], k: int) -> int:
```
| 0.625
|
{"tests": "{\"inputs\": [\"5 0\\n2 5\\n\", \"3 1\\n4 1\\n\", \"2552608206527595 5411232866732612\\n771856005518028 7206210729152763\\n\", \"4781732879448891 183482112471753\\n4781732879448891 9644257416479985\\n\", \"6544605838412317 5090865519680273\\n3731935893323877 2278195574591833\\n\", \"0 0\\n10000000000000000 0\\n\", \"8418329510387518 3202360550160355\\n7615972582823963 2400003622596800\\n\", \"4014941784357095 6085696188357076\\n7880022861125851 2220615111588322\\n\", \"7215755183863224 5951996685971472\\n4572191670573160 5951996685971472\\n\", \"4014382622377284 7013421623561212\\n232961242787485 3232000243971411\\n\", \"9930915806195072 116116195085278\\n160682763376123 9886349237904226\\n\", \"9784209689015500 537613062202378\\n557720434281403 9764102316936474\\n\", \"10000000000000000 10000000000000000\\n10000000000000000 10000000000000000\\n\", \"7938828835684753 9587479182263189\\n26918308559601 1675568655138037\\n\", \"258486939697908 9609991118547586\\n9661505200356861 206972857888635\\n\", \"0 10000000000000000\\n0 10000000000000000\\n\", \"8751644283352116 6575476350995126\\n2361414790211682 185246857854691\\n\", \"8070073987022736 1704698409806847\\n3263696280075376 6511076116754207\\n\", \"8284987650542282 7767295753858627\\n1507692901416167 7767295753858627\\n\", \"10000000000000000 0\\n0 0\\n\", \"10000000000000000 10000000000000000\\n0 0\\n\", \"0 10000000000000000\\n10000000000000000 10000000000000000\\n\", \"1658322730453427 427544064863111\\n5414864693599393 3432727697673742\\n\", \"0 0\\n10000000000000000 10000000000000000\\n\", \"0 10000000000000000\\n10000000000000000 0\\n\", \"7469674595336959 3380784989113288\\n7289065616920729 9831704242945409\\n\", \"10000000000000000 10000000000000000\\n0 10000000000000000\\n\", \"8382605729111422 8146890158594981\\n4513003330309110 616078906857218\\n\", \"2219334934482116 5920443403095451\\n165878829991508 6183076791238851\\n\", \"0 0\\n0 10000000000000000\\n\", \"1544998523774144 8430682064042656\\n9504313523420391 471367064396410\\n\"], \"outputs\": [\"5\\n\", \"0\\n\", \"1794977862420151\\n\", \"9460775304008232\\n\", \"2812669945088440\\n\", \"5000000000000000\\n\", \"802356927563555\\n\", \"3865081076768755\\n\", \"1321781756645032\\n\", \"3781421379589801\\n\", \"9770233042818949\\n\", \"9226489254734097\\n\", \"0\\n\", \"7911910527125152\\n\", \"9403018260658952\\n\", \"0\\n\", \"6390229493140435\\n\", \"4806377706947360\\n\", \"3388647374563057\\n\", \"5000000000000000\\n\", \"10000000000000000\\n\", \"5000000000000000\\n\", \"3380862797978298\\n\", \"10000000000000000\\n\", \"10000000000000000\\n\", \"6450919253832121\\n\", \"5000000000000000\\n\", \"7530811251737763\\n\", \"1158044746317004\\n\", \"10000000000000000\\n\", \"7959314999646246\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
The coordinate plane is covered with 2\times1 tiles. The tiles are laid out according to the following rules:
- For an integer pair (i,j), the square A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace is contained in one tile.
- When i+j is even, A _ {i,j} and A _ {i + 1,j} are contained in the same tile.
Tiles include their boundaries, and no two different tiles share a positive area.
Near the origin, the tiles are laid out as follows:
Takahashi starts at the point (S _ x+0.5,S _ y+0.5) on the coordinate plane.
He can repeat the following move as many times as he likes:
- Choose a direction (up, down, left, or right) and a positive integer n. Move n units in that direction.
Each time he enters a tile, he pays a toll of 1.
Find the minimum toll he must pay to reach the point (T _ x+0.5,T _ y+0.5).
Input
The input is given from Standard Input in the following format:
S _ x S _ y
T _ x T _ y
Output
Print the minimum toll Takahashi must pay.
Constraints
- 0\leq S _ x\leq2\times10 ^ {16}
- 0\leq S _ y\leq2\times10 ^ {16}
- 0\leq T _ x\leq2\times10 ^ {16}
- 0\leq T _ y\leq2\times10 ^ {16}
- All input values are integers.
Sample Input 1
5 0
2 5
Sample Output 1
5
For example, Takahashi can pay a toll of 5 by moving as follows:
- Move left by 1. Pay a toll of 0.
- Move up by 1. Pay a toll of 1.
- Move left by 1. Pay a toll of 0.
- Move up by 3. Pay a toll of 3.
- Move left by 1. Pay a toll of 0.
- Move up by 1. Pay a toll of 1.
It is impossible to reduce the toll to 4 or less, so print 5.
Sample Input 2
3 1
4 1
Sample Output 2
0
There are cases where no toll needs to be paid.
Sample Input 3
2552608206527595 5411232866732612
771856005518028 7206210729152763
Sample Output 3
1794977862420151
Note that the value to be output may exceed the range of a 32-bit integer.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"363\\n\", \"101\\n\", \"3154625100\\n\", \"146659312800\\n\", \"248961081600\\n\", \"963761198400\\n\", \"936888861285\\n\", \"637822752336\\n\", \"549755813888\\n\", \"240940299600\\n\", \"442597478400\\n\", \"110649369600\\n\", \"39571817593\\n\", \"771852316660\\n\", \"607588581600\\n\", \"764197228384\\n\", \"324899807232\\n\", \"307359360000\\n\", \"293318625600\\n\", \"274877906944\\n\", \"405059054400\\n\", \"810118108800\\n\", \"823586567760\\n\", \"530767036800\\n\", \"498941766577\\n\", \"474896822400\\n\", \"642507465600\\n\", \"321253732800\\n\", \"3\\n\", \"452474573364\\n\", \"160626866400\\n\"], \"outputs\": [\"11*3*11\\n\", \"-1\\n\", \"2*57*184481*75*2\\n\", \"2*3*5*12*646646*21*5*3*2\\n\", \"2*2*2*2*3*3*3*3*5*7*121*7*5*3*3*3*3*2*2*2*2\\n\", \"2*3*5*2964*77*4692*5*3*2\\n\", \"-1\\n\", \"2*3*7*14*629926*41*7*3*2\\n\", \"2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*8*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2\\n\", \"3*5*2964*77*4692*5*3\\n\", \"2*2*2*2*2*2*3*3*3*5*7*121*7*5*3*3*3*2*2*2*2*2*2\\n\", \"2*2*2*2*2*3*3*3*5*7*121*7*5*3*3*3*2*2*2*2*2\\n\", \"39571817593\\n\", \"2*346655*1*556643*2\\n\", \"2*2*3*3*19*58*55*85*91*3*3*2*2\\n\", \"2*2*47762326774*2*2\\n\", \"2*2*2*2*2*2*182*1551*281*2*2*2*2*2*2\\n\", \"2*2*2*2*2*3*3*5*5*7*121*7*5*5*3*3*2*2*2*2*2\\n\", \"2*2*2*15*147*55*741*51*2*2*2\\n\", \"2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*4*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2\\n\", \"3*5*6188*33*8816*5*3\\n\", \"3*5*6188*66*8816*5*3\\n\", \"2*2*3*11*5987*1*7895*11*3*2*2\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"2*3*5*23*969969*32*5*3*2\\n\", \"2*2964*5775*4692*2\\n\", \"3\\n\", \"3*3*11*46166164*11*3*3\\n\", \"3*5*23*969969*32*5*3\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
You are given an integer N. Print a string S that satisfies all of the following conditions. If no such string exists, print -1.
- S is a string of length between 1 and 1000, inclusive, consisting of the characters 1, 2, 3, 4, 5, 6, 7, 8, 9, and * (multiplication symbol).
- S is a palindrome.
- The first character of S is a digit.
- The value of S when evaluated as a formula equals N.
Input
The input is given from Standard Input in the following format:
N
Output
If there is a string S that satisfies the conditions exists, print such a string. Otherwise, print -1.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Sample Input 1
363
Sample Output 1
11*3*11
S = 11*3*11 satisfies the conditions in the problem statement. Another string that satisfies the conditions is S= 363.
Sample Input 2
101
Sample Output 2
-1
Note that S must not contain the digit 0.
Sample Input 3
3154625100
Sample Output 3
2*57*184481*75*2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 8 4\\n1 5\\n3 2\\n4 1\\n5 3\\n\", \"2 1 1\\n3 2\\n3 2\\n\", \"2 100 100\\n3 2\\n3 2\\n\", \"6 364 463\\n230 381\\n154 200\\n328 407\\n339 94\\n193 10\\n115 309\\n\", \"18 10000 10000\\n5790 8778\\n9995 9908\\n9016 2300\\n2633 3650\\n2312 5582\\n8853 6097\\n8881 8620\\n6427 3925\\n9355 5240\\n5070 7050\\n4178 8133\\n6739 319\\n4533 5388\\n9299 5558\\n7720 122\\n861 7766\\n5922 1456\\n7601 8377\\n\", \"80 6376 77\\n30 10\\n10 1\\n42 4249\\n569 17\\n15 9\\n133 5786\\n644 6054\\n207 231\\n6 194\\n5218 71\\n461 63\\n35 216\\n32 88\\n2048 455\\n5 3188\\n4 2924\\n1 42\\n154 350\\n5279 24\\n50 5605\\n1587 3\\n6574 276\\n162 3173\\n129 17\\n79 1075\\n1 62\\n11 19\\n1373 1904\\n19 197\\n1193 5\\n1515 49\\n2007 3743\\n15 1\\n160 233\\n120 12\\n1374 2804\\n23 627\\n25 995\\n54 1\\n5 180\\n1754 506\\n5 19\\n3 1494\\n452 1478\\n17 9424\\n36 4397\\n2 3581\\n5066 29\\n13 7296\\n4 199\\n496 1\\n122 2817\\n1 17\\n1 261\\n1 5\\n29 15\\n46 1917\\n86 8412\\n422 590\\n2 12\\n205 511\\n573 5\\n363 366\\n713 46\\n74 1302\\n1 9\\n6 3\\n6128 2\\n198 427\\n37 5\\n3 937\\n164 874\\n143 2493\\n28 33\\n6425 2066\\n21 8\\n339 1586\\n1 8\\n1273 3\\n68 18\\n\", \"80 10000 10000\\n622 9\\n31 18\\n3000 1705\\n787 340\\n5 5\\n179 106\\n20 7\\n5311 1191\\n240 33\\n2 1887\\n141 66\\n49 908\\n15 5\\n2709 16\\n1 110\\n1976 21\\n4 68\\n32 295\\n2010 237\\n3 43\\n164 45\\n1 5082\\n5713 53\\n260 522\\n17 32\\n1 12\\n506 10\\n1967 59\\n154 2\\n14 42\\n1886 8309\\n7 12\\n195 7230\\n10 5\\n6 14\\n12 8876\\n3 12\\n57 5971\\n2917 348\\n21 31\\n1 7\\n3 250\\n1 15\\n99 156\\n1103 30\\n218 6\\n183 1\\n3 2888\\n12 1\\n292 21\\n371 8\\n8571 1263\\n2971 24\\n95 104\\n946 1506\\n5924 2\\n11 4\\n57 103\\n13 9\\n3776 86\\n1 14\\n6 19\\n47 12\\n8 7\\n1995 62\\n115 9834\\n3734 5\\n5868 61\\n11 1971\\n23 992\\n5651 6518\\n49 183\\n8212 78\\n17 1\\n208 10\\n19 51\\n2469 1105\\n497 15\\n4219 905\\n2 72\\n\", \"51 10000 4456\\n26 15\\n64 80\\n17 57\\n64 79\\n1 26\\n90 67\\n4 75\\n16 49\\n6 99\\n57 54\\n55 91\\n39 5\\n37 68\\n54 66\\n36 28\\n7 32\\n32 86\\n66 68\\n59 18\\n52 68\\n68 10\\n5 65\\n69 75\\n60 2\\n38 16\\n6 2\\n59 22\\n23 26\\n6 19\\n5 21\\n75 15\\n55 74\\n58 46\\n11 49\\n97 88\\n76 78\\n83 11\\n64 85\\n30 77\\n83 28\\n57 35\\n71 85\\n51 95\\n38 81\\n46 3\\n36 1\\n33 59\\n86 93\\n47 19\\n27 28\\n10 47\\n\", \"80 1694 7915\\n72 40\\n45 57\\n21 19\\n79 54\\n77 18\\n99 63\\n35 17\\n48 64\\n7 39\\n26 6\\n96 97\\n100 14\\n62 39\\n55 88\\n36 94\\n38 49\\n28 99\\n49 70\\n18 59\\n22 27\\n77 5\\n86 52\\n85 59\\n77 63\\n14 61\\n86 37\\n80 37\\n52 4\\n56 13\\n47 44\\n42 72\\n28 7\\n89 85\\n97 86\\n4 3\\n98 35\\n97 99\\n35 53\\n25 5\\n7 26\\n86 3\\n51 35\\n85 48\\n100 18\\n48 51\\n17 10\\n24 77\\n51 87\\n20 35\\n66 66\\n76 61\\n99 82\\n35 28\\n81 10\\n58 26\\n95 89\\n23 4\\n49 72\\n55 71\\n86 31\\n28 44\\n31 96\\n96 54\\n19 95\\n24 7\\n57 76\\n49 12\\n50 69\\n98 45\\n20 49\\n61 37\\n44 98\\n2 32\\n36 96\\n79 28\\n13 36\\n38 80\\n59 5\\n85 97\\n36 18\\n\", \"80 1920 10000\\n6 67\\n1 9\\n405 6\\n425 20\\n5 9285\\n201 16\\n1 1104\\n3 11\\n14 5391\\n876 6\\n130 367\\n79 6524\\n354 5129\\n1134 1089\\n23 1\\n77 43\\n21 41\\n257 63\\n1453 382\\n63 1\\n310 798\\n30 8536\\n94 781\\n146 19\\n61 110\\n1315 5878\\n18 142\\n2 318\\n9 138\\n1 2\\n855 5558\\n88 582\\n34 1643\\n72 2\\n8 1\\n3 392\\n179 636\\n5 18\\n68 22\\n395 262\\n5 21\\n13 4\\n1867 35\\n29 3\\n530 66\\n458 63\\n6 272\\n33 7\\n25 214\\n17 5\\n97 6245\\n28 67\\n20 7\\n240 5120\\n7 49\\n1 548\\n26 8\\n217 3474\\n508 1176\\n29 3\\n3 6996\\n108 5\\n2 674\\n1 6954\\n1471 19\\n28 9825\\n21 312\\n6 454\\n1350 9\\n39 36\\n1 224\\n257 1209\\n132 5\\n560 12\\n124 1\\n1595 2082\\n1 11\\n30 596\\n23 237\\n1 65\\n\", \"26 10000 10000\\n535 1\\n2049 754\\n336 48\\n491 3\\n71 7\\n2 26\\n233 1\\n15 6\\n3 1341\\n2269 3\\n268 565\\n149 37\\n27 113\\n36 5109\\n241 638\\n495 30\\n122 22\\n1046 2630\\n207 1509\\n1115 5\\n4520 2702\\n467 46\\n9 568\\n12 1\\n1468 5\\n1577 25\\n\", \"16 6013 7611\\n6 543\\n371 8\\n2 2636\\n1 914\\n1 2\\n83 135\\n2 117\\n115 5\\n3158 1\\n34 2\\n155 8\\n12 1\\n313 3691\\n16 626\\n441 3519\\n1217 3\\n\", \"1 10000 10000\\n1 1\\n\", \"80 10000 10000\\n94 20\\n54 3\\n9 45\\n5 62\\n65 92\\n75 15\\n57 70\\n22 15\\n13 40\\n46 54\\n81 77\\n84 57\\n64 80\\n57 20\\n58 19\\n27 29\\n86 73\\n9 47\\n60 29\\n34 68\\n64 41\\n87 24\\n26 40\\n61 8\\n91 53\\n74 52\\n63 33\\n65 96\\n81 60\\n58 75\\n97 89\\n88 19\\n91 10\\n90 55\\n52 73\\n69 5\\n64 49\\n72 92\\n95 54\\n70 100\\n23 100\\n4 93\\n85 4\\n57 79\\n84 16\\n4 73\\n5 18\\n69 13\\n85 17\\n40 61\\n66 68\\n73 34\\n46 65\\n90 60\\n70 94\\n96 63\\n72 52\\n31 49\\n45 83\\n85 17\\n84 27\\n19 70\\n54 22\\n56 90\\n72 32\\n4 99\\n64 78\\n58 50\\n24 47\\n98 46\\n2 18\\n16 50\\n46 42\\n27 52\\n43 61\\n15 31\\n22 53\\n75 62\\n93 34\\n8 94\\n\", \"64 10000 10000\\n82 66\\n46 4\\n9 49\\n96 27\\n85 55\\n13 59\\n63 39\\n91 70\\n60 34\\n11 74\\n76 45\\n77 14\\n45 43\\n9 79\\n37 40\\n82 53\\n31 95\\n17 94\\n71 65\\n90 86\\n93 4\\n72 93\\n54 21\\n32 60\\n23 82\\n81 64\\n36 65\\n71 94\\n58 75\\n56 10\\n54 29\\n74 95\\n16 26\\n83 64\\n52 15\\n40 35\\n80 62\\n74 45\\n12 45\\n7 54\\n21 20\\n11 7\\n3 13\\n52 63\\n51 91\\n25 74\\n42 43\\n81 42\\n19 30\\n29 53\\n57 3\\n1 40\\n43 38\\n71 73\\n6 89\\n78 31\\n78 19\\n52 56\\n49 47\\n61 34\\n51 18\\n30 91\\n93 23\\n3 63\\n\", \"4 9279 10000\\n504 2668\\n300 2\\n2 7\\n407 25\\n\", \"80 9251 6581\\n103 613\\n5 2\\n80 10\\n7717 113\\n422 30\\n186 35\\n51 1\\n2 140\\n344 1168\\n1 7279\\n6 349\\n65 4\\n304 108\\n18 4024\\n177 212\\n6587 2032\\n68 3\\n1031 36\\n46 10\\n3313 1101\\n7771 13\\n42 629\\n9 1310\\n9705 52\\n1832 4\\n25 1\\n6 4\\n5523 5589\\n6 56\\n2 2144\\n32 2\\n808 1\\n2 995\\n25 134\\n3608 142\\n1541 580\\n950 56\\n19 95\\n2564 1209\\n6917 47\\n287 1\\n252 1434\\n35 2056\\n5 1500\\n2 2399\\n3 4\\n5 151\\n7 2629\\n188 117\\n792 2\\n10 12\\n7 22\\n640 50\\n15 1\\n1 22\\n2 4975\\n1 15\\n763 4143\\n3445 502\\n35 6121\\n6 86\\n1 2\\n30 5\\n8 10\\n126 384\\n4 401\\n77 855\\n105 3\\n97 4009\\n1180 3907\\n5 1\\n1 359\\n552 295\\n160 1\\n2 57\\n562 38\\n1 49\\n9 162\\n3 3651\\n3 3\\n\", \"80 2762 10000\\n83 45\\n32 33\\n40 65\\n65 64\\n61 87\\n43 49\\n56 35\\n89 71\\n50 18\\n10 46\\n17 92\\n59 85\\n62 7\\n15 15\\n64 29\\n65 75\\n31 50\\n9 35\\n30 80\\n7 54\\n98 18\\n75 18\\n53 10\\n99 99\\n88 67\\n4 49\\n21 15\\n50 30\\n34 21\\n51 17\\n52 92\\n28 40\\n37 43\\n88 72\\n82 59\\n47 60\\n77 16\\n92 74\\n88 45\\n63 81\\n12 87\\n60 83\\n79 29\\n98 97\\n71 7\\n21 27\\n29 31\\n56 97\\n11 6\\n80 72\\n46 1\\n11 97\\n97 62\\n42 53\\n64 94\\n84 63\\n81 42\\n40 13\\n23 75\\n95 76\\n46 24\\n32 63\\n64 64\\n38 16\\n11 57\\n57 99\\n8 75\\n41 25\\n26 26\\n90 31\\n97 43\\n74 48\\n88 28\\n2 50\\n75 96\\n10 82\\n1 60\\n96 35\\n8 33\\n41 23\\n\", \"80 10000 9521\\n36 36\\n67 13\\n36 89\\n20 71\\n42 22\\n66 73\\n88 5\\n30 29\\n9 100\\n100 12\\n94 29\\n50 41\\n48 69\\n35 11\\n36 38\\n73 34\\n26 13\\n39 94\\n7 13\\n92 54\\n55 86\\n14 90\\n76 78\\n36 70\\n93 76\\n16 38\\n43 36\\n62 20\\n71 56\\n27 48\\n66 94\\n14 39\\n4 47\\n19 20\\n14 94\\n95 42\\n84 3\\n49 33\\n51 41\\n1 60\\n80 33\\n47 96\\n39 32\\n4 96\\n17 72\\n18 11\\n63 15\\n3 34\\n89 43\\n30 39\\n92 81\\n25 47\\n56 10\\n44 60\\n82 81\\n89 36\\n51 3\\n42 40\\n47 57\\n78 50\\n87 49\\n88 24\\n27 38\\n90 30\\n57 44\\n44 48\\n25 29\\n59 33\\n63 54\\n54 21\\n80 70\\n76 100\\n28 78\\n67 26\\n61 7\\n87 1\\n95 36\\n73 1\\n51 50\\n73 39\\n\", \"80 9875 9875\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n\", \"1 1 1\\n10000 10000\\n\", \"80 10000 10000\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n125 125\\n\", \"80 768 1885\\n1081 4\\n130 412\\n2828 3136\\n36 11\\n75 5342\\n160 19\\n1636 121\\n23 7\\n63 1561\\n5 640\\n380 3\\n9760 379\\n950 648\\n251 2\\n3643 3\\n1861 2\\n38 3008\\n26 703\\n733 1441\\n3 999\\n4360 2591\\n31 243\\n77 5096\\n8 10\\n6682 412\\n3750 7990\\n22 392\\n5389 3956\\n8 3865\\n280 346\\n2 2548\\n6 186\\n90 23\\n847 18\\n37 1\\n413 1476\\n5 6\\n2156 1980\\n124 9\\n1695 240\\n12 2\\n720 229\\n4 15\\n261 2\\n4351 149\\n298 2597\\n18 234\\n143 1\\n67 6\\n107 533\\n6 1559\\n13 333\\n1239 877\\n14 63\\n10 247\\n1658 1489\\n311 53\\n3 226\\n2 11\\n14 2812\\n9003 5\\n60 375\\n46 5\\n32 7449\\n27 432\\n825 1\\n2 527\\n98 2743\\n35 76\\n4691 1706\\n1132 1556\\n32 2\\n65 1844\\n571 5302\\n1961 6730\\n6585 169\\n1 2257\\n168 1\\n892 122\\n11 20\\n\", \"43 10000 8294\\n2516 58\\n2 965\\n6508 2004\\n8 1\\n3 5\\n5 4005\\n949 20\\n240 1\\n4 35\\n12 5204\\n7 113\\n262 6\\n98 2487\\n1878 26\\n3 11\\n27 6\\n40 2302\\n22 150\\n1 2\\n2194 1536\\n233 1\\n9 1\\n1 423\\n10 671\\n220 1036\\n1 266\\n3 189\\n6160 2612\\n11 33\\n7 26\\n719 5\\n44 2\\n2744 1\\n9864 3433\\n68 41\\n12 1\\n2671 125\\n2 120\\n2218 408\\n28 428\\n21 4165\\n131 10\\n7 50\\n\", \"80 9161 5663\\n1006 2222\\n301 4644\\n12 69\\n12 45\\n17 163\\n1464 4731\\n59 757\\n593 72\\n1 4994\\n8 1\\n2 42\\n14 7\\n3892 2123\\n3604 133\\n256 64\\n1074 1\\n300 222\\n20 29\\n6123 2643\\n4750 180\\n21 27\\n836 1388\\n4 2\\n167 77\\n6058 1\\n46 4\\n2 148\\n83 399\\n1 9\\n2430 55\\n5 826\\n12 30\\n85 83\\n7112 1546\\n424 2\\n21 3084\\n3622 142\\n78 24\\n7334 6\\n6 14\\n62 104\\n10 3632\\n431 131\\n38 643\\n966 5\\n6 3343\\n24 26\\n2 31\\n8482 316\\n7142 443\\n981 213\\n151 2466\\n10 29\\n381 2323\\n142 3600\\n1319 302\\n9102 4966\\n3 42\\n5 14\\n36 1378\\n1634 71\\n1174 36\\n2 2937\\n7 90\\n5 2\\n1098 36\\n6229 270\\n1 190\\n3063 7\\n1 2253\\n132 2\\n5682 7\\n3117 2067\\n3493 433\\n4426 2\\n1 2355\\n28 5\\n23 2533\\n2183 1098\\n3 181\\n\", \"80 1552 903\\n86 431\\n3224 1449\\n3533 549\\n30 166\\n934 371\\n11 9158\\n28 7\\n115 3461\\n178 2\\n544 2080\\n6 78\\n7828 8965\\n4270 140\\n43 1656\\n315 9\\n84 26\\n9315 1109\\n214 3\\n369 8\\n1 453\\n17 3\\n2 227\\n422 3\\n51 16\\n636 33\\n66 1170\\n149 4479\\n1 237\\n166 554\\n3 3921\\n152 1416\\n187 6\\n106 21\\n64 7857\\n44 11\\n3008 28\\n6 1082\\n7 3297\\n123 41\\n1 7330\\n1 9452\\n5 386\\n6079 12\\n55 167\\n1115 729\\n52 3\\n525 8526\\n8 1673\\n2089 69\\n13 485\\n136 1\\n1271 2\\n9 767\\n1 225\\n30 152\\n1539 4\\n232 6184\\n3375 117\\n620 9\\n5 1\\n1759 603\\n397 7521\\n1745 49\\n9503 48\\n18 52\\n39 315\\n7810 217\\n2066 1\\n5300 965\\n2922 7\\n27 2\\n1043 251\\n176 9452\\n12 1\\n783 5\\n42 1184\\n482 202\\n4 129\\n1 15\\n8982 4718\\n\", \"80 1889 10000\\n8517 4554\\n956 1523\\n2877 9544\\n2080 7273\\n1907 97\\n6097 4231\\n548 4323\\n8423 9587\\n1375 7519\\n4507 2922\\n6794 7147\\n189 8796\\n5405 9953\\n1487 6571\\n4853 9246\\n7591 3616\\n8051 2500\\n5553 2790\\n8523 2408\\n3339 7885\\n3110 5748\\n152 4008\\n9664 5526\\n5902 6015\\n9594 2575\\n264 3070\\n2537 9174\\n9364 2004\\n5653 3155\\n4005 4629\\n331 7204\\n4434 6761\\n5484 7707\\n4581 2363\\n7644 1069\\n4638 3866\\n2995 4164\\n398 8251\\n8783 1919\\n8988 9829\\n5872 4061\\n2547 835\\n3499 4630\\n7970 9734\\n4520 5810\\n8427 689\\n1316 8143\\n3172 5483\\n2064 31\\n4633 1984\\n8128 8007\\n536 1473\\n476 2402\\n2947 5743\\n3154 8700\\n8754 2436\\n3138 4360\\n2654 8442\\n2273 4491\\n3863 2721\\n3431 2494\\n495 2462\\n8081 2943\\n5117 1734\\n3647 6656\\n9435 8967\\n7735 1063\\n9449 6000\\n6576 525\\n3879 7828\\n9032 5071\\n5151 780\\n8639 8960\\n8920 6769\\n938 85\\n1252 2742\\n6496 1191\\n8787 2828\\n1040 2053\\n1582 6283\\n\", \"80 10000 605\\n38 10\\n374 66\\n2145 6\\n13 4\\n17 2\\n122 9\\n3 69\\n3 3\\n341 3\\n28 95\\n858 2\\n1 441\\n8 118\\n45 2\\n9 61\\n3 8\\n10 35\\n920 3\\n20 604\\n257 12\\n13 4\\n6 4\\n1347 3\\n1569 3\\n638 14\\n17 20\\n1 14\\n5 1\\n445 2\\n12 5\\n2 5\\n382 4\\n32 44\\n17 1\\n2 9\\n1 165\\n379 48\\n4719 1\\n8 30\\n39 13\\n1564 54\\n108 11\\n1 144\\n237 17\\n209 87\\n4355 601\\n86 15\\n1650 17\\n158 584\\n63 303\\n2471 2\\n1 123\\n1 97\\n369 22\\n173 1\\n22 560\\n786 26\\n800 75\\n1 214\\n45 2\\n160 124\\n191 21\\n19 33\\n11 9\\n8 4\\n556 14\\n5 44\\n626 21\\n683 1\\n26 2\\n3306 8\\n147 6\\n137 10\\n3 53\\n1167 179\\n231 231\\n409 375\\n8 53\\n57 330\\n2 2\\n\", \"80 6095 3812\\n6978 8593\\n4714 8422\\n8797 9536\\n3565 9466\\n6936 26\\n5359 7181\\n581 4182\\n3144 4179\\n9589 6994\\n232 1794\\n6322 6333\\n4719 4246\\n2646 2062\\n19 7147\\n770 9291\\n8397 5862\\n8617 6643\\n7611 2925\\n4274 9973\\n4064 9498\\n8873 2407\\n640 6908\\n6302 9296\\n789 4581\\n4980 717\\n1388 9613\\n531 8544\\n1864 7325\\n4952 1660\\n5550 9590\\n3184 2235\\n56 4664\\n4352 8520\\n3443 9019\\n4112 373\\n4448 2793\\n4443 7878\\n6822 7953\\n2960 3700\\n6926 54\\n2884 6220\\n8614 2830\\n3982 2349\\n2447 7396\\n1834 766\\n1215 9111\\n2743 8645\\n9856 6377\\n5353 3713\\n5343 592\\n4967 5537\\n1374 6264\\n4862 1562\\n18 3774\\n268 8293\\n3557 3607\\n645 2334\\n5173 8375\\n210 9222\\n1923 8635\\n8637 5762\\n7430 5088\\n8423 7179\\n5574 5721\\n4387 4780\\n6673 7356\\n6920 8727\\n8569 405\\n4386 7472\\n4979 4179\\n7649 1120\\n8841 3670\\n5800 3699\\n2457 7639\\n2751 5723\\n8933 7408\\n5138 2539\\n65 4031\\n8785 6124\\n8360 1816\\n\", \"80 10000 3783\\n3079 3244\\n4382 9074\\n5167 5284\\n2015 9783\\n9521 8593\\n2443 4218\\n1622 515\\n3573 120\\n9912 8481\\n7009 2589\\n1511 5410\\n4362 30\\n519 2771\\n749 7313\\n6240 6516\\n444 8928\\n5085 3131\\n5453 6234\\n3998 1503\\n1753 4386\\n6822 7550\\n4637 46\\n2877 4567\\n9484 441\\n8526 3249\\n3226 5537\\n1866 5315\\n323 8634\\n212 1641\\n546 2793\\n1508 8918\\n2026 2025\\n9636 7948\\n4721 7466\\n8966 1701\\n7184 6749\\n8667 6766\\n8276 3705\\n6253 935\\n7936 8201\\n1078 5540\\n1913 9692\\n5447 2351\\n2888 9332\\n6338 1891\\n1292 9975\\n1409 8258\\n4069 4769\\n4141 433\\n3482 8368\\n2615 7415\\n4692 4039\\n6514 209\\n8897 7979\\n8630 9937\\n1602 6073\\n6159 9802\\n1677 830\\n7917 2294\\n1963 5821\\n9986 80\\n3899 8589\\n7543 3178\\n5758 4377\\n5542 4281\\n7641 3294\\n817 8468\\n3062 6416\\n762 8984\\n9459 2725\\n5881 1495\\n8449 4120\\n2922 740\\n1110 9304\\n7532 5384\\n988 8678\\n4563 3857\\n9247 4891\\n2390 7454\\n8963 6095\\n\", \"46 10000 4870\\n9394 4314\\n9513 901\\n2687 6748\\n6614 9965\\n4222 1122\\n5748 2234\\n8311 2997\\n2193 9838\\n3172 7006\\n803 3711\\n2547 9136\\n5442 8343\\n3431 7420\\n2923 5843\\n3239 6314\\n7903 8901\\n2622 8535\\n5777 8275\\n3321 2177\\n1404 6261\\n2972 4093\\n8747 1562\\n8237 1698\\n4271 4836\\n504 9420\\n5101 4743\\n5433 3897\\n1277 8110\\n8645 9487\\n3324 246\\n3889 5524\\n5243 4258\\n7961 8389\\n3581 789\\n4619 4688\\n6477 3899\\n4025 9913\\n6134 1920\\n3179 1065\\n8697 4727\\n1051 7706\\n763 2500\\n2471 1068\\n5652 3266\\n8850 52\\n8000 6319\\n\", \"80 10000 10000\\n8546 6436\\n7158 9927\\n3186 1091\\n533 3273\\n640 7693\\n5673 3531\\n8591 3371\\n1166 1108\\n9444 5117\\n7764 8250\\n5337 5894\\n6877 5659\\n6026 6586\\n8641 2056\\n7691 2551\\n5293 7605\\n3024 8425\\n3919 5659\\n3811 4612\\n908 5623\\n8641 734\\n3579 5432\\n4317 3985\\n200 9556\\n3564 5374\\n6674 4339\\n600 7509\\n7884 275\\n3022 7535\\n144 9267\\n1679 4660\\n5207 1224\\n4018 9221\\n4898 7466\\n9696 6963\\n4645 8552\\n1479 837\\n5462 9808\\n2088 9639\\n2130 3576\\n58 7413\\n5305 2056\\n6932 260\\n1773 829\\n4134 1850\\n3159 5528\\n833 3345\\n482 3373\\n6826 9064\\n5310 2421\\n7916 8946\\n926 6956\\n3619 9332\\n6714 899\\n9617 4331\\n654 1647\\n5548 6980\\n3529 4072\\n8926 1667\\n399 5275\\n9764 509\\n1880 5321\\n7088 3933\\n127 902\\n6375 7363\\n8771 8378\\n4564 576\\n713 8563\\n8707 2891\\n2440 8306\\n4087 7775\\n6203 5929\\n8372 3386\\n8691 4963\\n1845 4064\\n6275 8956\\n8743 9495\\n8962 5061\\n4460 1000\\n2732 8418\\n\"], \"outputs\": [\"3\\n\", \"1\\n\", \"2\\n\", \"3\\n\", \"3\\n\", \"17\\n\", \"55\\n\", \"51\\n\", \"50\\n\", \"50\\n\", \"23\\n\", \"15\\n\", \"1\\n\", \"80\\n\", \"64\\n\", \"4\\n\", \"52\\n\", \"66\\n\", \"80\\n\", \"80\\n\", \"1\\n\", \"80\\n\", \"23\\n\", \"34\\n\", \"44\\n\", \"23\\n\", \"5\\n\", \"49\\n\", \"3\\n\", \"5\\n\", \"4\\n\", \"8\\n\"], \"fn_name\": null}", "source": "lcbv5"}
|
Takahashi has prepared N dishes for Snuke.
The dishes are numbered from 1 to N, and dish i has a sweetness of A_i and a saltiness of B_i.
Takahashi can arrange these dishes in any order he likes.
Snuke will eat the dishes in the order they are arranged, but if at any point the total sweetness of the dishes he has eaten so far exceeds X or the total saltiness exceeds Y, he will not eat any further dishes.
Takahashi wants Snuke to eat as many dishes as possible.
Find the maximum number of dishes Snuke will eat if Takahashi arranges the dishes optimally.
Input
The input is given from Standard Input in the following format:
N X Y
A_1 B_1
A_2 B_2
\vdots
A_N B_N
Output
Print the answer as an integer.
Constraints
- 1 \leq N \leq 80
- 1 \leq A_i, B_i \leq 10000
- 1 \leq X, Y \leq 10000
- All input values are integers.
Sample Input 1
4 8 4
1 5
3 2
4 1
5 3
Sample Output 1
3
Consider the scenario where Takahashi arranges the dishes in the order 2, 3, 1, 4.
- First, Snuke eats dish 2. The total sweetness so far is 3, and the total saltiness is 2.
- Next, Snuke eats dish 3. The total sweetness so far is 7, and the total saltiness is 3.
- Next, Snuke eats dish 1. The total sweetness so far is 8, and the total saltiness is 8.
- The total saltiness has exceeded Y=4, so Snuke will not eat any further dishes.
Thus, in this arrangement, Snuke will eat three dishes.
No matter how Takahashi arranges the dishes, Snuke will not eat all four dishes, so the answer is 3.
Sample Input 2
2 1 1
3 2
3 2
Sample Output 2
1
Sample Input 3
2 100 100
3 2
3 2
Sample Output 3
2
Sample Input 4
6 364 463
230 381
154 200
328 407
339 94
193 10
115 309
Sample Output 4
3
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n2\\n[1, 3]\\n[5]\", \"2\\n2\\n[7]\\n[4]\", \"10\\n10\\n[420, 1, 597, 1, 905, 1, 261, 1, 681]\\n[101, 1, 333, 1, 502, 1, 409, 1, 787]\", \"6\\n2\\n[1,3,2,3,1]\\n[1]\", \"17\\n18\\n[781, 307, 573, 596, 536, 761, 591, 848, 858, 302, 652, 540, 770, 607, 809, 322]\\n[841, 828, 682, 480, 391, 915, 948, 736, 933, 705, 909, 717, 881, 954, 807, 297, 696]\", \"10\\n20\\n[543, 1, 831, 1, 737, 1, 241, 1, 471]\\n[69, 1, 130, 1, 259, 1, 701, 1, 324, 1, 840, 1, 265, 1, 609, 1, 299, 1, 779]\", \"5\\n3\\n[1,1,1,1]\\n[1,1]\", \"7\\n7\\n[16,8,1,10,13,3]\\n[18,2,3,12,12,15]\", \"9\\n8\\n[7,7,4,3,1,2,3,5]\\n[2,3,1,1,2,2,1]\", \"2\\n2\\n[215]\\n[215]\", \"10\\n20\\n[939, 911, 880, 751, 716, 621, 618, 328, 98]\\n[990, 967, 926, 817, 785, 721, 655, 653, 544, 350, 278, 248, 234, 206, 148, 138, 61, 52, 32]\", \"20\\n20\\n[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]\\n[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]\", \"8\\n2\\n[2,4,3,3,5,1,1]\\n[5]\", \"2\\n2\\n[832]\\n[918]\", \"1\\n7\\n[]\\n[1,2,1,1,2,1]\", \"20\\n20\\n[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]\\n[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]\", \"1\\n20\\n[]\\n[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]\", \"5\\n6\\n[3,3,3,3]\\n[5,3,5,5,1]\", \"20\\n20\\n[794, 744, 448, 293, 101, 197, 955, 51, 749, 485, 52, 511, 981, 101, 283, 149, 44, 636, 947]\\n[413, 746, 603, 720, 636, 193, 67, 928, 520, 575, 323, 838, 10, 619, 344, 810, 901, 181, 743]\", \"5\\n5\\n[527, 527, 527, 527]\\n[527, 527, 527, 527]\", \"20\\n20\\n[812, 1, 974, 1, 871, 1, 117, 1, 453, 1, 199, 1, 719, 1, 596, 1, 408, 1, 263]\\n[94, 1, 523, 1, 261, 1, 271, 1, 547, 1, 614, 1, 878, 1, 522, 1, 749, 1, 989]\", \"20\\n1\\n[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]\\n[]\", \"10\\n20\\n[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\\n[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\", \"20\\n20\\n[537, 294, 694, 235, 534, 607, 413, 356, 888, 924, 425, 91, 243, 136, 260, 941, 443, 649, 685]\\n[239, 749, 577, 940, 809, 562, 366, 824, 877, 714, 578, 698, 785, 206, 999, 199, 76, 642, 453]\", \"3\\n4\\n[21, 54]\\n[99, 4, 96]\", \"7\\n8\\n[100, 262, 33, 273, 422, 318]\\n[204, 107, 56, 189, 129, 95, 46]\", \"10\\n10\\n[891, 835, 866, 757, 791, 644, 671, 592, 591]\\n[921, 821, 822, 652, 683, 617, 584, 520, 574]\", \"1\\n1\\n[]\\n[]\", \"7\\n1\\n[4,1,3,12,9,2]\\n[]\", \"10\\n10\\n[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\\n[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\", \"10\\n10\\n[989, 1, 126, 1, 388, 1, 825, 1, 601]\\n[262, 1, 204, 1, 971, 1, 221, 1, 788]\", \"1\\n7\\n[]\\n[2,1,2,1,2,1]\", \"2\\n11\\n[706]\\n[46, 17, 582, 837, 668, 491, 484, 996, 421, 749]\", \"4\\n1\\n[10,5,4]\\n[]\", \"2\\n2\\n[91]\\n[986]\", \"8\\n4\\n[6,5,4,3,5,3,8]\\n[10,9,1]\", \"16\\n18\\n[210,283,5,312,42,232,67,147,296,143,346,10,191,42,314]\\n[344,31,69,4,300,263,309,167,216,253,313,36,57,145,199,152,172]\"], \"outputs\": [\"13\", \"15\", \"13988\", \"16\", \"175365\", \"24503\", \"14\", \"333\", \"134\", \"645\", \"77464\", \"399\", \"43\", \"2582\", \"8\", \"19380\", \"19000\", \"83\", \"131105\", \"12648\", \"49461\", \"19000\", \"199000\", \"160334\", \"432\", \"6366\", \"64747\", \"0\", \"31\", \"99000\", \"14167\", \"9\", \"10824\", \"19\", \"1168\", \"129\", \"34481\"], \"fn_name\": \"minimumCost\"}", "source": "lcbv5"}
|
There is an m x n cake that needs to be cut into 1 x 1 pieces.
You are given integers m, n, and two arrays:
horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.
verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line j.
In one operation, you can choose any piece of cake that is not yet a 1 x 1 square and perform one of the following cuts:
Cut along a horizontal line i at a cost of horizontalCut[i].
Cut along a vertical line j at a cost of verticalCut[j].
After the cut, the piece of cake is divided into two distinct pieces.
The cost of a cut depends only on the initial cost of the line and does not change.
Return the minimum total cost to cut the entire cake into 1 x 1 pieces.
Example 1:
Input: m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]
Output: 13
Explanation:
Perform a cut on the vertical line 0 with cost 5, current total cost is 5.
Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.
Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.
Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.
Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.
The total cost is 5 + 1 + 1 + 3 + 3 = 13.
Example 2:
Input: m = 2, n = 2, horizontalCut = [7], verticalCut = [4]
Output: 15
Explanation:
Perform a cut on the horizontal line 0 with cost 7.
Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.
Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.
The total cost is 7 + 4 + 4 = 15.
Constraints:
1 <= m, n <= 20
horizontalCut.length == m - 1
verticalCut.length == n - 1
1 <= horizontalCut[i], verticalCut[i] <= 10^3
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def minimumCost(self, m: int, n: int, horizontalCut: List[int], verticalCut: List[int]) -> int:
```
| 0
|
{"tests": "{\"inputs\": [\"3\\n[[2, 2], [0, 0]]\", \"3\\n[[2, 2], [1, 1], [0, 0]]\", \"2\\n[[0, 0], [1, 0]]\", \"69\\n[[0, 0], [1, 0], [2, 2], [3, 4], [4, 8], [5, 7], [6, 10], [7, 0], [8, 22], [9, 17], [10, 50], [11, 31], [12, 59], [13, 77], [14, 62], [15, 53], [16, 0], [17, 132], [18, 91], [19, 86], [20, 40], [21, 71], [22, 213], [23, 17], [24, 201], [25, 196], [26, 205], [27, 227], [28, 182], [29, 276], [30, 333], [31, 283], [32, 394], [33, 127], [34, 290], [35, 49], [36, 112], [37, 350], [38, 232], [39, 143], [40, 378], [41, 218], [42, 297], [43, 98], [44, 16], [45, 284], [46, 111], [47, 123], [48, 108], [49, 239], [50, 355], [51, 302], [52, 198], [53, 57], [54, 206], [55, 28], [56, 342], [57, 273], [58, 94], [59, 239], [60, 293], [61, 91], [62, 338], [63, 326], [64, 266], [65, 387], [66, 11], [67, 59], [68, 237]]\", \"2\\n[[1,0],[0,0]]\", \"102\\n[[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [10, 0], [11, 0], [12, 0], [13, 0], [14, 0], [15, 0], [16, 0], [17, 0], [18, 0], [19, 0], [20, 0], [21, 0], [22, 0], [23, 0], [24, 0], [25, 0], [26, 0], [27, 0], [28, 0], [29, 0], [30, 0], [31, 0], [32, 0], [33, 0], [34, 0], [35, 0], [36, 0], [37, 0], [38, 0], [39, 0], [40, 0], [41, 0], [42, 0], [43, 0], [44, 0], [45, 0], [46, 0], [47, 0], [48, 0], [49, 0], [50, 0], [51, 0], [52, 0], [53, 0], [54, 0], [55, 0], [56, 0], [57, 0], [58, 0], [59, 0], [60, 0], [61, 0], [62, 0], [63, 0], [64, 0], [65, 0], [66, 0], [67, 0], [68, 0], [69, 0], [70, 0], [71, 0], [72, 0], [73, 0], [74, 0], [75, 0], [76, 0], [77, 0], [78, 0], [79, 0], [80, 0], [81, 0], [82, 0], [83, 0], [84, 0], [85, 0], [86, 0], [87, 0], [88, 0], [89, 0], [90, 0], [91, 0], [92, 0], [93, 0], [94, 0], [95, 0], [96, 0], [97, 0], [98, 0], [99, 0], [100, 0], [101, 0]]\", \"300\\n[[27,152],[6,13],[25,134],[12,32],[32,239],[0,0],[21,93],[19,76],[4,6],[34,267],[30,205],[299,382],[35,275],[11,31],[38,322],[3,3],[10,24],[33,254],[2,2],[37,303],[7,18],[40,368],[16,65],[18,69],[31,214],[14,51],[17,65],[22,98],[23,115],[9,20]]\", \"52\\n[[0, 0], [6, 0], [1, 1], [2, 2], [3, 2], [7, 6], [4, 7], [26, 7], [5, 9], [50, 9], [8, 11], [9, 24], [12, 25], [27, 29], [11, 35], [10, 38], [16, 42], [14, 47], [48, 60], [18, 61], [36, 61], [49, 61], [42, 71], [15, 86], [13, 88], [20, 96], [34, 108], [19, 110], [23, 119], [31, 132], [41, 142], [32, 144], [38, 144], [17, 151], [29, 158], [47, 162], [21, 171], [30, 173], [22, 176], [25, 192], [51, 195], [24, 196], [40, 196], [39, 271], [45, 288], [28, 300], [44, 303], [43, 306], [35, 318], [33, 326], [37, 390], [46, 397]]\", \"100\\n[[34,234],[39,330],[37,315],[26,148],[17,73],[41,377],[19,77],[31,191],[15,58],[16,61],[25,130],[14,46],[99,379],[1,1],[18,73],[4,9],[11,40],[5,9],[40,357],[30,191],[9,19],[0,0],[38,323],[32,203],[35,246],[3,6],[36,278],[33,216],[7,15],[10,29],[29,181],[12,45],[8,16]]\", \"2\\n[[1,0]]\", \"2\\n[[1,0]]\", \"100\\n[[28,167],[30,175],[2,1],[26,138],[1,0],[18,90],[13,45],[25,138],[3,3],[31,179],[21,106],[9,15],[34,216],[12,36],[5,4],[7,8],[4,3],[22,116],[14,58],[23,119],[39,326],[40,356],[10,20],[37,288],[38,305],[29,175],[99,384],[32,184],[17,86],[8,15],[6,6],[19,96]]\", \"300\\n[[0, 400], [1, 399], [2, 398], [3, 397], [4, 396], [5, 395], [6, 394], [7, 393], [8, 392], [9, 391], [10, 390], [11, 389], [12, 388], [13, 387], [14, 386], [15, 385], [16, 384], [17, 383], [18, 382], [19, 381], [20, 380], [21, 379], [22, 378], [23, 377], [24, 376], [25, 375], [26, 374], [27, 373], [28, 372], [29, 371], [30, 370], [31, 369], [32, 368], [33, 367], [34, 366], [35, 365], [36, 364], [37, 363], [38, 362], [39, 361], [40, 360], [41, 359], [42, 358], [43, 357], [44, 356], [45, 355], [46, 354], [47, 353], [48, 352], [49, 351], [50, 350], [51, 349], [52, 348], [53, 347], [54, 346], [55, 345], [56, 344], [57, 343], [58, 342], [59, 341], [60, 340], [61, 339], [62, 338], [63, 337], [64, 336], [65, 335], [66, 334], [67, 333], [68, 332], [69, 331], [70, 330], [71, 329], [72, 328], [73, 327], [74, 326], [75, 325], [76, 324], [77, 323], [78, 322], [79, 321], [80, 320], [81, 319], [82, 318], [83, 317], [84, 316], [85, 315], [86, 314], [87, 313], [88, 312], [89, 311], [90, 310], [91, 309], [92, 308], [93, 307], [94, 306], [95, 305], [96, 304], [97, 303], [98, 302], [99, 301], [100, 300], [101, 299], [102, 298], [103, 297], [104, 296], [105, 295], [106, 294], [107, 293], [108, 292], [109, 291], [110, 290], [111, 289], [112, 288], [113, 287], [114, 286], [115, 285], [116, 284], [117, 283], [118, 282], [119, 281], [120, 280], [121, 279], [122, 278], [123, 277], [124, 276], [125, 275], [126, 274], [127, 273], [128, 272], [129, 271], [130, 270], [131, 269], [132, 268], [133, 267], [134, 266], [135, 265], [136, 264], [137, 263], [138, 262], [139, 261], [140, 260], [141, 259], [142, 258], [143, 257], [144, 256], [145, 255], [146, 254], [147, 253], [148, 252], [149, 251], [150, 250], [151, 249], [152, 248], [153, 247], [154, 246], [155, 245], [156, 244], [157, 243], [158, 242], [159, 241], [160, 240], [161, 239], [162, 238], [163, 237], [164, 236], [165, 235], [166, 234], [167, 233], [168, 232], [169, 231], [170, 230], [171, 229], [172, 228], [173, 227], [174, 226], [175, 225], [176, 224], [177, 223], [178, 222], [179, 221], [180, 220], [181, 219], [182, 218], [183, 217], [184, 216], [185, 215], [186, 214], [187, 213], [188, 212], [189, 211], [190, 210], [191, 209], [192, 208], [193, 207], [194, 206], [195, 205], [196, 204], [197, 203], [198, 202], [199, 201], [200, 200], [201, 199], [202, 198], [203, 197], [204, 196], [205, 195], [206, 194], [207, 193], [208, 192], [209, 191], [210, 190], [211, 189], [212, 188], [213, 187], [214, 186], [215, 185], [216, 184], [217, 183], [218, 182], [219, 181], [220, 180], [221, 179], [222, 178], [223, 177], [224, 176], [225, 175], [226, 174], [227, 173], [228, 172], [229, 171], [230, 170], [231, 169], [232, 168], [233, 167], [234, 166], [235, 165], [236, 164], [237, 163], [238, 162], [239, 161], [240, 160], [241, 159], [242, 158], [243, 157], [244, 156], [245, 155], [246, 154], [247, 153], [248, 152], [249, 151], [250, 150], [251, 149], [252, 148], [253, 147], [254, 146], [255, 145], [256, 144], [257, 143], [258, 142], [259, 141], [260, 140], [261, 139], [262, 138], [263, 137], [264, 136], [265, 135], [266, 134], [267, 133], [268, 132], [269, 131], [270, 130], [271, 129], [272, 128], [273, 127], [274, 126], [275, 125], [276, 124], [277, 123], [278, 122], [279, 121], [280, 120], [281, 119], [282, 118], [283, 117], [284, 116], [285, 115], [286, 114], [287, 113], [288, 112], [289, 111], [290, 110], [291, 109], [292, 108], [293, 107], [294, 106], [295, 105], [296, 104], [297, 103], [298, 102], [299, 101]]\", \"3\\n[[1,0],[2,1],[0,0]]\", \"102\\n[[0, 0], [4, 0], [1, 1], [2, 2], [3, 4], [5, 6], [95, 6], [14, 13], [6, 14], [69, 14], [8, 16], [12, 17], [15, 20], [7, 23], [10, 23], [9, 39], [41, 42], [50, 43], [79, 45], [19, 46], [100, 47], [37, 48], [40, 49], [72, 50], [16, 53], [11, 54], [48, 62], [60, 65], [56, 66], [51, 67], [89, 71], [70, 72], [42, 78], [17, 80], [54, 82], [81, 82], [13, 91], [99, 91], [21, 93], [31, 93], [88, 110], [22, 114], [83, 120], [24, 123], [18, 130], [53, 130], [61, 131], [98, 133], [44, 134], [75, 135], [43, 141], [20, 142], [23, 147], [97, 151], [52, 153], [77, 156], [32, 160], [49, 172], [101, 175], [85, 176], [34, 182], [28, 184], [78, 184], [91, 184], [86, 185], [63, 192], [68, 193], [55, 196], [67, 204], [94, 207], [80, 209], [71, 215], [36, 229], [26, 232], [66, 236], [93, 250], [84, 253], [74, 255], [87, 265], [29, 283], [39, 287], [25, 288], [59, 292], [92, 296], [47, 298], [57, 303], [46, 309], [76, 310], [62, 314], [73, 318], [64, 326], [58, 331], [96, 336], [33, 347], [38, 349], [45, 349], [90, 354], [27, 367], [30, 368], [65, 371], [82, 378], [35, 392]]\", \"152\\n[[0, 0], [1, 0], [2, 3], [3, 1], [4, 3], [5, 12], [6, 2], [7, 0], [8, 16], [9, 36], [10, 38], [11, 55], [12, 30], [13, 87], [14, 94], [15, 54], [16, 135], [17, 5], [18, 135], [19, 182], [20, 76], [21, 186], [22, 96], [23, 211], [24, 261], [25, 45], [26, 72], [27, 154], [28, 32], [29, 183], [30, 349], [31, 88], [32, 274], [33, 435], [34, 528], [35, 244], [36, 397], [37, 371], [38, 167], [39, 328], [40, 568], [41, 754], [42, 288], [43, 78], [44, 964], [45, 606], [46, 704], [47, 600], [48, 1144], [49, 268], [50, 121], [51, 739], [52, 821], [53, 1140], [54, 1141], [55, 1037], [56, 124], [57, 1226], [58, 1320], [59, 70], [60, 1260], [61, 1643], [62, 295], [63, 787], [64, 359], [65, 1459], [66, 2204], [67, 1321], [68, 180], [69, 1657], [70, 2098], [71, 686], [72, 1797], [73, 1106], [74, 2568], [75, 2647], [76, 223], [77, 1064], [78, 43], [79, 35], [80, 3106], [81, 2139], [82, 1539], [83, 916], [84, 202], [85, 2613], [86, 3569], [87, 488], [88, 1862], [89, 331], [90, 1445], [91, 2367], [92, 2054], [93, 1791], [94, 2920], [95, 4446], [96, 3015], [97, 2452], [98, 674], [99, 696], [100, 4390], [101, 1961], [102, 3862], [103, 457], [104, 2212], [105, 4020], [106, 5448], [107, 2613], [108, 718], [109, 5082], [110, 185], [111, 3168], [112, 14], [113, 1692], [114, 841], [115, 1398], [116, 5995], [117, 1577], [118, 1634], [119, 1590], [120, 6536], [121, 5295], [122, 6600], [123, 6670], [124, 6024], [125, 3052], [126, 817], [127, 6675], [128, 7050], [129, 1383], [130, 6706], [131, 5617], [132, 8316], [133, 820], [134, 2811], [135, 8618], [136, 3772], [137, 2894], [138, 4806], [139, 3642], [140, 8910], [141, 6147], [142, 3217], [143, 3293], [144, 2452], [145, 3482], [146, 7481], [147, 3442], [148, 914], [149, 6538], [150, 3726], [151, 11055]]\", \"96\\n[[0, 0], [1, 1], [2, 3], [3, 6], [4, 10], [5, 15], [6, 21], [7, 28], [8, 36], [9, 45], [10, 55], [11, 66], [12, 78], [13, 91], [14, 105], [15, 120], [16, 136], [17, 153], [18, 171], [19, 190], [20, 210], [21, 231], [22, 253], [23, 276], [24, 300], [25, 325], [26, 351], [27, 378], [28, 400], [29, 400], [30, 400], [31, 400], [32, 400], [33, 400], [34, 400], [35, 400], [36, 400], [37, 400], [38, 400], [39, 400], [40, 400], [41, 400], [42, 400], [43, 400], [44, 400], [45, 400], [46, 400], [47, 400], [48, 400], [49, 400], [50, 400], [51, 400], [52, 400], [53, 400], [54, 400], [55, 400], [56, 400], [57, 400], [58, 400], [59, 400], [60, 400], [61, 400], [62, 400], [63, 400], [64, 400], [65, 400], [66, 400], [67, 400], [68, 400], [69, 400], [70, 400], [71, 400], [72, 400], [73, 400], [74, 400], [75, 400], [76, 400], [77, 400], [78, 400], [79, 400], [80, 400], [81, 400], [82, 400], [83, 400], [84, 400], [85, 400], [86, 400], [87, 400], [88, 400], [89, 400], [90, 400], [91, 400], [92, 400], [93, 400], [94, 400], [95, 400]]\", \"4\\n[[0, 0], [1, 1], [2, 0], [3, 2]]\", \"2\\n[[0, 0], [1, 0]]\", \"102\\n[[61, 400], [36, 12], [97, 400], [62, 60], [40, 387], [79, 400], [92, 94], [95, 400], [81, 400], [17, 140], [10, 1], [101, 400], [87, 400], [51, 400], [44, 63], [3, 4], [93, 400], [83, 400], [69, 400], [63, 400], [49, 400], [21, 190], [24, 69], [60, 330], [89, 400], [86, 85], [47, 400], [12, 33], [28, 104], [25, 222], [54, 321], [2, 1], [13, 53], [67, 400], [11, 65], [43, 400], [98, 195], [48, 27], [96, 205], [23, 222], [66, 336], [71, 400], [88, 187], [73, 400], [20, 33], [29, 362], [80, 243], [30, 60], [56, 198], [74, 81], [100, 28], [91, 400], [7, 17], [45, 400], [0, 0], [94, 367], [52, 258], [68, 47], [84, 356], [31, 260], [46, 68], [76, 30], [85, 400], [75, 400], [26, 50], [65, 400], [38, 10], [72, 381], [4, 2], [5, 7], [39, 393], [1, 1], [99, 400], [19, 104], [27, 235], [9, 24], [53, 400], [58, 109], [32, 22], [14, 32], [78, 218], [59, 400], [22, 102], [37, 399], [90, 154], [42, 123], [18, 3], [55, 400], [8, 11], [16, 57], [64, 350], [82, 53], [15, 94], [41, 400], [50, 92], [35, 333], [33, 330], [34, 160], [6, 7], [77, 400], [57, 400], [70, 8]]\", \"3\\n[[1,0],[2,0]]\", \"300\\n[[0, 0], [1, 1], [2, 0], [3, 0], [4, 6], [5, 0], [6, 19], [7, 15], [8, 33], [9, 21], [10, 39], [11, 59], [12, 65], [13, 54], [14, 5], [15, 50], [16, 69], [17, 91], [18, 157], [19, 56], [20, 101], [21, 199], [22, 5], [23, 197], [24, 68], [25, 145], [26, 182], [27, 221], [28, 320], [29, 29], [30, 363], [31, 32], [32, 185], [33, 100], [34, 198], [35, 297], [36, 134], [37, 185], [38, 392], [39, 82], [40, 28], [41, 124], [42, 300], [43, 354], [44, 62], [45, 181], [46, 262], [47, 69], [48, 249], [49, 296], [50, 37], [51, 340], [52, 362], [53, 39], [54, 187], [55, 341], [56, 167], [57, 313], [58, 290], [59, 173], [60, 127], [61, 329], [62, 36], [63, 279], [64, 236], [65, 2], [66, 160], [67, 189], [68, 150], [69, 54], [70, 140], [71, 334], [72, 330], [73, 139], [74, 33], [75, 102], [76, 56], [77, 120], [78, 226], [79, 239], [80, 256], [81, 161], [82, 381], [83, 145], [84, 389], [85, 265], [86, 361], [87, 247], [88, 111], [89, 43], [90, 159], [91, 358], [92, 177], [93, 290], [94, 365], [95, 264], [96, 218], [97, 285], [98, 147], [99, 344], [100, 333], [101, 360], [102, 283], [103, 3], [104, 217], [105, 137], [106, 174], [107, 374], [108, 236], [109, 120], [110, 396], [111, 367], [112, 177], [113, 170], [114, 326], [115, 66], [116, 158], [117, 356], [118, 94], [119, 163], [120, 189], [121, 327], [122, 72], [123, 192], [124, 87], [125, 173], [126, 388], [127, 361], [128, 52], [129, 17], [130, 146], [131, 203], [132, 330], [133, 317], [134, 364], [135, 306], [136, 217], [137, 62], [138, 218], [139, 400], [140, 379], [141, 18], [142, 373], [143, 113], [144, 194], [145, 201], [146, 65], [147, 87], [148, 75], [149, 243], [150, 121], [151, 318], [152, 138], [153, 78], [154, 77], [155, 363], [156, 24], [157, 124], [158, 262], [159, 309], [160, 45], [161, 2], [162, 43], [163, 291], [164, 215], [165, 293], [166, 235], [167, 227], [168, 281], [169, 103], [170, 259], [171, 266], [172, 93], [173, 326], [174, 5], [175, 135], [176, 261], [177, 10], [178, 298], [179, 370], [180, 52], [181, 143], [182, 248], [183, 333], [184, 238], [185, 61], [186, 52], [187, 278], [188, 361], [189, 125], [190, 225], [191, 335], [192, 256], [193, 390], [194, 242], [195, 275], [196, 229], [197, 91], [198, 65], [199, 342], [200, 196], [201, 369], [202, 51], [203, 127], [204, 36], [205, 73], [206, 210], [207, 256], [208, 346], [209, 386], [210, 273], [211, 147], [212, 159], [213, 155], [214, 17], [215, 367], [216, 242], [217, 221], [218, 32], [219, 256], [220, 389], [221, 237], [222, 227], [223, 49], [224, 302], [225, 58], [226, 128], [227, 46], [228, 121], [229, 119], [230, 343], [231, 195], [232, 46], [233, 59], [234, 318], [235, 135], [236, 331], [237, 400], [238, 281], [239, 390], [240, 305], [241, 305], [242, 31], [243, 311], [244, 165], [245, 157], [246, 111], [247, 221], [248, 139], [249, 11], [250, 339], [251, 58], [252, 325], [253, 249], [254, 230], [255, 281], [256, 304], [257, 295], [258, 349], [259, 124], [260, 332], [261, 343], [262, 332], [263, 318], [264, 110], [265, 99], [266, 104], [267, 383], [268, 172], [269, 234], [270, 175], [271, 77], [272, 241], [273, 295], [274, 294], [275, 294], [276, 134], [277, 124], [278, 142], [279, 56], [280, 361], [281, 76], [282, 75], [283, 163], [284, 18], [285, 1], [286, 126], [287, 290], [288, 49], [289, 379], [290, 139], [291, 155], [292, 162], [293, 298], [294, 198], [295, 311], [296, 229], [297, 34], [298, 121], [299, 340]]\", \"300\\n[[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11],[11,12],[12,13],[13,14],[14,15],[15,16],[16,17],[17,18],[18,19],[19,20],[20,21],[21,22],[22,23],[23,24],[24,25],[25,26],[26,27],[27,28],[28,29],[29,30],[30,31],[31,32],[32,33],[33,34],[34,35],[35,36],[36,37],[37,38],[38,39],[39,40],[40,41],[41,42],[42,43],[43,44],[44,45],[45,46],[46,47],[47,48],[48,49],[49,50],[50,51],[51,52],[52,53],[53,54],[54,55],[55,56],[56,57],[57,58],[58,59],[59,60],[60,61],[61,62],[62,63],[63,64],[64,65],[65,66],[66,67],[67,68],[68,69],[69,70],[70,71],[71,72],[72,73],[73,74],[74,75],[75,76],[76,77],[77,78],[78,79],[79,80],[80,81],[81,82],[82,83],[83,84],[84,85],[85,86],[86,87],[87,88],[88,89],[89,90],[90,91],[91,92],[92,93],[93,94],[94,95],[95,96],[96,97],[97,98],[98,99],[99,100],[100,101],[101,102],[102,103],[103,104],[104,105],[105,106],[106,107],[107,108],[108,109],[109,110],[110,111],[111,112],[112,113],[113,114],[114,115],[115,116],[116,117],[117,118],[118,119],[119,120],[120,121],[121,122],[122,123],[123,124],[124,125],[125,126],[126,127],[127,128],[128,129],[129,130],[130,131],[131,132],[132,133],[133,134],[134,135],[135,136],[136,137],[137,138],[138,139],[139,140],[140,141],[141,142],[142,143],[143,144],[144,145],[145,146],[146,147],[147,148],[148,149],[149,150],[150,151],[151,152],[152,153],[153,154],[154,155],[155,156],[156,157],[157,158],[158,159],[159,160],[160,161],[161,162],[162,163],[163,164],[164,165],[165,166],[166,167],[167,168],[168,169],[169,170],[170,171],[171,172],[172,173],[173,174],[174,175],[175,176],[176,177],[177,178],[178,179],[179,180],[180,181],[181,182],[182,183],[183,184],[184,185],[185,186],[186,187],[187,188],[188,189],[189,190],[190,191],[191,192],[192,193],[193,194],[194,195],[195,196],[196,197],[197,198],[198,199],[199,200],[200,201],[201,202],[202,203],[203,204],[204,205],[205,206],[206,207],[207,208],[208,209],[209,210],[210,211],[211,212],[212,213],[213,214],[214,215],[215,216],[216,217],[217,218],[218,219],[219,220],[220,221],[221,222],[222,223],[223,224],[224,225],[225,226],[226,227],[227,228],[228,229],[229,230],[230,231],[231,232],[232,233],[233,234],[234,235],[235,236],[236,237],[237,238],[238,239],[239,240],[240,241],[241,242],[242,243],[243,244],[244,245],[245,246],[246,247],[247,248],[248,249],[249,250],[250,251],[251,252],[252,253],[253,254],[254,255],[255,256],[256,257],[257,258],[258,259],[259,260],[260,261],[261,262],[262,263],[263,264],[264,265],[265,266],[266,267],[267,268],[268,269],[269,270],[270,271],[271,272],[272,273],[273,274],[274,275],[275,276],[276,277],[277,278],[278,279],[279,280],[280,281],[281,282],[282,283],[283,284],[284,285],[285,286],[286,287],[287,288],[288,289],[289,290],[290,291],[291,292],[292,293],[293,294],[294,295],[295,296],[296,297],[297,298],[298,299],[299,300]]\", \"3\\n[[0,0],[2,2]]\", \"257\\n[[0, 0], [7, 11], [9, 22], [13, 1], [14, 43], [25, 115], [26, 221], [31, 148], [34, 273], [38, 79], [40, 92], [41, 371], [42, 372], [43, 179], [47, 57], [49, 349], [52, 18], [57, 312], [62, 3], [65, 146], [67, 253], [68, 329], [71, 241], [72, 280], [73, 219], [75, 351], [80, 199], [82, 313], [83, 237], [84, 62], [86, 152], [87, 56], [98, 230], [106, 269], [109, 160], [111, 180], [112, 41], [113, 36], [115, 258], [116, 186], [117, 74], [124, 237], [127, 366], [129, 224], [135, 301], [137, 58], [139, 136], [141, 362], [144, 125], [151, 283], [153, 174], [154, 156], [156, 46], [157, 155], [161, 10], [167, 131], [173, 43], [177, 256], [178, 211], [181, 170], [184, 234], [186, 66], [189, 158], [196, 224], [199, 101], [200, 33], [203, 250], [205, 305], [207, 176], [209, 248], [212, 357], [216, 374], [217, 29], [220, 237], [224, 197], [225, 306], [228, 10], [229, 285], [233, 308], [236, 196], [239, 12], [241, 164], [242, 188], [243, 52], [249, 322], [250, 284], [256, 380]]\", \"3\\n[[0,0],[2,2]]\", \"150\\n[[15,68],[26,183],[21,124],[10,33],[30,197],[22,146],[5,1],[35,265],[6,7],[36,277],[3,1],[2,1],[14,56],[31,200],[23,165],[32,206],[24,165],[18,97],[11,34],[16,74],[34,239],[27,187],[17,87],[37,288],[149,393],[25,177],[29,196],[33,219],[1,1],[9,24]]\", \"20\\n[[0, 0], [1, 0], [2, 3], [3, 0], [4, 0], [5, 8], [8, 22], [9, 31], [11, 44], [12, 64], [14, 76], [16, 93], [18, 58], [19, 47]]\", \"3\\n[[2,1],[0,0],[1,0]]\", \"2\\n[[0, 2], [1, 2]]\", \"2\\n[[1,1]]\", \"2\\n[[1,0]]\", \"200\\n[[38,378],[24,111],[29,211],[7,8],[23,104],[33,286],[30,239],[18,75],[15,47],[27,172],[36,324],[37,345],[12,31],[4,2],[5,2],[32,257],[31,246],[11,29],[17,66],[8,14],[22,96],[21,95],[6,7],[35,307],[26,145],[3,2],[199,398]]\", \"6\\n[[4, 0], [5, 5]]\", \"3\\n[[1,0],[2,1],[0,0]]\", \"52\\n[[0, 0], [1, 1], [2, 1], [3, 3], [4, 10], [5, 6], [6, 13], [7, 18], [8, 6], [9, 31], [10, 53], [11, 24], [12, 23], [13, 60], [14, 93], [15, 72], [16, 49], [17, 40], [18, 77], [19, 100], [20, 187], [21, 194], [22, 51], [23, 129], [24, 136], [25, 139], [26, 77], [27, 75], [28, 175], [29, 93], [30, 274], [31, 247], [32, 77], [33, 458], [34, 58], [35, 313], [36, 335], [37, 376], [38, 236], [39, 52], [40, 473], [41, 508], [42, 604], [43, 607], [44, 918], [45, 798], [46, 879], [47, 1103], [48, 837], [49, 1099], [50, 1086], [51, 575]]\", \"98\\n[[0, 0], [1, 0], [2, 1], [3, 0], [6, 2], [7, 18], [8, 18], [9, 23], [10, 18], [11, 62], [12, 35], [13, 21], [14, 81], [15, 91], [16, 20], [18, 53], [19, 75], [21, 48], [23, 31], [29, 73], [31, 67], [34, 71], [35, 84], [36, 63], [37, 73], [38, 51], [39, 30], [40, 80], [41, 70], [43, 91], [44, 48], [45, 50], [46, 39], [47, 97], [48, 19], [49, 28], [51, 48], [52, 54], [54, 72], [55, 86], [57, 43], [58, 34], [59, 89], [60, 67], [61, 78], [64, 53], [65, 76], [66, 60], [67, 94], [68, 0], [71, 49], [72, 79], [73, 23], [74, 75], [75, 50], [77, 20], [78, 41], [79, 46], [82, 80], [83, 23], [84, 83], [86, 61], [87, 32], [88, 20], [89, 23], [90, 90], [91, 38], [92, 88], [94, 91], [95, 33], [96, 52], [97, 2]]\", \"215\\n[[0, 0], [1, 1], [2, 0], [3, 2], [4, 7], [5, 8], [6, 10], [7, 11], [8, 33], [9, 40], [10, 10], [11, 27], [12, 4], [13, 30], [14, 27], [15, 89], [16, 97], [17, 5], [18, 85], [19, 183], [20, 172], [21, 196], [23, 174], [24, 98], [25, 199], [26, 327], [27, 187], [29, 244], [30, 232], [31, 382], [32, 146], [33, 324], [34, 337], [35, 38], [36, 322], [37, 279], [38, 35], [40, 58], [41, 221], [42, 207], [44, 166], [45, 51], [46, 333], [47, 33], [48, 381], [49, 83], [50, 296], [51, 134], [52, 357], [54, 50], [56, 266], [57, 397], [58, 352], [59, 193], [60, 20], [61, 165], [62, 118], [63, 220], [64, 294], [65, 58], [66, 44], [67, 106], [68, 196], [69, 86], [70, 197], [71, 74], [72, 132], [73, 134], [74, 58], [75, 122], [76, 115], [77, 241], [78, 163], [79, 331], [80, 144], [81, 202], [82, 301], [83, 39], [86, 266], [87, 265], [88, 193], [89, 186], [90, 51], [91, 175], [92, 395], [93, 261], [96, 298], [97, 170], [98, 134], [99, 158], [100, 110], [101, 81], [102, 271], [103, 390], [104, 279], [105, 304], [106, 344], [107, 305], [108, 372], [109, 2], [110, 302], [111, 228], [112, 236], [113, 382], [114, 283], [115, 262], [116, 133], [117, 285], [118, 344], [119, 74], [121, 45], [122, 193], [124, 238], [125, 15], [126, 190], [127, 48], [130, 236], [131, 127], [132, 47], [133, 78], [134, 134], [135, 90], [136, 264], [137, 172], [138, 377], [139, 170], [140, 165], [141, 107], [142, 251], [143, 141], [145, 368], [146, 18], [147, 352], [148, 49], [149, 83], [150, 192], [151, 217], [153, 366], [154, 293], [155, 10], [156, 76], [157, 166], [158, 49], [159, 211], [160, 297], [161, 297], [162, 371], [163, 103], [165, 248], [166, 57], [167, 42], [168, 239], [169, 347], [170, 156], [171, 236], [172, 346], [173, 37], [175, 111], [176, 101], [177, 175], [178, 173], [180, 228], [181, 140], [182, 1], [183, 257], [185, 21], [186, 2], [188, 265], [189, 26], [190, 336], [191, 192], [192, 249], [193, 190], [194, 271], [195, 268], [196, 367], [197, 331], [198, 252], [199, 189], [200, 182], [201, 187], [202, 120], [203, 150], [204, 291], [205, 216], [206, 345], [207, 313], [209, 217], [210, 310], [211, 308], [212, 39], [213, 32], [214, 154]]\"], \"outputs\": [\"2\", \"1\", \"1\", \"0\", \"1\", \"1\", \"187501053\", \"0\", \"11398574\", \"1\", \"1\", \"441189139\", \"0\", \"1\", \"0\", \"0\", \"1\", \"0\", \"1\", \"0\", \"1\", \"0\", \"0\", \"2\", \"0\", \"2\", \"439851511\", \"0\", \"1\", \"0\", \"1\", \"1\", \"854380832\", \"1\", \"1\", \"0\", \"0\", \"0\"], \"fn_name\": \"numberOfPermutations\"}", "source": "lcbv5"}
|
You are given an integer n and a 2D array requirements, where requirements[i] = [end_i, cnt_i] represents the end index and the inversion count of each requirement.
A pair of indices (i, j) from an integer array nums is called an inversion if:
i < j and nums[i] > nums[j]
Return the number of permutations perm of [0, 1, 2, ..., n - 1] such that for all requirements[i], perm[0..end_i] has exactly cnt_i inversions.
Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
Input: n = 3, requirements = [[2,2],[0,0]]
Output: 2
Explanation:
The two permutations are:
[2, 0, 1]
Prefix [2, 0, 1] has inversions (0, 1) and (0, 2).
Prefix [2] has 0 inversions.
[1, 2, 0]
Prefix [1, 2, 0] has inversions (0, 2) and (1, 2).
Prefix [1] has 0 inversions.
Example 2:
Input: n = 3, requirements = [[2,2],[1,1],[0,0]]
Output: 1
Explanation:
The only satisfying permutation is [2, 0, 1]:
Prefix [2, 0, 1] has inversions (0, 1) and (0, 2).
Prefix [2, 0] has an inversion (0, 1).
Prefix [2] has 0 inversions.
Example 3:
Input: n = 2, requirements = [[0,0],[1,0]]
Output: 1
Explanation:
The only satisfying permutation is [0, 1]:
Prefix [0] has 0 inversions.
Prefix [0, 1] has an inversion (0, 1).
Constraints:
2 <= n <= 300
1 <= requirements.length <= n
requirements[i] = [end_i, cnt_i]
0 <= end_i <= n - 1
0 <= cnt_i <= 400
The input is generated such that there is at least one i such that end_i == n - 1.
The input is generated such that all end_i are unique.
You will use the following starter code to write the solution to the problem and enclose your code within ```python delimiters.
```python
class Solution:
def numberOfPermutations(self, n: int, requirements: List[List[int]]) -> int:
```
| 0
|
{"tests": "{\"inputs\": [\"10\\nhttp://abacaba.ru/test\\nhttp://abacaba.ru/\\nhttp://abacaba.com\\nhttp://abacaba.com/test\\nhttp://abacaba.de/\\nhttp://abacaba.ru/test\\nhttp://abacaba.de/test\\nhttp://abacaba.com/\\nhttp://abacaba.com/t\\nhttp://abacaba.com/test\\n\", \"14\\nhttp://c\\nhttp://ccc.bbbb/aba..b\\nhttp://cba.com\\nhttp://a.c/aba..b/a\\nhttp://abc/\\nhttp://a.c/\\nhttp://ccc.bbbb\\nhttp://ab.ac.bc.aa/\\nhttp://a.a.a/\\nhttp://ccc.bbbb/\\nhttp://cba.com/\\nhttp://cba.com/aba..b\\nhttp://a.a.a/aba..b/a\\nhttp://abc/aba..b/a\\n\", \"10\\nhttp://tqr.ekdb.nh/w\\nhttp://p.ulz/ifw\\nhttp://w.gw.dw.xn/kpe\\nhttp://byt.mqii.zkv/j/xt\\nhttp://ovquj.rbgrlw/k..\\nhttp://bv.plu.e.dslg/j/xt\\nhttp://udgci.ufgi.gwbd.s/\\nhttp://l.oh.ne.o.r/.vo\\nhttp://l.oh.ne.o.r/w\\nhttp://tqr.ekdb.nh/.vo\\n\", \"12\\nhttp://ickght.ck/mr\\nhttp://a.exhel/.b\\nhttp://a.exhel/\\nhttp://ti.cdm/\\nhttp://ti.cdm/x/wd/lm.h.\\nhttp://ickght.ck/a\\nhttp://ickght.ck\\nhttp://c.gcnk.d/.b\\nhttp://c.gcnk.d/x/wd/lm.h.\\nhttp://ti.cdm/.b\\nhttp://a.exhel/x/wd/lm.h.\\nhttp://c.gcnk.d/\\n\", \"14\\nhttp://jr/kgb\\nhttp://ps.p.t.jeua.x.a.q.t\\nhttp://gsqqs.n/t/\\nhttp://w.afwsnuc.ff.km/cohox/u.\\nhttp://u.s.wbumkuqm/\\nhttp://u.s.wbumkuqm/cohox/u.\\nhttp://nq.dzjkjcwv.f.s/bvm/\\nhttp://zoy.shgg\\nhttp://gsqqs.n\\nhttp://u.s.wbumkuqm/b.pd.\\nhttp://w.afwsnuc.ff.km/\\nhttp://w.afwsnuc.ff.km/b.pd.\\nhttp://nq.dzjkjcwv.f.s/n\\nhttp://nq.dzjkjcwv.f.s/ldbw\\n\", \"15\\nhttp://l.edzplwqsij.rw/\\nhttp://m.e.mehd.acsoinzm/s\\nhttp://yg.ttahn.xin.obgez/ap/\\nhttp://qqbb.pqkaqcncodxmaae\\nhttp://lzi.a.flkp.lnn.k/o/qfr.cp\\nhttp://lzi.a.flkp.lnn.k/f\\nhttp://p.ngu.gkoq/.szinwwi\\nhttp://qqbb.pqkaqcncodxmaae/od\\nhttp://qqbb.pqkaqcncodxmaae\\nhttp://wsxvmi.qpe.fihtgdvi/e./\\nhttp://p.ngu.gkoq/zfoh\\nhttp://m.e.mehd.acsoinzm/xp\\nhttp://c.gy.p.h.tkrxt.jnsjt/j\\nhttp://wsxvmi.qpe.fihtgdvi/grkag.z\\nhttp://p.ngu.gkoq/t\\n\", \"15\\nhttp://w.hhjvdn.mmu/.ca.p\\nhttp://m.p.p.lar/\\nhttp://lgmjun.r.kogpr.ijn/./t\\nhttp://bapchpl.mcw.a.lob/d/ym/./g.q\\nhttp://uxnjfnjp.kxr.ss.e.uu/jwo./hjl/\\nhttp://fd.ezw.ykbb.xhl.t/\\nhttp://i.xcb.kr/.ca.p\\nhttp://jofec.ry.fht.gt\\nhttp://qeo.gghwe.lcr/d/ym/./g.q\\nhttp://gt\\nhttp://gjvifpf.d/d/ym/./g.q\\nhttp://oba\\nhttp://rjs.qwd/v/hi\\nhttp://fgkj/\\nhttp://ivun.naumc.l/.ca.p\\n\", \"20\\nhttp://gjwr/xsoiagp/\\nhttp://gdnmu/j\\nhttp://yfygudx.e.aqa.ezh/j\\nhttp://mpjxue.cuvipq/\\nhttp://a/\\nhttp://kr/..n/c.\\nhttp://a/xsoiagp/\\nhttp://kr/z\\nhttp://kr/v.cv/rk/k\\nhttp://lvhpz\\nhttp://qv.v.jqzhq\\nhttp://y.no/\\nhttp://kr/n\\nhttp://y.no/xsoiagp/\\nhttp://kr/ebe/z/\\nhttp://olsvbxxw.win.n/j\\nhttp://p.ct/j\\nhttp://mpjxue.cuvipq/xsoiagp/\\nhttp://kr/j\\nhttp://gjwr/\\n\", \"1\\nhttp://a\\n\", \"1\\nhttp://a.a.a.f.r.f.q.e.w.a/fwe..sdfv....\\n\", \"3\\nhttp://abacaba.com/test\\nhttp://abacaba.de/test\\nhttp://abacaba.de/test\\n\"], \"outputs\": [\"1\\nhttp://abacaba.de http://abacaba.ru \\n\", \"2\\nhttp://cba.com http://ccc.bbbb \\nhttp://a.a.a http://a.c http://abc \\n\", \"2\\nhttp://l.oh.ne.o.r http://tqr.ekdb.nh \\nhttp://bv.plu.e.dslg http://byt.mqii.zkv \\n\", \"1\\nhttp://a.exhel http://c.gcnk.d http://ti.cdm \\n\", \"2\\nhttp://ps.p.t.jeua.x.a.q.t http://zoy.shgg \\nhttp://u.s.wbumkuqm http://w.afwsnuc.ff.km \\n\", \"0\\n\", \"4\\nhttp://gt http://jofec.ry.fht.gt http://oba \\nhttp://fd.ezw.ykbb.xhl.t http://fgkj http://m.p.p.lar \\nhttp://i.xcb.kr http://ivun.naumc.l http://w.hhjvdn.mmu \\nhttp://bapchpl.mcw.a.lob http://gjvifpf.d http://qeo.gghwe.lcr \\n\", \"3\\nhttp://lvhpz http://qv.v.jqzhq \\nhttp://a http://gjwr http://mpjxue.cuvipq http://y.no \\nhttp://gdnmu http://olsvbxxw.win.n http://p.ct http://yfygudx.e.aqa.ezh \\n\", \"0\\n\", \"0\\n\", \"1\\nhttp://abacaba.com http://abacaba.de \\n\"]}", "source": "primeintellect"}
|
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
<hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
<hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct.
-----Output-----
First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order.
-----Examples-----
Input
10
http://abacaba.ru/test
http://abacaba.ru/
http://abacaba.com
http://abacaba.com/test
http://abacaba.de/
http://abacaba.ru/test
http://abacaba.de/test
http://abacaba.com/
http://abacaba.com/t
http://abacaba.com/test
Output
1
http://abacaba.de http://abacaba.ru
Input
14
http://c
http://ccc.bbbb/aba..b
http://cba.com
http://a.c/aba..b/a
http://abc/
http://a.c/
http://ccc.bbbb
http://ab.ac.bc.aa/
http://a.a.a/
http://ccc.bbbb/
http://cba.com/
http://cba.com/aba..b
http://a.a.a/aba..b/a
http://abc/aba..b/a
Output
2
http://cba.com http://ccc.bbbb
http://a.a.a http://a.c http://abc
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"19 29\\n\", \"3 6\\n\", \"39 91\\n\", \"76 134\\n\", \"93 95\\n\", \"17 35\\n\", \"94 95\\n\", \"51 52\\n\", \"47 52\\n\", \"38 98\\n\", \"30 37\\n\", \"56 92\\n\", \"900000000 1000000000\\n\", \"37622224 162971117\\n\", \"760632746 850720703\\n\", \"908580370 968054552\\n\", \"951594860 953554446\\n\", \"347877978 913527175\\n\", \"620769961 988145114\\n\", \"820844234 892579936\\n\", \"741254764 741254768\\n\", \"80270976 80270977\\n\", \"392602363 392602367\\n\", \"519002744 519002744\\n\", \"331900277 331900277\\n\", \"419873015 419873018\\n\", \"349533413 349533413\\n\", \"28829775 28829776\\n\", \"568814539 568814539\\n\", \"720270740 720270743\\n\", \"871232720 871232722\\n\", \"305693653 305693653\\n\", \"634097178 634097179\\n\", \"450868287 450868290\\n\", \"252662256 252662260\\n\", \"575062045 575062049\\n\", \"273072892 273072894\\n\", \"770439256 770439256\\n\", \"2 1000000000\\n\", \"6 8\\n\", \"2 879190747\\n\", \"5 5\\n\", \"999999937 999999937\\n\", \"3 3\\n\", \"5 100\\n\", \"2 2\\n\", \"3 18\\n\", \"7 7\\n\", \"39916801 39916801\\n\", \"3 8\\n\", \"13 13\\n\", \"4 8\\n\", \"3 12\\n\", \"6 12\\n\", \"999999103 999999103\\n\", \"100000007 100000007\\n\", \"3 99\\n\", \"999999733 999999733\\n\", \"5 10\\n\", \"982451653 982451653\\n\", \"999900001 1000000000\\n\", \"999727999 999727999\\n\", \"2 999999999\\n\", \"242 244\\n\", \"3 10\\n\", \"15 27\\n\", \"998244353 998244353\\n\", \"5 15\\n\", \"999999797 999999797\\n\", \"2 3\\n\", \"999999929 999999929\\n\", \"3 111111\\n\", \"12 18\\n\", \"479001599 479001599\\n\", \"10000019 10000019\\n\", \"715827883 715827883\\n\", \"999992977 999992977\\n\", \"11 11\\n\", \"29 29\\n\", \"1000003 1000003\\n\", \"6 15\\n\", \"1200007 1200007\\n\", \"3 1000000000\\n\", \"990000023 990000023\\n\", \"1717 1717\\n\", \"141650963 141650963\\n\", \"1002523 1002523\\n\", \"900000011 900000011\\n\", \"104729 104729\\n\", \"4 12\\n\", \"100003 100003\\n\", \"17 17\\n\", \"10 100\\n\"], \"outputs\": [\"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"519002744\\n\", \"331900277\\n\", \"2\\n\", \"349533413\\n\", \"2\\n\", \"568814539\\n\", \"2\\n\", \"2\\n\", \"305693653\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"770439256\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"5\\n\", \"999999937\\n\", \"3\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"7\\n\", \"39916801\\n\", \"2\\n\", \"13\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"999999103\\n\", \"100000007\\n\", \"2\\n\", \"999999733\\n\", \"2\\n\", \"982451653\\n\", \"2\\n\", \"999727999\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"998244353\\n\", \"2\\n\", \"999999797\\n\", \"2\\n\", \"999999929\\n\", \"2\\n\", \"2\\n\", \"479001599\\n\", \"10000019\\n\", \"715827883\\n\", \"999992977\\n\", \"11\\n\", \"29\\n\", \"1000003\\n\", \"2\\n\", \"1200007\\n\", \"2\\n\", \"990000023\\n\", \"1717\\n\", \"141650963\\n\", \"1002523\\n\", \"900000011\\n\", \"104729\\n\", \"2\\n\", \"100003\\n\", \"17\\n\", \"2\\n\"]}", "source": "primeintellect"}
|
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
-----Input-----
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 10^9).
-----Output-----
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
-----Examples-----
Input
19 29
Output
2
Input
3 6
Output
3
-----Note-----
Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"5 5 20 25\\n1 2 25\\n2 3 25\\n3 4 20\\n4 5 20\\n5 1 20\\n\", \"6 7 13 22\\n1 2 13\\n2 3 13\\n1 4 22\\n3 4 13\\n4 5 13\\n5 6 13\\n6 1 13\\n\", \"2 1 1 2\\n2 1 1\\n\", \"2 1 9999999 10000000\\n1 2 10000000\\n\", \"3 3 78422 6789101\\n3 1 6789101\\n2 1 78422\\n2 3 78422\\n\", \"3 3 2770628 3912422\\n1 2 2770628\\n2 3 2770628\\n1 3 3912422\\n\", \"3 3 2566490 5132980\\n1 2 2566490\\n2 3 2566490\\n3 1 5132980\\n\", \"3 2 509529 5982470\\n1 2 509529\\n3 2 509529\\n\", \"3 2 1349740 8457492\\n2 1 1349740\\n3 1 1349740\\n\", \"3 2 150319 5002968\\n3 2 150319\\n1 2 5002968\\n\", \"3 2 990530 8623767\\n3 2 8623767\\n1 2 990530\\n\", \"3 2 810925 2022506\\n1 2 2022506\\n1 3 810925\\n\", \"3 2 1651136 5131013\\n1 2 5131013\\n3 2 5131013\\n\", \"3 2 451715 1577270\\n1 3 1577270\\n1 2 1577270\\n\", \"3 3 1291926 4943478\\n2 3 1291926\\n1 2 1291926\\n3 1 1291926\\n\", \"3 3 2132137 9084127\\n1 2 2132137\\n3 2 9084127\\n3 1 2132137\\n\", \"3 3 1126640 9858678\\n3 1 9858678\\n3 2 1126640\\n1 2 9858678\\n\", \"3 3 1966851 6439891\\n1 3 6439891\\n1 2 1966851\\n3 2 6439891\\n\", \"3 3 1787246 7806211\\n3 2 7806211\\n2 1 7806211\\n1 3 7806211\\n\"], \"outputs\": [\"0 25 60 40 20\\n\", \"0 13 26 39 26 13\\n\", \"0 1\\n\", \"0 10000000\\n\", \"0 78422 156844\\n\", \"0 2770628 5541256\\n\", \"0 2566490 5132980\\n\", \"0 509529 1019058\\n\", \"0 1349740 1349740\\n\", \"0 5002968 5153287\\n\", \"0 990530 9614297\\n\", \"0 2022506 810925\\n\", \"0 5131013 10262026\\n\", \"0 1577270 1577270\\n\", \"0 1291926 1291926\\n\", \"0 2132137 2132137\\n\", \"0 9858678 9858678\\n\", \"0 1966851 6439891\\n\", \"0 7806211 7806211\\n\"]}", "source": "primeintellect"}
|
Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be equal either to $a$ or $b$ seconds. It's guaranteed that one can go between any pair of settlements by following a sequence of roads.
Codefortia was recently struck by the financial crisis. Therefore, the king decided to abandon some of the roads so that:
it will be possible to travel between each pair of cities using the remaining roads only, the sum of times required to pass each remaining road will be minimum possible (in other words, remaining roads must form minimum spanning tree, using the time to pass the road as its weight), among all the plans minimizing the sum of times above, the time required to travel between the king's residence (in settlement $1$) and the parliament house (in settlement $p$) using the remaining roads only will be minimum possible.
The king, however, forgot where the parliament house was. For each settlement $p = 1, 2, \dots, n$, can you tell what is the minimum time required to travel between the king's residence and the parliament house (located in settlement $p$) after some roads are abandoned?
-----Input-----
The first line of the input contains four integers $n$, $m$, $a$ and $b$ ($2 \leq n \leq 70$, $n - 1 \leq m \leq 200$, $1 \leq a < b \leq 10^7$) — the number of settlements and gravel roads in Codefortia, and two possible travel times. Each of the following lines contains three integers $u, v, c$ ($1 \leq u, v \leq n$, $u \neq v$, $c \in \{a, b\}$) denoting a single gravel road between the settlements $u$ and $v$, which requires $c$ minutes to travel.
You can assume that the road network is connected and has no loops or multiedges.
-----Output-----
Output a single line containing $n$ integers. The $p$-th of them should denote the minimum possible time required to travel from $1$ to $p$ after the selected roads are abandoned. Note that for each $p$ you can abandon a different set of roads.
-----Examples-----
Input
5 5 20 25
1 2 25
2 3 25
3 4 20
4 5 20
5 1 20
Output
0 25 60 40 20
Input
6 7 13 22
1 2 13
2 3 13
1 4 22
3 4 13
4 5 13
5 6 13
6 1 13
Output
0 13 26 39 26 13
-----Note-----
The minimum possible sum of times required to pass each road in the first example is $85$ — exactly one of the roads with passing time $25$ must be abandoned. Note that after one of these roads is abandoned, it's now impossible to travel between settlements $1$ and $3$ in time $50$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"10 5\\n\", \"4 2\\n\", \"4 1\\n\", \"1 1\\n\", \"63 1\\n\", \"98 88\\n\", \"746 173\\n\", \"890 553\\n\", \"883 1000\\n\", \"1 1000\\n\", \"695 188\\n\", \"2060 697\\n\", \"70 3321\\n\", \"6358 1646\\n\", \"15000 1\\n\", \"1048576 1\\n\", \"1000000 1\\n\", \"10009 1\\n\", \"10001 1\\n\"], \"outputs\": [\"6\\n1 1 1 7 13 19 \", \"3\\n1 1 4 \", \"3\\n1 1 3 \", \"1\\n1 \", \"21\\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 \", \"15\\n1 1 1 1 1 1 90 90 90 90 90 179 268 357 446 \", \"37\\n1 1 1 1 1 1 1 1 1 175 175 175 175 175 175 175 349 349 349 349 349 349 523 523 523 523 523 697 697 697 871 1045 1219 1393 1567 1741 1915 \", \"43\\n1 1 1 1 1 1 1 1 1 555 555 555 555 555 555 555 555 1109 1109 1109 1109 1109 1109 1663 1663 1663 1663 1663 2217 2217 2217 2217 2771 2771 2771 3325 3879 4433 4987 5541 6095 6649 7203 \", \"40\\n1 1 1 1 1 1 1 1 1 1002 1002 1002 1002 1002 1002 1002 1002 2003 2003 2003 2003 2003 2003 3004 3004 3004 3004 3004 4005 4005 4005 4005 5006 6007 7008 8009 9010 10011 11012 12013 \", \"1\\n1 \", \"35\\n1 1 1 1 1 1 1 1 1 190 190 190 190 190 190 190 379 379 379 379 379 568 568 568 568 757 757 946 1135 1324 1513 1702 1891 2080 2269 \", \"19\\n1 1 1 1 1 1 1 1 1 1 1 699 699 699 1397 1397 2095 2793 3491 \", \"12\\n1 1 1 1 1 1 3323 3323 6645 9967 13289 16611 \", \"50\\n1 1 1 1 1 1 1 1 1 1 1 1 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 3295 3295 3295 3295 3295 3295 3295 4942 4942 4942 4942 4942 4942 6589 6589 6589 6589 8236 8236 9883 11530 13177 14824 16471 18118 19765 21412 \", \"66\\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 11 11 11 11 13 13 13 15 17 19 21 23 25 27 \", \"21\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 \", \"106\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 15 17 19 21 23 25 27 \", \"54\\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 11 11 13 15 17 19 21 23 25 \", \"50\\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 13 15 17 19 21 \"]}", "source": "primeintellect"}
|
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 ≤ X, d ≤ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 ≤ n ≤ 10 000)— the number of integers in the final array.
Second line should consist of n space separated integers — a_1, a_2, ... , a_{n} (1 ≤ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"technocup\\n\", \"tictictactac\\n\", \"bbaabaabbb\\n\", \"cbbbbcaaca\\n\", \"cadbcdddda\\n\", \"bababbdaee\\n\", \"fabbbhgedd\\n\", \"gaejllebhn\\n\", \"bbababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbb\\n\", \"eaaebccaeacdecaedcaabbbdeebccdcdaabeeaeeaddbaabdccebecebbbbedbdcbbbbbbecbaddcddcccdcbbadbecddecedbba\\n\", \"hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb\\n\", \"difhjdjbcdjedhiegagdejkbjfcdcdagdijdjajecbheiabfbjdgjdecfhdkgdbkcgcgakkiiggfkgcfadkjhiijkjacgejfhjge\\n\", \"khjcoijiicdkdianmdolmadobdkcmgifdnffddnjehhbldlkjffknficdcmokfacioiegjedbmadjioomdacbodcajcmonmnlabo\\n\", \"kpsaloedscghjeaqadfhmlibjepjafdomkkorinrpakondtnrnknbqarbejcenrlsbfgdbsdmkpphbkdnbitjfcofsjibssmmlll\\n\", \"jkeaagakbifeaechkifkdghcjcgighidcgdccfbdbcackfgaebkddabgijkhjkaffkabacekdkjekeccegbecbkecbgbgcacgdackcdfjefaifgbigahkbedidfhjbikejdhejcgideaeejdcegeeccaefbddejkbdkfagfcdjbikbidfggkidcdcic\\n\", \"ibledofnibedebifmnjdoaijeghajecbkjaebbkofnacceaodiifbhgkihkibddneeiemacodeafeaiiiaoajhmkjffbmmiehebhokfklhbkeoanoajdedjdlkbhenidclagggfhhhldfleccgmjbkhaginlhabkabagikalccndciokabfaebjkndf\\n\", \"aaabbbaaaabbbbaaabbbbbaabbbbaaababbaaabbbbaaabbbbababbbbaaabbbbaaabbbbbaabbbbaaabbbbaaabbbb\\n\", \"abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab\\n\", \"abbacba\\n\"], \"outputs\": [\"1.000000000000000\\n\", \"0.333333333333333\\n\", \"0.100000000000000\\n\", \"0.800000000000000\\n\", \"0.800000000000000\\n\", \"1.000000000000000\\n\", \"1.000000000000000\\n\", \"1.000000000000000\\n\", \"0.000000000000000\\n\", \"0.080000000000000\\n\", \"0.450000000000000\\n\", \"0.840000000000000\\n\", \"0.960000000000000\\n\", \"1.000000000000000\\n\", \"0.438502673796791\\n\", \"0.786096256684492\\n\", \"0.000000000000000\\n\", \"0.000000000000000\\n\", \"1.000000000000000\\n\"]}", "source": "primeintellect"}
|
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = s_{k} + 1s_{k} + 2... s_{n}s_1s_2... s_{k}. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
-----Input-----
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
-----Output-----
Print the only number — the answer for the problem. You answer is considered correct, if its absolute or relative error does not exceed 10^{ - 6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$
-----Examples-----
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
-----Note-----
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"15\\n1/3 2/1\\n3 1\\n6 2\\n4 2\\n2 5\\n4 5\\n6 6\\n3 4\\n1 6\\n2 1\\n7 4\\n9 3\\n5 3\\n1 3\\n15 5\\n12 4\\n\", \"15\\n2/1 2/0\\n3 1\\n6 2\\n9 3\\n12 4\\n15 5\\n2 1\\n4 2\\n5 3\\n7 4\\n1 3\\n3 4\\n2 5\\n4 5\\n1 6\\n6 6\\n\", \"15\\n2/1 2/0\\n3 1\\n6 2\\n9 3\\n12 4\\n15 5\\n2 1\\n4 2\\n5 3\\n7 4\\n1 3\\n3 4\\n2 6\\n4 5\\n1 6\\n6 6\\n\", \"15\\n1/4 2/1\\n3 1\\n6 2\\n9 3\\n12 4\\n15 5\\n2 1\\n4 2\\n5 3\\n7 4\\n1 3\\n3 4\\n2 5\\n4 5\\n1 6\\n6 6\\n\", \"5\\n3/24 24/3\\n31394 23366\\n27990 71363\\n33642 36903\\n79731 10588\\n10907 5058\\n\", \"5\\n3/18 18/17\\n84697 26074\\n16334 31084\\n38824 37740\\n1288 50582\\n87807 48721\\n\", \"5\\n3/18 18/17\\n5148 38615\\n84759 63111\\n16345 23100\\n49727 20597\\n43590 46573\\n\", \"5\\n3/18 18/17\\n49797 95131\\n5075 96918\\n91898 7865\\n91852 41070\\n12076 45049\\n\", \"5\\n3/18 18/17\\n43008 52460\\n68903 46619\\n16613 30280\\n66639 17904\\n83797 83401\\n\", \"5\\n3/18 18/17\\n66980 84763\\n69224 39\\n62888 61748\\n53474 234\\n77487 94808\\n\", \"5\\n3/18 18/17\\n35429 29897\\n89928 67711\\n29047 22691\\n84838 6917\\n32683 99009\\n\", \"5\\n3/18 18/17\\n62344 72564\\n31069 2824\\n74485 34763\\n61186 78544\\n75470 51019\\n\", \"5\\n27/18 27/17\\n27746 42830\\n22071 47985\\n44242 62799\\n16038 48367\\n85158 21622\\n\", \"5\\n27/18 27/17\\n91659 76441\\n96317 38081\\n99805 94867\\n79758 84753\\n96445 53616\\n\", \"5\\n27/18 27/17\\n85006 4046\\n10811 30171\\n97316 32923\\n73899 71559\\n76723 17949\\n\", \"5\\n0/17 74/0\\n24922 93126\\n75686 80827\\n33683 91759\\n10584 66980\\n58159 52129\\n\", \"5\\n0/17 74/0\\n69711 29703\\n91677 56040\\n26051 78244\\n20816 40897\\n70770 35908\\n\", \"5\\n0/17 74/0\\n68877 18122\\n96115 84747\\n71027 43746\\n31622 3444\\n93281 34803\\n\", \"5\\n3/24 24/3\\n31394 23366\\n27990 71363\\n33642 36903\\n79731 10588\\n10907 5058\\n\"], \"outputs\": [\"4\\n\", \"1\\n\", \"2\\n\", \"5\\n\", \"3\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"3\\n\"]}", "source": "primeintellect"}
|
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α_1 and α_2 to the OX axis.
[Image]
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α_1 and α_2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
[Image]
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that $\frac{a}{b} = \frac{\operatorname{sin} \alpha_{1}}{\operatorname{cos} \alpha_{1}}$ and $\frac{c}{d} = \frac{\operatorname{sin} \alpha_{2}}{\operatorname{cos} \alpha}$ (0 ≤ a, b, c, d ≤ 10^5; $0^{\circ} \leq \alpha_{1} < \alpha_{2} \leq 90^{\circ}$; $\frac{a}{b} \neq \frac{0}{0}$; $\frac{c}{d} \neq \frac{0}{0}$). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers x_{i}, y_{i} (1 ≤ x_{i}, y_{i} ≤ 10^5)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
-----Output-----
In a single line print number m — the answer to the problem.
-----Examples-----
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
-----Note-----
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
[Image]
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 4\\n2 5 6\\n1 3 6 8\\n\", \"3 3\\n1 2 3\\n1 2 3\\n\", \"1 2\\n165\\n142 200\\n\", \"1 2\\n5000000000\\n1 10000000000\\n\", \"2 4\\n3 12\\n1 7 8 14\\n\", \"3 3\\n1 2 3\\n2 3 4\\n\", \"2 1\\n1 10\\n9\\n\", \"3 19\\n7 10 13\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\\n\", \"3 3\\n2 3 4\\n1 3 5\\n\", \"10 11\\n1 909090909 1818181817 2727272725 3636363633 4545454541 5454545449 6363636357 7272727265 8181818173\\n454545455 1363636363 2272727271 3181818179 4090909087 4999999995 5909090903 6818181811 7727272719 8636363627 9545454535\\n\", \"3 10\\n4999999999 5000000000 5000000001\\n1 1000 100000 1000000 4999999999 5000000000 5000000001 6000000000 8000000000 10000000000\\n\", \"2 4\\n4500000000 5500000000\\n5 499999999 5000000001 9999999995\\n\", \"10 10\\n331462447 1369967506 1504296131 2061390288 2309640071 3006707770 4530801731 4544099460 7357049371 9704808257\\n754193799 3820869903 4594383880 5685752675 6303322854 6384906441 7863448848 8542634752 9573124462 9665646063\\n\", \"1 1\\n10000000000\\n1\\n\", \"1 1\\n1\\n10000000000\\n\", \"10 10\\n9999999991 9999999992 9999999993 9999999994 9999999995 9999999996 9999999997 9999999998 9999999999 10000000000\\n1 2 3 4 5 6 7 8 9 10\\n\", \"3 12\\n477702277 4717363935 8947981095\\n477702276 477702304 477702312 477702317 4717363895 4717363896 4717363920 4717363936 8947981094 8947981111 8947981112 8947981135\\n\", \"10 10\\n389151626 1885767612 2609703695 3054567325 4421751790 5636236054 6336088034 7961001379 8631992167 9836923433\\n389144165 389158510 1885760728 1885775073 2609696234 2609710579 3054559864 3054574209 4421744329 4421758674\\n\", \"1 1\\n10000000000\\n1\\n\"], \"outputs\": [\"2\\n\", \"0\\n\", \"81\\n\", \"14999999998\\n\", \"8\\n\", \"1\\n\", \"1\\n\", \"6\\n\", \"1\\n\", \"1363636362\\n\", \"4999999999\\n\", \"5499999993\\n\", \"1840806981\\n\", \"9999999999\\n\", \"9999999999\\n\", \"9999999990\\n\", \"42\\n\", \"21229\\n\", \"9999999999\\n\"]}", "source": "primeintellect"}
|
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the i-th reading head is above the track number h_{i}. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered h_1, h_2, ..., h_{n} have been read at the beginning of the operation. [Image]
Mike needs to read the data on m distinct tracks with numbers p_1, p_2, ..., p_{m}. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.
-----Input-----
The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers h_{i} in ascending order (1 ≤ h_{i} ≤ 10^10, h_{i} < h_{i} + 1) — the initial positions of the heads. The third line contains m distinct integers p_{i} in ascending order (1 ≤ p_{i} ≤ 10^10, p_{i} < p_{i} + 1) - the numbers of tracks to read.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
-----Output-----
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
-----Examples-----
Input
3 4
2 5 6
1 3 6 8
Output
2
Input
3 3
1 2 3
1 2 3
Output
0
Input
1 2
165
142 200
Output
81
-----Note-----
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way: during the first second move the 1-st head to the left and let it stay there; move the second head to the left twice; move the third head to the right twice (note that the 6-th track has already been read at the beginning).
One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n999999 0\\n0 999999\\n999999 0\\n\", \"1\\n-824590 246031\\n\", \"8\\n-67761 603277\\n640586 -396671\\n46147 -122580\\n569609 -2112\\n400 914208\\n131792 309779\\n-850150 -486293\\n5272 721899\\n\", \"6\\n1000000 0\\n1000000 0\\n-1000000 0\\n0 1000000\\n0 -1000000\\n0 -1000000\\n\", \"8\\n-411248 143802\\n300365 629658\\n363219 343742\\n396148 -94037\\n-722124 467785\\n-178147 -931253\\n265458 73307\\n-621502 -709713\\n\", \"3\\n1000000 0\\n0 999999\\n600000 -600000\\n\", \"5\\n140239 46311\\n399464 -289055\\n-540174 823360\\n538102 -373313\\n326189 933934\\n\", \"3\\n1000000 0\\n0 999999\\n300000 -300000\\n\", \"9\\n1000000 0\\n0 -999999\\n600000 600000\\n600000 600000\\n600000 600000\\n-600000 -600000\\n600000 600000\\n600000 600000\\n-700000 710000\\n\", \"2\\n1 999999\\n1 -999999\\n\", \"2\\n999999 1\\n999999 -1\\n\", \"2\\n-1 999999\\n-1 -999999\\n\", \"2\\n-999999 -1\\n-999999 1\\n\", \"2\\n999999 1\\n-999999 1\\n\", \"2\\n999999 -1\\n-999999 -1\\n\", \"2\\n1 999999\\n-1 999999\\n\", \"2\\n1 -999999\\n-1 -999999\\n\", \"4\\n1000000 0\\n-1 999999\\n600000 -600000\\n0 0\\n\", \"2\\n999999 -1\\n-1 999999\\n\"], \"outputs\": [\"1 1 -1 \\n\", \"1 \\n\", \"1 1 1 1 1 1 1 -1 \\n\", \"1 1 1 1 1 1 \\n\", \"1 1 1 1 1 1 1 -1 \\n\", \"-1 1 1 \\n\", \"1 1 1 1 -1 \\n\", \"1 1 -1 \\n\", \"1 1 1 -1 1 1 1 -1 1 \\n\", \"1 1 \\n\", \"1 -1 \\n\", \"1 1 \\n\", \"1 -1 \\n\", \"1 1 \\n\", \"1 1 \\n\", \"1 -1 \\n\", \"1 -1 \\n\", \"-1 1 1 1 \\n\", \"1 1 \\n\"]}", "source": "primeintellect"}
|
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in the direction $\vec{v_i}$ or $-\vec{v_i}$. In other words, if his position is currently $p = (x, y)$, he will either move to $p + \vec{v_i}$ or $p - \vec{v_i}$.
Allen doesn't want to wander too far from home (which happens to also be the bar). You need to help him figure out a sequence of moves (a sequence of signs for the vectors) such that his final position $p$ satisfies $|p| \le 1.5 \cdot 10^6$ so that he can stay safe.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of moves.
Each of the following lines contains two space-separated integers $x_i$ and $y_i$, meaning that $\vec{v_i} = (x_i, y_i)$. We have that $|v_i| \le 10^6$ for all $i$.
-----Output-----
Output a single line containing $n$ integers $c_1, c_2, \cdots, c_n$, each of which is either $1$ or $-1$. Your solution is correct if the value of $p = \sum_{i = 1}^n c_i \vec{v_i}$, satisfies $|p| \le 1.5 \cdot 10^6$.
It can be shown that a solution always exists under the given constraints.
-----Examples-----
Input
3
999999 0
0 999999
999999 0
Output
1 1 -1
Input
1
-824590 246031
Output
1
Input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
Output
1 1 1 1 1 1 1 -1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6\\n2 1 4 6 2 2\\n\", \"7\\n3 3 3 1 3 3 3\\n\", \"7\\n5128 5672 5805 5452 5882 5567 5032\\n\", \"10\\n1 2 2 3 5 5 5 4 2 1\\n\", \"14\\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\\n\", \"50\\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4\\n\", \"1\\n1\\n\", \"1\\n1000000000\\n\", \"2\\n1 1\\n\", \"2\\n1049 1098\\n\", \"2\\n100 100\\n\", \"5\\n1 2 3 2 1\\n\", \"15\\n2 2 1 1 2 2 2 2 2 2 2 2 2 1 2\\n\", \"28\\n415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 2 802811737 802811737 802811737 802811737 802811737 802811737 802811737 802811737 1 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901\\n\", \"45\\n3 12 13 11 13 13 10 11 14 15 15 13 14 12 13 11 14 10 10 14 14 11 10 12 11 11 13 14 10 11 14 13 14 11 11 11 12 15 1 10 15 12 14 14 14\\n\", \"84\\n1 3 4 5 6 5 6 7 8 9 7 4 5 4 2 5 1 1 1 3 2 7 7 8 10 9 5 6 5 2 3 3 3 3 3 2 4 8 6 5 8 9 8 7 9 3 4 4 4 2 2 1 6 4 9 5 9 9 10 7 10 4 5 4 2 4 3 3 4 4 6 6 6 9 10 12 7 5 9 8 5 3 3 2\\n\", \"170\\n1 2 1 2 1 1 1 1 2 3 2 1 1 2 2 1 2 1 2 1 1 2 3 3 2 1 1 1 1 1 1 1 1 2 1 2 3 3 2 1 2 2 1 2 3 2 1 1 2 3 2 1 2 1 1 1 2 3 3 2 1 2 1 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 2 1 2 3 2 1 1 2 3 4 4 3 2 1 2 1 2 1 2 3 3 2 1 2 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 3 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 3 2 1 2 1 1 1 2 3 4 5 4 3 2 1 1 2 1 2 3 4 3 2 1\\n\", \"1\\n5\\n\"], \"outputs\": [\"3\\n\", \"2\\n\", \"4\\n\", \"5\\n\", \"5\\n\", \"4\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"3\\n\", \"2\\n\", \"6\\n\", \"13\\n\", \"8\\n\", \"5\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 10^5).
The second line contains n space-separated integers h_1, h_2, ..., h_{n} (1 ≤ h_{i} ≤ 10^9) — sizes of towers.
-----Output-----
Print the number of operations needed to destroy all towers.
-----Examples-----
Input
6
2 1 4 6 2 2
Output
3
Input
7
3 3 3 1 3 3 3
Output
2
-----Note-----
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. [Image] After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 2\\n1 2 3\\n\", \"5 10\\n0 1 0 2 1\\n\", \"9 0\\n11 22 33 44 55 66 77 88 99\\n\", \"10 100\\n2705446 2705444 2705446 2705445 2705448 2705447 2705444 2705448 2705448 2705449\\n\", \"10 5\\n5914099 5914094 5914099 5914097 5914100 5914101 5914097 5914095 5914101 5914102\\n\", \"12 3\\n7878607 7878605 7878605 7878613 7878612 7878609 7878609 7878608 7878609 7878611 7878609 7878613\\n\", \"9 6\\n10225066 10225069 10225069 10225064 10225068 10225067 10225066 10225063 10225062\\n\", \"20 10\\n12986238 12986234 12986240 12986238 12986234 12986238 12986234 12986234 12986236 12986236 12986232 12986238 12986232 12986239 12986233 12986238 12986237 12986232 12986231 12986235\\n\", \"4 3\\n16194884 16194881 16194881 16194883\\n\", \"2 5\\n23921862 23921857\\n\", \"3 8\\n28407428 28407413 28407422\\n\", \"7 4\\n0 10 10 11 11 12 13\\n\", \"10 6\\n4 2 2 3 4 0 3 2 2 2\\n\", \"5 10000000\\n1 1 2 2 100000000\\n\", \"2 2\\n2 2\\n\", \"2 0\\n8 9\\n\", \"2 5\\n8 9\\n\", \"10 1\\n10 10 10 10 10 4 4 4 4 1\\n\"], \"outputs\": [\"1\\n1 2 2 \\n\", \"3\\n2 2 2 2 2 \\n\", \"154\\n2 2 2 2 2 2 2 2 2 \\n\", \"9\\n2 2 2 2 2 2 2 2 2 2 \\n\", \"11\\n2 1 2 2 2 2 2 2 2 2 \\n\", \"14\\n2 2 1 2 2 2 2 2 2 2 2 2 \\n\", \"11\\n2 2 2 2 2 2 2 2 1 \\n\", \"16\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 \\n\", \"4\\n2 2 1 2 \\n\", \"0\\n1 1\\n\", \"7\\n2 1 2 \\n\", \"11\\n1 2 2 2 2 2 2 \\n\", \"6\\n2 2 2 2 2 2 2 2 2 2 \\n\", \"100000000\\n2 2 2 2 2 \\n\", \"0\\n1 1\\n\", \"0\\n1 1\\n\", \"0\\n1 1\\n\", \"14\\n2 2 2 2 2 2 2 2 2 1 \\n\"]}", "source": "primeintellect"}
|
This problem is the most boring one you've ever seen.
Given a sequence of integers a_1, a_2, ..., a_{n} and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements). Each element of the original sequence should be contained in exactly one of the result subsequences. Note, that one of the result subsequences can be empty.
Let's define function f(a_{i}, a_{j}) on pairs of distinct elements (that is i ≠ j) in the original sequence. If a_{i} and a_{j} are in the same subsequence in the current partition then f(a_{i}, a_{j}) = a_{i} + a_{j} otherwise f(a_{i}, a_{j}) = a_{i} + a_{j} + h.
Consider all possible values of the function f for some partition. We'll call the goodness of this partiotion the difference between the maximum value of function f and the minimum value of function f.
Your task is to find a partition of the given sequence a that have the minimal possible goodness among all possible partitions.
-----Input-----
The first line of input contains integers n and h (2 ≤ n ≤ 10^5, 0 ≤ h ≤ 10^8). In the second line there is a list of n space-separated integers representing a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^8).
-----Output-----
The first line of output should contain the required minimum goodness.
The second line describes the optimal partition. You should print n whitespace-separated integers in the second line. The i-th integer is 1 if a_{i} is in the first subsequence otherwise it should be 2.
If there are several possible correct answers you are allowed to print any of them.
-----Examples-----
Input
3 2
1 2 3
Output
1
1 2 2
Input
5 10
0 1 0 2 1
Output
3
2 2 2 2 2
-----Note-----
In the first sample the values of f are as follows: f(1, 2) = 1 + 2 + 2 = 5, f(1, 3) = 1 + 3 + 2 = 6 and f(2, 3) = 2 + 3 = 5. So the difference between maximum and minimum values of f is 1.
In the second sample the value of h is large, so it's better for one of the sub-sequences to be empty.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n4 2 1\\n\", \"1\\n4\\n\", \"2\\n1 1\\n\", \"1\\n2\\n\", \"1\\n3\\n\", \"1\\n5\\n\", \"2\\n2 2\\n\", \"3\\n1 2 4\\n\", \"3\\n3 3 3\\n\", \"3\\n3 3 6\\n\", \"3\\n6 6 6\\n\", \"3\\n6 6 9\\n\", \"26\\n1 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\", \"3\\n7 7 21\\n\", \"2\\n95 50\\n\", \"3\\n30 30 15\\n\", \"3\\n1 50 70\\n\", \"2\\n70 10\\n\"], \"outputs\": [\"1\\naabcbaa\\n\", \"4\\naaaa\\n\", \"0\\nab\\n\", \"2\\naa\\n\", \"3\\naaa\\n\", \"5\\naaaaa\\n\", \"2\\nabba\\n\", \"1\\nbccaccb\\n\", \"0\\naaabbbccc\\n\", \"0\\naaabbbcccccc\\n\", \"6\\nabccbaabccbaabccba\\n\", \"3\\nabcccbaabcccbaabcccba\\n\", \"0\\nabcdefghijklmnopqrstuvwxyz\\n\", \"0\\naaaaaaabbbbbbbccccccccccccccccccccc\\n\", \"5\\nbbbbbaaaaaaaaaaaaaaaaaaabbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbb\\n\", \"15\\nabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcba\\n\", \"1\\nbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccacccccccccccccccccccccccccccccccccccbbbbbbbbbbbbbbbbbbbbbbbbb\\n\", \"10\\naaaabaaaaaabaaaaaaaabaaaaaabaaaaaaaabaaaaaabaaaaaaaabaaaaaabaaaaaaaabaaaaaabaaaa\\n\"]}", "source": "primeintellect"}
|
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).
[Image]
Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace.
-----Input-----
The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after n positive integers a_{i} — the quantity of beads of i-th color. It is guaranteed that the sum of a_{i} is at least 2 and does not exceed 100 000.
-----Output-----
In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace.
Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point.
-----Examples-----
Input
3
4 2 1
Output
1
abacaba
Input
1
4
Output
4
aaaa
Input
2
1 1
Output
0
ab
-----Note-----
In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.
In the second sample there is only one way to compose a necklace.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 2\\n1 2\\n2 3\\n\", \"3 3\\n1 2\\n2 3\\n1 3\\n\", \"5 7\\n3 2\\n5 4\\n3 4\\n1 3\\n1 5\\n1 4\\n2 5\\n\", \"10 11\\n4 10\\n8 10\\n2 3\\n2 4\\n7 1\\n8 5\\n2 8\\n7 2\\n1 2\\n2 9\\n6 8\\n\", \"10 9\\n2 5\\n2 4\\n2 7\\n2 9\\n2 3\\n2 8\\n2 6\\n2 10\\n2 1\\n\", \"10 16\\n6 10\\n5 2\\n6 4\\n6 8\\n5 3\\n5 4\\n6 2\\n5 9\\n5 7\\n5 1\\n6 9\\n5 8\\n5 10\\n6 1\\n6 7\\n6 3\\n\", \"10 17\\n5 1\\n8 1\\n2 1\\n2 6\\n3 1\\n5 7\\n3 7\\n8 6\\n4 7\\n2 7\\n9 7\\n10 7\\n3 6\\n4 1\\n9 1\\n8 7\\n10 1\\n\", \"10 15\\n5 9\\n7 8\\n2 9\\n1 9\\n3 8\\n3 9\\n5 8\\n1 8\\n6 9\\n7 9\\n4 8\\n4 9\\n10 9\\n10 8\\n6 8\\n\", \"10 9\\n4 9\\n1 9\\n10 9\\n2 9\\n3 9\\n6 9\\n5 9\\n7 9\\n8 9\\n\", \"2 1\\n1 2\\n\", \"10 10\\n6 4\\n9 1\\n3 6\\n6 7\\n4 2\\n9 6\\n8 6\\n5 7\\n1 4\\n6 10\\n\", \"20 22\\n20 8\\n1 3\\n3 18\\n14 7\\n19 6\\n7 20\\n14 8\\n8 10\\n2 5\\n11 2\\n4 19\\n14 2\\n7 11\\n15 1\\n12 15\\n7 6\\n11 13\\n1 16\\n9 12\\n1 19\\n17 3\\n11 20\\n\", \"20 22\\n3 18\\n9 19\\n6 15\\n7 1\\n16 8\\n18 7\\n12 3\\n18 4\\n9 15\\n20 1\\n4 2\\n6 7\\n14 2\\n7 15\\n7 10\\n8 1\\n13 6\\n9 7\\n11 8\\n2 6\\n18 5\\n17 15\\n\", \"1000 1\\n839 771\\n\", \"1000 1\\n195 788\\n\", \"100000 1\\n42833 64396\\n\", \"100000 1\\n26257 21752\\n\", \"5 5\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n\"], \"outputs\": [\"1\\n2 \\n2\\n1 3 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"1\\n2 \\n9\\n1 5 4 7 9 3 8 6 10 \\n\", \"2\\n5 6 \\n8\\n1 2 10 4 8 9 7 3 \\n\", \"7\\n5 3 2 8 4 9 10 \\n3\\n1 7 6 \\n\", \"2\\n9 8 \\n8\\n1 5 7 3 4 10 6 2 \\n\", \"1\\n9 \\n9\\n1 4 10 2 3 6 5 7 8 \\n\", \"1\\n2 \\n1\\n1 \\n\", \"6\\n9 4 3 7 8 10 \\n4\\n1 6 2 5 \\n\", \"-1\\n\", \"-1\\n\", \"1\\n839 \\n1\\n771 \\n\", \"1\\n788 \\n1\\n195 \\n\", \"1\\n64396 \\n1\\n42833 \\n\", \"1\\n26257 \\n1\\n21752 \\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e. $u \in A$ or $v \in A$ (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices A and B, such that both A and B are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
-----Input-----
The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next m lines contains a pair of integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n), denoting an undirected edge between u_{i} and v_{i}. It's guaranteed the graph won't contain any self-loops or multiple edges.
-----Output-----
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer k denoting the number of vertices in that vertex cover, and the second line contains k integers — the indices of vertices. Note that because of m ≥ 1, vertex cover cannot be empty.
-----Examples-----
Input
4 2
1 2
2 3
Output
1
2
2
1 3
Input
3 3
1 2
2 3
1 3
Output
-1
-----Note-----
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 4\\n\", \"2 1\\n\", \"1 1\\n\", \"1 2\\n\", \"1 3\\n\", \"2 2\\n\", \"2 3\\n\", \"3 1\\n\", \"3 2\\n\", \"3 3\\n\", \"1 4\\n\", \"4 1\\n\", \"4 2\\n\", \"100 1\\n\", \"1 100\\n\", \"101 1\\n\", \"1 101\\n\", \"2 20\\n\"], \"outputs\": [\"YES\\n5 4 7 2 \\n3 6 1 8 \\n\", \"NO\\n\", \"YES\\n1\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n6 1 8\\n7 5 3\\n2 9 4\\n\", \"YES\\n2 4 1 3\\n\", \"YES\\n2\\n4\\n1\\n3\\n\", \"YES\\n2 5 \\n7 4 \\n6 1 \\n3 8 \\n\", \"YES\\n1\\n3\\n5\\n7\\n9\\n11\\n13\\n15\\n17\\n19\\n21\\n23\\n25\\n27\\n29\\n31\\n33\\n35\\n37\\n39\\n41\\n43\\n45\\n47\\n49\\n51\\n53\\n55\\n57\\n59\\n61\\n63\\n65\\n67\\n69\\n71\\n73\\n75\\n77\\n79\\n81\\n83\\n85\\n87\\n89\\n91\\n93\\n95\\n97\\n99\\n2\\n4\\n6\\n8\\n10\\n12\\n14\\n16\\n18\\n20\\n22\\n24\\n26\\n28\\n30\\n32\\n34\\n36\\n38\\n40\\n42\\n44\\n46\\n48\\n50\\n52\\n54\\n56\\n58\\n60\\n62\\n64\\n66\\n68\\n70\\n72\\n74\\n76\\n78\\n80\\n82\\n84\\n86\\n88\\n90\\n92\\n94\\n96\\n98\\n100\\n\", \"YES\\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 \", \"YES\\n1\\n3\\n5\\n7\\n9\\n11\\n13\\n15\\n17\\n19\\n21\\n23\\n25\\n27\\n29\\n31\\n33\\n35\\n37\\n39\\n41\\n43\\n45\\n47\\n49\\n51\\n53\\n55\\n57\\n59\\n61\\n63\\n65\\n67\\n69\\n71\\n73\\n75\\n77\\n79\\n81\\n83\\n85\\n87\\n89\\n91\\n93\\n95\\n97\\n99\\n101\\n2\\n4\\n6\\n8\\n10\\n12\\n14\\n16\\n18\\n20\\n22\\n24\\n26\\n28\\n30\\n32\\n34\\n36\\n38\\n40\\n42\\n44\\n46\\n48\\n50\\n52\\n54\\n56\\n58\\n60\\n62\\n64\\n66\\n68\\n70\\n72\\n74\\n76\\n78\\n80\\n82\\n84\\n86\\n88\\n90\\n92\\n94\\n96\\n98\\n100\\n\", \"YES\\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 \", \"YES\\n21 4 23 6 25 8 27 10 29 12 31 14 33 16 35 18 37 20 39 2 \\n3 22 5 24 7 26 9 28 11 30 13 32 15 34 17 36 19 38 1 40 \\n\"]}", "source": "primeintellect"}
|
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
-----Input-----
The only line contains two integers n and m (1 ≤ n, m ≤ 10^5; n·m ≤ 10^5) — the number of rows and the number of columns in the required matrix.
-----Output-----
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
-----Examples-----
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
-----Note-----
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n\", \"2\\n\", \"1\\n\", \"3\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"20\\n\", \"21\\n\", \"22\\n\", \"23\\n\", \"24\\n\", \"25\\n\", \"100\\n\", \"108\\n\"], \"outputs\": [\"3 4 1 2\\n\", \"2 1\\n\", \"1\\n\", \"3 2 1\\n\", \"4 5 2 3 1\\n\", \"5 6 3 4 1 2\\n\", \"6 7 4 5 2 3 1\\n\", \"7 8 5 6 3 4 1 2\\n\", \"7 8 9 4 5 6 1 2 3\\n\", \"8 9 10 5 6 7 2 3 4 1\\n\", \"17 18 19 20 13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4\\n\", \"18 19 20 21 14 15 16 17 10 11 12 13 6 7 8 9 2 3 4 5 1\\n\", \"19 20 21 22 15 16 17 18 11 12 13 14 7 8 9 10 3 4 5 6 1 2\\n\", \"20 21 22 23 16 17 18 19 12 13 14 15 8 9 10 11 4 5 6 7 1 2 3\\n\", \"21 22 23 24 17 18 19 20 13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4\\n\", \"21 22 23 24 25 16 17 18 19 20 11 12 13 14 15 6 7 8 9 10 1 2 3 4 5\\n\", \"91 92 93 94 95 96 97 98 99 100 81 82 83 84 85 86 87 88 89 90 71 72 73 74 75 76 77 78 79 80 61 62 63 64 65 66 67 68 69 70 51 52 53 54 55 56 57 58 59 60 41 42 43 44 45 46 47 48 49 50 31 32 33 34 35 36 37 38 39 40 21 22 23 24 25 26 27 28 29 30 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10\\n\", \"99 100 101 102 103 104 105 106 107 108 89 90 91 92 93 94 95 96 97 98 79 80 81 82 83 84 85 86 87 88 69 70 71 72 73 74 75 76 77 78 59 60 61 62 63 64 65 66 67 68 49 50 51 52 53 54 55 56 57 58 39 40 41 42 43 44 45 46 47 48 29 30 31 32 33 34 35 36 37 38 19 20 21 22 23 24 25 26 27 28 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8\\n\"]}", "source": "primeintellect"}
|
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!
The only thing Mrs. Smith remembered was that any permutation of $n$ can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.
The sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.
The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).
A subsequence $a_{i_1}, a_{i_2}, \ldots, a_{i_k}$ where $1\leq i_1 < i_2 < \ldots < i_k\leq n$ is called increasing if $a_{i_1} < a_{i_2} < a_{i_3} < \ldots < a_{i_k}$. If $a_{i_1} > a_{i_2} > a_{i_3} > \ldots > a_{i_k}$, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.
For example, if there is a permutation $[6, 4, 1, 7, 2, 3, 5]$, LIS of this permutation will be $[1, 2, 3, 5]$, so the length of LIS is equal to $4$. LDS can be $[6, 4, 1]$, $[6, 4, 2]$, or $[6, 4, 3]$, so the length of LDS is $3$.
Note, the lengths of LIS and LDS can be different.
So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.
-----Input-----
The only line contains one integer $n$ ($1 \le n \le 10^5$) — the length of permutation that you need to build.
-----Output-----
Print a permutation that gives a minimum sum of lengths of LIS and LDS.
If there are multiple answers, print any.
-----Examples-----
Input
4
Output
3 4 1 2
Input
2
Output
2 1
-----Note-----
In the first sample, you can build a permutation $[3, 4, 1, 2]$. LIS is $[3, 4]$ (or $[1, 2]$), so the length of LIS is equal to $2$. LDS can be ony of $[3, 1]$, $[4, 2]$, $[3, 2]$, or $[4, 1]$. The length of LDS is also equal to $2$. The sum is equal to $4$. Note that $[3, 4, 1, 2]$ is not the only permutation that is valid.
In the second sample, you can build a permutation $[2, 1]$. LIS is $[1]$ (or $[2]$), so the length of LIS is equal to $1$. LDS is $[2, 1]$, so the length of LDS is equal to $2$. The sum is equal to $3$. Note that permutation $[1, 2]$ is also valid.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"nolon\\n\", \"otto\\n\", \"qqqq\\n\", \"kinnikkinnik\\n\", \"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\\n\", \"ababababababababababababababababababababababababababababababababababababababababababababababababababa\\n\", \"bbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbggggggggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbggggggggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbb\\n\", \"lllhhlhhllhhlllhlhhhhlllllhhhhlllllllhhlhhllhhlllhlhhhhlllllhhhhllllllllhhhhlllllhhhhlhlllhhllhhlhhlllllllhhhhlllllhhhhlhlllhhllhhlhhllllllhhlhhllhhlllhlhhhhlllllhhhhlllllllhhlhhllhhlllhlhhhhlllllhhhhllllllllhhhhlllllhhhhlhlllhhllhhlhhlllllllhhhhlllllhhhhlhlllhhllhhlhhlll\\n\", \"eaaaeaeaaaeeaaaeaeaaaeeaaaeaeaaae\\n\", \"tttdddssstttssstttdddddddddttttttdddsssdddtttsssdddsssssstttddddddtttdddssstttsssttttttdddtttsssssstttssssssssstttsssssstttssstttdddddddddsssdddssssssdddssstttsssdddssstttdddttttttdddddddddsssssstttdddtttssssssdddddddddttttttdddtttsssdddssstttsssdddssssssdddsssdddddddddtttssstttsssssstttssssssssstttsssssstttdddttttttssstttsssdddtttddddddtttssssssdddssstttdddsssdddttttttdddddddddtttssstttsssdddttt\\n\", \"a\\n\", \"abacaba\\n\", \"axalaxa\\n\", \"abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacaba\\n\", \"abbba\\n\", \"f\\n\", \"aaabbbaaa\\n\"], \"outputs\": [\"2\\n\", \"1\\n\", \"Impossible\\n\", \"1\\n\", \"Impossible\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"2\\n\", \"2\\n\", \"Impossible\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"Impossible\\n\", \"2\\n\"]}", "source": "primeintellect"}
|
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in the South Incánus, in the North Gandalf; to the East I go not."
And at that moment Sasha thought, how would that character be called in the East? In the East all names are palindromes. A string is a palindrome if it reads the same backward as forward. For example, such strings as "kazak", "oo" and "r" are palindromes, but strings "abb" and "ij" are not.
Sasha believed that the hero would be named after one of the gods of the East. As long as there couldn't be two equal names, so in the East people did the following: they wrote the original name as a string on a piece of paper, then cut the paper minimum number of times $k$, so they got $k+1$ pieces of paper with substrings of the initial string, and then unite those pieces together to get a new string. Pieces couldn't be turned over, they could be shuffled.
In this way, it's possible to achive a string abcdefg from the string f|de|abc|g using $3$ cuts (by swapping papers with substrings f and abc). The string cbadefg can't be received using the same cuts.
More formally, Sasha wants for the given palindrome $s$ find such minimum $k$, that you can cut this string into $k + 1$ parts, and then unite them in such a way that the final string will be a palindrome and it won't be equal to the initial string $s$. It there is no answer, then print "Impossible" (without quotes).
-----Input-----
The first line contains one string $s$ ($1 \le |s| \le 5\,000$) — the initial name, which consists only of lowercase Latin letters. It is guaranteed that $s$ is a palindrome.
-----Output-----
Print one integer $k$ — the minimum number of cuts needed to get a new name, or "Impossible" (without quotes).
-----Examples-----
Input
nolon
Output
2
Input
otto
Output
1
Input
qqqq
Output
Impossible
Input
kinnikkinnik
Output
1
-----Note-----
In the first example, you can cut the string in those positions: no|l|on, and then unite them as follows on|l|no. It can be shown that there is no solution with one cut.
In the second example, you can cut the string right in the middle, and swap peaces, so you get toot.
In the third example, you can't make a string, that won't be equal to the initial one.
In the fourth example, you can cut the suffix nik and add it to the beginning, so you get nikkinnikkin.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.625
|
{"tests": "{\"inputs\": [\"5 2 3\\n1 2\\n1 3\\n3 4\\n5 3\\n\", \"5 3 2\\n1 2\\n1 3\\n3 4\\n5 3\\n\", \"50 23129 410924\\n18 28\\n17 23\\n21 15\\n18 50\\n50 11\\n32 3\\n44 41\\n50 31\\n50 34\\n5 14\\n36 13\\n22 40\\n20 9\\n9 43\\n19 47\\n48 40\\n20 22\\n33 45\\n35 22\\n33 24\\n9 6\\n13 1\\n13 24\\n49 20\\n1 20\\n29 38\\n10 35\\n25 23\\n49 30\\n42 8\\n20 18\\n32 15\\n32 1\\n27 10\\n20 47\\n41 7\\n20 14\\n18 26\\n4 20\\n20 2\\n46 37\\n41 16\\n46 41\\n12 20\\n8 40\\n18 37\\n29 3\\n32 39\\n23 37\\n\", \"2 3 4\\n1 2\\n\", \"50 491238 12059\\n42 3\\n5 9\\n11 9\\n41 15\\n42 34\\n11 6\\n40 16\\n23 8\\n41 7\\n22 6\\n24 29\\n7 17\\n31 2\\n17 33\\n39 42\\n42 6\\n41 50\\n21 45\\n19 41\\n1 21\\n42 1\\n2 25\\n17 28\\n49 42\\n30 13\\n4 12\\n10 32\\n48 35\\n21 2\\n14 6\\n49 29\\n18 20\\n38 22\\n19 37\\n20 47\\n3 36\\n1 44\\n20 7\\n4 11\\n39 26\\n30 40\\n6 7\\n25 46\\n2 27\\n30 42\\n10 11\\n8 21\\n42 43\\n35 8\\n\", \"2 4 1\\n1 2\\n\", \"5 2 2\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"4 100 1\\n1 2\\n1 3\\n1 4\\n\", \"3 2 1\\n1 2\\n1 3\\n\", \"5 6 1\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"3 100 1\\n1 2\\n2 3\\n\", \"2 2 1\\n1 2\\n\", \"5 3 2\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"4 1000 1\\n1 2\\n1 3\\n1 4\\n\", \"4 100 1\\n1 2\\n2 3\\n3 4\\n\", \"2 3 1\\n1 2\\n\", \"5 4 3\\n1 2\\n1 3\\n1 4\\n1 5\\n\"], \"outputs\": [\"9\\n\", \"8\\n\", \"8113631\\n\", \"3\\n\", \"590891\\n\", \"4\\n\", \"8\\n\", \"102\\n\", \"3\\n\", \"9\\n\", \"101\\n\", \"2\\n\", \"9\\n\", \"1002\\n\", \"3\\n\", \"3\\n\", \"13\\n\"]}", "source": "primeintellect"}
|
A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road.
A spanning tree is a set of roads containing exactly n - 1 roads such that it's possible to travel between any two cities using only these roads.
Some spanning tree of the initial network was chosen. For every road in this tree the time one needs to traverse this road was changed from y to x seconds. Note that it's not guaranteed that x is smaller than y.
You would like to travel through all the cities using the shortest path possible. Given n, x, y and a description of the spanning tree that was chosen, find the cost of the shortest path that starts in any city, ends in any city and visits all cities exactly once.
-----Input-----
The first line of the input contains three integers n, x and y (2 ≤ n ≤ 200 000, 1 ≤ x, y ≤ 10^9).
Each of the next n - 1 lines contains a description of a road in the spanning tree. The i-th of these lines contains two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n) — indices of the cities connected by the i-th road. It is guaranteed that these roads form a spanning tree.
-----Output-----
Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once.
-----Examples-----
Input
5 2 3
1 2
1 3
3 4
5 3
Output
9
Input
5 3 2
1 2
1 3
3 4
5 3
Output
8
-----Note-----
In the first sample, roads of the spanning tree have cost 2, while other roads have cost 3. One example of an optimal path is $5 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 2$.
In the second sample, we have the same spanning tree, but roads in the spanning tree cost 3, while other roads cost 2. One example of an optimal path is $1 \rightarrow 4 \rightarrow 5 \rightarrow 2 \rightarrow 3$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 3\\n3 2 2\\n\", \"10 1\\n1\\n\", \"1 1\\n1\\n\", \"2 2\\n1 2\\n\", \"200 50\\n49 35 42 47 134 118 14 148 58 159 33 33 8 123 99 126 75 94 1 141 61 79 122 31 48 7 66 97 141 43 25 141 7 56 120 55 49 37 154 56 13 59 153 133 18 1 141 24 151 125\\n\", \"3 3\\n3 3 1\\n\", \"100000 1\\n100000\\n\", \"2000 100\\n5 128 1368 1679 1265 313 1854 1512 1924 338 38 1971 238 1262 1834 1878 1749 784 770 1617 191 395 303 214 1910 1300 741 1966 1367 24 268 403 1828 1033 1424 218 1146 925 1501 1760 1164 1881 1628 1596 1358 1360 29 1343 922 618 1537 1839 1114 1381 704 464 692 1450 1590 1121 670 300 1053 1730 1024 1292 1549 1112 1028 1096 794 38 1121 261 618 1489 587 1841 627 707 1693 1693 1867 1402 803 321 475 410 1664 1491 1846 1279 1250 457 1010 518 1785 514 1656 1588\\n\", \"10000 3\\n3376 5122 6812\\n\", \"99999 30\\n31344 14090 93157 5965 57557 41264 93881 58871 57763 46958 96029 37297 75623 12215 38442 86773 66112 7512 31968 28331 90390 79301 56205 704 15486 63054 83372 45602 15573 78459\\n\", \"100000 10\\n31191 100000 99999 99999 99997 100000 99996 99994 99995 99993\\n\", \"1000 2\\n1 1\\n\", \"10 3\\n1 9 2\\n\", \"6 3\\n2 2 6\\n\", \"100 3\\n45 10 45\\n\", \"6 3\\n1 2 2\\n\", \"9 3\\n9 3 1\\n\"], \"outputs\": [\"1 2 4\\n\", \"-1\\n\", \"1\\n\", \"-1\\n\", \"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 76\\n\", \"-1\\n\", \"1\\n\", \"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 413\\n\", \"1 2 3189\\n\", \"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 5968 21541\\n\", \"-1\\n\", \"-1\\n\", \"1 2 9\\n\", \"-1\\n\", \"1 46 56\\n\", \"-1\\n\", \"1 6 9\\n\"]}", "source": "primeintellect"}
|
Dreamoon likes coloring cells very much.
There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$.
You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l_i \le n$)
Dreamoon will perform $m$ operations.
In $i$-th operation, Dreamoon will choose a number $p_i$ from range $[1, n-l_i+1]$ (inclusive) and will paint all cells from $p_i$ to $p_i+l_i-1$ (inclusive) in $i$-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.
Dreamoon hopes that after these $m$ operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose $p_i$ in each operation to satisfy all constraints.
-----Input-----
The first line contains two integers $n,m$ ($1 \leq m \leq n \leq 100\,000$).
The second line contains $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \leq l_i \leq n$).
-----Output-----
If it's impossible to perform $m$ operations to satisfy all constraints, print "'-1" (without quotes).
Otherwise, print $m$ integers $p_1, p_2, \ldots, p_m$ ($1 \leq p_i \leq n - l_i + 1$), after these $m$ operations, all colors should appear at least once and all cells should be colored.
If there are several possible solutions, you can print any.
-----Examples-----
Input
5 3
3 2 2
Output
2 4 1
Input
10 1
1
Output
-1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6\\n1 2\\n2 3\\n2 4\\n4 5\\n1 6\\n\", \"7\\n1 2\\n1 3\\n3 4\\n1 5\\n5 6\\n6 7\\n\", \"2\\n1 2\\n\", \"3\\n3 1\\n1 2\\n\", \"10\\n5 10\\n7 8\\n8 3\\n2 6\\n3 2\\n9 7\\n4 5\\n10 1\\n6 4\\n\", \"11\\n11 9\\n6 7\\n7 1\\n8 11\\n5 6\\n3 5\\n9 3\\n10 8\\n2 4\\n4 10\\n\", \"10\\n4 2\\n7 4\\n2 6\\n2 5\\n4 8\\n10 3\\n2 9\\n9 1\\n5 10\\n\", \"11\\n8 9\\n2 7\\n1 11\\n3 2\\n9 1\\n8 5\\n8 6\\n5 4\\n4 10\\n8 3\\n\", \"12\\n12 6\\n6 7\\n8 11\\n4 8\\n10 4\\n12 3\\n2 10\\n6 2\\n12 9\\n4 1\\n9 5\\n\", \"4\\n4 1\\n4 3\\n4 2\\n\", \"5\\n1 5\\n2 3\\n2 4\\n1 2\\n\", \"6\\n1 6\\n3 1\\n6 4\\n5 3\\n2 5\\n\", \"7\\n5 6\\n5 7\\n5 1\\n7 4\\n6 3\\n3 2\\n\", \"8\\n6 1\\n4 7\\n4 8\\n8 5\\n7 6\\n4 3\\n4 2\\n\", \"3\\n1 3\\n3 2\\n\", \"5\\n5 4\\n4 3\\n3 1\\n5 2\\n\", \"9\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n6 7\\n6 8\\n8 9\\n\"], \"outputs\": [\"3\\n\", \"-1\\n\", \"1\\n\", \"1\\n\", \"9\\n\", \"5\\n\", \"-1\\n\", \"1\\n\", \"-1\\n\", \"1\\n\", \"3\\n\", \"5\\n\", \"-1\\n\", \"-1\\n\", \"1\\n\", \"1\\n\", \"3\\n\"]}", "source": "primeintellect"}
|
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a_0 = v, a_1, ..., a_{k}, and b_0 = v, b_1, ..., b_{k}. Additionally, vertices a_1, ..., a_{k}, b_1, ..., b_{k} must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b_1, ..., b_{k} can be effectively erased: [Image]
Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
-----Input-----
The first line of input contains the number of vertices n (2 ≤ n ≤ 2·10^5).
Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 ≤ u, v ≤ n, u ≠ v) — indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
-----Output-----
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
-----Examples-----
Input
6
1 2
2 3
2 4
4 5
1 6
Output
3
Input
7
1 2
1 3
3 4
1 5
5 6
6 7
Output
-1
-----Note-----
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n1 1 1\\n\", \"2\\n1 2 2\\n\", \"10\\n1 1 1 1 1 1 1 1 1 1 1\\n\", \"10\\n1 1 1 1 1 2 1 1 1 1 1\\n\", \"10\\n1 1 1 1 2 2 1 1 1 1 1\\n\", \"10\\n1 1 1 1 1 1 1 2 1 1 2\\n\", \"10\\n1 1 1 3 2 1 2 4 1 3 1\\n\", \"10\\n1 1 1 4 1 1 2 1 5 1 2\\n\", \"10\\n1 1 21 1 20 1 14 1 19 1 20\\n\", \"10\\n1 1 262 1 232 1 245 1 1 254 1\\n\", \"2\\n1 1 199998\\n\", \"3\\n1 1 199997 1\\n\", \"123\\n1 1 1 3714 1 3739 1 3720 1 1 3741 1 1 3726 1 3836 1 3777 1 1 3727 1 1 3866 1 3799 1 3785 1 3693 1 1 3667 1 3930 1 3849 1 1 3767 1 3792 1 3792 1 3808 1 3680 1 3798 1 3817 1 3636 1 3833 1 1 3765 1 3774 1 3747 1 1 3897 1 3773 1 3814 1 3739 1 1 3852 1 3759 1 3783 1 1 3836 1 3787 1 3752 1 1 3818 1 3794 1 3745 1 3785 1 3784 1 1 3765 1 3750 1 3690 1 1 3806 1 3781 1 3680 1 1 3748 1 3709 1 3793 1 3618 1 1 3893 1\\n\", \"13\\n1 1 40049 1 1 39777 1 1 40008 1 40060 1 40097 1\\n\", \"4\\n1 2 1 2 2\\n\", \"4\\n1 2 1 2 3\\n\", \"2\\n1 3 2\\n\"], \"outputs\": [\"perfect\\n\", \"ambiguous\\n0 1 1 3 3\\n0 1 1 3 2\\n\", \"perfect\\n\", \"perfect\\n\", \"ambiguous\\n0 1 2 3 4 4 6 6 8 9 10 11 12\\n0 1 2 3 4 4 6 5 8 9 10 11 12\\n\", \"perfect\\n\", \"ambiguous\\n0 1 2 3 3 3 6 6 8 9 9 11 11 11 11 15 16 16 16 19\\n0 1 2 3 3 3 6 5 8 9 9 11 10 10 10 15 16 16 16 19\\n\", \"perfect\\n\", \"perfect\\n\", \"perfect\\n\", \"perfect\\n\", \"perfect\\n\", \"perfect\\n\", \"perfect\\n\", \"ambiguous\\n0 1 1 3 4 4 6 6\\n0 1 1 3 4 4 6 5\\n\", \"ambiguous\\n0 1 1 3 4 4 6 6 6\\n0 1 1 3 4 4 6 5 5\\n\", \"ambiguous\\n0 1 1 1 4 4\\n0 1 1 1 4 3\\n\"]}", "source": "primeintellect"}
|
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence a_0, a_1, ..., a_{h}, where h is the height of the tree, and a_{i} equals to the number of vertices that are at distance of i edges from root.
Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence a_{i}, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree.
Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal.
The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex.
-----Input-----
The first line contains a single integer h (2 ≤ h ≤ 10^5) — the height of the tree.
The second line contains h + 1 integers — the sequence a_0, a_1, ..., a_{h} (1 ≤ a_{i} ≤ 2·10^5). The sum of all a_{i} does not exceed 2·10^5. It is guaranteed that there is at least one tree matching this sequence.
-----Output-----
If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print $\sum_{i = 0}^{h} a_{i}$ integers, the k-th of them should be the parent of vertex k or be equal to zero, if the k-th vertex is the root.
These treese should be non-isomorphic and should match the given sequence.
-----Examples-----
Input
2
1 1 1
Output
perfect
Input
2
1 2 2
Output
ambiguous
0 1 1 3 3
0 1 1 3 2
-----Note-----
The only tree in the first example and the two printed trees from the second example are shown on the picture:
$88$
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n2 4\\n4 3\\n3 0\\n1 3\\n\", \"3\\n0 0\\n0 2\\n2 0\\n\", \"8\\n0 3\\n2 2\\n3 0\\n2 -2\\n0 -3\\n-2 -2\\n-3 0\\n-2 2\\n\", \"4\\n-100000000 -100000000\\n-100000000 100000000\\n100000000 100000000\\n100000000 -100000000\\n\", \"4\\n0 0\\n10 10\\n10 9\\n1 0\\n\", \"4\\n12345678 99999999\\n12345679 100000000\\n12345680 99999999\\n12345679 99999998\\n\", \"6\\n-1000 1000\\n-998 1001\\n-996 1000\\n-996 996\\n-997 995\\n-1001 997\\n\", \"3\\n51800836 -5590860\\n51801759 -5590419\\n51801320 -5590821\\n\", \"3\\n97972354 -510322\\n97972814 -510361\\n97972410 -510528\\n\", \"4\\n-95989415 -89468419\\n-95989014 -89468179\\n-95989487 -89468626\\n-95989888 -89468866\\n\", \"4\\n100000000 0\\n0 -100000000\\n-100000000 0\\n0 100000000\\n\", \"3\\n77445196 95326351\\n77444301 95326820\\n77444705 95326693\\n\", \"3\\n-99297393 80400183\\n-99297475 80399631\\n-99297428 80399972\\n\", \"10\\n811055 21220458\\n813063 21222323\\n815154 21220369\\n817067 21218367\\n815214 21216534\\n813198 21214685\\n803185 21212343\\n805063 21214436\\n806971 21216475\\n808966 21218448\\n\", \"12\\n-83240790 -33942371\\n-83240805 -33942145\\n-83240821 -33941752\\n-83240424 -33941833\\n-83240107 -33942105\\n-83239958 -33942314\\n-83239777 -33942699\\n-83239762 -33942925\\n-83239746 -33943318\\n-83240143 -33943237\\n-83240460 -33942965\\n-83240609 -33942756\\n\", \"20\\n-2967010 48581504\\n-2967318 48581765\\n-2967443 48581988\\n-2967541 48582265\\n-2967443 48582542\\n-2967318 48582765\\n-2967010 48583026\\n-2966691 48583154\\n-2966252 48583234\\n-2965813 48583154\\n-2965494 48583026\\n-2965186 48582765\\n-2965061 48582542\\n-2964963 48582265\\n-2965061 48581988\\n-2965186 48581765\\n-2965494 48581504\\n-2965813 48581376\\n-2966252 48581296\\n-2966691 48581376\\n\", \"4\\n0 99999999\\n0 100000000\\n1 -99999999\\n1 -100000000\\n\"], \"outputs\": [\"12 14 \", \"8 \", \"20 24 24 24 24 24 \", \"800000000 800000000 \", \"40 40 \", \"6 8 \", \"20 22 22 22 \", \"2728 \", \"1332 \", \"3122 3122 \", \"600000000 800000000 \", \"2728 \", \"1268 \", \"47724 47724 47724 47724 47724 47724 47724 47724 \", \"5282 5282 5282 5282 5282 5282 5282 5282 5282 5282 \", \"7648 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 9032 \", \"400000002 400000002 \"]}", "source": "primeintellect"}
|
You are given $n$ points on the plane. The polygon formed from all the $n$ points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from $1$ to $n$, in clockwise order.
We define the distance between two points $p_1 = (x_1, y_1)$ and $p_2 = (x_2, y_2)$ as their Manhattan distance: $$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|.$$
Furthermore, we define the perimeter of a polygon, as the sum of Manhattan distances between all adjacent pairs of points on it; if the points on the polygon are ordered as $p_1, p_2, \ldots, p_k$ $(k \geq 3)$, then the perimeter of the polygon is $d(p_1, p_2) + d(p_2, p_3) + \ldots + d(p_k, p_1)$.
For some parameter $k$, let's consider all the polygons that can be formed from the given set of points, having any $k$ vertices, such that the polygon is not self-intersecting. For each such polygon, let's consider its perimeter. Over all such perimeters, we define $f(k)$ to be the maximal perimeter.
Please note, when checking whether a polygon is self-intersecting, that the edges of a polygon are still drawn as straight lines. For instance, in the following pictures:
[Image]
In the middle polygon, the order of points ($p_1, p_3, p_2, p_4$) is not valid, since it is a self-intersecting polygon. The right polygon (whose edges resemble the Manhattan distance) has the same order and is not self-intersecting, but we consider edges as straight lines. The correct way to draw this polygon is ($p_1, p_2, p_3, p_4$), which is the left polygon.
Your task is to compute $f(3), f(4), \ldots, f(n)$. In other words, find the maximum possible perimeter for each possible number of points (i.e. $3$ to $n$).
-----Input-----
The first line contains a single integer $n$ ($3 \leq n \leq 3\cdot 10^5$) — the number of points.
Each of the next $n$ lines contains two integers $x_i$ and $y_i$ ($-10^8 \leq x_i, y_i \leq 10^8$) — the coordinates of point $p_i$.
The set of points is guaranteed to be convex, all points are distinct, the points are ordered in clockwise order, and there will be no three collinear points.
-----Output-----
For each $i$ ($3\leq i\leq n$), output $f(i)$.
-----Examples-----
Input
4
2 4
4 3
3 0
1 3
Output
12 14
Input
3
0 0
0 2
2 0
Output
8
-----Note-----
In the first example, for $f(3)$, we consider four possible polygons: ($p_1, p_2, p_3$), with perimeter $12$. ($p_1, p_2, p_4$), with perimeter $8$. ($p_1, p_3, p_4$), with perimeter $12$. ($p_2, p_3, p_4$), with perimeter $12$.
For $f(4)$, there is only one option, taking all the given points. Its perimeter $14$.
In the second example, there is only one possible polygon. Its perimeter is $8$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 1\\n6\\n\", \"3 3\\n1 7 8\\n\", \"3 4\\n1 3 5 7\\n\", \"10 10\\n334 588 666 787 698 768 934 182 39 834\\n\", \"2 4\\n3 2 4 1\\n\", \"3 4\\n3 4 1 6\\n\", \"2 0\\n\", \"2 1\\n1\\n\", \"17 0\\n\", \"17 1\\n95887\\n\", \"2 2\\n4 2\\n\", \"2 3\\n2 1 3\\n\", \"3 5\\n7 2 1 4 8\\n\", \"3 6\\n5 4 1 3 6 7\\n\", \"3 7\\n5 4 8 1 7 3 6\\n\", \"3 8\\n2 5 6 1 8 3 4 7\\n\", \"16 50\\n57794 44224 38309 41637 11732 44974 655 27143 11324 49584 3371 17159 26557 38800 33033 18231 26264 14765 33584 30879 46988 60703 52973 47349 22720 51251 54716 29642 7041 54896 12197 38530 51481 43063 55463 2057 48064 41953 16250 21272 34003 51464 50389 30417 45901 38895 25949 798 29404 55166\\n\"], \"outputs\": [\"6\\n\", \"11\\n\", \"14\\n\", \"138\\n\", \"6\\n\", \"12\\n\", \"0\\n\", \"4\\n\", \"0\\n\", \"34\\n\", \"6\\n\", \"6\\n\", \"13\\n\", \"14\\n\", \"14\\n\", \"14\\n\", \"1005\\n\"]}", "source": "primeintellect"}
|
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. $2^n$ teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify the champion.
Teams are numbered from $1$ to $2^n$ and will play games one-on-one. All teams start in the upper bracket.
All upper bracket matches will be held played between teams that haven't lost any games yet. Teams are split into games by team numbers. Game winner advances in the next round of upper bracket, losers drop into the lower bracket.
Lower bracket starts with $2^{n-1}$ teams that lost the first upper bracket game. Each lower bracket round consists of two games. In the first game of a round $2^k$ teams play a game with each other (teams are split into games by team numbers). $2^{k-1}$ loosing teams are eliminated from the championship, $2^{k-1}$ winning teams are playing $2^{k-1}$ teams that got eliminated in this round of upper bracket (again, teams are split into games by team numbers). As a result of each round both upper and lower bracket have $2^{k-1}$ teams remaining. See example notes for better understanding.
Single remaining team of upper bracket plays with single remaining team of lower bracket in grand-finals to identify championship winner.
You are a fan of teams with numbers $a_1, a_2, ..., a_k$. You want the championship to have as many games with your favourite teams as possible. Luckily, you can affect results of every championship game the way you want. What's maximal possible number of championship games that include teams you're fan of?
-----Input-----
First input line has two integers $n, k$ — $2^n$ teams are competing in the championship. You are a fan of $k$ teams ($2 \le n \le 17; 0 \le k \le 2^n$).
Second input line has $k$ distinct integers $a_1, \ldots, a_k$ — numbers of teams you're a fan of ($1 \le a_i \le 2^n$).
-----Output-----
Output single integer — maximal possible number of championship games that include teams you're fan of.
-----Examples-----
Input
3 1
6
Output
6
Input
3 3
1 7 8
Output
11
Input
3 4
1 3 5 7
Output
14
-----Note-----
On the image, each game of the championship is denoted with an English letter ($a$ to $n$). Winner of game $i$ is denoted as $Wi$, loser is denoted as $Li$. Teams you're a fan of are highlighted with red background.
In the first example, team $6$ will play in 6 games if it looses the first upper bracket game (game $c$) and wins all lower bracket games (games $h, j, l, m$). [Image]
In the second example, teams $7$ and $8$ have to play with each other in the first game of upper bracket (game $d$). Team $8$ can win all remaining games in upper bracket, when teams $1$ and $7$ will compete in the lower bracket. [Image]
In the third example, your favourite teams can play in all games of the championship. [Image]
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n3 5\\n5 3\\n\", \"2\\n5 3\\n3 5\\n\", \"9\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 1\\n\", \"50\\n9 5\\n2 6\\n5 4\\n7 5\\n3 6\\n5 8\\n1 2\\n6 1\\n9 7\\n8 1\\n9 5\\n6 8\\n6 8\\n2 8\\n4 9\\n6 7\\n7 8\\n5 8\\n1 2\\n9 2\\n5 9\\n6 7\\n3 2\\n9 8\\n7 8\\n7 4\\n6 5\\n1 7\\n6 5\\n2 6\\n3 1\\n6 5\\n3 7\\n9 3\\n8 1\\n8 3\\n8 2\\n1 9\\n9 2\\n3 2\\n8 7\\n5 1\\n6 2\\n2 1\\n6 1\\n3 4\\n4 1\\n2 3\\n2 6\\n2 9\\n\", \"50\\n8 9\\n6 7\\n6 8\\n4 1\\n3 2\\n9 3\\n8 3\\n9 7\\n4 6\\n4 6\\n5 6\\n7 2\\n6 3\\n1 3\\n8 2\\n4 6\\n6 8\\n7 6\\n8 6\\n9 4\\n8 6\\n9 1\\n3 8\\n3 1\\n4 7\\n4 9\\n9 1\\n7 4\\n3 5\\n1 7\\n3 5\\n8 9\\n5 4\\n2 9\\n2 9\\n3 9\\n8 5\\n4 9\\n9 4\\n5 6\\n6 1\\n4 2\\n3 9\\n9 1\\n9 4\\n4 5\\n2 4\\n2 6\\n3 6\\n1 9\\n\", \"50\\n3 9\\n8 9\\n7 2\\n9 1\\n5 2\\n2 8\\n2 4\\n8 6\\n4 6\\n1 6\\n5 3\\n3 8\\n8 2\\n6 7\\n7 1\\n2 4\\n2 8\\n3 7\\n7 1\\n7 9\\n9 3\\n7 2\\n2 7\\n8 4\\n5 8\\n6 8\\n7 1\\n7 5\\n5 6\\n9 1\\n8 6\\n3 6\\n7 6\\n4 3\\n3 2\\n9 2\\n4 9\\n2 1\\n7 9\\n1 8\\n4 9\\n5 2\\n7 2\\n9 8\\n3 1\\n4 5\\n3 4\\n2 7\\n2 1\\n6 1\\n\", \"50\\n7 1\\n4 8\\n9 3\\n9 3\\n2 4\\n5 9\\n1 5\\n1 4\\n7 6\\n4 8\\n3 6\\n2 8\\n5 1\\n8 9\\n7 4\\n7 2\\n2 4\\n7 9\\n8 7\\n3 8\\n1 7\\n4 5\\n7 2\\n6 4\\n6 1\\n4 8\\n5 6\\n4 3\\n6 5\\n6 4\\n6 9\\n2 5\\n9 3\\n3 4\\n3 4\\n9 3\\n7 9\\n5 8\\n1 6\\n5 1\\n8 3\\n7 4\\n1 8\\n5 2\\n1 7\\n6 1\\n9 6\\n3 1\\n6 5\\n9 7\\n\", \"50\\n1 9\\n9 4\\n4 2\\n2 4\\n3 8\\n9 5\\n3 2\\n8 3\\n8 1\\n4 7\\n5 3\\n2 6\\n1 8\\n6 5\\n4 1\\n5 7\\n1 4\\n4 7\\n5 4\\n8 2\\n4 6\\n8 7\\n1 9\\n1 6\\n6 4\\n5 2\\n5 3\\n2 6\\n4 6\\n5 2\\n6 7\\n5 3\\n9 5\\n8 3\\n1 9\\n2 6\\n5 1\\n7 3\\n4 3\\n7 2\\n4 3\\n5 7\\n6 8\\n8 2\\n3 6\\n4 9\\n1 8\\n7 8\\n5 4\\n7 6\\n\", \"50\\n5 9\\n1 2\\n6 9\\n1 6\\n8 1\\n5 3\\n2 1\\n2 7\\n6 1\\n4 3\\n6 1\\n2 6\\n2 8\\n2 1\\n3 4\\n6 2\\n4 8\\n6 4\\n2 1\\n1 5\\n4 9\\n6 8\\n4 1\\n1 6\\n1 5\\n5 9\\n2 6\\n6 9\\n4 2\\n4 7\\n8 2\\n4 6\\n2 5\\n9 4\\n3 1\\n8 4\\n3 9\\n1 3\\n2 3\\n8 7\\n5 4\\n2 6\\n9 5\\n6 2\\n5 8\\n2 8\\n8 9\\n9 2\\n5 3\\n9 1\\n\", \"50\\n9 8\\n8 9\\n2 3\\n2 6\\n7 6\\n9 8\\n7 5\\n8 5\\n2 9\\n4 2\\n4 6\\n9 4\\n1 9\\n4 8\\n7 9\\n7 4\\n4 7\\n7 6\\n8 9\\n2 8\\n1 3\\n6 7\\n6 3\\n1 8\\n9 3\\n4 9\\n9 6\\n4 2\\n6 5\\n3 8\\n9 3\\n7 5\\n9 6\\n5 6\\n4 7\\n5 7\\n9 1\\n7 5\\n5 6\\n3 1\\n4 3\\n7 1\\n9 8\\n7 8\\n3 7\\n8 3\\n9 6\\n5 7\\n1 8\\n6 4\\n\", \"9\\n2 1\\n5 9\\n2 6\\n2 6\\n4 7\\n7 3\\n3 1\\n3 1\\n7 8\\n\", \"5\\n1 7\\n2 5\\n8 6\\n3 4\\n1 6\\n\", \"4\\n2 1\\n1 7\\n5 8\\n8 4\\n\", \"1\\n1 9\\n\", \"1\\n9 1\\n\", \"1\\n1 5\\n\", \"1\\n8 6\\n\"], \"outputs\": [\"10\", \"12\", \"34\", \"278\", \"252\", \"260\", \"274\", \"258\", \"282\", \"275\", \"46\", \"29\", \"21\", \"10\", \"18\", \"6\", \"11\"]}", "source": "primeintellect"}
|
You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.
Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you know the order in which people came to the elevator.
According to the company's rules, if an employee comes to the elevator earlier than another one, he has to enter the elevator earlier too (even if these employees stay on different floors). Note that the employees are allowed to leave the elevator in arbitrary order.
The elevator has two commands: Go up or down one floor. The movement takes 1 second. Open the doors on the current floor. During this operation all the employees who have reached their destination get out of the elevator. Then all the employees on the floor get in the elevator in the order they are queued up while it doesn't contradict the company's rules and there is enough space in the elevator. Each employee spends 1 second to get inside and outside the elevator.
Initially the elevator is empty and is located on the floor 1.
You are interested what is the minimum possible time you need to spend to deliver all the employees to their destination. It is not necessary to return the elevator to the floor 1.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of employees.
The i-th of the next n lines contains two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 9, a_{i} ≠ b_{i}) — the floor on which an employee initially is, and the floor he wants to reach.
The employees are given in the order they came to the elevator.
-----Output-----
Print a single integer — the minimal possible time in seconds.
-----Examples-----
Input
2
3 5
5 3
Output
10
Input
2
5 3
3 5
Output
12
-----Note-----
Explaination for the first sample [Image] t = 0
[Image] t = 2
[Image] t = 3
[Image] t = 5
[Image] t = 6
[Image] t = 7
[Image] t = 9
[Image] t = 10
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n\", \"4 3\\n1 2\\n2 3\\n3 1\\n\", \"3 2\\n1 3\\n2 3\\n\", \"6 3\\n1 3\\n2 5\\n4 6\\n\", \"100 50\\n55 13\\n84 2\\n22 63\\n100 91\\n2 18\\n98 64\\n1 86\\n93 11\\n17 6\\n24 97\\n14 35\\n24 74\\n22 3\\n42 5\\n63 79\\n31 89\\n81 22\\n86 88\\n77 51\\n81 34\\n19 55\\n41 54\\n34 57\\n45 9\\n55 72\\n67 61\\n41 84\\n39 32\\n51 89\\n58 74\\n32 79\\n65 6\\n86 64\\n63 42\\n100 57\\n46 39\\n100 9\\n23 58\\n26 81\\n61 49\\n71 83\\n66 2\\n79 74\\n30 27\\n44 52\\n50 49\\n88 11\\n94 89\\n2 35\\n80 94\\n\", \"2 2\\n2 1\\n1 2\\n\", \"5 3\\n1 2\\n3 4\\n5 4\\n\", \"5 5\\n4 1\\n5 4\\n2 1\\n3 2\\n3 4\\n\", \"10 6\\n6 2\\n8 2\\n1 5\\n7 9\\n5 1\\n2 3\\n\", \"10 8\\n4 6\\n1 6\\n9 4\\n9 5\\n8 7\\n7 4\\n3 1\\n2 9\\n\", \"10 10\\n4 1\\n10 7\\n5 4\\n5 3\\n7 6\\n2 1\\n6 4\\n8 7\\n6 8\\n7 10\\n\", \"51 50\\n4 34\\n50 28\\n46 41\\n37 38\\n29 9\\n4 29\\n38 42\\n16 3\\n34 21\\n27 39\\n34 29\\n22 50\\n14 47\\n23 35\\n11 4\\n26 5\\n50 27\\n29 33\\n18 14\\n42 24\\n18 29\\n28 36\\n17 48\\n47 51\\n51 37\\n47 48\\n35 9\\n23 28\\n41 36\\n34 6\\n8 17\\n7 30\\n27 23\\n41 51\\n19 6\\n21 46\\n11 22\\n21 46\\n16 15\\n1 4\\n51 29\\n3 36\\n15 40\\n17 42\\n29 3\\n27 20\\n3 17\\n34 10\\n10 31\\n20 44\\n\", \"99 50\\n34 91\\n28 89\\n62 71\\n25 68\\n88 47\\n36 7\\n85 33\\n30 91\\n45 39\\n65 66\\n69 80\\n44 58\\n67 98\\n10 85\\n88 48\\n18 26\\n83 24\\n20 14\\n26 3\\n54 35\\n48 3\\n62 58\\n99 27\\n62 92\\n5 65\\n66 2\\n95 62\\n48 27\\n17 56\\n58 66\\n98 73\\n17 57\\n73 40\\n54 66\\n56 75\\n85 6\\n70 63\\n76 25\\n85 40\\n1 89\\n21 65\\n90 9\\n62 5\\n76 11\\n18 50\\n32 66\\n10 74\\n74 80\\n44 33\\n7 82\\n\", \"5 6\\n1 4\\n4 3\\n5 4\\n4 3\\n2 3\\n1 5\\n\", \"12 30\\n2 11\\n7 1\\n9 5\\n9 10\\n10 7\\n2 4\\n12 6\\n3 11\\n9 6\\n12 5\\n12 3\\n7 6\\n7 4\\n3 11\\n6 5\\n3 4\\n10 1\\n2 6\\n2 3\\n10 5\\n10 1\\n7 4\\n9 1\\n9 5\\n12 11\\n7 1\\n9 3\\n9 3\\n8 1\\n7 3\\n\", \"12 11\\n7 11\\n4 1\\n6 3\\n3 4\\n9 7\\n1 5\\n2 9\\n5 10\\n12 6\\n11 12\\n8 2\\n\"], \"outputs\": [\"1\\nAE\\n\", \"-1\\n\", \"2\\nAAE\\n\", \"3\\nAAEAEE\\n\", \"59\\nAAAAAAAAAAEAAAAAEEEAAEAAAEAAAEAAAEEAAAEAEEAAEEAAAEAEAEEAEEAAEAEEEEEAAAAEAEAAEAEAEAEEAEAEEAAAEEAAEEAE\\n\", \"-1\\n\", \"2\\nAEAEE\\n\", \"1\\nAEEEE\\n\", \"-1\\n\", \"3\\nAAEEEEEEEA\\n\", \"-1\\n\", \"13\\nAAEEAEAAEEEAAEAEEEEEEEEEAEEEEEEAEEEEEEEEEEAEAEEEAEE\\n\", \"58\\nAAAAEAAAAEAAAAAAAEAEEAAAAEAAAAAEEAAEAAAEAAAEEAAEAEAAAEAEEEAAAEAAEEEEAEEAEEEEAAAEAEEAEAAEEEEEAAEAAEE\\n\", \"2\\nAAEEE\\n\", \"2\\nAAEEEEEEEEEE\\n\", \"1\\nAEEEEEEEEEEE\\n\"]}", "source": "primeintellect"}
|
Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universal ($\forall$) and existential ($\exists$). You can read more about them here.
The universal quantifier is used to make a claim that a statement holds for all real numbers. For example: $\forall x,x<100$ is read as: for all real numbers $x$, $x$ is less than $100$. This statement is false. $\forall x,x>x-1$ is read as: for all real numbers $x$, $x$ is greater than $x-1$. This statement is true.
The existential quantifier is used to make a claim that there exists some real number for which the statement holds. For example: $\exists x,x<100$ is read as: there exists a real number $x$ such that $x$ is less than $100$. This statement is true. $\exists x,x>x-1$ is read as: there exists a real number $x$ such that $x$ is greater than $x-1$. This statement is true.
Moreover, these quantifiers can be nested. For example: $\forall x,\exists y,x<y$ is read as: for all real numbers $x$, there exists a real number $y$ such that $x$ is less than $y$. This statement is true since for every $x$, there exists $y=x+1$. $\exists y,\forall x,x<y$ is read as: there exists a real number $y$ such that for all real numbers $x$, $x$ is less than $y$. This statement is false because it claims that there is a maximum real number: a number $y$ larger than every $x$.
Note that the order of variables and quantifiers is important for the meaning and veracity of a statement.
There are $n$ variables $x_1,x_2,\ldots,x_n$, and you are given some formula of the form $$ f(x_1,\dots,x_n):=(x_{j_1}<x_{k_1})\land (x_{j_2}<x_{k_2})\land \cdots\land (x_{j_m}<x_{k_m}), $$
where $\land$ denotes logical AND. That is, $f(x_1,\ldots, x_n)$ is true if every inequality $x_{j_i}<x_{k_i}$ holds. Otherwise, if at least one inequality does not hold, then $f(x_1,\ldots,x_n)$ is false.
Your task is to assign quantifiers $Q_1,\ldots,Q_n$ to either universal ($\forall$) or existential ($\exists$) so that the statement $$ Q_1 x_1, Q_2 x_2, \ldots, Q_n x_n, f(x_1,\ldots, x_n) $$
is true, and the number of universal quantifiers is maximized, or determine that the statement is false for every possible assignment of quantifiers.
Note that the order the variables appear in the statement is fixed. For example, if $f(x_1,x_2):=(x_1<x_2)$ then you are not allowed to make $x_2$ appear first and use the statement $\forall x_2,\exists x_1, x_1<x_2$. If you assign $Q_1=\exists$ and $Q_2=\forall$, it will only be interpreted as $\exists x_1,\forall x_2,x_1<x_2$.
-----Input-----
The first line contains two integers $n$ and $m$ ($2\le n\le 2\cdot 10^5$; $1\le m\le 2\cdot 10^5$) — the number of variables and the number of inequalities in the formula, respectively.
The next $m$ lines describe the formula. The $i$-th of these lines contains two integers $j_i$,$k_i$ ($1\le j_i,k_i\le n$, $j_i\ne k_i$).
-----Output-----
If there is no assignment of quantifiers for which the statement is true, output a single integer $-1$.
Otherwise, on the first line output an integer, the maximum possible number of universal quantifiers.
On the next line, output a string of length $n$, where the $i$-th character is "A" if $Q_i$ should be a universal quantifier ($\forall$), or "E" if $Q_i$ should be an existential quantifier ($\exists$). All letters should be upper-case. If there are multiple solutions where the number of universal quantifiers is maximum, print any.
-----Examples-----
Input
2 1
1 2
Output
1
AE
Input
4 3
1 2
2 3
3 1
Output
-1
Input
3 2
1 3
2 3
Output
2
AAE
-----Note-----
For the first test, the statement $\forall x_1, \exists x_2, x_1<x_2$ is true. Answers of "EA" and "AA" give false statements. The answer "EE" gives a true statement, but the number of universal quantifiers in this string is less than in our answer.
For the second test, we can show that no assignment of quantifiers, for which the statement is true exists.
For the third test, the statement $\forall x_1, \forall x_2, \exists x_3, (x_1<x_3)\land (x_2<x_3)$ is true: We can set $x_3=\max\{x_1,x_2\}+1$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 3\\n0 0 0 1 2\\n\", \"5 7\\n0 6 1 3 2\\n\", \"10 10\\n5 0 5 9 4 6 4 5 0 0\\n\", \"4 6\\n0 3 5 1\\n\", \"6 4\\n1 3 0 2 1 0\\n\", \"10 1000\\n981 824 688 537 969 72 39 734 929 718\\n\", \"10 300000\\n111862 91787 271781 182224 260248 142019 30716 102643 141870 19206\\n\", \"100 10\\n8 4 4 9 0 7 9 5 1 1 2 3 7 1 8 4 8 8 6 0 8 7 8 3 7 0 6 4 8 4 2 7 0 0 3 8 4 4 2 0 0 4 7 2 4 7 9 1 3 3 6 2 9 6 0 6 3 5 6 5 5 3 0 0 8 7 1 4 2 4 1 3 9 7 9 0 6 6 7 4 2 3 7 1 7 3 5 1 4 3 7 5 7 5 0 5 1 9 0 9\\n\", \"100 1\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100 2\\n1 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 1 0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1\\n\", \"100 1000\\n980 755 745 448 424 691 210 545 942 979 555 783 425 942 495 741 487 514 752 434 187 874 372 617 414 505 659 445 81 397 243 986 441 587 31 350 831 801 194 103 723 166 108 182 252 846 328 905 639 690 738 638 986 340 559 626 572 808 442 410 179 549 880 153 449 99 434 945 163 687 173 797 999 274 975 626 778 456 407 261 988 43 25 391 937 856 54 110 884 937 940 205 338 250 903 244 424 871 979 810\\n\", \"1 1\\n0\\n\", \"10 10\\n1 2 3 4 5 6 7 8 9 0\\n\", \"2 1\\n0 0\\n\", \"2 2\\n0 1\\n\", \"2 2\\n1 0\\n\"], \"outputs\": [\"0\\n\", \"1\\n\", \"6\\n\", \"3\\n\", \"2\\n\", \"463\\n\", \"208213\\n\", \"8\\n\", \"0\\n\", \"1\\n\", \"860\\n\", \"0\\n\", \"9\\n\", \"0\\n\", \"0\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
Toad Zitz has an array of integers, each integer is between $0$ and $m-1$ inclusive. The integers are $a_1, a_2, \ldots, a_n$.
In one operation Zitz can choose an integer $k$ and $k$ indices $i_1, i_2, \ldots, i_k$ such that $1 \leq i_1 < i_2 < \ldots < i_k \leq n$. He should then change $a_{i_j}$ to $((a_{i_j}+1) \bmod m)$ for each chosen integer $i_j$. The integer $m$ is fixed for all operations and indices.
Here $x \bmod y$ denotes the remainder of the division of $x$ by $y$.
Zitz wants to make his array non-decreasing with the minimum number of such operations. Find this minimum number of operations.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 300\,000$) — the number of integers in the array and the parameter $m$.
The next line contains $n$ space-separated integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i < m$) — the given array.
-----Output-----
Output one integer: the minimum number of described operations Zitz needs to make his array non-decreasing. If no operations required, print $0$.
It is easy to see that with enough operations Zitz can always make his array non-decreasing.
-----Examples-----
Input
5 3
0 0 0 1 2
Output
0
Input
5 7
0 6 1 3 2
Output
1
-----Note-----
In the first example, the array is already non-decreasing, so the answer is $0$.
In the second example, you can choose $k=2$, $i_1 = 2$, $i_2 = 5$, the array becomes $[0,0,1,3,3]$. It is non-decreasing, so the answer is $1$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 2 3 10\\nwwhw\\n\", \"5 2 4 13\\nhhwhh\\n\", \"5 2 4 1000\\nhhwhh\\n\", \"3 1 100 10\\nwhw\\n\", \"10 2 3 32\\nhhwwhwhwwh\\n\", \"1 2 3 3\\nw\\n\", \"100 20 100 10202\\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwhwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwww\\n\", \"20 10 10 1\\nhwhwhwhwhwhwhwhwhhhw\\n\", \"12 10 10 1\\nwhwhwhwhwhwh\\n\", \"2 5 5 1000000000\\nwh\\n\", \"16 1 1000 2100\\nhhhwwwhhhwhhhwww\\n\", \"5 2 4 13\\nhhhwh\\n\", \"7 1 1000 13\\nhhhhwhh\\n\", \"10 1 1000 10\\nhhhhhhwwhh\\n\", \"7 1 100 8\\nhhhwwwh\\n\", \"5 2 4 12\\nhhhwh\\n\"], \"outputs\": [\"2\\n\", \"4\\n\", \"5\\n\", \"0\\n\", \"7\\n\", \"0\\n\", \"100\\n\", \"1\\n\", \"0\\n\", \"2\\n\", \"5\\n\", \"4\\n\", \"6\\n\", \"5\\n\", \"4\\n\", \"4\\n\"]}", "source": "primeintellect"}
|
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a seconds to swipe from photo to adjacent.
For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can't be rotated. It takes b second to change orientation of the photo.
Vasya has T seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends b seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn't spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.
Help Vasya find the maximum number of photos he is able to watch during T seconds.
-----Input-----
The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·10^5, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 10^9) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.
Second line of the input contains a string of length n containing symbols 'w' and 'h'.
If the i-th position of a string contains 'w', then the photo i should be seen in the horizontal orientation.
If the i-th position of a string contains 'h', then the photo i should be seen in vertical orientation.
-----Output-----
Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds.
-----Examples-----
Input
4 2 3 10
wwhw
Output
2
Input
5 2 4 13
hhwhh
Output
4
Input
5 2 4 1000
hhwhh
Output
5
Input
3 1 100 10
whw
Output
0
-----Note-----
In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.
Note that in the last sample test the time is not enough even to watch the first photo, also you can't skip it.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 5\\n1 2 0 4\\n1 2 0 4\\n5 0 0 3\\n0 5 0 3\\n\", \"1 2\\n1\\n2\\n1\\n2\\n\", \"1 2\\n1\\n1\\n2\\n2\\n\", \"2 2\\n1 0\\n0 2\\n0 1\\n0 2\\n\", \"7 14\\n2 11 1 14 9 8 5\\n12 6 7 1 10 2 3\\n14 13 9 8 5 4 11\\n13 6 4 3 12 7 10\\n\", \"2 1\\n0 0\\n0 0\\n0 1\\n0 1\\n\", \"2 3\\n0 2\\n0 1\\n3 2\\n3 1\\n\", \"1 1\\n0\\n1\\n0\\n1\\n\", \"2 4\\n3 4\\n2 1\\n3 4\\n2 1\\n\", \"3 5\\n2 1 5\\n5 3 2\\n4 0 1\\n0 4 3\\n\", \"10 1\\n0 0 1 0 0 0 0 0 0 0\\n0 0 1 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n\", \"50 1\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"22 2\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0\\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 2 0 0 0 0\\n\", \"12 3\\n0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0\\n2 0 0 0 0 3 0 0 0 1 0 0\\n0 0 0 0 0 0 0 1 3 0 2 0\\n\", \"10 20\\n18 9 4 5 12 14 16 1 15 20\\n11 13 16 6 18 5 20 17 4 3\\n12 9 15 14 8 10 2 19 1 7\\n6 11 13 2 7 19 10 3 8 17\\n\", \"15 30\\n20 24 17 13 26 8 5 6 27 14 18 22 25 2 15\\n4 12 6 25 3 5 28 11 15 21 9 26 7 17 13\\n19 20 24 16 2 23 8 29 22 30 1 27 10 14 18\\n9 29 3 7 12 28 10 16 23 19 21 1 30 11 4\\n\"], \"outputs\": [\"6\\n1 1 1\\n2 1 2\\n4 1 4\\n3 4 4\\n5 3 2\\n5 4 2\\n\", \"-1\\n\", \"2\\n1 1 1\\n2 4 1\\n\", \"7\\n2 2 1\\n1 2 2\\n2 3 1\\n1 2 1\\n2 3 2\\n1 1 1\\n2 4 2\\n\", \"-1\\n\", \"1\\n1 4 2\\n\", \"7\\n1 2 1\\n2 2 2\\n3 4 1\\n1 3 1\\n2 1 2\\n1 3 2\\n1 4 2\\n\", \"2\\n1 3 1\\n1 4 1\\n\", \"-1\\n\", \"18\\n4 3 2\\n5 3 1\\n3 2 1\\n2 2 2\\n1 2 3\\n4 4 2\\n5 3 2\\n3 3 1\\n2 2 1\\n1 2 2\\n5 3 3\\n3 3 2\\n2 1 1\\n1 1 2\\n5 2 3\\n3 3 3\\n5 1 3\\n3 4 3\\n\", \"1\\n1 1 3\\n\", \"34\\n1 3 27\\n1 3 28\\n1 3 29\\n1 3 30\\n1 3 31\\n1 3 32\\n1 3 33\\n1 3 34\\n1 3 35\\n1 3 36\\n1 3 37\\n1 3 38\\n1 3 39\\n1 3 40\\n1 3 41\\n1 3 42\\n1 3 43\\n1 3 44\\n1 3 45\\n1 3 46\\n1 3 47\\n1 3 48\\n1 3 49\\n1 3 50\\n1 2 50\\n1 2 49\\n1 2 48\\n1 2 47\\n1 2 46\\n1 2 45\\n1 2 44\\n1 2 43\\n1 2 42\\n1 1 42\\n\", \"65\\n2 2 13\\n1 3 21\\n2 2 12\\n1 3 22\\n2 2 11\\n1 2 22\\n2 2 10\\n1 2 21\\n2 2 9\\n1 2 20\\n2 2 8\\n1 2 19\\n2 2 7\\n1 2 18\\n2 2 6\\n1 2 17\\n2 2 5\\n1 2 16\\n2 2 4\\n1 2 15\\n2 2 3\\n1 2 14\\n2 2 2\\n1 2 13\\n2 2 1\\n1 2 12\\n2 3 1\\n1 2 11\\n2 3 2\\n1 2 10\\n2 3 3\\n1 2 9\\n2 3 4\\n1 2 8\\n2 3 5\\n1 2 7\\n2 3 6\\n1 2 6\\n2 3 7\\n1 2 5\\n2 3 8\\n1 2 4\\n2 3 9\\n1 2 3\\n2 3 10\\n1 2 2\\n2 3 11\\n1 2 1\\n2 3 12\\n1 3 1\\n2 3 13\\n1 3 2\\n2 3 14\\n1 3 3\\n2 3 15\\n1 3 4\\n2 3 16\\n1 3 5\\n2 3 17\\n1 3 6\\n2 3 18\\n1 3 7\\n2 4 18\\n1 3 8\\n1 4 8\\n\", \"38\\n1 3 11\\n3 3 7\\n2 3 2\\n1 3 12\\n3 3 8\\n2 3 3\\n1 2 12\\n3 3 9\\n2 3 4\\n1 2 11\\n3 4 9\\n2 3 5\\n1 2 10\\n2 3 6\\n1 2 9\\n2 3 7\\n1 2 8\\n2 3 8\\n1 2 7\\n2 3 9\\n1 2 6\\n2 3 10\\n1 2 5\\n2 3 11\\n1 2 4\\n2 4 11\\n1 2 3\\n1 2 2\\n1 2 1\\n1 3 1\\n1 3 2\\n1 3 3\\n1 3 4\\n1 3 5\\n1 3 6\\n1 3 7\\n1 3 8\\n1 4 8\\n\", \"-1\\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be represented as a rectangle with $4$ rows and $n$ ($n \le 50$) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having $k$ ($k \le 2n$) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places.
[Image] Illustration to the first example.
However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space.
Allen knows he will be a very busy man, and will only have time to move cars at most $20000$ times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important.
-----Input-----
The first line of the input contains two space-separated integers $n$ and $k$ ($1 \le n \le 50$, $1 \le k \le 2n$), representing the number of columns and the number of cars, respectively.
The next four lines will contain $n$ integers each between $0$ and $k$ inclusive, representing the initial state of the parking lot. The rows are numbered $1$ to $4$ from top to bottom and the columns are numbered $1$ to $n$ from left to right.
In the first and last line, an integer $1 \le x \le k$ represents a parking spot assigned to car $x$ (you can only move this car to this place), while the integer $0$ represents a empty space (you can't move any car to this place).
In the second and third line, an integer $1 \le x \le k$ represents initial position of car $x$, while the integer $0$ represents an empty space (you can move any car to this place).
Each $x$ between $1$ and $k$ appears exactly once in the second and third line, and exactly once in the first and fourth line.
-----Output-----
If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $20000$ car moves, then print $m$, the number of moves, on the first line. On the following $m$ lines, print the moves (one move per line) in the format $i$ $r$ $c$, which corresponds to Allen moving car $i$ to the neighboring space at row $r$ and column $c$.
If it is not possible for Allen to move all the cars to the correct spaces with at most $20000$ car moves, print a single line with the integer $-1$.
-----Examples-----
Input
4 5
1 2 0 4
1 2 0 4
5 0 0 3
0 5 0 3
Output
6
1 1 1
2 1 2
4 1 4
3 4 4
5 3 2
5 4 2
Input
1 2
1
2
1
2
Output
-1
Input
1 2
1
1
2
2
Output
2
1 1 1
2 4 1
-----Note-----
In the first sample test case, all cars are in front of their spots except car $5$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $20000$ will be accepted.
In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 1\\n1 1 4 2\\n\", \"3 1\\n2 2 2\\n\", \"10 20\\n6 4 7 10 4 5 5 3 7 10\\n\", \"30 7\\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2\\n\", \"2 0\\n182 2\\n\", \"123 54564\\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94 57 65 85 64 47 24 20 34 86 26 91 98 12 36 96 80 4 70 40 95 38 70 22 58 50 34 84 80 45 14 60 61 43 11 56 19 59 50 63 21 15 97 98 27 13 9 71 32 18 90 10 2 99 75 87 74 83 79 37 89 3 49 27 92 95 49 1 26 50 72 75 81 37 60 98 28 28 10 93 99 63 14 26 69 51 47 59 42 7 20 17 75 44 44 20 44 85 27 32 65 95 47 46 12 22 64 77 21\\n\", \"111 10\\n2 8 6 1 3 5 8 3 8 2 9 9 6 9 8 8 5 2 3 8 8 3 8 3 7 9 4 3 9 7 1 8 3 1 5 5 5 8 2 4 2 7 9 1 4 4 3 1 6 7 7 4 1 3 5 3 9 4 4 4 8 8 7 3 5 6 3 3 8 2 8 4 5 8 1 8 4 1 7 1 4 9 8 9 7 6 5 6 3 7 4 8 9 3 8 9 9 3 5 9 1 3 6 8 9 1 1 3 8 7 6\\n\", \"10 1000000\\n307196 650096 355966 710719 99165 959865 500346 677478 614586 6538\\n\", \"5 1000000\\n145119584 42061308 953418415 717474449 57984109\\n\", \"100 20\\n2 5 3 3 2 7 6 2 2 2 6 7 2 1 8 10 2 4 10 6 10 2 1 1 4 7 1 2 9 7 5 3 7 4 6 3 10 10 3 7 6 8 2 2 10 3 1 2 1 3 1 6 3 1 4 10 3 10 9 5 10 4 3 10 3 3 5 3 10 2 1 5 10 7 8 7 7 2 4 2 1 3 3 8 8 5 7 3 1 1 8 10 5 7 4 4 7 7 1 9\\n\", \"10 1000\\n1000000000 999999994 999999992 1000000000 999999994 999999999 999999990 999999997 999999995 1000000000\\n\", \"2 100000\\n1 3\\n\", \"4 0\\n1 4 4 4\\n\", \"4 42\\n1 1 1 1000000000\\n\", \"3 4\\n1 2 7\\n\", \"4 100\\n1 1 10 10\\n\"], \"outputs\": [\"2\\n\", \"0\\n\", \"1\\n\", \"2\\n\", \"180\\n\", \"1\\n\", \"8\\n\", \"80333\\n\", \"909357107\\n\", \"7\\n\", \"1\\n\", \"0\\n\", \"3\\n\", \"999999943\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekoland, each person has c_{i} coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to the poorest person (poorest person right after taking richest's 1 coin). In case the choice is not unique, he will select one among them at random. Sadly, Robin Hood is old and want to retire in k days. He decided to spend these last days with helping poor people.
After taking his money are taken by Robin Hood richest person may become poorest person as well, and it might even happen that Robin Hood will give his money back. For example if all people have same number of coins, then next day they will have same number of coins too.
Your task is to find the difference between richest and poorest persons wealth after k days. Note that the choosing at random among richest and poorest doesn't affect the answer.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 500 000, 0 ≤ k ≤ 10^9) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement.
The second line contains n integers, the i-th of them is c_{i} (1 ≤ c_{i} ≤ 10^9) — initial wealth of the i-th person.
-----Output-----
Print a single line containing the difference between richest and poorest peoples wealth.
-----Examples-----
Input
4 1
1 1 4 2
Output
2
Input
3 1
2 2 2
Output
0
-----Note-----
Lets look at how wealth changes through day in the first sample. [1, 1, 4, 2] [2, 1, 3, 2] or [1, 2, 3, 2]
So the answer is 3 - 1 = 2
In second sample wealth will remain the same for each person.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"5 2\\n4 2 1 10 2\\n\", \"3 2\\n3 1 2\\n\", \"5 5\\n5 5 9 100 3\\n\", \"1 1\\n1\\n\", \"1 1\\n10000000\\n\", \"6 4\\n85666 52319 21890 51912 90704 10358\\n\", \"10 5\\n66220 81797 38439 54881 86879 94346 8802 59094 57095 41949\\n\", \"8 1\\n3669 11274 87693 33658 58862 78334 42958 30572\\n\", \"2 2\\n16927 73456\\n\", \"6 6\\n21673 27126 94712 82700 59725 46310\\n\", \"10 6\\n2226 89307 11261 28772 23196 30298 10832 43119 74662 24028\\n\", \"9 7\\n6972 18785 36323 7549 27884 14286 20795 80005 67805\\n\", \"3 1\\n20230 80967 85577\\n\", \"7 1\\n783 77740 34830 89295 96042 14966 21810\\n\", \"7 3\\n94944 94750 49432 83079 89532 78359 91885\\n\"], \"outputs\": [\"20\\n3 6 7 4 5 \\n\", \"11\\n3 5 4 \\n\", \"321\\n9 8 7 6 10 \\n\", \"1\\n2 \\n\", \"10000000\\n2 \\n\", \"1070345\\n6 7 9 8 5 10 \\n\", \"2484818\\n9 8 14 12 7 6 15 10 11 13 \\n\", \"29352\\n9 2 3 4 5 6 7 8 \\n\", \"124237\\n4 3 \\n\", \"1616325\\n12 11 7 8 9 10 \\n\", \"1246672\\n16 7 14 11 13 10 15 8 9 12 \\n\", \"1034082\\n16 13 10 15 11 14 12 8 9 \\n\", \"60690\\n4 2 3 \\n\", \"5481\\n8 2 3 4 5 6 7 \\n\", \"1572031\\n4 5 10 8 6 9 7 \\n\"]}", "source": "primeintellect"}
|
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created.
All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.
Helen knows that each minute of delay of the i-th flight costs airport c_{i} burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.
-----Input-----
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart.
The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^7), here c_{i} is the cost of delaying the i-th flight for one minute.
-----Output-----
The first line must contain the minimum possible total cost of delaying the flights.
The second line must contain n different integers t_1, t_2, ..., t_{n} (k + 1 ≤ t_{i} ≤ k + n), here t_{i} is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them.
-----Example-----
Input
5 2
4 2 1 10 2
Output
20
3 6 7 4 5
-----Note-----
Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.
However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20 burles.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"3 1\\n2 2\\n\", \"3 0\\n\", \"4 3\\n3 1\\n3 2\\n3 3\\n\", \"2 1\\n1 1\\n\", \"2 3\\n1 2\\n2 1\\n2 2\\n\", \"5 1\\n3 2\\n\", \"5 1\\n2 3\\n\", \"1000 0\\n\", \"999 0\\n\", \"5 5\\n3 2\\n5 4\\n3 3\\n2 3\\n1 2\\n\", \"5 5\\n3 2\\n1 4\\n5 1\\n4 5\\n3 1\\n\", \"5 5\\n2 2\\n5 3\\n2 3\\n5 1\\n4 4\\n\", \"6 5\\n2 6\\n6 5\\n3 1\\n2 2\\n1 2\\n\", \"6 5\\n2 6\\n5 2\\n4 3\\n6 6\\n2 5\\n\", \"6 5\\n2 1\\n6 4\\n2 2\\n4 3\\n4 1\\n\"], \"outputs\": [\"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"4\\n\", \"4\\n\", \"1996\\n\", \"1993\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"4\\n\", \"2\\n\", \"3\\n\"]}", "source": "primeintellect"}
|
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases: At least one of the chips at least once fell to the banned cell. At least once two chips were on the same cell. At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).
In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.
-----Input-----
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 10^5) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers x_{i} and y_{i} (1 ≤ x_{i}, y_{i} ≤ n) — the coordinates of the i-th banned cell. All given cells are distinct.
Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.
-----Output-----
Print a single integer — the maximum points Gerald can earn in this game.
-----Examples-----
Input
3 1
2 2
Output
0
Input
3 0
Output
1
Input
4 3
3 1
3 2
3 3
Output
1
-----Note-----
In the first test the answer equals zero as we can't put chips into the corner cells.
In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.
In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 2\\n1 2 1\\n3 4\\n\", \"2 2\\n0 1\\n1 0\\n\", \"2 3\\n1 0\\n1 1 2\\n\", \"2 2\\n0 0\\n100000000 100000000\\n\", \"2 2\\n14419485 34715515\\n45193875 34715515\\n\", \"2 2\\n4114169 4536507\\n58439428 4536507\\n\", \"2 2\\n89164828 36174769\\n90570286 89164829\\n\", \"2 2\\n23720786 67248252\\n89244428 67248253\\n\", \"2 2\\n217361 297931\\n297930 83550501\\n\", \"2 2\\n72765050 72765049\\n72763816 77716490\\n\", \"2 2\\n100000000 100000000\\n100000000 100000000\\n\", \"2 2\\n100000000 100000000\\n0 0\\n\", \"2 2\\n0 0\\n0 0\\n\", \"4 2\\n0 2 7 3\\n7 9\\n\", \"4 3\\n1 5 6 7\\n8 9 10\\n\"], \"outputs\": [\"12\", \"-1\", \"4\", \"200000000\", \"108748360\", \"71204273\", \"305074712\", \"247461719\", \"-1\", \"-1\", \"400000000\", \"-1\", \"0\", \"26\", \"64\"]}", "source": "primeintellect"}
|
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some girl is equal to $b_i$ and for all $1 \leq j \leq m$ the maximal number of sweets, which $j$-th girl received from some boy is equal to $g_j$.
More formally, let $a_{i,j}$ be the number of sweets which the $i$-th boy give to the $j$-th girl. Then $b_i$ is equal exactly to the minimum among values $a_{i,1}, a_{i,2}, \ldots, a_{i,m}$ and $g_j$ is equal exactly to the maximum among values $b_{1,j}, b_{2,j}, \ldots, b_{n,j}$.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of $a_{i,j}$ for all $(i,j)$ such that $1 \leq i \leq n$ and $1 \leq j \leq m$. You are given the numbers $b_1, \ldots, b_n$ and $g_1, \ldots, g_m$, determine this number.
-----Input-----
The first line contains two integers $n$ and $m$, separated with space — the number of boys and girls, respectively ($2 \leq n, m \leq 100\,000$). The second line contains $n$ integers $b_1, \ldots, b_n$, separated by spaces — $b_i$ is equal to the minimal number of sweets, which $i$-th boy presented to some girl ($0 \leq b_i \leq 10^8$). The third line contains $m$ integers $g_1, \ldots, g_m$, separated by spaces — $g_j$ is equal to the maximal number of sweets, which $j$-th girl received from some boy ($0 \leq g_j \leq 10^8$).
-----Output-----
If the described situation is impossible, print $-1$. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
-----Examples-----
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
-----Note-----
In the first test, the minimal total number of sweets, which boys could have presented is equal to $12$. This can be possible, for example, if the first boy presented $1$ and $4$ sweets, the second boy presented $3$ and $2$ sweets and the third boy presented $1$ and $1$ sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to $12$.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to $4$. This can be possible, for example, if the first boy presented $1$, $1$, $2$ sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to $4$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"123123\\n1\\n2->00\\n\", \"123123\\n1\\n3->\\n\", \"222\\n2\\n2->0\\n0->7\\n\", \"1000000008\\n0\\n\", \"100\\n5\\n1->301\\n0->013\\n1->013\\n0->103\\n0->103\\n\", \"21222\\n10\\n1->\\n2->1\\n1->1\\n1->1\\n1->1\\n1->22\\n2->2\\n2->1\\n1->21\\n1->\\n\", \"21122\\n10\\n1->\\n2->12\\n1->\\n2->21\\n2->\\n1->21\\n1->\\n2->12\\n2->\\n1->21\\n\", \"7048431802\\n3\\n0->9285051\\n0->785476659\\n6->3187205\\n\", \"1\\n10\\n1->111\\n1->111\\n1->111\\n1->111\\n1->111\\n1->111\\n1->111\\n1->111\\n1->111\\n1->111\\n\", \"80125168586785605523636285409060490408816122518314\\n0\\n\", \"4432535330257407726572090980499847187198996038948464049414107600178053433384837707125968777715401617\\n10\\n1->\\n3->\\n5->\\n2->\\n9->\\n0->\\n4->\\n6->\\n7->\\n8->\\n\", \"332434109630379\\n20\\n7->1\\n0->2\\n3->6\\n1->8\\n6->8\\n4->0\\n9->8\\n2->4\\n4->8\\n0->1\\n1->7\\n7->3\\n3->4\\n4->6\\n6->3\\n8->4\\n3->8\\n4->2\\n2->8\\n8->1\\n\", \"88296041076454194379\\n20\\n5->62\\n8->48\\n4->\\n1->60\\n9->00\\n6->16\\n0->03\\n6->\\n3->\\n1->\\n7->02\\n2->35\\n8->86\\n5->\\n3->34\\n4->\\n8->\\n0->\\n3->46\\n6->84\\n\", \"19693141406182378241404307417907800263629336520110\\n49\\n2->\\n0->\\n3->\\n9->\\n6->\\n5->\\n1->\\n4->\\n8->\\n7->0649713852\\n0->\\n4->\\n5->\\n3->\\n1->\\n8->\\n7->\\n9->\\n6->\\n2->2563194780\\n0->\\n8->\\n1->\\n3->\\n5->\\n4->\\n7->\\n2->\\n6->\\n9->8360512479\\n0->\\n3->\\n6->\\n4->\\n2->\\n9->\\n7->\\n1->\\n8->\\n5->8036451792\\n7->\\n6->\\n5->\\n1->\\n2->\\n0->\\n8->\\n9->\\n4->\\n\", \"103\\n32\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n0->00\\n\"], \"outputs\": [\"10031003\\n\", \"1212\\n\", \"777\\n\", \"1\\n\", \"624761980\\n\", \"22222222\\n\", \"212121\\n\", \"106409986\\n\", \"97443114\\n\", \"410301862\\n\", \"0\\n\", \"110333334\\n\", \"425093096\\n\", \"3333\\n\", \"531621060\\n\"]}", "source": "primeintellect"}
|
Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "d_{i} → t_{i}", that means "replace all digits d_{i} in string s with substrings equal to t_{i}". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query "3 → " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (10^9 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero.
Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him!
-----Input-----
The first line contains string s (1 ≤ |s| ≤ 10^5), consisting of digits — the string before processing all the requests.
The second line contains a single integer n (0 ≤ n ≤ 10^5) — the number of queries.
The next n lines contain the descriptions of the queries. The i-th query is described by string "d_{i}->t_{i}", where d_{i} is exactly one digit (from 0 to 9), t_{i} is a string consisting of digits (t_{i} can be an empty string). The sum of lengths of t_{i} for all queries doesn't exceed 10^5. The queries are written in the order in which they need to be performed.
-----Output-----
Print a single integer — remainder of division of the resulting number by 1000000007 (10^9 + 7).
-----Examples-----
Input
123123
1
2->00
Output
10031003
Input
123123
1
3->
Output
1212
Input
222
2
2->0
0->7
Output
777
Input
1000000008
0
Output
1
-----Note-----
Note that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample).
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 2\\n50 110 130 40 120\\n\", \"4 1\\n2 3 4 1\\n\", \"1 1\\n4\\n\", \"2 2\\n7 5\\n\", \"3 2\\n34 3 75\\n\", \"5 2\\n932 328 886 96 589\\n\", \"10 4\\n810 8527 9736 3143 2341 6029 7474 707 2513 2023\\n\", \"20 11\\n924129 939902 178964 918687 720767 695035 577430 407131 213304 810868 596349 266075 123602 376312 36680 18426 716200 121546 61834 851586\\n\", \"100 28\\n1 2 3 5 1 1 1 4 1 5 2 4 3 2 5 4 1 1 4 1 4 5 4 1 4 5 1 3 5 1 1 1 4 2 5 2 3 5 2 2 3 2 4 5 5 5 5 1 2 4 1 3 1 1 1 4 3 1 5 2 5 1 3 3 2 4 5 1 1 3 4 1 1 3 3 1 2 4 3 3 4 4 3 1 2 1 5 1 4 4 2 3 1 3 3 4 2 4 1 1\\n\", \"101 9\\n3 2 2 1 4 1 3 2 3 4 3 2 3 1 4 4 1 1 4 1 3 3 4 1 2 1 1 3 1 2 2 4 3 1 4 3 1 1 4 4 1 2 1 1 4 2 3 4 1 2 1 4 4 1 4 3 1 4 2 1 2 1 4 3 4 3 4 2 2 4 3 2 1 3 4 3 2 2 4 3 3 2 4 1 3 2 2 4 1 3 4 2 1 3 3 2 2 1 1 3 1\\n\", \"2 2\\n1 1000000000\\n\", \"2 1\\n1 1000000000\\n\", \"11 3\\n412 3306 3390 2290 1534 316 1080 2860 253 230 3166\\n\", \"10 3\\n2414 294 184 666 2706 1999 2201 1270 904 653\\n\", \"24 4\\n33 27 12 65 19 6 46 33 57 2 21 50 73 13 59 69 51 45 39 1 6 64 39 27\\n\"], \"outputs\": [\"20\\n\", \"0\\n\", \"0\\n\", \"2\\n\", \"72\\n\", \"343\\n\", \"3707\\n\", \"921476\\n\", \"1\\n\", \"0\\n\", \"999999999\\n\", \"0\\n\", \"1122\\n\", \"707\\n\", \"9\\n\"]}", "source": "primeintellect"}
|
Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible.
Evlampiy already knows the contrast v_{i} for each of his n photos. Now he wants to split the photos into groups, so that each group contains at least k photos. As a result, each photo must belong to exactly one group.
He considers a processing time of the j-th group to be the difference between the maximum and minimum values of v_{i} in the group. Because of multithreading the processing time of a division into groups is the maximum processing time among all groups.
Split n photos into groups in a such way that the processing time of the division is the minimum possible, i.e. that the the maximum processing time over all groups as least as possible.
-----Input-----
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·10^5) — number of photos and minimum size of a group.
The second line contains n integers v_1, v_2, ..., v_{n} (1 ≤ v_{i} ≤ 10^9), where v_{i} is the contrast of the i-th photo.
-----Output-----
Print the minimal processing time of the division into groups.
-----Examples-----
Input
5 2
50 110 130 40 120
Output
20
Input
4 1
2 3 4 1
Output
0
-----Note-----
In the first example the photos should be split into 2 groups: [40, 50] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division is less than 20.
In the second example the photos should be split into four groups, each containing one photo. So the minimal possible processing time of a division is 0.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7\\n-1 3\\n1 2\\n1 1\\n1 4\\n4 5\\n4 3\\n5 2\\n\", \"1\\n-1 42\\n\", \"2\\n-1 3\\n1 2\\n\", \"3\\n-1 3\\n1 1\\n1 2\\n\", \"3\\n-1 1\\n1 2\\n1 3\\n\", \"3\\n-1 3\\n1 2\\n2 1\\n\", \"20\\n-1 100\\n1 10\\n2 26\\n2 33\\n3 31\\n2 28\\n1 47\\n6 18\\n6 25\\n9 2\\n4 17\\n6 18\\n6 2\\n6 30\\n13 7\\n5 25\\n7 11\\n11 7\\n17 40\\n12 43\\n\", \"20\\n-1 100\\n1 35\\n2 22\\n3 28\\n3 2\\n4 8\\n3 17\\n2 50\\n5 37\\n5 25\\n4 29\\n9 21\\n10 16\\n10 39\\n11 41\\n9 28\\n9 30\\n12 36\\n13 26\\n19 17\\n\", \"20\\n-1 100\\n1 35\\n1 22\\n1 28\\n1 2\\n1 8\\n1 17\\n1 50\\n5 37\\n1 25\\n1 29\\n5 21\\n4 16\\n2 39\\n1 41\\n3 28\\n3 30\\n2 36\\n2 26\\n14 17\\n\", \"3\\n-1 1\\n1 42\\n1 42\\n\", \"2\\n-1 1\\n1 2\\n\", \"3\\n-1 1\\n1 2\\n2 3\\n\", \"4\\n-1 1\\n1 42\\n1 42\\n1 42\\n\", \"4\\n-1 1\\n1 100\\n1 100\\n1 100\\n\"], \"outputs\": [\"17\\n\", \"42\\n\", \"3\\n\", \"6\\n\", \"6\\n\", \"3\\n\", \"355\\n\", \"459\\n\", \"548\\n\", \"85\\n\", \"2\\n\", \"3\\n\", \"126\\n\", \"300\\n\"]}", "source": "primeintellect"}
|
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will call person a a subordinates of another person b, if either b is an immediate supervisor of a, or the immediate supervisor of a is a subordinate to person b. In particular, subordinates of the head are all other employees of the company.
To solve achieve an Important Goal we need to form a workgroup. Every person has some efficiency, expressed by a positive integer a_{i}, where i is the person's number. The efficiency of the workgroup is defined as the total efficiency of all the people included in it.
The employees of the big software company are obsessed with modern ways of work process organization. Today pair programming is at the peak of popularity, so the workgroup should be formed with the following condition. Each person entering the workgroup should be able to sort all of his subordinates who are also in the workgroup into pairs. In other words, for each of the members of the workgroup the number of his subordinates within the workgroup should be even.
Your task is to determine the maximum possible efficiency of the workgroup formed at observing the given condition. Any person including the director of company can enter the workgroup.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 2·10^5) — the number of workers of the Big Software Company.
Then n lines follow, describing the company employees. The i-th line contains two integers p_{i}, a_{i} (1 ≤ a_{i} ≤ 10^5) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency. For the director p_1 = - 1, for all other people the condition 1 ≤ p_{i} < i is fulfilled.
-----Output-----
Print a single integer — the maximum possible efficiency of the workgroup.
-----Examples-----
Input
7
-1 3
1 2
1 1
1 4
4 5
4 3
5 2
Output
17
-----Note-----
In the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n1 3 2 4\\n\", \"1\\n34688642\\n\", \"2\\n-492673762 -496405053\\n\", \"4\\n-432300451 509430974 -600857890 -140418957\\n\", \"16\\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\\n\", \"8\\n-311553829 469225525 -933496047 -592182543 -29674334 -268378634 -985852520 -225395842\\n\", \"3\\n390029247 153996608 -918017777\\n\", \"5\\n450402558 -840167367 -231820501 586187125 -627664644\\n\", \"6\\n-76959846 -779700294 380306679 -340361999 58979764 -392237502\\n\", \"7\\n805743163 -181176136 454376774 681211377 988713965 -599336611 -823748404\\n\", \"11\\n686474839 417121618 697288626 -353703861 -630836661 -885184394 755247261 -611483316 -204713255 -618261009 -223868114\\n\", \"13\\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\\n\", \"17\\n-542470641 -617247806 998970243 699622219 565143960 -860452587 447120886 203125491 707835273 960261677 908578885 550556483 718584588 -844249102 -360207707 702669908 297223934\\n\", \"19\\n-482097330 -201346367 -19865188 742768969 -113444726 -736593719 -223932141 474661760 -517960081 -808531390 -667493854 90097774 -45779385 200613819 -132533405 -931316230 -69997546 -623661790 -4421275\\n\"], \"outputs\": [\"1 4\\n-4 -12 -8 0\\n1 3\\n3 9 6 \\n4 4\\n-4\\n\", \"1 1\\n-34688642\\n1 1\\n0\\n1 1\\n0\\n\", \"1 2\\n985347524 0\\n1 1\\n-492673762 \\n2 2\\n496405053\\n\", \"1 4\\n1729201804 -2037723896 2403431560 0\\n1 3\\n-1296901353 1528292922 -1802573670 \\n4 4\\n140418957\\n\", \"1 16\\n241731792 -7828171872 -10908965712 1261781840 6663483888 14343092320 -14467076736 14922282304 -2771988832 -6435316288 5269175968 -8603136720 14387734816 -14437567712 9529436064 0\\n1 15\\n-226623555 7338911130 10227155355 -1182920475 -6247016145 -13446649050 13562884440 -13989639660 2598739530 6033109020 -4939852470 8065440675 -13488501390 13535219730 -8933846310 \\n16 16\\n480337024\\n\", \"1 8\\n2492430632 -3753804200 7467968376 4737460344 237394672 2147029072 7886820160 0\\n1 7\\n-2180876803 3284578675 -6534472329 -4145277801 -207720338 -1878650438 -6900967640 \\n8 8\\n225395842\\n\", \"1 3\\n-1170087741 -461989824 0\\n1 2\\n780058494 307993216 \\n3 3\\n918017777\\n\", \"1 5\\n-2252012790 4200836835 1159102505 -2930935625 0\\n1 4\\n1801610232 -3360669468 -927282004 2344748500 \\n5 5\\n627664644\\n\", \"1 6\\n461759076 4678201764 -2281840074 2042171994 -353878584 0\\n1 5\\n-384799230 -3898501470 1901533395 -1701809995 294898820 \\n6 6\\n392237502\\n\", \"1 7\\n-5640202141 1268232952 -3180637418 -4768479639 -6920997755 4195356277 0\\n1 6\\n4834458978 -1087056816 2726260644 4087268262 5932283790 -3596019666 \\n7 7\\n823748404\\n\", \"1 11\\n-7551223229 -4588337798 -7670174886 3890742471 6939203271 9737028334 -8307719871 6726316476 2251845805 6800871099 0\\n1 10\\n6864748390 4171216180 6972886260 -3537038610 -6308366610 -8851843940 7552472610 -6114833160 -2047132550 -6182610090 \\n11 11\\n223868114\\n\", \"1 13\\n12456399241 7501550641 8014683287 7197409739 9353379867 9897231838 2740049780 584736789 -11237962918 5031702962 -7109751272 -8299843760 0\\n1 12\\n-11498214684 -6924508284 -7398169188 -6643762836 -8633889108 -9135906312 -2529276720 -539757036 10373504232 -4644648888 6562847328 7661394240 \\n13 13\\n-299190036\\n\", \"1 17\\n9222000897 10493212702 -16982494131 -11893577723 -9607447320 14627693979 -7601055062 -3453133347 -12033199641 -16324448509 -15445841045 -9359460211 -12215937996 14352234734 6123531019 -11945388436 0\\n1 16\\n-8679530256 -9875964896 15983523888 11193955504 9042303360 -13767241392 7153934176 3250007856 11325364368 15364186832 14537262160 8808903728 11497353408 -13507985632 -5763323312 11242718528 \\n17 17\\n-297223934\\n\", \"1 19\\n9159849270 3825580973 377438572 -14112610411 2155449794 13995280661 4254710679 -9018573440 9841241539 15362096410 12682383226 -1711857706 869808315 -3811662561 2518134695 17695008370 1329953374 11849574010 0\\n1 18\\n-8677751940 -3624234606 -357573384 13369841442 -2042005068 -13258686942 -4030778538 8543911680 -9323281458 -14553565020 -12014889372 1621759932 -824028930 3611048742 -2385601290 -16763692140 -1259955828 -11225912220 \\n19 19\\n4421275\\n\"]}", "source": "primeintellect"}
|
You are given an array $a$ of $n$ integers.
You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where $len$ is the length of this segment (added integers can be different).
It can be proven that it is always possible to make all elements of $a$ equal to zero.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 100\,000$): the number of elements of the array.
The second line contains $n$ elements of an array $a$ separated by spaces: $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
The output should contain six lines representing three operations.
For each operation, print two lines:
The first line contains two integers $l$, $r$ ($1 \le l \le r \le n$): the bounds of the selected segment.
The second line contains $r-l+1$ integers $b_l, b_{l+1}, \dots, b_r$ ($-10^{18} \le b_i \le 10^{18}$): the numbers to add to $a_l, a_{l+1}, \ldots, a_r$, respectively; $b_i$ should be divisible by $r - l + 1$.
-----Example-----
Input
4
1 3 2 4
Output
1 1
-1
3 4
4 2
2 4
-3 -6 -6
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n3 6 9 12 15\\n\", \"4\\n3 7 5 2\\n\", \"1\\n1\\n\", \"16\\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082\\n\", \"18\\n341796022 486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 882144246 60135494 374392733 408166459 179944793 331468916 401182818 69503967\\n\", \"17\\n458679894 912524637 347508634 863280107 226481104 787939275 48953130 553494227 458256339 673787326 353107999 298575751 436592642 233596921 957974470 254020999 707869688\\n\", \"19\\n519879446 764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759\\n\", \"1\\n1000000000\\n\", \"3\\n524125987 923264237 374288891\\n\", \"4\\n702209411 496813081 673102149 561219907\\n\", \"5\\n585325539 365329221 412106895 291882089 564718673\\n\", \"6\\n58376259 643910770 5887448 757703054 544067926 902981667\\n\", \"7\\n941492387 72235422 449924898 783332532 378192988 592684636 147499872\\n\", \"2\\n500000004 500000003\\n\"], \"outputs\": [\"36\\n\", \"1000000006\\n\", \"1\\n\", \"347261016\\n\", \"773499683\\n\", \"769845668\\n\", \"265109293\\n\", \"1000000000\\n\", \"996365563\\n\", \"317278572\\n\", \"974257995\\n\", \"676517605\\n\", \"328894634\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
Karen has just arrived at school, and she has a math test today! [Image]
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.
Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.
The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.
Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?
Since this number can be quite large, output only the non-negative remainder after dividing it by 10^9 + 7.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.
The next line contains n integers. Specifically, the i-th one among these is a_{i} (1 ≤ a_{i} ≤ 10^9), the i-th number on the first row.
-----Output-----
Output a single integer on a line by itself, the number on the final row after performing the process above.
Since this number can be quite large, print only the non-negative remainder after dividing it by 10^9 + 7.
-----Examples-----
Input
5
3 6 9 12 15
Output
36
Input
4
3 7 5 2
Output
1000000006
-----Note-----
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.
Karen performs the operations as follows: [Image]
The non-negative remainder after dividing the final number by 10^9 + 7 is still 36, so this is the correct output.
In the second test case, the numbers written on the first row are 3, 7, 5 and 2.
Karen performs the operations as follows: [Image]
The non-negative remainder after dividing the final number by 10^9 + 7 is 10^9 + 6, so this is the correct output.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 1\\n1 1 2 2\\n2 2 3 3\\n3 3 4 4\\n\", \"4 1\\n1 1 2 2\\n1 9 2 10\\n9 9 10 10\\n9 1 10 2\\n\", \"3 0\\n1 1 2 2\\n1 1 1000000000 1000000000\\n1 3 8 12\\n\", \"11 8\\n9 1 11 5\\n2 2 8 12\\n3 8 23 10\\n2 1 10 5\\n7 1 19 5\\n1 8 3 10\\n1 5 3 9\\n1 2 3 4\\n1 2 3 4\\n4 2 12 16\\n8 5 12 9\\n\", \"20 5\\n1 12 21 22\\n9 10 15 20\\n10 12 12 20\\n1 1 25 29\\n5 10 21 22\\n4 9 16 25\\n12 10 14 24\\n3 3 19 27\\n3 4 23 28\\n9 1 11 31\\n9 14 17 18\\n8 12 14 20\\n8 11 18 19\\n12 3 14 29\\n7 8 13 22\\n6 4 16 30\\n11 3 13 27\\n9 16 15 18\\n6 13 14 21\\n9 12 15 22\\n\", \"1 0\\n1 1 100 100\\n\", \"1 0\\n1 1 2 2\\n\", \"1 0\\n1 1 4 4\\n\", \"2 1\\n1 1 1000000000 1000000000\\n100 200 200 300\\n\", \"2 1\\n1 1 1000000000 2\\n1 1 2 1000000000\\n\", \"2 1\\n1 1 999999999 1000000000\\n1 1 1000000000 999999999\\n\", \"1 0\\n1 1 1000000000 1000000000\\n\", \"1 0\\n100 300 400 1000\\n\", \"1 0\\n2 2 3 3\\n\"], \"outputs\": [\"1\\n\", \"64\\n\", \"249999999000000001\\n\", \"4\\n\", \"4\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be positive integers.
Edo figured out how he wants to place the magnets on the refrigerator. He introduced a system of coordinates on the plane, where each magnet is represented as a rectangle with sides parallel to the coordinate axes.
Now he wants to remove no more than k magnets (he may choose to keep all of them) and attach all remaining magnets to the refrigerator door, and the area of the door should be as small as possible. A magnet is considered to be attached to the refrigerator door if its center lies on the door or on its boundary. The relative positions of all the remaining magnets must correspond to the plan.
Let us explain the last two sentences. Let's suppose we want to hang two magnets on the refrigerator. If the magnet in the plan has coordinates of the lower left corner (x_1, y_1) and the upper right corner (x_2, y_2), then its center is located at ($\frac{x_{1} + x_{2}}{2}$, $\frac{y_{1} + y_{2}}{2}$) (may not be integers). By saying the relative position should correspond to the plan we mean that the only available operation is translation, i.e. the vector connecting the centers of two magnets in the original plan, must be equal to the vector connecting the centers of these two magnets on the refrigerator.
The sides of the refrigerator door must also be parallel to coordinate axes.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ min(10, n - 1)) — the number of magnets that Edo has and the maximum number of magnets Edo may not place on the refrigerator.
Next n lines describe the initial plan of placing magnets. Each line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 < x_2 ≤ 10^9, 1 ≤ y_1 < y_2 ≤ 10^9) — the coordinates of the lower left and upper right corners of the current magnet. The magnets can partially overlap or even fully coincide.
-----Output-----
Print a single integer — the minimum area of the door of refrigerator, which can be used to place at least n - k magnets, preserving the relative positions.
-----Examples-----
Input
3 1
1 1 2 2
2 2 3 3
3 3 4 4
Output
1
Input
4 1
1 1 2 2
1 9 2 10
9 9 10 10
9 1 10 2
Output
64
Input
3 0
1 1 2 2
1 1 1000000000 1000000000
1 3 8 12
Output
249999999000000001
-----Note-----
In the first test sample it is optimal to remove either the first or the third magnet. If we remove the first magnet, the centers of two others will lie at points (2.5, 2.5) and (3.5, 3.5). Thus, it is enough to buy a fridge with door width 1 and door height 1, the area of the door also equals one, correspondingly.
In the second test sample it doesn't matter which magnet to remove, the answer will not change — we need a fridge with door width 8 and door height 8.
In the third sample you cannot remove anything as k = 0.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 5 9\\n2 3 4 5\\n\", \"3 3 4\\n1 2 4\\n\", \"100 8883 915\\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 2900 239 3551 1977 2420 3361 3035 956 2539 1056 1837 477 1894 1762 1835 3577 2730 950 2960 1004 3293 2401 1271 2388 3950 1908 2804 2011 4952 3075 2507 2992 1883 1591 1095 959 1611 4749 3717 2245 207 814 4862 3525 2371 3277 817 701 574 2964 1278 705 1397 415 2892\\n\", \"53 7311 233\\n163 70 172 6330 5670 33 59 7 3432 199 197 3879 145 226 117 26 116 98 981 6054 114 48 36 135 174 185 7249 192 150 11 65 83 62 61 88 7291 222 41 1257 20 6551 119 34 7246 6830 200 760 207 1641 97 118 115 481\\n\", \"70 416035 416023\\n70034 70322 345689 345965 345701 70046 345737 345713 70166 345821 70010 345749 345677 345725 69962 345869 70178 70310 345785 69998 70070 69974 70058 346001 70106 345953 70226 70154 345929 69950 70298 346049 70346 345989 70286 69986 345893 70082 70238 345797 70250 345833 70334 345845 70094 70118 70202 345977 70262 70274 70190 345941 346025 345761 345773 70142 70022 70130 345881 345917 70358 345905 345665 346013 346061 345809 345857 346037 346073 70214\\n\", \"1 2 2\\n1\\n\", \"1 2 3\\n1\\n\", \"2 2 3\\n1 2\\n\", \"1 527802320 589732288\\n418859112\\n\", \"1 1 1\\n1\\n\", \"4 10 9\\n6 5 4 3\\n\", \"8 12 13\\n2 10 3 9 4 8 5 7\\n\", \"4 7 9\\n2 4 5 7\\n\"], \"outputs\": [\"YES\\n0 0 1 1\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1 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\", \"YES\\n0\\n\", \"YES\\n0\\n\", \"YES\\n1 1\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1 1 1 1\\n\", \"YES\\n0 0 0 0 0 0 0 0\\n\", \"YES\\n1 1 1 1\\n\"]}", "source": "primeintellect"}
|
Little X has n distinct integers: p_1, p_2, ..., p_{n}. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number a - x must also belong to set A. If number x belongs to set B, then number b - x must also belong to set B.
Help Little X divide the numbers into two sets or determine that it's impossible.
-----Input-----
The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 10^5; 1 ≤ a, b ≤ 10^9). The next line contains n space-separated distinct integers p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ 10^9).
-----Output-----
If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b_1, b_2, ..., b_{n} (b_{i} equals either 0, or 1), describing the division. If b_{i} equals to 0, then p_{i} belongs to set A, otherwise it belongs to set B.
If it's impossible, print "NO" (without the quotes).
-----Examples-----
Input
4 5 9
2 3 4 5
Output
YES
0 0 1 1
Input
3 3 4
1 2 4
Output
NO
-----Note-----
It's OK if all the numbers are in the same set, and the other one is empty.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n1 1\\n\", \"2\\n1 2\\n\", \"5\\n0 0 0 0 35\\n\", \"5\\n8 4 2 0 1\\n\", \"5\\n24348 15401 19543 206086 34622\\n\", \"10\\n7758 19921 15137 1138 90104 17467 82544 55151 3999 6781\\n\", \"2\\n0 1\\n\", \"2\\n184931 115069\\n\", \"100\\n9 0 2 8 3 6 55 1 11 12 3 8 32 18 38 16 0 27 6 3 3 4 25 2 0 0 7 3 6 16 10 26 5 4 2 38 13 1 7 4 14 8 1 9 5 26 4 8 1 11 3 4 18 2 6 11 5 6 13 9 1 1 1 2 27 0 25 3 2 6 9 5 3 17 17 2 5 1 15 41 2 2 4 4 22 64 10 31 17 7 0 0 3 5 17 20 5 1 1 4\\n\", \"100\\n4364 698 1003 1128 1513 39 4339 969 7452 3415 1154 1635 6649 136 1442 50 834 1680 107 978 983 3176 4017 1692 1113 1504 1118 396 1975 2053 2366 3022 3007 167 610 4649 14659 2331 4565 318 7232 204 7131 6122 2885 5748 1998 3833 6799 4219 8454 8698 4964 1736 1554 1665 2425 4227 1967 534 2719 80 2865 652 1920 1577 658 1165 3222 1222 1238 560 12018 768 7144 2701 501 2520 9194 8052 13092 7366 2733 6050 2914 1740 5467 546 2947 186 1789 2658 2150 19 1854 1489 7590 990 296 1647\\n\", \"2\\n300000 0\\n\", \"36\\n110 7 51 3 36 69 30 7 122 22 11 96 98 17 133 44 38 75 7 10 4 3 68 50 43 25 4 29 42 36 11 7 36 12 75 1\\n\", \"39\\n79 194 29 36 51 363 57 446 559 28 41 34 98 168 555 26 111 97 167 121 749 21 719 20 207 217 226 63 168 248 478 1231 399 518 291 14 741 149 97\\n\"], \"outputs\": [\"1\\n\", \"3\\n\", \"0\\n\", \"801604029\\n\", \"788526601\\n\", \"663099907\\n\", \"0\\n\", \"244559876\\n\", \"241327503\\n\", \"301328767\\n\", \"0\\n\", \"420723999\\n\", \"918301015\\n\"]}", "source": "primeintellect"}
|
Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2 + \ldots + a_n$ biscuits, and the owner of this biscuit will give it to a random uniform player among $n-1$ players except himself. The game stops when one person will have all the biscuits.
As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.
For convenience, as the answer can be represented as a rational number $\frac{p}{q}$ for coprime $p$ and $q$, you need to find the value of $(p \cdot q^{-1})\mod 998\,244\,353$. You can prove that $q\mod 998\,244\,353 \neq 0$.
-----Input-----
The first line contains one integer $n\ (2\le n\le 100\,000)$: the number of people playing the game.
The second line contains $n$ non-negative integers $a_1,a_2,\dots,a_n\ (1\le a_1+a_2+\dots+a_n\le 300\,000)$, where $a_i$ represents the number of biscuits the $i$-th person own at the beginning.
-----Output-----
Print one integer: the expected value of the time that the game will last, modulo $998\,244\,353$.
-----Examples-----
Input
2
1 1
Output
1
Input
2
1 2
Output
3
Input
5
0 0 0 0 35
Output
0
Input
5
8 4 2 0 1
Output
801604029
-----Note-----
For the first example, in the first second, the probability that player $1$ will give the player $2$ a biscuit is $\frac{1}{2}$, and the probability that player $2$ will give the player $1$ a biscuit is $\frac{1}{2}$. But anyway, the game will stop after exactly $1$ second because only one player will occupy all biscuits after $1$ second, so the answer is $1$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 5\\n1 2 3 1\\n2 1 2 8\\n2 3 4 7\\n1 1 3 3\\n2 3 4 8\\n\", \"4 5\\n1 2 3 1\\n2 1 2 8\\n2 3 4 7\\n1 1 3 3\\n2 3 4 13\\n\", \"1 4\\n1 1 1 2\\n2 1 1 6\\n1 1 1 1\\n2 1 1 7\\n\", \"1 4\\n1 1 1 2\\n2 1 1 6\\n1 1 1 1\\n2 1 1 8\\n\", \"1 2\\n2 1 1 8\\n2 1 1 7\\n\", \"1 2\\n2 1 1 10\\n2 1 1 5\\n\", \"2 2\\n2 1 1 10\\n2 1 2 5\\n\", \"1 2\\n2 1 1 5\\n2 1 1 1\\n\", \"2 2\\n2 1 2 8\\n2 1 2 7\\n\", \"1 2\\n2 1 1 1\\n2 1 1 0\\n\", \"1 1\\n2 1 1 40000000\\n\", \"1 2\\n2 1 1 2\\n2 1 1 1\\n\", \"3 2\\n2 1 2 100\\n2 1 3 50\\n\"], \"outputs\": [\"YES\\n8 7 4 7 \\n\", \"NO\\n\", \"YES\\n4 \\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n40000000 \\n\", \"NO\\n\", \"NO\\n\"]}", "source": "primeintellect"}
|
Levko loves array a_1, a_2, ... , a_{n}, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
Increase all elements from l_{i} to r_{i} by d_{i}. In other words, perform assignments a_{j} = a_{j} + d_{i} for all j that meet the inequation l_{i} ≤ j ≤ r_{i}. Find the maximum of elements from l_{i} to r_{i}. That is, calculate the value $m_{i} = \operatorname{max}_{j = l_{i}}^{r_{i}} a_{j}$.
Sadly, Levko has recently lost his array. Fortunately, Levko has records of all operations he has performed on array a. Help Levko, given the operation records, find at least one suitable array. The results of all operations for the given array must coincide with the record results. Levko clearly remembers that all numbers in his array didn't exceed 10^9 in their absolute value, so he asks you to find such an array.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 5000) — the size of the array and the number of operations in Levko's records, correspondingly.
Next m lines describe the operations, the i-th line describes the i-th operation. The first integer in the i-th line is integer t_{i} (1 ≤ t_{i} ≤ 2) that describes the operation type. If t_{i} = 1, then it is followed by three integers l_{i}, r_{i} and d_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n, - 10^4 ≤ d_{i} ≤ 10^4) — the description of the operation of the first type. If t_{i} = 2, then it is followed by three integers l_{i}, r_{i} and m_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n, - 5·10^7 ≤ m_{i} ≤ 5·10^7) — the description of the operation of the second type.
The operations are given in the order Levko performed them on his array.
-----Output-----
In the first line print "YES" (without the quotes), if the solution exists and "NO" (without the quotes) otherwise.
If the solution exists, then on the second line print n integers a_1, a_2, ... , a_{n} (|a_{i}| ≤ 10^9) — the recovered array.
-----Examples-----
Input
4 5
1 2 3 1
2 1 2 8
2 3 4 7
1 1 3 3
2 3 4 8
Output
YES
4 7 4 7
Input
4 5
1 2 3 1
2 1 2 8
2 3 4 7
1 1 3 3
2 3 4 13
Output
NO
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n2 1\\n1 0\\n0 1\\n\", \"5\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n\", \"10\\n-1 2\\n-3 0\\n5 5\\n4 4\\n-2 1\\n1 1\\n3 3\\n2 2\\n0 0\\n-1000000000 0\\n\", \"10\\n-678318184 2\\n-678318182 3\\n580731357 2\\n-678318182 1\\n-678318184 1\\n-678318183 0\\n-678318181 2\\n580731357 1\\n580731358 0\\n-678318183 2\\n\", \"15\\n-491189818 2\\n-491189821 6\\n-491189823 4\\n-491189821 4\\n-491189822 5\\n-491189819 1\\n-491189822 4\\n-491189822 7\\n-491189821 1\\n-491189820 2\\n-491189823 3\\n-491189817 3\\n-491189821 3\\n-491189820 0\\n-491189822 2\\n\", \"20\\n900035308 3\\n900035314 0\\n900035309 2\\n900035307 0\\n900035311 0\\n900035313 2\\n900035312 0\\n900035313 0\\n900035311 3\\n900035310 0\\n900035311 2\\n900035311 1\\n900035308 2\\n900035308 1\\n900035308 0\\n900035309 3\\n900035310 2\\n900035313 1\\n900035312 3\\n900035309 0\\n\", \"25\\n-611859852 0\\n-611859842 0\\n-611859837 0\\n-611859843 0\\n-611859863 0\\n-611859851 0\\n-611859857 0\\n-611859858 0\\n-611859845 0\\n-611859865 0\\n-611859836 0\\n-611859839 0\\n-611859850 0\\n-611859854 0\\n-611859838 0\\n-611859840 0\\n-611859860 0\\n-611859853 0\\n-611859848 0\\n-611859844 0\\n-611859861 0\\n-611859856 0\\n-611859862 0\\n-611859859 0\\n-611859849 0\\n\", \"20\\n1000000000 3\\n-1000000000 3\\n-1000000000 6\\n1000000000 7\\n-1000000000 5\\n-1000000000 8\\n-1000000000 0\\n1000000000 0\\n-1000000000 9\\n1000000000 5\\n-1000000000 4\\n1000000000 4\\n1000000000 2\\n-1000000000 7\\n-1000000000 2\\n1000000000 1\\n1000000000 9\\n1000000000 6\\n-1000000000 1\\n1000000000 8\\n\", \"2\\n72098079 0\\n72098078 1\\n\", \"2\\n-67471165 1\\n-67471166 0\\n\", \"2\\n-939306957 0\\n361808970 0\\n\", \"2\\n-32566075 1\\n-32566075 0\\n\", \"2\\n73639551 1\\n73639551 0\\n\"], \"outputs\": [\"19\\n\", \"2930\\n\", \"41236677\\n\", \"41627304\\n\", \"936629642\\n\", \"362446399\\n\", \"93673276\\n\", \"205917730\\n\", \"2\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.
The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x, y) either y = 0, or there is a cube with coordinates (x - 1, y - 1), (x, y - 1) or (x + 1, y - 1).
Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.
Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 10^9 + 9.
-----Input-----
The first line contains number m (2 ≤ m ≤ 10^5).
The following m lines contain the coordinates of the cubes x_{i}, y_{i} ( - 10^9 ≤ x_{i} ≤ 10^9, 0 ≤ y_{i} ≤ 10^9) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.
No two cubes occupy the same place.
-----Output-----
In the only line print the answer to the problem.
-----Examples-----
Input
3
2 1
1 0
0 1
Output
19
Input
5
0 0
0 1
0 2
0 3
0 4
Output
2930
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n| 3\\n^ 2\\n| 1\\n\", \"3\\n& 1\\n& 3\\n& 5\\n\", \"3\\n^ 1\\n^ 2\\n^ 3\\n\", \"2\\n| 999\\n^ 689\\n\", \"3\\n& 242\\n^ 506\\n^ 522\\n\", \"2\\n| 56\\n^ 875\\n\", \"3\\n^ 125\\n^ 377\\n& 1019\\n\", \"1\\n& 123\\n\", \"1\\n| 123\\n\", \"1\\n^ 123\\n\", \"10\\n^ 218\\n& 150\\n| 935\\n& 61\\n| 588\\n& 897\\n| 411\\n| 584\\n^ 800\\n| 704\\n\", \"10\\n^ 160\\n& 1021\\n& 510\\n^ 470\\n& 1022\\n& 251\\n& 760\\n& 1016\\n| 772\\n| 515\\n\", \"1\\n& 0\\n\", \"1\\n| 0\\n\", \"1\\n^ 0\\n\", \"1\\n& 1023\\n\", \"1\\n| 1023\\n\", \"1\\n^ 1023\\n\"], \"outputs\": [\"2\\n| 3\\n^ 2\\n\", \"1\\n& 1\\n\", \"0\\n\", \"2\\n| 999\\n^ 689\\n\", \"2\\n| 781\\n^ 253\\n\", \"2\\n| 56\\n^ 875\\n\", \"2\\n| 4\\n^ 260\\n\", \"1\\n& 123\\n\", \"1\\n| 123\\n\", \"1\\n^ 123\\n\", \"2\\n| 1023\\n^ 260\\n\", \"2\\n| 775\\n^ 112\\n\", \"1\\n& 0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n| 1023\\n\", \"1\\n^ 1023\\n\"]}", "source": "primeintellect"}
|
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines.
Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023.
-----Output-----
Output an integer k (0 ≤ k ≤ 5) — the length of your program.
Next k lines must contain commands in the same format as in the input.
-----Examples-----
Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0
-----Note-----
You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation.
Second sample:
Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n2 3\\n3 4\\n4 5\\n1 3 2\\n3 5 2\\n\", \"5 4\\n1 2\\n2 3\\n3 4\\n4 5\\n1 3 2\\n2 4 2\\n\", \"5 4\\n1 2\\n2 3\\n3 4\\n4 5\\n1 3 2\\n3 5 1\\n\", \"9 9\\n1 2\\n2 3\\n2 4\\n4 5\\n5 7\\n5 6\\n3 8\\n8 9\\n9 6\\n1 7 4\\n3 6 3\\n\", \"9 9\\n1 2\\n2 3\\n2 4\\n4 5\\n5 7\\n5 6\\n3 8\\n8 9\\n9 6\\n1 7 4\\n3 6 4\\n\", \"10 11\\n1 3\\n2 3\\n3 4\\n4 5\\n4 6\\n3 7\\n3 8\\n4 9\\n4 10\\n7 9\\n8 10\\n1 5 3\\n6 2 3\\n\", \"1 0\\n1 1 0\\n1 1 0\\n\", \"2 1\\n1 2\\n1 1 0\\n1 2 1\\n\", \"2 1\\n1 2\\n1 1 0\\n1 2 0\\n\", \"6 5\\n1 3\\n2 3\\n3 4\\n4 5\\n4 6\\n1 6 3\\n5 2 3\\n\", \"6 5\\n1 2\\n2 3\\n3 4\\n3 5\\n2 6\\n1 4 3\\n5 6 3\\n\", \"5 4\\n1 2\\n2 3\\n3 4\\n4 5\\n1 3 2\\n4 2 2\\n\"], \"outputs\": [\"0\\n\", \"1\\n\", \"-1\\n\", \"2\\n\", \"3\\n\", \"6\\n\", \"0\\n\", \"0\\n\", \"-1\\n\", \"0\\n\", \"0\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any city you can get to any other one by moving along the roads.
You want to destroy the largest possible number of roads in the country so that the remaining roads would allow you to get from city s_1 to city t_1 in at most l_1 hours and get from city s_2 to city t_2 in at most l_2 hours.
Determine what maximum number of roads you need to destroy in order to meet the condition of your plan. If it is impossible to reach the desired result, print -1.
-----Input-----
The first line contains two integers n, m (1 ≤ n ≤ 3000, $n - 1 \leq m \leq \operatorname{min} \{3000, \frac{n(n - 1)}{2} \}$) — the number of cities and roads in the country, respectively.
Next m lines contain the descriptions of the roads as pairs of integers a_{i}, b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}). It is guaranteed that the roads that are given in the description can transport you from any city to any other one. It is guaranteed that each pair of cities has at most one road between them.
The last two lines contains three integers each, s_1, t_1, l_1 and s_2, t_2, l_2, respectively (1 ≤ s_{i}, t_{i} ≤ n, 0 ≤ l_{i} ≤ n).
-----Output-----
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
-----Examples-----
Input
5 4
1 2
2 3
3 4
4 5
1 3 2
3 5 2
Output
0
Input
5 4
1 2
2 3
3 4
4 5
1 3 2
2 4 2
Output
1
Input
5 4
1 2
2 3
3 4
4 5
1 3 2
3 5 1
Output
-1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"())(())(())(\\n7\\n1 1\\n2 3\\n1 2\\n1 12\\n8 12\\n5 11\\n2 10\\n\", \"(((((()((((((((((()((()(((((\\n1\\n8 15\\n\", \"((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\\n39\\n28 56\\n39 46\\n57 63\\n29 48\\n51 75\\n14 72\\n5 70\\n51 73\\n10 64\\n31 56\\n50 54\\n15 78\\n78 82\\n1 11\\n1 70\\n1 19\\n10 22\\n13 36\\n3 10\\n34 40\\n51 76\\n64 71\\n36 75\\n24 71\\n1 63\\n5 14\\n46 67\\n32 56\\n39 43\\n43 56\\n61 82\\n2 78\\n1 21\\n10 72\\n49 79\\n12 14\\n53 79\\n15 31\\n7 47\\n\", \"))(()))))())())))))())((()()))))()))))))))))))\\n9\\n26 42\\n21 22\\n6 22\\n7 26\\n43 46\\n25 27\\n32 39\\n22 40\\n2 45\\n\", \"(()((((()(())((((((((()((((((()((((\\n71\\n15 29\\n17 18\\n5 26\\n7 10\\n16 31\\n26 35\\n2 30\\n16 24\\n2 24\\n7 12\\n15 18\\n12 13\\n25 30\\n1 30\\n12 13\\n16 20\\n6 35\\n20 28\\n18 23\\n9 31\\n12 35\\n14 17\\n8 16\\n3 10\\n12 33\\n7 19\\n2 33\\n7 17\\n21 27\\n10 30\\n29 32\\n9 28\\n18 32\\n28 31\\n31 33\\n4 26\\n15 27\\n10 17\\n8 14\\n11 28\\n8 23\\n17 33\\n4 14\\n3 6\\n6 34\\n19 23\\n4 21\\n16 27\\n14 27\\n6 19\\n31 32\\n29 32\\n9 17\\n1 21\\n2 31\\n18 29\\n16 26\\n15 18\\n4 5\\n13 20\\n9 28\\n18 30\\n1 32\\n2 9\\n16 24\\n1 20\\n4 15\\n16 23\\n19 34\\n5 22\\n5 23\\n\", \"(((())((((()()((((((()((()(((((((((((()((\\n6\\n20 37\\n28 32\\n12 18\\n7 25\\n21 33\\n4 5\\n\", \"(((()((((()()()(()))((((()(((()))()((((()))()((())\\n24\\n37 41\\n13 38\\n31 34\\n14 16\\n29 29\\n12 46\\n1 26\\n15 34\\n8 47\\n11 23\\n6 32\\n2 22\\n9 27\\n17 40\\n6 15\\n4 49\\n12 33\\n3 48\\n22 47\\n19 48\\n10 27\\n23 25\\n4 44\\n27 48\\n\", \")()((((((((((((((((()(((()()(()((((((()(((((((()()))((((())(((((((((()(((((((((\\n51\\n29 53\\n31 69\\n54 59\\n3 52\\n26 46\\n14 62\\n6 54\\n39 56\\n17 27\\n46 74\\n60 72\\n18 26\\n38 46\\n4 27\\n22 52\\n44 49\\n42 77\\n2 20\\n39 57\\n61 70\\n33 54\\n10 30\\n67 70\\n46 66\\n17 77\\n5 52\\n33 77\\n26 32\\n1 72\\n40 78\\n38 68\\n19 47\\n30 53\\n19 29\\n52 71\\n1 11\\n22 53\\n17 42\\n2 51\\n4 12\\n24 76\\n22 34\\n21 69\\n11 69\\n36 52\\n17 31\\n57 58\\n54 62\\n23 71\\n5 46\\n51 53\\n\", \"(\\n1\\n1 1\\n\", \")\\n1\\n1 1\\n\", \"()\\n1\\n1 2\\n\", \")(\\n1\\n1 2\\n\"], \"outputs\": [\"0\\n0\\n2\\n10\\n4\\n6\\n6\\n\", \"0\\n\", \"4\\n4\\n2\\n4\\n2\\n12\\n16\\n2\\n12\\n4\\n0\\n12\\n0\\n6\\n18\\n6\\n2\\n6\\n6\\n0\\n2\\n0\\n6\\n8\\n18\\n4\\n2\\n4\\n2\\n2\\n2\\n18\\n8\\n12\\n2\\n0\\n2\\n6\\n12\\n\", \"4\\n0\\n6\\n8\\n0\\n2\\n2\\n10\\n20\\n\", \"2\\n0\\n8\\n2\\n4\\n2\\n10\\n2\\n10\\n4\\n0\\n0\\n0\\n10\\n0\\n0\\n10\\n2\\n2\\n8\\n4\\n0\\n6\\n2\\n4\\n6\\n12\\n6\\n2\\n6\\n2\\n6\\n4\\n2\\n0\\n8\\n2\\n4\\n6\\n4\\n8\\n4\\n6\\n0\\n10\\n2\\n6\\n2\\n2\\n6\\n0\\n2\\n4\\n8\\n12\\n2\\n2\\n0\\n0\\n0\\n6\\n2\\n12\\n4\\n2\\n8\\n6\\n2\\n4\\n6\\n8\\n\", \"4\\n0\\n2\\n6\\n4\\n2\\n\", \"2\\n16\\n0\\n2\\n0\\n26\\n16\\n12\\n30\\n8\\n18\\n14\\n14\\n12\\n6\\n34\\n16\\n32\\n18\\n18\\n12\\n0\\n30\\n16\\n\", \"12\\n14\\n4\\n18\\n6\\n22\\n18\\n8\\n4\\n12\\n2\\n4\\n2\\n4\\n16\\n2\\n14\\n2\\n8\\n2\\n10\\n6\\n2\\n10\\n24\\n18\\n16\\n4\\n26\\n14\\n14\\n10\\n12\\n6\\n6\\n2\\n16\\n10\\n18\\n0\\n22\\n6\\n20\\n22\\n10\\n8\\n2\\n4\\n22\\n10\\n0\\n\", \"0\\n\", \"0\\n\", \"2\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The answer to the i-th query is the length of the maximum correct bracket subsequence of sequence s_{l}_{i}, s_{l}_{i} + 1, ..., s_{r}_{i}. Help Sereja answer all queries.
You can find the definitions for a subsequence and a correct bracket sequence in the notes.
-----Input-----
The first line contains a sequence of characters s_1, s_2, ..., s_{n} (1 ≤ n ≤ 10^6) without any spaces. Each character is either a "(" or a ")". The second line contains integer m (1 ≤ m ≤ 10^5) — the number of queries. Each of the next m lines contains a pair of integers. The i-th line contains integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the description of the i-th query.
-----Output-----
Print the answer to each question on a single line. Print the answers in the order they go in the input.
-----Examples-----
Input
())(())(())(
7
1 1
2 3
1 2
1 12
8 12
5 11
2 10
Output
0
0
2
10
4
6
6
-----Note-----
A subsequence of length |x| of string s = s_1s_2... s_{|}s| (where |s| is the length of string s) is string x = s_{k}_1s_{k}_2... s_{k}_{|}x| (1 ≤ k_1 < k_2 < ... < k_{|}x| ≤ |s|).
A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.
For the third query required sequence will be «()».
For the fourth query required sequence will be «()(())(())».
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"5\\n1 3 2 5 4\\n\", \"4\\n4 3 2 1\\n\", \"4\\n10 30 50 101\\n\", \"1\\n1\\n\", \"1\\n200000\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"2\\n1 200000\\n\", \"2\\n200000 1\\n\", \"10\\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967\\n\", \"3\\n1 100 1000000000\\n\", \"3\\n1000000000 100 1\\n\"], \"outputs\": [\"1 3 5 \\n2 4 \\n\", \"4 \\n3 \\n2 \\n1 \\n\", \"10 30 50 101 \\n\", \"1 \\n\", \"200000 \\n\", \"1 2 \\n\", \"2 \\n1 \\n\", \"1 200000 \\n\", \"200000 \\n1 \\n\", \"71550121 446173607 640274071 802030518 983359971 \\n402690754 598196518 796619138 799843967 \\n96204862 \\n\", \"1 100 1000000000 \\n\", \"1000000000 \\n100 \\n1 \\n\"]}", "source": "primeintellect"}
|
Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.
Ivan represent his array with increasing sequences with help of the following algorithm.
While there is at least one unused number in array Ivan repeats the following procedure: iterate through array from the left to the right; Ivan only looks at unused numbers on current iteration; if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down.
For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one — [2, 4].
Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^5) — the number of elements in Ivan's array.
The second line contains a sequence consisting of distinct integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — Ivan's array.
-----Output-----
Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.
-----Examples-----
Input
5
1 3 2 5 4
Output
1 3 5
2 4
Input
4
4 3 2 1
Output
4
3
2
1
Input
4
10 30 50 101
Output
10 30 50 101
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.5
|
{"tests": "{\"inputs\": [\"4\\n1 2 1\\n2 3 2\\n3 4 3\\n1\\n1\\n1\\n1\\n\", \"4\\n1 2 1\\n2 3 2\\n3 4 3\\n4\\n4\\n4\\n4\\n\", \"10\\n2 1 8760\\n3 1 3705\\n4 1 1862\\n5 2 7332\\n6 3 7015\\n7 5 4866\\n8 3 4465\\n9 7 8886\\n10 3 9362\\n2\\n5\\n5\\n4\\n4\\n5\\n4\\n5\\n1\\n2\\n\", \"10\\n2 1 5297\\n3 2 7674\\n4 1 1935\\n5 2 1941\\n6 3 1470\\n7 1 3823\\n8 2 4959\\n9 4 6866\\n10 9 2054\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"10\\n2 1 3921\\n3 2 3204\\n4 3 1912\\n5 4 6844\\n6 5 8197\\n7 6 7148\\n8 7 5912\\n9 8 104\\n10 9 5881\\n4\\n4\\n5\\n2\\n2\\n4\\n1\\n2\\n3\\n1\\n\", \"10\\n2 1 6818\\n3 2 9734\\n4 3 2234\\n5 4 3394\\n6 5 1686\\n7 6 3698\\n8 7 700\\n9 8 716\\n10 9 1586\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"10\\n1 6 4890\\n2 6 2842\\n3 6 7059\\n4 6 3007\\n5 6 6195\\n7 6 3962\\n8 6 3413\\n9 6 7658\\n10 6 8049\\n3\\n3\\n3\\n1\\n4\\n4\\n5\\n2\\n1\\n1\\n\", \"10\\n1 2 5577\\n3 2 6095\\n4 2 4743\\n5 2 2254\\n6 2 9771\\n7 2 7417\\n8 2 9342\\n9 2 2152\\n10 2 5785\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"10\\n2 1 2464\\n3 1 5760\\n4 3 9957\\n5 1 6517\\n6 4 8309\\n7 3 3176\\n8 7 1982\\n9 1 7312\\n10 2 3154\\n1\\n1\\n4\\n1\\n1\\n3\\n3\\n5\\n3\\n2\\n\", \"10\\n2 1 559\\n3 1 5707\\n4 2 9790\\n5 3 1591\\n6 1 7113\\n7 6 2413\\n8 6 3006\\n9 4 1935\\n10 6 5954\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"2\\n1 2 10000\\n1\\n1\\n\", \"1\\n1\\n\"], \"outputs\": [\"2\\n\", \"3\\n\", \"8760\\n\", \"5297\\n\", \"8197\\n\", \"3698\\n\", \"6195\\n\", \"5785\\n\", \"7312\\n\", \"7113\\n\", \"10000\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
DZY loves planting, and he enjoys solving tree problems.
DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every z.
For every integer sequence p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ n), DZY defines f(p) as $\operatorname{min}_{i = 1}^{n} g(i, p_{i})$.
DZY wants to find such a sequence p that f(p) has maximum possible value. But there is one more restriction: the element j can appear in p at most x_{j} times.
Please, find the maximum possible f(p) under the described restrictions.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 3000).
Each of the next n - 1 lines contains three integers a_{i}, b_{i}, c_{i} (1 ≤ a_{i}, b_{i} ≤ n; 1 ≤ c_{i} ≤ 10000), denoting an edge between a_{i} and b_{i} with length c_{i}. It is guaranteed that these edges form a tree.
Each of the next n lines describes an element of sequence x. The j-th line contains an integer x_{j} (1 ≤ x_{j} ≤ n).
-----Output-----
Print a single integer representing the answer.
-----Examples-----
Input
4
1 2 1
2 3 2
3 4 3
1
1
1
1
Output
2
Input
4
1 2 1
2 3 2
3 4 3
4
4
4
4
Output
3
-----Note-----
In the first sample, one of the optimal p is [4, 3, 2, 1].
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 2\\n\", \"3 1\\n\", \"5 2\\n\", \"5 4\\n\", \"10 4\\n\", \"10 3\\n\", \"10 9\\n\", \"2 1\\n\", \"4 1\\n\", \"4 2\\n\", \"9 8\\n\", \"7 5\\n\"], \"outputs\": [\"1 3 2\\n\", \"1 2 3\\n\", \"1 3 2 4 5\\n\", \"1 5 2 4 3\\n\", \"1 10 2 9 8 7 6 5 4 3\\n\", \"1 10 2 3 4 5 6 7 8 9\\n\", \"1 10 2 9 3 8 4 7 5 6\\n\", \"1 2\\n\", \"1 2 3 4\\n\", \"1 4 3 2\\n\", \"1 9 2 8 3 7 4 6 5\\n\", \"1 7 2 6 3 4 5\\n\"]}", "source": "primeintellect"}
|
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}.
Your task is to find such permutation p of length n, that the group of numbers |p_1 - p_2|, |p_2 - p_3|, ..., |p_{n} - 1 - p_{n}| has exactly k distinct elements.
-----Input-----
The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 10^5).
-----Output-----
Print n integers forming the permutation. If there are multiple answers, print any of them.
-----Examples-----
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
-----Note-----
By |x| we denote the absolute value of number x.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n7 5 5 7\\n\", \"5\\n7 8 8 10 12\\n\", \"10\\n3 9 5 5 1 7 5 3 8 7\\n\", \"12\\n8 10 4 6 6 4 1 2 2 6 9 5\\n\", \"7\\n765898 894083 551320 290139 300748 299067 592728\\n\", \"13\\n987069 989619 960831 976342 972924 961800 954209 956033 998067 984513 977987 963504 985482\\n\", \"1\\n12345\\n\", \"2\\n100 20\\n\", \"3\\n100 20 50\\n\", \"3\\n20 100 50\\n\", \"3\\n20 90 100\\n\", \"5\\n742710 834126 850058 703320 972844\\n\"], \"outputs\": [\"5.666666667\\n5.666666667\\n5.666666667\\n7.000000000\\n\", \"7.000000000\\n8.000000000\\n8.000000000\\n10.000000000\\n12.000000000\\n\", \"3.000000000\\n5.000000000\\n5.000000000\\n5.000000000\\n5.000000000\\n5.000000000\\n5.000000000\\n5.000000000\\n7.500000000\\n7.500000000\\n\", \"4.777777778\\n4.777777778\\n4.777777778\\n4.777777778\\n4.777777778\\n4.777777778\\n4.777777778\\n4.777777778\\n4.777777778\\n6.000000000\\n7.000000000\\n7.000000000\\n\", \"516875.833333333\\n516875.833333333\\n516875.833333333\\n516875.833333333\\n516875.833333333\\n516875.833333333\\n592728.000000000\\n\", \"969853.375000000\\n969853.375000000\\n969853.375000000\\n969853.375000000\\n969853.375000000\\n969853.375000000\\n969853.375000000\\n969853.375000000\\n981017.750000000\\n981017.750000000\\n981017.750000000\\n981017.750000000\\n985482.000000000\\n\", \"12345.000000000\\n\", \"60.000000000\\n60.000000000\\n\", \"56.666666667\\n56.666666667\\n56.666666667\\n\", \"20.000000000\\n75.000000000\\n75.000000000\\n\", \"20.000000000\\n90.000000000\\n100.000000000\\n\", \"742710.000000000\\n795834.666666667\\n795834.666666667\\n795834.666666667\\n972844.000000000\\n\"]}", "source": "primeintellect"}
|
There are $n$ water tanks in a row, $i$-th of them contains $a_i$ liters of water. The tanks are numbered from $1$ to $n$ from left to right.
You can perform the following operation: choose some subsegment $[l, r]$ ($1\le l \le r \le n$), and redistribute water in tanks $l, l+1, \dots, r$ evenly. In other words, replace each of $a_l, a_{l+1}, \dots, a_r$ by $\frac{a_l + a_{l+1} + \dots + a_r}{r-l+1}$. For example, if for volumes $[1, 3, 6, 7]$ you choose $l = 2, r = 3$, new volumes of water will be $[1, 4.5, 4.5, 7]$. You can perform this operation any number of times.
What is the lexicographically smallest sequence of volumes of water that you can achieve?
As a reminder:
A sequence $a$ is lexicographically smaller than a sequence $b$ of the same length if and only if the following holds: in the first (leftmost) position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 10^6$) — the number of water tanks.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — initial volumes of water in the water tanks, in liters.
Because of large input, reading input as doubles is not recommended.
-----Output-----
Print the lexicographically smallest sequence you can get. In the $i$-th line print the final volume of water in the $i$-th tank.
Your answer is considered correct if the absolute or relative error of each $a_i$ does not exceed $10^{-9}$.
Formally, let your answer be $a_1, a_2, \dots, a_n$, and the jury's answer be $b_1, b_2, \dots, b_n$. Your answer is accepted if and only if $\frac{|a_i - b_i|}{\max{(1, |b_i|)}} \le 10^{-9}$ for each $i$.
-----Examples-----
Input
4
7 5 5 7
Output
5.666666667
5.666666667
5.666666667
7.000000000
Input
5
7 8 8 10 12
Output
7.000000000
8.000000000
8.000000000
10.000000000
12.000000000
Input
10
3 9 5 5 1 7 5 3 8 7
Output
3.000000000
5.000000000
5.000000000
5.000000000
5.000000000
5.000000000
5.000000000
5.000000000
7.500000000
7.500000000
-----Note-----
In the first sample, you can get the sequence by applying the operation for subsegment $[1, 3]$.
In the second sample, you can't get any lexicographically smaller sequence.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6 11\\n1 3\\n1 4\\n1 5\\n1 6\\n2 3\\n2 4\\n2 5\\n2 6\\n3 4\\n3 5\\n3 6\\n\", \"3 0\\n\", \"2 0\\n\", \"1 0\\n\", \"2 1\\n1 2\\n\", \"4 2\\n3 2\\n1 4\\n\", \"3 3\\n1 2\\n3 1\\n2 3\\n\", \"7 5\\n7 5\\n1 5\\n3 2\\n2 6\\n3 6\\n\", \"10 10\\n1 5\\n1 8\\n1 9\\n5 8\\n8 9\\n4 7\\n2 3\\n3 10\\n2 6\\n2 10\\n\", \"5 10\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n1 3\\n2 4\\n3 5\\n4 1\\n5 2\\n\", \"15 10\\n2 3\\n5 4\\n5 6\\n5 7\\n3 8\\n3 10\\n11 12\\n12 13\\n13 14\\n14 15\\n\", \"100000 0\\n\"], \"outputs\": [\"2\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"2\\n\", \"0\\n\", \"0\\n\", \"4\\n\", \"0\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.
It is an undirected weighted graph on $n$ vertices. It is a complete graph: each pair of vertices is connected by an edge. The weight of each edge is either $0$ or $1$; exactly $m$ edges have weight $1$, and all others have weight $0$.
Since Ujan doesn't really want to organize his notes, he decided to find the weight of the minimum spanning tree of the graph. (The weight of a spanning tree is the sum of all its edges.) Can you find the answer for Ujan so he stops procrastinating?
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \leq n \leq 10^5$, $0 \leq m \leq \min(\frac{n(n-1)}{2},10^5)$), the number of vertices and the number of edges of weight $1$ in the graph.
The $i$-th of the next $m$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$), the endpoints of the $i$-th edge of weight $1$.
It is guaranteed that no edge appears twice in the input.
-----Output-----
Output a single integer, the weight of the minimum spanning tree of the graph.
-----Examples-----
Input
6 11
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
Output
2
Input
3 0
Output
0
-----Note-----
The graph from the first sample is shown below. Dashed edges have weight $0$, other edges have weight $1$. One of the minimum spanning trees is highlighted in orange and has total weight $2$. [Image]
In the second sample, all edges have weight $0$ so any spanning tree has total weight $0$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n1 1 2 3 3\\n\", \"4\\n0 1 2 3\\n\", \"1\\n120287\\n\", \"2\\n28288 0\\n\", \"2\\n95745 95745\\n\", \"13\\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599\\n\", \"13\\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743\\n\", \"35\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"35\\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4\\n\", \"35\\n0 0 298 0 0 0 0 0 689063 65442 0 984598 2054 43668 0 369 0 2054 0 996220 0 16327 369 0 996220 0 0 0 4693 2054 348 0 118 0 0\\n\", \"100\\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 10 75252 93 7302 0 81 408441 19579 10 39 19 37748 4364 31135 47700 105818 47700 10 4142 543356 3 30647 45917 60714 8939 18 22925 7302 93 75252\\n\"], \"outputs\": [\"2\\n\", \"4\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"11\\n\", \"4\\n\", \"3\\n\", \"31\\n\", \"16\\n\", \"59\\n\"]}", "source": "primeintellect"}
|
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2^{w}_{i} pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. [Image]
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2^{a}_1, ..., 2^{a}_{k} if and only if there exists a non-negative integer x such that 2^{a}_1 + 2^{a}_2 + ... + 2^{a}_{k} = 2^{x}, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
-----Input-----
The first line of input contains integer n (1 ≤ n ≤ 10^6), the number of weights.
The second line contains n integers w_1, ..., w_{n} separated by spaces (0 ≤ w_{i} ≤ 10^6 for each 1 ≤ i ≤ n), the powers of two forming the weights values.
-----Output-----
Print the minimum number of steps in a single line.
-----Examples-----
Input
5
1 1 2 3 3
Output
2
Input
4
0 1 2 3
Output
4
-----Note-----
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.875
|
{"tests": "{\"inputs\": [\"4\\n0 1 3 2\\n\", \"9\\n10 7 9 10 7 5 5 3 5\\n\", \"3\\n8 10 3\\n\", \"5\\n1000000000 1000000000 1000000000 0 0\\n\", \"1\\n0\\n\", \"3\\n2 24 18\\n\", \"7\\n23 18 5 10 29 33 36\\n\", \"19\\n1 32 25 40 18 32 5 23 38 1 35 24 39 26 0 9 26 37 0\\n\", \"96\\n79 50 37 49 30 58 90 41 77 73 31 10 8 57 73 90 86 73 72 5 43 15 11 2 59 31 38 66 19 63 33 17 14 16 44 3 99 89 11 43 14 86 10 37 1 100 84 81 57 88 37 80 65 11 18 91 18 94 76 26 73 47 49 73 21 60 69 20 72 7 5 86 95 11 93 30 84 37 34 7 15 24 95 79 47 87 64 40 2 24 49 36 83 25 71 17\\n\", \"100\\n74 88 64 8 9 27 63 64 79 97 92 38 26 1 4 4 2 64 53 62 24 82 76 40 48 58 40 59 3 56 35 37 0 30 93 71 14 97 49 37 96 59 56 55 70 88 77 99 51 55 71 25 10 31 26 50 61 18 35 55 49 33 86 25 65 74 89 99 5 27 2 9 67 29 76 68 66 22 68 59 63 16 62 25 35 57 63 35 41 68 86 22 91 67 61 3 92 46 96 74\\n\", \"94\\n89 100 92 24 4 85 63 87 88 94 68 14 61 59 5 77 82 6 13 13 25 43 80 67 29 42 89 35 72 81 35 0 12 35 53 54 63 37 52 33 11 84 64 33 65 58 89 37 59 32 23 92 14 12 30 61 5 78 39 73 21 37 64 50 10 97 12 94 20 65 63 41 86 60 47 72 79 65 31 56 23 5 85 44 4 34 66 1 92 91 60 43 18 58\\n\"], \"outputs\": [\"1 0\\n\", \"4 14\\n\", \"0 8\\n\", \"0 536870912\\n\", \"0 0\\n\", \"0 8\\n\", \"3 16\\n\", \"65 49\\n\", \"2045 43\\n\", \"2290 10\\n\", \"1961 87\\n\"]}", "source": "primeintellect"}
|
You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ denotes the operation bitwise XOR).
An inversion in the $b$ array is a pair of integers $i$ and $j$ such that $1 \le i < j \le n$ and $b_i > b_j$.
You should choose $x$ in such a way that the number of inversions in $b$ is minimized. If there are several options for $x$ — output the smallest one.
-----Input-----
First line contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of elements in $a$.
Second line contains $n$ space-separated integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
-----Output-----
Output two integers: the minimum possible number of inversions in $b$, and the minimum possible value of $x$, which achieves those number of inversions.
-----Examples-----
Input
4
0 1 3 2
Output
1 0
Input
9
10 7 9 10 7 5 5 3 5
Output
4 14
Input
3
8 10 3
Output
0 8
-----Note-----
In the first sample it is optimal to leave the array as it is by choosing $x = 0$.
In the second sample the selection of $x = 14$ results in $b$: $[4, 9, 7, 4, 9, 11, 11, 13, 11]$. It has $4$ inversions:
$i = 2$, $j = 3$; $i = 2$, $j = 4$; $i = 3$, $j = 4$; $i = 8$, $j = 9$.
In the third sample the selection of $x = 8$ results in $b$: $[0, 2, 11]$. It has no inversions.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"2\\n1 2\\n\", \"5\\n3 5 2 4 1\\n\", \"16\\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\\n\", \"9\\n1 7 8 5 3 4 6 9 2\\n\", \"5\\n2 3 4 5 1\\n\", \"9\\n4 1 8 6 7 5 2 9 3\\n\", \"10\\n3 4 1 5 7 9 8 10 6 2\\n\", \"13\\n3 1 11 12 4 5 8 10 13 7 9 2 6\\n\", \"10\\n8 4 1 7 6 10 9 5 3 2\\n\", \"2\\n2 1\\n\", \"95\\n68 56 24 89 79 20 74 69 49 59 85 67 95 66 15 34 2 13 92 25 84 77 70 71 17 93 62 81 1 87 76 38 75 31 63 51 35 33 37 11 36 52 23 10 27 90 12 6 45 32 86 26 60 47 91 65 58 80 78 88 50 9 44 4 28 29 22 8 48 7 19 57 14 54 55 83 5 30 72 18 82 94 43 46 41 3 61 53 73 39 40 16 64 42 21\\n\"], \"outputs\": [\"0.000000\\n\", \"13.000000\\n\", \"108.000000\\n\", \"33.000000\\n\", \"8.000000\\n\", \"33.000000\\n\", \"29.000000\\n\", \"69.000000\\n\", \"53.000000\\n\", \"1.000000\\n\", \"5076.000000\\n\"]}", "source": "primeintellect"}
|
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p_1, p_2, ..., p_{n}. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent permutation elements and then the boy swaps them. During his move, Furic tosses a coin and if the coin shows "heads" he chooses a random pair of adjacent elements with indexes i and i + 1, for which an inequality p_{i} > p_{i} + 1 holds, and swaps them. But if the coin shows "tails", Furik chooses a random pair of adjacent elements with indexes i and i + 1, for which the inequality p_{i} < p_{i} + 1 holds, and swaps them. If the coin shows "heads" or "tails" and Furik has multiple ways of adjacent pairs to take, then he uniformly takes one of the pairs. If Furik doesn't have any pair to take, he tosses a coin one more time. The game ends when the permutation is sorted in the increasing order.
Jeff wants the game to finish as quickly as possible (that is, he wants both players to make as few moves as possible). Help Jeff find the minimum mathematical expectation of the number of moves in the game if he moves optimally well.
You can consider that the coin shows the heads (or tails) with the probability of 50 percent.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ n) — the permutation p. The numbers are separated by spaces.
-----Output-----
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10^{ - 6}.
-----Examples-----
Input
2
1 2
Output
0.000000
Input
5
3 5 2 4 1
Output
13.000000
-----Note-----
In the first test the sequence is already sorted, so the answer is 0.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1 0\\n1\\n\", \"2 1\\n1 2\\n1 2 1\\n\", \"5 6\\n13 56 73 98 17\\n1 2 56\\n1 3 29\\n1 4 42\\n2 3 95\\n2 4 88\\n3 4 63\\n\", \"1 0\\n734135\\n\", \"10 10\\n132402 148489 472187 403302 657890 205188 750668 276911 372190 828796\\n8 10 162\\n1 8 489\\n6 7 279\\n1 10 740\\n5 6 721\\n3 6 862\\n2 3 194\\n7 10 601\\n2 10 658\\n1 5 930\\n\", \"20 20\\n265918 744212 196368 74731 293587 679367 460805 632939 453630 565881 835276 606327 181087 721045 219431 849838 370939 582350 335676 32244\\n2 16 989\\n14 19 628\\n1 6 483\\n5 8 733\\n13 19 556\\n10 17 911\\n2 7 599\\n13 17 390\\n10 20 965\\n9 11 449\\n3 15 310\\n3 6 557\\n14 18 225\\n1 18 703\\n10 18 234\\n6 14 114\\n8 18 23\\n1 7 13\\n5 6 108\\n4 12 80\\n\", \"30 7\\n757449 649347 745109 33126 786508 643820 514399 195852 220502 122381 298189 760229 330623 782818 92550 737997 981538 185996 139833 694984 605470 928975 574293 485050 265558 56466 247185 372975 847922 530210\\n21 22 604\\n3 12 859\\n24 30 56\\n15 24 627\\n3 23 494\\n2 27 409\\n13 25 806\\n\", \"40 0\\n333755 354468 763743 983044 791235 558007 639137 977841 767439 595261 276101 212062 189789 573751 751706 311404 689132 603080 300272 15008 274365 411257 191645 451302 387673 289269 427129 352075 335498 665358 917537 392450 219168 587894 920119 930721 72109 817927 33248 189473\\n\", \"5 7\\n348 348 348 348 348\\n1 2 9\\n2 4 9\\n2 3 9\\n1 4 9\\n3 5 9\\n1 3 9\\n3 4 9\\n\", \"10 23\\n483 482 483 483 483 482 483 482 483 482\\n4 6 360\\n1 4 360\\n3 4 360\\n1 2 360\\n1 9 359\\n3 5 360\\n7 9 359\\n6 7 360\\n1 6 360\\n5 10 359\\n3 7 360\\n2 9 360\\n3 10 359\\n1 10 360\\n4 5 359\\n1 7 360\\n7 8 359\\n3 8 359\\n4 7 359\\n2 7 359\\n2 10 360\\n1 8 359\\n2 5 360\\n\", \"3 3\\n100 100 1\\n1 2 50\\n1 3 49\\n2 3 49\\n\"], \"outputs\": [\"0.000000000000000\\n\", \"3.000000000000000\\n\", \"2.965517241379311\\n\", \"0.000000000000000\\n\", \"6825.351851851852200\\n\", \"55901.769230769234000\\n\", \"18129.642857142859000\\n\", \"0.000000000000000\\n\", \"77.333333333333329\\n\", \"2.690807799442897\\n\", \"4.000000000000000\\n\"]}", "source": "primeintellect"}
|
DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: $\left\{\begin{array}{ll}{\frac{v}{e}} & {(e > 0)} \\{0} & {(e = 0)} \end{array} \right.$ where v is the sum of the values of the nodes, e is the sum of the values of the edges.
Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.
An induced subgraph G'(V', E') of a graph G(V, E) is a graph that satisfies: $V^{\prime} \subseteq V$; edge $(a, b) \in E^{\prime}$ if and only if $a \in V^{\prime}, b \in V^{\prime}$, and edge $(a, b) \in E$; the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node.
Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected. [Image]
-----Input-----
The first line contains two space-separated integers n (1 ≤ n ≤ 500), $m(0 \leq m \leq \frac{n(n - 1)}{2})$. Integer n represents the number of nodes of the graph G, m represents the number of edges.
The second line contains n space-separated integers x_{i} (1 ≤ x_{i} ≤ 10^6), where x_{i} represents the value of the i-th node. Consider the graph nodes are numbered from 1 to n.
Each of the next m lines contains three space-separated integers a_{i}, b_{i}, c_{i} (1 ≤ a_{i} < b_{i} ≤ n; 1 ≤ c_{i} ≤ 10^3), denoting an edge between node a_{i} and b_{i} with value c_{i}. The graph won't contain multiple edges.
-----Output-----
Output a real number denoting the answer, with an absolute or relative error of at most 10^{ - 9}.
-----Examples-----
Input
1 0
1
Output
0.000000000000000
Input
2 1
1 2
1 2 1
Output
3.000000000000000
Input
5 6
13 56 73 98 17
1 2 56
1 3 29
1 4 42
2 3 95
2 4 88
3 4 63
Output
2.965517241379311
-----Note-----
In the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.
In the second sample, choosing the whole graph is optimal.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 4 3\\n1 2 2\\n2 4 1\\n1 3 1\\n3 4 2\\n\", \"5 11 23\\n1 2 3\\n2 3 4\\n3 4 5\\n4 5 6\\n1 3 4\\n2 4 5\\n3 5 6\\n1 4 2\\n2 5 3\\n1 5 2\\n3 2 30\\n\", \"10 16 63\\n1 2 1\\n2 10 1\\n1 3 1\\n3 10 1\\n1 4 1\\n4 10 1\\n1 5 1\\n5 10 1\\n1 6 1\\n6 10 1\\n1 7 1\\n7 10 1\\n1 8 1\\n8 10 1\\n1 9 1\\n9 10 1\\n\", \"2 1 3\\n1 2 301\\n\", \"2 2 1\\n1 2 48\\n2 1 39\\n\", \"5 9 5\\n3 2 188619\\n4 2 834845\\n2 4 996667\\n1 2 946392\\n2 5 920935\\n2 3 916558\\n1 5 433923\\n4 5 355150\\n3 5 609814\\n\", \"7 15 10\\n1 3 776124\\n6 7 769968\\n2 1 797048\\n4 3 53774\\n2 7 305724\\n4 1 963904\\n4 6 877656\\n4 5 971901\\n1 4 803781\\n3 1 457050\\n3 7 915891\\n1 7 8626\\n5 7 961155\\n3 4 891456\\n5 4 756977\\n\", \"3 2 100000\\n1 2 1\\n2 3 1\\n\", \"3 2 100000\\n1 2 1\\n2 3 1000000\\n\", \"2 1 100000\\n1 2 1\\n\", \"3 2 100000\\n1 2 1\\n2 3 100000\\n\"], \"outputs\": [\"1.5000000000\\n\", \"10.2222222222\\n\", \"7.8750000000\\n\", \"301.0000000000\\n\", \"48.0000000000\\n\", \"1182990.0000000000\\n\", \"1552248.0000000000\\n\", \"1.0000000000\\n\", \"1.0000000000\\n\", \"1.0000000000\\n\", \"1.0000000000\\n\"]}", "source": "primeintellect"}
|
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.
In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge has a weight capacity. A delivery consists of a bear carrying weights with their bear hands on a simple path from node 1 to node n. The total weight that travels across a particular edge must not exceed the weight capacity of that edge.
Niwel has exactly x bears. In the interest of fairness, no bear can rest, and the weight that each bear carries must be exactly the same. However, each bear may take different paths if they like.
Niwel would like to determine, what is the maximum amount of weight he can deliver (it's the sum of weights carried by bears). Find the maximum weight.
-----Input-----
The first line contains three integers n, m and x (2 ≤ n ≤ 50, 1 ≤ m ≤ 500, 1 ≤ x ≤ 100 000) — the number of nodes, the number of directed edges and the number of bears, respectively.
Each of the following m lines contains three integers a_{i}, b_{i} and c_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}, 1 ≤ c_{i} ≤ 1 000 000). This represents a directed edge from node a_{i} to b_{i} with weight capacity c_{i}. There are no self loops and no multiple edges from one city to the other city. More formally, for each i and j that i ≠ j it's guaranteed that a_{i} ≠ a_{j} or b_{i} ≠ b_{j}. It is also guaranteed that there is at least one path from node 1 to node n.
-----Output-----
Print one real value on a single line — the maximum amount of weight Niwel can deliver if he uses exactly x bears. Your answer will be considered correct if its absolute or relative error does not exceed 10^{ - 6}.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if $\frac{|a - b|}{\operatorname{max}(1, b)} \leq 10^{-6}$.
-----Examples-----
Input
4 4 3
1 2 2
2 4 1
1 3 1
3 4 2
Output
1.5000000000
Input
5 11 23
1 2 3
2 3 4
3 4 5
4 5 6
1 3 4
2 4 5
3 5 6
1 4 2
2 5 3
1 5 2
3 2 30
Output
10.2222222222
-----Note-----
In the first sample, Niwel has three bears. Two bears can choose the path $1 \rightarrow 3 \rightarrow 4$, while one bear can choose the path $1 \rightarrow 2 \rightarrow 4$. Even though the bear that goes on the path $1 \rightarrow 2 \rightarrow 4$ can carry one unit of weight, in the interest of fairness, he is restricted to carry 0.5 units of weight. Thus, the total weight is 1.5 units overall. Note that even though Niwel can deliver more weight with just 2 bears, he must use exactly 3 bears on this day.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"8 10 8\\n1 1 10\\n1 4 13\\n1 7 1\\n1 8 2\\n2 2 0\\n2 5 14\\n2 6 0\\n2 6 1\\n\", \"3 2 3\\n1 1 2\\n2 1 1\\n1 1 5\\n\", \"1 10 10\\n1 8 1\\n\", \"3 4 5\\n1 3 9\\n2 1 9\\n1 2 8\\n\", \"10 500 500\\n2 88 59\\n2 470 441\\n1 340 500\\n2 326 297\\n1 74 45\\n1 302 273\\n1 132 103\\n2 388 359\\n1 97 68\\n2 494 465\\n\", \"20 50000 50000\\n2 45955 55488\\n1 19804 29337\\n2 3767 90811\\n2 24025 33558\\n1 46985 56518\\n2 21094 30627\\n2 5787 15320\\n1 4262 91306\\n2 37231 46764\\n1 18125 27658\\n1 36532 12317\\n1 31330 40863\\n1 18992 28525\\n1 29387 38920\\n1 44654 54187\\n2 45485 55018\\n2 36850 46383\\n1 44649 54182\\n1 40922 50455\\n2 12781 99825\\n\", \"20 15 15\\n2 7 100000\\n1 2 100000\\n2 1 100000\\n1 9 100000\\n2 4 100000\\n2 3 100000\\n2 14 100000\\n1 6 100000\\n1 10 100000\\n2 5 100000\\n2 13 100000\\n1 8 100000\\n1 13 100000\\n1 14 100000\\n2 10 100000\\n1 5 100000\\n1 11 100000\\n1 12 100000\\n1 1 100000\\n2 2 100000\\n\", \"5 20 20\\n1 15 3\\n2 15 3\\n2 3 1\\n2 1 0\\n1 16 4\\n\", \"15 80 80\\n2 36 4\\n2 65 5\\n1 31 2\\n2 3 1\\n2 62 0\\n2 37 5\\n1 16 4\\n2 47 2\\n1 17 5\\n1 9 5\\n2 2 0\\n2 62 5\\n2 34 2\\n1 33 1\\n2 69 3\\n\", \"15 15 15\\n1 10 1\\n2 11 0\\n2 6 4\\n1 1 0\\n1 7 5\\n1 14 3\\n1 3 1\\n1 4 2\\n1 9 0\\n2 10 1\\n1 12 1\\n2 2 0\\n1 5 3\\n2 3 0\\n2 4 2\\n\", \"5 5 5\\n1 1 0\\n2 1 0\\n2 2 1\\n1 2 1\\n2 4 3\\n\"], \"outputs\": [\"4 8\\n10 5\\n8 8\\n10 6\\n10 2\\n1 8\\n7 8\\n10 6\\n\", \"1 3\\n2 1\\n1 3\\n\", \"8 10\\n\", \"3 5\\n4 1\\n2 5\\n\", \"500 494\\n97 500\\n340 500\\n302 500\\n500 470\\n500 88\\n500 326\\n132 500\\n500 388\\n74 500\\n\", \"18125 50000\\n50000 45955\\n50000 12781\\n31330 50000\\n50000 5787\\n40922 50000\\n44649 50000\\n50000 3767\\n19804 50000\\n44654 50000\\n36532 50000\\n50000 37231\\n46985 50000\\n50000 45485\\n50000 21094\\n18992 50000\\n29387 50000\\n50000 24025\\n50000 36850\\n4262 50000\\n\", \"15 7\\n15 2\\n1 15\\n9 15\\n15 4\\n15 3\\n14 15\\n6 15\\n15 10\\n5 15\\n13 15\\n8 15\\n15 13\\n15 14\\n10 15\\n15 5\\n11 15\\n12 15\\n15 1\\n2 15\\n\", \"16 20\\n15 20\\n20 3\\n20 1\\n20 15\\n\", \"80 37\\n80 65\\n31 80\\n80 3\\n80 62\\n33 80\\n16 80\\n80 47\\n17 80\\n9 80\\n80 2\\n80 62\\n80 36\\n80 34\\n80 69\\n\", \"15 10\\n12 15\\n3 15\\n1 15\\n15 2\\n15 11\\n7 15\\n15 6\\n10 15\\n9 15\\n14 15\\n5 15\\n15 4\\n15 3\\n4 15\\n\", \"5 2\\n5 4\\n2 5\\n5 1\\n1 5\\n\"]}", "source": "primeintellect"}
|
Wherever the destination is, whoever we meet, let's render this song together.
On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage.
On the sides of the stage stand n dancers. The i-th of them falls into one of the following groups: Vertical: stands at (x_{i}, 0), moves in positive y direction (upwards); Horizontal: stands at (0, y_{i}), moves in positive x direction (rightwards). [Image]
According to choreography, the i-th dancer should stand still for the first t_{i} milliseconds, and then start moving in the specified direction at 1 unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.
When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on. [Image]
Dancers stop when a border of the stage is reached. Find out every dancer's stopping position.
-----Input-----
The first line of input contains three space-separated positive integers n, w and h (1 ≤ n ≤ 100 000, 2 ≤ w, h ≤ 100 000) — the number of dancers and the width and height of the stage, respectively.
The following n lines each describes a dancer: the i-th among them contains three space-separated integers g_{i}, p_{i}, and t_{i} (1 ≤ g_{i} ≤ 2, 1 ≤ p_{i} ≤ 99 999, 0 ≤ t_{i} ≤ 100 000), describing a dancer's group g_{i} (g_{i} = 1 — vertical, g_{i} = 2 — horizontal), position, and waiting time. If g_{i} = 1 then p_{i} = x_{i}; otherwise p_{i} = y_{i}. It's guaranteed that 1 ≤ x_{i} ≤ w - 1 and 1 ≤ y_{i} ≤ h - 1. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.
-----Output-----
Output n lines, the i-th of which contains two space-separated integers (x_{i}, y_{i}) — the stopping position of the i-th dancer in the input.
-----Examples-----
Input
8 10 8
1 1 10
1 4 13
1 7 1
1 8 2
2 2 0
2 5 14
2 6 0
2 6 1
Output
4 8
10 5
8 8
10 6
10 2
1 8
7 8
10 6
Input
3 2 3
1 1 2
2 1 1
1 1 5
Output
1 3
2 1
1 3
-----Note-----
The first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure. [Image]
In the second example, no dancers collide.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 0\\n\", \"4 4\\n1 2 1\\n2 3 1\\n3 4 0\\n4 1 0\\n\", \"4 4\\n1 2 1\\n2 3 1\\n3 4 0\\n4 1 1\\n\", \"100000 0\\n\", \"100 3\\n1 2 0\\n2 3 0\\n3 1 0\\n\", \"9 2\\n1 2 0\\n2 3 0\\n\", \"28567 13\\n28079 24675 1\\n18409 26720 1\\n980 10815 1\\n20794 16571 1\\n7376 19861 1\\n11146 706 1\\n4255 16391 1\\n27376 18263 1\\n10019 28444 1\\n6574 28053 1\\n5036 16610 1\\n3543 7122 1\\n512 9554 1\\n\", \"4 4\\n1 2 0\\n2 3 0\\n2 4 0\\n3 4 0\\n\", \"4 3\\n2 3 0\\n3 4 0\\n2 4 0\\n\", \"6 6\\n1 2 0\\n2 3 1\\n3 4 0\\n4 5 1\\n5 6 0\\n6 1 1\\n\", \"5 5\\n1 2 0\\n2 3 0\\n3 4 0\\n4 5 0\\n1 5 0\\n\"], \"outputs\": [\"4\\n\", \"1\\n\", \"0\\n\", \"303861760\\n\", \"0\\n\", \"64\\n\", \"928433852\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (there is no neutral state).
You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A).
You are given a list of m known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo 1 000 000 007.
-----Input-----
The first line of input will contain two integers n, m (3 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000).
The next m lines will contain the description of the known relationships. The i-th line will contain three integers a_{i}, b_{i}, c_{i}. If c_{i} is 1, then a_{i} and b_{i} are in love, otherwise, they hate each other (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}, $c_{i} \in \{0,1 \}$).
Each pair of people will be described no more than once.
-----Output-----
Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1 000 000 007.
-----Examples-----
Input
3 0
Output
4
Input
4 4
1 2 1
2 3 1
3 4 0
4 1 0
Output
1
Input
4 4
1 2 1
2 3 1
3 4 0
4 1 1
Output
0
-----Note-----
In the first sample, the four ways are to: Make everyone love each other Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 7\\n2 4\\n5 1\\n2 3\\n3 4\\n4 1\\n5 3\\n3 5\\n\", \"2 3\\n1 2\\n1 2\\n1 2\\n\", \"5 3\\n2 4\\n5 4\\n3 2\\n\", \"10 3\\n3 4\\n1 3\\n5 2\\n\", \"20 5\\n3 12\\n5 20\\n16 4\\n13 3\\n9 14\\n\", \"50 20\\n4 18\\n39 33\\n49 32\\n7 32\\n38 1\\n46 11\\n8 1\\n3 31\\n30 47\\n24 16\\n33 5\\n5 21\\n3 48\\n13 23\\n49 50\\n18 47\\n40 32\\n9 23\\n19 39\\n25 12\\n\", \"100 50\\n55 68\\n94 68\\n39 6\\n45 32\\n59 20\\n72 53\\n41 25\\n63 32\\n78 18\\n79 97\\n17 1\\n72 64\\n85 89\\n26 25\\n82 29\\n15 1\\n8 18\\n28 3\\n33 61\\n87 25\\n90 62\\n86 60\\n90 66\\n55 10\\n16 21\\n23 97\\n38 100\\n64 66\\n63 83\\n99 97\\n97 43\\n88 21\\n79 32\\n47 36\\n83 26\\n71 52\\n76 75\\n80 1\\n48 26\\n65 87\\n73 12\\n73 21\\n46 15\\n5 32\\n77 8\\n91 90\\n39 29\\n41 70\\n36 52\\n80 88\\n\", \"5 3\\n1 2\\n4 3\\n1 5\\n\", \"10 3\\n7 9\\n3 2\\n7 1\\n\", \"50 20\\n45 33\\n44 7\\n31 41\\n45 12\\n3 13\\n18 17\\n3 39\\n31 11\\n31 1\\n44 7\\n44 23\\n18 46\\n44 1\\n45 6\\n31 22\\n18 13\\n31 22\\n45 8\\n45 17\\n18 43\\n\", \"100 50\\n29 35\\n10 75\\n29 34\\n10 87\\n29 13\\n29 38\\n41 21\\n10 6\\n29 94\\n10 47\\n31 27\\n41 24\\n41 8\\n10 93\\n41 52\\n41 36\\n31 32\\n85 81\\n31 32\\n41 79\\n41 99\\n85 88\\n41 25\\n31 68\\n41 93\\n10 87\\n85 97\\n41 85\\n10 64\\n10 68\\n85 22\\n10 45\\n85 15\\n10 16\\n10 21\\n41 66\\n29 68\\n41 96\\n29 34\\n10 22\\n41 72\\n85 54\\n29 48\\n10 100\\n29 91\\n41 43\\n85 59\\n85 10\\n31 90\\n41 64\\n\"], \"outputs\": [\"10 9 10 10 9 \\n\", \"5 6 \\n\", \"8 7 6 8 7 \\n\", \"11 11 10 10 9 16 15 14 13 12 \\n\", \"23 22 21 28 27 34 33 32 31 30 29 28 27 29 28 27 27 26 25 24 \\n\", \"99 98 97 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 93 92 91 90 89 88 87 86 85 84 100 \\n\", \"261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 271 270 269 268 267 266 265 264 263 262 \\n\", \"7 10 9 8 8 \\n\", \"18 17 16 18 17 16 15 21 20 19 \\n\", \"255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 259 258 257 256 255 254 253 252 251 250 249 248 247 246 260 259 258 257 256 \\n\", \"1442 1441 1440 1439 1438 1437 1436 1435 1434 1433 1432 1431 1430 1429 1428 1427 1426 1425 1424 1423 1422 1421 1420 1419 1418 1417 1416 1415 1414 1413 1412 1411 1410 1409 1408 1407 1406 1405 1404 1403 1402 1501 1500 1499 1498 1497 1496 1495 1494 1493 1492 1491 1490 1489 1488 1487 1486 1485 1484 1483 1482 1481 1480 1479 1478 1477 1476 1475 1474 1473 1472 1471 1470 1469 1468 1467 1466 1465 1464 1463 1462 1461 1460 1459 1458 1457 1456 1455 1454 1453 1452 1451 1450 1449 1448 1447 1446 1445 1444 1443 \\n\"]}", "source": "primeintellect"}
|
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of $n$ stations, enumerated from $1$ through $n$. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit after station $i$ is station $i+1$ if $1 \leq i < n$ or station $1$ if $i = n$. It takes the train $1$ second to travel to its next station as described.
Bob gave Alice a fun task before he left: to deliver $m$ candies that are initially at some stations to their independent destinations using the train. The candies are enumerated from $1$ through $m$. Candy $i$ ($1 \leq i \leq m$), now at station $a_i$, should be delivered to station $b_i$ ($a_i \neq b_i$). [Image] The blue numbers on the candies correspond to $b_i$ values. The image corresponds to the $1$-st example.
The train has infinite capacity, and it is possible to load off any number of candies at a station. However, only at most one candy can be loaded from a station onto the train before it leaves the station. You can choose any candy at this station. The time it takes to move the candies is negligible.
Now, Alice wonders how much time is needed for the train to deliver all candies. Your task is to find, for each station, the minimum time the train would need to deliver all the candies were it to start from there.
-----Input-----
The first line contains two space-separated integers $n$ and $m$ ($2 \leq n \leq 5\,000$; $1 \leq m \leq 20\,000$) — the number of stations and the number of candies, respectively.
The $i$-th of the following $m$ lines contains two space-separated integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$; $a_i \neq b_i$) — the station that initially contains candy $i$ and the destination station of the candy, respectively.
-----Output-----
In the first and only line, print $n$ space-separated integers, the $i$-th of which is the minimum time, in seconds, the train would need to deliver all the candies were it to start from station $i$.
-----Examples-----
Input
5 7
2 4
5 1
2 3
3 4
4 1
5 3
3 5
Output
10 9 10 10 9
Input
2 3
1 2
1 2
1 2
Output
5 6
-----Note-----
Consider the second sample.
If the train started at station $1$, the optimal strategy is as follows. Load the first candy onto the train. Proceed to station $2$. This step takes $1$ second. Deliver the first candy. Proceed to station $1$. This step takes $1$ second. Load the second candy onto the train. Proceed to station $2$. This step takes $1$ second. Deliver the second candy. Proceed to station $1$. This step takes $1$ second. Load the third candy onto the train. Proceed to station $2$. This step takes $1$ second. Deliver the third candy.
Hence, the train needs $5$ seconds to complete the tasks.
If the train were to start at station $2$, however, it would need to move to station $1$ before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is $5+1 = 6$ seconds.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"3\\n-1 -1 -1\\n\", \"2\\n2 -1\\n\", \"40\\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3\\n\", \"8\\n-1 3 -1 -1 -1 3 -1 -1\\n\", \"10\\n3 -1 -1 -1 -1 -1 -1 -1 2 2\\n\", \"50\\n36 36 45 44 -1 -1 13 -1 36 -1 44 36 -1 -1 -1 35 -1 36 36 35 -1 -1 -1 14 36 36 22 36 13 -1 35 -1 35 36 -1 -1 13 13 45 36 14 -1 36 -1 -1 -1 22 36 -1 13\\n\", \"10\\n7 7 7 7 7 7 -1 7 7 -1\\n\", \"10\\n-1 4 4 -1 4 4 -1 4 -1 4\\n\", \"10\\n-1 6 6 6 -1 -1 -1 -1 6 -1\\n\", \"10\\n-1 -1 -1 -1 -1 -1 1 -1 -1 8\\n\", \"10\\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\\n\"], \"outputs\": [\"3\\n\", \"0\\n\", \"755808950\\n\", \"124\\n\", \"507\\n\", \"949472419\\n\", \"256\\n\", \"448\\n\", \"496\\n\", \"509\\n\", \"511\\n\"]}", "source": "primeintellect"}
|
There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following steps happen until there is exactly one active startup. The following sequence of steps takes exactly 1 day. Two distinct active startups $A$, $B$, are chosen uniformly at random. A fair coin is flipped, and with equal probability, $A$ acquires $B$ or $B$ acquires $A$ (i.e. if $A$ acquires $B$, then that means $B$'s state changes from active to acquired, and its starts following $A$). When a startup changes from active to acquired, all of its previously acquired startups become active.
For example, the following scenario can happen: Let's say $A$, $B$ are active startups. $C$, $D$, $E$ are acquired startups under $A$, and $F$, $G$ are acquired startups under $B$: [Image]
Active startups are shown in red.
If $A$ acquires $B$, then the state will be $A$, $F$, $G$ are active startups. $C$, $D$, $E$, $B$ are acquired startups under $A$. $F$ and $G$ have no acquired startups: $G$
If instead, $B$ acquires $A$, then the state will be $B$, $C$, $D$, $E$ are active startups. $F$, $G$, $A$ are acquired startups under $B$. $C$, $D$, $E$ have no acquired startups: [Image]
You are given the initial state of the startups. For each startup, you are told if it is either acquired or active. If it is acquired, you are also given the index of the active startup that it is following.
You're now wondering, what is the expected number of days needed for this process to finish with exactly one active startup at the end.
It can be shown the expected number of days can be written as a rational number $P/Q$, where $P$ and $Q$ are co-prime integers, and $Q \not= 0 \pmod{10^9+7}$. Return the value of $P \cdot Q^{-1}$ modulo $10^9+7$.
-----Input-----
The first line contains a single integer $n$ ($2 \leq n \leq 500$), the number of startups.
The next line will contain $n$ space-separated integers $a_1, a_2, \ldots, a_n$ ($a_i = -1$ or $1 \leq a_i \leq n$). If $a_i = -1$, then that means startup $i$ is active. Otherwise, if $1 \leq a_i \leq n$, then startup $i$ is acquired, and it is currently following startup $a_i$. It is guaranteed if $a_i \not= -1$, then $a_{a_i} =-1$ (that is, all startups that are being followed are active).
-----Output-----
Print a single integer, the expected number of days needed for the process to end with exactly one active startup, modulo $10^9+7$.
-----Examples-----
Input
3
-1 -1 -1
Output
3
Input
2
2 -1
Output
0
Input
40
3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3
Output
755808950
-----Note-----
In the first sample, there are three active startups labeled $1$, $2$ and $3$, and zero acquired startups. Here's an example of how one scenario can happen Startup $1$ acquires startup $2$ (This state can be represented by the array $[-1, 1, -1]$) Startup $3$ acquires startup $1$ (This state can be represented by the array $[3, -1, -1]$) Startup $2$ acquires startup $3$ (This state can be represented by the array $[-1, -1, 2]$). Startup $2$ acquires startup $1$ (This state can be represented by the array $[2, -1, 2]$).
At this point, there is only one active startup, and this sequence of steps took $4$ days. It can be shown the expected number of days is $3$.
For the second sample, there is only one active startup, so we need zero days.
For the last sample, remember to take the answer modulo $10^9+7$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n1 2\\n1 3\\n2 4\\n\", \"4\\n1 2\\n1 3\\n1 4\\n\", \"6\\n2 1\\n3 2\\n4 1\\n5 4\\n1 6\\n\", \"2\\n2 1\\n\", \"3\\n1 2\\n3 2\\n\", \"5\\n3 5\\n4 3\\n2 4\\n1 2\\n\", \"6\\n4 6\\n1 5\\n5 4\\n5 3\\n2 4\\n\", \"7\\n2 7\\n2 6\\n4 7\\n7 3\\n7 5\\n1 7\\n\", \"8\\n4 5\\n1 2\\n6 3\\n2 3\\n2 8\\n4 7\\n2 4\\n\", \"9\\n5 6\\n1 3\\n2 3\\n7 6\\n4 1\\n3 6\\n8 1\\n1 9\\n\", \"10\\n5 4\\n5 2\\n3 7\\n9 3\\n3 2\\n3 1\\n3 8\\n9 10\\n1 6\\n\"], \"outputs\": [\"16\", \"24\", \"144\", \"2\", \"6\", \"40\", \"216\", \"1680\", \"2304\", \"7776\", \"19200\"]}", "source": "primeintellect"}
|
Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of $n$ nodes and $n-1$ edges. The nodes are numbered from $1$ to $n$.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in $n$ distinct points on the circle, and the edges should be straight without crossing each other.
"Without crossing each other" means that every two edges have no common point or the only common point is an endpoint of both edges.
Nauuo wants to draw the tree using a permutation of $n$ elements. A permutation of $n$ elements is a sequence of integers $p_1,p_2,\ldots,p_n$ in which every integer from $1$ to $n$ appears exactly once.
After a permutation is chosen Nauuo draws the $i$-th node in the $p_i$-th point on the circle, then draws the edges connecting the nodes.
The tree is given, Nauuo wants to know how many permutations are there so that the tree drawn satisfies the rule (the edges are straight without crossing each other). She only wants to know the answer modulo $998244353$, can you help her?
It is obvious that whether a permutation is valid or not does not depend on which $n$ points on the circle are chosen.
-----Input-----
The first line contains a single integer $n$ ($2\le n\le 2\cdot 10^5$) — the number of nodes in the tree.
Each of the next $n-1$ lines contains two integers $u$ and $v$ ($1\le u,v\le n$), denoting there is an edge between $u$ and $v$.
It is guaranteed that the given edges form a tree.
-----Output-----
The output contains a single integer — the number of permutations suitable to draw the given tree on a circle satisfying the rule, modulo $998244353$.
-----Examples-----
Input
4
1 2
1 3
2 4
Output
16
Input
4
1 2
1 3
1 4
Output
24
-----Note-----
Example 1
All valid permutations and their spanning trees are as follows.
[Image]
Here is an example of invalid permutation: the edges $(1,3)$ and $(2,4)$ are crossed.
[Image]
Example 2
Every permutation leads to a valid tree, so the answer is $4! = 24$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n1 1 1 1\\n1 -1 -1 -1 -1\\n\", \"5\\n1 2 3 1\\n1 -1 2 -1 -1\\n\", \"3\\n1 2\\n2 -1 1\\n\", \"2\\n1\\n0 -1\\n\", \"2\\n1\\n1 -1\\n\", \"5\\n1 2 2 3\\n1 -1 2 3 -1\\n\", \"5\\n1 2 3 4\\n5 -1 5 -1 7\\n\", \"10\\n1 1 1 1 2 3 4 5 1\\n3 -1 -1 -1 -1 3 3 3 3 -1\\n\", \"10\\n1 1 2 4 4 5 6 3 3\\n0 -1 -1 0 -1 -1 1 2 3 4\\n\", \"10\\n1 2 3 4 4 3 3 8 8\\n1 -1 1 -1 1 1 -1 -1 2 2\\n\", \"25\\n1 2 1 4 4 4 1 2 8 5 1 8 1 6 9 6 10 10 7 10 8 17 14 6\\n846 -1 941 -1 1126 1803 988 -1 1352 1235 -1 -1 864 -1 -1 -1 -1 -1 -1 -1 -1 1508 1802 1713 -1\\n\"], \"outputs\": [\"1\\n\", \"2\\n\", \"-1\\n\", \"0\\n\", \"1\\n\", \"3\\n\", \"7\\n\", \"3\\n\", \"7\\n\", \"2\\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
Mitya has a rooted tree with $n$ vertices indexed from $1$ to $n$, where the root has index $1$. Each vertex $v$ initially had an integer number $a_v \ge 0$ written on it. For every vertex $v$ Mitya has computed $s_v$: the sum of all values written on the vertices on the path from vertex $v$ to the root, as well as $h_v$ — the depth of vertex $v$, which denotes the number of vertices on the path from vertex $v$ to the root. Clearly, $s_1=a_1$ and $h_1=1$.
Then Mitya erased all numbers $a_v$, and by accident he also erased all values $s_v$ for vertices with even depth (vertices with even $h_v$). Your task is to restore the values $a_v$ for every vertex, or determine that Mitya made a mistake. In case there are multiple ways to restore the values, you're required to find one which minimizes the total sum of values $a_v$ for all vertices in the tree.
-----Input-----
The first line contains one integer $n$ — the number of vertices in the tree ($2 \le n \le 10^5$). The following line contains integers $p_2$, $p_3$, ... $p_n$, where $p_i$ stands for the parent of vertex with index $i$ in the tree ($1 \le p_i < i$). The last line contains integer values $s_1$, $s_2$, ..., $s_n$ ($-1 \le s_v \le 10^9$), where erased values are replaced by $-1$.
-----Output-----
Output one integer — the minimum total sum of all values $a_v$ in the original tree, or $-1$ if such tree does not exist.
-----Examples-----
Input
5
1 1 1 1
1 -1 -1 -1 -1
Output
1
Input
5
1 2 3 1
1 -1 2 -1 -1
Output
2
Input
3
1 2
2 -1 1
Output
-1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7\\nNNESWW\\nSWSWSW\\n\", \"3\\nNN\\nSS\\n\", \"3\\nES\\nNW\\n\", \"5\\nWSSE\\nWNNE\\n\", \"2\\nE\\nE\\n\", \"2\\nW\\nS\\n\", \"2\\nS\\nN\\n\", \"100\\nWNWWSWWSESWWWSSSSWSSEENWNWWWWNNENESWSESSENEENNWWWWWSSWSWSENESWNEENESWWNNEESESWSEEENWWNWNNWWNNWWWWSW\\nEESEESSENWNWWWNWWNWWNWWSWNNWNWNWSWNNEENWSWNNESWSWNWSESENWSWSWWWWNNEESSSWSSESWWSSWSSWSWNEEESWWSSSSEN\\n\", \"200\\nNESENEESEESWWWNWWSWSWNWNNWNNESWSWNNWNWNENESENNESSWSESWWSSSEEEESSENNNESSWWSSSSESWSWWNNEESSWWNNWSWSSWWNWNNEENNENWWNESSSENWNESWNESWNESEESSWNESSSSSESESSWNNENENESSWWNNWWSWWNESEENWWWWNWWNWWNENESESSWWSWWSES\\nNWNESESSENNNESWNWWSWWWNWSESSSWWNWWNNWSENWSWNENNNWWSWWSWNNNESWWWSSESSWWWSSENWSENWWNENESESWNENNESWNWNNENNWWWSENWSWSSSENNWWNEESENNESEESSEESWWWWWWNWNNNESESWSSEEEESWNENWSESEEENWNNWWNWNNNNWWSSWNEENENEEEEEE\\n\", \"11\\nWWNNNNWNWN\\nENWSWWSSEE\\n\", \"12\\nWNNWSWWSSSE\\nNESWNNNWSSS\\n\"], \"outputs\": [\"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\"]}", "source": "primeintellect"}
|
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.
One example of a grid path is (0, 0) → (0, 1) → (0, 2) → (1, 2) → (1, 1) → (0, 1) → ( - 1, 1). Note that squares in this sequence might be repeated, i.e. path has self intersections.
Movement within a grid path is restricted to adjacent squares within the sequence. That is, from the i-th square, one can only move to the (i - 1)-th or (i + 1)-th squares of this path. Note that there is only a single valid move from the first and last squares of a grid path. Also note, that even if there is some j-th square of the path that coincides with the i-th square, only moves to (i - 1)-th and (i + 1)-th squares are available. For example, from the second square in the above sequence, one can only move to either the first or third squares.
To ensure that movement is not ambiguous, the two grid paths will not have an alternating sequence of three squares. For example, a contiguous subsequence (0, 0) → (0, 1) → (0, 0) cannot occur in a valid grid path.
One marble is placed on the first square of each grid path. Genos wants to get both marbles to the last square of each grid path. However, there is a catch. Whenever he moves one marble, the other marble will copy its movement if possible. For instance, if one marble moves east, then the other marble will try and move east as well. By try, we mean if moving east is a valid move, then the marble will move east.
Moving north increases the second coordinate by 1, while moving south decreases it by 1. Similarly, moving east increases first coordinate by 1, while moving west decreases it.
Given these two valid grid paths, Genos wants to know if it is possible to move both marbles to the ends of their respective paths. That is, if it is possible to move the marbles such that both marbles rest on the last square of their respective paths.
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 1 000 000) — the length of the paths.
The second line of the input contains a string consisting of n - 1 characters (each of which is either 'N', 'E', 'S', or 'W') — the first grid path. The characters can be thought of as the sequence of moves needed to traverse the grid path. For example, the example path in the problem statement can be expressed by the string "NNESWW".
The third line of the input contains a string of n - 1 characters (each of which is either 'N', 'E', 'S', or 'W') — the second grid path.
-----Output-----
Print "YES" (without quotes) if it is possible for both marbles to be at the end position at the same time. Print "NO" (without quotes) otherwise. In both cases, the answer is case-insensitive.
-----Examples-----
Input
7
NNESWW
SWSWSW
Output
YES
Input
3
NN
SS
Output
NO
-----Note-----
In the first sample, the first grid path is the one described in the statement. Moreover, the following sequence of moves will get both marbles to the end: NNESWWSWSW.
In the second sample, no sequence of moves can get both marbles to the end.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n1 3 1 0\\n\", \"2\\n4 4\\n\", \"5\\n5 4 3 2 1\\n\", \"10\\n3 3 3 5 6 9 3 1 7 3\\n\", \"100\\n57 5 28 44 99 10 66 93 76 32 67 92 67 81 33 3 6 6 67 10 41 72 5 71 27 22 21 54 21 59 36 62 43 39 28 49 55 65 21 73 87 40 0 62 67 59 40 18 56 71 15 97 73 73 2 61 54 44 6 52 25 34 13 20 18 13 25 51 19 66 63 87 50 63 82 60 11 11 54 58 88 20 33 40 85 68 13 74 37 51 63 32 45 20 30 28 32 64 82 19\\n\", \"5\\n1 2 3 4 5\\n\", \"2\\n0 0\\n\", \"3\\n1 3 0\\n\", \"2\\n100000 100000\\n\", \"5\\n1 0 0 1 1\\n\"], \"outputs\": [\"YES\\n7 3 8 7 \\n\", \"NO\\n\", \"YES\\n5 20 16 13 11 \\n\", \"YES\\n38 35 32 29 24 9 52 49 48 41 \\n\", \"YES\\n332 275 270 242 99 4629 4619 4553 4460 4384 4352 4285 4193 4126 4045 4012 4009 4003 3997 3930 3920 3879 3807 3802 3731 3704 3682 3661 3607 3586 3527 3491 3429 3386 3347 3319 3270 3215 3150 3129 3056 2969 2929 2929 2867 2800 2741 2701 2683 2627 2556 2541 2444 2371 2298 2296 2235 2181 2137 2131 2079 2054 2020 2007 1987 1969 1956 1931 1880 1861 1795 1732 1645 1595 1532 1450 1390 1379 1368 1314 1256 1168 1148 1115 1075 990 922 909 835 798 747 684 652 607 587 557 529 497 433 351 \\n\", \"YES\\n20 19 17 14 5 \\n\", \"YES\\n1 1\\n\", \"YES\\n7 3 7 \\n\", \"NO\\n\", \"YES\\n3 2 2 1 4 \\n\"]}", "source": "primeintellect"}
|
While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers $a_1, a_2, \ldots, a_n$. Since the talk was long and not promising, Kostya created a new cyclic array $b_1, b_2, \ldots, b_{n}$ so that $b_i = (a_i \mod a_{i + 1})$, where we take $a_{n+1} = a_1$. Here $mod$ is the modulo operation. When the talk became interesting, Kostya completely forgot how array $a$ had looked like. Suddenly, he thought that restoring array $a$ from array $b$ would be an interesting problem (unfortunately, not A).
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 140582$) — the length of the array $a$.
The second line contains $n$ integers $b_1, b_2, \ldots, b_{n}$ ($0 \le b_i \le 187126$).
-----Output-----
If it is possible to restore some array $a$ of length $n$ so that $b_i = a_i \mod a_{(i \mod n) + 1}$ holds for all $i = 1, 2, \ldots, n$, print «YES» in the first line and the integers $a_1, a_2, \ldots, a_n$ in the second line. All $a_i$ should satisfy $1 \le a_i \le 10^{18}$. We can show that if an answer exists, then an answer with such constraint exists as well.
It it impossible to restore any valid $a$, print «NO» in one line.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
4
1 3 1 0
Output
YES
1 3 5 2
Input
2
4 4
Output
NO
-----Note-----
In the first example: $1 \mod 3 = 1$ $3 \mod 5 = 3$ $5 \mod 2 = 1$ $2 \mod 1 = 0$
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n2 0\\n0 2\\n2 0\\n\", \"5\\n0 1\\n1 3\\n2 1\\n3 0\\n2 0\\n\", \"1\\n0 0\\n\", \"2\\n0 1\\n1 0\\n\", \"2\\n2 0\\n0 0\\n\", \"2\\n2 1\\n0 1\\n\", \"3\\n0 0\\n1 0\\n1 0\\n\", \"3\\n0 1\\n3 0\\n1 0\\n\", \"3\\n3 1\\n1 0\\n0 1\\n\", \"3\\n2 1\\n0 0\\n1 1\\n\"], \"outputs\": [\"YES\\n1 3 2 \\n\", \"YES\\n2 5 3 1 4 \\n\", \"YES\\n1 \\n\", \"YES\\n2 1 \\n\", \"YES\\n2 1 \\n\", \"NO\\n\", \"YES\\n1 2 3 \\n\", \"YES\\n2 3 1 \\n\", \"YES\\n3 1 2 \\n\", \"NO\\n\"]}", "source": "primeintellect"}
|
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from $1$ to $n$. Each of its vertices also has an integer $a_i$ written on it. For each vertex $i$, Evlampiy calculated $c_i$ — the number of vertices $j$ in the subtree of vertex $i$, such that $a_j < a_i$. [Image]Illustration for the second example, the first integer is $a_i$ and the integer in parentheses is $c_i$
After the new year, Evlampiy could not remember what his gift was! He remembers the tree and the values of $c_i$, but he completely forgot which integers $a_i$ were written on the vertices.
Help him to restore initial integers!
-----Input-----
The first line contains an integer $n$ $(1 \leq n \leq 2000)$ — the number of vertices in the tree.
The next $n$ lines contain descriptions of vertices: the $i$-th line contains two integers $p_i$ and $c_i$ ($0 \leq p_i \leq n$; $0 \leq c_i \leq n-1$), where $p_i$ is the parent of vertex $i$ or $0$ if vertex $i$ is root, and $c_i$ is the number of vertices $j$ in the subtree of vertex $i$, such that $a_j < a_i$.
It is guaranteed that the values of $p_i$ describe a rooted tree with $n$ vertices.
-----Output-----
If a solution exists, in the first line print "YES", and in the second line output $n$ integers $a_i$ $(1 \leq a_i \leq {10}^{9})$. If there are several solutions, output any of them. One can prove that if there is a solution, then there is also a solution in which all $a_i$ are between $1$ and $10^9$.
If there are no solutions, print "NO".
-----Examples-----
Input
3
2 0
0 2
2 0
Output
YES
1 2 1
Input
5
0 1
1 3
2 1
3 0
2 0
Output
YES
2 3 2 1 2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n3 1 7 4\\n2 3 2\\n2 8 5\\n1 10\\n\", \"2\\n2 3 -2\\n2 -1 5\\n\", \"2\\n2 -10 10\\n2 0 -20\\n\", \"1\\n1 0\\n\", \"3\\n1 20\\n2 30 40\\n3 50 60 80\\n\", \"3\\n3 1 3 100\\n2 4 104\\n2 2 102\\n\", \"4\\n3 80 1 10\\n3 52 19 24\\n3 27 46 29\\n3 74 13 25\\n\", \"2\\n5 -1000000000 999999999 -999999998 999999997 0\\n5 1000000000 -999999999 999999998 -999999997 4\\n\", \"5\\n10 -251 650 475 -114 364 -75754 -982 -532 -151 -484\\n10 -623 -132 -317561 -438 20 -275 -323 -530089 -311 -587\\n10 450900 -519 903 -401 -789 -606529 277 -267 -682 -161\\n10 -246 873 -641 838 719 234 789 -74 -287288 -772972\\n10 186 741 -927 -866 -855 578 -1057019 202 162962 -458\\n\", \"2\\n2 1 2\\n10 0 1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 589934621\\n\"], \"outputs\": [\"Yes\\n7 2\\n2 3\\n5 1\\n10 4\\n\", \"No\\n\", \"Yes\\n-10 2\\n-20 1\\n\", \"Yes\\n0 1\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n0 2\\n4 1\\n\", \"Yes\\n650 3\\n-530089 1\\n450900 5\\n-287288 2\\n162962 4\\n\", \"No\\n\"]}", "source": "primeintellect"}
|
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct.
Ujan is lazy, so he will do the following reordering of the numbers exactly once. He will pick a single integer from each of the boxes, $k$ integers in total. Then he will insert the chosen numbers — one integer in each of the boxes, so that the number of integers in each box is the same as in the beginning. Note that he may also insert an integer he picked from a box back into the same box.
Ujan will be happy if the sum of the integers in each box is the same. Can he achieve this and make the boxes perfectly balanced, like all things should be?
-----Input-----
The first line contains a single integer $k$ ($1 \leq k \leq 15$), the number of boxes.
The $i$-th of the next $k$ lines first contains a single integer $n_i$ ($1 \leq n_i \leq 5\,000$), the number of integers in box $i$. Then the same line contains $n_i$ integers $a_{i,1}, \ldots, a_{i,n_i}$ ($|a_{i,j}| \leq 10^9$), the integers in the $i$-th box.
It is guaranteed that all $a_{i,j}$ are distinct.
-----Output-----
If Ujan cannot achieve his goal, output "No" in a single line. Otherwise in the first line output "Yes", and then output $k$ lines. The $i$-th of these lines should contain two integers $c_i$ and $p_i$. This means that Ujan should pick the integer $c_i$ from the $i$-th box and place it in the $p_i$-th box afterwards.
If there are multiple solutions, output any of those.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
4
3 1 7 4
2 3 2
2 8 5
1 10
Output
Yes
7 2
2 3
5 1
10 4
Input
2
2 3 -2
2 -1 5
Output
No
Input
2
2 -10 10
2 0 -20
Output
Yes
-10 2
-20 1
-----Note-----
In the first sample, Ujan can put the number $7$ in the $2$nd box, the number $2$ in the $3$rd box, the number $5$ in the $1$st box and keep the number $10$ in the same $4$th box. Then the boxes will contain numbers $\{1,5,4\}$, $\{3, 7\}$, $\{8,2\}$ and $\{10\}$. The sum in each box then is equal to $10$.
In the second sample, it is not possible to pick and redistribute the numbers in the required way.
In the third sample, one can swap the numbers $-20$ and $-10$, making the sum in each box equal to $-10$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 1 3 4 3\\n3 2 5 1\\n\", \"4 2 4 4 1\\n4 5 1 2\\n\", \"2 2 5 7 3\\n4 5\\n\", \"100 4 8 9 1\\n1 8 1 8 7 8 1 8 10 4 7 7 3 2 6 7 3 7 3 7 1 8 5 7 4 10 9 7 3 4 7 7 4 9 6 10 4 5 5 2 5 3 9 2 8 3 7 8 8 8 10 4 7 2 3 6 2 8 9 9 7 4 8 6 5 8 5 2 5 10 3 6 2 8 1 3 3 7 6 1 5 8 9 9 2 2 9 3 7 3 3 3 10 10 3 5 10 1 3 3\\n\", \"100 5 5 9 3\\n3 4 2 3 4 3 8 5 2 1 1 4 1 1 10 10 7 5 2 9 4 2 10 10 8 2 4 9 6 2 6 7 7 5 7 7 1 8 10 9 9 3 10 3 10 1 1 8 3 6 4 5 5 4 9 5 9 4 8 2 10 8 9 1 5 9 7 2 1 7 9 3 2 9 1 5 4 2 3 10 6 7 8 2 10 1 6 2 1 6 10 9 1 2 2 7 2 8 4 4\\n\", \"12 5 9 9 8\\n5 1 9 4 2 10 7 3 8 1 7 10\\n\", \"35 2 5 6 3\\n6 8 3 4 2 1 1 10 8 1 2 4 4 2 10 1 1 6 3 8 10 6 3 8 10 8 9 7 9 10 3 9 4 6 7\\n\", \"36 6 6 9 6\\n3 5 8 7 6 8 1 5 10 10 8 5 10 9 8 1 9 7 2 1 8 8 6 1 6 7 4 3 10 2 5 8 4 1 1 4\\n\", \"17 2 7 10 6\\n10 5 9 2 7 5 6 10 9 7 10 3 10 2 9 10 1\\n\", \"77 2 8 8 3\\n7 9 3 6 2 7 8 4 4 1 8 6 1 7 6 3 4 6 1 1 6 5 6 6 4 8 7 5 10 6 9 2 1 2 4 5 1 3 8 2 2 7 3 8 8 4 8 10 5 1 6 8 1 3 8 6 8 4 10 7 10 5 3 8 6 6 8 2 2 3 8 4 10 7 6 5 2\\n\"], \"outputs\": [\"34\", \"31\", \"23\", \"1399\", \"1597\", \"341\", \"442\", \"852\", \"346\", \"1182\"]}", "source": "primeintellect"}
|
Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and three different types of guns.
Namely, the two types of monsters are: a normal monster with $1$ hp. a boss with $2$ hp.
And the three types of guns are: Pistol, deals $1$ hp in damage to one monster, $r_1$ reloading time Laser gun, deals $1$ hp in damage to all the monsters in the current level (including the boss), $r_2$ reloading time AWP, instantly kills any monster, $r_3$ reloading time
The guns are initially not loaded, and the Ziota can only reload 1 gun at a time.
The levels of the game can be considered as an array $a_1, a_2, \ldots, a_n$, in which the $i$-th stage has $a_i$ normal monsters and 1 boss. Due to the nature of the game, Ziota cannot use the Pistol (the first type of gun) or AWP (the third type of gun) to shoot the boss before killing all of the $a_i$ normal monsters.
If Ziota damages the boss but does not kill it immediately, he is forced to move out of the current level to an arbitrary adjacent level (adjacent levels of level $i$ $(1 < i < n)$ are levels $i - 1$ and $i + 1$, the only adjacent level of level $1$ is level $2$, the only adjacent level of level $n$ is level $n - 1$). Ziota can also choose to move to an adjacent level at any time. Each move between adjacent levels are managed by portals with $d$ teleportation time.
In order not to disrupt the space-time continuum within the game, it is strictly forbidden to reload or shoot monsters during teleportation.
Ziota starts the game at level 1. The objective of the game is rather simple, to kill all the bosses in all the levels. He is curious about the minimum time to finish the game (assuming it takes no time to shoot the monsters with a loaded gun and Ziota has infinite ammo on all the three guns). Please help him find this value.
-----Input-----
The first line of the input contains five integers separated by single spaces: $n$ $(2 \le n \le 10^6)$ — the number of stages, $r_1, r_2, r_3$ $(1 \le r_1 \le r_2 \le r_3 \le 10^9)$ — the reload time of the three guns respectively, $d$ $(1 \le d \le 10^9)$ — the time of moving between adjacent levels.
The second line of the input contains $n$ integers separated by single spaces $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^6, 1 \le i \le n)$.
-----Output-----
Print one integer, the minimum time to finish the game.
-----Examples-----
Input
4 1 3 4 3
3 2 5 1
Output
34
Input
4 2 4 4 1
4 5 1 2
Output
31
-----Note-----
In the first test case, the optimal strategy is: Use the pistol to kill three normal monsters and AWP to kill the boss (Total time $1\cdot3+4=7$) Move to stage two (Total time $7+3=10$) Use the pistol twice and AWP to kill the boss (Total time $10+1\cdot2+4=16$) Move to stage three (Total time $16+3=19$) Use the laser gun and forced to move to either stage four or two, here we move to stage four (Total time $19+3+3=25$) Use the pistol once, use AWP to kill the boss (Total time $25+1\cdot1+4=30$) Move back to stage three (Total time $30+3=33$) Kill the boss at stage three with the pistol (Total time $33+1=34$)
Note that here, we do not finish at level $n$, but when all the bosses are killed.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n11011\\n3\\n1 3 3\\n1 4 2\\n1 2 3\\n\", \"1\\n0\\n1\\n1 1 1\\n\", \"3\\n010\\n3\\n1 3 1\\n1 3 1\\n3 2 1\\n\", \"10\\n0100001001\\n10\\n2 5 4\\n10 2 1\\n5 3 5\\n2 9 2\\n5 3 1\\n3 3 3\\n9 8 1\\n5 3 1\\n9 5 2\\n2 3 6\\n\", \"5\\n00010\\n5\\n5 3 1\\n2 1 2\\n4 1 1\\n3 1 3\\n2 1 3\\n\", \"50\\n01110011100101101001001101110101011011101011010011\\n50\\n10 18 32\\n13 50 1\\n5 42 1\\n10 6 35\\n47 4 4\\n42 44 7\\n50 7 1\\n45 1 5\\n14 38 11\\n28 29 4\\n7 48 2\\n35 10 1\\n12 44 6\\n28 26 4\\n43 4 4\\n42 12 4\\n47 29 3\\n47 49 1\\n19 47 2\\n3 46 2\\n9 17 23\\n17 30 1\\n1 31 11\\n48 48 1\\n14 27 9\\n15 26 4\\n7 32 10\\n39 33 4\\n8 46 3\\n7 42 8\\n34 25 12\\n18 18 9\\n41 14 6\\n25 25 24\\n22 26 24\\n49 9 2\\n27 44 4\\n5 32 9\\n18 34 7\\n23 22 4\\n16 26 12\\n8 49 2\\n4 10 30\\n21 8 20\\n26 27 5\\n4 29 14\\n32 22 2\\n34 40 2\\n26 49 1\\n6 13 34\\n\", \"5\\n11010\\n5\\n2 1 4\\n3 5 1\\n4 2 1\\n4 5 1\\n2 4 2\\n\", \"50\\n01110100101100100100011001100001110010010000000101\\n50\\n27 18 7\\n22 35 2\\n50 35 1\\n41 16 1\\n27 5 5\\n11 6 33\\n7 19 2\\n9 12 33\\n14 37 4\\n1 22 8\\n22 3 5\\n50 42 1\\n50 38 1\\n29 20 2\\n20 34 17\\n20 4 29\\n16 21 3\\n11 43 3\\n15 45 1\\n12 28 3\\n31 34 13\\n43 1 8\\n3 41 1\\n18 3 13\\n29 44 6\\n47 44 3\\n40 43 2\\n6 46 5\\n9 12 35\\n19 45 2\\n38 47 4\\n19 47 3\\n48 3 1\\n16 12 9\\n24 18 2\\n32 40 4\\n16 28 11\\n33 22 12\\n7 16 9\\n17 30 3\\n16 13 26\\n46 24 5\\n48 17 2\\n25 32 15\\n46 19 1\\n40 29 2\\n36 34 10\\n47 27 4\\n43 18 6\\n4 10 12\\n\", \"10\\n1101011011\\n10\\n10 3 1\\n10 10 1\\n5 10 1\\n10 4 1\\n10 10 1\\n10 10 1\\n10 10 1\\n10 4 1\\n4 5 2\\n3 5 3\\n\", \"10\\n1100111011\\n10\\n10 10 1\\n5 4 5\\n6 10 1\\n10 10 1\\n10 10 1\\n5 5 4\\n6 10 1\\n4 6 4\\n10 10 1\\n6 10 1\\n\"], \"outputs\": [\"Yes\\nYes\\nNo\\n\", \"Yes\\n\", \"Yes\\nYes\\nNo\\n\", \"No\\nYes\\nNo\\nNo\\nYes\\nYes\\nYes\\nYes\\nNo\\nNo\\n\", \"Yes\\nYes\\nNo\\nNo\\nNo\\n\", \"No\\nNo\\nYes\\nNo\\nNo\\nNo\\nYes\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\n\", \"No\\nYes\\nYes\\nNo\\nYes\\n\", \"Yes\\nNo\\nNo\\nYes\\nNo\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nNo\\nYes\\nNo\\nNo\\nNo\\nNo\\nNo\\n\", \"No\\nYes\\nNo\\nYes\\nYes\\nYes\\nYes\\nYes\\nNo\\nNo\\n\", \"Yes\\nNo\\nYes\\nYes\\nYes\\nYes\\nYes\\nYes\\nYes\\nYes\\n\"]}", "source": "primeintellect"}
|
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with the $r$-th character as $s[l \dots r]$. The characters of each string are numbered from $1$.
We can perform several operations on the strings we consider. Each operation is to choose a substring of our string and replace it with another string. There are two possible types of operations: replace 011 with 110, or replace 110 with 011. For example, if we apply exactly one operation to the string 110011110, it can be transformed into 011011110, 110110110, or 110011011.
Binary string $a$ is considered reachable from binary string $b$ if there exists a sequence $s_1$, $s_2$, ..., $s_k$ such that $s_1 = a$, $s_k = b$, and for every $i \in [1, k - 1]$, $s_i$ can be transformed into $s_{i + 1}$ using exactly one operation. Note that $k$ can be equal to $1$, i. e., every string is reachable from itself.
You are given a string $t$ and $q$ queries to it. Each query consists of three integers $l_1$, $l_2$ and $len$. To answer each query, you have to determine whether $t[l_1 \dots l_1 + len - 1]$ is reachable from $t[l_2 \dots l_2 + len - 1]$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of string $t$.
The second line contains one string $t$ ($|t| = n$). Each character of $t$ is either 0 or 1.
The third line contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries.
Then $q$ lines follow, each line represents a query. The $i$-th line contains three integers $l_1$, $l_2$ and $len$ ($1 \le l_1, l_2 \le |t|$, $1 \le len \le |t| - \max(l_1, l_2) + 1$) for the $i$-th query.
-----Output-----
For each query, print either YES if $t[l_1 \dots l_1 + len - 1]$ is reachable from $t[l_2 \dots l_2 + len - 1]$, or NO otherwise. You may print each letter in any register.
-----Example-----
Input
5
11011
3
1 3 3
1 4 2
1 2 3
Output
Yes
Yes
No
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n\", \"5\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\"], \"outputs\": [\"2\\n3 1 2 3\\n3 1 2 3\\n\", \"6\\n3 1 2 3\\n3 2 3 4\\n3 3 4 5\\n3 4 5 1\\n4 2 1 3 5\\n4 5 1 4 2\\n\", \"4\\n3 4 1 2\\n3 2 3 4\\n3 1 2 3\\n3 3 4 1\\n\", \"6\\n3 1 2 3\\n3 2 3 4\\n3 3 4 5\\n3 4 5 1\\n4 2 1 3 5\\n4 5 1 4 2\\n\", \"9\\n3 6 1 2\\n4 6 2 5 3\\n3 3 4 5\\n3 1 2 3\\n4 1 3 6 4\\n3 4 5 6\\n3 2 3 4\\n4 2 4 1 5\\n3 5 6 1\\n\", \"12\\n4 2 3 1 4\\n4 3 4 2 5\\n4 4 5 3 6\\n4 5 6 4 7\\n4 6 7 5 1\\n4 7 1 6 2\\n3 2 5 6\\n3 1 5 4\\n3 3 6 7\\n3 7 4 3\\n3 3 2 1\\n3 7 1 2\\n\", \"16\\n3 8 1 2\\n4 8 2 7 3\\n4 7 3 6 4\\n3 4 5 6\\n3 1 2 3\\n4 1 3 8 4\\n4 8 4 7 5\\n3 5 6 7\\n3 2 3 4\\n4 2 4 1 5\\n4 1 5 8 6\\n3 6 7 8\\n3 3 4 5\\n4 3 5 2 6\\n4 2 6 1 7\\n3 7 8 1\\n\", \"20\\n3 1 2 3\\n4 1 3 9 4\\n3 2 3 4\\n4 2 4 1 5\\n3 3 4 5\\n4 3 5 2 6\\n3 4 5 6\\n4 4 6 3 7\\n3 5 6 7\\n4 5 7 4 8\\n3 6 7 8\\n4 6 8 5 9\\n3 7 8 9\\n4 7 9 6 1\\n3 8 9 1\\n4 8 1 7 2\\n4 2 1 5 9\\n4 9 1 6 2\\n4 3 9 4 8\\n4 8 2 7 3\\n\", \"25\\n3 10 1 2\\n4 10 2 9 3\\n4 9 3 8 4\\n4 8 4 7 5\\n3 5 6 7\\n3 1 2 3\\n4 1 3 10 4\\n4 10 4 9 5\\n4 9 5 8 6\\n3 6 7 8\\n3 2 3 4\\n4 2 4 1 5\\n4 1 5 10 6\\n4 10 6 9 7\\n3 7 8 9\\n3 3 4 5\\n4 3 5 2 6\\n4 2 6 1 7\\n4 1 7 10 8\\n3 8 9 10\\n3 4 5 6\\n4 4 6 3 7\\n4 3 7 2 8\\n4 2 8 1 9\\n3 9 10 1\\n\", \"30\\n4 2 3 1 4\\n4 1 4 11 5\\n4 3 4 2 5\\n4 2 5 1 6\\n4 4 5 3 6\\n4 3 6 2 7\\n4 5 6 4 7\\n4 4 7 3 8\\n4 6 7 5 8\\n4 5 8 4 9\\n4 7 8 6 9\\n4 6 9 5 10\\n4 8 9 7 10\\n4 7 10 6 11\\n4 9 10 8 11\\n4 8 11 7 1\\n4 10 11 9 1\\n4 9 1 8 2\\n4 11 1 10 2\\n4 10 2 9 3\\n3 2 7 8\\n3 1 7 6\\n3 3 8 9\\n3 11 6 5\\n3 4 9 10\\n3 10 5 4\\n3 3 2 1\\n3 11 1 2\\n3 4 3 11\\n3 10 11 3\\n\"]}", "source": "primeintellect"}
|
In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
We are sure that Mister B will solve the problem soon and will fly to the Moon. Will you?
-----Input-----
The only line contains single integer n (3 ≤ n ≤ 300).
-----Output-----
If there is no answer, print -1.
Otherwise, in the first line print k (1 ≤ k ≤ n^2) — the number of cycles in your solution.
In each of the next k lines print description of one cycle in the following format: first print integer m (3 ≤ m ≤ 4) — the length of the cycle, then print m integers v_1, v_2, ..., v_{m} (1 ≤ v_{i} ≤ n) — the vertices in the cycle in the traverse order. Each edge should be in exactly two cycles.
-----Examples-----
Input
3
Output
2
3 1 2 3
3 1 2 3
Input
5
Output
6
3 5 4 2
3 3 1 5
4 4 5 2 3
4 4 3 2 1
3 4 2 1
3 3 1 5
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 3\\n100 100 100\\n100 1 100\\n100 100 100\\n\", \"4 5\\n87882 40786 3691 85313 46694\\n28884 16067 3242 97367 78518\\n4250 35501 9780 14435 19004\\n64673 65438 56977 64495 27280\\n\", \"3 3\\n3 1 2\\n3 2 0\\n2 3 2\\n\", \"3 3\\n1 10 1\\n1 10 1\\n1 10 1\\n\", \"3 3\\n0 0 0\\n0 10000 0\\n0 0 0\\n\", \"3 3\\n1 1 1\\n0 10000 0\\n1 1 1\\n\", \"3 3\\n9 0 9\\n0 9 9\\n9 9 9\\n\", \"3 3\\n0 0 0\\n0 100 0\\n0 0 0\\n\", \"3 3\\n100000 100000 100000\\n1 100000 100000\\n1 1 100000\\n\", \"3 3\\n100 0 100\\n1 100 100\\n0 100 100\\n\"], \"outputs\": [\"800\", \"747898\", \"16\", \"26\", \"0\", \"6\", \"54\", \"0\", \"500003\", \"501\"]}", "source": "primeintellect"}
|
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with workout located at line 1 and column 1. He needs to finish with workout a[n][m]. After finishing workout a[i][j], he can go to workout a[i + 1][j] or a[i][j + 1]. Similarly, Iahubina starts with workout a[n][1] and she needs to finish with workout a[1][m]. After finishing workout from cell a[i][j], she goes to either a[i][j + 1] or a[i - 1][j].
There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.
If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.
-----Input-----
The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 10^5).
-----Output-----
The output contains a single number — the maximum total gain possible.
-----Examples-----
Input
3 3
100 100 100
100 1 100
100 100 100
Output
800
-----Note-----
Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3].
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"8\\n0 0 5 3\\n2 -1 5 0\\n-3 -4 2 -1\\n-1 -1 2 0\\n-3 0 0 5\\n5 2 10 3\\n7 -3 10 2\\n4 -2 7 -1\\n\", \"1\\n0 0 1 1\\n\", \"4\\n0 0 1 1\\n1 0 2 1\\n1 1 2 2\\n0 1 1 2\\n\", \"3\\n0 0 1 3\\n1 0 4 1\\n1 1 2 2\\n\", \"6\\n0 1 1 4\\n0 4 1 7\\n1 0 2 3\\n1 3 2 4\\n1 4 2 5\\n2 3 3 4\\n\", \"25\\n0 0 7 7\\n0 18 7 29\\n7 36 12 41\\n7 18 12 29\\n15 29 26 36\\n7 7 12 18\\n12 36 15 41\\n15 7 26 18\\n12 0 15 7\\n12 7 15 18\\n7 29 12 36\\n12 29 15 36\\n15 18 26 29\\n26 18 27 29\\n12 18 15 29\\n26 29 27 36\\n0 7 7 18\\n26 0 27 7\\n7 0 12 7\\n15 36 26 41\\n26 7 27 18\\n26 36 27 41\\n15 0 26 7\\n0 36 7 41\\n0 29 7 36\\n\", \"25\\n76 0 85 9\\n46 0 55 9\\n6 0 13 9\\n86 0 95 9\\n56 0 65 9\\n152 0 157 9\\n146 0 151 9\\n14 0 21 9\\n0 0 1 9\\n180 0 189 9\\n120 0 125 9\\n96 0 99 9\\n126 0 133 9\\n158 0 169 9\\n22 0 27 9\\n100 0 107 9\\n170 0 179 9\\n2 0 5 9\\n134 0 141 9\\n114 0 119 9\\n108 0 113 9\\n66 0 75 9\\n36 0 45 9\\n142 0 145 9\\n28 0 35 9\\n\", \"28\\n0 0 3 1\\n0 1 1 6\\n0 6 1 9\\n0 9 1 12\\n0 12 1 13\\n0 13 3 14\\n1 1 2 4\\n1 4 2 7\\n1 7 2 10\\n1 10 2 13\\n2 1 3 2\\n2 2 3 5\\n2 5 3 8\\n2 8 3 13\\n3 0 6 1\\n3 1 4 6\\n3 6 4 9\\n3 9 4 12\\n3 12 4 13\\n3 13 6 14\\n4 1 5 4\\n4 4 5 7\\n4 7 5 10\\n4 10 5 13\\n5 1 6 2\\n5 2 6 5\\n5 5 6 8\\n5 8 6 13\\n\", \"4\\n3 3 10 12\\n5 0 14 3\\n0 3 3 12\\n0 0 5 3\\n\", \"4\\n3 11 12 18\\n0 0 1 11\\n0 11 3 18\\n1 0 8 11\\n\"], \"outputs\": [\"YES\\n1\\n4\\n3\\n2\\n3\\n3\\n2\\n1\\n\", \"YES\\n1\\n\", \"YES\\n1\\n3\\n4\\n2\\n\", \"YES\\n1\\n3\\n4\\n\", \"YES\\n2\\n1\\n3\\n4\\n3\\n2\\n\", \"YES\\n1\\n1\\n3\\n3\\n4\\n4\\n1\\n4\\n1\\n2\\n4\\n2\\n3\\n1\\n1\\n2\\n2\\n1\\n3\\n3\\n2\\n1\\n3\\n1\\n2\\n\", \"YES\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"YES\\n1\\n2\\n1\\n2\\n1\\n2\\n4\\n3\\n4\\n3\\n2\\n1\\n2\\n1\\n3\\n4\\n3\\n4\\n3\\n4\\n2\\n1\\n2\\n1\\n4\\n3\\n4\\n3\\n\", \"YES\\n4\\n3\\n2\\n1\\n\", \"YES\\n4\\n1\\n2\\n3\\n\"]}", "source": "primeintellect"}
|
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.
Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length [Image] The picture corresponds to the first example
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 5·10^5) — the number of rectangles.
n lines follow. The i-th of these lines contains four integers x_1, y_1, x_2 and y_2 ( - 10^9 ≤ x_1 < x_2 ≤ 10^9, - 10^9 ≤ y_1 < y_2 ≤ 10^9), that means that points (x_1, y_1) and (x_2, y_2) are the coordinates of two opposite corners of the i-th rectangle.
It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.
-----Output-----
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.
Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer c_{i} (1 ≤ c_{i} ≤ 4) — the color of i-th rectangle.
-----Example-----
Input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
Output
YES
1
2
2
3
2
2
4
1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n\", \"6\\n15 14 3 13 1 12\\n\", \"6\\n9 7 13 17 5 11\\n\", \"10\\n18 14 19 17 11 7 20 10 4 12\\n\", \"100\\n713 716 230 416 3 2 597 216 779 839 13 156 723 793 168 368 232 316 98 257 170 27 746 9 616 147 792 890 796 362 852 117 993 556 885 73 131 475 121 753 508 158 473 931 527 282 541 325 606 321 159 17 682 290 586 685 529 11 645 224 821 53 152 966 269 754 672 523 386 347 719 525 92 315 832 393 893 83 956 725 258 851 112 38 601 782 324 210 642 818 56 485 679 10 922 469 36 990 14 742\\n\", \"100\\n41 173 40 30 165 155 92 180 193 24 187 189 65 4 200 80 152 174 20 81 170 72 104 8 13 7 117 176 191 34 90 46 17 188 63 134 76 60 116 42 183 45 1 103 15 119 142 70 148 136 73 68 86 94 32 190 112 166 141 78 6 102 66 97 93 106 47 22 132 129 139 177 62 105 100 77 88 54 3 167 120 145 197 195 64 11 38 2 28 140 87 109 185 23 31 153 39 18 57 122\\n\", \"10\\n10 1 6 7 9 8 4 3 5 2\\n\", \"100\\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55\\n\", \"1\\n32\\n\", \"30\\n1000000000 500000000 250000000 125000000 62500000 31250000 15625000 7812500 3906250 1953125 976562 488281 244140 122070 61035 30517 15258 7629 3814 1907 953 476 238 119 59 29 14 7 3 1\\n\"], \"outputs\": [\"4 5 2 3 1 \\n\", \"12 13 14 7 3 1 \\n\", \"4 5 2 6 3 1 \\n\", \"8 9 4 10 5 2 6 7 3 1 \\n\", \"128 129 130 131 65 32 132 134 135 139 141 17 145 146 147 73 36 149 150 151 152 154 38 156 157 158 159 79 9 160 161 80 162 81 83 168 84 85 42 86 21 10 89 44 90 45 22 92 93 46 94 47 23 11 5 2 96 97 48 98 99 49 24 102 51 12 104 105 52 106 53 26 108 110 111 55 27 13 6 112 56 115 57 28 116 117 58 118 119 59 29 14 120 121 60 123 124 127 3 1 \\n\", \"129 64 65 32 132 66 134 136 68 139 34 140 141 70 142 17 8 145 72 73 148 18 152 153 76 155 77 38 78 39 4 80 81 40 165 166 167 41 20 170 42 173 86 174 87 176 177 88 180 90 183 45 22 185 92 187 93 46 188 189 94 95 47 23 11 5 2 96 97 48 98 24 100 50 102 103 104 105 106 109 54 13 6 112 57 28 116 117 119 120 60 122 30 62 63 31 15 7 3 1 \\n\", \"8 9 4 10 5 2 6 7 3 1 \\n\", \"64 65 32 66 67 33 16 68 69 34 70 71 35 17 8 72 73 36 74 75 37 18 76 77 38 78 79 39 19 9 4 80 81 40 82 83 41 20 84 85 42 86 87 43 21 10 88 89 44 90 91 45 22 92 93 46 94 95 47 23 11 5 2 96 97 48 98 99 49 24 100 50 51 25 12 52 53 26 54 55 27 13 6 56 57 28 58 59 29 14 60 61 30 62 63 31 15 7 3 1 \\n\", \"1 \\n\", \"1000000000 500000000 250000000 125000000 62500000 31250000 15625000 7812500 3906250 1953125 976562 488281 244140 122070 61035 30517 15258 7629 3814 1907 953 476 238 119 59 29 14 7 3 1 \\n\"]}", "source": "primeintellect"}
|
You are given a set Y of n distinct positive integers y_1, y_2, ..., y_{n}.
Set X of n distinct positive integers x_1, x_2, ..., x_{n} is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X: Take any integer x_{i} and multiply it by two, i.e. replace x_{i} with 2·x_{i}. Take any integer x_{i}, multiply it by two and add one, i.e. replace x_{i} with 2·x_{i} + 1.
Note that integers in X are not required to be distinct after each operation.
Two sets of distinct integers X and Y are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal.
Note, that any set of integers (or its permutation) generates itself.
You are given a set Y and have to find a set X that generates Y and the maximum element of X is mininum possible.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 50 000) — the number of elements in Y.
The second line contains n integers y_1, ..., y_{n} (1 ≤ y_{i} ≤ 10^9), that are guaranteed to be distinct.
-----Output-----
Print n integers — set of distinct integers that generate Y and the maximum element of which is minimum possible. If there are several such sets, print any of them.
-----Examples-----
Input
5
1 2 3 4 5
Output
4 5 2 3 1
Input
6
15 14 3 13 1 12
Output
12 13 14 7 3 1
Input
6
9 7 13 17 5 11
Output
4 5 2 6 3 1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7\\n\", \"6\\n\", \"7137\\n\", \"1941\\n\", \"55004\\n\", \"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\"], \"outputs\": [\"YES\\n1\\n2\\n5\\n6\\n3\\n4\\n7\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1\\n\", \"YES\\n1\\n2\\n\", \"YES\\n1\\n2\\n3\\n\", \"YES\\n1\\n3\\n2\\n4\", \"YES\\n1\\n2\\n4\\n3\\n5\\n\"]}", "source": "primeintellect"}
|
Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$.
Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1, ..., n - 1].
-----Input-----
The only input line contains an integer n (1 ≤ n ≤ 10^5).
-----Output-----
In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists.
If any solution exists, you should output n more lines. i-th line contains only an integer a_{i}. The elements of the sequence should be different positive integers no larger than n.
If there are multiple solutions, you are allowed to print any of them.
-----Examples-----
Input
7
Output
YES
1
4
3
6
5
2
7
Input
6
Output
NO
-----Note-----
For the second sample, there are no valid sequences.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 1 5\\n3 2 5\\n2 4 2\\n1 2\\n\", \"4 2 11\\n2 4 6 6\\n6 4 2 1\\n1 2\\n2 3\\n\", \"10 5 100\\n70 67 8 64 28 82 18 61 82 7\\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\\n1 7\\n2 4\\n3 6\\n5 7\\n1 5\\n\", \"10 5 100\\n64 90 3 94 96 97 52 54 82 31\\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\\n6 8\\n8 3\\n3 9\\n2 3\\n10 3\\n\", \"10 5 100\\n6 18 35 6 87 58 4 53 37 71\\n465782 57034 547741 748298 315223 370368 679320 349012 9740 622511\\n1 2\\n10 9\\n6 7\\n3 6\\n7 1\\n\", \"10 5 100\\n78 89 3 2 95 96 87 11 13 60\\n694709 921 799687 428614 221900 536251 117674 36488 219932 771513\\n4 5\\n3 4\\n6 2\\n2 3\\n8 3\\n\", \"10 5 100\\n48 73 30 46 95 19 98 73 94 24\\n501216 675859 843572 565104 879875 828759 80776 766980 213551 492652\\n1 2\\n6 5\\n7 6\\n10 3\\n8 1\\n\", \"10 5 100\\n68 55 15 94 53 100 52 68 24 3\\n286803 660813 226501 624597 215418 290774 416040 961916 910482 50278\\n1 5\\n7 2\\n2 8\\n5 3\\n10 3\\n\", \"10 5 100\\n19 8 95 18 9 79 42 94 20 49\\n735491 935681 717266 935275 521356 866021 356037 394445 589369 585077\\n9 4\\n5 6\\n5 1\\n1 4\\n7 1\\n\"], \"outputs\": [\"6\\n\", \"7\\n\", \"2383854\\n\", \"1495706\\n\", \"2050129\\n\", \"1791132\\n\", \"2237435\\n\", \"1922676\\n\", \"2456033\\n\"]}", "source": "primeintellect"}
|
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight w_{i} and some beauty b_{i}. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a_1, a_2, ..., a_{k} such that a_{i} and a_{i} + 1 are friends for each 1 ≤ i < k, and a_1 = x and a_{k} = y.
[Image]
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
-----Input-----
The first line contains integers n, m and w (1 ≤ n ≤ 1000, $0 \leq m \leq \operatorname{min}(\frac{n \cdot(n - 1)}{2}, 10^{5})$, 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w_1, w_2, ..., w_{n} (1 ≤ w_{i} ≤ 1000) — the weights of the Hoses.
The third line contains n integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 10^6) — the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers x_{i} and y_{i} (1 ≤ x_{i}, y_{i} ≤ n, x_{i} ≠ y_{i}), meaning that Hoses x_{i} and y_{i} are friends. Note that friendship is bidirectional. All pairs (x_{i}, y_{i}) are distinct.
-----Output-----
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
-----Examples-----
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
-----Note-----
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.375
|
{"tests": "{\"inputs\": [\"4\\n1 2\\n1 3\\n1 4\\n\", \"7\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n\", \"1\\n\", \"10\\n9 8\\n7 4\\n10 7\\n6 7\\n1 9\\n4 9\\n9 3\\n2 3\\n1 5\\n\", \"20\\n13 11\\n4 12\\n17 16\\n15 19\\n16 6\\n7 6\\n6 8\\n12 2\\n19 20\\n1 8\\n4 17\\n18 12\\n9 5\\n14 13\\n11 15\\n1 19\\n3 13\\n4 9\\n15 10\\n\", \"30\\n15 21\\n21 3\\n22 4\\n5 18\\n26 25\\n12 24\\n11 2\\n27 13\\n11 14\\n7 29\\n10 26\\n16 17\\n16 27\\n16 1\\n3 22\\n5 19\\n2 23\\n4 10\\n8 4\\n1 20\\n30 22\\n9 3\\n28 15\\n23 4\\n4 1\\n2 7\\n5 27\\n6 26\\n6 24\\n\", \"2\\n2 1\\n\", \"3\\n2 1\\n3 2\\n\", \"4\\n3 1\\n3 2\\n2 4\\n\"], \"outputs\": [\"0.1250000000\\n0.2916666667\\n0.2916666667\\n0.2916666667\\n\", \"0.0850694444\\n0.0664062500\\n0.0664062500\\n0.1955295139\\n0.1955295139\\n0.1955295139\\n0.1955295139\\n\", \"1.0000000000\\n\", \"0.0716733902\\n0.1568513416\\n0.0716733902\\n0.0513075087\\n0.1568513416\\n0.1496446398\\n0.0462681362\\n0.1274088542\\n0.0186767578\\n0.1496446398\\n\", \"0.0241401787\\n0.0917954309\\n0.0976743034\\n0.0150433990\\n0.1006279377\\n0.0150716827\\n0.0758016731\\n0.0241290115\\n0.0444770708\\n0.0796739239\\n0.0310518413\\n0.0248005499\\n0.0287209519\\n0.0976743034\\n0.0160891602\\n0.0248310267\\n0.0253902066\\n0.0917954309\\n0.0146375074\\n0.0765744099\\n\", \"0.0047521072\\n0.0089582002\\n0.0091024503\\n0.0005692947\\n0.0158713738\\n0.0231639046\\n0.0280364616\\n0.0385477047\\n0.0508439275\\n0.0104849699\\n0.0280364616\\n0.0756812249\\n0.0527268460\\n0.0663906850\\n0.0348291400\\n0.0067068947\\n0.0473003760\\n0.0620785158\\n0.0620785158\\n0.0431676433\\n0.0225005681\\n0.0055308416\\n0.0101877956\\n0.0354105896\\n0.0520300528\\n0.0099339742\\n0.0093540308\\n0.0748580820\\n0.0663906850\\n0.0444766827\\n\", \"0.5000000000\\n0.5000000000\\n\", \"0.3750000000\\n0.2500000000\\n0.3750000000\\n\", \"0.3125000000\\n0.1875000000\\n0.1875000000\\n0.3125000000\\n\"]}", "source": "primeintellect"}
|
Consider a tree $T$ (that is, a connected graph without cycles) with $n$ vertices labelled $1$ through $n$. We start the following process with $T$: while $T$ has more than one vertex, do the following:
choose a random edge of $T$ equiprobably;
shrink the chosen edge: if the edge was connecting vertices $v$ and $u$, erase both $v$ and $u$ and create a new vertex adjacent to all vertices previously adjacent to either $v$ or $u$. The new vertex is labelled either $v$ or $u$ equiprobably.
At the end of the process, $T$ consists of a single vertex labelled with one of the numbers $1, \ldots, n$. For each of the numbers, what is the probability of this number becoming the label of the final vertex?
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 50$).
The following $n - 1$ lines describe the tree edges. Each of these lines contains two integers $u_i, v_i$ — labels of vertices connected by the respective edge ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$). It is guaranteed that the given graph is a tree.
-----Output-----
Print $n$ floating numbers — the desired probabilities for labels $1, \ldots, n$ respectively. All numbers should be correct up to $10^{-6}$ relative or absolute precision.
-----Examples-----
Input
4
1 2
1 3
1 4
Output
0.1250000000
0.2916666667
0.2916666667
0.2916666667
Input
7
1 2
1 3
2 4
2 5
3 6
3 7
Output
0.0850694444
0.0664062500
0.0664062500
0.1955295139
0.1955295139
0.1955295139
0.1955295139
-----Note-----
In the first sample, the resulting vertex has label 1 if and only if for all three edges the label 1 survives, hence the probability is $1/2^3 = 1/8$. All other labels have equal probability due to symmetry, hence each of them has probability $(1 - 1/8) / 3 = 7/24$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"000\\n\", \"0101\\n\", \"0001111\\n\", \"00101100011100\\n\", \"0\\n\", \"11\\n\", \"01011111111101101100000100000000100000111001011011110110110010010001011110100011000011100100010001\\n\", \"0100111100100101001101111001011101011001111100110111101110001001010111100010011100011011101111010111111010010101000001110110111110010001100010101110111111000011101110000000001101010011000111111100000000000000001010011111010111\\n\", \"10100011001101100010000111001011\\n\"], \"outputs\": [\"3\\n\", \"6\\n\", \"16\\n\", \"477\\n\", \"1\\n\", \"2\\n\", \"911929203\\n\", \"975171002\\n\", \"259067\\n\"]}", "source": "primeintellect"}
|
Koa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form:
In one operation Koa selects positions $i$ and $i+1$ for some $i$ with $1 \le i < |s|$ and sets $s_i$ to $max(s_i, s_{i+1})$. Then Koa deletes position $i+1$ from $s$ (after the removal, the remaining parts are concatenated).
Note that after every operation the length of $s$ decreases by $1$.
How many different binary strings can Koa obtain by doing no more than $n-1$ (possibly zero) operations modulo $10^9+7$ ($1000000007$)?
-----Input-----
The only line of input contains binary string $s$ ($1 \le |s| \le 10^6$). For all $i$ ($1 \le i \le |s|$) $s_i = 0$ or $s_i = 1$.
-----Output-----
On a single line print the answer to the problem modulo $10^9+7$ ($1000000007$).
-----Examples-----
Input
000
Output
3
Input
0101
Output
6
Input
0001111
Output
16
Input
00101100011100
Output
477
-----Note-----
In the first sample Koa can obtain binary strings: $0$, $00$ and $000$.
In the second sample Koa can obtain binary strings: $1$, $01$, $11$, $011$, $101$ and $0101$. For example: to obtain $01$ from $0101$ Koa can operate as follows: $0101 \rightarrow 0(10)1 \rightarrow 011 \rightarrow 0(11) \rightarrow 01$. to obtain $11$ from $0101$ Koa can operate as follows: $0101 \rightarrow (01)01 \rightarrow 101 \rightarrow 1(01) \rightarrow 11$.
Parentheses denote the two positions Koa selected in each operation.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n2 3 2\\n3 1 2 3\\n\", \"8\\n4 6 2 3 4\\n2 3 6\\n\", \"10\\n3 4 7 5\\n2 8 5\\n\", \"17\\n1 10\\n1 12\\n\", \"23\\n1 20\\n3 9 2 12\\n\", \"2\\n1 1\\n1 1\\n\", \"2\\n1 1\\n1 1\\n\", \"3\\n1 1\\n1 2\\n\", \"20\\n1 1\\n1 11\\n\"], \"outputs\": [\"Lose Win Win Loop\\nLoop Win Win Win\\n\", \"Win Win Win Win Win Win Win\\nLose Win Lose Lose Win Lose Lose\\n\", \"Win Win Win Win Win Win Win Loop Win\\nLose Win Loop Lose Win Lose Lose Lose Lose\\n\", \"Win Win Win Win Win Win Win Win Win Win Win Lose Win Win Win Win\\nLose Lose Lose Lose Win Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose\\n\", \"Lose Lose Win Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose Lose\\nWin Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win Win\\n\", \"Win\\nWin\\n\", \"Win\\nWin\\n\", \"Loop Win\\nWin Loop\\n\", \"Loop Loop Win Lose Loop Loop Win Lose Loop Loop Win Lose Loop Loop Win Lose Loop Loop Win\\nWin Loop Loop Lose Win Loop Loop Lose Win Loop Loop Lose Win Loop Loop Lose Win Loop Loop\\n\"]}", "source": "primeintellect"}
|
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.
In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario. [Image]
Each one of them has a set of numbers between 1 and n - 1 (inclusive). Rick's set is s_1 with k_1 elements and Morty's is s_2 with k_2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.
Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.
-----Input-----
The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game.
The second line contains integer k_1 followed by k_1 distinct integers s_{1, 1}, s_{1, 2}, ..., s_{1, }k_1 — Rick's set.
The third line contains integer k_2 followed by k_2 distinct integers s_{2, 1}, s_{2, 2}, ..., s_{2, }k_2 — Morty's set
1 ≤ k_{i} ≤ n - 1 and 1 ≤ s_{i}, 1, s_{i}, 2, ..., s_{i}, k_{i} ≤ n - 1 for 1 ≤ i ≤ 2.
-----Output-----
In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.
Similarly, in the second line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Morty plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.
-----Examples-----
Input
5
2 3 2
3 1 2 3
Output
Lose Win Win Loop
Loop Win Win Win
Input
8
4 6 2 3 4
2 3 6
Output
Win Win Win Win Win Win Win
Lose Win Lose Lose Win Lose Lose
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"10 4\\n1 5 2 9 1 3 4 2 1 7\\n2 4\\n3 8\\n7 10\\n1 9\\n\", \"7 6\\n5 7 7 4 6 6 2\\n1 2\\n2 3\\n2 6\\n1 7\\n4 7\\n3 5\\n\", \"2 2\\n0 0\\n1 2\\n1 2\\n\", \"2 2\\n0 100000000\\n1 2\\n1 2\\n\", \"4 6\\n1 2 3 2\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n3 4\\n\", \"3 6\\n10 20 30\\n1 2\\n1 3\\n2 3\\n1 2\\n2 3\\n1 3\\n\", \"3 6\\n48261735 26888803 75904937\\n1 2\\n1 3\\n2 3\\n1 2\\n2 3\\n1 3\\n\", \"3 6\\n100000000 99999999 0\\n1 2\\n1 3\\n2 3\\n1 2\\n2 3\\n1 3\\n\", \"2 2\\n100000000 0\\n1 2\\n1 2\\n\"], \"outputs\": [\"17\\n82\\n23\\n210\\n\", \"2\\n0\\n22\\n59\\n16\\n8\\n\", \"0\\n0\\n\", \"100000000\\n100000000\\n\", \"1\\n3\\n6\\n1\\n3\\n1\\n\", \"10\\n30\\n10\\n10\\n10\\n30\\n\", \"21372932\\n119405200\\n49016134\\n21372932\\n49016134\\n119405200\\n\", \"1\\n199999999\\n99999999\\n1\\n99999999\\n199999999\\n\", \"100000000\\n100000000\\n\"]}", "source": "primeintellect"}
|
A function $f : R \rightarrow R$ is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all $x, y \in R$. We'll deal with a more... discrete version of this term.
For an array $h [ 1 . . n ]$, we define it's Lipschitz constant $L(h)$ as follows: if n < 2, $L(h) = 0$ if n ≥ 2, $L(h) = \operatorname{max} [ \frac{|h [ j ] - h [ i ]|}{j - i} ]$ over all 1 ≤ i < j ≤ n
In other words, $L = L(h)$ is the smallest non-negative integer such that |h[i] - h[j]| ≤ L·|i - j| holds for all 1 ≤ i, j ≤ n.
You are given an array [Image] of size n and q queries of the form [l, r]. For each query, consider the subarray $s = a [ l . . r ]$; determine the sum of Lipschitz constants of all subarrays of $S$.
-----Input-----
The first line of the input contains two space-separated integers n and q (2 ≤ n ≤ 100 000 and 1 ≤ q ≤ 100) — the number of elements in array [Image] and the number of queries respectively.
The second line contains n space-separated integers $a [ 1 . . n ]$ ($0 \leq a [ i ] \leq 10^{8}$).
The following q lines describe queries. The i-th of those lines contains two space-separated integers l_{i} and r_{i} (1 ≤ l_{i} < r_{i} ≤ n).
-----Output-----
Print the answers to all queries in the order in which they are given in the input. For the i-th query, print one line containing a single integer — the sum of Lipschitz constants of all subarrays of [Image].
-----Examples-----
Input
10 4
1 5 2 9 1 3 4 2 1 7
2 4
3 8
7 10
1 9
Output
17
82
23
210
Input
7 6
5 7 7 4 6 6 2
1 2
2 3
2 6
1 7
4 7
3 5
Output
2
0
22
59
16
8
-----Note-----
In the first query of the first sample, the Lipschitz constants of subarrays of $[ 5,2,9 ]$ with length at least 2 are: $L([ 5,2 ]) = 3$ $L([ 2,9 ]) = 7$ $L([ 5,2,9 ]) = 7$
The answer to the query is their sum.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"3 6\\n5 3 1\\n\", \"1 4\\n19\\n\", \"1 3\\n1000000\\n\", \"1 1\\n1\\n\", \"10 23\\n343 984 238 758983 231 74 231 548 893 543\\n\", \"20 40\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"29 99047\\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931765 721679 518973 65009 804367 608526 535640 117656 342804 398273 369209 298745 365459 942772 89584\\n\", \"54 42164\\n810471 434523 262846 930807 148016 633714 247313 376546 142288 30094 599543 829013 182512 647950 512266 827248 452285 531124 257259 453752 114536 833190 737596 267349 598567 781294 390500 318098 354290 725051 978831 905185 849542 761886 55532 608148 631077 557070 355245 929381 280340 620004 285066 42159 82460 348896 446782 672690 364747 339938 715721 870099 357424 323761\\n\", \"12 21223\\n992192 397069 263753 561788 903539 521894 818097 223467 511651 737418 975119 528954\\n\"], \"outputs\": [\"15\\n\", \"91\\n\", \"333333333334\\n\", \"1\\n\", \"41149446942\\n\", \"40\\n\", \"2192719703\\n\", \"17049737221\\n\", \"2604648091\\n\"]}", "source": "primeintellect"}
|
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots into $k$ pieces. For some reason, all resulting carrot lengths must be positive integers.
Big carrots are very difficult for rabbits to handle and eat, so the time needed to eat a carrot of size $x$ is $x^2$.
Help Zookeeper split his carrots while minimizing the sum of time taken for rabbits to eat the carrots.
-----Input-----
The first line contains two integers $n$ and $k$ $(1 \leq n \leq k \leq 10^5)$: the initial number of carrots and the number of rabbits.
The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 10^6)$: lengths of carrots.
It is guaranteed that the sum of $a_i$ is at least $k$.
-----Output-----
Output one integer: the minimum sum of time taken for rabbits to eat carrots.
-----Examples-----
Input
3 6
5 3 1
Output
15
Input
1 4
19
Output
91
-----Note-----
For the first test, the optimal sizes of carrots are $\{1,1,1,2,2,2\}$. The time taken is $1^2+1^2+1^2+2^2+2^2+2^2=15$
For the second test, the optimal sizes of carrots are $\{4,5,5,5\}$. The time taken is $4^2+5^2+5^2+5^2=91$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7 4\\n1 3\\n1 2\\n2 0 1\\n2 1 2\\n\", \"10 9\\n2 2 9\\n1 1\\n2 0 1\\n1 8\\n2 0 8\\n1 2\\n2 1 3\\n1 4\\n2 2 4\\n\", \"10 5\\n2 1 9\\n2 4 10\\n1 1\\n2 0 1\\n2 0 1\\n\", \"10 5\\n1 8\\n1 1\\n1 1\\n1 3\\n1 2\\n\", \"10 10\\n2 5 9\\n2 2 9\\n2 1 7\\n2 3 9\\n2 3 4\\n2 0 6\\n2 3 9\\n2 2 8\\n2 5 9\\n1 9\\n\", \"100000 1\\n2 19110 78673\\n\", \"100000 1\\n1 99307\\n\", \"1 1\\n2 0 1\\n\", \"2 3\\n2 0 2\\n2 0 1\\n1 1\\n\"], \"outputs\": [\"4\\n3\\n\", \"7\\n2\\n10\\n4\\n5\\n\", \"8\\n6\\n2\\n2\\n\", \"\", \"4\\n7\\n6\\n6\\n1\\n6\\n6\\n6\\n4\\n\", \"59563\\n\", \"\", \"1\\n\", \"2\\n1\\n\"]}", "source": "primeintellect"}
|
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types: Fold the sheet of paper at position p_{i}. After this query the leftmost part of the paper with dimensions 1 × p_{i} must be above the rightmost part of the paper with dimensions 1 × ([current width of sheet] - p_{i}). Count what is the total width of the paper pieces, if we will make two described later cuts and consider only the pieces between the cuts. We will make one cut at distance l_{i} from the left border of the current sheet of paper and the other at distance r_{i} from the left border of the current sheet of paper.
Please look at the explanation of the first test example for better understanding of the problem.
-----Input-----
The first line contains two integers: n and q (1 ≤ n ≤ 10^5; 1 ≤ q ≤ 10^5) — the width of the paper and the number of queries.
Each of the following q lines contains one of the described queries in the following format: "1 p_{i}" (1 ≤ p_{i} < [current width of sheet]) — the first type query. "2 l_{i} r_{i}" (0 ≤ l_{i} < r_{i} ≤ [current width of sheet]) — the second type query.
-----Output-----
For each query of the second type, output the answer.
-----Examples-----
Input
7 4
1 3
1 2
2 0 1
2 1 2
Output
4
3
Input
10 9
2 2 9
1 1
2 0 1
1 8
2 0 8
1 2
2 1 3
1 4
2 2 4
Output
7
2
10
4
5
-----Note-----
The pictures below show the shapes of the paper during the queries of the first example: [Image]
After the first fold operation the sheet has width equal to 4, after the second one the width of the sheet equals to 2.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.