text:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="StudySettings">
    <StudyTaskManager>
      <option name="VERSION" value="11" />
      <option name="myUserTests">
        <map />
      </option>
      <option name="course">
        <Course>
          <option name="authors">
            <list />
          </option>
          <option name="courseMode" value="Study" />
          <option name="courseType" value="PyCharm" />
          <option name="customPresentableName" />
          <option name="description" value="Practice Exercises for DS course taught by Prof. Sharifi." />
          <option name="fromZip" value="false" />
          <option name="index" value="-1" />
          <option name="language" value="Python" />
          <option name="languageCode" value="en" />
          <option name="name" value="DS Course" />
          <option name="stepikChangeStatus" value="Up to date" />
          <option name="items">
            <list>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="1" />
                <option name="name" value="Comparison of Sorting Algorithms" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  الگوریتم mergeSort یکی از روش های مرتب کردن چند عنصر است.تابعی که عناصر آرایه a را مرتب می کند می تواند به روش زیر پیاده سازی شود:

  1-اگر بازه (l , r] به صورت صعودی مرتب شده بود کار تابع تمام می شود

  2- در غیر این صورت mid برابر جزء صحیح 2 / (l + r) می شود .

  3-تابع (mergeSort(a , l , mid صدا زده می شود

  4-تابع (mergeSort(a , mid , r صدا زده می شود

  5- در این مرحله بخش های (l , mid] و (mid , r] با هم دیگر merge می شوند

  در سوال آرایه a از اندیس 0 شروع می شود

  حال یکی از بچه ها این برنامه را طوری پیاده سازی کرده که تعداد دفعاتی که تابع mergeSort صدا زده می شود را می شمارد.مثلا اگر آرایه a برابر با {4 , 3 , 2 , 1} باشد این تابع صرفا یک بار صدا زده می شود(تابع (mergeSort(0 , 4) و چون آرایه به صورت صعودی مرتب است کار تابع تمام می شود. و یا مثلا اگر آرایه a برابر با {3 , 1 , 2} باشد 3 بار این تابع صدا زده می شود(ابتدا (mergeSort(0 , 3 صدا زده می شود و مقدار mid برابر با 1 می شود و بعد به ترتیب تابع های (0 , 1)mergeSort و (mergeSort(1 , 3 صدا زده می شوند  و بعد با عمل merge شدن آرایه مرتب می شود.

  این فرد برای تست کردن برنامه اش به شما دو عدد n , k را به ترتیب ورودی می دهد و از شما می خواهد که جایگشتی از اعداد 1 تا n به او خروجی بدهید که هنگام مرتب کردن آن دقیقا k بار تابع mergeSort صدا زده شده باشد و در صورت عدم وجود ، 1- خروجی بدهد
  اگر هم چندین جواب وجود داشت جوابی که از لحاظ دیکشنری زود تر میاید را خروجی بدهید

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="32" />
                                          <option name="offset" value="20" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="32" />
                                      <option name="offset" value="20" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return -1 #Complete the function" />
                                      <option name="possibleAnswer" value="global t
    if k % 2 == 0:
        return -1
    t = k
    t -= 1
    a = [i + 1 for i in range(n)]

    def sl(l, r):
        global t
        if r - l < 2 or t == 0:
            return
        t -= 2
        m = (l + r) // 2
        a[m], a[m - 1] = a[m - 1], a[m]
        sl(l, m)
        sl(m, r)

    sl(0, n)
    if t != 0:
        return -1
    return a" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def func(n, k):
    return -1 #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        (3, 3, [2, 1, 3]),
        (4, 1, [1, 2, 3, 4]),
        (5, 6, -1),
        (100, 100, -1),
        (10, 17, [3, 1, 4, 6, 2, 8, 5, 9, 7, 10]),
        (20, 15, [3, 1, 4, 6, 2, 5, 8, 7, 9, 11, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20]),
        (30, 17,
         [2, 4, 1, 6, 3, 8, 5, 7, 9, 10, 11, 12, 13, 14, 16, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
          30]),
        (80, 25,
         [3, 1, 4, 6, 2, 8, 5, 9, 11, 7, 10, 12, 13, 14, 15, 16, 17, 18, 19, 21, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
          31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 40, 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]),
        (120, 66, -1)

    ]
    for test in tests:
        test_function(test[-1], func, test[0], test[1])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  یکی از دانش جویان درس DS که از سادگی الگوریتم Bubble Sort خسته شده تصمیم دارد با ساختن گرافی با الگوریتم زیر کمی آن را جذاب تر کند.

    procedure bubbleSortGraph()
      - build a graph G with n vertices and 0 edges
      - repeat
      - swapped = false
      - for i = 1 to n - 1 inclusive do:
          - if a[i] > a[i + 1] then
            - add an undirected edge in G between a[i] and a[i + 1]
            - swap( a[i], a[i + 1] )
            - swapped = true
          - end if
      - end for
      - until not swapped
       /* repeat the algorithm as long as swapped value is true. */
    end procedure

  حالا او می خواهد ببیند که به ازای آرایه های مختلفی که به تابع او داده می شود ، تعداد مولفه های هم بندی گراف او چند تا است . به او کمک کنید تا جواب را پیدا کند.
  در ورودی ابتدا تعداد عناصر آرایه می آید و بعد خود آرایه خروجی هم یک عدد است که تعداد مولفه های هم بندی را نشان می دهد

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="32" />
                                          <option name="offset" value="40" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="32" />
                                      <option name="offset" value="40" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return -1 #Complete the function" />
                                      <option name="possibleAnswer" value="all = []
    for i in range(n):
        pos = bisect.bisect(all, array[i])
        if pos >= len(all):
            all.append(array[i])
        else:
            all[pos] = array[i]
    return len(all)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="import bisect

def func(n, array):
    return -1 #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        (3, [3, 1, 2], 2),
        (5, [4, 2, 1, 3, 5], 3),
        (10, [1, 9, 8, 10, 2, 3, 4, 6, 5, 7], 6),
        (10, [3, 1, 4, 6, 2, 8, 5, 9, 7, 10], 6),
        (20, [3, 1, 4, 6, 2, 5, 8, 7, 9, 11, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20], 15),
        (30, [2, 4, 1, 6, 3, 8, 5, 7, 9, 10, 11, 12, 13, 14, 16, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
              30], 25),
        (80 , [3, 1, 4, 6, 2, 8, 5, 9, 11, 7, 10, 12, 13, 14, 15, 16, 17, 18, 19, 21, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
          31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 40, 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] , 73)
    ]
    for test in tests:
        test_function(test[-1], func, test[0], test[1])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  الگوریتم quickSort را با این تفاوت که در هر مرحله عنصری که به عنوان pivot انتخاب می شود به صورت رندم انتخاب شود پیاده سازی کنید.

  سپس با استفاده از زمان سیستم ، به صورت local زمان مرتب کردن را با quickSort معمولی برای ورودی های بزرگ مقایسه کنید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="33" />
                                          <option name="offset" value="70" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="33" />
                                      <option name="offset" value="70" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return arr #Complete the function" />
                                      <option name="possibleAnswer" value="#start = timeit.default_timer()
    if fst >= lst: return

    i, j = fst, lst
    pivot = arr[random.randint(fst, lst)]

    while i <= j:
        while arr[i] < pivot: i += 1
        while arr[j] > pivot: j -= 1
        if i <= j:
            arr[i], arr[j] = arr[j], arr[i]
            i, j = i + 1, j - 1
    qSortRandomPivot(arr, fst, j)
    qSortRandomPivot(arr, i, lst)
    #end = timeit.default_timer()
    #print('qSort Random Pivot Time: ' , end - start)
    return arr" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="import random
import timeit

def qSortRandomPivot(arr, fst, lst):
    return arr #Complete the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from task import qSortRandomPivot
from test_helper import *

if __name__ == '__main__':
    tests = [
        ([3, 1, 2], 0, 2, [1, 2, 3]),
        ([3, 1, 4, 6, 2, 8, 5, 9, 11, 7, 10, 12, 13, 14, 15, 16, 17, 18, 19, 21, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
          31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 40, 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] , 0 , 79 , [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])
    ]
    for test in tests:
        test_function(test[-1], qSortRandomPivot, test[0], test[1], test[2])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

الگوریتم shell Sort یکی از الگوریتم های قدیمی برای مرتب سازی است که به گونه تعمیم الگوریتم insertion Sort می باشد.

    این الگوریتم به این صورت عمل می کند که با تعریف عددی به اسم gap در هر مرحله عناصری که با هم دیگر به اندازه gap فاصله دارند را مرتب می کند(با استفاده از مرتب سازی درجی) و بعد مقدار gap را کاهش می دهد با این روش در هر مرحله داده ها به صورت نسبی مرتب می شوند.

    این الگوریتم را پیاده سازی کنید و در رابطه با بهترین اعداد برای انتخاب gap تحقیق کنید .

    همچنین پیچیدگی زمانی این الگوریتم را با الگوریتم مرتب سازی درجی مقایسه کنید.اگر در هر مرحله به جای الگوریتم مرتب سازی درجی از الگوریتم های دیگری مانند مرتب سازی سریع یا ... استفاده شود پیچیدگی زمانی چه تغییری خواهد کرد؟

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="4" />
                      <option name="name" value="Q4" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="33" />
                                          <option name="offset" value="24" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="33" />
                                      <option name="offset" value="24" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return arr #Complete the function" />
                                      <option name="possibleAnswer" value="n = len(arr)
    gap = n // 2
    while gap > 0:

        for i in range(gap, n):
            temp = arr[i]

            j = i
            while j >= gap and arr[j - gap] > temp:
                arr[j] = arr[j - gap]
                j -= gap

            arr[j] = temp
        gap //= 2
    return arr" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def shellSort(arr):
    return arr #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        ([3, 1, 2],[1, 2, 3]),
        ([3, 1, 4, 6, 2, 8, 5, 9, 11, 7, 10, 12, 13, 14, 15, 16, 17, 18, 19, 21, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
          31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 40, 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] ,[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])
    ]
    for test in tests:
        test_function(test[-1], shellSort, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  در الگوریتم مرتب سازی ((من)) ! در هر مرحله می توانیم یک عنصر را انتخاب کنیم و آن را به آخر و یا اول آرایه انتقال دهیم و جایگاه خالی را با شیفت دادن بقیه اعداد پر کنیم. مثلا در آرایه رو به رو [1 , 2 , 4 , 3] میتوناین عنصر 4 را به آخر آرایه انتقال دهیم و جای خالی را با شیفت دادن پر کنیم که در این صورت آرایه تبدیل به [4 , 1 , 2 , 3] می شود.

  حالا با الگوریتمی از مرتبه خطی ، کمترین تعداد مورد نیاز حرکت بالا برای مرتب کردن این عناصر به صورت صعودی را بیابید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="5" />
                      <option name="name" value="Q5" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="31" />
                                          <option name="offset" value="22" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="31" />
                                      <option name="offset" value="22" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return 0 #Complete the function" />
                                      <option name="possibleAnswer" value="a = [0] * (n + 1)
    for i in arr: a[i] = a[i - 1] + 1
    return n - max(a)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def func(n, arr):
    return 0 #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        (3, [3, 1, 2], 1),
        (80, [3, 1, 4, 6, 2, 8, 5, 9, 11, 7, 10, 12, 13, 14, 15, 16, 17, 18, 19, 21, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30,
          31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 40, 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], 40),
        (5 , [4 ,1 , 2 , 5 , 3] , 2),
        (4 , [4 , 1 , 3, 2] , 2),
        (1 , [1] , 0),
        (2 , [2 , 1] , 1),
        (6 , [5 ,3 , 6 , 4, 1 ,2]  , 4),
        (7 , [1 , 2 , 3 , 6, 7 , 4 , 5] , 2),
        (8 , [6 , 2 , 1 , 8 , 5 ,7 , 3 , 4] , 5),
        (9 , [1 , 6 , 4 , 5 , 9 ,8 , 7, 3 , 2] , 7),
        (10 , [5 , 1 ,6 , 2, 8 , 3 , 4 , 10 , 9 , 7] , 6)

    ]
    for test in tests:
        test_function(test[-1], func, test[0], test[1])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  به شما دو عدد  n , m داده می شود که n تعداد اعضای آرایه و m کران بالایی برای اعضا است.

  این n عنصر را به صورت stack کنار هم می چینیم(که ارتفاع stack شماره i برابر با ai است یعنی از ai تا block تشکیل شده)

  ماکسیمم تعداد block هایی که می توان برداشت بدون اینکه تصویر از بالا و راست این stack ها تغییر کند چقدر است ؟ (فرض کنید با برداشتن یک بلاک، بلاک های دیگر که روی آن هستند نمی افتند.)مثلا اگر ارتفاع بلاک ها به ترتیب 3 1 2 باشند می توان بلاک زیر 2 و دو بلاک زیر 3 را برداشت بدون آنکه تصویر ها تغییری کند.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="6" />
                      <option name="name" value="Q6" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="31" />
                                          <option name="offset" value="27" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="31" />
                                      <option name="offset" value="27" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return 0 #Complete the function" />
                                      <option name="possibleAnswer" value="arr.sort()
    c = 0
    d = 0
    s = sum(arr)
    for i in range(n):
        if (arr[i] > d):
            d += 1
    #c += (arr[n - 1] - d)
    return s - arr[n - 1] - n + d" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def func(n , m , arr):
    return 0 #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        (5, 6, [3, 3, 3, 3, 3], 10),
        (3, 5, [1, 2, 4], 3),
        (10, 17, [12, 16, 6, 9, 12, 6, 12, 1, 12, 13], 83),
        (24, 1, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 0),
        (21, 19, [19, 13, 2, 16, 8, 15, 14, 15, 7, 8, 3, 17, 11, 6, 1, 18, 16, 6, 2, 15, 5], 196),
        (6, 6, [2, 2, 4, 4, 6, 6], 18),
        (2, 1000, [1, 1000], 1)
    ]
    for test in tests:
        test_function(test[-1], func, test[0], test[1], test[2])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  به شما یک آرایه n عضوی داده می شود که تعداد عناصر زوج آن با فرد آن برابر است.

     می توانید آرایه را از بین دو عنصر x و y با هزینه قدر مطلق x - y برش بزنید به شرطی که تعداد عناصر زوج و فرد در هر کدام از برش ها با یکدیگر برابر باشند.مثلا آرایه [1 , 4 , 3 , 2] را میتوان از بین 3 و 4 با هزینه 1 برش زد.

  حداکثر تعداد برش هایی را بیابید که هزینه برش ها از مقدار b داده شده بیشتر نباشد.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="7" />
                      <option name="name" value="Q7" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="31" />
                                          <option name="offset" value="27" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="31" />
                                      <option name="offset" value="27" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return 0 #Complete the function" />
                                      <option name="possibleAnswer" value="odd = 0
    even = 0
    cuts = []
    for i in range(n - 1):
        if (arr[i] % 2 != 0):
            odd = odd + 1
        else:
            even = even + 1
        if (odd == even):
            cuts.append(abs(arr[i + 1] - arr[i]))
    cuts.sort()
    ans = 0
    sum = 0
    for i in cuts:
        if (sum + i <= b):
            sum = sum + i
            ans = ans + 1
    return ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def func(n , b , arr):
    return 0 #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        (5, 6, [1, 2, 5, 10, 15, 20], 1),
        (4, 10, [1, 3, 2, 4], 0),
        (10, 100, [94, 65, 24, 47, 29, 98, 20, 65, 6, 17], 2)
    ]
    for test in tests:
        test_function(test[-1], func, test[0], test[1], test[2])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="2" />
                <option name="name" value="Basic Data Structures" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
پیش‌نیاز:

آشنایی با داده‌ساختار پشته

تعدادی انسان با قدهای گوناگون در یک صف ایستاده‌اند. می‌خواهیم ببینیم آیا می‌توانیم به کمک یک پشته آنها را به یک صف دیگر منتقل کنیم به طوری که به ترتیب صعودی قد بایستند.

عملیات ممکن عبارتند از: 1- قرار دادن نفر اول صف اول در بالای پشته 2- قرار دادن نفر بالای پشته در انتهای صف دوم.

در ابتدا پشته و صف دوم خالی هستند.

اگر تعداد افراد صف اول n باشد، قد آنها جایگشتی از 1 تا n است.

انتظار  می‌رود پیچیدگی تابع شما از (O(n باشد.

ورودی

صف اول در قالب یک لیست

خروجی

امکان مرتب‌سازی افراد صف اول در صف دوم به صورت True یا False.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="35" />
                                          <option name="offset" value="40" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="35" />
                                      <option name="offset" value="40" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return False #Complete the function" />
                                      <option name="possibleAnswer" value="stack = []
    output_queue_needed_height = 1
    while len(input_queue) > 0 or len(stack) > 0:
        if len(stack) == 0 or (len(input_queue) > 0 and input_queue[0] < stack[-1]):
            stack.append(input_queue.pop(0))
        elif stack[-1] == output_queue_needed_height:
            stack.pop()
            output_queue_needed_height += 1
        else:
            return False
    return True" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def can_sort_by_stack(input_queue):
    return False #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        ([1, 2, 3], True),
        ([3, 2, 1], True),
        ([2, 3, 1], False),
        ([3, 1, 2], True),
        ([1, 10, 5, 6, 4, 9, 8, 7, 3, 2], False),
        ([6, 5, 1, 2, 4, 3], True)
    ]
    for test in tests:
        test_function(test[-1], can_sort_by_stack, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
پیش‌نیاز:

آشنایی با داده‌ساختار صف

اولین عدد منفی در هر k عضو متوالی آرایه A را بیابید.

انتظار  می‌رود پیچیدگی تابع شما از (O(n باشد و و فقط یکبار از روی اعضای A گذر کنید.

ورودی

آرایه A و عدد k

خروجی

یک آرایه به اندازه len(A)-k+1 که عضو iام آن، اولین عدد منفی در بازه بین عضو i ام و عضو i+k-1 آرایه A است (اگر عدد منفی در این بازه نبود عضو iام برابر 0 است).

 اندیس اعداد منفی در k عضو پیشین را در یک صف نگهداری کنید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="31" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="31" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="queue = []
    ans = []
    for i in range(len(A)):
        if A[i] < 0:
            queue.append(i)
        if i >= k-1:
            if len(queue) and i - queue[0] >= k:
                queue.pop(0)
            ans.append(A[queue[0]] if len(queue) else 0)
    return ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def first_negatives(A, k):
    return #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        ([5, -4, -6, 3, -2, 4, 8, 12], 3, [-4, -4, -6, -2, -2, 0]),
        ([-1, -2, 4, -5, -1, -3], 6, [-1]),
        ([-1, -2, -3, -5, -1, -3], 1, [-1, -2, -3, -5, -1, -3]),
        ([2, -9, 8, 1, 0, 0, 1, -2, 5, 5, 4, -7, 10, -1, -2, -1, -7, -7, -3, 5, 5, 2, 2, 2, -8, 5, -7, -5, -1, 3, 8, 7,
          -7, 4, -9, 0, 9, 5, -2, 7, -9, 4, 6, 5, 9, 9, 1, 6, -2, -5, 4, 10, 4, 2, 2, 10, 8, 10, 6, -3, -4, -4, -4, -5,
          -2, -5, 2, -1, -7, 4, -4, 5, -10, 8, -7, 0, -4, 2, -7, 10, 7, 2, -3, 8, -1, 4, 1, 4, -9, 10, 8, 6, 5, 5, 3,
          -6, 5, 8, -6, 4], 4,
         [-9, -9, 0, 0, -2, -2, -2, -2, -7, -7, -7, -7, -1, -1, -2, -1, -7, -7, -3, 0, 0, -8, -8, -8, -8, -7, -7, -5,
          -1, -7, -7, -7, -7, -9, -9, -2, -2, -2, -2, -9, -9, 0, 0, 0, 0, -2, -2, -2, -2, -5, 0, 0, 0, 0, 0, 0, -3, -3,
          -3, -3, -4, -4, -4, -5, -2, -5, -1, -1, -7, -4, -4, -10, -10, -7, -7, -4, -4, -7, -7, -3, -3, -3, -3, -1, -1,
          -9, -9, -9, -9, 0, 0, 0, -6, -6, -6, -6, -6])

    ]
    for test in tests:
        test_function(test[-1], first_negatives, test[0], test[1])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
پیش‌نیاز:

آشنایی با داده‌ساختار لیست پیوندی

دو node متمایز در یک لیست پیوندی دوسویه را با هم جابه‌جا کنید. توجه داشته باشید که این دو node ممکن است پشت سر هم باشند.

انتظار می‌رود پیچیدگی تابع شما از (O(1 باشد.

nodeها به شکل زیر تعریف شده‌اند:

class Node:
  def __init__(self, data, next_node=None, prev_node=None):
    self.data = data
    self.next = next_node
    self.prev = prev_node

self.prev برای node ابتدایی و self.next برای node انتهایی برابر None هستند.

توجه داشته باشید که برای قبول شدن تابعتان، نباید در آن node جدیدی تعریف کنید یا مقادیر nodeها را تغییر دهید.

ورودی

nodeهایی که باید با هم جابه‌جا شوند.

خروجی

ندارد.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="40" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="40" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="if node1.prev == node2:
        node1, node2 = node2, node1
    if node1.prev:
        node1.prev.next = node2
    if node1.next and node1.next != node2:
        node1.next.prev = node2
    if node2.next:
        node2.next.prev = node1
    if node2.prev and node2.prev != node1:
        node2.prev.next = node1
    node1.next, node2.next = node2.next, (node1.next if node1.next != node2 else node1)
    node1.prev, node2.prev = (node2.prev if node2.prev != node1 else node2), node1.prev" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def linked_list_swap(node1, node2):
    return #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *
import random

class Node:
    def __init__(self, data, next_node=None, prev_node=None):
        self.data = data
        self.next = next_node
        self.prev = prev_node

def check_swap(array_list, i, j):
    print(i, j)
    linked_list_swap(array_list[i], array_list[j])
    array_list[i], array_list[j] = array_list[j], array_list[i]
    error = False
    for k in range(0, len(array_list) - 1):
        if array_list[k].next != array_list[k + 1] or array_list[-k - 1].prev != array_list[-k - 2]:
            error = True
    if array_list[0].prev != None or array_list[-1].next != None or error:
        if abs(i - j) == 1:
            failed("Wrong linked list. Input is adjacent nodes.")
        elif i == 0 or j == 0 or i == len(array_list) - 1 or j == len(array_list) - 1:
            failed("Wrong linked list. Input contains head or tail nodes.")
        else:
            failed("Wrong linked list. Input isn't adjacent or head or tail nodes.")

if __name__ == '__main__':
    prev = Node(random.random())
    array_list = [prev]
    for i in range(1, 100):
        new = Node(random.random())
        new.prev = prev
        prev.next = new
        prev = new
        array_list.append(new)

    check_swap(array_list, 44, 88)
    check_swap(array_list, 0, 10)
    check_swap(array_list, 99, 5)
    check_swap(array_list, 0, 99)
    check_swap(array_list, 64, 65)
    check_swap(array_list, 9, 8)
    check_swap(array_list, 98, 99)
    check_swap(array_list, 1, 0)
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="3" />
                <option name="name" value="Tree Storage - Traversal" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

دفترچه پیمایش و ذخیره سازی درخت

    انواع روش‌های ذخیره‌سازی درخت و چند داستان دیگر!

    تشخیص دهید که برای یک درخت دودویی ورودی که ریشه آن به شما داده شده است، آیا آن درخت ، یک درخت قرینه هست یا نه.

    درخت قرینه درختی است که نسبت به خود آیینه است. مثلا درخت زیر یک درخت قرینه است.

مثال

     1
   /   \
  2     2
 / \   / \
3   4 4   3

    توضیحات: یک روش ذخیره‌سازی درخت را در دفترچه مربوطه دیدید.(leftchild, rightsibling)
    .
    حال سعی کنید روش دیگری برای ذخیره‌سازی درخت اتخاذ کنید که در حل سوال انعطاف بیشتری به شما بدهد.(کلا به چند روش میتوان درخت را ذخیره کرد ؟ )

        یکی از روشهای پر کاربرد ذخیره سازی درخت ها ، استفاده از شی برای هر راس است که آن شی دارای اشاره گر به فرزند چپ و راست خود(در درخت دودویی) می باشد. نقطه قوت این نوع ذخیره سازی، ایجاد امکان فکر کردن به صورت بازگشتی به مسئله می باشد!

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="41" />
                                          <option name="offset" value="123" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="41" />
                                      <option name="offset" value="123" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="# Maybe want to write another function ?!" />
                                      <option name="possibleAnswer" value="def mirror(root1, root2):
    if root1 is None and root2 is None:
        return True
    if root1 is not None and root2 is not None:
        if root1.value == root2.value:
            return (mirror(root1.left, root2.right) and
                    mirror(root1.right, root2.left))
    return False" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="25" />
                                          <option name="offset" value="193" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="25" />
                                      <option name="offset" value="193" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return False #Do the task" />
                                      <option name="possibleAnswer" value="return mirror(root, root)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

# Maybe want to write another function ?!

def isSymmetric(root):
    return False #Do the task

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    root1 = Node(1)
    root1.left = Node(2)
    root1.right = Node(2)
    root1.left.left = Node(3)
    root1.left.right = Node(4)
    root1.right.left = Node(4)
    root1.right.right = Node(3)

    root2 = Node(3)
    root2.left = Node(1)
    root2.right = Node(1)
    root2.left.left = Node(0)
    root2.left.right = Node(2)
    root2.right.left = Node(0)
    root2.right.right = Node(2)

    root3 = Node(1)
    root3.left = Node(2)
    root3.right = Node(2)
    root3.left.left = Node(3)
    root3.left.right = Node(4)
    root3.right.left = Node(4)
    root3.right.right = Node(3)
    root3.left.left.left = Node(5)
    root3.left.left.right = Node(6)
    root3.left.right.left = Node(7)
    root3.left.right.right = Node(8)
    root3.right.left.left = Node(8)
    root3.right.left.right = Node(7)
    root3.right.right.left = Node(6)
    root3.right.right.right = Node(5)

    root4 = Node(1)
    root4.left = Node(2)
    root4.right = Node(2)
    root4.left.left = Node(3)
    root4.left.right = Node(4)
    root4.right.left = Node(4)
    root4.right.right = Node(3)
    root4.left.left.left = Node(5)
    root4.left.left.right = Node(6)
    root4.left.right.left = Node(7)
    root4.left.right.right = Node(8)
    root4.right.left.left = Node(8)
    root4.right.left.right = Node(7)
    root4.right.right.left = Node(5)
    root4.right.right.right = Node(6)
    tests = [
        (root1, True),
        (root2, False),
        (root3, True),
        (root4, False)
    ]
    for test in tests:
        test_function(test[-1], isSymmetric, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

دفترچه پیمایش و ذخیره سازی درخت

پیمایش عمودی درخت !

اگر هنگام کشیدن یک درخت دودویی مثلا یک راس را در مختصات x = A رسم کنیم و فرزند چپ و راست را به ترتیب در A-1 و A+1 رسم کنیم، پیمایش عمودی آن درخت عبارت است از دسته هایی از رئوس که مختصات x یکسانی دارند.(به مثال دقت کنید)

حال برای یک درخت دودویی که ریشه آن به شما داده شده است، آنرا به صورت عمودی پیمایش کنید.(خروجی به صورت لیستی از لیستها می بایست باشد)

مثال

          1
        /    \
       2      3
      / \    / \
     4   5  6   7
             \   \
              8   9

  که پیمایش عمودی آن به صورت زیر است:

[[4], [2], [1, 5, 6], [3, 8], [7], [9]]

برای مطالعه

  علاوه بر روش های پیمایش معروف و پرکاربردی که دیده اید، روش های پیمایش مختلف و زیادی دیگری برای درخت وجود دارد . تعدادی از معروف ترین آنها عبارتد از: level, spiral, specific, ... که در صورت علاقه می توانید درباره آنها مطالعه کنید.

عددهایی که در یک ستون قرار می گیرند دارای چه ویژگی مشترکی هستند ؟

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="123" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="123" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="minimum = 0
maximum = 0

def find_left_right(node, distance):
    global minimum, maximum
    if node is None:
        return
    if distance < minimum:
        minimum = distance
    elif distance > maximum:
        maximum = distance
    find_left_right(node.left, distance - 1)
    find_left_right(node.right, distance + 1)

def vertical(node, column, distance, list):
    if node is None:
        return

    if distance == column:
        list[-1].append(node.value)

    vertical(node.left, column, distance - 1, list)
    vertical(node.right, column, distance + 1, list)
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="154" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="154" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="list = []
    global minimum, maximum
    minimum, maximum = 0, 0
    find_left_right(root, 0)
    for column in range(minimum, maximum + 1):
        list.append([])
        vertical(root, column, 0, list)
    return list" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

def verticalOrder(root):
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    root1 = Node(1)
    root1.left = Node(2)
    root1.right = Node(3)
    root1.left.left = Node(4)
    root1.left.right = Node(5)
    root1.right.left = Node(6)
    root1.right.right = Node(7)
    root1.right.left.right = Node(8)
    root1.right.right.right = Node(9)

    root2 = Node(3)
    root2.left = Node(1)
    root2.right = Node(1)
    root2.left.left = Node(0)
    root2.left.right = Node(2)
    root2.right.left = Node(0)
    root2.right.right = Node(2)

    root3 = Node(1)
    root3.left = Node(2)
    root3.right = Node(2)
    root3.left.left = Node(3)
    root3.left.right = Node(4)
    root3.right.left = Node(4)
    root3.right.right = Node(3)
    root3.left.left.left = Node(5)
    root3.left.left.right = Node(6)
    root3.left.right.left = Node(7)
    root3.left.right.right = Node(8)
    root3.right.left.left = Node(8)
    root3.right.left.right = Node(7)
    root3.right.right.left = Node(6)
    root3.right.right.right = Node(5)

    root4 = Node(1)
    root4.left = Node(2)
    root4.right = Node(3)
    root4.left.left = Node(4)
    root4.right.right = Node(5)
    root4.left.left.left = Node(6)
    root4.right.right.right = Node(7)
    root4.right.right.right.left = Node(8)
    root4.right.right.right.left.left = Node(9)
    root4.right.right.right.left.left.left = Node(10)

    tests = [
        (root1, [[4], [2], [1, 5, 6], [3, 8], [7], [9]]),
        (root2, [[0], [1], [3, 2, 0], [1], [2]]),
        (root3, [[5], [3], [2, 6, 7, 8], [1, 4, 4], [8, 2, 7, 6], [3], [5]]),
        (root4, [[6], [4], [2], [1, 10], [3, 9], [5, 8], [7]])
    ]
    for test in tests:
        test_function(test[-1], verticalOrder, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

دفترچه پیمایش و ذخیره سازی درخت

یکی بودن یا نبودن، مسئله این است!

به شما ۳ آرایه از اعداد متمایز داده شده است که نشان دهنده پیمایش های پیش ترتیب ، میان ترتیب و پس ترتیب می باشند. در زمان

 O(n2)

 بررسی
 کنید که آیا این ۳ پیمایش ، پیمایش مربوط به یک درخت یکسان بوده اند یا نه! (درخت ها دودویی هستند)

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="123" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="123" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def buildTree(preorder, inorder):
    if len(preorder) == 0:
        return
    if len(preorder) == 1:
        return Node(preorder[0])
    root = Node(preorder[0])
    div = inorder.index(preorder[0])
    root.left = buildTree(preorder[1:(div + 1)], inorder[0:div])
    root.right = buildTree(preorder[(div + 1):], inorder[(div + 1):])
    return root

def postorder_traversal(root, list):
    if root:
        if root.left:
            postorder_traversal(root.left, list)
        if root.right:
            postorder_traversal(root.right, list)
        list.append(root.value)
        return list" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="35" />
                                          <option name="offset" value="170" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="35" />
                                      <option name="offset" value="170" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return False #Complete the function" />
                                      <option name="possibleAnswer" value="root = buildTree(preorder, inorder)
    root_postorder = postorder_traversal(root, [])
    if postorder == root_postorder:
        return True
    return False" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

def check(preorder, inorder, postorder):
    return False #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':

    tests = [
        ([1, 2, 4, 5, 3], [4, 2, 5, 1, 3], [4, 5, 2, 3, 1], True),
        ([25,15,10,4,12,22,18,24,50,35,31,44,70,66,90], [4,10,12,15,18,22,24,25,31,35,44,50,66,70,90], [4,12,10,18,24,22,15,31,44,35,66,90,70,50,25], True),
        ([2,7,3,6,8,11,5,9,4], [3,7,8,6,11,2,5,4,9], [3,8,11,7,6,4,9,5,2], False),
        ([8,5,9,7,1,12,2,4,11,3], [9,5,1,7,2,12,8,4,3,11], [9,1,2,12,7,5,11,3,4,8], False)
    ]
    for test in tests:
        test_function(test[-1], check, test[0], test[1], test[2])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

دفترچه پیمایش و ذخیره سازی درخت

از جدایی ها حکایت می کند!

  اکبر دو دوست با نام های مستعار اصغر و احمد دارد که همگی در شهر پشمکستان زندگی می کنند.شهر پشمکستان ، به علت مشکلات عدیده تنها دو جاده به شهرهای دیگر دارد. هر یک از شهرهای دیگر نیز علاوه بر جاده به شهر قبلی، نهایتا ۲ جاده به شهرهای دیگر می توانند داشته باشد.(دقت شود که دور وجود ندارد)

  بعد از برگزاری فینال اخیر جام باشگاه های اروپا و خطای جنجالی سرخیو راموس روی محمد صلاح، دعوای شدیدی میان اصغر و احمد رخ داده است و هر لحظه ممکن است کار به مراحل باریک تری برسد!

  حال اکبر به عنوان یک دوست خوب می خواهد برای مدتی اصغر و احمد را از یکدیگر دور کند تا دوستی آنها پابرجا بماند.

  به اکبر کمک کنید که فاصله دورترین دو شهر را در زمان
  خطی
    O(n)
   پیدا کند. فاصله دو شهر بر اساس تعداد شهرهای میان آن دو شهر(به علاوه خودشان) تعریف می شود.

یک راه حل در زمان خطی خواسته شده است. پس احتمالا حق نداریم بیشتر از یکبار هر شهر را نگاه کنیم. نه ؟

بازگشتی فکر کنید!

سوال در مبحث پیمایش درخت است. به انواع پیمایش ها فکر کنید و اینکه اینجا کدام یک گره از مشکل ما باز می کند .

در حل سوال پیمایشی بدرد بخور است که از ریشه شروع به حل مسئله می کند یا از برگ ها ؟

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="4" />
                      <option name="name" value="Q4" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="177" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="177" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def postorder_traversal(root, list):
    if root:
        if root.city1:
            postorder_traversal(root.city1, list)
        if root.city2:
            postorder_traversal(root.city2, list)
        if root.city1 and root.city2:
            root.max_depth = max(root.city1.max_depth, root.city2.max_depth) + 1
            root.answer = root.city1.max_depth + root.city2.max_depth + 1
        elif root.city1:
            root.max_depth = root.city1.max_depth + 1
            root.answer = root.city1.max_depth + 1
        elif root.city2:
            root.max_depth = root.city2.max_depth + 1
            root.answer = root.city2.max_depth + 1
        else:
            pass
        list.append(root.answer)
        return list
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="31" />
                                          <option name="offset" value="200" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="31" />
                                      <option name="offset" value="200" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return 0 #Complete the function" />
                                      <option name="possibleAnswer" value="temp = postorder_traversal(root, [])
    return max(temp)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node:
    def __init__(self, name):
        self.city_name = name
        self.city1 = None
        self.city2 = None
        self.max_depth = 1
        self.answer = 0

def solve(root):
    return 0 #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    root1 = Node(1)
    root1.city1 = Node(2)
    root1.city2 = Node(3)
    root1.city1.city1 = Node(4)
    root1.city1.city2 = Node(5)
    root1.city2.city1 = Node(6)
    root1.city2.city2 = Node(7)
    root1.city2.city1.city2 = Node(8)
    root1.city2.city2.city2 = Node(9)

    root2 = Node(3)
    root2.city1 = Node(1)
    root2.city2 = Node(1)
    root2.city1.city1 = Node(0)
    root2.city1.city2 = Node(2)
    root2.city2.city1 = Node(0)
    root2.city2.city2 = Node(2)

    root3 = Node(1)
    root3.city1 = Node(2)
    root3.city2 = Node(2)
    root3.city1.city1 = Node(3)
    root3.city1.city2 = Node(4)
    root3.city2.city1 = Node(4)
    root3.city2.city2 = Node(3)
    root3.city1.city1.city1 = Node(5)
    root3.city1.city1.city2 = Node(6)
    root3.city1.city2.city1 = Node(7)
    root3.city1.city2.city2 = Node(8)
    root3.city2.city1.city1 = Node(8)
    root3.city2.city1.city2 = Node(7)
    root3.city2.city2.city1 = Node(6)
    root3.city2.city2.city2 = Node(5)

    root4 = Node(1)
    root4.city1 = Node(2)
    root4.city2 = Node(3)
    root4.city1.city1 = Node(4)
    root4.city2.city2 = Node(5)
    root4.city1.city1.city1 = Node(6)
    root4.city2.city2.city2 = Node(7)
    root4.city2.city2.city2.city1 = Node(8)
    root4.city2.city2.city2.city1.city1 = Node(9)
    root4.city2.city2.city2.city1.city1.city1 = Node(10)

    root5 = Node(1)
    root5.city1 = Node(2)
    root5.city2 = Node(3)
    root5.city1.city1 = Node(4)
    root5.city1.city2 = Node(5)
    root5.city1.city1.city1 = Node(6)
    root5.city1.city1.city1.city1 = Node(8)
    root5.city1.city2.city1 = Node(7)
    root5.city1.city2.city1.city1 = Node(9)

    tests = [
        (root1, 6),
        (root2, 5),
        (root3, 7),
        (root4, 10),
        (root5, 7)
    ]
    for test in tests:
        test_function(test[-1], solve, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="4" />
                <option name="name" value="BST" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه BST را مطالعه کنید.

دو درخت جست و جوی دودویی  به عنوان ورودی داده شده اند.
عناصر مشترک این دو درخت را با الگوریتمی در زمان خطی چاپ کنید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="22" />
                                          <option name="offset" value="150" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="22" />
                                      <option name="offset" value="150" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete the function" />
                                      <option name="possibleAnswer" value="if data > root.value:
        if root.right:
            insert(root.right, data)
        else:
            root.right = Node(data)
    if data < root.value:
        if root.left:
            insert(root.left, data)
        else:
            root.left = Node(data)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="22" />
                                          <option name="offset" value="288" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="22" />
                                      <option name="offset" value="288" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete the function" />
                                      <option name="possibleAnswer" value="if root:
        # First call on left child
        inordertraversal(root.left, inorder)

        # then print the data of node
        inorder.append(root.value)

        # now recur on right child
        inordertraversal(root.right, inorder)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="
class Node:
    def __init__(self, value):
        self.left = None
        self.right = None
        self.value = value

def insert(root,data):
    #Complete the function

#inorder is an array which we want to store the inorder traversal in it.
def inordertraversal(root, inorder):
    #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    placeholder = placeholders[0]
    if placeholder == "":       # TODO: your condition here
        passed()
    else:
        failed()

#intersection in O(m + n)
# m is size of arr1, n is size of array2
finalarray = []
def printIntersection(arr1, arr2, m, n):
    i, j = 0, 0
    while i < m and j < n:
        i, j = 0, 0
        while i < m and j < n:
            if arr1[i] < arr2[j]:
                i += 1
            elif arr2[j] < arr1[i]:
                j += 1
            else:
                # common element.
                finalarray.append(arr2[j])
                j += 1
                i += 1

if __name__ == '__main__':
    mainroot = Node(5)
    insert(mainroot,1)
    insert(mainroot,3)
    insert(mainroot,6)
    insert(mainroot,8)
    insert(mainroot,7)
    insert(mainroot, 4)

    mainroot2 = Node(10)
    insert(mainroot2, 11)
    insert(mainroot2, 4)
    insert(mainroot2, 6)
    insert(mainroot2, 7)
    insert(mainroot2, 14)
    insert(mainroot2, 9)

    inorder1 = []
    inorder2 = []
    inordertraversal(mainroot, inorder1)
    inordertraversal(mainroot2, inorder2)

    m = len(inorder1)
    n = len(inorder2)
    printIntersection(inorder1, inorder2, m, n)

    for i in [4,6,7]:
        if i not in finalarray:
            failed("try again")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

پیمایش پیشوندی یک درخت جست و جوی دودویی داده شده است. بررسی کنید که آیا هر راس داخلی دقیقا یک فرزند دارد یا خیر.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="22" />
                                          <option name="offset" value="36" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="22" />
                                      <option name="offset" value="36" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete the function" />
                                      <option name="possibleAnswer" value="nextDiff = 0
    #next node in preorder - next next node
    lastDiff = 0
    #next node in preorder - last node in preorder.

    for i in range(size - 1):
        nextDiff = pre[i] - pre[i + 1]
        lastDiff = pre[i] - pre[size - 1]
        if nextDiff * lastDiff < 0:
            return False
    return True" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def hasOnlyOneChild(pre, size):
    #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import*

if __name__ == "__main__":

    pre = [8, 3, 5, 7, 6]
    size = len(pre)

    if (hasOnlyOneChild(pre, size) == False):
        failed("please try again")

    pre = [11, 10, 6, 8, 3]
    size = len(pre)
    if (hasOnlyOneChild(pre, size) == True):
        failed("please try again")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

یک درخت به عنوان ورودی داده شده است. بررسی کنید که آیا این یک درخت جست و جوی دودویی است یا خیر.

    پیچیدگی زمانی:

O(n)

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="123" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="123" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="prev = None" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="22" />
                                          <option name="offset" value="146" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="22" />
                                      <option name="offset" value="146" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete the function" />
                                      <option name="possibleAnswer" value="global prev
    prev = None
    return isbst_mainfunc(root)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="2" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="170" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="170" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def isbst_mainfunc(root):
    #using inorder travers
    global prev

    if root is None:
        return True

    if isbst_mainfunc(root.left) is False:
        return False

    if prev is not None and prev.value > root.value:
        return False

    prev = root
    return isbst_mainfunc(root.right)
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

def isbst(root):
    #Complete the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':

    root = Node(10)
    root.left = Node(6)
    root.right = Node(14)
    root.left.left = Node(3)
    root.left.right = Node(8)
    root.right.left = Node(12)
    root.right.right = Node(1)

    if isbst(root):
        failed("please try again. 1")

    root = Node(10)
    root.left = Node(6)
    root.right = Node(14)
    root.left.left = Node(3)
    root.left.right = Node(8)
    root.right.left = Node(12)
    root.right.right = Node(16)
    if  isbst(root) is False:
        failed("please try again. 2")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="5" />
                <option name="name" value="Trie" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه Trie را مطالعه کنید.

    در این task، آرابه A از n عدد به شما داده میشود. فرض کنید تابعی مانند XOR_ARRAY داریم به طوریکه دو اندیس L و R به عنوان وروری میگیرد و در خروجی XOR عناصر A از اندیس L تا R (با احتساب خودِ L و R) میدهد.
    شما باید تابع main را طوری تکمیل کنید که ماکسیموم تابع

        XOR_Array(L,R)

 به ازای تمامی

        \(L \le R\)

    را return کند.

محدودیت ها:

    \(n < 3 \times 10^3 \)

    \(A[i] < 10^9 \)

ورودی نمونه:

n = 5

A = [3, 7, 7, 7, 0]

خروجی نمونه:

7

    توجه کنید که میتوان XOR_ARRAY را به صورت زیر حساب کرد:

        XOR_ARRAY(L , R) = XOR( XOR_ARRAY(1, R) , XOR_ARRAY(1, L-1))

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="128" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="128" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def insert(root, a):
    current_node = root
    b = []
    i = 64
    while i > 0:
        b.append(a%2)
        a = a//2
        i -= 1

    b.reverse()
    for bit in b:
        if bit == 0:
            if current_node.zero == None:
                current_node.zero = Node(0)
                current_node = current_node.zero
            else:
                current_node = current_node.zero
        else:
            if current_node.one == None:
                current_node.one = Node(0)
                current_node = current_node.one
            else:
                current_node = current_node.one
    current_node.cnt += 1" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="130" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="130" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def find_max_xor(root, a):
    current_node = root
    b = []
    i = 64
    while i > 0:
        b.append(a%2)
        a //= 2
        i -= 1
    b.reverse()
    ans = 0
    for bit in b:
        if bit == 0:
            if current_node.one == None:
                current_node = current_node.zero
                ans = ans*2
            else:
                current_node = current_node.one
                ans = ans*2 + 1
        else:
            if current_node.zero == None:
                current_node = current_node.one
                ans = ans*2
            else:
                current_node = current_node.zero
                ans = ans*2 + 1

    return  ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="2" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="152" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="152" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="root = Node(0)
    partial_xor = []

    insert(root, 0)

    partial_xor.append(a[0])
    insert(root, a[0])

    max_xor = a[0]
    for i in range(n - 1):
        #print(i, " " , max_xor)
        n_xor = a[i+1] ^ partial_xor[i]
        partial_xor.append(n_xor)
        insert(root, n_xor)
        max_xor = max(max_xor, find_max_xor(root, n_xor))
    return max_xor" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="import random
class Node:
    def __init__(self, cnt):
        self.cnt = cnt
        self.zero = None
        self.one = None

def main(n, a):
    return #Complete the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from test_helper import *
from task import *

def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    placeholder = placeholders[0]
    if placeholder == "7":       # TODO: your condition here
        passed()
    else:
        failed()

if __name__ == '__main__':
    tests = [
        (5, [3, 7, 7, 7, 0], 7),
        (5, [3, 8, 2, 6, 4], 15),
        (100, [760931312,
961953649,
429596411,
182330388,
16335298,
76880608,
346788756,
355556955,
334080582,
350409683,
937057391,
969259835,
174707619,
113291960,
360805778,
71938466,
438765547,
603511580,
10787845,
938312989,
359609538,
940176361,
210359121,
550234627,
742633517,
555718375,
734223942,
1442635,
981887833,
898263064,
619239874,
742819137,
860216705,
48836277,
777665890,
876552003,
978233257,
124454638,
84625316,
312313832,
327380686,
21682699,
134090025,
354604670,
987491032,
494895802,
279059501,
278772937,
950923748,
289847346,
69602285,
310533278,
82540065,
279961405,
860767904,
825173581,
688196145,
447508205,
679132582,
670083970,
345771261,
298372448,
265419465,
58504325,
199725090,
43085347,
787572693,
30474706,
20056350,
872198008,
342788537,
199953402,
746397073,
476878561,
554558071,
586404463,
824290729,
833617572,
865177399,
775214469,
975981283,
934779683,
938264112,
58521340,
67257446,
651548374,
736211286,
755453591,
99056571,
267860226,
278053919,
297344198,
566232673,
395989750,
355848522,
618474129,
291591462,
143421207,
648948834,
164164178], 1073354569)
    ]
    for test in tests:
        test_function(test[-1], main, test[0], test[1])

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

شما یک Numpad دارید که میتوانید از آن برای نوشتن کلمات کمک بگیرید. numpad شما کلید های 0 تا 9 ای دارد که به هرکدام حروفی از 'a' تا 'z' نسبت داده شده. هیچ حرفی به دو کلید نسبت داده نشده است.
یک نمونه از numpad آمده است:

 0: a e u	 1: b l v	 2: c m w

 3: d n x	 4: i o y	 5: f p z

 6: g q	 7: h r 	 8: k s

	9: j t

    از طرفی، یک دیکشنری از کلمات هم به شما داده شده. شما میتوانید از keypad برای نوشتن کلمات استفاده کنید. مثلا برای جمله "Hello World" باید کلید ها به شکلِ

"7 0 1 1 4 2 4 7 1 3"

وارد شوند. ممکن است یک دنباله از کلید ها بتواند نمایانگر چند عبارت از دیکشنری باشد یا حتی نمایانگر عبارتی از دیکشنری نباشد. میگوییم یک مجموعه از کلمات، یک دنباله از کلیدها را پوشش میدهد، اگر بتوان یک عبارت از آن کلمات ساخت که دنباله کلیدها نشان دهنده آن عبارت باشد. یک عبارت از به هم چسباندنِ چند کلمه ساخته میشود. حالا شما باید با گرفتنِ یک دیکشنری، یک numpad و یک دنباله از کلید ها، اندازه کوچکترین مجموعه ای از کلمات که دنباله کلیدها را پوشش میدهد، خروجی دهید.

ورودی:

پارامترهای تابع main که باید آن را کامل کنید.

Dictionary, Numpad, Keyset

توضیح بیشتر:

    dictionary = ['worda','wordb', 'wordc']

    numpad[i] = array of chars corresponding to i : [['a','b','c'] , ['e','f','g'] , ...]

    Keyset = array of keys = [0,1,2,3,4,5,...]

محدودیت ها:

    dictionary_size \(\le 10^4\)

    Keyset_size \(\le 10^3\)

خروجی تابع باید اندازه کوچکترین مجموعه ای باشد که دنباله کلیدهای داده شده را پوشش میدهد.

ورودی و خروجی نمونه:

    input:

    dictionary = ["am","axe","exam","boy","colour","dam","dot","donkey","fox","new","prim","prime","primeval","pry","the","this","theory","van"]

    numpad = [['a','b','c'],['d','e','f'],['g','h'],['i','j','y'], ['l','m','n'],['o','p','q'],['r','s'],['t','u'], ['v','w','x'],['k','z']]

    keyset = [7,2,1,5,6,3,4,1,8,0,4]

    output:

    2

    dynamic programming.

    f[0] = 0;

    f[i] = min{ f[j] + 1 };  for all 0 <= j < i and S[j+1 .. i] is a word.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="89" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="89" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="root = Node()
digit = [None]*26

def trieInsert(string):
    current = root
    for c in string:
        tmp_char = ord(c) - ord('a')
        tmp_digit = digit[tmp_char]
        if current.next[tmp_digit] == None:
            current.next[tmp_digit] = Node()
            current = current.next[tmp_digit]
        else:
            current = current.next[tmp_digit]
    current.cnt = current.cnt + 1" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="133" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="133" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="for i in range(len(numpad)):
        chars = numpad[i]
        for char in chars:
            tmp_char = ord(char) - ord('a')
            digit[tmp_char] = i
    for word in dictionary:
        trieInsert(word)
    dp = [0]*(len(keyset)+1)
    for i in range(len(keyset)):
        j = len(keyset) - i - 1
        current = root
        k = j
        dp[j] = 999999
        while k < len(keyset) and current is not None:
            current = current.next[keyset[k]]
            if current is None:
                break
            if current.cnt > 0 and dp[k+1] != -1:
                dp[j] = min(dp[j], 1 + dp[k+1])
            k = k + 1
        if dp[j] == 999999:
            dp[j] = -1
    return dp[0]" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="
class Node:
    def __init__(self):
        self.cnt = 0
        self.next = [None]*10

def main(dictionary, numpad, keyset):
    return #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    placeholder = placeholders[0]
    if placeholder == "":       # TODO: your condition here
        passed()
    else:
        failed()

if __name__ == '__main__':
    dic = ["am","axe","exam"
    ,"boy","colour","dam","dot","donkey",
    "fox","new","prim","prime","primeval","pry",
       "the","this","theory","van"]
    numpad = [['a','b','c'],['d','e','f'],['g','h'],['i','j','y'],
          ['l','m','n'],['o','p','q'],['r','s'],['t','u'],
          ['v','w','x'],['k','z']]
    keyset = [7,2,1,5,6,3,4,1,8,0,4]

    dic2 = ["am", "ant", "axe", "boy", "colour", "dam", "dot",
            "donkey", "exam", "exact", "fox", "new", "prim",
            "prime", "primeval", "pry", "the", "this", "theory", "van"]
    numpad2 = [['a','b','c'],['d','e','f'],['g','h'],['i','j','y'],
          ['l','m','n'],['o','p','q'],['r','s'],['t','u'],
          ['v','w','x'],['k','z']]
    keyset2 = [2,4,3,0,2]

    tests = [ (dic, numpad, keyset, 2),
          (dic2, numpad2, keyset2, -1)]
    for test in tests:
        test_function(test[-1], main, test[0], test[1], test[2])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="6" />
                <option name="name" value="Heap" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه Heap را مطالعه کنید.

  یک مسیر طولانی به صورت یک ردیف nتایی که از ۱ تا n و از چپ به راست شماره‌گذاری شده‌است.

  ما در خانه 1 می باشیم و می خواهیم به خانه n برسیم. در طول مسیر باید از تمام خانه ها عبور کنیم و حق نداریم به خانه ای برگردیم.

  هر خانه به جز خانه‌ی اول شامل یک استاد یا یک درس است. درس خانه‌ی iام مقدار u_i تا واحد دارد.

  هر بار پویا وارد یک خانه شامل درس می‌شود می‌تواند درس را پاس کند و در نتیجه u_i تا به واحدهای پاس شده‌ی خود اضافه کند- یا از آن بگذرد. از آن جایی که پویا خیلی بااستعداد است حتما می‌تواند درسی که می‌خواهد را پاس کند.

  اگر پویا وارد خانه‌ای شود که توسط استاد اشغال شده‌است، استاد از او می‌پرسد که چند درس (نه چند واحد) پاس کرده‌است و اگر تعداد درس‌های پاس کرده‌ی پویا از h_index استاد بیشتر یا مساوی باشد استاد او را مجبور می‌کند در آزمایشگاهش کار کند و انقدر کار به او می‌دهد که نتواند دیگر مسیر را ادامه دهد و لیسانس بگیرد. از آن جایی که پویا خیلی مودب است نمی‌تواند درخواست استاد را رد کند.

  اما از آن جایی که پویا مصمم است که لیسانسش را بگیرد می‌خواهد حتما به خانه‌ی آخر برسد و هم‌چنین در طول راه بیشترین تعداد واحد را پاس کند. به پویا در رسیدن به هدفش کمک کنید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="0" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="0" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="from heapq import heappush,heappop" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="195" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="195" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="heap = []
    heapSize = 0
    arr1 = list(map(int, arr1.split()))
    arr2 = list(map(int, arr2.split()))

    for i in range(n-1):
        if(arr1[i] == 0):
            heappush(heap,arr2[i])
            heapSize += 1
        else:
            while(heapSize >= arr2[i]):
                heapSize -= 1
                heappop(heap)

    return sum(heap)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="

# Sample Input:
# n = 10
# arr1 = "0 0 0 0 1 0 1 0 1"  0 is for a course, 1 is for a prof.
# arr2 = "5 10 17 6 2 1 3 2 4" course units or h_index of the prof.

def maxVahed(n, arr1, arr2):
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    n = 10
    arr1 = "0 0 0 0 1 0 1 0 1"
    arr2 = "5 10 17 6 2 1 3 2 4"
    if maxVahed(n,arr1,arr2) != 20:
        failed("Wrong Answer")

    n = 6
    arr1 = "0 0 1 0 1"
    arr2 = "10 12 2 1 3"

    if maxVahed(n,arr1,arr2) != 13:
        failed("Wrong Answer")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  k تا آرایه مرتب شده داریم.

  می خواهیم با ترکیب این آرایه ها که طول هر یک n می باشد به یک ارایه مرتب شده برسیم.

  تابع merge_k_sorted_arrays را طوری کامل کنید که این کار را انجام دهد.

  ورودی های این تابع یک لیست k عضوی از لیست هایی به طول n می باشند که هریک مرتب شده هستند.

  می توانید از کلاس Heap که قرار داده شده نیز استفاده کنید.

  پیچیدگی زمانی:

O(nk Log k)

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="102" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="102" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def heapfiy_min(heap, i, size):

    while True:
        left = 2 * i + 1
        right = 2 * i + 2
        min_ele = i
        if left < size and heap[min_ele].data > heap[left].data:
            min_ele = left
        if right < size and heap[min_ele].data > heap[right].data:
            min_ele = right

        if min_ele == i:
            break
        else:
            heap[i], heap[min_ele] = heap[min_ele], heap[i]
        i = min_ele" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="149" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="149" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="row = k
    col = n
    bubble = [0] * row
    heap = [None] * row
    ans = [None] * (row * col)
    n = row * col
    for i in range(0, row):
        heap[i] = HeapNode(matrix[i][0], i)
    for i in range(row - 1, -1, -1):
        heapfiy_min(heap, i, row)
    for i in range(0, n):
        ans[i] = heap[0].data
        # print "ans::iter", ans
        mat_row = heap[0].row
        if bubble[mat_row] >= col - 1:
            heap[0] = heap[row - 1]
            row = row - 1
        else:
            bubble[mat_row] += 1
            mat_col = bubble[mat_row]
            heap[0] = HeapNode(matrix[mat_row][mat_col], mat_row)
        heapfiy_min(heap, 0, row)
    return ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class HeapNode:
    def __init__(self, data, row,):
        self.data = data
        self.row = row

def merge_k_sorted_arrays(matrix, k, n):
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    mat = [ [1, 3, 5, 7],
            [2, 4, 6, 8],
            [0, 9, 10, 11] ]
    arr = merge_k_sorted_arrays(mat, 3, 4)
    if not all(arr[i] <= arr[i+1] for i in range(len(arr)-1)):
        failed("Wrong Answer!")

    mat = [ [-2, 3, 5, 10, 11, 100],
            [1, 3, 5, 6, 7, 8],
            [-3, -2, -1, 101, 102, 103],
            [0, 0, 0, 0, 0, 105]]
    arr = merge_k_sorted_arrays(mat, 4, 6)
    if not all(arr[i] <= arr[i+1] for i in range(len(arr)-1)):
        failed("Wrong Answer!")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="7" />
                <option name="name" value="Binary Search" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه Binary Search را مطالعه کنید.

انتخاب واحد به پایان رسیده‌است و واحد‌های بعضی دانشجویان بسیار کم است. به همین دلیل معاون آموزشی تصمیم گرفته‌است که از
تعداد واحدهای دانشجویانی که تعداد واحدهایشان زیاد است بکاهد و به دانشجویانی که تعداد واحد کمی دارند بیفزاید.

دانشکده‌ی
مهندسی کامپیوتر n دانشجو با تعداد واحدهای $$a_1, a_2, ..., a_n$$ دارد.

معاون آموزشی هر روز از دانشجویی که بیشترین تعداد
واحدها را دارد یکی کم می‌کند و به دانشجویی که کم‌ترین تعداد واحدها را دارد یکی اضافه می‌کند(اگر چند نفر با خصوصیات فوق
وجود داشته باشند، یکی را به صورت تصادفی انتخاب می‌کند). بدیهی است که اگر کم کردن واحد از یک دانشجو باعث شود به
کم‌واحدترین دانشجو تبدیل شود، این کار را انجام نمی‌دهد.

برنامه‌ی واحدها k روز دیگر بسته می‌شود. حال وظیفه‌ی شماست که اختلاف تعداد واحدهای دانشجوی با بیش‌ترین تعداد واحد و
دانشجوی با کم‌ترین واحد را پس از k روز به‌دست بیاورید.

محدودیت‌ها:

    $$ 1 \le n \le 10000 $$
    $$ 1 \le a_i \le 100000 $$
    $$ 1 \le k \le 100000000 $$

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="24" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="24" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="a = sorted(a)

    # First Let's find smallest possible maximum for k days
    def is_max_ok(mx):
        tmp = 0
        for val in a:
            if val > mx:
                tmp += val - mx
        return tmp <= k

    max_lo = a[0]
    max_hi = a[-1]

    while max_hi - max_lo > 1:
        mid = int((max_hi + max_lo) / 2)
        if is_max_ok(mid):
            max_hi = mid
        else:
            max_lo = mid

    if is_max_ok(max_lo):
        ans_max = max_lo
    else:
        ans_max = max_hi

    # Now, Let's find greatest possible minimum for k days

    def is_min_ok(mn):
        tmp = 0
        for val in a:
            if val < mn:
                tmp += mn - val
        return tmp <= k

    min_lo = a[0]
    min_hi = a[-1]

    while min_hi - min_lo > 1:
        mid = int((min_hi + min_lo) / 2)
        if is_min_ok(mid):
            min_lo = mid
        else:
            min_hi = mid

    if is_min_ok(min_hi):
        ans_min = min_hi
    else:
        ans_min = min_lo

    if ans_min >= ans_max:
        if sum(a) % n != 0:  # We can only achieve it iff sum is divisible by 0
            return 1
        else:
            return 0
    else:
        return ans_max - ans_min" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def solve(n, k, a):
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="testcases.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="testcases.py" />
                                <option name="text" value="tests = [
    [0, 3, 1, [2, 2, 2]],
    [1, 4, 100, [1, 1, 10, 10]],
    [1, 10, 20, [6, 4, 7, 10, 4, 5, 5, 3, 7, 10]],
    [7, 100, 20, [2, 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]],
    [80333, 10, 1000000, [307196, 650096, 355966, 710719, 99165, 959865, 500346, 677478, 614586, 6538]],
    [909357107, 5, 1000000, [145119584, 42061308, 953418415, 717474449, 57984109]],
    [8, 111, 10, [2, 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]],
    [9838, 10000, 4000, [9583, 3539, 1944, 6975, 68, 1663, 2856, 1523, 9764, 2388, 5845, 6161, 9947, 7737, 609, 8541, 6533, 6477, 9750, 2946, 3192, 816, 5459, 7052, 5991, 7544, 2246, 6190, 8988, 323, 3079, 4171, 2677, 505, 9729, 7056, 1608, 5489, 1460, 9178, 8323, 5383, 7731, 4880, 6313, 1910, 4400, 81, 3225, 4713, 35, 1456, 5004, 4806, 6253, 7227, 4328, 471, 2294, 4916, 7174, 8191, 1737, 9194, 6612, 7303, 2014, 5436, 2869, 8915, 5763, 9779, 3634, 6070, 8269, 3411, 3575, 7594, 3633, 7031, 4627, 3468, 3328, 7067, 5356, 4106, 1887, 7700, 7062, 2114, 5174, 8297, 4160, 3830, 3049, 5925, 9136, 9135, 2183, 6870, 5513, 6186, 2308, 8389, 4427, 1411, 9113, 3199, 8343, 2853, 9971, 1827, 4772, 8112, 867, 2378, 1155, 845, 5140, 4403, 1817, 6355, 8072, 3490, 2, 7538, 4273, 4721, 7056, 2983, 6884, 8683, 1623, 1876, 2084, 9908, 3259, 3617, 1999, 6437, 5239, 5292, 2823, 9761, 8978, 7536, 8082, 6058, 3494, 9589, 2028, 4289, 8632, 3831, 4237, 5376, 3330, 9607, 2926, 525, 9103, 995, 3673, 8808, 7655, 4925, 2285, 2938, 3206, 9146, 4935, 9273, 9153, 5771, 309, 4743, 9936, 4491, 3030, 6206, 1825, 4133, 6394, 1435, 2311, 544, 567, 7898, 2966, 1938, 2074, 3904, 1385, 6947, 3433, 1640, 1508, 7035, 7553, 8877, 2469, 5891, 230, 5690, 4726, 6255, 2349, 1685, 351, 6609, 3637, 739, 7747, 3552, 2036, 6818, 5372, 1168, 9460, 1500, 8779, 5332, 884, 9959, 4819, 8183, 1309, 6197, 3038, 6022, 5819, 3054, 3732, 6934, 4116, 8330, 979, 5519, 3063, 3129, 221, 9740, 5137, 5859, 6334, 1125, 5650, 2915, 66, 5456, 9628, 8285, 4427, 9223, 9169, 3363, 1853, 1245, 32, 4336, 1795, 7811, 7444, 3668, 9210, 9423, 9054, 1397, 5147, 3868, 4752, 2407, 6679, 7867, 1719, 981, 8210, 4603, 7189, 8824, 9982, 2405, 680, 2701, 3276, 2777, 7595, 652, 1285, 6730, 2084, 476, 4635, 1116, 5380, 2000, 6404, 4137, 1683, 8227, 3946, 1580, 5224, 9800, 581, 9787, 2484, 3176, 515, 4456, 597, 4573, 7117, 5034, 1289, 4991, 3456, 8617, 810, 7805, 4149, 8545, 9284, 5065, 5410, 625, 8996, 5708, 3677, 8961, 7319, 4542, 3066, 9630, 8786, 6533, 6767, 8163, 6117, 855, 1387, 2140, 7080, 6458, 6727, 9457, 5020, 1163, 7258, 7175, 7311, 2359, 7651, 182, 2985, 5981, 2116, 8400, 4234, 750, 4354, 8312, 9354, 4086, 7629, 2190, 9885, 6698, 1953, 1407, 6901, 1488, 2491, 846, 2145, 7646, 9967, 5936, 2755, 6146, 7336, 1265, 6589, 6547, 5350, 2297, 3871, 7619, 7043, 8831, 2603, 2342, 997, 3183, 1485, 4788, 1417, 4252, 6951, 4104, 2741, 1769, 7116, 1472, 3156, 556, 1186, 9881, 9382, 8190, 7545, 8404, 1434, 5169, 8802, 8939, 926, 1891, 2542, 6586, 2393, 1765, 9808, 868, 5552, 4104, 4555, 2795, 6647, 9864, 4695, 5445, 1826, 5629, 6446, 1825, 272, 7056, 6839, 7604, 2429, 6673, 614, 2565, 8973, 6541, 1764, 2662, 1147, 897, 928, 7227, 3396, 9461, 9499, 3574, 7183, 7641, 6485, 8099, 2465, 9510, 1968, 7927, 2434, 5053, 9030, 1387, 1646, 687, 8938, 6875, 5612, 4561, 5385, 3616, 4232, 5397, 1409, 2502, 963, 9651, 5234, 9627, 786, 9022, 630, 2281, 204, 8495, 3051, 2502, 9917, 764, 6669, 2558, 7222, 9441, 8989, 9696, 3287, 8433, 8919, 779, 1177, 6297, 4529, 3953, 4536, 5572, 204, 1462, 3409, 334, 4725, 3348, 6480, 4635, 328, 6682, 8470, 5816, 6696, 3574, 7331, 1575, 7753, 5274, 4004, 3186, 9528, 2719, 232, 5063, 9179, 5275, 7000, 6283, 775, 4793, 3637, 2321, 8847, 8726, 3018, 3889, 505, 6974, 5206, 2500, 1740, 5456, 9335, 9068, 433, 9192, 7409, 4792, 4986, 9197, 5343, 9707, 4661, 1120, 2249, 6599, 5137, 7447, 9644, 8261, 8627, 4618, 6216, 4536, 4408, 414, 9147, 9932, 3021, 2913, 50, 6022, 4201, 6371, 957, 117, 7495, 8667, 8458, 3595, 1194, 8184, 2545, 2194, 7418, 3615, 6823, 2467, 3219, 5282, 4993, 3529, 650, 4247, 6789, 271, 9087, 6200, 4606, 3067, 2178, 9719, 7753, 8228, 5314, 3186, 9516, 7247, 8676, 7276, 1679, 6116, 3051, 7335, 9414, 7217, 5965, 2957, 4786, 1465, 6529, 5654, 4420, 1579, 9184, 9311, 3989, 1901, 4719, 2670, 9655, 2687, 88, 573, 1053, 5562, 2272, 9944, 897, 8708, 7407, 7260, 1296, 5180, 7462, 9914, 5590, 3179, 1592, 7328, 4598, 1071, 5356, 2733, 7941, 117, 2409, 9057, 2405, 6555, 2683, 4483, 8169, 985, 3010, 1101, 5659, 7573, 5737, 853, 8530, 8862, 3876, 6427, 3281, 9872, 6197, 5858, 9797, 3120, 5704, 8774, 779, 9504, 3019, 5416, 5779, 4209, 4330, 3796, 4666, 1169, 8039, 5545, 2368, 6480, 1833, 8631, 4174, 9895, 6353, 9064, 8091, 1253, 3674, 3640, 6445, 9578, 5978, 7959, 2727, 6641, 5223, 3942, 9151, 4691, 1259, 6654, 1299, 6979, 5343, 5079, 5472, 8665, 5110, 187, 2719, 1963, 1492, 5388, 5309, 3991, 6568, 450, 9855, 5368, 5912, 6122, 5854, 7078, 865, 9591, 1663, 7802, 978, 1662, 2611, 2939, 3252, 4976, 3447, 3233, 9868, 2057, 8930, 6913, 6932, 899, 714, 7049, 4997, 8202, 5564, 6317, 5669, 6689, 4574, 6910, 3758, 7435, 428, 9902, 7200, 531, 381, 7196, 6965, 5555, 2448, 6182, 4026, 850, 2530, 9908, 4757, 1157, 4259, 4648, 8479, 4136, 8111, 5561, 7090, 2952, 2286, 1517, 7953, 8559, 7472, 5576, 4897, 7765, 9541, 5238, 4963, 8525, 3815, 7232, 6956, 4979, 9033, 3576, 5520, 4211, 3107, 1774, 2188, 1057, 3743, 9979, 3054, 9410, 9862, 7568, 5391, 8437, 9941, 344, 4022, 4946, 278, 368, 7023, 3831, 8794, 3656, 5516, 1906, 7773, 8334, 2066, 5510, 8299, 236, 2601, 6560, 2257, 7818, 7614, 4879, 6436, 5026, 7976, 4790, 4950, 5156, 9221, 5167, 5520, 6593, 1699, 921, 9170, 7824, 5161, 2818, 5095, 3549, 2120, 8154, 3935, 7277, 7998, 8360, 8721, 9460, 8003, 5328, 9114, 7225, 5548, 1040, 4077, 8192, 5634, 2177, 1079, 9651, 5100, 3184, 2673, 5476, 4712, 3267, 4305, 6651, 325, 5173, 298, 6716, 4750, 8876, 4614, 6620, 8581, 2386, 6515, 2916, 326, 4743, 3276, 1451, 5133, 2767, 5454, 9047, 6513, 6962, 1070, 2652, 36, 7992, 8078, 9808, 809, 7113, 1826, 6599, 105, 7432, 666, 1064, 8123, 4993, 9362, 857, 6989, 695, 3771, 5083, 1156, 5620, 4525, 2268, 3173, 4826, 8374, 1008, 8653, 532, 4473, 2793, 2486, 4114, 1241, 9046, 7734, 138, 6513, 806, 5153, 4718, 299, 30, 5255, 8817, 8320, 4726, 1496, 3409, 2548, 5210, 9622, 1341, 767, 210, 3410, 9147, 4949, 1432, 7072, 8687, 8856, 6732, 2414, 9280, 4812, 4555, 2620, 6233, 9297, 8103, 7027, 9317, 5964, 4598, 6722, 4183, 7748, 1834, 8646, 7135, 7817, 3349, 4865, 3689, 8947, 6291, 8303, 811, 906, 8635, 8783, 1936, 2582, 3842, 1519, 2418, 7797, 9766, 5052, 1246, 225, 6112, 9381, 434, 7721, 5277, 5538, 7900, 9441, 6130, 1236, 1896, 7940, 554, 8937, 3496, 2810, 7770, 7220, 6986, 5500, 6688, 3787, 3445, 7023, 2732, 9500, 5200, 3281, 7573, 1472, 442, 4371, 1163, 1947, 7832, 4519, 5232, 3181, 8572, 7799, 1417, 3085, 8329, 9064, 4913, 8210, 6490, 8629, 2857, 5867, 7955, 6706, 945, 7376, 6258, 2666, 5580, 949, 8769, 8876, 2959, 9929, 5634, 9434, 1233, 9512, 8284, 7842, 1638, 3458, 7121, 8774, 6379, 6837, 8121, 8152, 3359, 2658, 3363, 5453, 157, 1495, 6735, 4510, 2049, 6386, 2416, 8730, 3625, 1619, 4488, 1, 428, 4873, 3013, 6776, 3395, 4541, 6518, 2371, 7778, 1916, 8345, 1255, 3185, 2993, 9161, 9036, 8330, 2219, 8601, 1845, 6193, 4188, 7774, 8339, 2962, 6327, 8656, 1358, 3403, 9091, 3304, 5452, 6157, 4441, 3751, 3602, 7538, 3804, 4965, 9362, 8936, 6417, 3722, 2229, 529, 435, 717, 5833, 2277, 3527, 4633, 6062, 9091, 823, 5085, 7764, 2460, 987, 9904, 5727, 7041, 8141, 3520, 868, 8882, 1088, 8411, 5452, 8177, 9697, 9973, 9226, 1135, 1480, 800, 2826, 2137, 7738, 8816, 5587, 9014, 881, 315, 293, 8759, 1555, 4240, 3812, 6174, 6996, 1597, 7610, 8560, 6641, 9214, 1708, 8318, 8583, 8288, 8809, 7265, 4943, 8360, 457, 5018, 4384, 2052, 7154, 9131, 5102, 7651, 1790, 678, 5667, 7387, 146, 3773, 1300, 8892, 3260, 4682, 9019, 6677, 1441, 179, 2049, 3051, 1631, 1064, 3329, 8257, 7414, 4231, 6915, 5166, 2799, 175, 3312, 1599, 4121, 561, 6449, 1059, 9564, 4684, 1601, 1012, 4072, 347, 924, 1861, 8564, 4311, 9900, 6531, 5917, 8332, 925, 9123, 5733, 1631, 9048, 6956, 8113, 9751, 7325, 8537, 5487, 2835, 9240, 5877, 3411, 9545, 8627, 6487, 9660, 3512, 6390, 1230, 1405, 7433, 1429, 4646, 3823, 4434, 5657, 3291, 6424, 9037, 2521, 4505, 5458, 9294, 3370, 941, 3946, 7022, 7556, 9228, 8006, 2455, 1040, 5880, 654, 7658, 5799, 4484, 5787, 365, 4842, 5660, 3619, 1175, 871, 866, 3269, 5246, 6837, 512, 6065, 414, 7835, 9317, 253, 1074, 9602, 9472, 5790, 7011, 8855, 9641, 6416, 4170, 6592, 4445, 612, 9481, 4563, 3929, 498, 5679, 5085, 2182, 3191, 942, 9927, 1545, 5775, 672, 1993, 4836, 3371, 6897, 9218, 1578, 9478, 9701, 8024, 5849, 820, 7045, 3762, 6815, 1689, 1066, 4262, 6936, 1231, 1994, 7088, 9692, 360, 939, 327, 9666, 9486, 5019, 3510, 9532, 6774, 6331, 2314, 9663, 3750, 4987, 9819, 3443, 4252, 3110, 125, 5974, 4491, 9855, 7605, 8835, 742, 3962, 4083, 975, 9561, 8442, 2245, 3837, 3509, 7483, 4738, 7818, 7646, 2746, 3226, 3135, 6470, 8510, 5148, 2542, 6934, 1455, 7173, 8391, 2544, 3907, 914, 4709, 6349, 3856, 3989, 1652, 1204, 2772, 5537, 6547, 7094, 6988, 973, 9124, 4408, 9427, 9663, 6749, 1239, 4145, 2709, 974, 501, 5609, 6554, 745, 7016, 5918, 8822, 4800, 9475, 5181, 8245, 7108, 7413, 630, 122, 685, 6083, 3868, 7760, 9909, 9335, 3904, 4405, 9333, 3544, 3656, 3239, 7, 681, 1750, 7823, 6031, 6383, 5917, 2679, 9482, 6490, 5883, 7327, 7131, 1862, 7104, 3619, 2336, 1332, 1494, 9019, 6572, 11, 5179, 2418, 9849, 2072, 3018, 1388, 3202, 5606, 4206, 4360, 5196, 1216, 4105, 1180, 4122, 558, 704, 5731, 3338, 2409, 9756, 4852, 3413, 8247, 1628, 3825, 6690, 2575, 4668, 149, 9567, 2399, 9201, 827, 6818, 6225, 9813, 3824, 3365, 1085, 1120, 8451, 8180, 1446, 3649, 4565, 9463, 9542, 5393, 4968, 1117, 59, 7077, 7631, 6843, 396, 1470, 9753, 1206, 8082, 9717, 6228, 6816, 9584, 3145, 5255, 1246, 9514, 2132, 1798, 7197, 5416, 2858, 3226, 3972, 1103, 387, 7309, 3279, 8857, 605, 597, 4298, 188, 6929, 1624, 2219, 4048, 3903, 47, 4221, 8829, 8045, 8598, 3057, 6308, 2624, 4752, 6587, 6799, 4173, 30, 6424, 7108, 1999, 230, 3796, 4469, 5431, 3090, 3093, 1642, 1760, 250, 6707, 9601, 7341, 3651, 2492, 1379, 9522, 3695, 8600, 5977, 1219, 6503, 6629, 5993, 8214, 9159, 1854, 3822, 9434, 8542, 9997, 2046, 6943, 8590, 6705, 3216, 6385, 5718, 5571, 3770, 6163, 6267, 8748, 4973, 2889, 7439, 7000, 4570, 5552, 8586, 2787, 1518, 7213, 1256, 5184, 6972, 4194, 7331, 2010, 4458, 9686, 5984, 7398, 8991, 3192, 8187, 49, 9679, 9760, 5949, 3492, 7407, 8028, 7008, 7304, 1732, 7203, 3091, 3742, 8616, 8909, 6452, 9174, 4384, 3611, 2783, 4298, 5516, 7060, 8159, 3119, 2884, 9289, 1387, 7910, 9390, 1938, 5482, 5418, 7470, 6276, 2465, 2892, 5030, 606, 1486, 8554, 8589, 3493, 1195, 4354, 5200, 7224, 5843, 2731, 3507, 268, 9023, 8019, 8340, 6125, 1987, 4155, 4299, 4627, 2368, 619, 455, 1182, 8437, 8070, 5513, 823, 256, 7976, 1534, 5641, 2303, 2215, 9716, 9371, 7091, 7669, 7358, 5535, 8704, 5964, 1349, 3136, 9112, 9284, 3453, 7862, 2279, 8287, 2454, 2274, 7477, 494, 7304, 9778, 6293, 2715, 9745, 4972, 3360, 3, 2983, 653, 3403, 8355, 5185, 4981, 9946, 7902, 6114, 86, 7988, 9961, 4163, 8474, 9493, 4070, 1646, 2124, 3836, 4442, 2142, 9344, 8282, 8936, 8820, 7076, 9455, 4274, 8945, 9377, 929, 4039, 5449, 8471, 8021, 4327, 7014, 5737, 8836, 1337, 163, 8603, 513, 8958, 9319, 7628, 5691, 4968, 6098, 5558, 3326, 3244, 4177, 1494, 8775, 2877, 5986, 8504, 6427, 1857, 6888, 8073, 2310, 8079, 6960, 5976, 3479, 4981, 8082, 1100, 3598, 6500, 5319, 8473, 6998, 6330, 2934, 7186, 3040, 195, 5904, 3310, 2846, 4215, 2211, 869, 4145, 8128, 759, 238, 1645, 6309, 8914, 4124, 4765, 6870, 729, 3771, 547, 95, 987, 996, 6154, 4825, 7666, 4595, 5754, 8007, 2223, 4740, 469, 6482, 90, 1298, 3882, 4093, 710, 7549, 8149, 8354, 7296, 6425, 4929, 3725, 2373, 8387, 5887, 1503, 5451, 2109, 9623, 8779, 496, 9659, 1480, 4952, 585, 8688, 521, 8953, 7306, 5161, 2278, 3141, 5228, 9353, 8521, 761, 2999, 1235, 65, 3926, 5977, 9587, 4064, 1115, 3024, 4953, 8968, 7187, 3566, 6283, 8409, 9041, 8081, 4275, 5157, 9942, 3669, 4889, 3993, 4560, 3743, 1763, 9067, 175, 9815, 8674, 2554, 721, 4683, 756, 5173, 6651, 3870, 693, 9735, 1717, 8865, 2342, 5436, 1930, 2073, 8580, 1505, 5716, 8169, 5397, 1945, 8562, 9969, 2878, 871, 645, 5871, 5499, 9114, 148, 7744, 1164, 4345, 8026, 3072, 382, 8628, 9862, 4936, 7512, 7133, 1379, 414, 3955, 5144, 9884, 1992, 4050, 8901, 487, 9992, 4867, 6142, 1332, 241, 9779, 2473, 6518, 7423, 5203, 3345, 6588, 258, 14, 4560, 1118, 3173, 2734, 2719, 961, 5998, 8680, 7073, 3042, 2889, 3283, 9082, 1635, 7602, 633, 2305, 2141, 4422, 1296, 1034, 5901, 6482, 5023, 9649, 7296, 5024, 9470, 507, 9759, 7553, 1365, 8828, 8011, 3397, 2583, 4455, 3769, 5071, 9444, 1043, 9034, 6693, 4990, 7998, 5738, 5136, 5246, 4659, 8121, 9529, 6643, 1003, 501, 2436, 4184, 5853, 1226, 2838, 7990, 7851, 171, 6905, 4566, 3935, 3873, 915, 3110, 6746, 6633, 8248, 6267, 6204, 6808, 1759, 3287, 5956, 5181, 9436, 2828, 9094, 8261, 1142, 1651, 2522, 1464, 1861, 8622, 2437, 9520, 9996, 3664, 2113, 7856, 4527, 9655, 227, 7078, 7419, 9456, 1817, 7863, 2834, 7843, 3873, 4471, 4576, 2530, 5205, 6790, 949, 1647, 2650, 9169, 2557, 2316, 7496, 7088, 4826, 2897, 452, 8338, 9324, 5361, 9404, 1444, 2876, 8938, 8235, 203, 6716, 9285, 3788, 7919, 2250, 8498, 4137, 6402, 9639, 3875, 104, 2497, 237, 1876, 2208, 508, 6182, 3222, 7972, 4882, 6478, 5550, 6548, 5256, 6461, 1312, 5914, 4255, 9354, 6107, 6390, 4297, 9641, 4700, 6222, 2443, 6453, 7251, 8109, 7733, 7814, 7815, 3593, 8834, 6365, 3928, 5550, 4041, 1095, 7772, 1825, 4609, 7593, 7032, 3535, 3516, 8769, 9626, 800, 7431, 440, 9528, 4357, 9635, 8706, 3237, 2735, 8235, 175, 9839, 6000, 534, 3584, 5976, 8373, 2833, 753, 7062, 7187, 5346, 9432, 4989, 8769, 4504, 3498, 8404, 8066, 4238, 1928, 5741, 7460, 8622, 1300, 6930, 7677, 3462, 2780, 8210, 7047, 7060, 3325, 4995, 526, 6665, 3196, 5020, 5670, 4281, 3472, 9723, 2967, 190, 6085, 2805, 5179, 3968, 8615, 4919, 9057, 6971, 5348, 6516, 3076, 1407, 1013, 2046, 1715, 317, 8551, 2442, 4420, 3065, 1772, 8907, 1095, 35, 3654, 9715, 1421, 4476, 2782, 7482, 2324, 1870, 2757, 6746, 7908, 3679, 4275, 1186, 7285, 4022, 9223, 2199, 8470, 6030, 9655, 8015, 3315, 3390, 8750, 5150, 4833, 3485, 9048, 6989, 3007, 4494, 8976, 7907, 5148, 2133, 8450, 8496, 9233, 6925, 5789, 9458, 7639, 8657, 4470, 5773, 4639, 9383, 7080, 8822, 8100, 6530, 9289, 4731, 4817, 351, 7523, 7641, 9860, 2060, 2156, 6145, 8996, 1128, 9672, 3135, 7807, 5450, 185, 2605, 4671, 138, 7623, 2582, 9694, 1359, 3278, 3586, 7079, 9592, 353, 8814, 3435, 5896, 598, 4533, 8924, 9316, 8970, 1047, 7073, 3633, 6698, 4190, 1784, 2480, 4940, 8617, 5929, 9882, 4794, 3218, 7882, 3536, 5739, 9781, 1381, 8338, 9792, 9092, 1470, 4576, 291, 9944, 3549, 2172, 6354, 4196, 9479, 4670, 7464, 3072, 4098, 6877, 3544, 6822, 9293, 6187, 8457, 7668, 3770, 7780, 2051, 5979, 6628, 4908, 986, 2861, 2259, 4523, 5629, 5168, 6063, 7987, 6263, 3232, 1070, 6280, 5456, 514, 260, 2642, 8203, 3329, 4575, 2431, 3420, 9191, 7889, 9835, 1374, 8227, 1745, 8747, 2890, 3568, 9099, 4453, 9002, 5040, 6068, 7152, 5827, 6121, 7402, 7616, 7424, 1950, 7549, 222, 1724, 5418, 6624, 6005, 2175, 7686, 6569, 9993, 8668, 1960, 2164, 1550, 7897, 1036, 7326, 1241, 3940, 3374, 4497, 500, 6374, 9858, 6836, 7502, 6403, 6535, 7062, 2997, 6713, 4735, 6258, 211, 5998, 132, 7710, 2782, 8374, 8055, 7553, 5889, 9979, 214, 7722, 8620, 1082, 9786, 8162, 7605, 2438, 611, 4008, 7238, 8824, 3658, 1720, 4088, 2810, 8064, 3941, 903, 7158, 5965, 4697, 6056, 8640, 7724, 9303, 9856, 3019, 5448, 3145, 9072, 9093, 7021, 7435, 3529, 2560, 6363, 2571, 1511, 3363, 2550, 1539, 3909, 6884, 2146, 2578, 6305, 2502, 3493, 2469, 1210, 7921, 1953, 6473, 615, 3196, 2540, 7812, 2528, 6158, 7284, 1272, 4259, 6993, 4448, 3089, 4545, 3898, 2295, 4994, 2730, 1653, 748, 2029, 7771, 5239, 2932, 3655, 8567, 9477, 9998, 3004, 6401, 9672, 2104, 5669, 997, 6715, 2407, 9859, 2239, 9752, 9315, 8898, 663, 5139, 4836, 8572, 859, 8685, 6090, 1339, 3458, 8377, 8378, 315, 3470, 8986, 8426, 6780, 2302, 1083, 9257, 206, 8973, 9911, 9611, 5504, 4398, 2931, 590, 3577, 4277, 1551, 7494, 5727, 2917, 416, 3367, 2941, 5731, 3803, 5693, 8437, 3201, 3681, 4172, 8238, 1297, 7718, 7054, 2166, 8493, 2866, 7229, 5399, 6494, 5384, 8523, 6950, 2172, 3699, 2582, 4732, 3730, 462, 295, 4082, 76, 6829, 1287, 7807, 929, 9766, 3043, 8485, 4217, 8802, 5386, 916, 9505, 8586, 6298, 7949, 235, 3276, 3903, 8987, 5566, 7645, 3516, 2068, 9409, 3525, 8209, 41, 425, 1037, 5351, 6767, 1624, 7507, 5289, 9893, 6459, 5607, 7912, 1224, 863, 412, 8648, 9681, 6225, 6070, 293, 8816, 372, 7877, 5076, 4715, 4423, 6985, 9637, 9511, 7361, 5117, 8745, 5336, 5276, 427, 179, 7927, 3876, 5737, 4908, 2345, 1269, 8723, 6486, 5222, 3728, 3600, 2969, 6010, 3058, 3226, 2766, 8932, 54, 1383, 8646, 6753, 6637, 1656, 2694, 6266, 829, 9828, 7545, 7918, 9637, 4928, 2219, 4735, 1864, 6794, 839, 5509, 3553, 5274, 9182, 573, 7317, 7088, 5586, 6209, 7170, 1166, 1258, 853, 2063, 4274, 6227, 7192, 9743, 948, 1520, 3664, 9797, 1317, 5220, 6568, 9065, 79, 5215, 6111, 5330, 4283, 2561, 725, 4967, 1986, 4198, 5013, 5668, 4290, 9885, 6647, 4628, 3552, 4962, 7761, 3339, 5433, 3653, 346, 3693, 1948, 9372, 6108, 3033, 4454, 5497, 7242, 2910, 9871, 5848, 2941, 9777, 8433, 6985, 3628, 4726, 5901, 4987, 7042, 6237, 7122, 252, 7686, 8208, 2281, 1129, 9888, 1147, 7294, 8739, 6176, 4449, 3898, 3153, 1919, 3514, 8425, 5353, 7081, 9290, 2732, 8312, 1368, 4327, 6809, 1167, 7151, 2682, 8947, 9040, 8802, 88, 9301, 5389, 9972, 966, 7134, 5230, 9092, 387, 8789, 8435, 1555, 9298, 7529, 8856, 6829, 8065, 5142, 8257, 1468, 9344, 1587, 5974, 4189, 367, 5667, 93, 6580, 4982, 9511, 4466, 4706, 7743, 7124, 9789, 3476, 4147, 9796, 810, 2371, 5474, 2782, 7533, 2735, 5985, 8948, 2331, 180, 6659, 9291, 27, 9962, 2104, 6781, 6085, 9873, 1975, 6247, 9547, 7578, 5478, 7790, 4302, 6288, 7178, 9597, 3381, 5574, 300, 1958, 8362, 1962, 1171, 3154, 4329, 4617, 4258, 4339, 2369, 9142, 7628, 7533, 5564, 2420, 1797, 1204, 3108, 1397, 541, 8450, 720, 2134, 5555, 8429, 3599, 77, 4343, 1155, 6572, 9239, 4257, 2266, 9223, 993, 396, 6998, 2263, 1455, 2021, 478, 7754, 1596, 1384, 4377, 8974, 7697, 4455, 1749, 2442, 8628, 9214, 1739, 3011, 7151, 4347, 8046, 340, 6995, 2895, 7759, 3475, 4823, 8512, 4688, 6572, 6307, 6676, 6005, 4665, 7877, 4963, 9315, 4397, 646, 7962, 128, 5928, 6329, 862, 9813, 2195, 3186, 2229, 7719, 4124, 8377, 248, 1144, 9350, 7648, 25, 1455, 8861, 2409, 6536, 8427, 3326, 831, 9281, 7782, 7419, 1520, 6275, 8126, 9935, 6967, 4664, 4041, 9702, 9627, 6666, 7795, 6942, 2809, 6134, 1141, 6957, 7603, 7636, 8181, 3502, 9660, 7827, 2832, 4461, 5556, 4287, 2224, 2779, 9052, 4443, 7900, 5365, 3057, 7849, 9148, 4424, 3959, 4094, 5885, 7230, 8032, 1456, 2909, 1659, 1945, 2322, 9858, 2695, 8789, 7504, 8215, 3610, 8269, 7241, 7297, 104, 7563, 4989, 6871, 3491, 6003, 8880, 739, 5109, 794, 3716, 7057, 802, 9813, 4643, 8455, 9194, 1082, 6307, 2360, 9363, 9332, 3798, 5186, 3003, 7590, 4024, 7547, 2187, 8718, 8553, 4986, 818, 3058, 3069, 1901, 5033, 4517, 2661, 1376, 9896, 4262, 7143, 1338, 5088, 1849, 7301, 7112, 6717, 5306, 9130, 3608, 2982, 9782, 6994, 6897, 9604, 1076, 6109, 4044, 2796, 2832, 1665, 1287, 7337, 2455, 870, 4977, 3530, 3084, 9475, 7252, 4601, 2009, 9212, 9156, 2042, 5711, 3909, 2113, 8222, 6288, 383, 3526, 2587, 2232, 5496, 4132, 6179, 3702, 423, 9905, 5235, 9633, 1972, 8953, 9786, 5604, 7608, 8367, 2862, 9651, 8933, 8596, 4631, 6266, 9700, 9842, 7474, 8884, 5199, 9937, 5137, 3071, 3626, 5272, 9999, 7654, 9351, 8080, 6672, 4100, 8810, 8290, 5102, 1860, 1330, 111, 692, 931, 3929, 6445, 3380, 2688, 1524, 6431, 1408, 8964, 3075, 2307, 1948, 2126, 4304, 5662, 3008, 4675, 3575, 8908, 6711, 8021, 155, 3051, 1908, 9075, 4757, 3615, 2056, 5263, 3650, 1730, 6905, 6859, 8517, 250, 5797, 5875, 9901, 1977, 2571, 9581, 240, 8343, 4584, 4836, 4175, 3454, 4585, 1279, 5954, 7899, 857, 9077, 4595, 1718, 5255, 1767, 2985, 7335, 7088, 6796, 1826, 7077, 5521, 8635, 421, 5581, 3688, 5577, 679, 3228, 3104, 1988, 7383, 2709, 4628, 6156, 7811, 8824, 7794, 1755, 1234, 1921, 2845, 5775, 8595, 4528, 3289, 2123, 6538, 6268, 4664, 1607, 251, 2592, 9771, 3318, 5072, 7899, 9427, 8560, 3849, 5847, 3066, 9760, 1079, 3317, 4582, 4400, 2978, 1509, 2401, 902, 4978, 9617, 2767, 1590, 7550, 696, 586, 6127, 6815, 4842, 9056, 3927, 4723, 9735, 9996, 7642, 5931, 1204, 6264, 8069, 9945, 2653, 8455, 2896, 4057, 100, 5969, 3896, 5711, 2971, 4678, 3843, 8938, 3802, 8264, 3409, 7789, 4106, 9221, 9835, 2698, 4063, 8685, 7591, 9670, 5745, 3412, 6877, 3141, 8987, 7094, 9720, 8536, 8835, 528, 9437, 2136, 5992, 1835, 8432, 9301, 6137, 2008, 2209, 2491, 9135, 8488, 8420, 9478, 8274, 8534, 5995, 425, 779, 8721, 444, 5506, 578, 4181, 8377, 6376, 7133, 2835, 1114, 3099, 7336, 3924, 6902, 2164, 6301, 8218, 873, 5619, 7228, 6450, 4823, 8693, 1560, 3596, 6679, 2855, 5038, 2764, 7639, 8101, 5153, 7025, 5381, 1284, 9467, 7658, 1448, 4243, 8673, 16, 6838, 21, 1338, 3661, 8914, 7693, 1249, 5506, 2878, 2690, 2758, 4751, 2376, 2034, 6277, 8561, 3895, 5086, 2491, 8684, 6940, 9786, 9459, 9811, 7295, 5069, 5336, 6286, 6454, 1145, 8722, 9519, 3986, 2277, 4445, 7012, 2686, 3914, 9108, 2863, 1491, 8844, 179, 5621, 9374, 8563, 2408, 3472, 7758, 4785, 2180, 2442, 5178, 1305, 9705, 3111, 3237, 1483, 3772, 3077, 141, 6807, 5101, 618, 9497, 7912, 4374, 9510, 2926, 8804, 3011, 1315, 6407, 9828, 5505, 7140, 3599, 2699, 471, 507, 496, 9265, 3888, 8858, 2209, 9936, 6422, 5530, 9692, 3532, 4185, 3280, 5824, 5371, 8786, 5987, 75, 7738, 6620, 2614, 2856, 2367, 4540, 6764, 3403, 5629, 7520, 2659, 3421, 1937, 4293, 1902, 4236, 9940, 3750, 1728, 7660, 4172, 7543, 1559, 3964, 2115, 2060, 5886, 2259, 1692, 3032, 570, 6044, 2995, 6491, 2947, 7685, 349, 9079, 9493, 656, 9128, 5690, 9698, 1513, 3885, 7346, 542, 106, 6698, 5905, 779, 2877, 1548, 821, 9388, 6375, 6271, 6869, 122, 465, 7395, 6235, 9326, 9882, 5902, 9600, 6995, 9712, 2828, 5355, 7096, 3550, 553, 1689, 5052, 6681, 5842, 3756, 7014, 1845, 5867, 5138, 6976, 9278, 9503, 505, 1111, 4750, 6481, 7992, 5806, 7553, 9222, 5178, 7863, 3264, 817, 766, 7813, 1032, 621, 3729, 251, 9398, 7279, 5096, 8011, 8996, 7253, 8782, 7837, 2424, 2447, 2575, 9266, 2597, 6063, 7393, 8244, 8384, 2650, 5076, 2968, 5571, 5126, 2128, 1687, 7131, 3753, 8138, 5081, 8067, 3650, 4499, 5333, 2253, 1682, 9776, 7437, 2577, 1242, 7240, 2442, 8181, 9446, 9328, 2236, 9654, 5040, 6232, 1800, 7531, 9806, 5287, 7060, 3010, 5405, 5964, 7340, 6846, 7378, 5487, 8520, 8056, 3390, 3, 6105, 978, 5068, 3636, 6674, 7157, 443, 7127, 7639, 44, 3828, 2245, 3848, 1644, 1750, 8258, 4972, 3551, 3875, 4898, 5417, 2278, 2124, 6492, 848, 439, 2231, 4215, 7212, 1568, 383, 8556, 3129, 3928, 9661, 1455, 5415, 8333, 8172, 3958, 425, 4584, 9576, 5991, 1316, 1307, 6784, 8233, 5092, 8511, 9045, 8546, 4828, 5901, 4934, 7141, 4696, 669, 7511, 9195, 6011, 5926, 9326, 8554, 9707, 7314, 1619, 2231, 1734, 4048, 1420, 9944, 601, 9181, 1040, 8203, 5263, 7558, 1375, 7446, 6908, 4948, 8492, 5576, 3785, 641, 4746, 2339, 1557, 3454, 6057, 9595, 5913, 1938, 3058, 5765, 8820, 8618, 7747, 385, 7244, 8948, 2330, 2377, 4928, 3168, 6841, 4669, 6199, 5482, 8733, 115, 6183, 2758, 4732, 4611, 4427, 8695, 472, 2489, 33, 4486, 8609, 1650, 2019, 3845, 2516, 6648, 8882, 6437, 1106, 6500, 6794, 9992, 2211, 5237, 6672, 5012, 9822, 7931, 6631, 7058, 1570, 3225, 6209, 3362, 1593, 6626, 2034, 7702, 874, 9963, 2940, 2189, 3015, 3261, 6049, 3761, 3676, 3814, 3679, 8672, 4668, 4708, 6055, 2183, 6546, 4386, 1183, 3063, 1785, 765, 6979, 7424, 6875, 9686, 7436, 2617, 4870, 3344, 3900, 413, 2266, 9787, 1564, 3023, 7381, 6328, 541, 8187, 3280, 1719, 8732, 3515, 4679, 5709, 1665, 3594, 9745, 4568, 8779, 3499, 7702, 2552, 4438, 8719, 3339, 6530, 4345, 6890, 5113, 1763, 9447, 2130, 6769, 8520, 6506, 2268, 4631, 5805, 4817, 1378, 6581, 6366, 4065, 7537, 629, 7331, 5185, 7481, 4955, 5430, 4677, 5453, 3952, 1701, 7296, 4165, 6754, 3586, 8620, 8932, 2402, 5042, 2773, 1550, 3759, 1035, 5923, 4699, 9985, 302, 6014, 2988, 4204, 3202, 1297, 1852, 7261, 5941, 5648, 2096, 5121, 6893, 2899, 3416, 9202, 2591, 452, 3049, 5479, 5653, 6615, 6429, 6996, 5694, 3014, 2988, 2528, 4796, 3931, 2915, 3216, 4059, 101, 8520, 3880, 870, 4425, 2810, 9300, 4233, 9139, 1225, 5646, 235, 4036, 3119, 4522, 237, 4229, 2389, 9149, 9214, 6755, 2776, 758, 3925, 5184, 4096, 9268, 2267, 9971, 70, 9588, 3709, 825, 6584, 8955, 4779, 8337, 7928, 5956, 689, 2953, 9668, 4688, 9369, 4661, 9697, 9252, 5369, 5871, 6020, 1524, 470, 1097, 1179, 477, 7842, 1473, 179, 8079, 7512, 7157, 6484, 5028, 4257, 8412, 2808, 34, 2520, 8901, 7340, 2247, 9844, 1931, 4841, 8584, 3659, 6983, 3562, 9264, 6415, 278, 6070, 9219, 1396, 7741, 7589, 9870, 4633, 5477, 8953, 5242, 7169, 2866, 1277, 9434, 8782, 4260, 857, 2779, 3414, 4536, 7595, 6031, 9756, 5157, 2369, 4193, 9890, 7597, 888, 1486, 4051, 8792, 4828, 7366, 211, 1259, 2881, 1288, 432, 3448, 5734, 8115, 1880, 3696, 625, 8897, 295, 6669, 4295, 4788, 5208, 2506, 5432, 9976, 7503, 7849, 5508, 3334, 3889, 6064, 5577, 9045, 4471, 6504, 8241, 2104, 3664, 396, 8314, 6868, 1798, 856, 423, 6707, 4170, 5550, 7776, 6748, 7076, 8341, 695, 6801, 5678, 308, 720, 3149, 180, 4489, 9088, 9003, 7941, 1705, 3582, 4759, 8072, 4623, 9506, 3137, 9416, 7921, 8749, 9293, 7427, 6646, 4236, 77, 9369, 5244, 2410, 9781, 5389, 3510, 4329, 6722, 2915, 4821, 2755, 823, 8091, 6188, 5694, 4403, 7342, 562, 8289, 9428, 1757, 5985, 8772, 3694, 7542, 4598, 9471, 6028, 2603, 181, 9966, 5358, 4248, 7136, 5988, 6218, 1362, 4585, 2334, 1079, 2846, 551, 3996, 5899, 5721, 6841, 7445, 1331, 8327, 9461, 8259, 5341, 7374, 2393, 8124, 1731, 1798, 52, 5279, 7366, 5298, 9990, 7900, 4696, 9271, 311, 7068, 3234, 2203, 2081, 2450, 2290, 1173, 2221, 8404, 424, 6243, 4248, 1697, 8060, 755, 7726, 8331, 3096, 6554, 8330, 2081, 7564, 5596, 1657, 8664, 2542, 9957, 3507, 4213, 8015, 1507, 3792, 650, 2507, 9524, 505, 8269, 8059, 3806, 5561, 9811, 4066, 4499, 3341, 3052, 7374, 5752, 4803, 1688, 420, 8612, 3809, 8242, 1450, 6363, 3194, 737, 23, 740, 1247, 3423, 3397, 8695, 7131, 1595, 1275, 595, 3308, 3014, 8381, 6295, 5990, 3996, 3774, 4332, 9452, 9828, 7598, 1779, 9071, 1995, 8481, 4137, 9359, 4081, 1097, 849, 3275, 5583, 567, 1245, 2784, 9333, 9253, 9671, 3617, 5310, 6101, 3080, 4410, 15, 3609, 7131, 9051, 3179, 8340, 4093, 2433, 4801, 1196, 9106, 523, 7349, 2059, 2353, 4210, 7402, 4121, 2607, 4573, 3692, 9671, 5333, 8564, 3336, 3750, 6033, 6070, 1381, 8454, 8109, 5080, 7894, 5071, 3776, 8758, 5164, 1569, 710, 2739, 4794, 704, 2213, 9815, 6609, 3634, 3300, 8955, 2203, 9980, 2642, 2767, 8914, 7824, 3611, 2392, 9011, 2851, 3587, 3926, 6788, 2759, 7388, 7588, 9409, 7277, 9975, 8350, 5259, 3980, 2019, 7952, 189, 9613, 1553, 4444, 4026, 5308, 5570, 7557, 7095, 5722, 1297, 415, 7520, 9031, 6784, 2001, 583, 7563, 9079, 9393, 80, 5526, 1569, 6352, 2416, 6102, 762, 6306, 3335, 1522, 2395, 8908, 6726, 8618, 6836, 6257, 3898, 9404, 9073, 2651, 2352, 9093, 3483, 9673, 4606, 7032, 9817, 1369, 2287, 9059, 2140, 3041, 3878, 6774, 3171, 1365, 8182, 4599, 3719, 9329, 5247, 2233, 1684, 8207, 950, 1965, 8137, 7508, 3775, 7123, 9920, 8198, 6359, 3442, 1021, 7128, 9111, 6322, 1867, 3962, 2557, 5047, 1450, 9016, 3201, 148, 1902, 5841, 3559, 8515, 1005, 236, 5986, 3849, 2019, 808, 3832, 1633, 3105, 2784, 4682, 6012, 475, 2307, 8384, 1312, 4972, 9227, 3188, 161, 1084, 5625, 8185, 9947, 8538, 6712, 1630, 6938, 9888, 1601, 4654, 5892, 9748, 10, 5660, 7129, 8907, 420, 9522, 6051, 6549, 8011, 2889, 6115, 8634, 4235, 8371, 7478, 9160, 1971, 2897, 4802, 475, 8281, 236, 9037, 2925, 633, 5936, 5378, 4207, 9664, 2081, 1232, 489, 9480, 2144, 1617, 7868, 3644, 4657, 2110, 7520, 3314, 7393, 3054, 9408, 1176, 3064, 3764, 562, 7335, 4989, 1382, 191, 2935, 6082, 2225, 8675, 614, 152, 6754, 6385, 3398, 7155, 9053, 2602, 6616, 7802, 9264, 7443, 248, 2410, 4056, 3542, 58, 5155, 9111, 2911, 1684, 1302, 1195, 6352, 9003, 4602, 1360, 8381, 1542, 4152, 3215, 7084, 8689, 9379, 4001, 237, 4788, 7971, 3078, 9262, 8993, 8277, 4211, 1462, 7794, 6276, 1357, 5520, 7989, 3878, 1091, 2295, 9145, 8260, 6898, 6268, 7704, 3388, 2115, 8203, 6733, 8988, 7308, 2303, 6269, 2270, 7123, 5046, 618, 6473, 4106, 2, 60, 8411, 7741, 7606, 9317, 5518, 3788, 176, 4551, 5906, 4561, 5068, 1543, 7559, 9945, 3276, 2128, 2548, 4086, 7814, 984, 3075, 7378, 5358, 7368, 9080, 1431, 703, 5896, 4280, 3953, 3889, 3245, 2688, 2256, 7751, 8896, 1058, 6214, 2274, 7315, 1330, 6933, 6308, 9037, 3097, 8371, 2778, 5378, 9416, 1138, 4440, 4130, 9823, 7498, 4394, 7293, 8414, 815, 3007, 1580, 9001, 5923, 2258, 4518, 2428, 2900, 8973, 4599, 3064, 6797, 5727, 280, 1512, 9786, 9815, 2581, 8938, 3858, 7936, 9131, 7791, 591, 8837, 5614, 4448, 6539, 6877, 6034, 6840, 4708, 974, 144, 6421, 1160, 2587, 2541, 266, 5846, 6406, 5643, 1351, 954, 3532, 9958, 8719, 5034, 2637, 3219, 6616, 5152, 3622, 8628, 5187, 1172, 7939, 436, 932, 1888, 6258, 6208, 4759, 1576, 550, 2814, 5640, 6496, 826, 8782, 214, 5707, 1327, 2141, 1433, 6566, 3714, 5891, 3799, 4029, 146, 9881, 2591, 8936, 903, 1885, 1026, 6145, 2607, 6924, 823, 3779, 9733, 8341, 27, 8613, 4029, 8076, 977, 8527, 2542, 8440, 3145, 4467, 1064, 8621, 6907, 3941, 312, 6451, 2372, 2359, 4116, 5095, 3621, 3889, 1312, 5727, 6063, 6479, 6465, 8644, 7522, 6175, 5418, 4455, 2004, 4145, 951, 6954, 7730, 5131, 4071, 3293, 3716, 729, 1545, 6261, 2571, 5445, 7710, 6087, 4160, 4299, 6835, 1622, 4403, 4317, 2731, 1186, 4122, 5890, 5044, 2556, 1106, 4565, 89, 9007, 8518, 796, 3533, 7810, 8040, 8759, 5401, 5421, 5788, 3, 9439, 7113, 3239, 3029, 2277, 6045, 2934, 781, 2318, 4112, 1861, 441, 7300, 3253, 5930, 347, 1974, 6103, 6782, 8181, 74, 1040, 1465, 8538, 2707, 3950, 6766, 1828, 2588, 383, 172, 405, 5768, 5523, 6904, 9983, 2728, 5922, 1360, 8799, 2736, 5137, 4492, 6479, 3039, 4540, 1629, 4141, 4921, 607, 4733, 8937, 8106, 8824, 4745, 1719, 8965, 7710, 1257, 4629, 5622, 406, 4525, 1135, 3482, 3555, 2862, 1774, 8465, 1996, 4485, 6540, 7704, 4974, 2903, 8328, 8986, 8756, 8615, 9511, 9762, 4139, 7008, 4072, 5055, 9837, 9535, 8839, 9106, 229, 6172, 1666, 3236, 1071, 4689, 5791, 587, 4111, 4627, 4968, 6790, 1432, 5184, 5348, 6126, 4259, 8326, 5115, 953, 5580, 3654, 9570, 3074, 6208, 8653, 96, 7861, 13, 9369, 2198, 5024, 5528, 5319, 2647, 1397, 5653, 6668, 5605, 7325, 9222, 9710, 4662, 1551, 8262, 6527, 8982, 9073, 3913, 1816, 1870, 816, 503, 5473, 1679, 1313, 4949, 8473, 154, 5498, 2346, 5161, 6874, 2835, 3225, 4687, 6195, 5095, 1309, 7918, 6301, 8789, 8004, 2215, 4018, 5987, 6956, 9951, 3970, 1353, 2714, 3024, 9068, 5471, 1026, 1587, 9691, 6493, 4130, 2637, 7, 6857, 4873, 3125, 7871, 3187, 1642, 1902, 3917, 9204, 3449, 3086, 7281, 7949, 9402, 1217, 365, 3693, 2097, 9919, 3833, 9209, 4470, 1884, 863, 1831, 5854, 2658, 4829, 7465, 1249, 7244, 9359, 1779, 4347, 2514, 4095, 7352, 5703, 2422, 3307, 1074, 1548, 49, 8682, 2969, 1796, 1226, 1884, 1312, 3134, 461, 9766, 8654, 9255, 8367, 2846, 3579, 4611, 7526, 1675, 5554, 8754, 7018, 2521, 9643, 3337, 5480, 5218, 2225, 6429, 8627, 2106, 3575, 3541, 9395, 9770, 6297, 2237, 3088, 1105, 5388, 2608, 2813, 9926, 5048, 5842, 5672, 9064, 3213, 3054, 1238, 9970, 9701, 7617, 11, 1667, 2739, 7701, 2011, 7150, 4500, 2218, 8580, 3623, 9106, 1266, 4032, 6802, 1861, 4884, 1493, 9336, 660, 7019, 5377, 3660, 4767, 8163, 5494, 4514, 2050, 8159, 6355, 4822, 5661, 3344, 4564, 9768, 413, 237, 5372, 6174, 614, 7633, 7929, 5373, 3025, 3402, 1286, 9943, 7388, 4170, 3424, 2914, 594, 7221, 6818, 4192, 9026, 1335, 7374, 9754, 6232, 8948, 2133, 718, 1141, 6087, 367, 4125, 5557, 7338, 7890, 51, 2529, 8165, 2630, 1064, 6678, 6092, 7180, 2785, 1291, 9341, 3679, 1858, 7567, 4509, 4176, 9190, 743, 9018, 7606, 764, 2180, 1859, 5013, 9666, 8670, 9041, 943, 1160, 2150, 9399, 7313, 6926, 6253, 5974, 8263, 616, 5416, 9167, 1084, 1710, 2909, 1434, 9835, 7609, 3887, 6533, 3495, 6395, 9872, 6179, 6422, 8546, 9031, 2424, 4925, 1739, 7241, 3519, 5542, 2546, 3615, 4464, 2971, 9342, 259, 3877, 7686, 7375, 9512, 3942, 3237, 5539, 8814, 235, 5661, 655, 6648, 1958, 121, 2620, 3683, 8240, 9276, 6041, 4740, 7370, 4350, 2242, 4886, 5477, 9520, 6997, 7777, 12, 4979, 2073, 6346, 4, 805, 1039, 2525, 7574, 7909, 6412, 7725, 5003, 7960, 8119, 8840, 1969, 5458, 5022, 4498, 5760, 2503, 2810, 23, 4351, 7067, 2038, 4894, 5976, 7878, 1532, 9375, 4467, 3646, 7052, 9850, 7952, 4437, 8779, 5726, 8485, 304, 1540, 8924, 7752, 8440, 3006, 3279, 4839, 4677, 9025, 6369, 4819, 7098, 9141, 7785, 6694, 6813, 8142, 2876, 4791, 3006, 4061, 6810, 1820, 355, 2847, 2254, 3728, 4257, 8766, 9939, 6279, 4424, 3628, 8341, 9027, 1438, 3712, 4482, 3809, 3494, 4166, 3667, 1137, 4713, 7015, 5725, 7671, 5611, 3648, 1770, 6570, 4758, 8338, 7311, 1826, 4823, 7529, 8237, 2403, 7865, 6344, 6100, 5370, 8845, 957, 2562, 8353, 9417, 9162, 3190, 3682, 1398, 6780, 794, 4351, 886, 5043, 9556, 3461, 6596, 5896, 502, 2949, 5117, 8950, 8938, 5084, 6330, 141, 17, 1209, 1470, 3002, 662, 9786, 9915, 6726, 5092, 6648, 8418, 3340, 7383, 828, 9990, 8492, 1492, 7609, 4453, 2294, 7528, 7745, 5631, 7834, 7344, 388, 8585, 669, 3132, 1985, 4117, 38, 87, 2452, 4689, 9668, 4674, 1777, 9409, 7339, 4001, 9689, 4513, 4224, 2454, 5815, 8228, 7563, 3164, 8057, 8327, 6704, 9672, 7022, 6028, 2235, 4179, 1370, 5020, 8857, 6419, 5952, 1165, 5277, 9478, 4584, 5731, 2712, 3140, 5576, 4244, 9917, 709, 1944, 3924, 6091, 651, 4871, 4971, 7950, 2115, 4597, 9658, 2238, 9176, 821, 6228, 4478, 9148, 7813, 4822, 8442, 1342, 8599, 521, 7524, 1555, 7882, 5514, 728, 8766, 3197, 8298, 8328, 3572, 675, 7857, 9854, 2605, 3219, 1387, 6951, 4741, 697, 4923, 7951, 7325, 8404, 1901, 8527, 9105, 9986, 766, 2576, 8955, 9861, 3078, 4858, 7447, 4353, 1259, 1642, 718, 5612, 8156, 1933, 4637, 9135, 2472, 5163, 61, 8514, 2828, 2643, 7952, 1790, 4063, 4232, 999, 5837, 8418, 8088, 1509, 6757, 3945, 9008, 8745, 4217, 6863, 6037, 7999, 1902, 3594, 2242, 8564, 8194, 9888, 5919, 4331, 7956, 2055, 8097, 5601, 2084, 993, 983, 9897, 4636, 5381, 8217, 8506, 8029, 3419, 8931, 8735, 8098, 919, 2772, 9468, 3267, 351, 1851, 5876, 7836, 5148, 6941, 6435, 5793, 6392, 8010, 6421, 4155, 7417, 4647, 9288, 4743, 2482, 1674, 937, 6766, 6324, 2508, 9901, 6829, 1087, 739, 2304, 2050, 3182, 4767, 4201, 5817, 5593, 2433, 5141, 3839, 2966, 2212, 5207, 9623, 7357, 5476, 2573, 2999, 1187, 9868, 8660, 7414, 2522, 6576, 6707, 3390, 9845, 75, 1652, 7986, 2453, 6961, 677, 7212, 567, 4463, 8632, 2902, 2856, 6106, 1076, 3269, 4340, 460, 4176, 334, 5334, 4619, 5612, 8981, 5592, 1223, 9850, 3392, 9114, 9412, 4507, 2264, 137, 1097, 3234, 5292, 2090, 8004, 3880, 1223, 4888, 2719, 4855, 8410, 7283, 5072, 6755, 8553, 1577, 4034, 4718, 3614, 4156, 3954, 5189, 9722, 9452, 2679, 1900, 5265, 6554, 7719, 5308, 4870, 3432, 4414, 667, 9116, 3939, 6407, 6195, 390, 4430, 5779, 7026, 6843, 6913, 6427, 3121, 3135, 8720, 4906, 7105, 1169, 82, 2613, 8103, 8487, 6204, 8006, 5166, 2740, 579, 3419, 6336, 4639, 3941, 4000, 624, 2082, 2653, 146, 8671, 3975, 4211, 7217, 8835, 992, 2099, 9051, 7208, 7853, 2976, 4351, 3482, 8398, 5233, 5672, 3022, 3077, 7782, 8880, 5944, 858, 8665, 3476, 8176, 9557, 144, 2496, 2336, 50, 4634, 3927, 7846, 2951, 9182, 8109, 2554, 8635, 6501, 4321, 9757, 4046, 9115, 4976, 3097, 9860, 8789, 9035, 4458, 5961, 9305, 587, 2652, 6359, 210, 2601, 5480, 5433, 7450, 7148, 5948, 9634, 1405, 615, 6061, 6034, 1455, 6247, 1221, 7349, 7273, 869, 9436, 4549, 8798, 5889, 2822, 9972, 6914, 11, 149, 5059, 9350, 2727, 1377, 6656, 9407, 4555, 4973, 5520, 1303, 9242, 7058, 3552, 6996, 1491, 8053, 8331, 1499, 5320, 6684, 7232, 8383, 6120, 3056, 9869, 2290, 2157, 7766, 5951, 8127, 4749, 106, 5078, 4594, 4636, 9428, 9301, 4226, 2522, 1496, 5106, 1360, 8827, 786, 9123, 6712, 6424, 702, 4879, 9898, 5168, 5856, 209, 5814, 598, 3505, 8254, 2093, 4629, 230, 4903, 7150, 958, 5712, 8878, 1487, 2279, 5579, 463, 1928, 6145, 9043, 713, 2156, 5824, 8957, 1390, 8820, 5414, 8859, 1749, 6700, 5603, 6870, 9956, 7746, 9356, 3812, 6171, 4814, 739, 1436, 3621, 5164, 5271, 3838, 17, 361, 6307, 1973, 1854, 4433, 963, 5340, 3115, 3820, 3930, 4010, 7429, 3252, 391, 331, 7707, 1415, 2475, 9154, 9813, 2407, 3151, 9314, 4795, 7924, 2925, 7660, 7854, 1864, 3965, 9141, 7061, 3185, 5832, 6050, 799, 5299, 9773, 8744, 8877, 8611, 957, 9729, 3316, 4011, 4639, 6304, 3393, 9834, 2401, 6301, 6953, 8314, 682, 9137, 3167, 4550, 8336, 4493, 2189, 871, 5915, 1397, 415, 7209, 5843, 4096, 76, 5102, 3265, 9595, 5054, 8004, 781, 5554, 1936, 1699, 615, 144, 3122, 3411, 2538, 7492, 2988, 5718, 7932, 5328, 7914, 1337, 8505, 5207, 4938, 913, 763, 1288, 1485, 6855, 3880, 2251, 6942, 1371, 1874, 2405, 7448, 1771, 945, 6037, 5766, 6406, 4727, 2613, 3011, 8408, 6916, 6238, 2598, 4260, 1014, 3543, 7322, 798, 8556, 3840, 7086, 5216, 7603, 3004, 2889, 5121, 8253, 530, 3160, 1350, 5810, 3026, 8735, 3876, 5679, 709, 2417, 6809, 9371, 9115, 7061, 7348, 2286, 8041, 8217, 6236, 2968, 8997, 6148, 5796, 5551, 4154, 4446, 7285, 8232, 3871, 9540, 9973, 7777, 1507, 7104, 5502, 1291, 887, 4488, 7582, 9042, 2407, 3040, 3536, 6608, 9792, 7501, 738, 2433, 761, 4529, 406, 3710, 5772, 9337, 9542, 4371, 4036, 8541, 8692, 670, 6560, 4719, 1761, 5585, 8516, 1699, 9424, 60, 4442, 6105, 9629, 6478, 8089, 5049, 5031, 7167, 8251, 8416, 2178, 6042, 3733, 6990, 4807, 8074, 1589, 3283, 7640, 2163, 9515, 5197, 8224, 7352, 8886, 7479, 9467, 9919, 1365, 9980, 5600, 8014, 1899, 7106, 755, 2037, 2205, 2175, 9102, 4936, 6432, 8364, 6146, 5272, 4377, 4292, 1079, 2048, 5153, 1594, 5229, 6279, 8260, 7662, 6274, 5738, 6157, 6234, 1927, 1015, 6936, 9580, 6243, 9151, 8238, 2914, 9040, 286, 9359, 2561, 6133, 3228, 7747, 5694, 85, 2035, 2471, 4775, 119, 7825, 7017, 8246, 1247, 7509, 7967, 95, 485, 9392, 846, 603, 6152, 4001, 1491, 7767, 5611, 5735, 611, 2510, 2779, 881, 4829, 2642, 5009, 3011, 5971, 4652, 8547, 307, 4174, 8050, 5732, 3972, 3994, 789, 217, 9116, 1498, 7786, 4265, 6843, 1828, 9998, 7643, 7138, 1099, 7774, 1189, 9137, 239, 9800, 3226, 4718, 9385, 6668, 3911, 5805, 2651, 4437, 1911, 389, 9888, 3589, 6505, 5113, 2855, 1363, 5287, 1897, 8500, 2835, 3467, 7581, 697, 5427, 8626, 4433, 1575, 1767, 4792, 4062, 719, 8188, 8983, 1390, 2734, 6071, 5915, 521, 3031, 3020, 425, 5948, 9028, 1227, 1809, 9299, 6299, 2518, 1490, 5979, 2123, 9499, 1224, 1311, 4551, 5479, 6437, 2292, 9235, 3601, 8796, 8948, 727, 7768, 9073, 7526, 5119, 6985, 4269, 1045, 271, 486, 5353, 6758, 2091, 6383, 6989, 8256, 9365, 8665, 5354, 5701, 3033, 3826, 5290, 6424, 5901, 8135, 1829, 4966, 624, 599, 9582, 9535, 2020, 1675, 624, 8400, 7165, 8432, 8746, 4043, 8058, 9162, 3391, 1794, 1388, 4221, 7103, 8756, 2823, 3663, 4184, 1039, 8563, 7285, 9492, 2507, 3022, 489, 9251, 4203, 1676, 934, 9509, 1533, 240, 3808, 1582, 9551, 8917, 3286, 5829, 8030, 8327, 5449, 7511, 6605, 3443, 1077, 7035, 9239, 768, 7532, 4870, 438, 4329, 7191, 9290, 9454, 7830, 837, 8542, 6390, 9767, 5167, 4265, 5015, 6480, 9008, 4814, 1751, 8385, 5860, 8313, 2490, 4026, 2395, 2715, 7373, 9062, 6358, 4710, 3430, 6519, 5161, 1417, 2925, 3126, 6730, 6619, 4063, 4213, 7665, 5861, 1567, 6491, 3745, 6239, 7324, 2350, 6804, 96, 7142, 5213, 3817, 5286, 7793, 5038, 6833, 6634, 3325, 6684, 5696, 7933, 4938, 4255, 9417, 1986, 9687, 5843, 2943, 1286, 6150, 7306, 6298, 5780, 5656, 9422, 6388, 2924, 8358, 4452, 850, 9316, 2928, 3941, 4375, 2081, 7182, 6292, 6809, 2326, 6043, 5674, 6179, 8675, 6636, 9523, 9917, 8240, 9672, 5796, 4679, 8558, 7651, 2144, 8348, 7745, 5379, 26, 243, 8234, 391, 7175, 9613, 7175, 6074, 2997, 3520, 3254, 654, 898, 9250, 7552, 2149, 1829, 86, 2733, 4557, 2498, 2216, 3652, 5190, 3050, 8362, 1891, 1301, 9226, 5718, 4172, 4898, 964, 7045, 9284, 9258, 5981, 4910, 3972, 6461, 9214, 9168, 2160, 3917, 3273, 5991, 7027, 1277, 6598, 4476, 247, 2219, 7191, 9143, 4572, 9087, 4857, 6229, 1574, 5498, 8856, 1466, 4178, 1306, 723, 9187, 5675, 4356, 2602, 7384, 4251, 2006, 7978, 4451, 234, 5790, 4859, 4130, 7878, 7745, 2624, 1663, 4331, 9160, 6359, 7972, 7058, 4240, 671, 2595, 4981, 9656, 647, 1412, 4385, 1092, 2760, 4552, 2131, 2454, 299, 1651, 1569, 8665, 9754, 3897, 5971, 160, 7224, 8634, 6627, 5565, 4719, 3087, 8479, 6426, 4802, 4848, 131, 2747, 3023, 1209, 8125, 3297, 1893, 2804, 6002, 1878, 1226, 7240, 5937, 9704, 4158, 9029, 2909, 5481, 8443, 822, 9542, 4872, 1607, 2305, 9960, 8511, 3290, 5890, 1213, 9210, 131, 5909, 6965, 7271, 4761, 6418, 4605, 6376, 4373, 2746, 379, 5779, 2841, 3285, 7514, 5562, 3928, 2298, 5577, 1435, 8566, 7805, 4304, 6058, 6898, 4966, 3637, 5167, 7448, 745, 3926, 5695, 422, 734, 6549, 5717, 5106, 4104, 8551, 4886, 8254, 1288, 6540, 983, 9627, 8194, 3112, 7791, 9750, 7733, 4434, 9145, 1800, 2043, 8196, 3737, 6839, 6122, 3576, 1209, 8231, 968, 98, 2831, 3778, 8354, 2258, 3900, 2577, 3165, 8337, 2798, 7574, 189, 4845, 5745, 4756, 5201, 8022, 3174, 2395, 4126, 5168, 8524, 3426, 5123, 3266, 7819, 5835, 7381, 3610, 9491, 5906, 2833, 6124, 7776, 5999, 8606, 1797, 3113, 1378, 345, 5443, 178, 5023, 9399, 1083, 314, 3932, 2117, 6643, 5984, 3469, 8485, 9576, 1201, 6344, 1094, 1708, 9189, 3987, 173, 6885, 115, 9572, 610, 9131, 5610, 1455, 8617, 9366, 5427, 7969, 9031, 5134, 239, 8237, 4500, 6284, 1112, 9294, 6817, 3996, 1570, 3878, 8419, 897, 6566, 1651, 9213, 2750, 9293, 5492, 390, 4549, 223, 4415, 6879, 7477, 1529, 7794, 9292, 1455, 8069, 1919, 8045, 7320, 6292, 3494, 5443, 3114, 3693, 6795, 6042, 3545, 4910, 9242, 1718, 2502, 7983, 785, 6132, 1718, 6241, 9516, 1505, 7140, 5660, 7215, 9478, 6804, 3948, 9493, 9738, 1695, 1903, 3266, 5144, 6991, 1633, 8575, 8491, 7, 8388, 480, 4547, 6507, 6699, 4584, 2983, 8227, 2768, 2271, 6428, 241, 4176, 7181, 468, 2528, 4403, 5907, 7119, 1930, 2933, 315, 186, 4112, 9688, 6991, 1246, 2345, 8890, 6097, 5371, 2927, 7295, 9529, 5435, 7098, 5732, 8635, 5665, 1911, 4757, 7591, 3702, 6071, 4726, 2799, 9456, 7648, 1114, 5023, 4687, 5931, 4963, 9028, 1465, 6248, 612, 5317, 3989, 3141, 1077, 1469, 6583, 1715, 1464, 9587, 7131, 3121, 3173, 2041, 6621, 9566, 9627, 6094, 8782, 842, 1983, 7349, 8510, 5200, 4757, 4914, 709, 965, 5034, 1464, 6004, 898, 1753, 6777, 8397, 2472, 5306, 6970, 8547, 609, 8405, 5970, 944, 4133, 1728, 808, 2086, 4718, 7673, 6042, 1867, 3506, 9159, 2808, 1794, 3068, 4047, 5430, 6418, 5604, 9852, 201, 3160, 1699, 7568, 5098, 468, 4810, 70, 6517, 124, 4557, 9039, 7727, 4555, 7256, 7632, 9159, 2328, 7684, 6015, 1789, 4708, 7568, 2554, 156, 5685, 1851, 6295, 7709, 5107, 3299, 4319, 1338, 1557, 1666, 419, 5030, 7974, 5597, 1645, 6269, 9927, 6800, 8884, 686, 9797, 1721, 6333, 5270, 349, 6784, 9605, 1247, 2406, 9731, 6446, 6128, 9622, 9597, 5445, 8911, 7601, 4969, 7885, 6592, 291, 7914, 4686, 9986, 4692, 2248, 4972, 5523, 2526, 9535, 9166, 5550, 7506, 8835, 4895, 7486, 9545, 5761, 2898, 564, 9156, 660, 3273, 8051, 2667, 4783, 9340, 1743, 2738, 7560, 6964, 1959, 3701, 9558, 8696, 9456, 9624, 12, 2608, 4282, 8676, 7336, 5054, 7443, 2445, 6632, 9286, 9764, 261, 4779, 2367, 3792, 861, 5763, 6442, 9325, 4633, 4163, 9198, 2331, 7869, 8220, 9343, 448, 8404, 549, 1573, 4152, 6093, 2450, 5539, 1202, 2666, 8838, 5776, 9381, 8959, 3841, 8762, 7294, 8434, 2280, 6550, 9894, 2468, 8728, 1963, 7268, 7534, 8547, 2338, 6836, 3506, 4347, 4204, 357, 3186, 9653, 583, 1826, 8859, 1862, 866, 7414, 482, 3402, 8218, 5131, 6236, 6576, 9062, 2247, 8806, 8023, 1902, 3234, 2485, 9820, 9866, 6089, 9457, 8959, 7581, 2697, 7516, 694, 1214, 5055, 1291, 4322, 4045, 5709, 23, 895, 2427, 9234, 7777, 9859, 4163, 4420, 6613, 9783, 5967, 9547, 7985, 7105, 1303, 4748, 8557, 6960, 9066, 3241, 5309, 2987, 1527, 5675, 5005, 5930, 331, 7072, 2167, 3206, 5509, 655, 1473, 9638, 4611, 5661, 2509, 633, 4774, 8472, 9170, 6577, 59, 159, 5137, 6549, 2482, 6858, 2298, 5696, 407, 7783, 9872, 4196, 8886, 5749, 5841, 8403, 3864, 7926, 6530, 2884, 1691, 156, 76, 2029, 5323, 2400, 1872, 9705, 6623, 6604, 4574, 6814, 4881, 6450, 5270, 539, 9365, 8665, 4149, 5004, 878, 5454, 3832, 8203, 2965, 2079, 6024, 5296, 1085, 9949, 6885, 6006, 9070, 8925, 8066, 4781, 8389, 4217, 6911, 9881, 4000, 190, 3057, 4599, 3082, 5045, 1877, 7151, 9043, 7979, 3337, 6876, 3271, 2093, 8988, 8050, 9091, 6505, 5037, 3886, 9858, 6762, 4306, 8999, 682, 3645, 2651, 7460, 1149, 2562, 3078, 9434, 6026, 6627, 2931, 5214, 1612, 4134, 7989, 4335, 6527, 3844, 4010, 5221, 6720, 3634, 9580, 3609, 1048, 5360, 674, 6085, 6461, 2626, 6816, 8250, 3675, 3603, 9346, 5546, 8763, 3725, 1654, 148, 7051, 6703, 8288, 1663, 9518, 8151, 3733, 9279, 4440, 9004, 3645, 4330, 7967, 9607, 9159, 606, 9869, 2819, 8884, 3589, 6150, 1149, 1947, 7769, 4954, 7942, 377, 8422, 5010, 4278, 3190, 4974, 2247, 2112, 8543, 4197, 8219, 6600, 6611, 2138, 7323, 8853, 7482, 5319, 8756, 6263, 1574, 3609, 6768, 5479, 2443, 4987, 8486, 6838, 8801, 4250, 5526, 4345, 8567, 5925, 9511, 8138, 250, 3418, 9672, 7136, 2110, 3367, 2847, 2495, 3539, 2733, 7554, 3980, 7110, 3163, 82, 9075, 9835, 9332, 6696, 3747, 2019, 3042, 356, 7631, 61, 7089, 9404, 6090, 636, 3790, 2264, 9907, 7702, 214, 5964, 1607, 3747, 5901, 211, 9858, 5432, 388, 438, 4060, 7265, 2086, 6674, 8503, 2518, 8140, 7324, 3010, 3806, 7448, 253, 9142, 5837, 4973, 7320, 9279, 7230, 1692, 7461, 5519, 7331, 3628, 1517, 761, 8735, 8763, 6930, 4992, 8022, 565, 6223, 9828, 3977, 6344, 7460, 3250, 8156, 1013, 9350, 9527, 1084, 5593, 5934, 6754, 7088, 7727, 5953, 4470, 7549, 6647, 9127, 9457, 7392, 3394, 4226, 6490, 1749, 5979, 581, 5543, 6263, 4618, 1018, 261, 6596, 8876, 1042, 6576, 6183, 3730, 5387, 1833, 10000, 6276, 8960, 6030, 9595, 7481, 7388, 5760, 9124, 938, 3892, 6549, 1082, 2810, 4555, 2647, 5902, 4100, 2370, 3973, 7383, 1682, 3104, 5814, 8317, 4118, 2794, 427, 2058, 238, 6487, 8818, 5321, 8191, 1656, 464, 6117, 8867, 6347, 2670, 5823, 7896, 173, 6015, 7811, 9025, 3923, 6725, 2927, 3046, 6777, 406, 2686, 4062, 9400, 3488, 5593, 1107, 4822, 1195, 2529, 5779, 5471, 1581, 5340, 7403, 478, 462, 2714, 1651, 8312, 1314, 8908, 9207, 1038, 6755, 5190, 2473, 6516, 9798, 9627, 6686, 9252, 8684, 1780, 6539, 6978, 1802, 5828, 4795, 4543, 3524, 7151, 4671, 3336, 5113, 3410, 9669, 8185, 495, 1114, 8261, 8822, 2493, 9169, 9771, 5851, 5941, 3794, 8937, 3135, 5515, 7643, 3146, 8319, 9338, 7038, 4502, 9170, 8650, 2282, 5718, 1210, 8841, 3624, 8984, 2105, 928, 7567, 5546, 9035, 9552, 5804, 1866, 4709, 1982, 3623, 296, 1354, 7811, 6074, 8861, 2878, 6080, 861, 9541, 9146, 5106, 9467, 4169, 9886, 3046, 5247, 7699, 8792, 1699, 4576, 2112, 7982, 4839, 3461, 5774, 4475, 6040, 4152, 1268, 7480, 3253, 5944, 2832, 4045, 4011, 6030, 6577, 3553, 1110, 3311, 1467, 2204, 844, 8025, 5280, 1237, 6469, 3743, 2663, 8280, 8216, 7865, 2548, 1167, 6863, 8389, 6661, 3372, 2408, 8921, 1197, 4012, 3227, 7887, 5981, 6675, 8474, 287, 1454, 1668, 8069, 4752, 2426, 3173, 3415, 770, 1245, 8753, 3, 6207, 6732, 2736, 8726, 6305, 7528, 9149, 7294, 17, 8261, 9873, 5593, 1371, 6134, 6997, 794, 6156, 1664, 5546, 7076, 3786, 6294, 9170, 4074, 3302, 1959, 3422, 8466, 1656, 9465, 4051, 8251, 844, 1601, 4581, 4883, 5794, 1175, 3362, 5354, 7575, 2579, 3495, 3922, 2003, 5430, 9828, 5122, 6450, 369, 7526, 8515, 7123, 4935, 1853, 9328, 4638, 7508, 5925, 8194, 4113, 7062, 684, 9763, 5360, 8292, 6486, 4448, 5269, 7501, 19, 5452, 9806, 2236, 9938, 3171, 3987, 8341, 6088, 4745, 5764, 4928, 1588, 3023, 4582, 9874, 2198, 7551, 4774, 7744, 382, 8813, 1867, 2596, 2611, 2041, 9479, 4161, 5203, 8998, 1603, 3692, 9996, 4028, 6541, 3328, 1766, 7121, 5610, 2648, 3517, 5715, 6446, 5993, 7735, 8808, 372, 9372, 341, 9622, 8878, 8170, 8783, 9067, 7938, 4573, 7679, 1824, 9614, 6868, 8032, 5235, 4343, 4861, 2267, 3037, 5489, 8397, 4333, 7506, 9148, 7157, 46, 990, 3137, 753, 3886, 165, 9368, 7023, 5793, 4132, 9084, 5937, 2645, 2487, 7262, 1160, 5406, 8933, 3584, 6073, 1529, 6251, 1659, 1043, 1803, 8090, 3921, 658, 5316, 4909, 2279, 7539, 7457, 7030, 9936, 4145, 8507, 6569, 1255, 509, 2509, 5130, 9922, 1577, 6089, 5097, 8735, 9281, 2225, 347, 2143, 2557, 4973, 8435, 6862, 886, 428, 5362, 8419, 4238, 3390, 6839, 7198, 9511, 6424, 4078, 8963, 104, 7098, 7888, 4036, 8922, 9530, 8822, 640, 6187, 6967, 2388, 7858, 1553, 5650, 7218, 3993, 3517, 8842, 1261, 6843, 5828, 7929, 326, 1743, 2078, 239, 7950, 4934, 1473, 6853, 9645, 2955, 4808, 5994, 7856, 8994, 1750, 9968, 3112, 64, 3907, 558, 5276, 8917, 2831, 4230, 5191, 2761, 345, 9467, 7887, 4254, 7525, 5639, 6759, 119, 9766, 4455, 645, 7669, 2214, 4354, 8487, 3923, 6839, 6100, 3882, 2593, 4524, 1192, 8803, 77, 3938, 5455, 7841, 3888, 8582, 6216, 8708, 9412, 7777, 4496, 3721, 567, 7450, 9375, 5477, 4968, 8929, 1739, 6632, 1514, 3552, 2668, 7775, 1680, 7726, 491, 4734, 39, 3138, 6141, 224, 3459, 9302, 5025, 3416, 3199, 262, 3457, 2873, 7414, 7370, 1174, 1707, 5585, 2762, 4378, 950, 7950, 5789, 3591, 2848, 9817, 4080, 5741, 2784, 7265, 1643, 843, 3993, 4318, 9093, 8565, 1224, 4920, 4169, 5637, 6971, 87, 7199, 6849, 9071, 3571, 7956, 1708, 1104, 3920, 8736, 8124, 52, 5426, 6764, 1272, 5549, 6073, 2314, 5001, 3217, 1303, 1912, 3825, 3682, 7987, 625, 2812, 6199, 386, 4060, 3405, 2338, 4072, 3342, 5579, 2313, 6024, 2246, 7273, 9469, 52, 3173, 2714, 9268, 2758, 1101, 4236, 9782, 5142, 2665, 3461, 2087, 1558, 1928, 2012, 3344, 3625, 237, 4168, 7714, 5303, 5280, 7919, 8526, 8944, 2886, 8282, 8331, 5945, 8888, 9331, 1618, 6436, 368, 170, 453, 8663, 6497, 2909, 8121, 4529, 9286, 2107, 494, 2061, 3428, 3497, 512, 9873, 1830, 4419, 5727, 7809, 3022, 8447, 1007, 6794, 3527, 704, 7515, 674, 4631, 6076, 7020, 1353, 1883, 7497, 7025, 4680, 5841, 184, 330, 3545, 8995, 5558, 2479, 4816, 4238, 3004, 6248, 6713, 7207, 6981, 9011, 9080, 8522, 1466, 4381, 1941, 5108, 1205, 2559, 3381, 4025, 7764, 5017, 9356, 8109, 6058, 5810, 6601, 2420, 7452, 4825, 4480, 5604, 8920, 8369, 4125, 5177, 195, 8860, 3264, 8534, 8275, 1196, 4049, 3053, 5135, 9576, 8070, 6696, 7307, 3789, 2087, 1537, 3492, 2251, 2449, 4459, 2148, 9481, 7552, 3148, 1114, 6314, 7541, 9074, 7816, 109, 2889, 2789, 8488, 9422, 5926, 1479, 4135, 3606, 608, 2364, 7190, 3384, 6679, 3930, 6834, 730, 1275, 7167, 4997, 444, 7363, 1330, 8123, 9571, 7499, 295, 8885, 4467, 1993, 475, 3872, 5560, 7992, 4811, 3290, 6858, 5888, 1479, 5137, 4971, 7770, 2092, 6430, 2431, 9454, 185, 4525, 3020, 4267, 736, 4031, 2673, 1585, 8602, 2044, 2201, 329, 3332, 5007, 9843, 2525, 6367, 5708, 3387, 4505, 1551, 1785, 3838, 1319, 3615, 1294, 923, 1052, 6631, 1938, 1854, 6323, 4790, 575, 6398, 7513, 25, 8039, 1100, 2133, 4535, 2723, 7960, 7209, 4962, 6417, 2105, 4662, 5614, 6222, 9779, 7770, 4138, 6308, 3289, 2832, 30, 2473, 5401, 9782, 3964, 8358, 6616, 9042, 754, 3718, 2726, 8021, 6849, 8376, 4926, 4441, 6119, 7153, 3033, 6050, 4711, 6373, 3058, 1734, 7834, 9905, 4751, 1822, 9369, 1089, 4900, 6564, 8522, 3137, 4589, 8213, 3546, 8584, 7844, 2242, 6472, 4879, 7925, 853, 6734, 6444, 3626, 8819, 9496, 4397, 7156, 2217, 2116, 2291, 9870, 9459, 2479, 7321, 8158, 4695, 855, 8894, 1751, 4342, 9431, 5987, 5279, 9107, 9808, 6205, 7941, 6246, 985, 8520, 922, 4770, 7200, 2742, 7061, 2785, 6545, 1426, 7270, 9134, 8522, 9617, 5933, 5541, 1091, 9320, 8126, 4339, 7223, 7745, 755, 3058, 2228, 3718, 9277, 664, 843, 6012, 753, 8675, 3454, 1216, 2545, 7466, 1366, 1129, 2348, 8997, 5264, 2421, 9700, 4366, 134, 1841, 8935, 9914, 9754, 4293, 156, 8008, 2358, 1080, 4905, 1895, 9474, 3182, 8179, 1798, 1058, 1344, 8178, 1718, 3518, 7038, 3768, 9680, 2989, 8985, 1869, 6735, 4637, 2534, 9285, 8433, 6560, 5141, 7394, 7435, 8497, 7177, 3914, 3454, 8154, 5481, 2934, 352, 28, 767, 3293, 5090, 7721, 369, 1699, 1168, 5379, 9619, 1239, 3987, 9412, 3745, 7012, 7318, 3559, 5652, 3630, 610, 9500, 5563, 9553, 6664, 8065, 4142, 7587, 1528, 2889, 5192, 1357, 5450, 5278, 7201, 3263, 8382, 6476, 2855, 3625, 8899, 1708, 4669, 5320, 1845, 8501, 4238, 7528, 967, 6338, 7363, 6568, 170, 5818, 9060, 4780, 2397, 2861, 3617, 7103, 324, 6856, 2020, 25, 2174, 1592, 4922, 4569, 9792, 5733, 216, 4975, 8350, 6895, 2500, 76, 2050, 7338, 2507, 3183, 2262, 46, 5158, 8641, 226, 1810, 5055, 8713, 5504, 3462, 958, 5307, 3215, 1637, 3491, 9508, 7822, 6212, 3071, 4004, 1236, 8060, 291, 2130, 8928, 7745, 909, 7837, 666, 4414, 3855, 4645, 9868, 473, 589, 7155, 7486, 1776, 2519, 3022, 6153, 9028, 1297, 5313, 4731, 8128, 4007, 3700, 1547, 2591, 3722, 3456, 3131, 3493, 5769, 3603, 8857, 292, 5791, 2884, 7999, 7619, 957, 9962, 7708, 6901, 6213, 3457, 5975, 2028, 6616, 8194, 2163, 2871, 2951, 4563, 7748, 8259, 6021, 7570, 9522, 9985, 5605, 5531, 7234, 5035, 4168, 8339, 3520, 1574, 8317, 4591, 1808, 6167, 3401, 7465, 1523, 6613, 153, 3800, 1582, 5790, 7266, 8746, 8499, 9580, 7267, 4255, 9458, 7572, 1134, 3106, 6070, 7158, 8470, 5922, 383, 4397, 4383, 7476, 5152, 7703, 5063, 4036, 2329, 5881, 2393, 713, 8242, 2098, 9246, 3123, 8398, 4057, 4506, 9837, 9085, 1024, 9570, 2153, 9761, 2028, 6333, 5439, 5908, 2767, 2901, 6682, 4547, 7236, 7170, 9120, 1440, 7694, 967, 7257, 8418, 3109, 8502, 3638, 4547, 371, 6494, 5533, 5416, 1649, 955, 8831, 4687, 8964, 5330, 2812, 4222, 2298, 2763, 948, 1340, 3598, 4575, 8681, 2562, 1351, 5400, 5346, 380, 8688, 1800, 9261, 4500, 6904, 3813, 1408, 1586, 3069, 5635, 811, 8839, 5370, 3890, 4242, 40, 6210, 2445, 5399, 9365, 4437, 447, 6592, 7827, 2559, 1914, 9329, 6468, 2443, 704, 1667, 2497, 3519, 2777, 1741, 7837, 1721, 9205, 9537, 9714, 6536, 142, 137, 5114, 377, 6522, 8693, 4997, 7277, 8486, 6320, 3727, 7648, 669, 8217, 6120, 9770, 1564, 5056, 4073, 10, 8108, 3760, 802, 777, 5186, 1460, 5895, 2123, 694, 5056, 8102, 6536, 8448, 7741, 1487, 523, 697, 9760, 8644, 6694, 3956, 251, 9173, 4217, 4776, 6486, 2722, 312, 6694, 6619, 211, 950, 4594, 2744, 5763, 2434, 5571, 9867, 3028, 5946, 3637, 4291, 495, 8387, 7746, 1173, 1219, 557, 7842, 8066, 4264, 7583, 7252, 987, 2478, 7257, 4365, 7256, 9695, 9967, 3565, 4539, 8347, 6317, 6435, 1298, 8124, 9213, 346, 595, 3232, 4892, 8233, 1893, 9011, 6086, 5343, 672, 3547, 8107, 3133, 2195, 1077, 91, 5956, 1177, 8552, 484, 7201, 3661, 5430, 2373, 7100, 3293, 5950, 1092, 6631, 9463, 5773, 7956, 4222, 4908, 4266, 150, 719, 3131, 5981, 102, 9451, 9705, 9104, 2999, 3565, 7173, 3797, 5277, 3810, 7117, 7635, 7673, 8935, 8286, 867, 7609, 8305, 5692, 3039, 327, 969, 3084, 4842, 2872, 4142, 4636, 3792, 9643, 6926, 3821, 6022, 9255, 5287, 2884, 2260, 5213, 7558, 2937, 9721, 5632, 8659, 3444, 6855, 2536, 6122, 7755, 3781, 4303, 3625, 3231, 2406, 118, 9139, 843, 4338, 4329, 3712, 2319, 2173, 5558, 8302, 9575, 362, 1686, 2283, 7010, 3498, 9476, 9000, 628, 9563, 4165, 7274, 69, 8289, 4247, 7810, 6899, 3117, 4500, 7688, 763, 483, 1631, 9090, 5929, 1461, 113, 2927, 6975, 8457, 5059, 5506, 865, 2515, 3583, 4776, 5897, 8160, 9807, 4473, 4757, 7207, 2056, 3092, 8285, 9197, 2661, 3075, 194, 8890, 3219, 9269, 5242, 209, 7018, 113, 5110, 324, 5420, 7265, 457, 1870, 270, 332, 1161, 8579, 6049, 3103, 5672, 640, 5039, 8004, 1536, 264, 3513, 5726, 6755, 6283, 638, 3653, 3540, 8003, 41, 3522, 3908, 4679, 7660, 3161, 2785, 1175, 2979, 8648, 4000, 3083, 4849, 1811, 239, 3155, 4414, 5390, 3389, 5595, 619, 4738, 8403, 765, 1901, 3226, 5397, 219, 394, 6135, 8764, 201, 5344, 1448, 5109, 7054, 8288, 9626, 2006, 5795, 5608, 6709, 1886, 9985, 359, 4157, 5980, 512, 6165, 4834, 2384, 8375, 317, 9880, 3253, 8069, 8525, 2621, 9001, 3332, 7626, 1273, 8450, 8352, 5617, 1810, 6261, 9512, 2989, 6735, 8655, 4636, 35, 230, 4068, 5982, 5885, 2749, 2952, 6489, 6426, 8975, 1736, 8702, 6223, 6594, 9139, 4711, 6457, 4462, 5595, 5214, 7985, 8135, 4392, 4317, 6526, 3049, 7098, 2502, 3809, 918, 4735, 3704, 7599, 8627, 8540, 3256, 6257, 6815, 1525, 1626, 8826, 6521, 7954, 2124, 1250, 5580, 6541, 3197, 8434, 3508, 9585, 6120, 7067, 1286, 4956, 2565, 3793, 5032, 7250, 1777, 5794, 7410, 1936, 3197, 9593, 5209, 9204, 5575, 7699, 7213, 410, 6844, 3634, 5544, 1463, 8991, 9848, 4785, 670, 1562, 7709, 5466, 3761, 3806, 7926, 982, 2487, 3487, 3499, 4162, 2832, 5473, 2988, 5067, 6645, 1148, 5361, 8046, 1068, 7264, 1791, 3776, 3050, 1123, 7227, 3074, 1001, 8777, 7061, 1982, 2883, 7131, 6631, 4699, 8123, 4190, 1553, 3672, 7139, 1201, 7708, 5354, 5376, 5336, 2898, 6146, 3415, 606, 3058, 278, 9112, 7408, 9221, 2863, 8371, 9718, 9949, 2173, 5860, 5801, 211, 2955, 2500, 8413, 3288, 4594, 2808, 9896, 7251, 7443, 27, 5062, 5622, 5528, 8454, 4343, 5105, 1122, 357, 3139, 1337, 5790, 9247, 7208, 8812, 2005, 3722, 7047, 209, 6699, 5136, 7940, 6771, 6805, 6866, 6055, 1104, 2498, 2078, 2897, 1331, 660, 1516, 662, 1576, 8395, 7138, 4935, 7847, 5367, 1328, 863, 3527, 4860, 1814, 1196, 845, 4077, 8219, 9428, 8308, 1453, 5616, 897, 2492, 214, 4343, 509, 1348, 3182, 4135, 8409, 4115, 5454, 1294, 5130, 426, 6880, 3119, 1967, 68, 9047, 827, 3721, 8732, 1361, 2261, 9709, 2558, 602, 8400, 6605, 9955, 1483, 5671, 1459, 792, 3348, 5509, 5987, 3122, 1865, 9059, 2099, 3190, 5914, 6161, 1981, 36, 9445, 6736, 177, 7296, 8654, 8019, 2941, 1656, 667, 616, 1760, 6324, 1196, 181, 9255, 1713, 5179, 5276, 7940, 644, 2051, 8611, 7220, 914, 1768, 4213, 1219, 9235, 1024, 3255, 412, 7257, 9557, 93, 3868, 4042, 583, 8410, 6270, 1615, 5746, 1813, 1306, 5158, 7491, 7350, 3218, 7161, 2961, 4612, 9741, 4491, 5152, 2064, 4292, 6552, 1637, 23, 8722, 4168, 7965, 4406, 500, 1754, 326, 3917, 9016, 4341, 9903, 1059, 8896, 567, 5411, 3144, 3901, 7718, 2346, 7094, 4246, 398, 73, 1694, 553, 2827, 8862, 3348, 7921, 3746, 3976, 3090, 3542, 9654, 90, 3799, 4555, 2386, 5485, 8432, 2914, 8777, 5579, 5968, 3612, 9676, 1980, 6791, 6310, 2691, 8939, 5755, 8284, 2394, 5734, 8186, 2977, 8539, 8866, 8759, 332, 6020, 8697, 8403, 5701, 9639, 4071, 2398, 5876, 6646, 3409, 957, 9033, 4124, 8077, 5421, 4909, 151, 8042, 5689, 4661, 9000, 7566, 2592, 7035, 8463, 3815, 9426, 9993, 2884, 6426, 7354, 2324, 5749, 9232, 7164, 2316, 8274, 9913, 7842, 890, 4860, 9877, 3987, 9287, 4525, 2585, 6432, 767, 3890, 8901, 7389, 7051, 8862, 8729, 710, 2782, 3904, 8533, 9862, 8161, 8484, 2207, 9012, 8081, 640, 4940, 3163, 6512, 3238, 6215, 1817, 2606, 8178, 6085, 8624, 1621, 4809, 7323, 2469, 7519, 281, 6804, 6175, 4704, 7286, 7188, 6105, 3922, 2965, 7814, 6530, 2243, 9053, 6287, 9983, 5877, 2794, 6399, 6793, 2070, 452, 5962, 8090, 3471, 9188, 4779, 7960, 503, 7356, 9741, 670, 4656, 2715, 7669, 8819, 227, 2898, 3489, 4015, 1991, 5376, 5839, 7988, 837, 3668, 5845, 5944, 9995, 3706, 9850, 6435, 1115, 7098, 4214, 6945, 8946, 226, 1180, 4721, 1746, 6894, 7962, 4700, 7626, 7099, 3092, 4563, 8949, 7483, 2240, 8754, 8028, 9072, 4708, 2035, 5945, 2333, 2472, 7734, 6551, 8742, 4783, 8175, 9372, 2712, 8200, 7513, 7269, 1031, 9418, 6902, 8637, 7273, 1154, 41, 5459, 9996, 6167, 1213, 8505, 3444, 6184, 6860, 8327, 3370, 6680, 1729, 3988, 7663, 6805, 8872, 7252, 5158, 4999, 1390, 8080, 1257, 645, 7402, 2362, 5096, 1090, 3766, 5325, 5021, 2598, 5084, 1179, 3187, 1554, 8056, 9202, 7851, 30, 4428, 664, 5441, 4849, 3417, 4628, 5834, 5621, 6324, 5198, 765, 3641, 1526, 1205, 5419, 2341, 5602, 4187, 9600, 3184, 3086, 5741, 8294, 8883, 2088, 8293, 5842, 2738, 8105, 5694, 8209, 763, 8656, 6259, 2700, 8906, 6010, 3628, 1332, 5442, 7183, 9452, 3962, 6342, 3039, 6809, 9043, 6193, 1940, 9711, 8204, 3161, 3494, 5516, 1311, 7422, 552, 9996, 7802, 6527, 7514, 4578, 5928, 8330, 1784, 1595, 6692, 5392, 8930, 7688, 549, 3020, 1984, 851, 7011, 385, 3419, 3173, 1368, 838, 8790, 7794, 6699, 9891, 5504, 5333, 4241, 4532, 5372, 6962, 8458, 3430, 1643, 3422, 5497, 4065, 3483, 1237, 7449, 5106, 8558, 9385, 8465, 5182, 3050, 2613, 4993, 192, 9572, 4899, 7627, 4603, 4161, 3636, 6057, 9960, 2062, 5438, 1039, 6607, 5047, 1544, 2180, 6889, 5662, 6954, 5366, 3928, 4175, 699, 9564, 5161, 2052, 3750, 4959, 2266, 6713, 1108, 3953, 9689, 7414, 8432, 4082, 6154, 6895, 1947, 5422, 480, 4458, 2780, 7480, 8717, 2229, 8840, 3205, 3094, 3533, 962, 8045, 8235, 488, 5243, 3735, 9717, 6294, 7780, 8978, 3424, 9260, 3445, 9212, 8331, 7854, 3933, 2084, 6445, 3262, 1890, 1112, 6451]]
]
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="false" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *
from testcases import tests

if __name__ == '__main__':
    for test in tests:
        test_function(test[0], solve, test[1], test[2], test[3])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

ممد و علی که حوصله‌شان از دانشگاه سر رفته‌است؛ تصمیم گرفتند که یک بازی چهل‌سوالی(!) به صورت زیر انجام دهند:

ابتدا ممد یک بازه‌ی [a,b] انتخاب می‌کند که a و b اعدادی طبیعی هستند. سپس علی می‌تواند تعدادی سوال به صورت "آیا بازه‌ی تو با بازه‌ی [x, y] اشتراک دارد؟ (x و y اعداد طبیعی هستند)" بپرسد. اما از آن‌جایی که ممد حوصله‌ی جواب دادن تعداد زیادی سوال ندارد، اگر از او بیش‌از 40  تا سوال بپرسد ممد شروع به دادن جواب‌های رندوم می‌کند. حال وظیفه‌ی شماست که با پرسیدن سوالاتی هوشمندانه به بازه‌ای که در ذهن ممد است برسید.

ورودی و خروجی:

در ورودی تابع solve یک آبجکت است که حاوی جواب است و دارای تابع ask است که این تابع دو عدد طبیعی ورودی می‌گیرد و یک boolean که جواب سوال است برمی‌گرداند. حال با توجه به خواسته‌های مساله شما باید یک آرایه‌ی ۲ عضوی خروجی دهید که نمایان‌گر دو سر بازه‌است

محدودیت‌ها:

    $$ 1 \le a, b \le 100000 $$

    بازه‌های به صورت [1, x] و [x, 100000] را در نظر داشته باشید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="25" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="25" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="max_n = 100000
    l_low = 1
    l_hi = max_n

    while l_hi - l_low > 1:
        mid = (l_hi + l_low) // 2
        ans = question.ask(1, mid)
        if ans:
            l_hi = mid
        else:
            l_low = mid

    if question.ask(1, l_low):
        l = l_low
    else:
        l = l_hi

    r_low = 1
    r_hi = max_n

    while r_hi - r_low > 1:
        mid = (r_hi + r_low) // 2
        ans = question.ask(mid, max_n)
        if ans:
            r_low = mid
        else:
            r_hi = mid

    if question.ask(r_hi, max_n):
        r = r_hi
    else:
        r = r_low

    return [l, r]" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def solve(question):
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="import random

from test_helper import *
from task import *

tests = [[57270, 70040],
 [84335, 98558],
 [29060, 43300],
 [39986, 95876],
 [89474, 91474],
 [98812, 99845],
 [60806, 70853],
 [5954, 43526],
 [14976, 47184],
 [5528, 12410],
 [61429, 93413],
 [79196, 93956],
 [87242, 96796],
 [40932, 42890],
 [25033, 87121],
 [59167, 81035],
 [9827, 93975],
 [54816, 79135],
 [36003, 45936],
 [57821, 86925],
 [82503, 86449],
 [79563, 93564],
 [80775, 83200],
 [35588, 94632],
 [72606, 75197],
 [66181, 93232],
 [4750, 69881],
 [24376, 54171],
 [30087, 45545],
 [33682, 74265],
 [57790, 90656],
 [87882, 89535],
 [34119, 83665],
 [6877, 30789],
 [55335, 73897],
 [89315, 98155],
 [87954, 98632],
 [17853, 53368],
 [30601, 84812],
 [32505, 96095],
 [1, 100000]
]

class Question:
    def __init__(self, a, b):
        self.a = a
        self.b = b
        self.asked_questions = 0

    def ask(self, x, y):
        if self.asked_questions == 40:
            return random.choice([True, False])

        self.asked_questions += 1
        return (x <= self.a <= y) or (x <= self.b <= y) or (self.a <= x <= self.b) or (self.a <= y <= self.b)

if __name__ == '__main__':
    for test in tests:
        test_function(test, solve, Question(test[0], test[1]))
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="8" />
                <option name="name" value="K Select" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه درس را مطالعه کنید.

سپس لطفا دیگر به جزوه و کدهای آن
مراجعه نکنید.

تابع ()find_kth را کامل کنید تا kاُمین عضو کوچک آرایه را برگرداند.

    ابتدا سعی کنید با استفاده از مرتب‌سازی و ادغام مسئله را حل کنید.
    پیچیدگی زمانی این راه‌حل چقدر است؟

    n: length of longer array

    Time Complexity: O(n*lg(n))

    حال برای کاهش مدت زمان اجرای الگوریتم از انتخاب سریع استفاده کنید.

    برای کاهش پیچیدگی حافظه سعی کنید الگوریتم را به صورت درجا پیاده‌سازی کنید.
    پیچیدگی زمانی این راه‌حل چقدر است؟

    Average Time Complexity: O(n)

    Worst case Time Complexity: O(n^2)

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="43" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="43" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="arr = a + b
    size = len(arr)
    left = 0
    right = size - 1
    while True:
        pivot = random.randint(left, right)
        new_pivot = partition(arr, left, right, pivot)
        pivot_distance = new_pivot - left
        if pivot_distance == k:
            return arr[new_pivot]
        elif k < pivot_distance:
            right = new_pivot - 1
        else:
            k -= pivot_distance + 1
            left = new_pivot + 1" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="69" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="69" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="def partition(arr, left, right, pivot):
    pivot_value = arr[pivot]
    arr[pivot], arr[right] = arr[right], arr[pivot]
    new_pivot = left
    for i in range(left, right):
        if arr[i] < pivot_value:
            arr[new_pivot], arr[i] = arr[i], arr[new_pivot]
            new_pivot += 1
    arr[right], arr[new_pivot] = arr[new_pivot], arr[right]
    return new_pivot" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="import random

def find_kth(a, b, k):
    #Implement the function

#Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        ([1, 2, 3, 4], [5, 6, 7, 8, 9], 4, 5),
        ([10, 11, 12], [4, 3, 4, 1], 2, 4),
        ([1, 1, 1, 1, 1, 1], [3, 4, 6, 1], 7, 3),
        ([1], [], 0, 1),
        (random.sample(list(range(1000)), 1000), random.sample(list(range(1000, 2000)), 1000), 1010, 1010),
        (random.sample(list(range(1000)), 1000), [], 30, 30),
        ([2, 5, 1, 7, 2, 5, 9], [8, 2, 0, 1, 5, 0], 12, 9)
    ]
    for test in tests:
        test_function(test[-1], find_kth, test[0], test[1], test[2])" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه درس را مطالعه کنید.

سپس لطفا دیگر به جزوه و کدهای آن
مراجعه نکنید.

تابع ()find_kth را کامل کنید تا kاُمین عضو کوچک آرایه را با استفاده از روش median of median برگرداند.

توجه کنید که برای انجام این پیاده‌سازی باید ورودی‌ها را به دسته‌های ۷تایی تقسیم کنید.

    بیایید مراحل انجام این الگوریتم را برای خود مرور کنیم، ابتدا داده‌ها به دسته‌های ۷تایی تقسیم می‌شوند. سپس داده‌های هر دسته مرتب می‌شوند و میانه‌ی آن‌ها را به مجموعهٔ میانه‌ها اضافه می‌کنیم. میانه‌ی میانه‌ها را به صورت بازگشتی پیدا کرده و آرایه را به کمک آن به دو دسته تقسیم می‌کنیم و با توجه به اندیسی که به دنبال آن می‌گردیم در آرایه سمت راست یا چپ به طور بازگشتی به دنبال آن می‌گردیم.

    پیچیدگی زمانی این راه‌حل چقدر است؟

    Time Complexity: O(n)

    به نظرتان در حالت میانگین این الگوریتم زمان بیش‌تری طول می‌کشد یا جست‌وجوی سریع؟

    الگوریتم انتخاب سریع از میانه‌ی میانه‌ها به طور کلی سریع‌تر است.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="43" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="43" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="if len(array) <= 10:
        array.sort()
        return array[k]
    subsets = []
    num_medians = len(array) // subset_size
    if (len(array) % subset_size) > 0:
        num_medians += 1
    for i in range(num_medians):
        beg = i * subset_size
        end = min(len(array), beg + subset_size)
        subset = array[beg:end]
        subsets.append(subset)
    medians = []
    for subset in subsets:
        median = find_kth(subset, len(subset) // 2)
        medians.append(median)
    median_of_medians = find_kth(medians, len(medians) // 2)
    pivot = median_of_medians  # pivot point value (not index)
    array_lt = []
    array_gt = []
    array_eq = []
    for item in array:
        if item < pivot:
            array_lt.append(item)
        elif item > pivot:
            array_gt.append(item)
        else:
            array_eq.append(item)
    if k < len(array_lt):
        return find_kth(array_lt, k)
    elif k < len(array_lt) + len(array_eq):
        return array_eq[0]
    else:
        normalized_k = k - (len(array_lt) + len(array_eq))
        return find_kth(array_gt, normalized_k)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def find_kth(array, k, subset_size=7):
    return #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="import random

from test_helper import *
from task import *

if __name__ == '__main__':
    tests = [
        ([1, 2, 3, 4, 5, 6, 7, 8, 9], 4, 5),
        ([10, 11, 12, 4, 3, 4, 1], 2, 4),
        ([1, 1, 1, 1, 1, 1, 3, 4, 6, 1], 7, 3),
        ([1], 0, 1),
        (random.sample(list(range(1000)), 1000), 221, 221),
        ([2, 5, 1, 7, 2, 5, 9, 8, 2, 0, 1, 5, 0], 12, 9)
    ]
    for test in tests:
        test_function(test[-1], find_kth, test[0], test[1])" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="9" />
                <option name="name" value="Hashing" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="<!DOCTYPE html>

    <meta charset="UTF-8">

    پیشنیاز:

دفترچه Hash را مطالعه کنید.

یکی از روش‌های تشخیص ایرادات تایپی (typoها) در متون و پیشنهاد کلمه‌های جایگزین
استفاده از جدول درهم سازیست. در این سوال می‌خواهیم که یک مدل ساده برنامه spell checker
را پیاده سازی کنیم.

شما باید پیاده سازی توابع setup و suggestions را کامل کنید. تابع setup
یکبار در ابتدای برنامه صدا زده می‌شود و کل کلمات صحیح موجود در دیکشنری
به عنوان ورودی به آن داده می‌شود. پس از صدا زدن تابع setup، با هر بار صدا زدن
تابع suggestions این تابع باید یک دوتایی برگرداند که مقدار اول آن True است در صورتیکه
تایپ کلمه صحیح باشد(کلمه در دیکشنری موجود باشد) و در غیر اینصورت false است.
مقدار دوم این دوتایی درصورتی که در کلمه غلط نگراشی موجود نبود یک مجموعه تهی
و در غیر این صورت مجموعه‌ای از کلمات مشابه آن کلمه است. یک کلمه مشابه کلمه‌ای است که نسبت
به کلمه ورودی دقیقا یک کارکتر بیشتر یا دقیقا یک کاراکتر کمتر داشته باشد
یا اگر تعداد کاراکترها یکی بود در دقیقا یک کارکتر متفاوت باشند.
ترتیب کلمات در لیست خروجی اهمیتی ندارند. برای درک بهتر
به مثال مراجعه کنید.

مثال:

فرض کنید تابع setup با ورودی {'hello', 'bye', 'salaam', 'salam'} صدا زده شود
سپس خروجی هرکدام از توابع زیر، به شکل زیر است.

suggestions("bye")

suggestions("hallo")

suggestions("hablo")

suggestions("salaa")

suggestions("aye")

Output:

(True, set())

(False, {"hello"})

(False, set())

(False, {"salaam", "salam"})

(False, {"bye"})

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="43" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="43" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="global words
    words = set(dictionary)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="102" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="102" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="result = set()
    is_legit = word in words
    if not is_legit:
        # add char
        for i in range(len(word) + 1):
            for char in string.ascii_lowercase:
                possible = word[:i] + char + word[i:]
                if possible in words:
                    result.add(possible)
        # remove char
        for i in range(len(word)):
            possible = word[:i] + word[i + 1:]
            if possible in words:
                result.add(possible)
        # change char
        for i in range(len(word)):
            for char in string.ascii_lowercase:
                possible = word[:i] + char + word[i + 1:]
                if possible in words:
                    result.add(possible)
    return is_legit, result" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="import string

def setup(dictionary):
    return #Complete the function

def suggestions(word):
    return #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="import task
import random
import string
from test_helper import failed

def sol_setup(dictionary):
    global words
    words = set(dictionary)

def sol_suggestions(word):
    result = set()
    is_legit = word in words
    if not is_legit:
        # add char
        for i in range(len(word) + 1):
            for char in string.ascii_lowercase:
                possible = word[:i] + char + word[i:]
                if possible in words:
                    result.add(possible)
        # remove char
        for i in range(len(word)):
            possible = word[:i] + word[i + 1:]
            if possible in words:
                result.add(possible)
        # change char
        for i in range(len(word)):
            for char in string.ascii_lowercase:
                possible = word[:i] + char + word[i + 1:]
                if possible in words:
                    result.add(possible)
    return is_legit, result

if __name__ == '__main__':
    task.setup({"abc", "abcd", "g", "e", "ggh"})
    if task.suggestions("ggh") != (True, set()):
        failed("Wrong Answer!")
    if task.suggestions("abcz") != (False, {"abcd", "abc"}):
        failed("Wrong Answer!")
    if task.suggestions("gh") != (False, {"g", "ggh"}):
        failed("Wrong Answer!")
    if task.suggestions("a") != (False, {"g", "e"}):
        failed("Wrong Answer!")
    if task.suggestions("bbb") != (False, set()):
        failed("Wrong Answer!")
    if task.suggestions("bbc") != (False, {"abc"}):
        failed("Wrong Answer!")
    dic = {''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(1, 50))) for _ in range(10000)}
    test = {''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(1, 10))) for _ in range(10000)}
    task.setup(dic)
    sol_setup(dic)
    for word in test:
        if task.suggestions(word) != sol_suggestions(word):
            failed("Wrong Answer!")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="<!DOCTYPE html>

    <meta charset="UTF-8">

تابع answer را کامل کنید. این تابع به عنوان ورودی یک آرایه از اعداد arr و
یک عدد k را می‌گیرد و بررسی می‌کند که آیا ۴ عدد با اندیس‌های متمایز در آرایه وجود دارند
که مجموعشان برابر k بشود یا خیر. در صورت وجود این ۴ عدد باید آن‌ها را به شکل
یک ۴تایی برگردانید و اگر چنین ۴تایی وجود نداشت مقدار None را برگردانید. اگر بیش از یک ۴تایی
وجود داشت یکی از آن‌ها را به دلخواه برگردانید.

توجه:

در صورتی که می‌خواهید از جدول درهم‌سازی استفاده کنید، باید پیاده سازی hash_table.py
را کامل کرده و از آن استفاده کنید و نمی‌توانید از dictionary یا داده ساختارهای
مشابه پایتون استفاده کنید.

محدودیت‌ها:

اندازه آرایه arr از 3^10 بیشتر نیست

عناصر آرایه اعداد صحیح مثبت کمتر از 12^10 هستند

مثال:

answer([1, 2, 3, 4, 5], 12)

answer([1, 2, 3, 4], 20)

answer([1, 1, 1, 1, 1, 1], 4)

Output:

(1, 2, 4, 5)

None

(1, 1, 1, 1)

    یک الگوریتم بهینه برای این سوال می‌تواند در زمان (O(n^2 اجرا شود

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="hash_table.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="19" />
                                          <option name="offset" value="157" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="19" />
                                      <option name="offset" value="157" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete it" />
                                      <option name="possibleAnswer" value="return key % self._size" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="19" />
                                          <option name="offset" value="220" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="19" />
                                      <option name="offset" value="220" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete it" />
                                      <option name="possibleAnswer" value="key_hash = self._hash(key)
        self._table[key_hash].append((key, value))" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="2" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="19" />
                                          <option name="offset" value="273" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="19" />
                                      <option name="offset" value="273" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete it" />
                                      <option name="possibleAnswer" value="key_hash = self._hash(key)
        for pair in self._table[key_hash]:
            if key == pair[0]:
                return pair[1]
        return None" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="hash_table.py" />
                                <option name="text" value="class HashTable:

    def __init__(self, size):
        self._size = size
        self._table = [[] for _ in range(size)]

    def _hash(self, key):
        return #Complete it

    def insert(self, key, value):
        return #Complete it

    def get(self, key):
        return #Complete it
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="29" />
                                          <option name="offset" value="59" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="29" />
                                      <option name="offset" value="59" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete the function" />
                                      <option name="possibleAnswer" value="table = HashTable(1000003)
    for i in range(len(arr)):
        for j in range(i + 1, len(arr)):
            pair = table.get(k - arr[i] - arr[j])
            if pair is not None:
                if i not in pair and j not in pair:
                    return (arr[i], arr[j]) + (arr[pair[0]], arr[pair[1]])
            table.insert(arr[i] + arr[j], (i, j))
    return None" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from hash_table import HashTable

def answer(arr, k):
    return #Complete the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="import random
from task import answer
from test_helper import failed

def solution(arr, k):
    sums = {}
    for i in range(len(arr)):
        for j in range(i + 1, len(arr)):
            if k - arr[i] - arr[j] in sums:
                pair = sums[k - arr[i] - arr[j]]
                if i not in pair and j not in pair:
                    return (arr[i], arr[j]) + (arr[pair[0]], arr[pair[1]])
            sums[arr[i] + arr[j]] = (i, j)
    return None

def generate_test():
    return [random.randint(0, 10 ** 12) for i in range(random.randint(10, 1000))]

if __name__ == '__main__':
    if answer([0, 0, 0, 0], 100) is not None:
        failed("Wrong Answer!")
    if set(answer([10, 20, 20, 10, 40, 100], 160)) != {100, 10, 40, 10}:
        failed("Wrong Answer!")
    for i in range(5):
        arr = generate_test()
        values = random.sample(arr, 4)
        result = answer(arr, sum(values))
        if result is None or len(set(result)) < 4 or sum(result) != sum(values):
            failed("Wrong Answer!")
    for i in range(3):
        arr = generate_test()
        value = random.randint(0, 10 ** 12)
        result = answer(arr, value)
        ans = solution(arr, value)
        if ans is None and result is not None:
            failed("Wrong Answer!")
        elif ans is not None:
            if len(set(result)) < 4 or sum(result) != sum(ans):
                failed("Wrong Answer!")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="<!DOCTYPE html>

    <meta charset="UTF-8">

دوره تناوب یک دنباله seq برابر است با کوچک‌ترین عدد مثبت(نا صفر) T که به ازای هر

    i < len(seq) - T

داشته باشیم

    seq[i] = seq[i + T]

تابع period را به گونه‌ای کامل کنید که به ازای هر رشته str دوره تناوب str را
برگرداند. تضمین می‌شود که رشته ورودی دوره تناوبی کمتر از طولش دارد.

محدودیت‌ها:

سایز رشته str بیشتر از 6^10 نیست

کاراکترهای رشته حروف lowercase انگلیسی هستند.

مثال:

    period("aabbaabb")

    period("aaa")

    Output:

    4

    1

    با کمک درهم‌سازی می‌توانید مسئله را در زمان خطی حل کنید

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="32" />
                                          <option name="offset" value="21" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="32" />
                                      <option name="offset" value="21" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return "" #Complete the function" />
                                      <option name="possibleAnswer" value="p, q = 27, 10**9 + 7
    hash_list = hash(str, q, p)
    offset = p
    for T in range(1, len(str)):
        if is_period(hash_list, T, offset, q):
            return T
        offset = (offset * p) % q
    return 0" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="56" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="56" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def is_period(hash_list, T, offset, q):
    return (hash_list[len(hash_list) - T - 1] * offset) % q == (hash_list[len(hash_list) - 1] - hash_list[T - 1]) % q

def hash(str, q, p):
    hash_list = [ord(str[0]) - ord('a') + 1]
    s = 1
    for i in range(1, len(str)):
        s = (s * p) % q
        hash_list.append((hash_list[i - 1] + (ord(str[i]) - ord('a') + 1) * s) % q)
    return hash_list
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="def period(str):
    return "" #Complete the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="import random
import string
import task
from test_helper import failed

def sol(str):
    p, q = 27, 10 ** 9 + 7
    hash_list = sol_hash(str, q, p)
    offset = p
    for T in range(1, len(str)):
        if sol_is_period(hash_list, T, offset, q):
            return T
        offset = (offset * p) % q
    return None

def sol_is_period(hash_list, T, offset, q):
    return (hash_list[len(hash_list) - T - 1] * offset) % q == (hash_list[len(hash_list) - 1] - hash_list[T - 1]) % q

def sol_hash(str, q, p):
    hash_list = [ord(str[0]) - ord('a') + 1]
    s = 1
    for i in range(1, len(str)):
        s = (s * p) % q
        hash_list.append((hash_list[i - 1] + (ord(str[i]) - ord('a') + 1) * s) % q)
    return hash_list

def generate_test():
    T = random.randint(0, 10 ** 4)
    return ''.join(random.choice(string.ascii_lowercase) for i in range(T)) * (10 ** 5 // T)

if __name__ == '__main__':
    # put_limit(10)
    # try:
    for i in range(5):
        str = generate_test()
        if sol(str) != task.period(str):
            failed("Wrong Answer!")
    # except Exception:
    #     failed("Timed Out!")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="<!DOCTYPE html>

    <meta charset="UTF-8">

در این سوال می‌خواهیم با استفاده از داده ساختار جدول درهم سازی یک LRU Cache پیاده
سازی کنیم.

برای اینکار باید توابع کلاس LRU Cache را کامل کنید. هنگام ساخت LRU Cache یک عدد
به عنوان اندازه آن (size) به سازنده آن پاس داده می‌شود. این cache به این شکل کار
می‌کند که ابتدا به کمک add مقادیر را به صورت key-value در آن درج می‌کنیم و به کمک تابع get
مقادیر متناظر با کلید‌هایی که قبلا درج کرده‌ایم را بازیابی می‌کنیم. هنگامی که cache
پر شود آخرین داده استفاده شده یعنی داده‌ای که قبل از بقیه get یا add شده باشد پاک می‌شود.
برای درک بهتر به مثال مراجعه کنید.

شما باید سه تابع add, get و init کلاس LRUCache را به گونه‌ای پیاده سازی کنید که هر
 عملیات add و get به طور متوسط در زمان (۱)O قابل انجام باشد. تابع add کلید key و
مقدار value را دریافت کرده و آن را در cache درج می‌کند. تابع get در صورتیکه کلید داده شده
در cache موجود باشد value متناظر با آن را برمی‌گرداند و در غیر این صورت مقدار None
را برمی‌گرداند. تابع init نیز یک LRUCache با سایز مشخص شده می‌سازد.

نکته:

برای این سوال نیاز به پیاده سازی جدول درهم‌سازی دارید، خودتان این داده ساختار را در
فایل hash_table.py پیاده سازی کنید. برای حل مشکل برخورد از روش آدرس‌دهی باز استفاده
کنید.

مثال:

cache = LRUCache(3)

cache.add(23, 765)

cache.add(100, 100000)

cache.add(2, -309)

cache.get(23)

cache.get(2)

cache.put(0, 2)

print(cache.get(23))

print(cache.get(100))

print(cache.get(2))

print(cache.get(0))

Output:

765

None

0398

2

  قاعدتا برای پیاده سازی نیاز به صف هم دارید!

  دقت کنید برای اینکه عملیات get از مرتبه (۱)O باقی بماند باید ظرفیت
    جدول در هم سازی به مراتب بیشتر از ظرفیت cache باشد.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="4" />
                      <option name="name" value="Q4" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="hash_table.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="19" />
                                          <option name="offset" value="655" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="19" />
                                      <option name="offset" value="655" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete it" />
                                      <option name="possibleAnswer" value="for i in range(self._size):
            cell: HashTable._Cell = self._table[self._hash(key, i)]
            if cell is None or cell.is_deleted():
                self._table[self._hash(key, i)] = HashTable._Cell(key, value)
                return True
        return False" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="19" />
                                          <option name="offset" value="711" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="19" />
                                      <option name="offset" value="711" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete it" />
                                      <option name="possibleAnswer" value="for i in range(self._size):
            cell: HashTable._Cell = self._table[self._hash(key, i)]
            if cell is None:
                break
            if cell.get_key() == key:
                cell.delete()
                break" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="2" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="19" />
                                          <option name="offset" value="764" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="19" />
                                      <option name="offset" value="764" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return #Complete it" />
                                      <option name="possibleAnswer" value="for i in range(self._size):
            cell: HashTable._Cell = self._table[self._hash(key, i)]
            if cell is None:
                return None
            if not cell.is_deleted() and cell.get_key() == key:
                return cell.get_value()" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="hash_table.py" />
                                <option name="text" value="class HashTable:
    class _Cell:
        def __init__(self, key: int, value: object) -> None:
            self._key = key
            self._value = value
            self._isDeleted = False

        def get_key(self):
            return self._key

        def get_value(self):
            return self._value

        def is_deleted(self):
            return self._isDeleted

        def delete(self):
            self._isDeleted = True

    def __init__(self, size):
        self._size = size
        self._table = [None for _ in range(size)]

    def _hash(self, key, i):
        return (key + i) % self._size

    def insert(self, key, value):
        return #Complete it

    def delete(self, key):
        return #Complete it

    def get(self, key):
        return #Complete it

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="12" />
                                          <option name="offset" value="89" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="12" />
                                      <option name="offset" value="89" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete it" />
                                      <option name="possibleAnswer" value="self._time_queue = Queue(size)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="12" />
                                          <option name="offset" value="135" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="12" />
                                      <option name="offset" value="135" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete it" />
                                      <option name="possibleAnswer" value="return self._time_queue.get(key)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="2" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="12" />
                                          <option name="offset" value="188" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="12" />
                                      <option name="offset" value="188" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete it" />
                                      <option name="possibleAnswer" value="self._time_queue.push(key, value)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="3" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="203" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="203" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="class Queue:
    class Node:
        def __init__(self, prev, key, value, next):
            self.prev = prev
            self.key = key
            self.value = value
            self.next = next

    def __init__(self, size):
        self._size = 0
        self._max = size
        self._front = None
        self._rear = None
        self._hashTable = HashTable(100 * size)

    def push(self, key, value):
        if self._rear is None:
            self._rear = Queue.Node(None, key, value, None)
            self._front = self._rear
        else:
            self._rear.prev = Queue.Node(None, key, value, self._rear)
            self._rear = self._rear.prev
        self._size += 1
        if self._size > self._max:
            self.pop()
        self._hashTable.insert(key, self._rear)

    def delete(self, key):
        node = self._hashTable.get(key)
        if node.prev is not None:
            node.prev.next = node.next
        else:
            self._rear = node.next
        if node.next is not None:
            node.next.prev = node.prev
        else:
            self._front = node.prev
        self._hashTable.delete(key)
        self._size -= 1

    def pop(self):
        key = None
        if self._front is not None:
            key = self._front.key
            self._front = self._front.prev
            self._front.next = None
            self._hashTable.delete(key)
        self._size -= 1
        return key

    def get(self, key):
        node = self._hashTable.get(key)
        if node is not None:
            self.delete(key)
            self.push(key, node.value)
            return node.value
        return None" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from hash_table import HashTable

class LRUCache:
    def __init__(self, size):
        #Complete it

    def get(self, key):
        #Complete it

    def add(self, key, value):
        #Complete it

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from task import LRUCache
from test_helper import failed
import random

class LRUCacheSol:
    def __init__(self, size):
        self._time_queue = Queue(size)

    def get(self, key):
        return self._time_queue.get(key)

    def add(self, key, value):
        self._time_queue.push(key, value)

class Queue:
    class Node:
        def __init__(self, prev, key, value, next):
            self.prev = prev
            self.key = key
            self.value = value
            self.next = next

    def __init__(self, size):
        self._size = 0
        self._max = size
        self._front = None
        self._rear = None
        self._hashTable = {}

    def push(self, key, value):
        if self._rear is None:
            self._rear = Queue.Node(None, key, value, None)
            self._front = self._rear
        else:
            self._rear.prev = Queue.Node(None, key, value, self._rear)
            self._rear = self._rear.prev
        self._size += 1
        if self._size > self._max:
            self.pop()
        self._hashTable[key] = self._rear

    def delete(self, key):
        node = self._hashTable.get(key)
        if node.prev is not None:
            node.prev.next = node.next
        else:
            self._rear = node.next
        if node.next is not None:
            node.next.prev = node.prev
        else:
            self._front = node.prev
        self._hashTable.pop(key)
        self._size -= 1

    def pop(self):
        key = None
        if self._front is not None:
            key = self._front.key
            self._front = self._front.prev
            self._front.next = None
            self._hashTable.pop(key, None)
        self._size -= 1
        return key

    def get(self, key):
        if key not in self._hashTable:
            return None
        node = self._hashTable[key]
        self.delete(key)
        self.push(key, node.value)
        return node.value

if __name__ == '__main__':
    simple_cache = LRUCache(5)
    simple_cache.add(10 ** 9, 5)
    simple_cache.add(3, 20)
    simple_cache.add(4, 30)
    if simple_cache.get(10 ** 9) != 5 or simple_cache.get(3) != 20 or simple_cache.get(4) != 30:
        failed("Wrong Answer!")
    simple_cache.add(100, 1)
    simple_cache.add(101, 2)
    simple_cache.get(10 ** 9)
    simple_cache.add(102, 3)
    if simple_cache.get(3) is not None:
        failed("Wrong Answer!")
    if simple_cache.get(10 ** 9) != 5:
        failed("Wrong Answer!")
    simple_cache.get(4)
    simple_cache.get(100)
    simple_cache.add(0, 0)
    if simple_cache.get(101) is not None:
        failed("Wrong Answer!")

    cache = LRUCache(100)
    sol = LRUCacheSol(100)
    keys = random.sample(range(0, 10 ** 10), 100000)
    added = []
    if cache.get(1) is not None:
        failed("Wrong Answer!")
    for key in keys:
        if random.randint(0, 1) == 0:
            cache.add(key, key / 3)
            sol.add(key, key / 3)
            added.append(key)
        elif len(added) > 0:
            key = random.choice(added)
            if cache.get(key) != sol.get(key):
                failed("Wrong Answer!")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="10" />
                <option name="name" value="DSU" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

مطالعه نوت‌بوک DSU

بیسیم پر هزینه

متین و کیانوش دو جفت بیسیم ارزان خریدند. اما بیسیم ها محدودیت هایی دارند که
    از طریق اونها می‌توان فقط n کلمه رو فرستاد و بعضی ازین کلمه ها هم، هم معنی اند.

برای فرستادن کلمه i ام
    ai
    ثانبه زمان لازم است. کیانوش پیامی دارد که میخواهد به متین برساند. او میتواند هر کلمه در پیامش
    را با هر کلمه ی هم معنیش جابحا کند. به کیانوش کمک کنید با کمترین زمان ممکن این پیام را
    به متین برساند.

    شما باید تابع solve را که n و m و لیست کلمات و لیست زمان های فرستادن و لیست گروه های هم معنی و پیام کیانوش را
    ورودی میگیرد را پر بکنید.

 n تعداد کل کلمات است.

    m تعداد کلمات در پیام کیانوش است.

    کلمات و زمان ها در قالب 2 لیست داده میشوند.

    گروه های هم معنی در قالب لیستی از لیست ها داده میشود که در هر لیست، اندیس کلمات هم معنی
    آمده است.

    و در نهایت لیستی از کلمات کیانوش داده میشود.

    خروجی تابع مینیمم زمان فرستادن است.

    تضمین شده است که:
    $$ 1 \le n \le 10000 $$
    $$ 1 \le m \le 10000 $$

مثال ها

مثال ۱

n = 5
m = 5
words = ['i', 'loser', 'am', 'the', 'second']
times =  [100, 1, 1, 5, 10]
groups = [[0], [2], [1, 4], [3]]
message =  ['i', 'am', 'the', 'second']
output = 107

مثال ۲

n = 1
m = 1
words = ['a']
times =  [1000000000]
groups = [[0]]
message =  ['a']
output = 1000000000

    کلمات هم معنی را در یک محموعه قرار بدهید. حالا چطوری مینیمم را بدست بیاریم؟

    DSU
    را به شکل درختی پیاده سازی بکنید. و یک مقدار min به ریشه هم بدهید.

    وقتی 2 تا مجموعه را اجتماع میگیرید، min ریشه ی جدید برابر با مینیمم  min های دو ریشه ی
    قبلی است.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="1294" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="1294" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="dsu = DisjointSet(n)
    indices = {}
    for i in range(n):
        dsu.nodes[i].min = prices[i]
        indices[words[i]] = i

    for group in groups:
        for i in range(len(group)):
            dsu.union(dsu.nodes[group[0]], dsu.nodes[group[i]])

    price = 0
    for word in message:
        price += dsu.find(dsu.nodes[indices[word]]).min

    return price" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node(object):
    def __init__(self, label):
        self.label = label
        self.par = self
        self.rank = 0
        self.min = 0

class DisjointSet(object):
    def __init__(self, n):
        self.n = n
        self.nodes = [Node(i) for i in range(n)]

    def find(self, u):
        if u == u.par:
            return u
        return self.find(u.par)

    def union(self, u, v):
        u, v = self.find(u), self.find(v)
        if u == v:  # u and v are in the same component
            return False

        # making v the vertex with better rank
        if u.rank > v.rank:
            u, v = v, u

        # merging two components
        u.par = v

        # updating maximum depth as rank
        if u.rank == v.rank:
            v.rank += 1

        v.min = min(v.min, u.min)

        return True

    # Returns a list of components where each component is a list of values
    def get_all_components(self):
        comps = [[] for _ in range(self.n)]
        for node in self.nodes:
            comps[self.find(node).label].append(node.label)

        comps = [i for i in comps if i]  # Remove empty lists
        return comps

def solve(n, m, words, prices, groups, message):
    assert n == len(words)
    assert n == len(prices)
    assert m == len(message)

    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import solve
import string, random

class Node(object):
    def __init__(self, label):
        self.label = label
        self.par = self
        self.rank = 0
        self.min = 0

class DisjointSet(object):
    def __init__(self, n):
        self.n = n
        self.nodes = [Node(i) for i in range(n)]

    def find(self, u):
        if u == u.par:
            return u
        return self.find(u.par)

    def union(self, u, v):
        u, v = self.find(u), self.find(v)
        if u == v:  # u and v are in the same component
            return False

        # making v the vertex with better rank
        if u.rank > v.rank:
            u, v = v, u

        # merging two components
        u.par = v

        # updating maximum depth as rank
        if u.rank == v.rank:
            v.rank += 1

        v.min = min(v.min, u.min)

        return True

    # Returns a list of components where each component is a list of values
    def get_all_components(self):
        comps = [[] for _ in range(self.n)]
        for node in self.nodes:
            comps[self.find(node).label].append(node.label)

        comps = [i for i in comps if i]  # Remove empty lists
        return comps

def solve2(n, m, words, prices, groups, message):
    dsu = DisjointSet(n)
    indices = {}
    for i in range(n):
        dsu.nodes[i].min = prices[i]
        indices[words[i]] = i

    for group in groups:
        for i in range(len(group)):
            dsu.union(dsu.nodes[group[0]], dsu.nodes[group[i]])

    price = 0
    for word in message:
        price += dsu.find(dsu.nodes[indices[word]]).min

    return price

def string_generator(size, chars=string.ascii_lowercase):
    return ''.join(random.choice(chars) for _ in range(size))

def partition(lst, n):
    random.shuffle(lst)
    division = len(lst) / float(n)
    return [lst[int(round(division * i)): int(round(division * (i + 1)))] for i in range(n)]

if __name__ == '__main__':
    manual_tests = [
        (5, 4, ['i', 'loser', 'am', 'the', 'second'], [100, 1, 1, 5, 10], [[0], [2], [1, 4], [3]],
         ['i', 'am', 'the', 'second'], 107),

        (5, 4, ['i', 'loser', 'am', 'the', 'second'], [100, 20, 1, 5, 10], [[0], [2], [1, 4], [3]],
         ['i', 'am', 'the', 'second'], 116),

        (1, 1, ['a'], [1000000000], [[0]], ['a'], 1000000000),

        (1, 10, ['a'], [1000000000], [[0]], ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'], 10000000000),
    ]

    for test in manual_tests:
        n, m, words, prices, groups, message, ans1 = test
        ans2 = solve(n, m, words, prices, groups, message)
        if ans1 != ans2:
            failed("Wrong Answer! Input: {}, your output: {}, answer: {}".format((words, prices, groups, message), ans2,
                                                                                ans1))

        random_tests = 10
        for i in range(random_tests):
            n = random.randint(1000, 10000)
            m = random.randint(1000, 10000)
            k = random.randint(1, min(10, n))
            words = [string_generator(random.randint(10, 20)) for _ in range(n)]
            prices = [random.randint(1, 10000) for _ in range(n)]
            lst = [i for i in range(n)]
            groups = partition(lst, k)
            message = [words[random.randint(0, n - 1)] for _ in range(m)]
            ans2 = solve(n, m, words, prices, groups, message)
            ans1 = solve2(n, m, words, prices, groups, message)
            if ans2 != ans1:
                failed("Wrong Answer! Input: {}, your output: {}, answer: {}".format((words, prices, groups, message),
                                                                                ans2,
                                                                                ans1))
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

مطالعه نوت‌بوک DSU

غار یخی

کیانوش به همراه n-1 تا از دانشجویان توی یک غار یخی گیر افتادند. غار را به صورت یک
    صفحه در نظر بگیرید (از بالا). این n نفر در n نقطه ی متمایز با مختصات صحیح قرار گرفته اند و هر کدام در نقطه خود مقداری شن برای
    جلوگیری از لغزش ریخته اند.
    کیانوش برای بالا بردن روحیه ی آنها، تصمیم گرفته توی این غار لیز بخوره و به هر کدام از دانشجویان یک "خدا رو شکر" بگوید.
    ولی همانطور که حدس میزنید غار لیز است. کیانوش در یکی از ۴ جهت بالا، پایین، چپ و راست میتواند
    سُر بخوره و تا به یکی از افراد دیگر یا محلی شنی نرسد نمیتواند بایستد.

     ممکن است کیانوش نتواند با شروع از جای اولیش به همه دانشجویان برسد. شما باید مینیمم
    تعداد نقاط دیگری ای که با شنی کردنشان کیانوش بتواند کارش رو انجام دهد پیدا بکنید.

    شما باید تابع solve را که n و لیست نقاط را ورودی میگیرد را پر بکنید.

    این تابع یک عدد که مینیمم نقاط شنی اضافه هست رو برمیگرداند.

    تضمین شده است که:
    $$ 1 \le n \le 100 $$
    $$ 1 \le x_i, y_i \le 1000 $$

مثال ها

مثال 1

n = 2
points = [(2, 1), (1, 2)]
output = 1

مثال 2

n = 2
points = [(2, 1), (4, 1)]
output = 0

    اگر بشه از A به B رفت و از B به C رفت میشه از A به C هم رفت.

    نقاطی را در نظر بگیرید که بشه از هر کدوم به اونیکی رفت. اگر یک نقطه ی جدید
    را شنی کنیم چه میشود؟

    میشه مسقیما از A به B رفت اگه:
    A.x = B.x
    و یا
    A.y = B.y

    یک DSU با n تا عضو در نظر بگیرید که هر عضو متناظر یک نقطه است. اگر بشه مستقیما
    از A به B رفت، مجموعه هایشان را اجتماع بگیرید. حالا چند تا نقطه ی شنی اضافه میخواهیم؟

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="1064" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="1064" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="dsu = DisjointSet(n)
    for i in range(n):
        for j in range(i + 1, n):
            if points[i][0] == points[j][0] or points[i][1] == points[j][1]:
                dsu.unite(i, j)

    return dsu.get_count() - 1" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class DisjointSet(object):
    def __init__(self, n):
        self.n = n
        # list of components of each set
        self.set_lists = [[i] for i in range(n)]
        # pointing to the set of each component
        self.set = [i for i in range(n)]

    def find(self, u):
        return self.set[u]

    def unite(self, u, v):
        u_set, v_set = self.find(u), self.find(v)
        if u_set == v_set:  # u and v are in the same component
            return False

        # set u to the smaller list
        if len(self.set_lists[u_set]) > len(self.set_lists[v_set]):
            u_set, v_set = v_set, u_set

        # merging the smaller list into the large list
        for i in self.set_lists[u_set]:
            self.set_lists[v_set].append(i)
            # updating set of each element
            self.set[i] = v_set

        return True

    def get_count(self):
        count = 0
        for i in range(self.n):
            if self.set[i] == i:
                count += 1
        return count

def solve(n, points):
    assert len(points) == n
    #Implement the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import solve

if __name__ == '__main__':
    manual_tests = [
        (14, [(25, 23), (499, 406), (193, 266), (823, 751), (219, 227), (101, 138), (978, 992), (43, 74), (997, 932),
              (237, 189), (634, 538), (774, 740), (842, 767), (742, 802)], 13),

        (6, [(535, 699), (217, 337), (508, 780), (180, 292), (393, 112), (732, 888)], 5),

        (7, [(948, 946), (130, 130), (761, 758), (941, 938), (971, 971), (387, 385), (509, 510)], 6),

        (9, [(811, 859), (656, 676), (76, 141), (945, 951), (497, 455), (18, 55), (335, 294), (267, 275), (656, 689)],
         7),

        (1, [(321, 88)], 0),
        (11,
         [(798, 845), (722, 911), (374, 270), (629, 537), (748, 856), (831, 885), (486, 641), (751, 829), (609, 492),
          (98, 27), (654, 663)], 10),
        (17,
         [(660, 646), (440, 442), (689, 618), (441, 415), (922, 865), (950, 972), (312, 366), (203, 229), (873, 860),
          (219, 199), (344, 308), (169, 176), (961, 992), (153, 84), (201, 230), (987, 938), (834, 815)], 16),
        (24, [(171, 35), (261, 20), (4, 206), (501, 446), (961, 912), (581, 748), (946, 978), (463, 514), (841, 889),
              (341, 466), (842, 967), (54, 102), (235, 261), (925, 889), (682, 672), (623, 636), (268, 94), (635, 710),
              (474, 510), (697, 794), (586, 663), (182, 184), (806, 663), (468, 459)], 21),
        (2, [(2, 1), (4, 1)], 0),
        (2, [(2, 1), (1, 2)], 1),
        (28,
         [(462, 483), (411, 401), (118, 94), (111, 127), (5, 6), (70, 52), (893, 910), (73, 63), (818, 818), (182, 201),
          (642, 633), (900, 886), (893, 886), (684, 700), (157, 173), (953, 953), (671, 660), (224, 225), (832, 801),
          (152, 157), (601, 585), (115, 101), (739, 722), (611, 606), (659, 642), (461, 469), (702, 689), (649, 653)],
         25),
    ]

    for test in manual_tests:
        n, points, ans1 = test
        ans2 = solve(n, points)
        if ans1 != ans2:
            failed("Wrong Answer! Input: {}, your output: {}, answer: {}".format((n, points), ans2, ans1))
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

مطالعه نوت‌بوک DSU

متین و کیانوش

متین و کیانوش دوستان صمیمی هستند. اینقدر صمیمی که بگفته ی خودشان در همه چیز با هم
  هم نظرند. یک روز که با هم قصد سفر کرده بودند، هر کدام تصمیم گرفتند پیراهنی بپوشند که روی
  آن یک لوگو قرار دارد. این لوگو ها رشته هایی به طول n با حروف کوچک انگلیسی اند.
  ولی وقتی به هم میرسند، متوجه میشوند که لوگوهایشان با هم فرق میکنند.

  همانطور که میشد حدس زد، این اصلا براشون قابل قبول نیست. خوشبختانه یک خیاط در نزدیکی هست
  و میتواند آنها را کمک کند. خیاط به این طریق عمل میکند که 1 دلار برای هر یک زوج مرتب از حروف
  میگیرد. سپس در هر دو پیرهن، میتواند هر کدام ازین زوج مرتب ها را به هر تعداد بار که میخواهد
  با هم عوض کند.

  چون متین و کیانوش دوست ندارند پول زیادی خرج کنند، از شما میخواهند تا مینیمم پولی که باید
  خرج کنند تا پیرهن هایشان یکی بشن را بیابید.

  شما باید تابع solve را که n طول رشته ها و a,b که دو رشته ی n تایی هستند را میگیرد پر بکنید.

  خروجی این تابع یک دوتایی است. عضو اول مینیمم مقدار پول است.
  عضو دوم لیستی از دو تایی های حروف است که به ازای هر کدوم یدونه پول پرداخت میکنیم.

  تضمین شده است که
  n &le; 100,000

مثال ها

مثال 1

n = 3
a = 'abb'
b = 'dad'
output = [2, [('a', 'd'), ('b', 'a')]]

مثال 2

n = 8
a = 'drpepper'
b = 'cocacola'
output = [7, [('l', 'e'), ('e', 'd'), ('d', 'c'), ('p', 'c'), ('o', 'p'), ('o', 'r'), ('a', 'r')]]

  هر دو تایی که به ازایش پرداخت میکنیم را به عنوان یک یال بین آندو کاراکتر در نظر بگیرید.

  اگر ('a', 'b') و ('a', 'c') را داشته باشیم جزو خرید هامون، آیا
  ('b', 'c')
  رو هم نیاز داریم؟

  برای تغییر k تا حرف به هم باید حداقل k-1 دلار هزینه کنیم. (چرا؟)

  هر وقت یک دو تایی اضافه میشود، مانند یک اجتماع عمل میکند. (اجتماع چه مجموعه هایی؟)

  یک DSU اه 26 تایی در نظر بگیرید.
  هر وقت 2 کاراکتر توی دو رشته مساوی نبودند، باید در نهایت توی یک مجموعه باشند. پس
  اجتماع میگیریم.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="1124" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="1124" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="dsu = DisjointSet(26)
    for i in range(n):
        n1 = dsu.nodes[ord(a[i]) - ord('a')]
        n2 = dsu.nodes[ord(b[i]) - ord('a')]
        dsu.union(n1, n2)
    comps = dsu.get_all_components()

    ans = 26 - len(comps)
    rules = []
    for i in comps:
        if len(i) > 1:
            for j in range(1, len(i)):
                rules.append((chr(ord('a') + i[0]), chr(ord('a') + i[j])))

    return ans, rules" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node(object):
    def __init__(self, label):
        self.label = label
        self.par = self
        self.rank = 0

class DisjointSet(object):
    def __init__(self, n):
        self.n = n
        self.nodes = [Node(i) for i in range(n)]

    def find(self, u):
        if u == u.par:
            return u
        return self.find(u.par)

    def union(self, u, v):
        u, v = self.find(u), self.find(v)
        if u == v:  # u and v are in the same component
            return False

        # making v the vertex with better rank
        if u.rank > v.rank:
            u, v = v, u

        # merging two components
        u.par = v

        # updating maximum depth as rank
        if u.rank == v.rank:
            v.rank += 1

        return True

    # Returns a list of components where each component is a list of values
    def get_all_components(self):
        comps = [[] for _ in range(self.n)]
        for node in self.nodes:
            comps[self.find(node).label].append(node.label)

        comps = [i for i in comps if i]  # Remove empty lists
        return comps

def solve(n, a, b):
    #Implement the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import solve
import random
import string

class Node(object):
    def __init__(self, label):
        self.label = label
        self.par = self
        self.rank = 0

class DisjointSet(object):
    def __init__(self, n):
        self.n = n
        self.nodes = [Node(i) for i in range(n)]

    def find(self, u):
        if u == u.par:
            return u
        return self.find(u.par)

    def union(self, u, v):
        u, v = self.find(u), self.find(v)
        if u == v:  # u and v are in the same component
            return False

        # making v the vertex with better rank
        if u.rank > v.rank:
            u, v = v, u

        # merging two components
        u.par = v

        # updating maximum depth as rank
        if u.rank == v.rank:
            v.rank += 1

        return True

    # Returns a list of components where each component is a list of values
    def get_all_components(self):
        comps = [[] for _ in range(self.n)]
        for node in self.nodes:
            comps[self.find(node).label].append(node.label)

        comps = [i for i in comps if i]  # Remove empty lists
        return comps

def solve2(n, a, b):
    dsu = DisjointSet(26)
    for i in range(n):
        n1 = dsu.nodes[ord(a[i]) - ord('a')]
        n2 = dsu.nodes[ord(b[i]) - ord('a')]
        dsu.union(n1, n2)
    comps = dsu.get_all_components()

    ans = 26 - len(comps)
    rules = []
    for i in comps:
        if len(i) > 1:
            for j in range(1, len(i)):
                rules.append((chr(ord('a') + i[0]), chr(ord('a') + i[j])))

    return ans, rules

def check_answer(n, a, b, ans, rules):
    dsu1 = DisjointSet(26)
    for i in range(n):
        n1 = dsu1.nodes[ord(a[i]) - ord('a')]
        n2 = dsu1.nodes[ord(b[i]) - ord('a')]
        dsu1.union(n1, n2)

    dsu2 = DisjointSet(26)
    for rule in rules:
        c1, c2 = rule
        c1 = dsu2.nodes[ord(c1) - ord('a')]
        c2 = dsu2.nodes[ord(c2) - ord('a')]
        dsu2.union(c1, c2)

    for i in range(26):
        dsu1.find(dsu1.nodes[i])
        dsu2.find(dsu1.nodes[i])
    for i in range(26):
        label2 = dsu2.find(dsu2.nodes[i]).label
        n1 = dsu1.find(dsu1.nodes[label2]).label
        n2 = dsu1.find(dsu1.nodes[i]).label
        if n1 != n2:
            failed("Wrong Answer! Input: {}, your output: {}, answer: {}".format((n, a, b), (ans, rules),
                                                                                solve2(n, a, b)))

def string_generator(size, chars=string.ascii_lowercase):
    return ''.join(random.choice(chars) for _ in range(size))

if __name__ == '__main__':
    manual_tests = [
        (3, 'abb', 'dad'),
        (8, 'drpepper', 'cocacola'),
        (1, 'h', 'p'),
        (2, 'cx', 'da'),
        (3, 'bab', 'aab'),
        (15, 'xrezbaoiksvhuww', 'dcgcjrkafntbpbl'),
        (10, 'daefcecfae', 'ccdaceefca'),
        (10, 'fdfbffedbc', 'cfcdddfbed'),
        (100, 'bltlukvrharrgytdxnbjailgafwdmeowqvwwsadryzquqzvfhjnpkwvgpwvohvjwzafcxqmisgyyuidvvjqljqshflzywmcccksk',
         'jmgilzxkrvntkvqpsemrmyrasfqrofkwjwfznctwrmegghlhbbomjlojyapmrpkowqhsvwmrccfbnictnntjevynqilptaoharqv'),

        (100, 'pfkskdknmbxxslokqdliigxyvntsmaziljamlflwllvbhqnzpyvvzirhhhglsskiuogfoytcxjmospipybckwmkjhnfjddweyqqi',
         'akvzmboxlcfwccaoknrzrhvqcdqkqnywstmxinqbkftnbjmahrvexoipikkqfjjmasnxofhklxappvufpsyujdtrpjeejhznoeai'),

        (3, 'whw', 'uuh'),
        (242,
         'rrrrrrrrrrrrrmmmmmmmmmmmmmgggggggggggggwwwwwwwwwwwwwyyyyyyyyyyyyyhhhhhhhhhhhhhoooooooooooooqqqqqqqqqqqqqjjjjjjjjjjjjjvvvvvvvvvvvvvlllllllllllllnnnnnnnnnnnnnfffffffffffffeeeeeeeeaaaaaaaaiiiiiiiiuuuuuuuuzzzzzzzzbbbbbbbbxxxxxxxxttttttttsscckppdd',
         'rmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfeaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxtscsckpdpd')
    ]

    for test in manual_tests:
        n, a, b = test
        ans, rules = solve(n, a, b)
        check_answer(n, a, b, ans, rules)

    random_tests = 50
    for i in range(random_tests):
        n = random.randint(1000, 100000)
        a = string_generator(n)
        b = string_generator(n)
        ans, rules = solve(n, a, b)
        check_answer(n, a, b, ans, rules)
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="MD" />
                      <option name="descriptionText" value="

پیش‌نیازها

مطالعه نوت‌بوک DSU

آرایه جادویی

به شما آرایه ای n عضوی از اعداد نامنفی داده شده است که به دلیل ناشناحته ای اعداد
  آن یکی یکی دارند از بین میروند.
  ترتیب از بین رفتن آنها به صورت یک جایگشت از اعداد 1 تا n است.

  پس از اینکه هر عضو از بین میرود شما باید ماکسیمم جمع بلوکی از آنهایی که باقی مانده اند
  را طوری بیابید که در این بلوک هیچ کدام از بین نرفته باشند.

شما باید تابع ای به اسم solve را که n ، آرایه ی اولیه به صورت لیست و جایگشت از بین رفتن
  ها را میگیرد را پر بکنید.

  این تابع باید لیستی برگرداند که عضو i
  ام آن جواب مسئله پس از i مین گام هست.

  $$ n \le 10^5 $$
  $$ numbers_i \le 10^9 $$

مثال

مثال 1

n = 4
numbers = [1,3,2,5]
perm = [3,4,1,2]
output = [5,4,3,0]

مثال 2

n = 5
numbers = [1,2,3,4,5]
perm = [4,2,3,5,1]
output = [6,5,5,1,0]

  سعی کنید برعکس فکر کنید.

  اگر از آخر به مسئله نگاه کنیم، بجای از بین رفتن اعضا دارند دونه دونه توی آرایه قرار میگیرند.

  وقتی یک عدد ظاعر میشود، باید دو طرفش را چک کنیم که ظاهر شده اند یا نه.
  و اگر ظاهر شده بودند عدد آن افزایش پیدا میکند.

  بلوک ها تعدادی مجموعه ی مجزا اند. که یا تمام اعضای آن ظاهر شده اند یا نه.

  یک DSU برای اعداد بین 1 تا n در نظر بگیرید. وقتی عددی ظاهر میشود،
  باید مجموعه ی متناظر با اندیسش را ظاهر شده در نظر بگیرید. و 2 طرفش را چک میکنیم.
  هر کدام ظاهر شده بودند، با آن باید اجتماع بگیریم و مقدار جمع بلوک جدید را آپدیت کنیم.

  یک متغیر ans تعریف کنید و از آخر هر وقت به عقب برمیگردید، اگر حاصل جمع مجموعه ی جدیدی
  که بوجود میاید از این بیشتر بود، باید برابر آن قرار گیرد.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="4" />
                      <option name="name" value="Q4" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="1019" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="1019" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="perm2 = [i - 1 for i in perm]
    perm = perm2
    answers = []
    current_answer = 0
    dsu = DisjointSet(n)

    def add(i, current_answer):
        node = dsu.nodes[i]
        node.added = True
        node.sum = numbers[i]
        if i > 0 and dsu.nodes[i - 1].added:
            dsu.unite(node, dsu.nodes[i - 1])
        if i < n - 1 and dsu.nodes[i + 1].added:
            dsu.unite(node, dsu.nodes[i + 1])

        parent = dsu.find(node)
        current_answer = max(current_answer, parent.sum)
        return current_answer

    for i in range(n - 1, -1, -1):
        answers.append(current_answer)
        current_answer = add(perm[i], current_answer)

    answers.reverse()
    return answers" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node(object):
    def __init__(self, label):
        self.label = label
        self.par = self
        self.size = 1
        self.sum = 0
        self.added = False

class DisjointSet(object):
    def __init__(self, n):
        self.n = n
        self.nodes = [Node(i) for i in range(n)]

    def find(self, u):
        if u != u.par:  # here we user path compression trick
            u.par = self.find(u.par)
        return u.par

    def unite(self, u, v):
        u, v = self.find(u), self.find(v)
        if u == v:  # u and v are in the same component
            return False

        # making v the vertex with bigger size
        if u.size > v.size:
            u, v = v, u

        # merging two components
        u.par = v

        # updating necessary variables
        v.size += u.size
        v.sum += u.sum

        return True

def solve(n, numbers, perm):
    # numbers is a list of n integers
    # perm is a list of the numbers 1 to n in some permutation
    # Return a list of answers
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from test_helper import *
from task import *
import random

def solve2(n, numbers, perm):
    # numbers is a list of n integers
    # perm is a list of the numbers 1 to n in some permutation
    # Return a list of answers

    perm2 = [i - 1 for i in perm]
    perm = perm2
    answers = []
    current_answer = 0
    dsu = DisjointSet(n)

    def add(i, current_answer):
        node = dsu.nodes[i]
        node.added = True
        node.sum = numbers[i]
        if i > 0 and dsu.nodes[i - 1].added:
            dsu.unite(node, dsu.nodes[i - 1])
        if i < n - 1 and dsu.nodes[i + 1].added:
            dsu.unite(node, dsu.nodes[i + 1])

        parent = dsu.find(node)
        current_answer = max(current_answer, parent.sum)
        return current_answer

    for i in range(n - 1, -1, -1):
        answers.append(current_answer)
        current_answer = add(perm[i], current_answer)

    answers.reverse()
    return answers

if __name__ == '__main__':
    manual_tests = [
        (4, [1, 3, 2, 5], [3, 4, 1, 2], [5, 4, 3, 0]),
        (5, [1, 2, 3, 4, 5], [4, 2, 3, 5, 1], [6, 5, 5, 1, 0]),
        (8, [5, 5, 4, 4, 6, 6, 5, 5], [5, 2, 8, 7, 1, 3, 4, 6], [18, 16, 11, 8, 8, 6, 6, 0]),
        (10, [3, 3, 3, 5, 6, 9, 3, 1, 7, 3], [3, 4, 6, 7, 5, 1, 10, 9, 2, 8], [34, 29, 14, 11, 11, 11, 8, 3, 1, 0]),
        (17, [12, 9, 17, 5, 0, 6, 5, 1, 3, 1, 17, 17, 2, 14, 5, 1, 17],
         [3, 7, 5, 8, 12, 9, 15, 13, 11, 14, 6, 16, 17, 1, 10, 2, 4],
         [94, 78, 78, 77, 39, 39, 21, 21, 21, 21, 21, 21, 21, 9, 9, 5, 0]),
        (17, [1, 6, 9, 2, 10, 5, 15, 16, 17, 14, 17, 3, 9, 8, 12, 0, 2],
         [9, 13, 15, 14, 16, 17, 11, 10, 12, 4, 6, 5, 7, 8, 2, 3, 1],
         [65, 64, 64, 64, 64, 64, 64, 64, 64, 46, 31, 31, 16, 16, 9, 1, 0]),
        (17, [10, 10, 3, 9, 8, 0, 10, 13, 11, 8, 11, 1, 6, 9, 2, 10, 5],
         [9, 4, 13, 2, 6, 15, 11, 5, 16, 10, 7, 3, 14, 1, 12, 8, 17],
         [63, 52, 31, 31, 26, 23, 23, 23, 23, 23, 13, 13, 13, 13, 13, 5, 0]),
        (10,
         [606976827, 581094359, 726836550, 554157795, 277900063, 389778978, 555756858, 259222039, 862348978, 749561490],
         [10, 8, 9, 5, 2, 1, 6, 3, 4, 7],
         [4814072447, 3692501430, 3692501430, 2469065531, 1280994345, 1280994345, 1280994345, 555756858, 555756858, 0]),
    ]

    for test in manual_tests:
        test_function(test[-1], solve, test[0], test[1], test[2])

    random_tests = 100
    for i in range(random_tests):
        n = random.randint(1000, 10000)
        nums = []
        for i in range(n):
            nums.append(random.randint(0, 1000000000))
        perm = list(range(1, n + 1))
        random.shuffle(perm)
        x = solve2(n, nums, perm)
        test_function(x, solve, n, nums, perm)
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="11" />
                <option name="name" value="Balanced BSTs" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه Balanced BSTs را مطالعه کنید.

<meta charset="UTF-8">
یک درخت دودویی جست و جوی تهی داریم(درخت جست و جوی معمولی است و متوازن نیست). لیستی از اعداد متمایز

به ما داده شده است. می خواهیم بدانیم که اگر اعضای این لیست را یکی یکی در درخت درج کنیم، عمق هر عضو چقدر است. از آنجایی که یکی یکی درج کردن این اعضا در درخت، از نظر زمانی مقدور به صرفه نیست، برنامه ای بنویسید که بتواند عمق اعضا را حساب کند.

تابع

  func(li)

&nbsp;
را پیاده سازی کنید که ورودی لیستی از اعداد است که قرار است به نوبت در درخت ما درج شوند و خروجی، عمق هر عضو هنگام درج است.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="rb_tree.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="rb_tree.py" />
                                <option name="text" value=""""
A classic (not left-leaning) Red-Black Tree implementation, supporting addition and deletion.
"""

# The possible Node colors
BLACK = 'BLACK'
RED = 'RED'
NIL = 'NIL'

class Node:
    def __init__(self, value, color, parent, left=None, right=None):
        self.value = value
        self.color = color
        self.parent = parent
        self.left = left
        self.right = right

    def __repr__(self):
        return '{color} {val} Node'.format(color=self.color, val=self.value)

    def __iter__(self):
        if self.left.color != NIL:
            yield from self.left.__iter__()

        yield self.value

        if self.right.color != NIL:
            yield from self.right.__iter__()

    def __eq__(self, other):
        if self.color == NIL and self.color == other.color:
            return True

        if self.parent is None or other.parent is None:
            parents_are_same = self.parent is None and other.parent is None
        else:
            parents_are_same = self.parent.value == other.parent.value and self.parent.color == other.parent.color
        return self.value == other.value and self.color == other.color and parents_are_same

    def has_children(self) -> bool:
        """ Returns a boolean indicating if the node has children """
        return bool(self.get_children_count())

    def get_children_count(self) -> int:
        """ Returns the number of NOT NIL children the node has """
        if self.color == NIL:
            return 0
        return sum([int(self.left.color != NIL), int(self.right.color != NIL)])

class RedBlackTree:
    # every node has null nodes as children initially, create one such object for easy management
    NIL_LEAF = Node(value=None, color=NIL, parent=None)

    def __init__(self):
        self.count = 0
        self.root = None
        self.ROTATIONS = {
            # Used for deletion and uses the sibling's relationship with his parent as a guide to the rotation
            'L': self._right_rotation,
            'R': self._left_rotation
        }

    def __iter__(self):
        if not self.root:
            return list()
        yield from self.root.__iter__()

    def add(self, value):
        if not self.root:
            self.root = Node(value, color=BLACK, parent=None, left=self.NIL_LEAF, right=self.NIL_LEAF)
            self.count += 1
            return
        parent, node_dir = self._find_parent(value)
        if node_dir is None:
            return  # value is in the tree
        new_node = Node(value=value, color=RED, parent=parent, left=self.NIL_LEAF, right=self.NIL_LEAF)
        if node_dir == 'L':
            parent.left = new_node
        else:
            parent.right = new_node

        self._try_rebalance(new_node)
        self.count += 1

    def remove(self, value):
        """
        Try to get a node with 0 or 1 children.
        Either the node we're given has 0 or 1 children or we get its successor.
        """
        node_to_remove = self.find_node(value)
        if node_to_remove is None:  # node is not in the tree
            return
        if node_to_remove.get_children_count() == 2:
            # find the in-order successor and replace its value.
            # then, remove the successor
            successor = self._find_in_order_successor(node_to_remove)
            node_to_remove.value = successor.value  # switch the value
            node_to_remove = successor

        # has 0 or 1 children!
        self._remove(node_to_remove)
        self.count -= 1

    def contains(self, value) -> bool:
        """ Returns a boolean indicating if the given value is present in the tree """
        return bool(self.find_node(value))

    def ceil(self, value) -> int or None:
        """
        Given a value, return the closest value that is equal or bigger than it,
        returning None when no such exists
        """
        if self.root is None: return None
        last_found_val = None if self.root.value < value else self.root.value

        def find_ceil(node):
            nonlocal last_found_val
            if node == self.NIL_LEAF:
                return None
            if node.value == value:
                last_found_val = node.value
                return node.value
            elif node.value < value:
                # go right
                return find_ceil(node.right)
            else:
                # this node is bigger, save its value and go left
                last_found_val = node.value

                return find_ceil(node.left)
        find_ceil(self.root)
        return last_found_val

    def floor(self, value) -> int or None:
        """
        Given a value, return the closest value that is equal or less than it,
        returning None when no such exists
        """
        if self.root is None: return None
        last_found_val = None if self.root.value > value else self.root.value

        def find_floor(node):
            nonlocal last_found_val
            if node == self.NIL_LEAF:
                return None
            if node.value == value:
                last_found_val = node.value
                return node.value
            elif node.value < value:
                # this node is smaller, save its value and go right, trying to find a cloer one
                last_found_val = node.value

                return find_floor(node.right)
            else:
                return find_floor(node.left)

        find_floor(self.root)
        return last_found_val

    def _remove(self, node):
        """
        Receives a node with 0 or 1 children (typically some sort of successor)
        and removes it according to its color/children
        :param node: Node with 0 or 1 children
        """
        left_child = node.left
        right_child = node.right
        not_nil_child = left_child if left_child != self.NIL_LEAF else right_child
        if node == self.root:
            if not_nil_child != self.NIL_LEAF:
                # if we're removing the root and it has one valid child, simply make that child the root
                self.root = not_nil_child
                self.root.parent = None
                self.root.color = BLACK
            else:
                self.root = None
        elif node.color == RED:
            if not node.has_children():
                # Red node with no children, the simplest remove
                self._remove_leaf(node)
            else:
                """
                Since the node is red he cannot have a child.
                If he had a child, it'd need to be black, but that would mean that
                the black height would be bigger on the one side and that would make our tree invalid
                """
                raise Exception('Unexpected behavior')
        else:  # node is black!
            if right_child.has_children() or left_child.has_children():  # sanity check
                raise Exception('The red child of a black node with 0 or 1 children'
                                ' cannot have children, otherwise the black height of the tree becomes invalid! ')
            if not_nil_child.color == RED:
                """
                Swap the values with the red child and remove it  (basically un-link it)
                Since we're a node with one child only, we can be sure that there are no nodes below the red child.
                """
                node.value = not_nil_child.value
                node.left = not_nil_child.left
                node.right = not_nil_child.right
            else:  # BLACK child
                # 6 cases :o
                self._remove_black_node(node)

    def _remove_leaf(self, leaf):
        """ Simply removes a leaf node by making it's parent point to a NIL LEAF"""
        if leaf.value >= leaf.parent.value:
            # in those weird cases where they're equal due to the successor swap
            leaf.parent.right = self.NIL_LEAF
        else:
            leaf.parent.left = self.NIL_LEAF

    def _remove_black_node(self, node):
        """
        Loop through each case recursively until we reach a terminating case.
        What we're left with is a leaf node which is ready to be deleted without consequences
        """
        self.__case_1(node)
        self._remove_leaf(node)

    def __case_1(self, node):
        """
        Case 1 is when there's a double black node on the root
        Because we're at the root, we can simply remove it
        and reduce the black height of the whole tree.

            __|10B|__                  __10B__
           /         \      ==>       /       \
          9B         20B            9B        20B
        """
        if self.root == node:
            node.color = BLACK
            return
        self.__case_2(node)

    def __case_2(self, node):
        """
        Case 2 applies when
            the parent is BLACK
            the sibling is RED
            the sibling's children are BLACK or NIL
        It takes the sibling and rotates it

                         40B                                              60B
                        /   \       --CASE 2 ROTATE-->                   /   \
                    |20B|   60R       LEFT ROTATE                      40R   80B
    DBL BLACK IS 20----^   /   \      SIBLING 60R                     /   \
                         50B    80B                                |20B|  50B
            (if the sibling's direction was left of it's parent, we would RIGHT ROTATE it)
        Now the original node's parent is RED
        and we can apply case 4 or case 6
        """
        parent = node.parent
        sibling, direction = self._get_sibling(node)
        if sibling.color == RED and parent.color == BLACK and sibling.left.color != RED and sibling.right.color != RED:
            self.ROTATIONS[direction](node=None, parent=sibling, grandfather=parent)
            parent.color = RED
            sibling.color = BLACK
            return self.__case_1(node)
        self.__case_3(node)

    def __case_3(self, node):
        """
        Case 3 deletion is when:
            the parent is BLACK
            the sibling is BLACK
            the sibling's children are BLACK
        Then, we make the sibling red and
        pass the double black node upwards

                            Parent is black
               ___50B___    Sibling is black                       ___50B___
              /         \   Sibling's children are black          /         \
           30B          80B        CASE 3                       30B        |80B|  Continue with other cases
          /   \        /   \        ==>                        /  \        /   \
        20B   35R    70B   |90B|<---REMOVE                   20B  35R     70R   X
              /  \                                               /   \
            34B   37B                                          34B   37B
        """
        parent = node.parent
        sibling, _ = self._get_sibling(node)
        if (sibling.color == BLACK and parent.color == BLACK
           and sibling.left.color != RED and sibling.right.color != RED):
            # color the sibling red and forward the double black node upwards
            # (call the cases again for the parent)
            sibling.color = RED
            return self.__case_1(parent)  # start again

        self.__case_4(node)

    def __case_4(self, node):
        """
        If the parent is red and the sibling is black with no red children,
        simply swap their colors
        DB-Double Black
                __10R__                   __10B__        The black height of the left subtree has been incremented
               /       \                 /       \       And the one below stays the same
             DB        15B      ===>    X        15R     No consequences, we're done!
                      /   \                     /   \
                    12B   17B                 12B   17B
        """
        parent = node.parent
        if parent.color == RED:
            sibling, direction = self._get_sibling(node)
            if sibling.color == BLACK and sibling.left.color != RED and sibling.right.color != RED:
                parent.color, sibling.color = sibling.color, parent.color  # switch colors
                return  # Terminating
        self.__case_5(node)

    def __case_5(self, node):
        """
        Case 5 is a rotation that changes the circumstances so that we can do a case 6
        If the closer node is red and the outer BLACK or NIL, we do a left/right rotation, depending on the orientation
        This will showcase when the CLOSER NODE's direction is RIGHT

              ___50B___                                                    __50B__
             /         \                                                  /       \
           30B        |80B|  <-- Double black                           35B      |80B|        Case 6 is now
          /  \        /   \      Closer node is red (35R)              /   \      /           applicable here,
        20B  35R     70R   X     Outer is black (20B)               30R    37B  70R           so we redirect the node
            /   \                So we do a LEFT ROTATION          /   \                      to it :)
          34B  37B               on 35R (closer node)           20B   34B
        """
        sibling, direction = self._get_sibling(node)
        closer_node = sibling.right if direction == 'L' else sibling.left
        outer_node = sibling.left if direction == 'L' else sibling.right
        if closer_node.color == RED and outer_node.color != RED and sibling.color == BLACK:
            if direction == 'L':
                self._left_rotation(node=None, parent=closer_node, grandfather=sibling)
            else:
                self._right_rotation(node=None, parent=closer_node, grandfather=sibling)
            closer_node.color = BLACK
            sibling.color = RED

        self.__case_6(node)

    def __case_6(self, node):
        """
        Case 6 requires
            SIBLING to be BLACK
            OUTER NODE to be RED
        Then, does a right/left rotation on the sibling
        This will showcase when the SIBLING's direction is LEFT

                            Double Black
                    __50B__       |                               __35B__
                   /       \      |                              /       \
      SIBLING--> 35B      |80B| <-                             30R       50R
                /   \      /                                  /   \     /   \
             30R    37B  70R   Outer node is RED            20B   34B 37B    80B
            /   \              Closer node doesn't                           /
         20B   34B                 matter                                   70R
                               Parent doesn't
                                   matter
                               So we do a right rotation on 35B!
        """
        sibling, direction = self._get_sibling(node)
        outer_node = sibling.left if direction == 'L' else sibling.right

        def __case_6_rotation(direction):
            parent_color = sibling.parent.color
            self.ROTATIONS[direction](node=None, parent=sibling, grandfather=sibling.parent)
            # new parent is sibling
            sibling.color = parent_color
            sibling.right.color = BLACK
            sibling.left.color = BLACK

        if sibling.color == BLACK and outer_node.color == RED:
            return __case_6_rotation(direction)  # terminating

        raise Exception('We should have ended here, something is wrong')

    def _try_rebalance(self, node):
        """
        Given a red child node, determine if there is a need to rebalance (if the parent is red)
        If there is, rebalance it
        """
        parent = node.parent
        value = node.value
        if (parent is None  # what the fuck? (should not happen)
           or parent.parent is None  # parent is the root
           or (node.color != RED or parent.color != RED)):  # no need to rebalance
            return
        grandfather = parent.parent
        node_dir = 'L' if parent.value > value else 'R'
        parent_dir = 'L' if grandfather.value > parent.value else 'R'
        uncle = grandfather.right if parent_dir == 'L' else grandfather.left
        general_direction = node_dir + parent_dir

        if uncle == self.NIL_LEAF or uncle.color == BLACK:
            # rotate
            if general_direction == 'LL':
                self._right_rotation(node, parent, grandfather, to_recolor=True)
            elif general_direction == 'RR':
                self._left_rotation(node, parent, grandfather, to_recolor=True)
            elif general_direction == 'LR':
                self._right_rotation(node=None, parent=node, grandfather=parent)
                # due to the prev rotation, our node is now the parent
                self._left_rotation(node=parent, parent=node, grandfather=grandfather, to_recolor=True)
            elif general_direction == 'RL':
                self._left_rotation(node=None, parent=node, grandfather=parent)
                # due to the prev rotation, our node is now the parent
                self._right_rotation(node=parent, parent=node, grandfather=grandfather, to_recolor=True)
            else:
                raise Exception("{} is not a valid direction!".format(general_direction))
        else:  # uncle is RED
            self._recolor(grandfather)

    def __update_parent(self, node, parent_old_child, new_parent):
        """
        Our node 'switches' places with the old child
        Assigns a new parent to the node.
        If the new_parent is None, this means that our node becomes the root of the tree
        """
        node.parent = new_parent
        if new_parent:
            # Determine the old child's position in order to put node there
            if new_parent.value > parent_old_child.value:
                new_parent.left = node
            else:
                new_parent.right = node
        else:
            self.root = node

    def _right_rotation(self, node, parent, grandfather, to_recolor=False):
        grand_grandfather = grandfather.parent
        self.__update_parent(node=parent, parent_old_child=grandfather, new_parent=grand_grandfather)

        old_right = parent.right
        parent.right = grandfather
        grandfather.parent = parent

        grandfather.left = old_right  # save the old right values
        old_right.parent = grandfather

        if to_recolor:
            parent.color = BLACK
            node.color = RED
            grandfather.color = RED

    def _left_rotation(self, node, parent, grandfather, to_recolor=False):
        grand_grandfather = grandfather.parent
        self.__update_parent(node=parent, parent_old_child=grandfather, new_parent=grand_grandfather)

        old_left = parent.left
        parent.left = grandfather
        grandfather.parent = parent

        grandfather.right = old_left  # save the old left values
        old_left.parent = grandfather

        if to_recolor:
            parent.color = BLACK
            node.color = RED
            grandfather.color = RED

    def _recolor(self, grandfather):
        grandfather.right.color = BLACK
        grandfather.left.color = BLACK
        if grandfather != self.root:
            grandfather.color = RED
        self._try_rebalance(grandfather)

    def _find_parent(self, value):
        """ Finds a place for the value in our binary tree"""
        def inner_find(parent):
            """
            Return the appropriate parent node for our new node as well as the side it should be on
            """
            if value == parent.value:
                return None, None
            elif parent.value < value:
                if parent.right.color == NIL:  # no more to go
                    return parent, 'R'
                return inner_find(parent.right)
            elif value < parent.value:
                if parent.left.color == NIL:  # no more to go
                    return parent, 'L'
                return inner_find(parent.left)

        return inner_find(self.root)

    def find_node(self, value):
        def inner_find(root):
            if root is None or root == self.NIL_LEAF:
                return None
            if value > root.value:
                return inner_find(root.right)
            elif value < root.value:
                return inner_find(root.left)
            else:
                return root

        found_node = inner_find(self.root)
        return found_node

    def _find_in_order_successor(self, node):
        right_node = node.right
        left_node = right_node.left
        if left_node == self.NIL_LEAF:
            return right_node
        while left_node.left != self.NIL_LEAF:
            left_node = left_node.left
        return left_node

    def _get_sibling(self, node):
        """
        Returns the sibling of the node, as well as the side it is on
        e.g

            20 (A)
           /     \
        15(B)    25(C)

        _get_sibling(25(C)) => 15(B), 'R'
        """
        parent = node.parent
        if node.value >= parent.value:
            sibling = parent.left
            direction = 'L'
        else:
            sibling = parent.right
            direction = 'R'
        return sibling, direction
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="830" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="830" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="tree = RedBlackTree()
    depths = []
    for num in li:
        next_node = tree.ceil(My_pair(num, None))
        prev_node = tree.floor(My_pair(num, None))
        parent_depth = -1
        for node in (next_node, prev_node):
            if node != None:
                parent_depth = max(parent_depth, node.value)
        tree.add(My_pair(num, parent_depth + 1))
        depths.append(parent_depth + 1)
    return depths" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from rb_tree import RedBlackTree
from random import shuffle

class My_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

    def increment_value(self):
        self.value += 1

    def __lt__(self, other):
        return self.key < other.key

    def __le__(self, other):
        return self.key <= other.key

    def __gt__(self, other):
        return self.key > other.key

    def __ge__(self, other):
        return self.key >= other.key

    def __eq__(self, other):
        if self is None or other is None:
            return self is None and other is None
        return self.key == other.key

    def __ne__(self, other):
        return not self == other

def main():
    n = 10
    li = [i for i in range(n)]
    shuffle(li)
    print(li)
    print(func(li))

def func(li):
    #Implement the function

if __name__ == '__main__':
    main()
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task_copy.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task_copy.py" />
                                <option name="text" value="from rb_tree import RedBlackTree
from random import shuffle

class My_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

    def increment_value(self):
        self.value += 1

    def __lt__(self, other):
        return self.key < other.key

    def __le__(self, other):
        return self.key <= other.key

    def __gt__(self, other):
        return self.key > other.key

    def __ge__(self, other):
        return self.key >= other.key

    def __eq__(self, other):
        if self is None or other is None:
            return self is None and other is None
        return self.key == other.key

    def __ne__(self, other):
        return not self == other

def main():
    n = 10
    li = [i for i in range(n)]
    shuffle(li)
    print(li)
    print(func(li))

def func(li):
    tree = RedBlackTree()
    depths = []
    for num in li:
        next_node = tree.ceil(My_pair(num, None))
        prev_node = tree.floor(My_pair(num, None))
        parent_depth = -1
        for node in (next_node, prev_node):
            if node != None:
                parent_depth = max(parent_depth, node.value)
        tree.add(My_pair(num, parent_depth + 1))
        depths.append(parent_depth + 1)
    return depths

if __name__ == '__main__':
    main()
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="false" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from random import shuffle
from random import randint
from task import func as func
from task_copy import func as func_judge

def test_generator(n):
    li = [i for i in range(n)]
    shuffle(li)
    return li

if __name__ == '__main__':
    test_nums = [10, 10, 100, 100, 10000]
    for test_num in test_nums:
        li = test_generator(test_num)
        user_li = func(li[0:len(li)])
        judge_li = func_judge(li[0:len(li)])
        if user_li != judge_li:
            failed("Wrong Answer! Input: " + str(li) +
                   " Your Answer: " + str(user_li) +
                   " Expected Answer: " + str(judge_li))
    print("PASS")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
<meta charset="UTF-8">

  فرض کنید که به تمامی اعداد طبیعی، ارزش ۰ را نسبت داده ایم. داده ساختاری پیاده سازی کنید که قابلیت انجام
  کار های زیر را داشته باشد.

      ارزش نقطه x را y واحد افزایش دهد

      مجموع ارزش های نقاطی که از x کمتر مساوی هستند را خروجی دهد

  برای این کار
  باید تابع

data_structure(li)

&nbsp;

  را  پیاده سازی کنید.
   ورودی یک لیست از درخواست ها و هر درخواست خود یک توپل است که اگر عضو اول آن ۱ باشد، درخواست از نوع اول بوده و ۲ عضو بعدی
  توپل مقادیر
  x و y است.
  اگر هم عضو اول آن ۲ بود، مقدار بعدی x است. خروجی باید یک لیست از جواب ها باشد
(یعنی هر عضو آن خروجی متناظر با یکی از درخواست های نوع دوم است)
.
اعداد در محدوده int هستند.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="22" />
                                          <option name="offset" value="5532" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="22" />
                                      <option name="offset" value="5532" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete the function" />
                                      <option name="possibleAnswer" value="x = Tree()
    output = []
    for cmd in li:
        if cmd[0] == 1:
            num = int(cmd[1])
            amount = int(cmd[2])
            x.increase_value(num, amount)
        else:
            num = int(cmd[1])
            output.append(x.sum_range_zero(My_pair(num, None)))
    return output" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Node:
    def __init__(self, key=None, red=False, parent=None, children=None):
        self.key = key
        self.red = red
        self.parent = parent
        self.children = children
        self.num_nodes = 0
        self.sum_nodes = 0

    def refresh_features(self):
        self.num_nodes = 1 + sum([child.num_nodes for child in self.children])
        self.sum_nodes = self.key.value + sum([child.sum_nodes for child in self.children])

    def get_direction(self):
        return 0 if self == self.parent.children[0] else 1

    def get_brother(self):
        return self.parent.children[1 - self.get_direction()]

    def get_uncle(self):
        return self.parent.get_brother()

    def make_black(self):
        self.red = False

    def make_red(self):
        self.red = True

class Tree:
    def __init__(self):
        self.dummy_parent = Node(children=[None])
        self.dummy_parent.children[0] = Node(parent=self.dummy_parent)
        self.nil = self.root
        self.nil.num_nodes = 0
        self.nil.sum_nodes = 0

    def insert(self, key):
        node = self.root
        node_parent = node.parent
        direction = 0
        while node != self.nil:
            node_parent = node
            direction = 0 if key < node.key else 1
            node = node.children[direction]
        # create new node
        node_parent.children[direction] = Node(key, red=True, parent=node_parent, children=[self.nil] * 2)
        # refresh features
        node = node_parent.children[direction]
        while node != self.dummy_parent:
            node.refresh_features()
            node = node.parent

        self.cleanup_insert(node_parent.children[direction])

    def cleanup_insert(self, node):
        while node != self.root and node.parent.red:
            uncle = node.get_uncle()
            if uncle.red:
                uncle.make_black()
                node.parent.make_black()
                node.parent.parent.make_red()
                node = node.parent.parent
                continue
            # Save the value of grandparent because the rotation in the "if" staement below will mess up order of nodes
            grand_parent = node.parent.parent
            direction = node.get_direction()
            if direction != node.parent.get_direction():
                self.rotate(node.parent, 1 - direction)
                direction = 1 - direction
            self.rotate(grand_parent, 1 - direction)
            grand_parent.make_red()
            grand_parent.parent.make_black()
            # rotations should terminate loop
            break
        # Root should always be black
        self.root.make_black()

    def rotate(self, node, direction):
        child = node.children[1 - direction]
        mid_child = child.children[direction]
        parent = node.parent

        parent.children[node.get_direction()] = child
        child.parent = parent

        child.children[direction] = node
        node.parent = child

        node.children[1 - direction] = mid_child
        mid_child.parent = node

        node.refresh_features()
        child.refresh_features()

    def in_order(self, node=None):
        if node is None:
            node = self.root
        if node == self.nil:
            return []
        return self.in_order(node.children[0]) + [node] + self.in_order(node.children[1])

    def rank(self, key):
        node = self.root
        num_smaller_or_equal = 0
        while node != self.nil:
            if key < node.key:
                node = node.children[0]
                continue
            num_smaller_or_equal += node.children[0].num_nodes + 1
            if key > node.key:
                node = node.children[1]
            else:
                break
        return num_smaller_or_equal

    def increase_value(self, key, amount):
        node = self.root
        while node != self.nil:
            if key < node.key.key:
                node = node.children[0]
            elif key > node.key.key:
                node = node.children[1]
            else:
                break
        if node == self.nil:
            self.insert(My_pair(key, amount))
        else:
            node.key.value += amount
            while node != self.dummy_parent:
                node.refresh_features()
                node = node.parent

    def sum_range_zero(self, key):
        node = self.root
        sum_smaller_or_equal = 0
        while node != self.nil:
            if key < node.key:
                node = node.children[0]
                continue
            sum_smaller_or_equal += node.sum_nodes - node.children[1].sum_nodes
            if key > node.key:
                node = node.children[1]
            else:
                break
        return sum_smaller_or_equal

    @property
    def root(self):
        return self.dummy_parent.children[0]

class My_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

    def increment_value(self):
        self.value += 1

    def __lt__(self, other):
        return self.key < other.key

    def __le__(self, other):
        return self.key <= other.key

    def __gt__(self, other):
        return self.key > other.key

    def __ge__(self, other):
        return self.key >= other.key

    def __eq__(self, other):
        if self is None or other is None:
            return self is None and other is None
        return self.key == other.key

    def __ne__(self, other):
        return not self == other

def data_structure(li):
    #Complete the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task_copy.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task_copy.py" />
                                <option name="text" value="# TODO: type solution here
class Node:
    def __init__(self, key=None, red=False, parent=None, children=None):
        self.key = key
        self.red = red
        self.parent = parent
        self.children = children
        self.num_nodes = 0
        self.sum_nodes = 0

    def refresh_features(self):
        self.num_nodes = 1 + sum([child.num_nodes for child in self.children])
        self.sum_nodes = self.key.value + sum([child.sum_nodes for child in self.children])

    def get_direction(self):
        return 0 if self == self.parent.children[0] else 1

    def get_brother(self):
        return self.parent.children[1 - self.get_direction()]

    def get_uncle(self):
        return self.parent.get_brother()

    def make_black(self):
        self.red = False

    def make_red(self):
        self.red = True

class Tree:
    def __init__(self):
        self.dummy_parent = Node(children=[None])
        self.dummy_parent.children[0] = Node(parent=self.dummy_parent)
        self.nil = self.root
        self.nil.num_nodes = 0
        self.nil.sum_nodes = 0

    def insert(self, key):
        node = self.root
        node_parent = node.parent
        direction = 0
        while node != self.nil:
            node_parent = node
            direction = 0 if key < node.key else 1
            node = node.children[direction]
        # create new node
        node_parent.children[direction] = Node(key, red=True, parent=node_parent, children=[self.nil] * 2)
        # refresh features
        node = node_parent.children[direction]
        while node != self.dummy_parent:
            node.refresh_features()
            node = node.parent

        self.cleanup_insert(node_parent.children[direction])

    def cleanup_insert(self, node):
        while node != self.root and node.parent.red:
            uncle = node.get_uncle()
            if uncle.red:
                uncle.make_black()
                node.parent.make_black()
                node.parent.parent.make_red()
                node = node.parent.parent
                continue
            # Save the value of grandparent because the rotation in the "if" staement below will mess up order of nodes
            grand_parent = node.parent.parent
            direction = node.get_direction()
            if direction != node.parent.get_direction():
                self.rotate(node.parent, 1 - direction)
                direction = 1 - direction
            self.rotate(grand_parent, 1 - direction)
            grand_parent.make_red()
            grand_parent.parent.make_black()
            # rotations should terminate loop
            break
        # Root should always be black
        self.root.make_black()

    def rotate(self, node, direction):
        child = node.children[1 - direction]
        mid_child = child.children[direction]
        parent = node.parent

        parent.children[node.get_direction()] = child
        child.parent = parent

        child.children[direction] = node
        node.parent = child

        node.children[1 - direction] = mid_child
        mid_child.parent = node

        node.refresh_features()
        child.refresh_features()

    def in_order(self, node=None):
        if node is None:
            node = self.root
        if node == self.nil:
            return []
        return self.in_order(node.children[0]) + [node] + self.in_order(node.children[1])

    def rank(self, key):
        node = self.root
        num_smaller_or_equal = 0
        while node != self.nil:
            if key < node.key:
                node = node.children[0]
                continue
            num_smaller_or_equal += node.children[0].num_nodes + 1
            if key > node.key:
                node = node.children[1]
            else:
                break
        return num_smaller_or_equal

    def increase_value(self, key, amount):
        node = self.root
        while node != self.nil:
            if key < node.key.key:
                node = node.children[0]
            elif key > node.key.key:
                node = node.children[1]
            else:
                break
        if node == self.nil:
            self.insert(My_pair(key, amount))
        else:
            node.key.value += amount
            while node != self.dummy_parent:
                node.refresh_features()
                node = node.parent

    def sum_range_zero(self, key):
        node = self.root
        sum_smaller_or_equal = 0
        while node != self.nil:
            if key < node.key:
                node = node.children[0]
                continue
            sum_smaller_or_equal += node.sum_nodes - node.children[1].sum_nodes
            if key > node.key:
                node = node.children[1]
            else:
                break
        return sum_smaller_or_equal

    @property
    def root(self):
        return self.dummy_parent.children[0]

class My_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

    def increment_value(self):
        self.value += 1

    def __lt__(self, other):
        return self.key < other.key

    def __le__(self, other):
        return self.key <= other.key

    def __gt__(self, other):
        return self.key > other.key

    def __ge__(self, other):
        return self.key >= other.key

    def __eq__(self, other):
        if self is None or other is None:
            return self is None and other is None
        return self.key == other.key

    def __ne__(self, other):
        return not self == other

def data_structure(li):
    x = Tree()
    output = []
    for cmd in li:
        if cmd[0] == 1:
            num = int(cmd[1])
            amount = int(cmd[2])
            x.increase_value(num, amount)
        else:
            num = int(cmd[1])
            output.append(x.sum_range_zero(My_pair(num, None)))
    return output
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="false" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from random import shuffle
from random import randint
from task import data_structure as func
from task_copy import data_structure as func_judge

def test_generator(n):
    li = []
    for i in range(n):
        kind = randint(1, 2)
        max_range = 10000
        if kind == 1:
            li.append((1, randint(1, max_range), randint(1, max_range)))
        else:
            li.append((2, randint(1, max_range)))
    return li
if __name__ == '__main__':
    test_nums = [10, 10, 100, 100, 10000]
    for test_num in test_nums:
        li = test_generator(test_num)
        user_li = func(li[0:len(li)])
        judge_li = func_judge(li[0:len(li)])
        if user_li != judge_li:
            failed("Wrong Answer! Input: " + str(li) +
                   " Your Answer: " + str(user_li) +
                   " Expected Answer: " + str(judge_li))
    print("PASS")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
<meta charset="UTF-8">
برنامه ای بنویسید که یک لیست از اعداد متمایز را ورودی بگیرد و
تعداد جفت هایی که خاصیت زیر را دارند، خروجی دهد.

  i < j, a[i] > 2 * a[j]

برای این کار باید تابع

func(li)

&nbsp;
را پیاده سازی کنید که ورودی آن لیست اعداد و خروجی آن تعداد جفت های مورد نظر است

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="22" />
                                          <option name="offset" value="3835" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="22" />
                                      <option name="offset" value="3835" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Complete the function" />
                                      <option name="possibleAnswer" value="total = 0
    x = Tree()
    for i in range(len(li)):
        total += i - x.rank(2 * li[i])
        x.insert(li[i])
    return total" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from random import shuffle
class Node:
    def __init__(self, key=None, red=False, parent=None, children=None):
        self.key = key
        self.red = red
        self.parent = parent
        self.children = children

    def refresh_features(self):
        self.num_nodes = 1 + sum([child.num_nodes for child in self.children])
        self.sum_nodes = self.key + sum([child.sum_nodes for child in self.children])

    def get_direction(self):
        return 0 if self == self.parent.children[0] else 1

    def get_brother(self):
        return self.parent.children[1 - self.get_direction()]

    def get_uncle(self):
        return self.parent.get_brother()

    def make_black(self):
        self.red = False

    def make_red(self):
        self.red = True

class Tree:
    def __init__(self):
        self.dummy_parent = Node(children=[None])
        self.dummy_parent.children[0] = Node(parent=self.dummy_parent)
        self.nil = self.root
        self.nil.num_nodes = 0
        self.nil.sum_nodes = 0

    def insert(self, key):
        node = self.root
        node_parent = node.parent
        direction = 0
        while node != self.nil:
            node_parent = node
            direction = 0 if key < node.key else 1
            node = node.children[direction]
        #create new node
        node_parent.children[direction] = Node(key, red=True, parent=node_parent, children=[self.nil] * 2)
        #refresh features
        node = node_parent.children[direction]
        while node != self.root:
            node.refresh_features()
            node = node.parent

        self.cleanup_insert(node_parent.children[direction])

    def cleanup_insert(self, node):
        while node != self.root and node.parent.red:
            uncle = node.get_uncle()
            if uncle.red:
                uncle.make_black()
                node.parent.make_black()
                node.parent.parent.make_red()
                node = node.parent.parent
                continue
            #Save the value of grandparent because the rotation in the "if" staement below will mess up order of nodes
            grand_parent = node.parent.parent
            direction = node.get_direction()
            if direction != node.parent.get_direction():
                self.rotate(node.parent, 1 - direction)
                direction = 1 - direction
            self.rotate(grand_parent, 1 - direction)
            grand_parent.make_red()
            grand_parent.parent.make_black()
            #rotations should terminate loop
            break
        #Root should always be black
        self.root.make_black()

    def rotate(self, node, direction):
        child = node.children[1 - direction]
        midchild = child.children[direction]
        parent = node.parent

        parent.children[node.get_direction()] = child
        child.parent = parent

        child.children[direction] = node
        node.parent = child

        node.children[1 - direction] = midchild
        midchild.parent = node

        node.refresh_features()
        child.refresh_features()

    def in_order(self, node=None):
        if (node==None):
            node = self.root
        if node==self.nil:
            return []
        return self.in_order(node.children[0]) + [node] + self.in_order(node.children[1])

    def rank(self, key):
        node = self.root
        num_smaller_or_equal = 0
        while node != self.nil:
            if key < node.key:
                node = node.children[0]
                continue
            num_smaller_or_equal += node.children[0].num_nodes + 1
            if key > node.key:
                node = node.children[1]
            else:
                break
        return num_smaller_or_equal

    @property
    def root(self):
        return self.dummy_parent.children[0]

def func(li):
    #Complete the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task_copy.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task_copy.py" />
                                <option name="text" value="# TODO: type solution here
from random import shuffle
class Node:
    def __init__(self, key=None, red=False, parent=None, children=None):
        self.key = key
        self.red = red
        self.parent = parent
        self.children = children

    def refresh_features(self):
        self.num_nodes = 1 + sum([child.num_nodes for child in self.children])
        self.sum_nodes = self.key + sum([child.sum_nodes for child in self.children])

    def get_direction(self):
        return 0 if self == self.parent.children[0] else 1

    def get_brother(self):
        return self.parent.children[1 - self.get_direction()]

    def get_uncle(self):
        return self.parent.get_brother()

    def make_black(self):
        self.red = False

    def make_red(self):
        self.red = True

class Tree:
    def __init__(self):
        self.dummy_parent = Node(children=[None])
        self.dummy_parent.children[0] = Node(parent=self.dummy_parent)
        self.nil = self.root
        self.nil.num_nodes = 0
        self.nil.sum_nodes = 0

    def insert(self, key):
        node = self.root
        node_parent = node.parent
        direction = 0
        while node != self.nil:
            node_parent = node
            direction = 0 if key < node.key else 1
            node = node.children[direction]
        #create new node
        node_parent.children[direction] = Node(key, red=True, parent=node_parent, children=[self.nil] * 2)
        #refresh features
        node = node_parent.children[direction]
        while node != self.root:
            node.refresh_features()
            node = node.parent

        self.cleanup_insert(node_parent.children[direction])

    def cleanup_insert(self, node):
        while node != self.root and node.parent.red:
            uncle = node.get_uncle()
            if uncle.red:
                uncle.make_black()
                node.parent.make_black()
                node.parent.parent.make_red()
                node = node.parent.parent
                continue
            #Save the value of grandparent because the rotation in the "if" staement below will mess up order of nodes
            grand_parent = node.parent.parent
            direction = node.get_direction()
            if direction != node.parent.get_direction():
                self.rotate(node.parent, 1 - direction)
                direction = 1 - direction
            self.rotate(grand_parent, 1 - direction)
            grand_parent.make_red()
            grand_parent.parent.make_black()
            #rotations should terminate loop
            break
        #Root should always be black
        self.root.make_black()

    def rotate(self, node, direction):
        child = node.children[1 - direction]
        midchild = child.children[direction]
        parent = node.parent

        parent.children[node.get_direction()] = child
        child.parent = parent

        child.children[direction] = node
        node.parent = child

        node.children[1 - direction] = midchild
        midchild.parent = node

        node.refresh_features()
        child.refresh_features()

    def in_order(self, node=None):
        if (node==None):
            node = self.root
        if node==self.nil:
            return []
        return self.in_order(node.children[0]) + [node] + self.in_order(node.children[1])

    def rank(self, key):
        node = self.root
        num_smaller_or_equal = 0
        while node != self.nil:
            if key < node.key:
                node = node.children[0]
                continue
            num_smaller_or_equal += node.children[0].num_nodes + 1
            if key > node.key:
                node = node.children[1]
            else:
                break
        return num_smaller_or_equal

    @property
    def root(self):
        return self.dummy_parent.children[0]

def func(li):
    total = 0
    x = Tree()
    for i in range(len(li)):
        total += i - x.rank(2 * li[i])
        x.insert(li[i])
    return total

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="false" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from random import shuffle
from random import randint
from task import func as func
from task_copy import func as func_judge

def test_generator(n):
    li = [i for i in range(n)]
    shuffle(li)
    return li
if __name__ == '__main__':
    test_nums = [10, 10, 100, 100, 10000]
    for test_num in test_nums:
        li = test_generator(test_num)
        user_li = func(li[0:len(li)])
        judge_li = func_judge(li[0:len(li)])
        if user_li != judge_li:
            failed("Wrong Answer! Input: " + str(li) +
                   " Your Answer: " + str(user_li) +
                   " Expected Answer: " + str(judge_li))
    print("PASS")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
<meta charset="UTF-8">
در یک شهر تعدادی ساختمان داریم و مختصات قرار گرفتن آن ها را نیز در اختیار داریم. می خواهیم خط افق این شهر را بیابیم
برای نمونه، شکل زیر را در نظر بگیرید

برنامه ای بنویسید که در ورودی لیستی از ساختمان ها بگیرد که هر ساختمان یک توپل ۳ تایی است که عضو اول آن مختصات شروع آن ساختمان است، عضو دوم ارتفاع  آن و عضو سوم مختصات پایان ساختمان.
در خروجی باید افق شهر را در یک لیست ارایه دهید. برای این کار، شکل افق شهر را در نظر بگیرید و نقاطی که در
آن شکل تغییر ارتفاع رخ می دهد را در یک لیست قرار دهید. هر عضو لیست یک ۲ تایی است که عضو اول آن مختصات نقطه و عضو دوم آن ارتفاع است.
برای مثال برای ورودی

  [(1,11,5), (2,6,7), (3,13,9), (12,7,16), (14,3,25),
         (19,18,22), (23,13,29), (24,4,28)]

باید خروجی شما

  [(1, 11), (3, 13), (9, 0), (12, 7), (16, 3), (19, 18),
        (22, 3), (25, 0)]

باشد
برای این کار، باید تابع

  func(li)

&nbsp;
را پیاده سازی کنید که ورودی و خروجی آن به فرمی که گفته شد می باشد.
تضمین می شود که نقطه پایان ساختمان، همواره بزرگتر از شروع آن است.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="4" />
                      <option name="name" value="Q4" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="img.png">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="img.png" />
                                <option name="text" value="[encoded data, 43188 characters]" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="false" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="rb_tree.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="rb_tree.py" />
                                <option name="text" value=""""
A classic (not left-leaning) Red-Black Tree implementation, supporting addition and deletion.
"""

# The possible Node colors
BLACK = 'BLACK'
RED = 'RED'
NIL = 'NIL'

class Node:
    def __init__(self, value, color, parent, left=None, right=None):
        self.value = value
        self.color = color
        self.parent = parent
        self.left = left
        self.right = right

    def __repr__(self):
        return '{color} {val} Node'.format(color=self.color, val=self.value)

    def __iter__(self):
        if self.left.color != NIL:
            yield from self.left.__iter__()

        yield self.value

        if self.right.color != NIL:
            yield from self.right.__iter__()

    def __eq__(self, other):
        if self.color == NIL and self.color == other.color:
            return True

        if self.parent is None or other.parent is None:
            parents_are_same = self.parent is None and other.parent is None
        else:
            parents_are_same = self.parent.value == other.parent.value and self.parent.color == other.parent.color
        return self.value == other.value and self.color == other.color and parents_are_same

    def has_children(self) -> bool:
        """ Returns a boolean indicating if the node has children """
        return bool(self.get_children_count())

    def get_children_count(self) -> int:
        """ Returns the number of NOT NIL children the node has """
        if self.color == NIL:
            return 0
        return sum([int(self.left.color != NIL), int(self.right.color != NIL)])

class RedBlackTree:
    # every node has null nodes as children initially, create one such object for easy management
    NIL_LEAF = Node(value=None, color=NIL, parent=None)

    def __init__(self):
        self.count = 0
        self.root = None
        self.ROTATIONS = {
            # Used for deletion and uses the sibling's relationship with his parent as a guide to the rotation
            'L': self._right_rotation,
            'R': self._left_rotation
        }

    def __iter__(self):
        if not self.root:
            return list()
        yield from self.root.__iter__()

    def add(self, value):
        if not self.root:
            self.root = Node(value, color=BLACK, parent=None, left=self.NIL_LEAF, right=self.NIL_LEAF)
            self.count += 1
            return
        parent, node_dir = self._find_parent(value)
        if node_dir is None:
            return  # value is in the tree
        new_node = Node(value=value, color=RED, parent=parent, left=self.NIL_LEAF, right=self.NIL_LEAF)
        if node_dir == 'L':
            parent.left = new_node
        else:
            parent.right = new_node

        self._try_rebalance(new_node)
        self.count += 1

    def remove(self, value):
        """
        Try to get a node with 0 or 1 children.
        Either the node we're given has 0 or 1 children or we get its successor.
        """
        node_to_remove = self.find_node(value)
        if node_to_remove is None:  # node is not in the tree
            return
        if node_to_remove.get_children_count() == 2:
            # find the in-order successor and replace its value.
            # then, remove the successor
            successor = self._find_in_order_successor(node_to_remove)
            node_to_remove.value = successor.value  # switch the value
            node_to_remove = successor

        # has 0 or 1 children!
        self._remove(node_to_remove)
        self.count -= 1

    def contains(self, value) -> bool:
        """ Returns a boolean indicating if the given value is present in the tree """
        return bool(self.find_node(value))

    def ceil(self, value) -> int or None:
        """
        Given a value, return the closest value that is equal or bigger than it,
        returning None when no such exists
        """
        if self.root is None: return None
        last_found_val = None if self.root.value < value else self.root.value

        def find_ceil(node):
            nonlocal last_found_val
            if node == self.NIL_LEAF:
                return None
            if node.value == value:
                last_found_val = node.value
                return node.value
            elif node.value < value:
                # go right
                return find_ceil(node.right)
            else:
                # this node is bigger, save its value and go left
                last_found_val = node.value

                return find_ceil(node.left)
        find_ceil(self.root)
        return last_found_val

    def floor(self, value) -> int or None:
        """
        Given a value, return the closest value that is equal or less than it,
        returning None when no such exists
        """
        if self.root is None: return None
        last_found_val = None if self.root.value > value else self.root.value

        def find_floor(node):
            nonlocal last_found_val
            if node == self.NIL_LEAF:
                return None
            if node.value == value:
                last_found_val = node.value
                return node.value
            elif node.value < value:
                # this node is smaller, save its value and go right, trying to find a cloer one
                last_found_val = node.value

                return find_floor(node.right)
            else:
                return find_floor(node.left)

        find_floor(self.root)
        return last_found_val

    def _remove(self, node):
        """
        Receives a node with 0 or 1 children (typically some sort of successor)
        and removes it according to its color/children
        :param node: Node with 0 or 1 children
        """
        left_child = node.left
        right_child = node.right
        not_nil_child = left_child if left_child != self.NIL_LEAF else right_child
        if node == self.root:
            if not_nil_child != self.NIL_LEAF:
                # if we're removing the root and it has one valid child, simply make that child the root
                self.root = not_nil_child
                self.root.parent = None
                self.root.color = BLACK
            else:
                self.root = None
        elif node.color == RED:
            if not node.has_children():
                # Red node with no children, the simplest remove
                self._remove_leaf(node)
            else:
                """
                Since the node is red he cannot have a child.
                If he had a child, it'd need to be black, but that would mean that
                the black height would be bigger on the one side and that would make our tree invalid
                """
                raise Exception('Unexpected behavior')
        else:  # node is black!
            if right_child.has_children() or left_child.has_children():  # sanity check
                raise Exception('The red child of a black node with 0 or 1 children'
                                ' cannot have children, otherwise the black height of the tree becomes invalid! ')
            if not_nil_child.color == RED:
                """
                Swap the values with the red child and remove it  (basically un-link it)
                Since we're a node with one child only, we can be sure that there are no nodes below the red child.
                """
                node.value = not_nil_child.value
                node.left = not_nil_child.left
                node.right = not_nil_child.right
            else:  # BLACK child
                # 6 cases :o
                self._remove_black_node(node)

    def _remove_leaf(self, leaf):
        """ Simply removes a leaf node by making it's parent point to a NIL LEAF"""
        if leaf.value >= leaf.parent.value:
            # in those weird cases where they're equal due to the successor swap
            leaf.parent.right = self.NIL_LEAF
        else:
            leaf.parent.left = self.NIL_LEAF

    def _remove_black_node(self, node):
        """
        Loop through each case recursively until we reach a terminating case.
        What we're left with is a leaf node which is ready to be deleted without consequences
        """
        self.__case_1(node)
        self._remove_leaf(node)

    def __case_1(self, node):
        """
        Case 1 is when there's a double black node on the root
        Because we're at the root, we can simply remove it
        and reduce the black height of the whole tree.

            __|10B|__                  __10B__
           /         \      ==>       /       \
          9B         20B            9B        20B
        """
        if self.root == node:
            node.color = BLACK
            return
        self.__case_2(node)

    def __case_2(self, node):
        """
        Case 2 applies when
            the parent is BLACK
            the sibling is RED
            the sibling's children are BLACK or NIL
        It takes the sibling and rotates it

                         40B                                              60B
                        /   \       --CASE 2 ROTATE-->                   /   \
                    |20B|   60R       LEFT ROTATE                      40R   80B
    DBL BLACK IS 20----^   /   \      SIBLING 60R                     /   \
                         50B    80B                                |20B|  50B
            (if the sibling's direction was left of it's parent, we would RIGHT ROTATE it)
        Now the original node's parent is RED
        and we can apply case 4 or case 6
        """
        parent = node.parent
        sibling, direction = self._get_sibling(node)
        if sibling.color == RED and parent.color == BLACK and sibling.left.color != RED and sibling.right.color != RED:
            self.ROTATIONS[direction](node=None, parent=sibling, grandfather=parent)
            parent.color = RED
            sibling.color = BLACK
            return self.__case_1(node)
        self.__case_3(node)

    def __case_3(self, node):
        """
        Case 3 deletion is when:
            the parent is BLACK
            the sibling is BLACK
            the sibling's children are BLACK
        Then, we make the sibling red and
        pass the double black node upwards

                            Parent is black
               ___50B___    Sibling is black                       ___50B___
              /         \   Sibling's children are black          /         \
           30B          80B        CASE 3                       30B        |80B|  Continue with other cases
          /   \        /   \        ==>                        /  \        /   \
        20B   35R    70B   |90B|<---REMOVE                   20B  35R     70R   X
              /  \                                               /   \
            34B   37B                                          34B   37B
        """
        parent = node.parent
        sibling, _ = self._get_sibling(node)
        if (sibling.color == BLACK and parent.color == BLACK
           and sibling.left.color != RED and sibling.right.color != RED):
            # color the sibling red and forward the double black node upwards
            # (call the cases again for the parent)
            sibling.color = RED
            return self.__case_1(parent)  # start again

        self.__case_4(node)

    def __case_4(self, node):
        """
        If the parent is red and the sibling is black with no red children,
        simply swap their colors
        DB-Double Black
                __10R__                   __10B__        The black height of the left subtree has been incremented
               /       \                 /       \       And the one below stays the same
             DB        15B      ===>    X        15R     No consequences, we're done!
                      /   \                     /   \
                    12B   17B                 12B   17B
        """
        parent = node.parent
        if parent.color == RED:
            sibling, direction = self._get_sibling(node)
            if sibling.color == BLACK and sibling.left.color != RED and sibling.right.color != RED:
                parent.color, sibling.color = sibling.color, parent.color  # switch colors
                return  # Terminating
        self.__case_5(node)

    def __case_5(self, node):
        """
        Case 5 is a rotation that changes the circumstances so that we can do a case 6
        If the closer node is red and the outer BLACK or NIL, we do a left/right rotation, depending on the orientation
        This will showcase when the CLOSER NODE's direction is RIGHT

              ___50B___                                                    __50B__
             /         \                                                  /       \
           30B        |80B|  <-- Double black                           35B      |80B|        Case 6 is now
          /  \        /   \      Closer node is red (35R)              /   \      /           applicable here,
        20B  35R     70R   X     Outer is black (20B)               30R    37B  70R           so we redirect the node
            /   \                So we do a LEFT ROTATION          /   \                      to it :)
          34B  37B               on 35R (closer node)           20B   34B
        """
        sibling, direction = self._get_sibling(node)
        closer_node = sibling.right if direction == 'L' else sibling.left
        outer_node = sibling.left if direction == 'L' else sibling.right
        if closer_node.color == RED and outer_node.color != RED and sibling.color == BLACK:
            if direction == 'L':
                self._left_rotation(node=None, parent=closer_node, grandfather=sibling)
            else:
                self._right_rotation(node=None, parent=closer_node, grandfather=sibling)
            closer_node.color = BLACK
            sibling.color = RED

        self.__case_6(node)

    def __case_6(self, node):
        """
        Case 6 requires
            SIBLING to be BLACK
            OUTER NODE to be RED
        Then, does a right/left rotation on the sibling
        This will showcase when the SIBLING's direction is LEFT

                            Double Black
                    __50B__       |                               __35B__
                   /       \      |                              /       \
      SIBLING--> 35B      |80B| <-                             30R       50R
                /   \      /                                  /   \     /   \
             30R    37B  70R   Outer node is RED            20B   34B 37B    80B
            /   \              Closer node doesn't                           /
         20B   34B                 matter                                   70R
                               Parent doesn't
                                   matter
                               So we do a right rotation on 35B!
        """
        sibling, direction = self._get_sibling(node)
        outer_node = sibling.left if direction == 'L' else sibling.right

        def __case_6_rotation(direction):
            parent_color = sibling.parent.color
            self.ROTATIONS[direction](node=None, parent=sibling, grandfather=sibling.parent)
            # new parent is sibling
            sibling.color = parent_color
            sibling.right.color = BLACK
            sibling.left.color = BLACK

        if sibling.color == BLACK and outer_node.color == RED:
            return __case_6_rotation(direction)  # terminating

        raise Exception('We should have ended here, something is wrong')

    def _try_rebalance(self, node):
        """
        Given a red child node, determine if there is a need to rebalance (if the parent is red)
        If there is, rebalance it
        """
        parent = node.parent
        value = node.value
        if (parent is None  # what the fuck? (should not happen)
           or parent.parent is None  # parent is the root
           or (node.color != RED or parent.color != RED)):  # no need to rebalance
            return
        grandfather = parent.parent
        node_dir = 'L' if parent.value > value else 'R'
        parent_dir = 'L' if grandfather.value > parent.value else 'R'
        uncle = grandfather.right if parent_dir == 'L' else grandfather.left
        general_direction = node_dir + parent_dir

        if uncle == self.NIL_LEAF or uncle.color == BLACK:
            # rotate
            if general_direction == 'LL':
                self._right_rotation(node, parent, grandfather, to_recolor=True)
            elif general_direction == 'RR':
                self._left_rotation(node, parent, grandfather, to_recolor=True)
            elif general_direction == 'LR':
                self._right_rotation(node=None, parent=node, grandfather=parent)
                # due to the prev rotation, our node is now the parent
                self._left_rotation(node=parent, parent=node, grandfather=grandfather, to_recolor=True)
            elif general_direction == 'RL':
                self._left_rotation(node=None, parent=node, grandfather=parent)
                # due to the prev rotation, our node is now the parent
                self._right_rotation(node=parent, parent=node, grandfather=grandfather, to_recolor=True)
            else:
                raise Exception("{} is not a valid direction!".format(general_direction))
        else:  # uncle is RED
            self._recolor(grandfather)

    def __update_parent(self, node, parent_old_child, new_parent):
        """
        Our node 'switches' places with the old child
        Assigns a new parent to the node.
        If the new_parent is None, this means that our node becomes the root of the tree
        """
        node.parent = new_parent
        if new_parent:
            # Determine the old child's position in order to put node there
            if new_parent.value > parent_old_child.value:
                new_parent.left = node
            else:
                new_parent.right = node
        else:
            self.root = node

    def _right_rotation(self, node, parent, grandfather, to_recolor=False):
        grand_grandfather = grandfather.parent
        self.__update_parent(node=parent, parent_old_child=grandfather, new_parent=grand_grandfather)

        old_right = parent.right
        parent.right = grandfather
        grandfather.parent = parent

        grandfather.left = old_right  # save the old right values
        old_right.parent = grandfather

        if to_recolor:
            parent.color = BLACK
            node.color = RED
            grandfather.color = RED

    def _left_rotation(self, node, parent, grandfather, to_recolor=False):
        grand_grandfather = grandfather.parent
        self.__update_parent(node=parent, parent_old_child=grandfather, new_parent=grand_grandfather)

        old_left = parent.left
        parent.left = grandfather
        grandfather.parent = parent

        grandfather.right = old_left  # save the old left values
        old_left.parent = grandfather

        if to_recolor:
            parent.color = BLACK
            node.color = RED
            grandfather.color = RED

    def _recolor(self, grandfather):
        grandfather.right.color = BLACK
        grandfather.left.color = BLACK
        if grandfather != self.root:
            grandfather.color = RED
        self._try_rebalance(grandfather)

    def _find_parent(self, value):
        """ Finds a place for the value in our binary tree"""
        def inner_find(parent):
            """
            Return the appropriate parent node for our new node as well as the side it should be on
            """
            if value == parent.value:
                return None, None
            elif parent.value < value:
                if parent.right.color == NIL:  # no more to go
                    return parent, 'R'
                return inner_find(parent.right)
            elif value < parent.value:
                if parent.left.color == NIL:  # no more to go
                    return parent, 'L'
                return inner_find(parent.left)

        return inner_find(self.root)

    def find_node(self, value):
        def inner_find(root):
            if root is None or root == self.NIL_LEAF:
                return None
            if value > root.value:
                return inner_find(root.right)
            elif value < root.value:
                return inner_find(root.left)
            else:
                return root

        found_node = inner_find(self.root)
        return found_node

    def _find_in_order_successor(self, node):
        right_node = node.right
        left_node = right_node.left
        if left_node == self.NIL_LEAF:
            return right_node
        while left_node.left != self.NIL_LEAF:
            left_node = left_node.left
        return left_node

    def _get_sibling(self, node):
        """
        Returns the sibling of the node, as well as the side it is on
        e.g

            20 (A)
           /     \
        15(B)    25(C)

        _get_sibling(25(C)) => 15(B), 'R'
        """
        parent = node.parent
        if node.value >= parent.value:
            sibling = parent.left
            direction = 'L'
        else:
            sibling = parent.right
            direction = 'R'
        return sibling, direction
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="734" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="734" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="li.sort(key=lambda x:x[1])
    tree = RedBlackTree()
    for a, h, b in li:
        prev_b = tree.floor(My_pair(b, None))
        if prev_b is None:
            height_b = 0
        else:
            height_b = prev_b.value

        next_a = tree.ceil(My_pair(a, None))
        while (next_a is not None) and next_a.key <= b:
            tree.remove(next_a)
            next_a = tree.ceil(My_pair(a, None))

        tree.add(My_pair(a, h))
        tree.add(My_pair(b, height_b))

    prev_height = 0
    ans = []
    for element in tree:
        if element.value != prev_height:
            prev_height = element.value
            ans.append((element.key, element.value))
    return ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from rb_tree import RedBlackTree

class My_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

    def increment_value(self):
        self.value += 1

    def __lt__(self, other):
        return self.key < other.key

    def __le__(self, other):
        return self.key <= other.key

    def __gt__(self, other):
        return self.key > other.key

    def __ge__(self, other):
        return self.key >= other.key

    def __eq__(self, other):
        if self is None or other is None:
            return self is None and other is None
        return self.key == other.key

    def __ne__(self, other):
        return not self == other

#li elements are in (a, b, h) form
def func(li):
    #Implement the function
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                          <entry key="task_copy.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list />
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task_copy.py" />
                                <option name="text" value="# TODO: type solution here
from rb_tree import RedBlackTree

class My_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

    def increment_value(self):
        self.value += 1

    def __lt__(self, other):
        return self.key < other.key

    def __le__(self, other):
        return self.key <= other.key

    def __gt__(self, other):
        return self.key > other.key

    def __ge__(self, other):
        return self.key >= other.key

    def __eq__(self, other):
        if self is None or other is None:
            return self is None and other is None
        return self.key == other.key

    def __ne__(self, other):
        return not self == other

#li elements are in (a, b, h) form
def func(li):
    li.sort(key=lambda x:x[1])
    tree = RedBlackTree()
    for a, h, b in li:
        prev_b = tree.floor(My_pair(b, None))
        if prev_b is None:
            height_b = 0
        else:
            height_b = prev_b.value

        next_a = tree.ceil(My_pair(a, None))
        while (next_a is not None) and next_a.key <= b:
            tree.remove(next_a)
            next_a = tree.ceil(My_pair(a, None))

        tree.add(My_pair(a, h))
        tree.add(My_pair(b, height_b))

    prev_height = 0
    ans = []
    for element in tree:
        if element.value != prev_height:
            prev_height = element.value
            ans.append((element.key, element.value))
    return ans
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="false" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from random import shuffle
from random import randint
from task import func as func
from task_copy import func as func_judge

def test_generator(n):
    li = []
    a_and_b_s = set()
    h_s = set()
    for i in range(n):
        max_range = 10000
        a = randint(1, max_range)
        b = randint(1, max_range)
        h = randint(1, max_range)
        # if a in a_and_b_s or b in a_and_b_s or h in h_s or a == b:
        #     continue
        # a_and_b_s.add(a)
        # a_and_b_s.add(b)
        # h_s.add(h)
        if a == b:
            continue
        if a > b:
            a, b = b, a
        li.append((a, h, b))
    return li

if __name__ == '__main__':
    test_nums = [10, 10, 100, 100, 10000]
    for test_num in test_nums:
        li = test_generator(test_num)
        user_li = func(li[0:len(li)])
        judge_li = func_judge(li[0:len(li)])
        if user_li != judge_li:
            failed("Wrong Answer! Input: " + str(li) +
                   " Your Answer: " + str(user_li) +
                   " Expected Answer: " + str(judge_li))
    print("PASS")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="12" />
                <option name="name" value="Segment Tree" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
پیش‌نیاز:

قسمت اول از بخش درخت بازه در جزوه‌ی داده ساختارهای پیشرفته را بخوانید.

مساله:

آرایه‌ای از اعداد داریم. در هر درخواست می‌خواهیم بدانیم مینیمم عضو یک زیردنباله‌ی متوالی مشخص از این آرایه چه مقداری دارد.

ورودی:

در خط اول ورودی اندازه‌ی آرایه (تعداد اعضا) n، در خط دوم n عدد که نمایانگر اعداد آرایه‌اند و در خط سوم تعداد درخواست‌ها q داده می‌شود. در هر کدام از q خط بعد دو عدد مانند l و r می‌آیند که بازه‌ای که مینیمم آن درخواست شده است را مشخص می‌کنند.

بازه‌ها به صورت بسته باز مشخص می‌شوند و اندیس اعضا آرایه از 0  شروع می‌شود.

(l < r , n <= 10^5 , a[i] <= 10^9)

خروجی:

شما باید در خروجی q خط چاپ کنید که خط iم شامل یک عدد معادل پاسخ درخواست iم است.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="133" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="133" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="a = []  # main array
    node = []  # array of minimum elements(use segment tree structure)
    s = arr.split()
    ans = []
    for i in range(4 * n):
        node.append(0)
    for i in range(n):
        a.append(int(s[i]))
    make_tree(1, 0, n, node, a)
    for i in range(q):
        s = inp[i].split()
        p1 = int(s[0])
        p2 = int(s[1])
        ans += [get_min(1, 0, n, p1, p2, node)]

    return ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="158" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="158" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def make_tree(ind, l, r, node, a):
    if (l == r - 1):
        node[ind] = a[l]
        return
    mid = (l + r) // 2
    make_tree(ind * 2, l, mid, node, a)
    make_tree(ind * 2 + 1, mid, r, node, a)
    node[ind] = min(node[ind * 2], node[ind * 2 + 1])

def get_min(ind, l, r, ql, qr, node):  # ql, qr determine segment of query
    if (qr <= l or r <= ql):
        return inf
    if (ql <= l and r <= qr):
        return node[ind]
    mid = (l + r) // 2
    return min(get_min(ind * 2, l, mid, ql, qr, node)
               , get_min(ind * 2 + 1, mid, r, ql, qr, node))" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="
inf = 1000000000
#Sample Input
# n = 7
# arr = "7 2 3 13 5 17 11"
# q = 4
# inp = ["3 7", "2 5", ...]
def func(n, arr, q, inp):
    #Implement the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    run_common_tests()

    n = 7
    arr = "7 2 3 13 5 17 11"
    q = 4
    inp = ["3 7", "2 5", "0 7", "5 6"]

    if func(n, arr, q, inp) != [5, 3, 2, 17]:
        failed("Wrong Answer!")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="
پیش‌نیاز:

قسمت درخت بازه از جزوه‌ی داده ساختارهای پیشرفته را بخوانید.

مساله:

دنباله‌ای از بیت‌های 0 و 1 داریم. دو نوع درخواست وجود دارد:

•	بیت‌های یک زیردنباله‌ی متوالی را برعکس کن (تبدیل 0 به 1 و 1 به 0).

•	مقدار بیت iم را در خروجی بده.

ورودی:

در خط اول n بیت می‌آید که نمایانگر اعضا دنباله‌اند و در خط دوم تعداد درخواست‌ها q داده می‌شود.  هر کدام از q خط بعد یا با s شروع می‌شود و بعد از آن دو عدد مانند l و r می‌آیند که بازه‌ای که بایستی بیت‌هایش برعکس شود را مشخص می‌کنند یا با g شروع می‌شود و سپس اندیس بیتی که بایستی مقدارش برگردانده شود داده می‌شود.
بازه‌ها به صورت بسته باز مشخص می‌شوند و اندیس اعضا آرایه از 0  شروع می‌شود.

(l < r , n <= 10^5 , a[i] <= 10^9)

خروجی:

شما باید به تعداد درخواست‌هایی که مقدار یک عضو را می‌خواهند و به ترتیب در خطوط خروجی مقدار بیت‌ها را چاپ کنید. (در هر خط یک مقدار)

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="107" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="107" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="node = []  # array of minimum elements(use segment tree structure)
    ans = []
    n = n.split()
    for i in range(4 * len(n)):
        node.append(0)
    for i in range(len(n)):
        if (int(n[i]) == 1):
            set_value(1, 0, len(n), i, i + 1, node)
    for i in range(q):
        s = inp[i].split()
        if (len(s) == 2):
            p1 = int(s[1])
            ans += [get_value(p1, 1, 0, len(n), node)]
        else:
            p1 = int(s[1])
            p2 = int(s[2])
            set_value(1, 0, len(n), p1, p2, node)

    return ans" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="134" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="134" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def set_value(ind, l, r, ql, qr, node):
    if (ql <= l and r <= qr):
        node[ind] = 1 - node[ind]
        return
    if (l != r - 1):
        mid = (l + r) // 2
        set_value(2 * ind, l, mid, ql, qr, node)
        set_value(2 * ind + 1, mid, r, ql, qr, node)

def get_value(qind, ind, l, r, node):
    if (l <= qind and qind < r):
        if (l == r - 1):
            return node[ind]
        mid = (l + r) // 2
        return (node[ind] + get_value(qind, 2 * ind, l, mid, node) + get_value(qind, 2 * ind + 1, mid, r, node)) % 2
    return 0" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="

#Sample Input
# n = "0 0 1 0 1 0 1 1 1 0"
# q = 8
# inp = ["s 3 7", "g 4", ...]
def func(n, q, inp):
    #Implement the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    run_common_tests()

    n = "0 0 1 0 1 0 1 1 1 0"
    q = 8
    inp = ["s 3 7", "g 4", "s 2 8", "s 5 10", "g 4", "s 0 6", "g 3", "g 5"]

    if func(n,q,inp) != [0, 1, 1, 0]:
        failed("Wrong Answer!")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="13" />
                <option name="name" value="DFS-BFS" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه DFS-BFS را مطالعه کنید.

  در اولین گام به یک مسئله ساده و کاربردی از الگوریتم های گراف می پردازیم.

  می خواهیم وجود یا عدم وجود دور را در یک گراف بدون جهت بررسی کنیم.

  در این سوال بر اساس کلاس گرافی که قرار داده شده، به تابع hasCycle یک گراف داده می شود و شما باید با کامل کردن آن، بررسی کنید که آیا در این گراف دور جود دارد یا خیر ؟

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="242" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="242" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def dfs(g,v,visited,parent):
    visited[v] = True
    for i in g.graph[v]:
        if not visited[i]:
            if dfs(g,i, visited, v):
                return True
        elif parent is not i:
            return True

    return False" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="266" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="266" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="visited =[False for i in range(g.V)]
    for i in range(g.V):
        if not visited[i]:
            if dfs(g, i, visited, -1):
                return True

    return False
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from collections import defaultdict

class Graph:
    def __init__(self,vertices):
        self.V = vertices
        self.graph = defaultdict(list)

    def addEdge(self,v,w):
        self.graph[v].append(w)
        self.graph[w].append(v)

def hasCycle(g):
    #Implement the function" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    run_common_tests()
    g = Graph(5)
    g.addEdge(1, 0)
    g.addEdge(0, 2)
    g.addEdge(2, 0)
    g.addEdge(0, 3)
    g.addEdge(3, 4)
    if not hasCycle(g):
        failed("Wrong Answer!")

    g = Graph(3)
    g.addEdge(0,1)
    g.addEdge(1,2)

    if hasCycle(g):
        failed("Wrong Answer!")

    g = Graph(5)
    g.addEdge(0, 1)
    g.addEdge(0, 4)
    g.addEdge(3, 4)
    g.addEdge(3, 2)
    g.addEdge(3, 1)

    if not hasCycle(g):
        failed("Wrong Answer!")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  یک گراف جهت دار بدون دور داریم.

  شما باید تابع countPaths را طوری کامل کنید
  به صورتی که با گرفتن یک گراف (بر اساس کلاس قرار داده شده)
  و دو راس تعداد تمام مسیر های بین این دو راس را برگرداند.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="32" />
                                          <option name="offset" value="241" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="32" />
                                      <option name="offset" value="241" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return 0 #Implement the function" />
                                      <option name="possibleAnswer" value="visited =[False for _ in range(g.V)]
    count = []
    dfs(g, s, d,visited, count)
    return len(count)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="275" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="275" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def dfs(g, s, d,visited, count):
    visited[s]= True
    if s == d:
        count += [1]
    else:
        for i in g.graph[s]:
            if not visited[i]:
                dfs(g, i, d, visited, count)

    visited[s] = False
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from collections import defaultdict

class Graph:

    def __init__(self,vertices):
        self.V = vertices
        self.graph = defaultdict(list)

    def addEdge(self, u, v):
        self.graph[u].append(v)

def countPaths(g, s, d):
    return 0 #Implement the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    run_common_tests()
    g = Graph(4)
    g.addEdge(0, 1)
    g.addEdge(0, 2)
    g.addEdge(0, 3)
    g.addEdge(2, 0)
    g.addEdge(2, 1)
    g.addEdge(1, 3)
    if countPaths(g, 2, 3) != 3:
        failed("Wrong Answer!")

    g = Graph(5)
    g.addEdge(0,1)
    g.addEdge(0,2)
    g.addEdge(0,4)
    g.addEdge(1,3)
    g.addEdge(1,4)
    g.addEdge(2,4)
    g.addEdge(3,2)

    if countPaths(g, 0, 4) != 4:
        failed("Wrong Answer!")

    if countPaths(g, 1, 0) != 0:
        failed("Wrong Answer!")
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

  یک گراف بدون جهت همبند داریم.

  می خواهیم بیشترین فاصله بین تمامی جفت شهرهای ممکن را محاسبه کنیم. فاصله‌ی دو شهر طول کوتاه‌ترین مسیر بین آن دو شهر است.

  تابع maxDistance را طوری کامل کنید تا بیشترین فاصله را برگرداند.

(گرافی که به این تابع داده می شود به صورت کلاسی که قرار داده شده پیاده شده است.)

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="32" />
                                          <option name="offset" value="308" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="32" />
                                      <option name="offset" value="308" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return 0 #Implement the function" />
                                      <option name="possibleAnswer" value="    maxDis = 0
    for i in range(g.v):
        tmp = bfs(g,i)
        if(tmp > maxDis):
            maxDis = tmp
    return maxDis" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="342" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="342" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def bfs(g,u):
        distance = [-1]*g.v
        distance[u] = 0
        q = []
        q.append(u)
        while(len(q) > 0):
            t = q.pop()
            for v in g.graph[t]:
                if(distance[v] == -1):
                    q.append(v)
                    distance[v] = distance[t] + 1

        return max(distance)
" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="from collections import defaultdict

class graph:
    def __init__(self,vertices):
        self.v = vertices
        self.graph = defaultdict(list)
        self.eSize = 0

    def addEdge(self,u,x):
        self.graph[u].append(x)
        self.graph[x].append(u)
        self.eSize += 1

def maxDistance(g):
return 0 #Implement the function

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import run_common_tests, failed, passed, get_answer_placeholders
from task import *

if __name__ == '__main__':
    run_common_tests()
    g = graph(7)
    g.addEdge(0,1)
    g.addEdge(1,2)
    g.addEdge(2,3)
    g.addEdge(3,4)
    g.addEdge(4,1)
    g.addEdge(2,6)
    g.addEdge(3,6)

    if maxDistance(g) != 4:
        failed("Wrong Answer")

    g = graph(4)
    g.addEdge(0,1)
    g.addEdge(1,2)
    g.addEdge(2,3)
    g.addEdge(3,0)
    if maxDistance(g) != 2:
        failed("Wrong Answer!")

    g.addEdge(0,2)
    g.addEdge(1,3)

    if maxDistance(g) != 1:
        failed("Wrong Answer!")

" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
              <Lesson>
                <option name="customPresentableName" />
                <option name="id" value="0" />
                <option name="index" value="14" />
                <option name="name" value="Topological Sort" />
                <option name="stepikChangeStatus" value="Up to date" />
                <option name="updateDate" value="0" />
                <option name="taskList">
                  <list>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچه ترتیب توپولوژیک

    وظیفه اول:

چگونه پیشنیازی خود را تربیت کنیم!

    سوال:

بعد از کش و قوس های فراوان در انتخاب واحد، اکبر بیچاره بالاخره توانست تعداد کمی واحد بردارد که برای یکی از آنها پیشنیازی را رعایت نکرده است و حالا فهمیده است که آموزش در صدد این است که دانشجویانی را که پیشنیازی را رعایت نکرده اند از درس مورد نظر حذف کند.

    اکبر که به کل با گراف پیشنیازی دروس(فرض می کنیم همنیازی نداریم) بیگانه است، می خواهد تمام حالاتی که می توان درس ها را گذراند بدون آنکه پیشنیازی را رعایت نکرده باشد را پیدا کند. به او کمک کنید تا به خواسته خود برسد.

    توضیحات بیشتر: به شما گراف پیشنیازی دروس داده شده است. تمام حالات خواسته شده را چاپ کنید. در هر حالت به ترتیب دروسی که می بایست بگذراند تا پیشنیازی رعایت شود را بدست آورید. در نهایت لیستی از لیست‌ها را خروجی دهید که هر لیست شامل یک ترتیب درست است.

        قاعدتا گراف موجود یک
        DAG
        است چرا که روابط پیشنیازی هیچگاه باعث بوجود آمدن دور نمی شوند.

هر وقت DAG در جایی دیدید ، آب دستتان بود روی زمین بگذارید و یاد ترتیب توپولوژیکال بیفتید.(بیشتر شبیه نکته های کنکورشد!)

        یک ترتیب درست از دروس، ترتیبی است که هر درسی که پیشنیاز درس دیگری بود قبل از آن درس بیاید. این همان ترتیب توپولوژیکال است!

        حال برای بدست آوردن تمام ترتیب ها چه کار می توانیم بکنیم ؟ در مبحث ترتیب توپولوژیکال راس های با درجه ورودی صفر راس ها مهمی بودند. نه ؟

       می دانیم که هر
        DAG
        قطعا حداقل یک راس با درجه ورودی صفر دارد. اگر این راس را برداریم و درجه ورودی راس هایی که با راس اولیه مجاورند را کاهش دهیم، احتمالا راس با درجه ورودی صفر جدید بوجود می‌آید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="1" />
                      <option name="name" value="Q1" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="33" />
                                          <option name="offset" value="257" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="33" />
                                      <option name="offset" value="257" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="return -1 #Implement the function" />
                                      <option name="possibleAnswer" value="visited = [False for _ in range(self.Vertices_num)]
        in_degree = [0 for _ in range(self.Vertices_num)]
        for i in range(self.Vertices_num):
            for j in self.graph[i]:
                in_degree[j] += 1

        answers = []
        self.find_topological(visited, in_degree, answers)
        return self.result" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="296" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="296" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def find_topological(self, visited, in_degree, answers):
        flag = False
        for i in range(self.Vertices_num):
            if in_degree[i] == 0 and not visited[i]:
                visited[i] = True
                answers.append(i)
                for j in self.graph[i]:
                    in_degree[j] -= 1
                self.find_topological(visited, in_degree, answers)

                visited[i] = False
                del answers[-1]
                for j in self.graph[i]:
                    in_degree[j] += 1
                flag = True
        if not flag:
            a = copy.deepcopy(answers)
            self.result.append(a)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="import copy

class Graph:
    def __init__(self, N):
        self.graph = [[] for _ in range(N)]
        self.Vertices_num = N
        self.result = []

    def add_edge(self, u, v):
        self.graph[u].append(v)

    def all_topologicals(self):
        return -1 #Implement the function

# Don't change this function
def solve(graph):
    return graph.all_topologicals()

" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    g = Graph(6)
    g.add_edge(5, 2)
    g.add_edge(5, 0)
    g.add_edge(4, 0)
    g.add_edge(4, 1)
    g.add_edge(2, 3)
    g.add_edge(3, 1)

    g2 = Graph(8)
    g2.add_edge(0, 3)
    g2.add_edge(1, 3)
    g2.add_edge(2, 3)
    g2.add_edge(3, 4)
    g2.add_edge(3, 5)
    g2.add_edge(3, 6)
    g2.add_edge(4, 7)
    g2.add_edge(5, 7)
    g2.add_edge(6, 7)

    g3 = Graph(7)
    g3.add_edge(0, 1)
    g3.add_edge(0, 2)
    g3.add_edge(1, 3)
    g3.add_edge(1, 4)
    g3.add_edge(3, 6)
    g3.add_edge(2, 5)
    g3.add_edge(5, 4)
    g3.add_edge(4, 6)
    g3.add_edge(5, 6)

    g4 = Graph(10)
    g4.add_edge(0, 1)
    g4.add_edge(0, 2)
    g4.add_edge(1, 3)
    g4.add_edge(1, 4)
    g4.add_edge(2, 3)
    g4.add_edge(2, 4)
    g4.add_edge(2, 5)
    g4.add_edge(2, 6)
    g4.add_edge(5, 8)
    g4.add_edge(6, 8)
    g4.add_edge(6, 7)
    g4.add_edge(6, 9)
    g4.add_edge(7, 9)

    tests = [
        (g, [[4, 5, 0, 2, 3, 1], [4, 5, 2, 0, 3, 1], [4, 5, 2, 3, 0, 1], [4, 5, 2, 3, 1, 0], [5, 2, 3, 4, 0, 1], [5, 2, 3, 4, 1, 0], [5, 2, 4, 0, 3, 1], [5, 2, 4, 3, 0, 1], [5, 2, 4, 3, 1, 0], [5, 4, 0, 2, 3, 1], [5, 4, 2, 0, 3, 1], [5, 4, 2, 3, 0, 1], [5, 4, 2, 3, 1, 0]]),
        (g2, [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 6, 5, 7], [0, 1, 2, 3, 5, 4, 6, 7], [0, 1, 2, 3, 5, 6, 4, 7], [0, 1, 2, 3, 6, 4, 5, 7], [0, 1, 2, 3, 6, 5, 4, 7], [0, 2, 1, 3, 4, 5, 6, 7], [0, 2, 1, 3, 4, 6, 5, 7], [0, 2, 1, 3, 5, 4, 6, 7], [0, 2, 1, 3, 5, 6, 4, 7], [0, 2, 1, 3, 6, 4, 5, 7], [0, 2, 1, 3, 6, 5, 4, 7], [1, 0, 2, 3, 4, 5, 6, 7], [1, 0, 2, 3, 4, 6, 5, 7], [1, 0, 2, 3, 5, 4, 6, 7], [1, 0, 2, 3,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, 6, 7, 9, 1, 5, 8, 3, 4], [0, 2, 6, 7, 9, 1, 5, 8, 4, 3], [0, 2, 6, 7, 9, 5, 1, 3, 4, 8], [0, 2, 6, 7, 9, 5, 1, 3, 8, 4], [0, 2, 6, 7, 9, 5, 1, 4, 3, 8], [0, 2, 6, 7, 9, 5, 1, 4, 8, 3], [0, 2, 6, 7, 9, 5, 1, 8, 3, 4], [0, 2, 6, 7, 9, 5, 1, 8, 4, 3], [0, 2, 6, 7, 9, 5, 8, 1, 3, 4], [0, 2, 6, 7, 9, 5, 8, 1, 4, 3]])
    ]
    for test in tests:
        test_function2(test[-1], solve, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچهٔ ترتیب توپولوژیک و مولقه‌های قویا همبند

    پیدا کردن جزیره‌ها

    سوال:
    می‌خواهیم الگوریتمی طراحی کنیم که از روی یک نقشه هوایی تعداد جزیره‌های یک منطقه را شناسایی کند. نقشه ورودی را در قالب یک آرایه دوبعدی دریافت می‌کنیم. عدد یک نشان‌دهنده خشکی و صفر نشان‌دهنده آب است. یک جزیره شامل تعدادی یک همجوار است (توجه کنید که هر خانه حداکثر ۸ همسایه دارد.)

برای مثال در نقشه زیر ۵ جزیره وجود دارد

    خروجی: الگوریتم باید تعداد جزایر روی نقشه را چاپ کند.

    به مفهوم مولفه‌های قویا همبند فکر کنید. چه تفاوتی میان ورودی این مسئله و گرافی که در آن مولفه‌های قویا همبند را می‌یافتیم وجود دارد؟ چگونه می‌توان مفهوم مولفه‌های قویا همبند را به گراف‌های بدون جهت تعمیم داد؟

    از جست‌وجوی عمق اول در پیاده‌سازی‌تان استفاده کنید.

    به جز استفاده از جست‌وجوی عمق اول چه راه دیگری برای حل این مسئله به ذهنتان می‌رسد؟

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="2" />
                      <option name="name" value="Q2" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="124" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="124" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def isSafe(self, i, j, visited):
        return (0 <= i < self.ROW and 0 <= j < self.COL and
                not visited[i][j] and self.graph[i][j])

    def dfs(self, i, j, visited):
        # These arrays are used to get row and
        # column numbers of 8 neighbours
        # of a given cell
        row_nbr = [-1, -1, -1, 0, 0, 1, 1, 1]
        col_nbr = [-1, 0, 1, -1, 1, -1, 0, 1]
        visited[i][j] = True
        for k in range(8):
            if self.isSafe(i + row_nbr[k], j + col_nbr[k], visited):
                self.dfs(i + row_nbr[k], j + col_nbr[k], visited)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="163" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="163" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the function" />
                                      <option name="possibleAnswer" value="visited = [[False for j in range(self.COL)] for i in range(self.ROW)]
        count = 0
        for i in range(self.ROW):
            for j in range(self.COL):
                if visited[i][j] == False and self.graph[i][j] == 1:
                    self.dfs(i, j, visited)
                    count += 1
        return count" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="class Graph:
    def __init__(self, row, col, g):
        self.ROW = row
        self.COL = col
        self.graph = g

    def count_islands(self):
        #Implement the function

# Don't change this function
def solve(graph):
    return graph.count_islands()
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

if __name__ == '__main__':
    graph = [[1, 1, 0, 0, 0],
             [0, 1, 0, 0, 1],
             [1, 0, 0, 1, 1],
             [0, 0, 0, 0, 0],
             [1, 0, 1, 0, 1]]
    row = len(graph)
    col = len(graph[0])
    g = Graph(row, col, graph)

    graph = [[1, 1],
             [1, 1]]
    row = len(graph)
    col = len(graph[0])
    g2 = Graph(row, col, graph)

    graph = [[0 for i in range(1000)] for j in range(1000)]
    row = col = 1000
    g3 = Graph(row, col, graph)

    graph = [[0 for i in range(1000)] for j in range(1000)]
    graph[500] = [(1 if i % 2 == 0 else 0) for i in range(1000)]
    print(graph[500])
    row = col = 1000
    g4 = Graph(row, col, graph)

    tests = [
        (g, 5),
        (g2, 1),
        (g3, 0),
        (g4, 500),
    ]
    for test in tests:
        my_test_function(test[-1], solve, test[0])
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                    <EduTask>
                      <option name="additionalFiles">
                        <map />
                      </option>
                      <option name="customPresentableName" />
                      <option name="descriptionFormat" value="HTML" />
                      <option name="descriptionText" value="

    پیشنیاز:

دفترچهٔ ترتیب توپولوژیک و مولقه‌های قویا همبند

     یکی از مهم‌ترین کاربردهای مسئله SCC در حل مسائل satisfiability است. در ادامه به یکی از این مصادیق این مسئله می‌پردازیم. به طور کلی در این مسائل تعدادی متغیر صحیح و غلط داریم که به فرم CNF در آمده‌اند و می‌خواهیم ببینیم آیا مقداردهی‌ای به این متغیرها وجود دارد که جواب نهایی مسئله را صحیح کند یا نه.

    سوال:
    در کشور پشمکستان، شهر‌ها به صورت دایره‌ای به هم راه دارند. یعنی شهر i ام به شهر‌های i-1 ام و i+1 ام جاده دارد. ( شهر اول و آخر نیز به هم جاده دارند.) همچنین شکل هندسی این جاده‌ها دقیقا به صورت یک دایره است.

    پشمک به عنوان وزیر راه و شهرسازی پشمکستان قصد دارد برای کاهش مسافت بین شهر‌ها ، بین تعدادی از شهر‌ها جاده‌ی مستقیم احداث کند. اما برای جلوگیری از ترافیک ، هیچ دو جاده‌ای ( شامل جاده‌های اولیه‌ی دایره‌ای و جاده‌های تازه تاسیس ) نباید جز در شهر‌ها باهم تقاطع داشته باشند. با توجه به این نکته ، بدیهی است هرکدام از جاده‌های جدید به طور کامل داخل دایره‌ی اولیه یا به طور کامل خارج از آن قرار خواهند گرفت. با مشخص کردن این که کدام جاده‌ها داخل و کدام جاده‌ها خارج دایره قرار می‌گیرند ، به پشمک در احداث جاده‌ها کمک کنید.

    ورودی:
    در خط اول ورودی دو عدد n و m داده می شود که به ترتیب تعداد شهرهای پشکمستان و تعداد جاده‌های جدید است. در هریک از m خط بعدی دو عدد می‌آیند که شماره‌ی شهر‌هایی هستند که پشمک قصد احداث جاده میان آن‌ها را دارد.

    خروجی:
    در صورتی که امکان احداث جاده‌های جدید با شرایط ذکر شده وجود نداشت ، در خروجی عبارت Impossible را چاپ کنید. در غیر این صورت رشته‌ای از I و O را چاپ کنید که در آن کاراکتر i ام در صورتی که جاده‌ی i ام بیرون دایره احداث شود O و در صورتی که این جاده درون دایره احداث شود I خواهد بود. ( در صورت وجود جواب‌های مختلف ، یکی را به دلخواه چاپ کنید )

هر جاده را بازه‌ای روی محور اعداد در نظر بگیرید. دو جاده چگونه ممکن است با هم تلاقی داشته باشند؟

سعی کنید مسئله را به صورت یک گراف مدل کنید. چگونه این کار را می‌کنید؟ یک ایده آن است که به ازای هر شهر یک رأس و هر جاده یک یال را در نظر بگیریم؛ چه راه دیگری به ذهنتان می‌رسد.

سعی کنید مسئله را به صورت یک گراف مدل کنید. چگونه این کار را می‌کنید؟ یک ایده آن است که به ازای هر شهر یک رأس و هر جاده یک یال را در نظر بگیریم؛ چه راه دیگری به ذهنتان می‌رسد.

    حال به راه‌هایی مثل تبدیل کردن گراف به مسئلهٔ پیدا کردن مولفه‌ّهای همبندی یا رنگ‌آمیزی فکر کنید و با استفاده از الگوریتم پیمایش عمق اول مسئله راه حل کنید.

" />
                      <option name="feedbackLink">
                        <FeedbackLink>
                          <option name="link" />
                          <option name="type" value="STEPIK" />
                        </FeedbackLink>
                      </option>
                      <option name="index" value="3" />
                      <option name="name" value="Q3" />
                      <option name="status" value="Unchecked" />
                      <option name="stepId" value="0" />
                      <option name="stepikChangeStatus" value="Up to date" />
                      <option name="taskFiles">
                        <map>
                          <entry key="task.py">
                            <value>
                              <TaskFile>
                                <option name="answerPlaceholders">
                                  <list>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="0" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="0" />
                                          <option name="offset" value="1" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="0" />
                                      <option name="offset" value="1" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="" />
                                      <option name="possibleAnswer" value="def intersect(l1, r1, l2, r2):
    if l1 <= l2 and r1 >= r2 or l2 <= l1 and r2 >= r1:
        return False
    if r2 <= r1 and l1 <= l2 and r2 <= l2:
        return False
    if l1 >= r2 and l1 >= l2 or r1 <= l2 and r1 <= r2:
        return False
    return True

def ans(color):
    return ''.join(['I' if i == 0 else 'O' for i in color])

def dfs(v, clr, color, graph):
    if color[v] != -1 and color[v] != clr:
        return 'Impossible'
    if color[v] != -1:
        return
    color[v] = clr
    for u in graph[v]:
        if dfs(u, 1 - clr, color, graph) == 'Impossible':
            return 'Impossible'" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                    <AnswerPlaceholder>
                                      <option name="hints">
                                        <list />
                                      </option>
                                      <option name="index" value="1" />
                                      <option name="initialState">
                                        <MyInitialState>
                                          <option name="length" value="23" />
                                          <option name="offset" value="77" />
                                        </MyInitialState>
                                      </option>
                                      <option name="initializedFromDependency" value="false" />
                                      <option name="length" value="23" />
                                      <option name="offset" value="77" />
                                      <option name="placeholderDependency" />
                                      <option name="placeholderText" value="#Implement the fucntion" />
                                      <option name="possibleAnswer" value="n, m = input[0]
    graph = [[] for i in range(m)]
    vedge = []
    color = [-1] * m
    for i in range(m):
        a, b = map(int, input[i + 1])
        a, b = min(a, b), max(a, b)
        for j, v in enumerate(vedge):
            if intersect(a, b, v[0], v[1]):
                graph[i].append(j)
                graph[j].append(i)
        vedge.append((a, b))

    for i in range(m):
        if color[i] == -1:
            if dfs(i, 0, color, graph):
                return 'Impossible'
    return ans(color)" />
                                      <option name="selected" value="false" />
                                      <option name="status" value="Unchecked" />
                                      <option name="studentAnswer" />
                                      <option name="useLength" value="true" />
                                    </AnswerPlaceholder>
                                  </list>
                                </option>
                                <option name="highlightErrors" value="false" />
                                <option name="name" value="task.py" />
                                <option name="text" value="

# Sample Input:
# Input = [[4, 2], [1, 3], [2, 4]]

def solve(input):
    #Implement the fucntion
" />
                                <option name="trackChanges" value="true" />
                                <option name="trackLengths" value="true" />
                                <option name="userCreated" value="false" />
                                <option name="visible" value="true" />
                              </TaskFile>
                            </value>
                          </entry>
                        </map>
                      </option>
                      <option name="testsText">
                        <map>
                          <entry key="tests.py" value="from test_helper import *
from task import *

def intersect(l1, r1, l2, r2):
    if l1 <= l2 and r1 >= r2 or l2 <= l1 and r2 >= r1:
        return False
    if r2 <= r1 and l1 <= l2 and r2 <= l2:
        return False
    if l1 >= r2 and l1 >= l2 or r1 <= l2 and r1 <= r2:
        return False
    return True

def check_fallacy(l1, r1, l2, r2, ans1, ans2):
    if intersect(l1, r1, l2, r2):
        return ans1 == ans2
    return False

def dfs(v, clr, color, graph):
    if color[v] != -1 and color[v] != clr:
        return 'Impossible'
    if color[v] != -1:
        return
    color[v] = clr
    for u in graph[v]:
        if dfs(u, 1 - clr, color, graph) == 'Impossible':
            return 'Impossible'

def my_solve(input):
    n, m = input[0]
    graph = [[] for i in range(m)]
    vedge = []
    color = [-1] * m
    for i in range(m):
        a, b = map(int, input[i + 1])
        a, b = min(a, b), max(a, b)
        for j, v in enumerate(vedge):
            if intersect(a, b, v[0], v[1]):
                graph[i].append(j)
                graph[j].append(i)
        vedge.append((a, b))

    for i in range(m):
        if color[i] == -1:
            if dfs(i, 0, color, graph):
                return 'Impossible'
    return answer(color)

def answer(color):
    return str(['I' if i == 0 else 'O' for i in color])

if __name__ == '__main__':
    in1 = [[4, 2], [1, 3], [2, 4]]
    in2 = [[5, 2], [2, 4], [4, 1]]
    in3 = [[6, 6], [1, 4], [4, 6], [2, 6], [2, 4], [5, 3], [6, 3]]
    in4 = [[17, 10], [4, 11], [7, 16], [8, 5], [12, 15], [7, 4], [1, 12], [11, 1], [15, 1], [7, 14], [2, 9]]

    tests = [in1, in2, in3, in4]
    for test in tests:
        ans = solve(test)
        true_ans = my_solve(test)
        if true_ans == 'Impossible':
            if ans == 'Impossible':
                continue
            else:
                failed("Wrong Answer! Input: {}, your output: {}, answer: {}".format(test, ans, my_solve(test)))
        for i in range(1, len(test)):
            for j in range(i + 1, len(test)):
                if check_fallacy(test[i][0], test[i][1], test[j][0], test[j][1], list(ans)[i - 1], list(ans)[j - 1]):
                    failed("Wrong Answer! Input: {}, your output: {}, answer: {}".format(test, ans, my_solve(test)))
                passed()
" />
                        </map>
                      </option>
                      <option name="updateDate" value="0" />
                    </EduTask>
                  </list>
                </option>
                <option name="unitId" value="0" />
              </Lesson>
            </list>
          </option>
        </Course>
      </option>
    </StudyTaskManager>
  </component>
</project>