Solution: HW02
testfuncscerrsol_stdoutsol_keptsol_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 442, 'const': 315, 'code+const': 757}
def best_lift(lifts, s, d):
    nfloors = [0]*(len(lifts)//2)
    for i in range(len(lifts)//2):
        a,b = lifts[2*i:2*i+2]
        if a <= b and s < d:
            if a <= s:
                nfloors[i] =  max(d - b,0)
            else:
                nfloors[i] = b-s + d-s
        elif b <= a and d < s:
            if s <= a:
                nfloors[i] = max(b - d, 0)
            else:
                nfloors[i] = s-b + s-d
        else:
            nfloors[i] = abs(b-s) + abs(s-d)
    return nfloors.index(min(nfloors))
n = int(input())
L = [0]*(2*n)
for i in range(n):
    lid,s,d = input().split()
    k = 2*(int(lid)-1)
    L[k] = int(s)
    L[k+1] = int(d)
m = int(input())
out = ''
for i in range(m):
    s,d = input().split()
    out += ">> " + str(1+best_lift(L, int(s), int(d))) + '\n'
print(out)

Testsuite: HW02
from spj_grader_034 import *
import builtins

class Testsuite(spjTestsuite):
    def user_code():
        # remove input prompt
        inp = builtins.input
        def myinput(prompt=''):
            return inp()
        builtins.input = myinput
        call_user_code()
        
    def score_main(self):
        has_greater_sym = ('>>' in self.stu_stdout)
        if has_greater_sym:
            stu_stdout = [e.split(">")[-1].strip()
                          for e in self.stu_stdout.splitlines()
                          if '>>' in e]
        else:
            stu_stdout = [e.split()[-1]
                          for e in self.stu_stdout.splitlines()
                          if e.strip() != ""]
            
        sol_stdout = [e.split(">>")[-1].strip()
                      for e in self.sol_stdout.splitlines()]
        s = 0        
        for i in range(min(len(stu_stdout), len(sol_stdout))):
            s += stu_stdout[i] == sol_stdout[i]
        #print(repr(stu_stdout))
        #print(repr(sol_stdout))
        #print(s, len(sol_stdout))
        return s/len(sol_stdout)*(1 if has_greater_sym else 0.9)
        
    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in 
         """4
            1 3 1
            2 1 8
            3 2 2  
            4 12 3
            3
            5 9
            6 2
            3 2""".splitlines()])
    def test_main_1(self):
        Testsuite.user_code()

    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """4
            1 3 1
            2 2 8
            3 10 10
            4 12 6
            4
            1 6
            8 12
            11 15
            4 1""".splitlines()])
    def test_main_2(self):
        Testsuite.user_code()

    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """4
            1 2 2
            2 4 4
            3 6 6
            4 8 8
            9
            1 3
            2 4
            3 5
            4 6
            5 7
            6 8
            7 9
            8 10
            9 11""".splitlines()])
    def test_main_3(self):
        Testsuite.user_code()

    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """4
            1 8 11
            2 6 9
            3 4 7
            4 2 5
            9
            1 12
            2 12
            3 12
            4 12
            5 12
            6 12
            7 12
            8 12
            9 12""".splitlines()])
    def test_main_4(self):
        Testsuite.user_code()
        
    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """4
            1 6 2
            2 8 4
            3 12 8
            4 10 6
            12
            13 1
            12 1
            11 1
            10 1
            9 1
            8 1
            7 1
            6 1
            5 1
            4 1
            3 1
            2 1""".splitlines()])
    def test_main_5(self):
        Testsuite.user_code()
        
    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """4
            1 8 11
            2 6 9
            3 4 7
            4 2 5
            11
            12 1
            11 1
            10 1
            9 1
            8 1
            7 1
            6 1
            5 1
            4 1
            3 1
            2 1""".splitlines()])
    def test_main_6(self):
        Testsuite.user_code()
        
    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """4
            1 6 2
            2 8 4
            3 12 8
            4 10 6
            12
            1 13
            2 13
            3 13
            4 13
            5 13
            6 13
            7 13
            8 13
            9 13
            10 13
            11 13
            12 13""".splitlines()])
    def test_main_7(self):
        Testsuite.user_code()
        
    @spjTestsuite.testcase(score_main, stdin=[e.strip() for e in
         """6
            2 5 2
            1 2 5
            3 7 10
            6 10 7
            5 12 15
            4 15 12
            22
            1 6
            2 7
            3 8
            4 9
            5 10
            6 11
            7 12
            8 13
            9 14
            10 15
            11 16
            6 1
            7 2
            8 3
            9 4
            10 5
            11 6
            12 7
            13 8
            14 9
            15 10
            16 11""".splitlines()])
    def test_main_8(self):
        Testsuite.user_code()         

6330070321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
[1,>> 2, 3,
>> 4]
[3, 1, 2,>> 12]
[1, 8, 2, 3]
[]
test_main_20.0
[1, 2, 3,>> 4]1
[3, 2, 10,>> 12]
[1,>> 8,3
>> 10, 6]4
[]
test_main_30.0
[1,>> 2,1
>> 3,1
>> 4]1
[>> 2,
>> 4,2
>> 6,3
>> 8]3
[2,>> 4, 6,
>> 8]4
[]
test_main_40.0
[1,>> 2,4
>> 3,4
>> 4]
[8,>> 6,3
>> 4,3
>> 2]
[11,>> 9,2
>> 7,1
>> 5]1
[]
test_main_50.0
[1,>> 2,3
>> 3,
>> 3
>> 4
>> 4]
>> 2
[6,>> 8,2
>> 12,
>> 10]
[2,>> 4,1
>> 8,1
>> 6]1
[]
test_main_60.0
[>> 1,
>> 1
>> 1
>> 2
>> 2,
>> 3
>> 3,
>> 4]
[8, 6,>> 4,
>> 2]4
[11, 9, 7,>> 5]4
[]
test_main_70.0
[>> 1,
>> 1
>> 1
>> 2,
>> 3,2
>> 4]
[6,>> 8,3
>> 12,3
>> 10]3
[2,>> 4,3
>> 8,3
>> 6]3
[]
test_main_80.0
[>> 2,
>> 1,
>> 1
>> 1
>> 1
>> 1
>> 3,
>> 6,3
>> 5,3
>> 3
>> 3
>> 1
>> 4]6
[5,>> 2,6
>> 7,6
>> 10,6
>> 12,3
>> 15]4
[2,>> 5,4
>> 10,4
>> 7,4
>> 15, 12]
[]
bytecount: {'code': 190, 'const': 96, 'code+const': 286}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
LCX = []
LDX = []
NOX = []
for i in range(n):
    L = input().split()
    NO = (L[0])
    LC = (L[1])
    LD = (L[2])
    NOX += [int(NO)]
    LCX += [int(LC)]
    LDX += [int(LD)]
m = int(input())
for j in range(m):
    Q = input().split()
    UC = (Q[0])
    UD = (Q[1])
print(NOX)
print(LCX)
print(LDX)
    #L LC LF

6331501721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
[2, 4, 1]
[3, 1, 2,>> 12]
[1, 8, 2,>> 3]
[5, 6, 3]4
[9,>> 2, 2]1
[]
test_main_20.0
[1, 2, 3, 4]
[3, 2,>> 10,
>> 12]
[1,>> 8, 10, 6]3
[1, 8, 11,>> 4]
[6, 12, 15, 1]
[]
test_main_30.0
[>> 1,
>> 1,
>> 1,
>> 2,
>> 2,
>> 3,
>> 3, 4, 4]
[2,>> 4, 6, 8]
[2,>> 4, 6, 8]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[3, 4, 5, 6, 7, 8, 9, 10, 11]
[]
test_main_40.0
[4,>> 4,
>> 4, 3, 3, 2, 2, 1, 1]
[8, 6,>> 4, 2]
[11, 9, 7,>> 5]3
[1, 2,>> 3, 4, 5, 6, 7, 8, 9]
[12,>> 12,
>> 12,
>> 12, 12, 12,
>> 12, 12, 12]
[]
test_main_50.0
[>> 3,
>> 3,
>> 3,
>> 4,
>> 4,
>> 2,
>> 2,
>> 1, 1, 1,
>> 1, 1]
[6, 8, 12,>> 10]
[2, 4, 8,>> 6]
[13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
[1, 1,>> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[]
test_main_60.0
[>> 1,
>> 1,
>> 1,
>> 2,
>> 2,
>> 3,
>> 3,
>> 4,
>> 4, 4, 4]
[8, 6,>> 4, 2]
[11, 9, 7, 5]
[12, 11, 10, 9, 8, 7, 6, 5,>> 4, 3, 2]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[]
test_main_70.0
[1,>> 1,
>> 1, 2, 2, 4, 3, 3, 3, 3, 3, 3]
[6, 8,>> 12,
>> 10]
[2, 4, 8, 6]
[1,>> 2, 3,
>> 4, 5, 6, 7, 8, 9, 10, 11, 12]
[13,>> 13,
>> 13,
>> 13,
>> 13,
>> 13, 13, 13, 13, 13, 13,
>> 13]
[]
test_main_80.0
[1,>> 2,
>> 2,1
>> 2,1
>> 2,1
>> 2,1
>> 3,1
>> 3,
>> 3,
>> 3,
>> 3, 2, 4, 4, 4, 4,
>> 3,
>> 6,1
>> 6,
>> 6,
>> 6, 5]
[5, 2, 7, 10,>> 12, 15]6
[2, 5,>> 10, 7, 15, 12]3
[1, 2, 3,>> 4, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 12, 13,
>> 14, 15, 16]
[6, 7, 8,>> 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3,
>> 4,
>> 5, 6, 7, 8, 9, 10, 11]
[]
bytecount: {'code': 1094, 'const': 512, 'code+const': 1606}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift=[]
user=[]
liftlist=[]
userlist=[]
liftcurrentfl=[]
liftdestfl=[]
usercurrentfl=[]
userdestfl=[]
answer=[]
best=0
x=True
y=True
liftcount=input("enter total lift number: ")
for i in range(int(liftcount)):
  liftelement = [int(n) for n in input("Enter lift value: ").split(" ")]
  liftlist.append(liftelement)
usercount=input("enter total user number: ")
for i in range(int(usercount)):
  userelement = [int(m) for m in input("Enter user value: ").split(" ")]
  userlist.append(userelement)
for i in range(len(liftlist)):
  for j in range(len(liftlist[i])):
    lift.append(liftlist[i][j])
for i in range(len(userlist)):
  for j in range(len(userlist[i])):
    user.append(userlist[i][j])
# print(lift)
# print(user)
for i in range(len(lift)):
  if (i %3) ==1:
    liftcurrentfl.append(lift[i])
  if (i%3) ==2:
    liftdestfl.append(lift[i])
for i in range(len(user)):
  if (i%2) ==0:
    usercurrentfl.append(user[i])
  if (i%2) ==1:
    userdestfl.append(user[i])
  #finding the best option
for i in range(len(userdestfl)):
  value=100
  for j in range(len(liftdestfl)):
    # user going up
    if int(userdestfl[i])>int(usercurrentfl[i]):
      # lift going up
      if int(liftdestfl[j])>int(liftcurrentfl[j]) and (int(usercurrentfl[i])<=int(liftdestfl[j]) and int(usercurrentfl[i])>=int(liftcurrentfl[j])):
          # user go higher than lift target
          if int(userdestfl[i])-int(liftdestfl[j]) > 0:
            cost=abs(int(liftdestfl[j])-int(userdestfl[i]))
            if cost<value:
              value=cost
              best=j
          # user go within lift target
          else:
            value=0
            best=j
        # starting under/above the lift range
      else:
        cost=int(userdestfl[i])-int(usercurrentfl[i])+ abs(int(liftdestfl[j]) - int(usercurrentfl[i]))
        if cost<value:
          value=cost
          best=j
    # user going down
    if int(userdestfl[i])<int(usercurrentfl[i]):
      # lift going down
      if int(liftdestfl[j])<int(liftcurrentfl[j]) and (int(usercurrentfl[i])>=int(liftdestfl[j]) and int(usercurrentfl[i])<=int(liftcurrentfl[j])) :
        # user go lower than lift target
        if int(userdestfl[i])-int(liftdestfl[j]) < 0:
          cost=abs(int(liftdestfl[j])-int(userdestfl[i]))
          if cost<value:
            value=cost
            best=j
        # user go within lift target
        else:
          value=0
          best=j
      # starting under/above the lift range
      else:
        cost=abs(int(userdestfl[i])-int(usercurrentfl[i]))+ abs(int(liftdestfl[j]) - int(usercurrentfl[i]))
        if cost<value:
          value=cost
          best=j
  answer.append(best+1)
print(answer)
print(liftcurrentfl)
print(liftdestfl)
print(usercurrentfl)
print(userdestfl)

6530394921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6531408221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
[6610013121, 4,>> 6610021021, 10, 6610061121,
>> 11,4
>> 6610000121, 8]
[]
test_main_20.0
[6610013121, 4,>> 6610021021,
>> 10, 6610061121,
>> 11, 6610000121,3
>> 8]4
[]
test_main_30.0
[6610013121, 4,>> 6610021021,
>> 10,
>> 6610061121,
>> 11,2
>> 6610000121,
>> 8]3
>> 3
>> 4
>> 4
[]
test_main_40.0
[6610013121,>> 4,
>> 6610021021,4
>> 10,4
>> 6610061121,3
>> 11,3
>> 661000012
>> 2
>> 1,
>> 8]1
[]
test_main_50.0
[661001>> 3
>> 3121,
>> 3
>> 4
>> 4,
>> 66100210
>> 2
>> 1,
>> 10,
>> 6610061121,
>> 11,
>> 6610000121, 8]
[]
test_main_60.0
[661001312>> 1,
>> 4,1
>> 66100
>> 210
>> 21,
>> 10,3
>> 6610061121,3
>> 11,4
>> 6610000121,4
>> 8]4
>> 4
[]
test_main_70.0
[66>> 100
>> 13
>> 1
>> 21,
>> 2
>> 4,
>> 6610021021,3
>> 10,3
>> 6610061121,3
>> 11,3
>> 6610000121,3
>> 8]3
[]
test_main_80.0
[66100131>> 2
>> 1,
>> 4,1
>> 661002
>> 102
>> 1,
>> 3
>> 3
>> 3
>> 3
>> 3
>> 10,
>> 6
>> 6100
>> 61121,
>> 6
>> 3
>> 11,4
>> 4
>> 4
>> 6610000121,4
>> 8]5
[]
bytecount: {'code': 328, 'const': 340, 'code+const': 668}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def get_sum(data):
    student_id = []
    for i in range(0,len(data)-1,2):
        if data[i] not in student_id:
            student_id.append(data[i])
            if data[i+1] == data[i]:
                student_id.remove(data[i+1])
            else:
                student_id.append(data[i+1])
        else:
            student_id[len(student_id)-1] += data[i+1]
    for i in range(0,len(student_id),2):
        score = []
        k = data.index(student_id[i])
        for e in range(k,len(data),2):
            if student_id[i] == data[e]:
                score.append(data[e+1])
            else:
                pass
        if len(score) > 3:
            student_id[i+1] = student_id[i+1] - min(score)
    return student_id
    return score
# -----------------------------
data = [
  6610013121,4,
  6610021021,5, 6610021021,5,
  6610061121,5, 6610061121,5, 6610061121,1,
  6610000121,3, 6610000121,2, 6610000121,2, 6610000121,3
]
out = get_sum(data)
print(out) # ต้องแสดง [6610013121, 4, 6610021021, 10, 6610061121, 11, 6610000121, 8]
# ข้อแนะนำ: ควรทดสอบ get_sum ด้วยข้อมูลชุดอื่นด้วย (ลิสต์ d ข้างบนอาจมีไม่ครอบคลุมทุกกรณี)

6532075021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0NameError("name 'calculate_additional_load' is not defined")
>> 2
>> 4
>> 1
[]
test_main_20.0NameError("name 'calculate_additional_load' is not defined")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0NameError("name 'calculate_additional_load' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'calculate_additional_load' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0NameError("name 'calculate_additional_load' is not defined")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0NameError("name 'calculate_additional_load' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0NameError("name 'calculate_additional_load' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0NameError("name 'calculate_additional_load' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 210, 'const': 147, 'code+const': 357}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevators = []
for i in range(n):
    elevator_info = list(map(int, input().split()))[1:]
    elevators.append(elevator_info)
m = int(input())
results = []
for i in range(m):
    start_floor, destination_floor = map(int, input().split())
    min_load = float('inf')
    best_elevator = i
    for j in range(n):
        elevator_load = calculate_additional_load(elevators[j], start_floor, destination_floor)
        if elevator_load < min_load:
            min_load = elevator_load
            best_elevator = j+1
    results.append(best_elevator)
for result in results:
    print(">>", result)

6630009421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
0>> 2
>> 4
>> 1
[]
test_main_20.0
5>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
7>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
5>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
7>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
9>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 490, 'const': 96, 'code+const': 586}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
import math
n = int(input())
a = []
for i in range(n):
    a.append([int(b) for b in input().split()])
q = int(input())
e = []
for i in range(q):
    e.append([int(b) for b in input().split()])
for i in e:
    for b in a:
        if i[1]>=i[0] and b[2] >= b[1]:
            if b[2] >= i[0] >= b[1]:
                i[0] = b[2]
                if b[2] >= i[1] >= b[1]:
                    i[1] = b[2]
        elif i[0] >= i[1] >= b[2] :
            if b[1] >= i[0] >= b[2]:
                i[0] = b[2]
                if b[1] >= i[1] >= b[2]:
                    i[1] = b[2]
        x = abs(b[2]-i[0])+abs(i[0]-i[1])
print(x)

6630029021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6630030521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0IndexError('list index out of range')
>> 2
>> 4
>> 1
[]
test_main_20.0IndexError('list index out of range')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0IndexError('list assignment index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0IndexError('list assignment index out of range')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0IndexError('list assignment index out of range')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0IndexError('list assignment index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0IndexError('list assignment index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0IndexError('list assignment index out of range')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1502, 'const': 147, 'code+const': 1649}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift_no = [0]*n
lift_floor = [0]*n
lift_di = [0]*n
lift_des = [0]*n
hm_floor = [0]*n
hm_des = [0]*n
hm_di = [0]*n
work = [0]*n
for i in range(n):
    t = input().split()
    lift_no[i] = str(t[0])
    lift_floor[i] = str(t[1])
    lift_des[i] = str(t[2])
    lift_di[i] = str(int(t[2])-int(t[1]))
q = int(input())
for i in range(q) :
    w = input().split()
    hm_floor[i] = str(w[0])
    hm_des[i] = str(w[1])
    hm_di[i] = str(int(w[1])-int(w[0]))
    for i in range(n) :
        if int(lift_di[i]) > 0 and int(hm_di[i]) > 0  and int(lift_floor[i]) < int(hm_floor[i]) and int(lift_des[i]) > int(hm_des[i]) :
            work[i] += 0
        elif int(lift_di[i]) > 0 and int(hm_di[i]) > 0 and int(lift_floor[i]) > int(hm_floor[i])  :
            work[i] += (int(lift_des[i])-int(hm_floor[i]))+(int(hm_des[i])-int(hm_floor[i]))
        elif int(lift_di[i]) > 0 and int(hm_di[i]) > 0 and int(lift_des[i]) < int(hm_des[i])  :
            work[i] += (int(hm_des[i]))-(int(lift_des[i]))
        elif int(lift_di[i]) > 0 and int(hm_di[i]) < 0 and int(hm_floor[i]) > int(lift_des[i])  :
            work[i] += ((int(hm_floor[i]))*2)-(int(hm_des[i])+int(lift_des[i]))
        elif int(lift_di[i]) > 0 and int(hm_di[i]) < 0 and int(hm_floor[i]) < int(lift_des[i])  :
            work[i] += int(lift_des[i])-int(hm_des[i])
        elif int(lift_di[i]) < 0 and int(hm_di[i]) < 0  and int(lift_floor[i]) > int(hm_floor[i]) and int(lift_des[i]) < int(hm_des[i]):
            work[i] += 0
        elif int(lift_di[i]) < 0 and int(hm_di[i]) < 0 and int(lift_floor[i]) < int(hm_floor[i])  :
            work[i] += (int(lift_des[i])-1)+(int(hm_floor[i])-1)+(int(hm_floor[i])-int(hm_des[i]))
        elif int(lift_di[i]) < 0 and int(hm_di[i]) < 0 and int(lift_des[i]) > int(hm_des[i])  :
            work[i] += (int(lift_des[i]))-(int(hm_des[i]))
        elif int(lift_di[i]) < 0 and int(hm_di[i]) > 0 and int(lift_des[i]) < int(hm_floor[i])  :
            work[i] += int(hm_des[i])-int(lift_des[i])
        elif int(lift_di[i]) < 0 and int(hm_di[i]) > 0 and int(lift_des[i]) > int(hm_floor[i])  :
            work[i] += ((int(hm_des[i])+int(lift_des[i]))-(int(hm_floor[i]))*2)
min = work[0]
for i in range(n+1) :
    if min > work[i] :
        min = work[i]
for i in range(n+1) :
    if min == work[i] :
        print (">>",i+1)

6630032821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6630053021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0TypeError("'list' object cannot be interpreted as an integer")
>> 2
>> 4
>> 1
[]
test_main_20.0TypeError("'list' object cannot be interpreted as an integer")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0TypeError("'list' object cannot be interpreted as an integer")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0TypeError("'list' object cannot be interpreted as an integer")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0TypeError("'list' object cannot be interpreted as an integer")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0TypeError("'list' object cannot be interpreted as an integer")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0TypeError("'list' object cannot be interpreted as an integer")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0TypeError("'list' object cannot be interpreted as an integer")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 618, 'const': 338, 'code+const': 956}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
amount = []
estart = []
estop = []
for i in range(amount):
  a, s1, s2  = [int(i) for i in input().split()]
  amount.append(a)
  estart.append(s1)
  estop.append(s2)
q = int(input())
qstart = []
qstop = []
for i in range(q):
  s1, s2 = [int(i) for i in input().split()]
  qstart.append(s1)
  qstop.append(s2)
def position(s1,s2):
  if s2 > s1:
    return 'up'
  elif s1 > s2:
    return 'down'
  else :
    return 'stationary'
def during(s1,ch,s2):
  if s1 <= ch <= s2:
    return True
  elif s1 >= ch >= s2:
    return True
  else :
    return False
for i in range(q): # ของคน
  total = []
  for j in range(n): # ของลิฟ
    if position(qstart[i],qstop[i]) == position(estart[j],estop[j]) and during(estart[j],qstart[i],estop[j]) and during(estart[j],qstop[i],estop[j]):
      work = 0
      total.append(work)
    elif position(qstart[i],qstop[i]) == position(estart[j],estop[j]) and during(estart[j],qstart[i],estop[j]):
      work = abs(estop[j]-estop[i])
      total.append(work)
    else:
      work = abs(estop[j]-qstart[i]) + abs(qstop[i]-qstart[i])
      total.append(work)
  winner = min(total) # หางานที่น้อยที่สุด
  index = total.index(winner)
  print(">>",amount[index])

6630062621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 8
IndentationError: unexpected indent
>> 2
>> 4
>> 1
[]
test_main_20.0 8
IndentationError: unexpected indent
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 8
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 8
IndentationError: unexpected indent
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 8
IndentationError: unexpected indent
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 8
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 8
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 8
IndentationError: unexpected indent
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
nls = []
n = int(input())
for i in range(n):
    nl,lh,ls = [int(e) for e in input().split()]
    nls.append([nl,lh,ls])
number_of_lift = []
for i in range(len(nls)):
    number_of_lift.append(nls[i][0])
      8
mh = []
ms = []
count = []
m = int(input())
for x in range(m):
    here,stop = [int(f) for f in input().split()]
    mh.append(here)
    ms.append(stop)
    for y in range(n):
        if (nls[y][2] >= mh[x] >= nls[y][1] and ((nls[y][2]-nls[y][1])/(ms[x]-mh[x]) > 0)) or (nls[y][2] <= mh[x] <= nls[y][1] and ((nls[y][2]-nls[y][1])/(ms[x]-mh[x])  > 0)):
            count.append(abs(ms[x] - nls[y][2]))
        else:
            count.append(abs(mh[x] - nls[y][2]) + abs(mh[x] - ms[x]))
new_count = []
for j in range(0, len(count), n):
    new_count.append(count[j:j+n])
for i in range(len(new_count)):
    print(">>", number_of_lift[new_count[i].index(min(new_count[i]))])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630064921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0EOFError('EOF when reading a line')
>> 2
>> 4
>> 1
[]
test_main_20.0EOFError('EOF when reading a line')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0EOFError('EOF when reading a line')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0EOFError('EOF when reading a line')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0EOFError('EOF when reading a line')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 706, 'const': 657, 'code+const': 1363}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
var = []
line = input()
while line:
    var.append(line)
    line = input()
data_lifts = []
data_people = []
for i in range(1, int(var[0]) + 1):
    data_lifts.append(var[i])
for i in range(int(var[0]) + 2, len(var)):
    data_people.append(var[i])
data_lifts_sep = []
data_people_sep = []
for i in data_lifts:
    data_lifts_sep.append(list(map(int, i.split())))
for i in data_people:
    data_people_sep.append(list(map(int, i.split())))
def up_or_down(a):
    for i in a:
        if i[-2] > i[-1]:
            i.append('Down')
        elif i[-2] < i[-1]:
            i.append('Up')
        elif i[-2] == i[-1]:
            i.append('Stay')
    return a
lifts = up_or_down(sorted(data_lifts_sep))
people = up_or_down(data_people_sep)
def least_work_lift(i, lift_list):
    work = []
    for j in lift_list:
        if i[2] == 'Stay':
            work.append(0)
        elif i[2] == j[3]:
            if (i[2] == 'Up' and j[1] <= i[0]) or (i[2] == 'Down' and j[1] >= i[0]):
                if (i[2] == 'Up' and j[2] < i[1]) or (i[2] == 'Down' and j[2] > i[1]):
                    work.append(abs(i[1] - j[2]))
                else:
                    work.append(0)
            else:
                work.append(abs(j[2] - i[0]) + abs(i[1] - i[0]))
        elif i[2] != j[3]:
            work.append(abs(j[2] - i[0]) + abs(i[0] - i[1]))
    return lift_list[work.index(min(work))][0]
for i in people:
    print('>>', least_work_lift(i, lifts))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630074121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0NameError("name 'n' is not defined")
>> 2
>> 4
>> 1
[]
test_main_20.0NameError("name 'n' is not defined")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0NameError("name 'n' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'n' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0NameError("name 'n' is not defined")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0NameError("name 'n' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0NameError("name 'n' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0NameError("name 'n' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 558, 'const': 314, 'code+const': 872}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้n= int(input())
liftnum=[]
liftstart=[]
liftstop=[]
for i in range(n):
    x,y,z =[int(i) for i in input().split()]
    liftnum.append(x)
    liftstart.append(y)
    liftstop.append(z)
m=int(input())
peoplestart=[]
peoplestop=[]
for i in range(m):
    x,y=[int(i) for i in input().split()]
    peoplestart.append(x)
    peoplestop.append(y)
def direction(start,stop):
    if stop < start:
        return "down"
    elif stop > start:
        return "up"
    else:
        return 'stationary'
def between(liftstart,people,liftstop):
    if liftstart <= people <= liftstop:
        return True
    elif liftstart >= people >= liftstop:
        return True
    else:
        False
for i in range(m):
    work=[]
    for j in range(n):
        if direction(peoplestart[i],peoplestop[i])== direction(liftstart[j],liftstop[j]) and between(liftstart[j],peoplestart[i],liftstop[j]):
            w = 0
            work.append(w)
        elif  direction(peoplestart[i],peoplestop[i])== direction(liftstart[j],liftstop[j]):
            w = abs(liftstop[j]-peoplestop[i])
            work.append(w)
        else :
            w = abs(liftstop[j]-peoplestart[i])+abs(peoplestop[i]-peoplestart[i])
            work.append(w)
    minimum = min(work)
    index = work.index(minimum)
    print(">>",liftnum[index])

6630079321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0ValueError("invalid literal for int() with base 10: '1 3 1'")
>> 2
>> 4
>> 1
[]
test_main_20.0ValueError("invalid literal for int() with base 10: '1 3 1'")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0ValueError("invalid literal for int() with base 10: '1 2 2'")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError("invalid literal for int() with base 10: '1 8 11'")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0ValueError("invalid literal for int() with base 10: '1 6 2'")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0ValueError("invalid literal for int() with base 10: '1 8 11'")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0ValueError("invalid literal for int() with base 10: '1 6 2'")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0ValueError("invalid literal for int() with base 10: '2 5 2'")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 612, 'const': 221, 'code+const': 833}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def Calculate(elevators,questions):
    scores = []
    for i in range(n):
        # ขึ้น
        if (elevators[i][2] > elevators[i][1]):
            # ผ่านชั้นที่เราอยู่
            if (elevators[i][1] <= questions[0]) and (elevators[i][2] >= questions[0]):
                # ชั้นปลายลิฟต์-ชั้นเป้าหมาย
                score = elevators[i][2] - questions[1]
                scores.append(abs(score))
            # ไม่ผ่านชั้นที่เราอยู่
            else :
                # (ชั้นปลาย-ชั้นที่เราอยู่)+(ชั้นเป้าหมาย-ชั้นเรา)
                scores.append(abs(elevators[i][2]-elevators[i][1])+abs(questions[1]-questions[0]))
        # จอด
        elif elevators[i][2] == elevators[i][1]:
            # (ชั้นที่เราอยู่-ชั้นที่จอด)+(ชั้นเป้าหมาย-ชั้นเรา)
            scores.append(abs(questions[0]-elevators[i][1])+abs(questions[1]-questions[0]))
        # ลง
        else :
            # ผ่านชั้นที่เราอยู่
            if(questions[0] <= elevators[i][1]) and (questions[0] >= elevators[i][2]):
                # (ชั้นปลายลิฟต์-ชั้นที่เป้าหมาย)
                score = elevators[i][2] - questions[1]
                scores.append(abs(score))
            # ไม่ผ่านชั้นที่เราอยู่
            else :
                # (ชั้นปลายลิฟต์-ชั้นที่เราอยู่)+(ชั้นเป้าหมาย-ชั้นเรา)
                scores.append(abs(elevators[i][2]-questions[0])+abs(questions[1]-questions[0]))
    result = min(scores)
    idx = scores.index(result)
    print(">>{}".format(idx+1))
# รับค่าลิฟต์
n = int(input())
elevators = []
for i in range(n):
    elevator = []
    for j in range(3):
        x = int(input())
        elevator.append(x)
    elevators.append(elevator)
# รับค่าคำถาม
q = int(input())
questions = []
for i in range(q):
    question = []
    for j in range(2):
        x = int(input())
        question.append(x)
    questions.append(question)
for i in range(q):
    Calculate(elevators,questions[i])

6630086721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 648, 'const': 96, 'code+const': 744}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
number_lift = int(input())
number_floor = []
start_all = []
end_all = []
for k in range(number_lift):
    f = input().split()
    number = f[0]
    start = f[1]
    end = f[2]
    number_floor.append(number)
    start_all.append(start)
    end_all.append(end)
number_question = int(input())
now_floor = []
to_floor = []
for l in range(number_question):
    me = input().split()
    now = me[0]
    to = me[1]
    now_floor.append(now)
    to_floor.append(to)
paracetamol = [0] * number_lift
for n in range(number_question):
    for m in range(number_lift):
        if int(start_all[m]) <= int(now_floor[n]) <= int(to_floor[n]) <= int(end_all[m]) or           int(start_all[m]) >= int(now_floor[n]) >= int(to_floor[n]) >= int(end_all[m]):
            para = 0
        elif int(start_all[m]) <= int(now_floor[n]) <= int(end_all[m]) < int(to_floor[n]) or             int(start_all[m]) >= int(now_floor[n]) >= int(end_all[m]) > int(to_floor[n]):
            para = abs(int(to_floor[n]) - int(end_all[m]))
        else:
            para = abs(int(start_all[m]) - int(now_floor[n])) + abs(int(end_all[m]) - int(now_floor[n]))
        paracetamol[m] = para
    number_n = number_lift
    for m in range(number_lift):
        if min(paracetamol) == paracetamol[m]:
            if int(number_floor[m]) <= int(number_n):
                number_n = number_floor[m]

6630268621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6630329221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 2
>> 4
>> 1
[]
test_main_20.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 if hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:
IndentationError: unexpected indent
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
num_of_elevator = input()
liststart = []
liststop = []
def liftwork(hstart,hstop):
  lift = 0
  max = 999
  work = 0


  for n in range(int(num_of_elevator)):
    elevstart = liststart[n]
    elevstop = liststop[n]
     if  hstart <= elevstart and hstop <= hstart and hstart >= elevstop and elevstop <= elevstart:

      if hstop < elevstop:
        work = elevstop - hstop
      else:
        work = 0

     else if hstart >= elevstart and hstop >= hstart and hstart >= elevstop and elevstop => elevstart:

       if hstop >= elevstop:
          work = hstop - elevstop
       else:
        work = 0

     elif hstart >= elevstop and hstop >= hstart:
               work = (hstart - elevstop)+(hstop-hstart)

     elif hstart <= hstop and elevstart >= elevstop:
               work = (elevstop - hstart)+(hstop-hstart)

     elif hstart <= hstop and elevstart >= elevstop:
               work = (hstart - elevstop)+(hstop-hstart)

     elif hstart >= elevstart and hstart >= hstop and elevstop < hstart:
               work = (hstart-elevstop)+(hstart-hstop)

     elif  hstart >= elevstart and hstart >= hstop and elevstop > hstart:
                work = (elestop-hstart)+(hstart-hstop)

     elif elevstop >= hstart and hstop <= hstart:
               work = (elevstop-hstart)+(hstop-hstart)

              if max > work
                 max = work
                 lift = n


     return lift + 1

 for n in range(int(num_of_elevator)):
      hques = input()
      lques = hques.split(" ")
      quesstart(int(lques[1]))
      quesstop(int(lques[2]))

quiz = input()
lifts = []
 for n in range(int(lques)):
      max = 999
      hques = input()
      lques = hques.split(" ")
      hstart = lques[0]
      hstop = lques[1]
      lift = liftwork(int(hstart),int(hstop))
      lifts.append(lift)

 for n in range(int(lques)):
      print(lift[n])

6631005021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0TypeError("'int' object is not subscriptable")
>> 2
>> 4
>> 1
[]
test_main_20.0TypeError("'int' object is not subscriptable")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0TypeError("'int' object is not subscriptable")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0TypeError("'int' object is not subscriptable")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0TypeError("'int' object is not subscriptable")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0TypeError("'int' object is not subscriptable")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0TypeError("'int' object is not subscriptable")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0TypeError("'int' object is not subscriptable")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 694, 'const': 147, 'code+const': 841}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
all_of_lift  = int(input())
lift = []
for i in range(all_of_lift):
    number_lift = all_of_lift[0]
    current_floor=all_of_lift[1]
    final_floor=all_of_lift[2]
lift.append([number_lift,current_floor,final_floor])
customer = int(input())
user = []
for j in range(passenger_use):
    current_customer=customer[0]
    final_customer=customer[1]
user.append([current_customer,final_customer])
a=[]
for i in a :
    u1=i[0]
    u2=i[1]
    a1=[]
    for j in lift :
        d1=j[1]
        d2=j[2]
        floor = 0
        if d2>d1 and u1>u2 :
            if d2>=u1:
                floor = d1-u1
            else :
                floor = (u1-u2)+(u1-d2)
        if d2>d1 and u1<u2 :
            if u1>=d2 :
                floor = u2-d2
            elif d2>u1 :
                if u2>d2 :
                    floor = u2-d2
                else :
                    floor = (d2+u2)-2*u1
            elif d1>=u1:
                 floor = (d2+u2)-2*u1
        if d1>d2 and u1<u2 :
             if u1>d2 :
                 floor = u2-d2
             if u1==d2 :
                 floor = u2-u1
             if u2==d2 :
                 floor = (d2+u2)-2*u1
             else :
                 floor = (d2+u2)-2*u1
        if d1>d2 and u1>u2 :
              if u1>d1 :
                  floor = 2*u1-(d2-u2)
              if u1==d1 :
                  if u1>=d2 :
                      floor = 0
                  else:
                      floor = d2-u2
              if u1<d1 :
                  floor = d2-u2
        if d1==d2:
               if u2>u1 :
                   if u1>=d1 :
                       floor = u2-d1
                   else :
                       floor = (d1+u2)-2*u1
               if u2<u1 :
                   if u1>d1:
                       floor = 2*u1-(d1+u2)
                   else :
                       floor = d1-u2
        a1.append(floor)
    a.append(a1)
for i in a :
    m = min(i)
    m2=i.index(m)+1
    print('>>',m2)

6631015321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0NameError("name 'ev' is not defined")
>> 2
>> 4
>> 1
[]
test_main_20.0NameError("name 'ev' is not defined")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0NameError("name 'ev' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'ev' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0NameError("name 'ev' is not defined")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0NameError("name 'ev' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0NameError("name 'ev' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0NameError("name 'ev' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 250, 'const': 216, 'code+const': 466}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
def find_n_ev(cf, df, ev):
    c_ev = None
    x = float('inf')
    for ev_id, (c_pos, d_pos) in ev.items():
        dc = abs(cf - c_pos)
        dd = abs(df - d_pos)
        y = dc + dd
        if y < x:
            c_ev = ev_id
            x = y
    return c_ev
for i in range(n):
    ev_info = input().split()
    ev_id = int(ev_info[0])
    c_pos = int(ev_info[1])
    d_pos = int(ev_info[2])
    ev[ev_id] = (c_pos, d_pos)
m = int(input())
for i in range(m):
    cf, df = map(int, input().split())
    n_ev = find_n_ev(cf, df, ev)
    print(f">> {n_ev}")

6631018221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 2
>> 4
>> 1
[]
test_main_20.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 load = (eleend-start) + (start-1 stop)
^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = int(input())
liststart = [0]*lift
listend = [0]*lift
def func(start,stop):
    load = int()
    min = 999e100
    ans = int()
    for i in range(lift):
        elestart = liststart[i]
        eleend = listend[i]
        if  elestart==stop and start==elestart and stop==eleend and start==stop:
            load = 0
        elif start>=elestart and eleend>=elestart and stop>=start and start<=eleend:
            if stop > eleend:
                load = stop-eleend
            else:
                load = 0
        elif start<=elestart and start>=eleend and stop<=start and eleend<=elestart:
            if stop < eleend:
                load = eleend-stop
            else:
                load = 0
        elif start>=eleend and stop>=start:
            load = (start-eleend)+(stop-start)
        elif elestart>=stop and stop>=start:
            if eleend > start:
                load = (eleend-start) + (stop-start)
            elif eleend < start:
                load = (start-eleend) + (stop-start)
        elif start<=eleend and stop<=start:
            load = (eleend-start) + (start-stop)
        elif elestart<=start and start>=stop:
            if eleend < start:
                load = (start-eleend) + (start-stop)
            elif eleend > start:
                load = (eleend-start) + (start-1 stop)
        if min > load:
            min = load
            ans = i
    return ans+1
for i in range(lift):
    x = input()
    s = x.split()
    liststart[int(s[0])-1]=int(s[1])
    listend[int(s[0])-1]=int(s[2])
Q = int(input())
LIS = []
for i in range(Q):
    y = input().split()
    start = y[0]
    stop = y[1]
    ans = func(int(start),int(stop))
    LIS.append(ans)
for i in range(int(Q)):
    print(">>", LIS[i])

6631103921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 if current < s < to
^
SyntaxError: expected ':'
>> 2
>> 4
>> 1
[]
test_main_20.0 if current < s < to
^
SyntaxError: expected ':'
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 if current < s < to
^
SyntaxError: expected ':'
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 if current < s < to
^
SyntaxError: expected ':'
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 if current < s < to
^
SyntaxError: expected ':'
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 if current < s < to
^
SyntaxError: expected ':'
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 if current < s < to
^
SyntaxError: expected ':'
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 if current < s < to
^
SyntaxError: expected ':'
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
list = []
for i in range(n):
  number = input().split()
  x = int(number[0])
  current = int(number[1])
  to = int(number[2])
  if current < to:
    up.append([x,currnt,to])
  else :
    down.append([x,current,to])
m = int(input())
for i in range(m):
  number = input().split()
  s = int(number[0])
  t = int(number[1])
  for lift in up:
    x,current,to = lift
    if current < s < to
    distance = 0
    else to < s
    distance = abs(current-to)+abs(s-t)
    else s < to
    distance = abs(current-to)+abs(s-t)
  for lift in down:
    x,current,to = lift
    distance = abs(current-s)+abs(s-to)
    if to < s < current
    distance = 0
    else s < current
    distance = abs(current-to)+abs(s-t)
    else to < s
    distance = abs(current-to)+abs(s-t)

6631121121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 for i in range(n):
IndentationError: unexpected indent
>> 2
>> 4
>> 1
[]
test_main_20.0 for i in range(n):
IndentationError: unexpected indent
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 for i in range(n):
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 for i in range(n):
IndentationError: unexpected indent
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 for i in range(n):
IndentationError: unexpected indent
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 for i in range(n):
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 for i in range(n):
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 for i in range(n):
IndentationError: unexpected indent
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)

# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
  for i in range(n):
    lift_info = input().split()
    lift_number = int(lift_info[0])
    initial_floor = int(lift_info[1])
    target_floor = int(lift_info[2])
    lifts_append((lift_number,initial_floor,target_floor))




      lift_direc = +1
   if (lift_start[index_lift] <= quation_start[index_quation] <= lift_final[index_lift]\
    or lift_final[index_lift] <= quation_start[index_quation] <= lift_start[index_lift])\
    and quation_direc == lift_direc:
   lift_distance.append(int(0))

   else:
 lift_distance.append(abs(lift_final[index_lift] - quation_start[index_quation]) + abs(quation_start[index_lift])
 min_distance = min(lift_distance)
 ans_lift = int((lift_distance.index(min_distance))) + 1
 print(ans_lift)

6631135021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0NameError("name 'calculate_workload' is not defined")
>> 2
>> 4
>> 1
[]
test_main_20.0NameError("name 'calculate_workload' is not defined")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0NameError("name 'calculate_workload' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'calculate_workload' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0NameError("name 'calculate_workload' is not defined")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0NameError("name 'calculate_workload' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0NameError("name 'calculate_workload' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0NameError("name 'calculate_workload' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 204, 'const': 223, 'code+const': 427}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lifts = []
for _ in range(n):
    lift_data = list(map(int, input().split()))
    lifts.append(lift_data)
m = int(input())
for _ in range(m):
    current_floor, destination_floor = map(int, input().split())
    min_workload = float('inf')
    best_lift = None
    for lift_num, lift_data in enumerate(lifts, start=1):
        lift_current_floor, lift_destination_floor = lift_data[1], lift_data[2]
        total_workload = calculate_workload(lift_current_floor, current_floor) + calculate_workload(current_floor, destination_floor)
        if total_workload < min_workload:
            min_workload = total_workload
            best_lift = lift_num
    print(">>", best_lift)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631205221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 2
>> 4
>> 1
[]
test_main_20.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 else:
^
IndentationError: unindent does not match any outer indentation level
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)

# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
l = []
for i in range(n):
    x = [int(e) for e in input().split()]
    l.append(x) #x=[1,3,1]
m = int(input())
for i in range(m):
     currentfloor,destination =[int(e) for e in input().split()]
     extrawork = []
     for e in l:
         if (e[1] <= currentfloor <= e[2] or e[2] <= currentfloor <= e[1]) and ((e[2] >= e[1] and destination >= currentfloor) or (e[1] >= e[2] and destination <= currentfloor)):
             if(e[1]<= destination <= e[2] or e[2] <= destination <= e[1]):
                extrawork.append(0)
            else:
                extrawork.append(abs(destination-e[2]))
         else:
             extrawork.append(abs(currentfloor-e[2])+abs(destination - currentfloor))
     mn= min(extrawork)
     ind = extrawork.index(mn)
     print(l[ind][0])

6631215521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 478, 'const': 163, 'code+const': 641}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def data_input(l):
   n = int(input())
   for i in range(n):
    x=[int(j) for j in input().split()]
    l.append(x)
    L=[]
    Q=[]
    data_input(L)
    data_input(Q)
    print(L,Q)
    for i in range(len(Q)):
      elevator_current,elevator_destination=Q[i][0],Q[i][1]
    lift_num=[]
    for j in range(len(L)):
      currentfloor,destination=L[j][1],L[j][2]
      if currentfloor>destination and elevator_current>=elevator_destination:
        if currentfloor>=elevator_current and destination>elevator_destination:
          lift_num.append(abs(elevator_destination-destination))
        elif currentfloor>=elevator_current and destination<=elevator_destination:
          lift_num.append(0)
        else:
          lift_num.append(abs(elevator_current-destination)+abs(elevator_current-elevator_destination))
      elif currentfloor<destination and elevator_current<=elevator_destination:
        if currentfloor<=elevator_current and destination<elevator_destination:
         lift_num.append(abs(elevator_destination-destination))
        elif currentfloor<=elevator_current and destination>=elevator_destination:
         lift_num.append(0)
        else:
         lift_num.append(abs(elevator_current-destination)+abs(elevator_current-elevator_destination))
        print(lift_num)
        print('>>',lift_num.index(min(lift_num))+1)
        lift_num=[]

6631222921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0EOFError('EOF when reading a line')
>> 2
>> 4
>> 1
[]
test_main_20.0EOFError('EOF when reading a line')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0EOFError('EOF when reading a line')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0EOFError('EOF when reading a line')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0EOFError('EOF when reading a line')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 812, 'const': 276, 'code+const': 1088}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
line=[]
while True:
  data=input()
  if data=='':
      break
  else:
      line.append(data)
number_lift=int(line[0])
number_question=int(line[number_lift+1])
lift=line[:number_lift+1]
question=line[number_lift+1:]
#check ques go up or down
for x in range(1,len(question)):
  question_x=question[x]
  q=question_x.split(' ')
  ans=[]
  for x in range(1,len(lift)):
      liftx=lift[x]
      l=liftx.split(' ')
        #go down ans and ques
      if int(l[1])>int(l[2]) and int(q[0])>int(q[1]):
          if int(l[1])>=int(q[0]) and int(l[2])>=int(q[1]):
              m=abs(int(l[2])-int(q[1]))
              ans.append(m)
          elif int(l[1])>=int(q[0]) and int(l[2])<=int(q[1]):
                ans.append(0)
          else:
            m=abs(int(q[0])-int(l[2]))+abs(int(q[1])-int(q[0]))
            ans.append(m)
        #go up ans and ques
      elif int(l[1])<int(l[2]) and int(q[0])<int(q[1]):
          if int(l[1])<=int(q[0]) and int(l[2])<=int(q[1]):
              m=abs(int(l[2])-int(q[1]))
              ans.append(m)
          elif int(l[1])<=int(q[0]) and int(l[2])>=int(q[1]):
              ans.append(0)
          else:
            m=abs(int(q[0])-int(l[2]))+abs(int(q[1])-int(q[0]))
            ans.append(m)
        #any opposite
      else:
          m=abs(int(q[0])-int(l[2]))+abs(int(q[1])-int(q[0]))
          ans.append(m)
  print('>>',ans.index(min(ans))+1)

6631227021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0EOFError('EOF when reading a line')
>> 2
>> 4
>> 1
[]
test_main_20.0EOFError('EOF when reading a line')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0EOFError('EOF when reading a line')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0EOFError('EOF when reading a line')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0EOFError('EOF when reading a line')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 580, 'const': 276, 'code+const': 856}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
line = []
while True:
    data = input()
    if data == '':
        break
    else:
        line.append(data)
lift_no = int(line[0])
lift = line[:lift_no + 1]
qu = line[lift_no + 1:]
for x in range(1, len(qu)):
    qu_x = qu[x]
    q = qu_x.split(' ')
    ans = []
    for x in range(1, len(lift)):
        liftb = lift[x]
        l = liftb.split(' ')
        if int(l[1]) > int(l[2]) and int(q[0]) > int(q[1]):
            if int(l[1]) >= int(q[0]) and int(l[2]) >= int(q[1]):
                a = abs(int(l[2]) - int(q[1]))
                ans.append(a)
            if int(l[1]) >= int(q[0]) and int(l[2]) <= int(q[1]):
                ans.append(0)
        if int(l[1]) < int(l[2]) and int(q[0]) < int(q[1]):
            if int(l[1]) <= int(q[0]) and int(l[2]) <= int(q[1]):
                a = abs(int(l[2]) - int(q[1]))
                ans.append(a)
        else:
            a = abs(int(q[0]) - int(l[2])) + abs(int(q[1]) - int(q[0]))
            ans.append(a)
    print('>>', ans.index(min(ans)) + 1)

6631307621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0NameError("name 'n' is not defined")
>> 2
>> 4
>> 1
[]
test_main_20.0NameError("name 'n' is not defined")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0NameError("name 'n' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'n' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0NameError("name 'n' is not defined")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0NameError("name 'n' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0NameError("name 'n' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0NameError("name 'n' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 582, 'const': 419, 'code+const': 1001}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def lift(present, go):
    value= [' ']*n
    present = int(present)
    go = int(go)
    if go-present > 0:
        statusrao = 'up'
    else:
        statusrao = 'down'
    for i in range(n):
        if int(data[i][2])- int(data[i][1]) > 0:
            statuslift[i] = 'up'
        else:
            statuslift[i] = 'down'
        if statuslift[i] != statusrao:
            load[i] = abs(present-int(data[i][2])) + abs(go-present)
        elif statuslift[i] == statusrao:
            if statusrao == 'down':
                if int(data[i][1]) < present:
                    load[i] = abs(present-int(data[i][2])) + abs(go-present)
                elif int(data[i][1]) >= present:
                    load[i] = abs(go-int(data[i][2]))
            elif statusrao == 'up':
                if int(data[i][1]) > present:
                    load[i] = (int(data[i][2])-present) + abs(go-present)
                elif int(data[i][1]) <= present:
                    load[i] = abs(go-int(data[i][2]))
    x = min(load)
    for j in range(n):
        if load[j] == x:
            anslift = j+1
            break
    return anslift
m = int(input())
ans = [' ']*m
for k in range(m):
    yarkru = input().split()
    ans[k] = lift(int(yarkru[0]), int(yarkru[1]))
#    print(">>", lift(int(yarkru[0]), int(yarkru[1]))) #แก้ตรงนี้เก็บใส่listแล้วprintทีเดียวก็ได้
for k in range(m):
    print(">>", ans[k])

6631454121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6631459321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6631471821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0ValueError('too many values to unpack (expected 2)')
>> 2
>> 4
>> 1
[]
test_main_20.0ValueError('too many values to unpack (expected 2)')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0ValueError('too many values to unpack (expected 2)')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('too many values to unpack (expected 2)')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0ValueError('too many values to unpack (expected 2)')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0ValueError('too many values to unpack (expected 2)')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0ValueError('too many values to unpack (expected 2)')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0ValueError('too many values to unpack (expected 2)')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 234, 'const': 164, 'code+const': 398}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def find_best_elevator(elevators, current_floor, target_floor):
    min_extra_floors = float('inf')
    best_elevator = None
    for elevator, (current_pos, target_pos) in enumerate(elevators):
        extra_floors = abs(current_pos - current_floor) + abs(target_pos - current_floor) + abs(target_pos - target_floor)
        if extra_floors < min_extra_floors:
            min_extra_floors = extra_floors
            best_elevator = elevator + 1
    return best_elevator
n = int(input())
elevators = []
for _ in range(n):
    elevator_info = tuple(map(int, input().split()))
    elevators.append(elevator_info)
m = int(input())
for _ in range(m):
    current_floor, target_floor = map(int, input().split())
    best_elevator = find_best_elevator(elevators, current_floor, target_floor)
    print(f">> {best_elevator}")
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631518721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 4, 'const': 16, 'code+const': 20}

6631525021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 = item[3]
^
SyntaxError: invalid syntax
>> 2
>> 4
>> 1
[]
test_main_20.0 = item[3]
^
SyntaxError: invalid syntax
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 = item[3]
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 = item[3]
^
SyntaxError: invalid syntax
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 = item[3]
^
SyntaxError: invalid syntax
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 = item[3]
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 = item[3]
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 = item[3]
^
SyntaxError: invalid syntax
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
ภาระ = 0
x = int(input())
happened = []
for i in range(x):
    num, c_lift, t_lift = map(int, input().split())
    if c_lift < t_lift:
        happened.append((int(num), 1, c_lift, t_lift))
    else:
        happened.append((int(num), 0, c_lift, t_lift))
m = int(input())
for i in range(m):
    c_me, t_me = map(int, input().split())
    min = float('inf')
    for item in happened:
        UoD = item[1]
        c_lift = item[2]
        t_lift
        = item[3]
        if UoD == 1:
            if c_lift <= c_me <= t_lift:
                ภาระ = abs(t_lift-t_me)
        else:
            if t_lift <= c_me <= c_lift:
                ภาระ = abs(t_lift-t_me)
            else:
                ภาระ = abs(t_lift - c_me)
        if ภาระ < min:
            min = ภาระ
            show = item[0]
    print(">>",show )

6631540421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 1 3 1
^
SyntaxError: invalid syntax
>> 2
>> 4
>> 1
[]
test_main_20.0 1 3 1
^
SyntaxError: invalid syntax
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 1 3 1
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 1 3 1
^
SyntaxError: invalid syntax
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 1 3 1
^
SyntaxError: invalid syntax
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 1 3 1
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 1 3 1
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 1 3 1
^
SyntaxError: invalid syntax
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = []
for i in range(n):
    lift_d = input().split()
    lift_n = int(lift_d[0])
    current_f = int(lift_d[1])
    target_f = int(lift_d[2])
    lifts.append((lift_n, current_f, target_f))
m = int(input())
for i in range(m):
    x = input().split()
    user = int(x[0])
    target_f = int(x[1])
    minf = float('inf')
    best = None
    for lift_n, current_f, target in lifts:
        if current_f <= user and target_f >= user :
            add = abs(target_f- target)
        elif current_f >= user and target_f <= user :
            add = abs(target_f- target)
        else:add = abs(target - user) + abs(target_f - user)
        if add < minf:
            minf = add
            best = lift_n
    print(f">> {best}")
4
1 3 1
2 2 8
3 10 10
4 12 6
4
1 6
8 12
11 15
4 1

6631548521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0IndexError('list index out of range')
>> 2
>> 4
>> 1
[]
test_main_20.0IndexError('list index out of range')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0IndexError('list index out of range')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0IndexError('list index out of range')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0IndexError('list index out of range')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 276, 'const': 255, 'code+const': 531}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
inputs = list(map(int, input().split()))
n = inputs[0]
elevators = []
for i in range(1, n * 3 + 1, 3):
    elevators.append(inputs[i:i+3])
m = inputs[n*3+1]
# Extract query details
queries = []
for i in range(n * 3 + 2, n * 3 + 2 + m * 2, 2):
    queries.append(inputs[i:i+2])
for q in queries:
    distances = [abs(e[1] - q[0]) + abs(e[2] - q[1]) for e in elevators]
    min_distance = min(distances)
    print(">>", distances.index(min_distance) + 1)

6631553621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 2
>> 4
>> 1
[]
test_main_20.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 print(">>", bestlift)6
^
SyntaxError: invalid syntax
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = []
for i in range(n):
    lift_num, lift_current_floor, lift_destination_floor = map(int, input().split())
    lifts.append((lift_num, lift_current_floor, lift_destination_floor))
m = int(input())
for i in range(m):
    x = input().split()
    user = int(x[0])
    target_f = int(x[1])
    minf = float("inf")
    best = None
    for lift_n, current_f, target in lifts :
        if current_f <= user and target_f >= user :
            add = abs(target_f - target)
        elif current_f >= user and target_f <= user :
            add = abs(target_f - target)
        else:
            add = abs(target - user) + abs(target_f - user)
        if add < minf:
            minf = add
            bestlift = lift_n
    print(">>", bestlift)6

6631803521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0 burdens = list()
IndentationError: unexpected indent
>> 2
>> 4
>> 1
[]
test_main_20.0 burdens = list()
IndentationError: unexpected indent
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0 burdens = list()
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0 burdens = list()
IndentationError: unexpected indent
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0 burdens = list()
IndentationError: unexpected indent
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0 burdens = list()
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0 burdens = list()
IndentationError: unexpected indent
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0 burdens = list()
IndentationError: unexpected indent
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input().strip())
elevators = list()
for _ in range(n):
  number, elevator_current_floor, elevator_destination_floor = [int(x) for x in input().split()]
  if elevator_destination_floor - elevator_current_floor > 0:
    elevator_move = 1    # up
  elif elevator_destination_floor - elevator_current_floor < 0:
    elevator_move = -1   # down
  else:
    elevator_move = 0    # still
  elevators.append([number, elevator_current_floor, elevator_destination_floor, elevator_move])
m = int(input().strip())
for _ in range(m):
  user_current_floor, user_destination_floor = [int(x) for x in input().split()]
  if user_destination_floor - user_current_floor > 0:
    user_move = 1    # up
  elif user_destination_floor - user_current_floor < 0:
    user_move = -1   # down
  else:
    user_move = 0    # still
11
  burdens = list()
  for elevator in elevators:
    if user_move == elevator[3]:
      if user_current_floor in range(min(elevator[1], elevator[2]), max(elevator[1], elevator[2]) + 1):
        burden = max(abs(user_destination_floor - elevator[2]), 0)
      else:
        burden = abs(elevator[2] - user_current_floor) + abs(user_destination_floor - user_current_floor)
    else:
      burden = abs(elevator[2] - user_current_floor) + abs(user_destination_floor - user_current_floor)
    burdens.append([burden, elevator[0]])
  print(">>", sorted(burdens)[0][1])

6631809321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632253521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0NameError("name 'calculate_load' is not defined")
>> 2
>> 4
>> 1
[]
test_main_20.0NameError("name 'calculate_load' is not defined")
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0NameError("name 'calculate_load' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'calculate_load' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0NameError("name 'calculate_load' is not defined")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0NameError("name 'calculate_load' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0NameError("name 'calculate_load' is not defined")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0NameError("name 'calculate_load' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 206, 'const': 227, 'code+const': 433}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevators = []
for i in range(n):
    elevator_data = input().split()
    elevator_num = int(elevator_data[0])
    current_floor = int(elevator_data[1])
    destination_floor = int(elevator_data[2])
    elevators.append((elevator_num, current_floor, destination_floor))
m = int(input())
for _ in range(m):
    current_floor, destination_floor = map(int, input().split())
    min_load = float('inf')
    chosen_elevator = -1
    for elevator_num, current, destination in elevators:
        load = calculate_load(current, destination, current_floor, destination_floor)
        if load < min_load:
            min_load = load
            chosen_elevator = elevator_num
print(">>", chosen_elevator)

6632156321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0ValueError('too many values to unpack (expected 2)')
>> 2
>> 4
>> 1
[]
test_main_20.23ValueError('too many values to unpack (expected 2)')
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.1ValueError('too many values to unpack (expected 2)')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('too many values to unpack (expected 2)')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0ValueError('too many values to unpack (expected 2)')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.09ValueError('too many values to unpack (expected 2)')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.08ValueError('too many values to unpack (expected 2)')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0ValueError('too many values to unpack (expected 2)')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 666, 'const': 218, 'code+const': 884}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
NE = int(input())
EN = []
EI = []
EF = []
UN = []
UI = []
UF = []
NW = []
for a in range (NE):
    number = a+1
    EN.append(number)
    print(EN[a], end=" ")
    EP = input()
    ei, ef = map(int, EP.split())
    EI.append(ei)
    EF.append(ef)
NU = int(input())
for a in range (NU):
    number = a+1
    UN.append(number)
    UP = input()
    ui, uf = map(int, UP.split())
    UI.append(ui)
    UF.append(uf)
for i in range (NU):
    NW.append([])
for a in range (NU):
    for b in range(NE):
        user = []
        elevator = []
        user.append(UI[a])
        user.append(UF[a])
        elevator.append(EI[b])
        elevator.append(EF[b])
        lower_floor, upper_floor = sorted(elevator)
        if lower_floor <= min(user) <= upper_floor and lower_floor <= max(user) <= upper_floor:
            if (UF[a]-UI[a])*(EF[b]-EI[b]) >= 1:
                w = 0
            else:
                w = abs(EF[b]-UF[a])
        elif lower_floor <= UI[a] <= upper_floor:
            w = abs(EF[b]-UF[a])
        else:
            w = abs(EF[b]-UI[a]) + abs(UI[a]-UF[a])
        NW[a].append(w)
    sort = sorted(NW[a])
    if sort[0] == sort[1]:
        best_elevator = sort[0]
        and_its_number_is = NW[a].index(best_elevator) + 1
    else:
        best_elevator = sort[0]
        and_its_number_is = NW[a].index(best_elevator) + 1
    print(">>>", and_its_number_is)

6631134321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.3IndexError('list index out of range')
>> 2
>> 4
4>> 1
[]
test_main_20.0IndexError('list index out of range')
4>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.2IndexError('list index out of range')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0IndexError('list index out of range')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0IndexError('list index out of range')
4>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0IndexError('list index out of range')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1750, 'const': 175, 'code+const': 1925}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
print(4) #จำนวนลิฟต์
a = input().split()
b = input().split()
c = input().split()
d = input().split()
print(4) #จำนวนคำถาม
e = input().split()
f = input().split()
g = input().split()
h = input().split()
A = abs(int(a[2]) - int(e[0])) + abs(int(e[0]) - int(e[1]))
B = abs(int(b[2]) - int(e[0])) + abs(int(e[0]) - int(e[1]))
C = abs(int(c[2]) - int(e[0])) + abs(int(e[0]) - int(e[1]))
D = abs(int(d[2]) - int(e[0])) + abs(int(e[0]) - int(e[1]))
if ((A < B) and (A < C) and (A < D)) :
  print(">>" + a[0])
else :
  if ((B < A) and (B < C) and (B < D)) :
    print(">>" + b[0])
  else :
    if ((C < A) and (C < B) and (C < D)) :
      print(">>" + c[0])
    else :
      if ((D < A) and (D < B) and (D < C)) :
        print(">>" + d[0])
E = abs(int(a[2]) - int(f[0])) + abs(int(f[0]) - int(f[1]))
F = abs(int(b[2]) - int(f[0])) + abs(int(f[0]) - int(f[1]))
G = abs(int(c[2]) - int(f[0])) + abs(int(f[0]) - int(f[1]))
H = abs(int(d[2]) - int(f[0])) + abs(int(f[0]) - int(f[1]))
if ((E < F) and (E < G) and (E < H)) :
  print(">>" + a[0])
else :
  if ((F < E) and (F < G) and (F < H)) :
    print(">>" + b[0])
  else :
    if ((G < E) and (G < F) and (G < H)) :
      print(">>" + c[0])
    else :
      if ((H < E) and (H < F) and (H < G)) :
        print(">>" + d[0])
I = abs(int(a[2]) - int(g[0])) + abs(int(g[0]) - int(g[1]))
J = abs(int(b[2]) - int(g[0])) + abs(int(g[0]) - int(g[1]))
K = abs(int(c[2]) - int(g[0])) + abs(int(g[0]) - int(g[1]))
L = abs(int(d[2]) - int(g[0])) + abs(int(g[0]) - int(g[1]))
if ((I < J) and (I < K) and (I < L)) :
  print(">>" + a[0])
else :
  if ((J < I) and (J < K) and (J < L)) :
    print(">>" + b[0])
  else :
    if ((K < I) and (K < J) and (K < L)) :
      print(">>" + c[0])
    else :
      if ((L < I) and (L < J) and (L < K)) :
        print(">>" + d[0])
M = abs(int(a[2]) - int(h[0])) + abs(int(h[0]) - int(h[1]))
N = abs(int(b[2]) - int(h[0])) + abs(int(h[0]) - int(h[1]))
O = abs(int(c[2]) - int(h[0])) + abs(int(h[0]) - int(h[1]))
P = abs(int(d[2]) - int(h[0])) + abs(int(h[0]) - int(h[1]))
if ((M < N) and (M < O) and (M < P)) :
  print(">>" + a[0])
else :
  if ((N < M) and (N < O) and (N < P)) :
    print(">>" + b[0])
  else :
    if ((O < M) and (O < N) and (O < P)) :
      print(">>" + c[0])
    else :
      if ((P < M) and (P < N) and (P < O)) :
        print(">>" + d[0])

6630095321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 1
>> 14
>> 1
[]
test_main_20.0
>> 51
>> 52
>> 53
>> 54
[]
test_main_30.0
>> 31
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 34
>> 4
[]
test_main_40.0
>> 74
>> 4
>> 4
>> 3
>> 3
>> 2
>> 72
>> 71
>> 71
[]
test_main_50.0
>> 53
>> 53
>> 53
>> 54
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0
>> 71
>> 71
>> 71
>> 72
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.23
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 336, 'const': 91, 'code+const': 427}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
no = [0] * n
now = [0] * n
goal = [0] * n
for i in range(n):
    x, y, z = map(int, input().split())
    no[i] = x
    now[i] = y
    goal[i] = z
m = int(input())
now0 = [0] * m
goal0 = [0] * m
for e in range(m):
    a, b = map(int, input().split())
    now0[e] = a
    goal0[e] = b
lift = [0] * n
for c in range(m):
    for d in range(n):
        if goal[d] != goal0[c]:
            p = abs(goal0[c] - goal[d])
        else:
            p = abs(now0[c] - goal[d]) + abs(goal0[c] - now0[c])
        lift[d] = p
for c in range(n):
    print(">>", lift[d])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630020221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 2
>> 4
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.12
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.12
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.09
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.09
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.09
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.05
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 548, 'const': 219, 'code+const': 767}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()); s = [];
for i in range(n): s += [int(e) for e in input().split()]
m = int(input()); u = [];
for i in range(m): u += [int(e) for e in input().split()]
# check travelling distance of lift
def distance_check(ls,lf,us,uf):
  if ls<=us<=uf<=lf or ls>=us>=uf>=lf: return 0 # fully overlap
  elif ls<=us<=lf<=uf or ls>=us>=lf>=uf: return abs(lf-uf) # partial overlap
  else: return abs(lf-us)+abs(us-uf) # not overlap
big_loop = 1;
while big_loop<=m: # check for every users
  small_loop = 1; ans_list = []; ans = []; # set parameters before starting a big loop
  while small_loop<=n: # check all lifts
    ans_list += [distance_check(int(s[3*small_loop-2]),int(s[3*small_loop-1]),int(u[2*big_loop-2]),int(u[2*big_loop-1]))]
    small_loop += 1
  for i in range(n):
    if ans_list[i] == min(ans_list): ans += [s[3*i]] # check minimum answer
  print(">>",str(min(ans))) # print final answer
  big_loop += 15

6630037021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.5
>> 1
>> 12
>> 3
>> 34
[]
test_main_30.12IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0IndexError('list index out of range')
>> 14
>> 4
>> 4
>> 3
>> 3
>> 12
>> 2
>> 1
>> 1
[]
test_main_50.0IndexError('list index out of range')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.09IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.09IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0IndexError('list index out of range')
>> 2
>> 1
>> 21
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 53
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 742, 'const': 147, 'code+const': 889}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
N = int(input())
Elevator = []
for i in range(N):
    x = input().split()
    y = x[1:]
    Elevator.append(y)
n = int(input())
Human = []
for i in range(n):
    x = input().split()
    Human.append(x)
Win = []
for i in range(len(Human)):
    winner = 0
    hstart,hstop = int(Human[i][0]),int(Human[i][1])
    hh = hstop - hstart
min = 100000000
for j in range(len(Elevator)):
    movesneeded = 0
    estart,estop = int(Elevator[j][0]),int(Elevator[j][1])
    ee = estop - estart
    if hh > 0 and ee > 0:
        if estart <= hstart <= estop:
            if hstop <= estop:
                movesneeded = 0
            else:
                movesneeded = hstop - estop
        elif hstart > estop :
            movesneeded = hstop - estop
        else:
            movesneeded = estop - hstart + (hstop-hstart)
    elif hh < 0 and ee < 0:
        if estop <= hstart <= estart:
            if hstop >= estop:
                movesneeded = 0
            else:
                movesneeded = estop - hstop
        elif estop > hstart :
            movesneeded = estop - hstop
        else:
            movesneeded = hstart - estop + (hstart - hstop)
    elif hh < 0 and ee > 0 :
        if estop >= hstop >= estart :
            if hstop > estart:
                movesneed = estop - hstop
            else :
                movesneeded = estop - hstop
        elif hstart > estop :
            movesneeded = hstart - estop + (hstart - hstop)
        else:
            movesneeded = estop - hstop
    else :
        hh > 0 and ee < 0
        if estop <= hstart <= estart :
            if estart > hstop :
                movesneeded = hstop - estop
            else :
                movesneeded = hstop - estop
        elif hstop < estop :
            movesneeded = estop - hstart + (hstop - hstart)
        else :
           movesneeded = hstop - estop
    if movesneeded < min :
        winner = j
        min = movesneeded
    else :
        pass
    Win.append(winner)
for q in range(len(Human)):
    print('>>',Win[q]+1)

6631534721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 12
>> 34
>> 3
>> 41
[]
test_main_20.75
>> 1
>> 32
>> 3
>> 4
[]
test_main_30.12
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0
>> 14
>> 4
>> 4
>> 3
>> 3
>> 42
>> 2
>> 1
>> 1
[]
test_main_50.25
>> 13
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.09
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.09
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 43
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 380, 'const': 506, 'code+const': 886}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def best_elevator(input_str):
    lines = input_str.strip().split("\n")
    n = int(lines[0])
    elevators = []
    for i in range(1, n + 1):
        elevator_number, current_floor, target_floor = map(int, lines[i].split())
        elevators.append((elevator_number, current_floor, target_floor))
    m = int(lines[n + 1])
    for i in range(n + 2, n + 2 + m):
        query_start, query_end = map(int, lines[i].split())
        min_additional_travel = float('inf')
        best_elevator = None
        for elevator_number, current_floor, target_floor in elevators:
            if current_floor == target_floor:
                additional_travel = abs(current_floor - query_start) + abs(query_end - query_start)
            elif current_floor <= query_start <= target_floor or target_floor <= query_start <= current_floor:
                additional_travel = abs(query_end - query_start)
            else:
                additional_travel = abs(current_floor - query_start) + abs(query_end - query_start)
            if additional_travel < min_additional_travel:
                min_additional_travel = additional_travel
                best_elevator = elevator_number
            elif additional_travel == min_additional_travel:
                best_elevator = min(best_elevator, elevator_number)
        print(f">> {best_elevator}")
input_str = """4
               1 3 1
               2 2 6
               3 9 10
               4 8 6
               4
               2 5
               9 12
               11 12
               7 3"""
best_elevator(input_str)

6631504921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.3
1>> 2
1>> 4
1
1
1
1
1
1
>> 1
[]
test_main_20.45
1
1
3
3
1
1
3
3
1
1
3
3
>> 1
1>> 2
>> 3
3>> 4
[]
test_main_30.1IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0IndexError('list index out of range')
1>> 4
>> 4
>> 4
>> 3
>> 3
1>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0IndexError('list index out of range')
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.25IndexError('list index out of range')
>> 1
>> 1
>> 1
1>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.23IndexError('list index out of range')
>> 1
>> 1
>> 1
1>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.04IndexError('list index out of range')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
5>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 590, 'const': 174, 'code+const': 764}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = input()
lstart =[]
lend = []
for i in range(int(lift)):
  dum = input()
  dummy = dum.split(" ")
  lstart.append(int(dummy[1]))
  lend.append(int(dummy[2]))
q = input()
listans = []
for i in range(int(q)) :
      dum = input()
      dummy = dum.split(" ")
      n = int(dummy[0])
      e = int(dummy[1])
      s = 0
      minn = 100000
      answer = 0
      for i in range(int(lift)) :
        es = lstart[i]
        ee = lend[i]
        if n >=es and n <= ee and e >= n and ee >= es :
          if e > ee :
            s = e - ee
          else:
            s = 0
        elif n <= es and n >= ee and e<= n and ee <= es :
          if e < ee :
            s = ee -e
          else :
            s = 0
        elif n >=ee and e >=n :
          s = (n - ee) + (e-n)
        elif es >=e and e >=n :
          if ee > n :
            s = (n - ee) + (e-n)
          elif ee < n :
            s = (n - ee) + (e - n)
          elif n <= ee and e <=n :
            s = (ee - n) + (n - e)
          elif   es <=n and n >=e :
                if ee < n :
                   s = (n -ee) + (n - e)
                elif ee > n :
                  s = (ee - n) + (n - e)
          #print(minn)
          if minn > s :
            minn = s
            answer = i
            #print(answer)
        listans.append(answer+1)
      for i in range(int(q)) :
        print(listans[i])

6631542721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 12
>> 24
>> 31
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.12IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0IndexError('list index out of range')
>> 14
>> 4
>> 4
>> 3
>> 3
>> 2
>> 32
>> 1
>> 41
[]
test_main_50.17IndexError('list index out of range')
>> 13
>> 23
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.09IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.09IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 32
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.09IndexError('list index out of range')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 56
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 748, 'const': 256, 'code+const': 1004}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
liftnum = [0]*n
liftstart = [0]*n
liftstop = [0]*n
for i in range(n):
  lift = input()
  lift = lift.split()
  liftnum[i] = int(lift[0])
  liftstart[i] = int(lift[1])
  liftstop[i] = int(lift[2])
m = int(input())
personstart = [0]*m
personstop = [0]*m
for j in range(m):
  person = input()
  person = person.split()
  personstart[j] = int(person[0])
  personstop[j] = int(person[1])
def morepara(lift_start,lift_stop,person_tart,person_stop) :
 if lift_stop <= person_stop <= person_start <= lift_start or lift_start <= person_start <= person_stop <= lift_stop :
  para = 0
 elif lift_start <= person_start <= lift_stop < person_stop or person_stop < lift_stop <= person_start <= lift_start :
  para = abs(person_stop - lift_stop)
 else :
  para = abs(lift_stop - person_start) + abs(person_start - person_stop)
 return para
def minn(a,b) :
  minn = b[0][a]
  for i in range(1,len(b)) :
    if b[i][a] < minn :
      minn = b[i][a]
  return minn
liftandpara = []
namelift = []
for i in range(0,m) :
  person_start = int(personstart[i])
  person_stop = int(personstop[i])
  for j in range(0,len(liftstart)):
    lift_num = int(liftnum[j])
    lift_start = int(liftstart[j])
    lift_stop = int(liftstart[j])
    liftandpara.append([lift_num,morepara(lift_start,lift_stop,person_start,person_stop)])
  minpara = minn(1,liftandpara)
  for k in range(0,len(liftandpara)) :
    if liftandpara[k][1] == minpara :
      namelift.append(liftandpara[i])
  if len(namelift) == 1 :
    print(">> " + str(namelift[0][0]))
  else :
    print(">> " + str(minn(0,namelift)))
  namelift.clear()
  liftandpara.clear()

6631110221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 12
>> 13
>> 14
[]
test_main_30.0ValueError('min() arg is an empty sequence')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.0ValueError('min() arg is an empty sequence')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.0ValueError('min() arg is an empty sequence')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.41
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 23
>> 1
>> 26
>> 26
>> 26
>> 16
>> 13
>> 14
>> 14
>> 14
>> 34
>> 35
[]
bytecount: {'code': 342, 'const': 147, 'code+const': 489}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = []
lft_str = []
lft_stp = []
score = []
step = []
for i in range(int(input())) :
    lft = input().split()
    lift.append(int(lft[0]))
    lft_str.append(int(lft[1]))
    lft_stp.append(int(lft[2]))
    stp = int(lft[1])-int(lft[2])
    step.append(stp)
for i in range(int(input())) :
    start,stop = map(int,input().split())
    stp = start-stop
    for i in range(len(lift)) :
        if stp < 0 and step[i] < 0 :
            scr = abs(lft_stp[i]-stop)
            score.append(scr)
        elif stp > 0 and step[i] > 0 :
            scr = abs(lft_stp[i]-stop)
            score.append(scr)
    mn = min(score)
    fnl = score.index(mn)
    print(">>", str(lift[fnl]))
    score = []

6630185121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.0
>> 42
>> 24
>> 21
[]
test_main_20.25
>> 1
>> 42
>> 43
>> 14
[]
test_main_30.34
>> 1
>> 21
>> 31
>> 32
>> 42
>> 43
>> 43
>> 4
>> 4
[]
test_main_40.0
>> 14
>> 24
>> 34
>> 43
>> 43
>> 42
>> 42
>> 41
>> 41
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.28
>> 1
>> 1
>> 1
>> 12
>> 12
>> 13
>> 13
>> 14
>> 14
>> 14
>> 14
[]
test_main_70.17
>> 1
>> 21
>> 31
>> 42
>> 2
>> 4
>> 4
>> 43
>> 43
>> 43
>> 43
>> 43
>> 43
[]
test_main_80.28
>> 2
>> 1
>> 1
>> 31
>> 1
>> 1
>> 63
>> 53
>> 53
>> 53
>> 3
>> 1
>> 6
>> 6
>> 6
>> 4
>> 1
>> 16
>> 3
>> 4
>> 4
>> 4
>> 4
>> 4
>> 4
>> 4
>> 45
[]
bytecount: {'code': 332, 'const': 199, 'code+const': 531}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# Input for the number of lifts
num_lifts = int(input())
# Initialize empty lists for lift start and stop positions
lift_start = []
lift_stop = []
# Loop to input lift start and stop positions
for i in range(num_lifts):
    lift_info = input().split()  # Split the input line into a list
    lift_start.append(int(lift_info[0]))  # Append the start position to the lift_start list
    lift_stop.append(int(lift_info[1]))   # Append the stop position to the lift_stop list
# Input for the number of queries
num_queries = int(input())
# Initialize an empty list for the answers
list_ans = []
# Loop to process queries
for i in range(num_queries):
    query_info = input().split()  # Split the input line into a list
    n = int(query_info[0])
    e = int(query_info[1])
    min_dist = float('inf')  # Initialize minimum distance with a large value
    ans = -1  # Initialize the answer with an invalid value
    # Loop through each lift
    for j in range(num_lifts):
        es = lift_start[j]
        ee = lift_stop[j]
        if n >= es and n <= ee and e >= n and e <= ee:
            s = min(ee - e, e - es, n - es, ee - n)
        else:
            s = abs(n - es) + abs(e - es)
        if s < min_dist:
            min_dist = s
            ans = j + 1
    list_ans.append(ans)  # Append the answer to the list_ans
# Output the answers
for i in range(num_queries):
    print( ">>" ,list_ans[i])

6631468021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 12
>> 4
>> 1
[]
test_main_20.0
>> 01
>> 42
>> 43
>> 54
[]
test_main_30.23
>> 31
>> 21
>> 31
>> 2
>> 3
>> 2
>> 3
>> 23
>> 4
>> 34
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.09
>> 173
>> 153
>> 103
>> 94
>> 84
>> 72
>> 62
>> 51
>> 41
>> 31
>> 21
>> 1
[]
test_main_60.37
>> 12
>> 10
>> 10
>> 82
>> 82
>> 63
>> 63
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.09
>> 51
>> 51
>> 51
>> 52
>> 52
>> 54
>> 53
>> 53
>> 43
>> 3
>> 23
>> 53
[]
test_main_80.14
>> 1
>> 02
>> 1
>> 1
>> 01
>> 1
>> 1
>> 0
>> 13
>> 13
>> 03
>> 13
>> 63
>> 51
>> 56
>> 56
>> 56
>> 6
>> 53
>> 4
>> 54
>> 54
>> 54
>> 65
[]
bytecount: {'code': 546, 'const': 215, 'code+const': 761}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def load(item_go, item_list):
    if item_list[1] == item_list[2]:
        x = abs(item_go[0] - item_list[1]) + abs(item_go[1] - item_go[0])
        return x
    elif (item_list[2] > item_go[0] or item_list[1] > item_go[1]) and item_go[1] > item_go[0]:
        x = abs(item_go[1] - item_list[2])
        return x
    elif item_list[1] > item_go[0] and item_list[2] < item_go[0]:
        x = abs(item_go[0] - item_go[1])
        return x
    elif item_list[1] == item_go[0] and item_go[1] > item_list[2]:
        x = abs(item_list[2] - item_go[1])
        return x
    else:
        x = abs(item_go[0] - item_list[2]) + abs(item_go[1] - item_go[0])
        return x
n = int(input())
lift_list = []
for i in range(n):
    lift_info = input().split()
    lift_info = [int(x) for x in lift_info]  # Convert input values to integers
    lift_list.append(lift_info)
m = int(input())
lift_go = []
for j in range(m):
    lift_m = input().split()
    lift_m = [int(x) for x in lift_m]  # Convert input values to integers
    lift_go.append(lift_m)
output = []  # เพิ่มรายการสำหรับเก็บผลลัพธ์
for item_go in lift_go:
    min_result = float('inf')  # ตั้งค่าผลลัพธ์เริ่มต้นเป็นค่ามาก
    for item_list in lift_list:
        result = load(item_go, item_list)  # Calculate the result using the load function
        min_result = min(min_result, result)  # เก็บผลลัพธ์ที่น้อยที่สุด
    output.append(min_result)  # เพิ่มผลลัพธ์ที่น้อยที่สุดลงในรายการผลลัพธ์
# พิมพ์ผลลัพธ์
for result in output:
    print(">>", result)

6631535321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.3
1>> 2
>> 4
4>> 1
[]
test_main_20.23
>> 1
1>> 2
1>> 3
2>> 4
[]
test_main_30.3
>> 1
>> 1
>> 1
1>> 2
1>> 2
1>> 3
1>> 3
1>> 4
1>> 4
[]
test_main_40.2
1>> 4
1>> 4
1>> 4
1>> 3
1>> 3
1>> 2
1>> 2
>> 1
>> 1
[]
test_main_50.38
1>> 3
1>> 3
1>> 3
1>> 4
1>> 4
1>> 2
1>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.25
>> 1
>> 1
>> 1
1>> 2
1>> 2
1>> 3
1>> 3
1>> 4
1>> 4
1>> 4
1>> 4
[]
test_main_70.23
>> 1
>> 1
>> 1
1>> 2
1>> 2
1>> 4
1>> 3
1>> 3
1>> 3
1>> 3
1>> 3
1>> 3
[]
test_main_80.04
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
2>> 1
2>> 3
2>> 3
2>> 3
2>> 3
2>> 3
2>> 1
3>> 6
3>> 6
3>> 6
3>> 6
2>> 3
2>> 4
2>> 4
2>> 4
2>> 4
2>> 5
[]
bytecount: {'code': 318, 'const': 136, 'code+const': 454}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def find_optimal_elevator(n, elevators, m, queries):
    results = []
    for query in queries:
        current_floor, target_floor = query
        min_additional_floors = float('inf')
        optimal_elevator = -1
        for elevator_num, current_elevator_floor, elevator_target_floor in elevators:
            elevator_additional_floors = 0
            if (current_elevator_floor <= target_floor <= elevator_target_floor) or (current_elevator_floor >= target_floor >= elevator_target_floor):
                elevator_additional_floors = abs(current_elevator_floor - current_floor) + abs(target_floor - current_elevator_floor)
            if elevator_additional_floors < min_additional_floors:
                min_additional_floors = elevator_additional_floors
                optimal_elevator = elevator_num
        results.append(optimal_elevator)
    return results
n = int(input())
elevators = [tuple(map(int, input().split())) for _ in range(n)]
m = int(input())
queries = [tuple(map(int, input().split())) for _ in range(m)]
results = find_optimal_elevator(n, elevators, m, queries)
for result in results:
    print(result)

6631128621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
People Number 1>> 42
People Number 2>> 4
People Number 3>> 41
[]
test_main_20.25
People Number 1>> 41
People Number 2>> 42
People Number 3>> 43
People Number 4>> 4
[]
test_main_30.23
People Number 1>> 41
People Number 2>> 41
People Number 3>> 41
People Number 4>> 42
People Number 5>> 42
People Number 6>> 43
People Number 7>> 43
People Number 8>> 4
People Number 9>> 4
[]
test_main_40.34
People Number 1>> 4
People Number 2>> 4
People Number 3>> 4
People Number 4>> 43
People Number 5>> 43
People Number 6>> 42
People Number 7>> 42
People Number 8>> 41
People Number 9>> 41
[]
test_main_50.17
People Number 1>> 43
People Number 2>> 43
People Number 3>> 43
People Number 4>> 4
People Number 5>> 4
People Number 6>> 42
People Number 7>> 42
People Number 8>> 41
People Number 9>> 41
People Number 10>> 4
People Number 11
>> 41
People Number 12>> 41
[]
test_main_60.37
People Number 1>> 41
People Number 2>> 41
People Number 3>> 41
People Number 4>> 42
People Number 5>> 42
People Number 6>> 43
People Number 7>> 43
People Number 8>> 4
People Number 9>> 4
People Number 10>> 4
People Number 11>> 4
[]
test_main_70.09
People Number 1>> 41
People Number 2>> 41
People Number 3>> 41
People Number 4>> 42
People Number 5>> 42
People Number 6>> 4
People Number 7>> 43
People Number 8>> 43
People Number 9>> 43
People Number 10>> 43
People Number 11>> 43
People Number 12>> 43
[]
test_main_80.19
People Number 1>> 6
People Number 2
>> 61
People Number 3>> 61
People Number 4>> 61
People Number 5>> 61
People Number 6>> 61
People Number 7>> 63
People Number 8>> 63
People Number 9>> 63
People Number 10>> 63
People Number 11>> 63
People Number 12>> 6
People Number 13
>> 6
People Number 14>> 6
People Number 15>> 6
People Number 16>> 6
People Number 17>> 63
People Number 18>> 64
People Number 19>> 64
People Number 20>> 64
People Number 21>> 64
People Number 22>> 65
[]
bytecount: {'code': 492, 'const': 607, 'code+const': 1099}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
amount = int(input("Enter the number of elavators: "))
lift_info = []
new_lift_info = []
for i in range(amount):
    lift_number = i+1
    lift_info.append(input("Elavator number " + str(lift_number) + " status: ").split( ))
for e in range(len(lift_info)):
    new_lift_info.append([int(lift_info[e][0]), int(lift_info[e][1])])
question = int(input("Enter the number of question: "))
status = []
new_status = []
for i in range(question):
    question_number = i+1
    status.append(input("People number " + str(question_number) + ": ").split( ))
for e in range(len(status)):
    new_status.append([int(status[e][0]), int(status[e][1])])
for i in range(question):
    for e in range(len(new_lift_info)):
        route = []
        lift_number = e+1
        a = abs(new_lift_info[e][1] - new_status[i][0]) + abs(new_status[i][0] - new_status[i][0])
        route.append([a, lift_number])
    shortest_route = route[0][0]
    shortest_lift = route[0][1]
    for u in range(0, len(route), 2):
        if (route[u][0] < shortest_route):
            shortest_route = route[u][0]
            shortest_lift = route[u][1]
    print("People Number " + str(i+1) + ">> " + str(shortest_lift))

6531502521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 24
>> 1
[]
test_main_20.5
>> 31
>> 2
>> 3
>> 14
[]
test_main_30.12
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 1
>> 1
[]
test_main_40.12
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 21
[]
test_main_50.25IndexError('list index out of range')
>> 23
>> 3
>> 3
>> 2
>> 34
>> 24
>> 2
>> 2
>> 21
>> 21
>> 21
>> 1
>> 1
[]
test_main_60.28
>> 1
>> 1
>> 1
>> 1
>> 12
>> 2
>> 23
>> 3
>> 14
>> 14
>> 14
>> 14
[]
test_main_70.0IndexError('list index out of range')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 13
>> 3
>> 3
>> 3
[]
test_main_80.05
>> 2
>> 31
>> 21
>> 21
>> 21
>> 21
>> 23
>> 23
>> 23
>> 23
>> 23
>> 21
>> 26
>> 26
>> 26
>> 26
>> 23
>> 24
>> 24
>> 24
>> 24
>> 25
[]
bytecount: {'code': 936, 'const': 200, 'code+const': 1136}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
ln = []
ls = []
ld = []
for i in range(n):
    l1,l2,l3 = input().split()
    ln += l1
    ls += l2
    ld += l3
k = int(input())
us = []
ud = []
for j in range(k):
    u1,u2 = input().split()
    us += u1
    ud += u2
for y in range(k):
    s = []
    for m in range(n):
        if ld[m] == us[y] :
            s += str(abs(int(ud[y])-int(ld[m])))
        elif ld[m] <= us[y] <= ls[m] and             ld[m] <= ud[y] <= ls[m]:
            s += '0'
        elif us[y] > ls[m] and us[y] > ld[m] and             ud[y] > ls[m] and ud[y] > ld[m]:
            s += str(abs(int(ud[y])-int(ld[m])))
        elif ls[m] == ld[m]:
            s += str(abs(int(ud[y])-int(ls[m])))
        elif ls[m] <= us[y] <= ld[m] and ld[m] > ls[m] and             ud[y] > ld[m]:
            s += str(abs(int(ud[y])-int(ld[m])))
        elif ls[m]<us[y]<ld[m] and ud[y]>ld[m]>ls[m]:
            s += str(abs(int(ud[y])-int(ld[m])))
        elif ld[m]<us[y]<ls[m] and us[y]>ld[m]>ud[y]:
            s += str(abs(int(ld[y])-int(ud[m])))
        elif us[y]==ls[m] and ld[m]<ud[y]<ls[m] and ls[m]>ld[m]:
            s += "0"
        else:
            s += "100000"
    print('>>', s.index(min(s))+1)

6631524421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
[0, 1, 1, 0]
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 12
>> 1
>> 1
>> 14
>> 1
[]
test_main_20.5
[0, 1, 1, 0]
>> 1
>> 2
>> 2
>> 23
>> 1
>> 2
>> 2
>> 2
>> 1
>> 2
>> 2
>> 2
>> 1
>> 2
>> 2
>> 24
[]
test_main_30.34
[1, 1, 1, 1]
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
>> 1
>> 2
>> 3
>> 4
[]
test_main_40.23
[1, 1, 1, 1]
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 12
>> 1
>> 1
[]
test_main_50.42
[0, 0, 0, 0]
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.28
[1, 1, 1, 1]
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 12
>> 12
>> 13
>> 13
>> 14
>> 14
>> 14
>> 1
>> 1
>> 1
>> 14
[]
test_main_70.25
[0, 0, 0, 0]
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 13
>> 13
>> 13
>> 13
>> 13
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 13
[]
test_main_80.23
[0, 1, 1, 0, 1, 0]
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 31
>> 21
>> 21
>> 31
>> 31
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 21
>> 6
>> 26
>> 36
>> 3
>> 36
>> 3
>> 24
>> 4
>> 24
>> 34
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 3
>> 2
>> 2
>> 3
>> 3
>> 3
>> 35
[]
bytecount: {'code': 378, 'const': 485, 'code+const': 863}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
a = int(input("How many lifts"))
happened = []
for i in range(a):
  lift, now, fin = map(int, input("Floor").split())
  if fin < now:
    happened.append((int(lift), 0, now, fin))
  else:
    happened.append((int(lift), 1, now, fin))
print([(t[1]) for t in happened[:a]])
b = int(input("Try"))
cal = 0
for i in range(b):
  start, des = map(int, input("Destination ").split())
  clear = float('inf')
  for item in happened:
    tare = item[1]
    start = item[2]
    des = item[3]
    if tare == 1:
      if tare <= start <= now:
        cal = abs(fin-des)
    else:
      if start <= des <= fin:
        cal = abs(fin-des)
      else:
        cal = abs(fin - start)
    if cal < clear:
      clear = cal
      selectedlift = item[0]
    print(">>",selectedlift )

6631216121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 34
>> 1
[]
test_main_20.25
>> 41
>> 2
>> 3
>> 3
>> 14
[]
test_main_30.34
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.37
>> 41
>> 41
>> 41
>> 42
>> 42
>> 43
>> 43
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.5
>> 31
>> 31
>> 31
>> 32
>> 32
>> 34
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0
>> 12
>> 61
>> 61
>> 31
>> 31
>> 31
>> 43
>> 43
>> 53
>> 53
>> 53
>> 21
>> 26
>> 26
>> 16
>> 16
>> 13
>> 64
>> 64
>> 34
>> 34
>> 35
[]
bytecount: {'code': 378, 'const': 238, 'code+const': 616}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def find_total_movement(init_lift,person):
    ln,lc,lt = init_lift
    pc,pt = person
    if pc >= lc and (pt <= lt and pt >= pc):
        return 0
    elif pc <= lc and (pt >= lt and pt <= pc):
        return 0
    else:
        return abs(pt-lt)
n_lift = int(input())
lfd = []
for i in range(n_lift):
    li = input().split(" ")
    lem = []
    for j in range(len(li)):
        lem.append(int(li[j]))
    lfd.append(lem)
pfd = []
n_p = int(input())
for i in range(n_p):
    li = input().split(" ")
    lem = []
    for j in range(len(li)):
        lem.append(int(li[j]))
    pfd.append(lem)
for pi in range(len(pfd)):
    min_d = 999
    num = -1
    for li in range(len(lfd)):
        d = find_total_movement(lfd[li],pfd[pi])
        if d < min_d:
            min_d = d
            num = lfd[li][0]
    print(f'>> {num}')

6632015521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 42
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 42
>> 43
>> 24
[]
test_main_30.45
>> 1
>> 1
>> 41
>> 42
>> 42
>> 43
>> 43
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.34
>> 43
>> 3
>> 3
>> 34
>> 4
>> 32
>> 32
>> 1
>> 1
>> 1
>> 81
>> 8
>> 21
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 62
>> 62
>> 63
>> 6
>> 63
>> 4
>> 4
>> 114
>> 4
[]
test_main_70.34
>> 1
>> 1
>> 1
>> 42
>> 42
>> 4
>> 43
>> 43
>> 43
>> 43
>> 43
>> 43
[]
test_main_80.5
>> 2
>> 1
>> 1
>> 1
>> 1
>> 41
>> 3
>> 3
>> 3
>> 3
>> 3
>> 12
>> 126
>> 126
>> 126
>> 126
>> 123
>> 124
>> 12
>> 124
>> 4
>> 4
>> 5
[]
bytecount: {'code': 448, 'const': 253, 'code+const': 701}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
total_floors = int(input()) #รับจำนวนชั้นของลิฟ
device_f = []
device_q = []
Z = []
for i in range(total_floors) : #ลิฟแต่ล่ะชั้นกำลังไปที่ไหน เช่น 1 --> 5
     X = []
     X.append(i+1)
     X += input(f"{i+1} ").split()
     device_f += [int(i) for i in X]
total_questions = int(input()) #จำนวนคำถาม
for i in range(total_questions) : #เก็บคำถามให้เป็นลิสข้อมูล
     X = []
     X += input().split()
     device_q += [int(i) for i in X]
for i in range(1,len(device_q),2) :
      numq1 = device_q[i]
      numq2 = device_q[i-1]
      min_load = float('inf') #ให้ค่าน้อยสุดเป็นอินฟินิตี้ก่อน
      for i in range(2,len(device_f),3) :
          numf1 = device_f[i]
          numf2 = device_f[i-1]
          if ((numf2 > numf1) and (numq2 > numq1)) and (numf2 >= numq2) :
                load = abs(numf1-numq1)
          elif ((numf2 < numf1) and (numq2 < numq1)) and (numf2 <= numq2) :
                load = abs(numf1-numq1)
          else :
                load = abs(numf1-numq2)+abs(numq2-numq1)
          if load < min_load :
                min_load = load
                n = device_f[i-2]
      Z.append(n)
for i in Z :
      print(">>",i)

6631107421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 4
>> 1
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.19
>> 2
>> 21
>> 21
>> 21
>> 21
>> 31
>> 3
>> 6
>> 6
>> 63
>> 5
>> 2
>> 2
>> 2
>> 2
>> 23
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 192, 'const': 119, 'code+const': 311}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
n = int(input())
a = []
for _ in range(n):
    b, c, d = map(int, input().split())
    a.append((b, c, d))
m = int(input())
for _ in range(m):
    c, d = map(int, input().split())
    minElev = None
    minA = float('inf')
    for b, C, target in a:
        Z = abs(C - c) + abs(C - d)
        if Z < minA:
            minA = Z
            minElev = b
    print(">>", minElev)
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631210321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 4
>> 1
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.19
>> 2
>> 21
>> 21
>> 21
>> 21
>> 31
>> 3
>> 6
>> 6
>> 63
>> 5
>> 2
>> 2
>> 2
>> 2
>> 23
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 278, 'const': 135, 'code+const': 413}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def find_optimal_elevator(n, elevators, m, queries):
    result = []
    for query in queries:
        current_floor, target_floor = query
        min_workload = float('inf')
        optimal_elevator = None
        for elevator_num, current, target in elevators:
            workload = abs(current - current_floor) + abs(current - target_floor)
            if workload < min_workload:
                min_workload = workload
                optimal_elevator = elevator_num
        result.append(optimal_elevator)
    return result
n = int(input())
elevators = []
for i in range(n):
    elevator_num, current, target = map(int, input().split())
    elevators.append((elevator_num, current, target))
m = int(input())
queries = []
for i in range(m):
    current_floor, target_floor = map(int, input().split())
    queries.append((current_floor, target_floor))
optimal_elevators = find_optimal_elevator(n, elevators, m, queries)
for elevator_num in optimal_elevators:
    print(">>", elevator_num)

6631470121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 14
>> 1
[]
test_main_20.0
>> 1
>> 2
>> 3
>> 4
>> 1
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.42
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 43
>> 43
>> 3
>> 3
[]
test_main_80.28
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 5
>> 51
>> 56
>> 26
>> 2
>> 2
>> 26
>> 6
>> 63
>> 64
>> 6
>> 64
>> 4
>> 4
>> 5
[]
bytecount: {'code': 330, 'const': 119, 'code+const': 449}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevators = []
for i in range(n):
    elevator_info = list(map(int, input().split()))
    elevators.append(elevator_info)
m = int(input())
for _ in range(m):
    current_floor, destination_floor = map(int, input().split())
    best_elevator = None
    min_additional_floors = float('inf')
    for i, elevator in enumerate(elevators):
        elevator_num, current, destination = elevator
        if current < destination:
            if current <= current_floor <= destination:
                additional_floors = abs(current - current_floor) + abs(destination_floor - current_floor)
            else:
                additional_floors = abs(current - current_floor) + abs(destination - destination_floor)
        else:
            if destination <= current_floor <= current:
                additional_floors = abs(current - current_floor) + abs(current_floor - destination_floor)
            else:
                additional_floors = abs(current - current_floor) + abs(destination - destination_floor)
        if additional_floors < min_additional_floors:
            min_additional_floors = additional_floors
            best_elevator = elevator_num
    print(">>", best_elevator)

6632105321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 24
>> 1
[]
test_main_20.25
>> 1
>> 12
>> 13
>> 14
[]
test_main_30.0UnboundLocalError("local variable 'workload' referenced before assignment")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.75
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.25
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 13
>> 13
>> 13
>> 13
>> 13
>> 13
[]
test_main_80.32
>> 12
>> 1
>> 1
>> 2
>> 3
>> 2
>> 2
>> 2
>> 2
>> 2
>> 21
>> 1
>> 1
>> 3
>> 3
>> 6
>> 3
>> 3
>> 53
>> 1
>> 56
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 576, 'const': 143, 'code+const': 719}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
elevators = []
for _ in range(n):
    elevator_info = list(map(int, input().split()))
    elevators.append(elevator_info)
m = int(input())
for _ in range(m):
    current_floor, target_floor = map(int, input().split())
    min_workload = float('inf')
    chosen_elevator = []
    for elevator_number, current, target in elevators:
        if current > target and current_floor < target_floor :
            if current_floor>target :
                workload = abs(target_floor - target)
            if target==target_floor :
                workload = target-current_floor+target_floor-current_floor
            if current_floor==target :
                workload = target_floor-current_floor
            else:
                workload=target-current_floor+target_floor-current_floor
        if target>current and target_floor>current_floor :
            if target_floor>=target :
                workload=target_floor-target
            elif target>current_floor :
                if target_floor>target :
                    workload=target_floor-target
                else :
                    workload=target_floor-current_floor+target_floor-current_floor
            elif current >= current_floor:
                workload= target-current_floor+target_floor-current_floor
        if current>target and current_floor>target_floor :
            if current_floor>current :
                workload = current_floor-target+current_floor-target_floor
            if current_floor==current :
                if target_floor>=target :
                    workload=0
                else:
                    workload=target-target_floor
            if current==target :
                if target_floor>current_floor :
                    if current_floor>=current:
                        workload = target_floor-current
                    else:
                        workload = current-current_floor+target_floor-current_floor
                if target_floor<current_floor :
                    if current_floor>current:
                        workload= current_floor-current+current_floor-target_floor
                    else:
                        workload=current-target_floor
        if target>current and current_floor>target_floor:
            if target>=current_floor :
                workload= target-target_floor
            else:
                workload=current_floor-target+current_floor-target_floor
        if workload < min_workload:
            min_workload = workload
            chosen_elevator = elevator_number
    print(">>", chosen_elevator)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630046621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34


















>>  42
>>  14
>>  1
[]
test_main_20.25































>>  21
>>  2
>>  23
>>  14
[]
test_main_30.0UnboundLocalError("local variable 'para' referenced before assignment")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0NameError("name 'fl_nex' is not defined")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.59














































































































































































































>>  3
>>  3
>>  43
>>  4
>>  24
>>  2
>>  12
>>  1
>>  21
>>  21
>>  1
>>  1
[]
test_main_61.0





































































































































































































>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
>>  4
>>  4
[]
test_main_71.0















































































































































































































































>>  1
>>  1
>>  1
>>  2
>>  2
>>  4
>>  3
>>  3
>>  3
>>  3
>>  3
>>  3
[]
test_main_80.0NameError("name 'fl_nex' is not defined")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 2498, 'const': 176, 'code+const': 2674}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
now = []
then = []
lift = []
for c in range(n):
    number = input().split()
    lift.append(number[0])
    now.append(number[1])
    then.append(number[2])
m = int(input())
fl_now = []
fl_next = []
for d in range(m):
    nb = input().split()
    fl_now.append(nb[0])
    fl_next.append(nb[1])
men = []
paraja = []
for l in range(m) :
    for g in range(n) :
        fl_now[l]=int(fl_now[l])
        fl_next[l]=int(fl_next[l])
        now[g]=int(now[g])
        then[g]=int(then[g])
        if now[g] - then[g] < 0 and fl_now[l] - fl_next[l] < 0 :
    #คูหนึ่งอยู๋ชั้นเดียวกัน
            if then[g] == fl_next[l] :
                if now[g] > fl_now[l] or now[g] == fl_now[l] :
                    para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                    if para < 0 :
                        para = 0
                elif now[g] < fl_now[l] :
                    para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
                    if para < 0 :
                        para = 0
            if now[g] == fl_now[l] and then[g] != fl_nex[l] :
                if then[g] < fl_next[l] :
                    para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                    if para < 0 :
                        para = 0
                if then[g] > fl_next[l] :
                    para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                    if para < 0 :
                        para = 0
            if now[g] > fl_now[l] and then[g] > fl_next[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
            if now[g] < fl_now[l] and then[g] < fl_next[l] :
                para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
                if para < 0 :
                    para = 0
            if now[g] < fl_now[l] and then[g] > fl_next[l] :
                para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
                if para < 0 :
                    para = 0
            if now[g] > fl_now[l] and then[g] < fl_next[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
        if now[g] - then[g] > 0 and fl_now[l] - fl_next[l] > 0 :
            if now[g] == fl_now[l] and then[g] > fl_next[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
            if now[g] == fl_now[l] and then[g] < fl_next[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
            if then[g] == fl_next[l] and now[g] < fl_now[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
            if then[g] == fl_next[l] and now[g] > fl_now[l] :
                para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
                if para < 0 :
                    para = 0
            if now[g] == fl_now[l] and then[g] == fl_next[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
            if then[g] > fl_next[l] and now[g] > fl_now[l]:
                para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
                if para < 0 :
                    para = 0
            if then[g] < fl_next[l] and now[g] < fl_now[l]:
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
            if then[g] < fl_next[l] and now[g] > fl_now[l] :
                para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
                if para < 0 :
                    para = 0
            if then[g] > fl_next[l] and now[g] < fl_now[l] :
                para = abs(fl_now[l]-now[g])+abs(fl_now[l]-fl_next[l])-abs(then[g]-now[g])
                if para < 0 :
                    para = 0
        if then[g] - now[g] > 0 and fl_next[l] - fl_now[l] < 0 :
            para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
        if then[g] - now[g] < 0 and fl_next[l] - fl_now[l] > 0 :
            para = abs(fl_now[l]-then[g])+abs(fl_now[l]-fl_next[l])
        men.append(para)
    paraja.append(men)
    men  = []
    i = 0
    j = 0
    index = []
    while i < len(paraja):
        min = -1
        min = paraja[i][0]
        j = 0
        while j < len(paraja[i]):
            if(paraja[i][j] < min):
                min = paraja[i][j]
            else :
                print()
            j = j + 1
        #print("min =>>", min)
        index.append(paraja[i].index(min)+1)
        i = i + 1
        min = -1
#print("result ==> ",index)
for mmm in range(len(index)):
    print(">> ",index[mmm])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631131421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.0
>> 31
>> 2
>> 3
>> 1
>> 24
[]
test_main_30.0
>> 41
>> 41
>> 41
>> 42
>> 42
>> 43
>> 43
>> 14
>> 14
[]
test_main_40.45
>> 1
>> 14
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.59
>> 3
>> 4
>> 3
>> 3
>> 34
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.64
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 14
>> 4
[]
test_main_70.09
>> 31
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_80.5
>> 5
>> 52
>> 1
>> 1
>> 51
>> 51
>> 1
>> 53
>> 3
>> 3
>> 3
>> 5
>> 53
>> 1
>> 16
>> 6
>> 6
>> 6
>> 3
>> 3
>> 34
>> 4
>> 4
>> 54
>> 5
[]
bytecount: {'code': 366, 'const': 175, 'code+const': 541}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def calculate_distance(floor1, floor2):
    return (floor1 - floor2)
def find_nearest_elevator(elevators, user_floor, user_distance):
        min_distance = float('inf')
        nearest_elevator = None
        total_distance = 0
        for elevator_number, ele_current_floor, ele_distance_floor in elevators:
                if (user_floor < user_distance):
                        if (ele_current_floor <= user_floor and ele_distance_floor >= user_distance):
                                return elevator_number
                        elif (ele_current_floor < user_floor and ele_distance_floor > user_floor):
                                return elevator_number
                        elif (ele_current_floor > user_floor):
                                total_distance = calculate_distance(user_current_floor, ele_distance_floor)
                if (user_floor > user_distance):
                        if (ele_current_floor >= user_floor and ele_distance_floor <= user_distance):
                                return elevator_number
                        elif (ele_current_floor > user_floor and ele_distance_floor < user_floor):
                                return elevator_number
                        elif (ele_current_floor < user_floor):
                                total_distance = calculate_distance(user_current_floor, ele_distance_floor)
                if total_distance < min_distance:
                        min_distance = total_distance
                        nearest_elevator = elevator_number
        return nearest_elevator
num_elevators = int(input())
elevators = []
for _ in range(num_elevators):
    elevator_number, current_floor, distance = map(int, input().split())
    elevators.append((elevator_number, current_floor, distance))
num_users = int(input())
for _ in range(num_users):
    user_current_floor, user_distance = map(int, input().split())
    nearest_elevator = find_nearest_elevator(elevators, user_current_floor, user_distance)
    print(">>", nearest_elevator)

6632220821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 4
>> 1
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.5
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 43
>> 43
>> 4
>> 53
>> 1
>> 16
>> 16
>> 16
>> 16
>> 3
>> 34
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 198, 'const': 147, 'code+const': 345}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = {}
for i in range(n):
    lift_num, C_floor, Tg_floor = map(int, input().split())
    lifts[i + 1] = (C_floor, Tg_floor)
m = int(input())
for _ in range(m):
    C_floor, Tg_floor = map(int, input().split())
    min_lift = None
    min_increase = float('inf')
    for lift_num, (C, Tg) in lifts.items():
        increase = abs(C - C_floor) + abs(Tg_floor - C)
        if increase < min_increase:
            min_increase = increase
            min_lift = lift_num
    print(">>", min_lift)

6630092421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0UnboundLocalError("local variable 'calculation' referenced before assignment")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0UnboundLocalError("local variable 'calculation' referenced before assignment")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.75
>> 3
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>> 12
>> 3
>> 23
>> 4
>> 34
>> 4
>> 4
[]
test_main_70.0UnboundLocalError("local variable 'calculation' referenced before assignment")
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0UnboundLocalError("local variable 'calculation' referenced before assignment")
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 724, 'const': 175, 'code+const': 899}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
liftsData = []
for i in range (n):
    inputinfo = input()
    splitdata = inputinfo.split()
    liftsData.append((int(splitdata[0]), int(splitdata[1]), int(splitdata[2])))
m = int(input())
questionData = []
for i in range (m):
    inputinfo = input()
    splitdata = inputinfo.split()
    questionData.append((int(splitdata[0]), int(splitdata[1])))
for i in range (len(questionData)):
  bestfloor = 0
  minmove = 100
  for y in range (len(liftsData)):
    if questionData[i][0] < questionData[i][1]:
      if questionData[i][0] == liftsData[y][2]:
        calculation = abs(questionData[i][1] - liftsData[y][2])
      elif questionData[i][0] > liftsData[y][2]:
        calculation = abs(questionData[i][0] - liftsData[y][2]) + abs(questionData[i][1] - questionData[i][0])
      elif questionData[i][0] < liftsData[y][2] and liftsData[y][1] < questionData[i][0] < liftsData[y][2]:
        calculation = abs(questionData[i][1] - liftsData[y][2])
    elif questionData[i][0] > questionData[i][1]:
      if questionData[i][0] == liftsData[y][1]:
        calculation = abs(questionData[i][1] - liftsData[y][1])
      elif questionData[i][0] > liftsData[y][1]:
        calculation = abs((questionData[i][0] - liftsData[y][2])) + abs((questionData[i][1] - questionData[i][0]))
      elif questionData[i][0] < liftsData[y][1]:
        calculation = abs(questionData[i][1] - liftsData[y][2])
    if calculation < minmove:
      minmove = calculation
      bestfloor = liftsData[y][0]
  print(">>",bestfloor)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631703421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 4
>> 1
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.56
>> 14
>> 4
>> 14
>> 3
>> 13
>> 2
>> 12
>> 1
>> 1
[]
test_main_50.67
>> 13
>> 3
>> 13
>> 4
>> 14
>> 2
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.5
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 43
>> 3
>> 3
[]
test_main_80.32
>> 2
>> 1
>> 21
>> 1
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 5
>> 2
>> 3
>> 2
>> 2
>> 6
>> 3
>> 54
>> 64
>> 64
>> 4
>> 5
[]
bytecount: {'code': 296, 'const': 152, 'code+const': 448}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def calculate_workload(current_floor, target_floor):
    return abs(current_floor - target_floor)
def find_optimal_lift(lifts, current_floor, target_floor):
    optimal_lift = None
    min_workload = float('inf')
    for lift_number, current, target in lifts:
        if current == current_floor:
            return lift_number
    for lift_number, current, target in lifts:
        workload = calculate_workload(current, current_floor) + calculate_workload(current, target_floor)
        if workload < min_workload:
            min_workload = workload
            optimal_lift = lift_number
    return optimal_lift
a = int(input())
lifts = []
for i in range(a):
    lift_number, current_floor, target_floor = map(int, input().split())
    lifts.append((lift_number, current_floor, target_floor))
b = int(input())
results = []
for i in range(b):
    current_floor, target_floor = map(int, input().split())
    optimal_lift = find_optimal_lift(lifts, current_floor, target_floor)
    results.append(optimal_lift)
for lift_number in results:
    print(f">> {lift_number}")
#พยายามสุดความสามารถเเล้วครับหาวิธีไม่ออกครับ T-T
#ขอความกรุณาด้วยครับ

6631020421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 3
>> 14
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.19
>> 1
>> 21
>> 21
>> 32
>> 12
>> 43
>> 23
>> 24
>> 34
>> 34
>> 4
[]
test_main_70.34
>> 1
>> 21
>> 1
>> 2
>> 3
>> 32
>> 14
>> 3
>> 23
>> 23
>> 43
>> 3
>> 3
[]
test_main_80.69
>> 2
>> 1
>> 1
>> 1
>> 21
>> 1
>> 3
>> 3
>> 3
>> 3
>> 63
>> 51
>> 2
>> 16
>> 6
>> 6
>> 6
>> 3
>> 34
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 514, 'const': 200, 'code+const': 714}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
n_list = []
for i in range(n):
  nn = [int(i) for i in input().split()]
  n_list.append(nn)
  num = nn[0]
  now = nn[1]
  go = nn[2]
m = int(input())
m_list = []
for x in range(m):
  mm = [int(x) for x in input().split()]
  m_list.append(mm)
  start = mm[0]
  finish = mm[1]
  numlist = 0
  results = float('inf')
  for [num,now,go] in n_list:
    for a in range(n):
      if (now <= start) and (go >= finish) and (start <= finish):
        result = 0
        if result < results:
          results = result
          numlist = str(num)
      elif (now >= start) and (go <= finish) and (start >= finish):
        result = 0
        if result < results:
          results = result
          numlist = str(num)
      elif (now <= finish) and (go < finish) and (start < go):
        result = abs(start-finish)
        if result < results:
          results = result
          numlist = str(num)
      elif (now >= finish) and (go > finish) and (start > go):
        result = abs(start-finish)
        if result < results:
          results = result
          numlist = str(num)
      else:
        result = abs(start-now) + abs(start-finish)
        if result < results:
          results = result
          numlist = str(num)
  print('>> '+ numlist)

6630021921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.5
>> 21
>> 32
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.25IndexError('list index out of range')
>> 3
>> 43
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.19IndexError('list index out of range')
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 51
>> 6
>> 6
>> 6
>> 6
>> 3
>> 54
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 802, 'const': 147, 'code+const': 949}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
#elevator
e = int(input())
n = []
stage = []
going = []
i = 0
j = 0
while i < e:
  i1 = input().split()
  n.append(int(i1[0]))
  stage.append(int(i1[1]))
  going.append(int(i1[2]))
  i += 1
#question
q = int(input())
now = []
stop = []
i = 0
while i < q:
  i2 = input().split()
  now.append(int(i2[0]))
  stop.append(int(i2[1]))
  i += 1
i = 0
while i < q :
  energy = []
  j = 0
  while j < e :
    if ( (going[j] - stage[j]) > 0)  and ( (stop[i]-now[i])> 0) :
      if stage[j] <= now[i] <= stop[i] <= going[j] :
        energy.append(0)
      elif stop[j] <= now[i] <= stage[j] :
        energy.append(abs(stop[i] - going[j]))
      else :
        energy.append(abs(stop[i] - going[j]) + abs(now[i] - stage[j]))
    elif ((going[j] - stage[j]) < 0) and ((stop[i]- now[i]) < 0) :
      if going[j] <= stop[i] <= now[i] <= stage[j] :
        energy.append(0)
      elif stop[i] <= now[i] <= stage[j] :
        energy.append(abs(stop[i] - going[j]))
      else :
        energy.append(abs(stop[i] - going[i]) + abs(now[i] - stage[j]))
    else :
        energy.append(abs(stop[i] - going[j]) + abs(now[i] - stage[j]))
    j += 1
  min_energy = min(energy)
  ans = n[energy.index(min_energy)]
  print(">>",ans)
  i += 1

6631102221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 14
>> 1
[]
test_main_20.5
>> 1
>> 2
>> 13
>> 14
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 12
>> 3
>> 13
>> 4
>> 14
[]
test_main_40.89
>> 14
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.28
>> 1
>> 1
>> 1
>> 12
>> 12
>> 13
>> 13
>> 14
>> 14
>> 14
>> 14
[]
test_main_70.25
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 13
>> 13
>> 13
>> 13
>> 13
>> 13
[]
test_main_80.46
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 13
>> 1
>> 16
>> 16
>> 16
>> 16
>> 13
>> 14
>> 14
>> 14
>> 14
>> 15
[]
bytecount: {'code': 220, 'const': 147, 'code+const': 367}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
elevators = []
for _ in range(n):
    elevator_data = list(map(int, input().split()))
    elevators.append(elevator_data)
m = int(input())
for _ in range(m):
    current_floor, target_floor = map(int, input().split())
    min_workload = float('inf')
    best_elevator = 1
    for i, elevator in enumerate(elevators):
        elevator_num, current, target = elevator
        if current <= target:
            if current <= current_floor and target >= current_floor and target <= target_floor:
                workload = (current_floor - current) + (target_floor - current_floor)
                if workload < min_workload:
                    min_workload = workload
                    best_elevator = elevator_num
    print(">>", best_elevator)

6631214921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 14
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 4
>> 24
>> 2
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.37
>> 1
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.42
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 13
>> 23
>> 23
>> 43
>> 3
>> 3
[]
test_main_80.32
>> 2
>> 21
>> 21
>> 1
>> 1
>> 1
>> 3
>> 3
>> 43
>> 43
>> 43
>> 1
>> 36
>> 36
>> 46
>> 46
>> 3
>> 4
>> 5
>> 54
>> 64
>> 64
>> 65
[]
bytecount: {'code': 244, 'const': 192, 'code+const': 436}
#HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def find_elevator(current_floor, destination_floor, elevator_list, your_floor):
    closest_elevator = None
    min_workload = float('inf')
    for elevator in elevator_list:
        elevator_num, current_pos, dest_pos = elevator
        workload = abs(current_pos - your_floor)
        if workload < min_workload:
            closest_elevator = elevator_num
            min_workload = workload
        elif workload == min_workload:
            closest_elevator = min(closest_elevator, elevator_num)
    return closest_elevator
n = int(input())
elevator_list = []
for i in range(n):
    elevator_data = list(map(int, input().split()))
    elevator_list.append((i + 1, elevator_data[1], elevator_data[2]))
m = int(input())
for _ in range(m):
    your_floor, desired_floor = map(int, input().split())
    elevator_num = find_elevator(your_floor, desired_floor, elevator_list, your_floor)
    print(f">> {elevator_num}")

6631461521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 24
>> 1
[]
test_main_20.25
>> 1
>> 42
>> 43
>> 24
[]
test_main_30.45
>> None1
>> 1
>> None1
>> 2
>> None2
>> 3
>> None3
>> 4
>> None4
[]
test_main_40.89
>> None4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.92
>> None3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.37
>> None
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.34
>> None
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.37
>> None2
>> 1
>> 1
>> 21
>> 21
>> None1
>> 3
>> 3
>> 63
>> 63
>> None3
>> None
>> 3
>> 31
>> 6
>> 6
>> None
>> 5
>> 56
>> 6
>> 3
>> 4
>> 4
>> None4
>> 4
>> 5
[]
bytecount: {'code': 262, 'const': 199, 'code+const': 461}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
elevators = []
for _ in range(n):
    elevator_info = input().split()
    elevator_num = int(elevator_info[0])
    current_floor = int(elevator_info[1])
    destination_floor = int(elevator_info[2])
    elevators.append((elevator_num, current_floor, destination_floor))
m = int(input())
for _ in range(m):
    start_floor, target_floor = map(int, input().split())
    best_elevator = None
    min_additional_floors = float('inf')
    for elevator_num, current_floor, destination_floor in elevators:
        if current_floor <= start_floor <= destination_floor or destination_floor <= start_floor <= current_floor:
            additional_floors = abs(current_floor - start_floor) + abs(start_floor - target_floor)
            if additional_floors < min_additional_floors:
                best_elevator = elevator_num
                min_additional_floors = additional_floors
    print(">>", best_elevator)

6631218421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 42
>> 4
>> 1
[]
test_main_20.25
>> 1
>> 2
>> 3
>> 4
>> 5
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 54
>> 54
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 43
>> 43
>> 43
>> 51
>> 26
>> 46
>> 46
>> 4
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 784, 'const': 197, 'code+const': 981}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
ploy = int(input())
p = []
for i in range(ploy) :
  A = input().split(' ')
  p.append(A)
pee = int(input())
n = []
for i in range(pee) :
  B = input().split(' ')
  n.append(B)
for i in range(0,len(n)) :
  d = n[i]
  w = []
  for t in range(0,len(p)) :
    z = p[t]
    if int( p[t][1] ) >= int( p[t][2] ) and int( n[i][0] ) >= int( n[i][1] ) :
     if int( p[t][1] ) >= int( n[i][0] ) and int( p[t][2] ) >= int( n[i][1] ) :
        k = abs( int( p[t][2] ) - int( n[i][1] ) )
        w.append(k)
    if int( p[t][1] ) >= int( n[i][0] ) and int( p[t][2] ) <= int( n[i][1] ) :
        w.append(0)
    if int( p[t][1] ) <= int( p[t][2] ) and int( n[i][0] ) <= int( n[i][1]) :
     if int( p[t][1] ) <= int( n[i][0] ) and int( p[t][2] ) <= int( n[i][1]) :
      k = abs( int( p[t][2] ) - int( n[i][1] ))
      w.append(k)
     if int( p[t][1]) <= int( n[i][0]) and int( p[t][2] ) >= int( n[i][1] ) :
        w.append(0)
    else :
       k = abs( int( n[i][0] ) - int( p[t][2] ) ) + abs( int( n[i][1] ) - int( n[i][0] ) )
       w.append(k)
  print( '>>' , w.index(min(w)) + 1 )

6331410221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 24
>> 1
[]
test_main_20.75
>> 1
>> 32
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.75
>> None3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 21
>> 21
>> 1
[]
test_main_60.91
>> None1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.5
>> 31
>> 31
>> 31
>> 32
>> 32
>> 34
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.19
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 36
>> 3
>> 4
>> 4
>> 4
>> 5
>> 6
>> 6
>> 3
>> 3
>> 3
>> 4
>> 4
>> 5
>> 5
>> 5
>> None
[]
bytecount: {'code': 450, 'const': 200, 'code+const': 650}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# จำนวนลิฟต์
n = int(input())
elevators = []
# ลิฟต์แต่ละตัว
for i in range(n):
    elevator_info = input().split()
    elevator_number = int(elevator_info[0])
    start = int(elevator_info[1])
    finish = int(elevator_info[2])
    elevators.append((elevator_number, start, finish))
# จำนวนคำถาม
m = int(input())
# ข้อมูลคำถาม
for i in range(m):
    current_floor, target_floor = map(int, input().split())
    best_elevator = None
    min_workload = float('inf')
# คำนวณการทำงานของลิฟต์
    for elevator_number, start, finish in elevators:
        if finish <= current_floor <= target_floor or finish >= current_floor >= target_floor:
            workload = abs(finish - current_floor) + abs(current_floor - target_floor)
            if workload < min_workload:
                min_workload = workload
                best_elevator = elevator_number
        elif target_floor > finish > current_floor:
            workload = abs(finish - target_floor)
            if workload < min_workload:
                min_workload = workload
                best_elevator = elevator_number
        elif start > current_floor > finish > target_floor:
            workload = abs(start - current_floor) + abs(current_floor - target_floor)
            if workload < min_workload:
                min_workload = workload
                best_elevator = elevator_number
        elif start == current_floor >= target_floor:
            workload = abs(start - target_floor)
            if workload < min_workload:
                min_workload = workload
                best_elevator = elevator_number
    print(f">> {best_elevator}")

6330128121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>>2 1
>> 2
>>3 2
>> 3
>>4 3
>> 4
>> 4
[]
test_main_40.23TypeError("'<' not supported between instances of 'int' and 'list'")
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.0TypeError("'<' not supported between instances of 'int' and 'list'")
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>>2 1
>> 2
>>3 2
>> 3
>>4 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.75
>> 1
>> 1
>>2 1
>> 2
>>4 2
>> 4
>>4 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.46
>>3 2
>>3 1
>> 1
>> 1
>>3 1
>>5 1
>>5 3
>> 3
>> 3
>> 3
>>4 3
>>6 1
>>1 6
>> 6
>> 6
>> 6
>>4 3
>>2 4
>> 4
>> 4
>>2 4
>>2 5
[]
bytecount: {'code': 1962, 'const': 147, 'code+const': 2109}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())#ของลิฟ
lift=[0]*n
for i in range(n): #บอกว่าลิฟแต่ละตัวข้อมูลเป็นยังไง
    x=(input()).split()
    lift[i]=x
m=int(input())#ของคำถาม
ME= [0]*m
for i in range(m):
    y=(input()).split()
    ME[i]=y
for i in ME:
    k=[]
    c=[]
    for e in lift:
        if int(e[2])-int(e[1])>0 : #liftup
            if int(i[1])-int(i[0])<0 :#medown
                x=abs(int(i[0])-int(e[2]))+abs(int(i[1])-int(i[0]))
            else:#meup
                if int(e[1])<int(i[0]) and int(e[2])==int(i[0]) and int(i[1])>int(e[2]):
                    x=abs(int(i[1])-int(i[0]))
                else:
                      if int(i[0])>int(e[1]) and int(e[2])>int(i[1]):
                            x=0
                      else:
                            if int(i[0])>int(e[1]) and int(i[0])<int(e[2]) and int(e[2])<int(i[1]):
                                    x=abs(int(i[1])-int(e[2]))
                            else:
                                    if int(e[1])<int(i[0]) and int(e[2])<int(i[0]) and int(i[1])>int(e[2]) and int(i[1])>int(e[1]):
                                         x=abs(int(i[1])-int(e[2]))
                                    else:
                                        if int(i[0])<int(e[1]) and int(i[1])>int(e[1]) and int(i[1])<int(e[2]):
                                            x=abs(int(e[2])-int(i[0]))+abs(int(i[1])-int(i[0]))
        else:
            if int(e[2])-int(e[1])<0 :#liftdown
                if int(i[1])-int(i[0])>0 and int(e[2])!= int(i[0]): #meup
                     x=abs(int(i[0])-int(e[2]))+abs(int(i[1])-int(i[0]))
                else:
                    if int(i[1])-int(i[0])>0 and int(e[2])== int(i[0]):
                        x=abs(int(i[1])-int(i[0]))
                    else: #medown
                        if int(i[0])<int(e[1]) and int(e[2])<int(i[1]):
                                    x=0
                        else:
                            if int(i[0])<int(e[1]) and int(i[0])>int(e[2]) and int(e[2])>int(i[1]):
                                         x=abs(int(i[1])-int(e[2]))
                            else:
                                if int(e[1])>int(i[0]) and int(e[2])>int(i[0]) and int(i[1])<int(e[2]) and int(i[1])<int(e[1]):
                                                 x=abs(int(i[1])-int(e[2]))
            else:
                if int(e[2])-int(e[1])==0: #liftstay
                    if int(i[1])-int(i[0])>0: #meup
                        if int(e[2])>int(i[0]) :
                            x=abs(int(e[2])-int(i[0]))+abs(int(i[1])-int(i[0]))
                        else:
                            if int(e[2])<int(i[0]) and int(e[2])<int(i[1]):
                                 x=abs(int(i[0])-int(e[2]))+abs(int(i[1])-int(i[0]))
                            else:
                                if int(e[2])==int(i[0]):
                                    x=abs(int(i[1])-int(i[0]))
                else:#medown
                    if int(e[2])<int(i[0]):
                        x=abs(int(i[0])-int(e[2]))+abs(int(i[1])-int(i[0]))
                    else:
                        if int(e[2])>int(i[0]) and int(e[2])>int(i[1]):
                            x=abs(int(i[1])-int(e[2]))
                        else:
                            if int(e[2])==int(i[0]):
                                x=abs(int(i[1])-int(i[0]))
        k.append([int(e[0]),x])
        c.append(x)
        minn = min(c)
        for a in k :
            if a[1] == minn :
                ans = a[0]
    print(">>"+str(ans))

6630083821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 2
>> 24
>> 31
[]
test_main_20.75
>> 1
>> 2
>> 3
>> 24
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 2
>> 3
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.25
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 42
>> 1
>> 21
>> 1
>> 21
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 2
>> 4
>> 4
>> 3
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.23
>> 1
>> 2
>> 21
>> 21
>> 21
>> 21
>> 41
>> 3
>> 3
>> 3
>> 3
>> 3
>> 6
>> 2
>> 4
>> 31
>> 46
>> 36
>> 36
>> 36
>> 3
>> 64
>> 54
>> 64
>> 5
>> 5
>> 54
>> 5
[]
bytecount: {'code': 408, 'const': 243, 'code+const': 651}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def solution(a, b, lst):
    sol = 100
    listsol = []
    for i in range(len(lst)):
        now = int(lst[i][1])
        last = int(lst[i][2])
        if now <= a <= last:
            x = abs(last - b)
        else:
            x = abs(now - last) + abs(a - last) + abs(a - b)
        temp = [i + 1, x]
        listsol.append(temp)
        if x < sol:
            sol = x
    for i in range(len(listsol)):
        if sol == listsol[i][1]:
            print(">>", listsol[i][0])
n = int(input())
lst = []
for _ in range(n):
    info = input().strip().split()
    lst.append(list(map(int, info)))
m = int(input())
listQ = []
for _ in range(m):
    q = input().strip().split()
    listQ.append(list(map(int, q)))
for i in range(m):
    a = listQ[i][0]
    b = listQ[i][1]
    solution(a, b, lst)

6631451221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 3
>> 54
[]
test_main_30.0ValueError('min() arg is an empty sequence')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('min() arg is an empty sequence')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 54
>> 54
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 784, 'const': 197, 'code+const': 981}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
x = []
for a in range(n) :
  m = input().split(' ')
  x.append(m)
k = int(input())
y = []
for a in range(k) :
  m = input().split(' ')
  y.append(m)
for i in range(0,len(y)) :
  w = y[i]
  q = []
  for j in range(0,len(x)) :
    r = x[j]
    if int( x[j][1] )>=int( x[j][2] ) and int( y[i][0] )>=int( y[i][1] ):
      if int( x[j][1] )>=int( y[i][0] ) and int( x[j][2] )>=int( y[i][1] ):
        b = abs( int( x[j][2] ) - int( y[i][1] ) )
        q.append(b)
      if int( x[j][1] )>=int( y[i][0] ) and int( x[j][2] )<=int( y[i][1] ):
        q.append(0)
    if int( x[j][1] )<=int( x[j][2] ) and int( y[i][0] )<=int( y[i][1] ):
      if int( x[j][1] )<=int( y[i][0] ) and int( x[j][2] )<=int( y[i][1] ):
        b = abs( int( x[j][2] ) - int( y[i][1] ) )
        q.append(b)
      if int( x[j][1] )<=int( y[i][0] ) and int( x[j][2] )>=int( y[i][1] ):
        q.append(0)
    else :
        b = abs( int( y[i][0] ) - int( x[j][2] ) ) + abs( int( y[i][1])  - int( y[i][0]) )
        q.append(b)
  print( '>>' , q.index(min(q)) + 1 )

6632146021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 4
>> 41
[]
test_main_20.75
>> None1
>> 2
>> 3
>> 4
[]
test_main_30.89
>> None1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.89
>> None4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.92
>> None3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.09
>> None
>> None
>> None
>> None1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.09
>> None
>> None
>> None
>> None
>> None1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.64
>> None2
>> 1
>> 1
>> 1
>> 2
>> 2
>> 31
>> 31
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 53
>> 54
>> 4
>> 4
>> 4
>> None5
[]
bytecount: {'code': 406, 'const': 199, 'code+const': 605}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
lifts = []
for a in range(n):
 lift_data = input().split()
 lift_number = int(lift_data[0])
 current_floor = int(lift_data[1])
 destination_floor = int(lift_data[2])
 lifts_list= lift_number,current_floor,destination_floor
 lifts.append(lifts_list)
m=int(input())
results= []
for b in range(m):
    current_floor, target_floor = map(int, input().split())
    best_lift = None
    min_add_floor = float('inf')
    for lift in lifts:
        lift_number,current,destination = lift
        if int(current_floor)< int(target_floor):
            if int(current_floor) >= int(current) and  int(target_floor)>=int(destination) :
                (add_floor) = (int(current_floor) - int(current))+(int(target_floor) - int(destination))
                if int(add_floor) < (min_add_floor):
                    (min_add_floor) = int(add_floor)
                    (best_lift) = (lift_number)
        else:
            if int(current_floor) <= int(current) and int(target_floor) <= int(destination):
                (add_floor) = (int(current) - int(current_floor)) + (int(destination) - int(target_floor))
                if int(add_floor) < (min_add_floor):
                    (min_add_floor) = int(add_floor)
                    (best_lift) = int(lift_number)
    results.append(best_lift)
for result in results:
    print(">>", result)

6430314621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.45
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 2
>> 3
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 2
>> 3
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.67
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.73
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 5
>> 21
>> 6
>> 6
>> 6
>> 6
>> 63
>> 4
>> 4
>> 4
>> 4
>> 45
[]
bytecount: {'code': 586, 'const': 188, 'code+const': 774}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def check_distance(L1,L2,P1,P2):
    if (L1-L2>0 and P1-P2>0) or (L1-L2<0 and P1-P2<0):#same direction
        if (L1<=P1<=L2 or L2<=P1<=L1) and (L1<=P2<=L2 or L2<=P2<=L1):#check in range for flow
            return 0
        elif P1<L2<P2 or P2<L2<P1:#check case not all
            return abs(P2-L2)
        else:#others
            path1=abs(P1-L2)
            path2=abs(P2-P1)
            return path1+path2
    else:#diff direction
        path1=abs(P1-L2)
        path2=abs(P2-P1)
        return path1+path2
m=int(input()) #nl: number of lift
nl=[] #number of lift
l1=[]
l2=[]
#lock people//check distance each lift//choose real ans
for i in range(m):#collect data
    a=input().split()
    nl.append(int(a[0]))
    l1.append(int(a[1]))
    l2.append(int(a[2]))
n=int(input())#collect data
p1=[] #initial
p2=[] #finish
ans=[]#load value and find min keep in int
for j in range(n):#collect data
    b=input().split()
    p1.append(int(b[0]))
    p2.append(int(b[1]))
for x in range(n):#lock people
    ans=[]
    for y in range(m):#check distance each lift
        z=check_distance(l1[y],l2[y],p1[x],p2[x])
        ans.append(z)
    for k in ans:
        if k==min(ans):
            locate=ans.index(k)
            print('>> '+str(nl[locate]))

6632084821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 4
>> 41
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.75
>> 3
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.28
>> 1
>> 1
>> 21
>> 2
>> 12
>> 13
>> 13
>> 14
>> 14
>> 14
>> 14
[]
test_main_70.84
>> 1
>> 1
>> 21
>> 2
>> 42
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.64
>> 2
>> 21
>> 1
>> 1
>> 1
>> 6
>> 61
>> 3
>> 3
>> 3
>> 43
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
>> 5
[]
bytecount: {'code': 1148, 'const': 175, 'code+const': 1323}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
a=[]
for i in range(0,n):
  a.append([int(j)
    for j in input().split()])
m=int(input())
b=[]
for i in range(0,m):
  b.append([int(j)
    for j in input().split()])
num=999
mi=999
i=0
k=0
while k < m:
    while i < n:
        if (b[k][0] <= a[i][1] and b[k][0] <= a[i][2]) or (b[k][0] >= a[i][1] and b[k][0] >= a[i][2]):
            if (abs(b[k][0]-a[i][2])+abs(b[k][0]-b[k][1])) == mi and num > a[i][0]:
                break
            elif (abs(b[k][0]-a[i][2])+abs(b[k][0]-b[k][1])) == mi and num < a[i][0]:
                num = a[i][0]
            elif (abs(b[k][0]-a[i][2])+abs(b[k][0]-b[k][1])) < mi:
                num = a[i][0]
                mi = (b[k][0]-a[i][2])+abs(b[k][0]-b[k][1])
        elif (b[k][0]<=a[i][1] and b[k][0]>=a[i][2] and b[k][1]>=a[i][2] and b[k][1]<=b[k][0]):
            if (mi==0 and num > a[i][0]):
                break
            num = a[i][0]
            mi = 0
        elif (b[k][0] >= a[i][1] and b[k][0] <= a[i][2] and b[k][1] <= a[i][2] and b[k][1] >= b[k][0]):
            if (mi==0 and num > a[i][0]):
                break
            num = a[i][0]
            mi = 0
        else:
            if (abs(a[i][2]-b[k][1])) == mi and num > a[i][0]:
                break
            elif (abs(a[i][2]-b[k][1])) == mi and num > a[i][0]:
                num = a[i][0]
            elif (abs(a[i][2]-b[k][1])) < mi:
                num = a[i][0]
                mi = abs(a[i][2]-b[k][1])
        i+=1
    i=0
    print('>>',num)
    num=999
    mi=999
    k+=1

6631463821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 12
>> 24
>> 1
[]
test_main_20.5
>> 1
>> 32
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.37
>> 2
>> 2
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 31
>> 3
>> 3
>> 2
>> 3
>> 3
>> 3
>> 31
>> 6
>> 6
>> 6
>> 6
>> 3
>> 54
>> 54
>> 54
>> 54
>> 5
[]
bytecount: {'code': 270, 'const': 135, 'code+const': 405}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def min_task(n, elevators, m, queries):
    result = []
    for query in queries:
        now_floor, last_floor = query
        min_load_elevator = None
        min_load = float('inf')
        for elevator_num, current_floor, last_floor in elevators:
            elevator_distance = abs(current_floor - now_floor) + abs(now_floor - last_floor)
            if elevator_distance < min_load:
                min_load = elevator_distance
                min_load_elevator = elevator_num
        result.append(min_load_elevator)
    return result
n = int(input())
elevators = [list(map(int, input().split())) for _ in range(n)]
m = int(input())
queries = [list(map(int, input().split())) for _ in range(m)]
results = min_task(n, elevators, m, queries)
for result in results:
    print(">>", result)

6631221221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.0ValueError('min() arg is an empty sequence')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('min() arg is an empty sequence')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 54
>> 54
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 784, 'const': 197, 'code+const': 981}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
L = int(input())
M=[]
for K in range(L):
  A = input().split(' ')
  M.append(A)
D = int(input())
S=[]
for T in range(D):
  U =input().split(' ')
  S.append(U)
for j in range(0,len(S)):
  q = S[j]
  D = []
  for i in range(0,len(M)):
    l = M[i]
    if int(M[i][1]) > int(M[i][2]) and int(S[j][0]) > int(S[j][1]):
       if int(M[i][1])>=int(S[j][0]) and int(M[i][2])>=int(S[j][1]):
           C=abs(int(M[i][2])-int(S[j][1]))
           D.append(C)
       if int(M[i][1])>=int(S[j][0])  and int(M[i][2])<=int(S[j][1]):
           D.append(0)
    if int(M[i][1])<=int(M[i][2])    and int(S[j][0])<=int(S[j][1]):
       if int(M[i][1])<=int(S[j][0]) and int(M[i][2])<=int(S[j][1]):
           C=abs(int(M[i][2])-int(S[j][1]))
           D.append(C)
       if int(M[i][1])<=int(S[j][0]) and int(M[i][2])>=int(S[j][1]):
           D.append(0)
    else:
      C=abs(int(S[j][0])-int(M[i][2])) + abs(int(S[j][1])-int(S[j][0]))
      D.append(C)
  print('>>',D.index(min(D))+1)

6631552021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.5
>> 1
>> 32
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 34
>> 4
>> 3
>> 3
>> 2
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 43
>> 4
>> 24
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.19
>> 1
>> 21
>> 21
>> 32
>> 32
>> 13
>> 43
>> 24
>> 34
>> 34
>> 4
[]
test_main_70.34
>> 1
>> 21
>> 1
>> 2
>> 4
>> 42
>> 34
>> 13
>> 13
>> 23
>> 3
>> 3
>> 3
[]
test_main_80.73
>> 2
>> 1
>> 1
>> 1
>> 31
>> 21
>> 3
>> 3
>> 3
>> 53
>> 3
>> 21
>> 26
>> 6
>> 6
>> 6
>> 3
>> 34
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 364, 'const': 223, 'code+const': 587}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevator = [0.0] * n
for i in range(n):
    elevator_info = input().split()
    elevator[i] = [int(elevator_info[0]), int(elevator_info[1]), int(elevator_info[2])]
q = int(input())
question = [0.0] * q
for j in range(q):
    question_info = input().split()
    question[j] = [int(question_info[0]), int(question_info[1])]
for k in range(q):
    current_floor = question[k][0]
    destination_floor = question[k][1]
    min_work = float('inf')
    selected_elevator = None
    for elev in elevator:
        elevator_num = elev[0]
        current = elev[1]
        destination = elev[2]
        if current <= current_floor <= destination or destination <= current_floor <= current:
            work = abs(current - current_floor) + abs(destination - destination_floor)
        else:
            work = abs(current - current_floor) + abs(destination - current_floor)
        if work < min_work:
            min_work = work
            selected_elevator = elevator_num
    print(">>", selected_elevator)

6631452921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.28
>> 1
>> 1
>> 1
>> 12
>> 12
>> 43
>> 43
>> 24
>> 24
>> 34
>> 34
[]
test_main_70.25
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 13
>> 13
>> 23
>> 23
>> 43
>> 43
[]
test_main_80.5
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 616, 'const': 226, 'code+const': 842}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator = int(input())
number1 = []
number2 = []
answer = []
for i in range(elevator):
    flr = input()
    lastflr = flr.split(" ")
    number1.append(int(lastflr[1]))
    number2.append(int(lastflr[2]))
#print(liststart[3])
lift = input()
for i in range(int(lift)) :
    min = 0
    max = 1000
    flr = input()
    lastflr = flr.split(" ")
    start = int(lastflr[0])
    next = int(lastflr[1])
    for e in range(int(elevator)) :
        e_start = number1[e]
        e_next = number2[e]
        if e_start <= start <=  e_next :
            if next >= start :
                if next >= e_next :
                    min = next - e_next
        elif e_next <= start <= e_start :
            if next <= start :
                if next <= e_next :
                    min = e_next - next
        elif (start >= e_start and start <= e_next and next >= start and e_next >= e_start) or (start <= e_start and start >= e_next and next <= start and e_next <= e_start):
            min = 0
        elif start <= e_next :
            if next <= start :
                min = (e_next - start) + (start - next)
        elif next >= start >= e_next :
            min = (start - e_next) + (next - start)
        elif e_start <= start >= next :
            min = abs(start - e_next) + abs(start - next)
        elif start <= next >= e_next :
            min = abs(e_next - start) + abs(next - start)
        if max > min :
            max = min
            ans = e+1
    answer.append(ans)
for i in range(int(lift)) :
    print(">> " + str(answer[i]))

6631549121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 32
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 14
>> 14
>> 14
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.67
>> 3
>> 43
>> 3
>> 4
>> 4
>> 2
>> 2
>> 3
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.64
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 13
>> 4
>> 14
>> 14
>> 14
[]
test_main_70.5
>> 1
>> 21
>> 1
>> 2
>> 42
>> 4
>> 3
>> 3
>> 3
>> 2
>> 3
>> 3
>> 3
[]
test_main_80.5
>> 2
>> 1
>> 1
>> 61
>> 61
>> 61
>> 3
>> 3
>> 43
>> 43
>> 43
>> 61
>> 26
>> 6
>> 6
>> 6
>> 43
>> 64
>> 4
>> 4
>> 4
>> 45
[]
bytecount: {'code': 324, 'const': 227, 'code+const': 551}
# @title ข้อความอธิบายภาพเริ่มต้น
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
la = 0
n = int(input())
happened = []
for i in range(n):
    lift, liftu, paomai = map(int, input().split())
    if liftu < paomai:
        happened.append((int(lift), 1, liftu, paomai))
    else:
        happened.append((int(lift), 0, liftu, paomai))
m = int(input())
for i in range(m):
    yu, want = map(int, input().split())
    min_point = float('inf')
    for item in happened:
        kin = item[1]
        liftu = item[2]
        paomai = item[3]
        if kin == 1:
            if liftu <= yu <= paomai:
                la = abs(paomai-want)
        else:
            if paomai <= yu <= liftu:
                la = abs(paomai-want)
            else:
                la = abs(paomai - yu)
        if la < min_point:
            min_point = la
            selected_lift = item[0]
    print(">>",selected_lift )

6631009621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.5
>> 21
>> 2
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.28
>> 2
>> 21
>> 1
>> 1
>> 21
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 51
>> 56
>> 56
>> 16
>> 16
>> 13
>> 4
>> 4
>> 4
>> 4
>> 4
>> 6
>> 6
>> 65
[]
bytecount: {'code': 850, 'const': 363, 'code+const': 1213}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
start = []
stop = []
direction = []
for x in range(n):
    info1 = input()
    info2 = info1.split(" ")
    info2 = [int(x) for x in info2]
    start += [info2[1]]
    stop += [info2[2]]
    if info2[1] > info2[2]:
        direction += ['down']
    elif info2[1] < info2[2]:
        direction += ['up']
    else:
        direction += ['stationary']
m = int(input())
problem = []
for x in range(m):
    info3 = input()
    info4 = info3.split(" ")
    info4 = [int(x) for x in info4]
    problem += [info4]
total_work = []
for x in range(m):
    if problem[x][0] > problem[x][1]:
        direction_check = 'down'
    elif problem[x][0] < problem[x][1]:
        direction_check = 'up'
    work = []
    for y in range(n):
        if direction[y] != direction_check and direction[y]!='stationary':
            work += [(abs(problem[x][0]-stop[y]) + abs(problem[x][0]-problem[x][1]))]
        elif direction[y] == direction_check and direction_check == 'up':
            total = 0
            if start[y]-problem[x][0] > 0:
                total += start[y]-problem[x][0]
            if problem[x][1]-stop[y] > 0:
                total += problem[x][1]-stop[y]
            work += [total]
        elif direction[y] == direction_check and direction_check == 'down':
            total = 0
            if problem[x][0]-start[y] > 0:
                total += problem[x][0]-start[y]
            if stop[y]-problem[x][1] > 0:
                total += stop[y]-problem[x][1]
            work += [total]
        else:
            total = abs(problem[x][0]-start[y]) + abs(problem[x][0]-problem[x][1])
            work += [total]
    total_work += [work]
for x in total_work:
    minimum = min(x)
    no = x.index(minimum)+1
    print(">> {}".format(no))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631013021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.37
>> 41
>> 41
>> 41
>> 42
>> 42
>> 43
>> 43
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.5
>> 31
>> 31
>> 31
>> 32
>> 32
>> 34
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.05
>> 42
>> 1
>> 41
>> 41
>> 61
>> 61
>> 43
>> 63
>> 63
>> 63
>> 63
>> 21
>> 26
>> 26
>> 26
>> 26
>> 23
>> 24
>> 34
>> 34
>> 34
>> 35
[]
bytecount: {'code': 404, 'const': 147, 'code+const': 551}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) # จำนวนลิฟท์
e_list = []
for i in range(n):
  lift = [int(e) for e in input().split()]
  e_list.append(lift)
m = int(input()) # จำนวนคน
q_list = []
for i in range(m):
  man = [int(e) for e in input().split()]
  q_list.append(man)
for begq,endq in q_list:
  result = []
  for idxe,bege,ende in e_list:
    tq = endq - begq # ผลต่างชั้นของแต่ละคน
    te = ende - bege # ผลต่างชั้นของแต่ละลิฟท์
    if(tq*te>=0): # ลิฟท์กับคนไปทิศเดียวกัน
      if(tq>0): # ทิศขึ้น
        if(bege<begq): # จุดเริ่มลิฟท์ก่อนจุดเริ่มคน
          result.append(max(endq-ende,0))
        else:
          result.append(ende - begq + abs(tq))
      else:
        if(bege>=begq): # จุดเริ่มลิฟท์ก่อนจุดเริ่มคน แต่ทิศลง
          result.append(max(ende-endq,0))
        else:
          result.append(begq - ende + abs(tq))
    else: # ลิฟท์ไปคนละทางกับคน
      if(endq==ende): result.append(2*tq) # จุดเริ่มคนและจุดจบลิฟท์จุดเดียวกัน
      else: result.append(abs(endq-ende))
  print(">>",result.index(min(result))+1)

6631209821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.5
>> 21
>> 2
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.45
>> 1
>> 14
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.5
>> 1
>> 1
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.28
>> 2
>> 21
>> 21
>> 21
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 51
>> 56
>> 16
>> 16
>> 46
>> 43
>> 4
>> 4
>> 4
>> 6
>> 64
>> 6
>> 65
[]
bytecount: {'code': 534, 'const': 227, 'code+const': 761}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
number = [0] * n
start = [0] * n
end = [0] * n
for i in range (0, n):
    x1 = input()
    y1 = x1.split()
    number[i] = int(y1[0])
    start[i] = int(y1[1])
    end[i] = int(y1[2])
m = int(input())
mystart = [0] * m
myend = [0] * m
for i in range (0, m):
    x1 = input()
    y1 = x1.split()
    mystart[i] = int(y1[0])
    myend[i] = int(y1[1])
result = [0] * m
for i in range (0, m):
    each_result = [0] * n
    for j in range (n):
        isUp = 0
        im_up = 0
        is_pass = False
        if (myend[i] > mystart[i]):
            im_up = 1
        elif(myend[i] < mystart[i]):
            im_up = -1
        if(end[j] > start[j]):
            isUp = 1
        elif(end[j] < start[j]):
            isUp = -1
        if(isUp == im_up):
            is_pass = True
        if(is_pass == True):
            if(((mystart[i] - end[j])*isUp) < 0) ^ (((mystart[i] - start[j])*isUp) > 0):
                    each_result[j] = abs(myend[i] - end[j])
        else:
            each_result[j] = abs(end[j] - mystart[i]) + abs(myend[i] - mystart[i])
        result[i] = each_result.index(min(each_result))+1
    print(">>", result[i])

6532069321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>>4 3
>> 3
>>3 2
>> 2
>>2 1
>> 1
[]
test_main_50.42
>>1 3
>>1 3
>>1 3
>>1 4
>>1 4
>>1 2
>>1 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.37
>>4 1
>>4 1
>>4 1
>>4 2
>>4 2
>>4 3
>>4 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.28
>>1 2
>> 1
>>2 1
>>2 1
>>2 1
>>2 1
>>4 3
>> 3
>> 3
>> 3
>> 3
>> 1
>>2 6
>>2 6
>>2 6
>>4 6
>>4 3
>>3 4
>>3 4
>>3 4
>>6 4
>>6 5
[]
bytecount: {'code': 658, 'const': 219, 'code+const': 877}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def data_collect() :
    data=list()
    for i in range(int(input())) :
        a=[int(e) for e in input().split()]
        data.append(a)
    return data
normal=data_collect()
persona=data_collect()
for user in persona :
    show=[]
    for a in normal :
        if user[0]<user[1] :
            if user[0]==a[2] and user[1]>a[2] :
                load=user[1]-a[2]
            elif user[0]>a[1] and user[0]<a[2] :
                load=user[1]-a[2]
            elif a[2]>user[0] :
                load=a[2]-user[0]+user[1]-user[0]
            elif a[2]<user[0] :
                load=user[0]-a[2]+user[1]-user[0]
            else :
                load =50000000
            show.append(load)
        else :
            if user[0]==a[1] and user[1]>a[2] :
                load=0
            elif user[0]<a[1] and user[1]<a[2] :
                load=a[2]-user[1]
            elif a[2]>user[1] :
                load=a[2]-user[0]+user[0]-user[1]
            elif a[2]<user[0] :
                load=user[0]-a[2]+user[0]-user[1]
            else :
                load =500000000
            show.append(load)
    pri=[]
    for i in range(len(show)) :
        pri.append([show[i],i+1])
    pri.sort()
    if len(pri)>1 :
        a=str(pri[0][1])
        print('>>'+a)

6532073821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>>4 3
>> 3
>>3 2
>> 2
>>2 1
>> 1
[]
test_main_50.42
>>1 3
>>1 3
>>1 3
>>1 4
>>1 4
>>1 2
>>1 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.37
>>4 1
>>4 1
>>4 1
>>4 2
>>4 2
>>4 3
>>4 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.28
>>1 2
>> 1
>>2 1
>>2 1
>>2 1
>>2 1
>>4 3
>> 3
>> 3
>> 3
>> 3
>> 1
>>2 6
>>2 6
>>2 6
>>4 6
>>4 3
>>3 4
>>3 4
>>3 4
>>6 4
>>6 5
[]
bytecount: {'code': 716, 'const': 175, 'code+const': 891}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
data=[]
for i in range(int(input())) :
    a=input().split()
    f=[]
    for e in a :
        e=int(e)
        f.append(e)
    data.append(f)
call=[]
for i in range(int(input())) :
    a=input().split()
    f=[]
    for e in a :
        e=int(e)
        f.append(e)
    call.append(f)
for user in call :
    mem=[]
    for d in data :
        if user[0]<user[1] :
            if user[0]==d[2] and user[1]>d[2] :
                work=user[1]-d[2]
            elif user[0]>d[1] and user[0]<d[2] :
                work=user[1]-d[2]
            elif d[2]>user[0] :
                work=d[2]-user[0]+user[1]-user[0]
            elif d[2]<user[0] :
                work=user[0]-d[2]+user[1]-user[0]
            else :
                work =100000
            mem.append(work)
        else :
            if user[0]==d[1] and user[1]>d[2] :
                work=0
            elif user[0]<d[1] and user[1]<d[2] :
                work=d[2]-user[1]
            elif d[2]>user[1] :
                work=d[2]-user[0]+user[0]-user[1]
            elif d[2]<user[0] :
                work=user[0]-d[2]+user[0]-user[1]
            else :
                work =100000
            mem.append(work)
    p=[]
    for i in range(len(mem)) :
        p.append([mem[i],i+1])
    p.sort()
    if len(p)>1 :
        a=str(p[0][1])
        print('>>'+a)

6631006721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.34
>> 4
>> 4
>> 4
>> 43
>> 43
>> 42
>> 42
>> 41
>> 41
[]
test_main_50.75
>> 1
>> 3
>> 3
>> 3
>> 34
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.64
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 13
>> 3
>> 13
>> 13
>> 13
>> 1
>> 6
>> 6
>> 6
>> 6
>> 63
>> 4
>> 4
>> 4
>> 4
>> 4
>> 25
[]
bytecount: {'code': 440, 'const': 119, 'code+const': 559}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lifts = []
for _ in range(n):
    lift = list(map(int, input().split()))
    lifts.append(lift)
m = int(input())
best_lifts = []
for _ in range(m):
    K1, K2 = map(int, input().split())
    min_workload = float('inf')
    best_lift = None
    for  L1, L2, L3 in lifts:
        if L2 == L3:
            workload = abs(L3 - K1) + abs(K1 - K2)
        else:
            if L2 < L3:
                if L2 <= K1 <= K2:
                    workload = K2 - (K1 - L2)
                elif K1 < L2:
                    workload = L2 + L3 + abs(L2 - K1) + abs(L3 - K2)
                else:
                    workload = K1 + K2 + abs(L2 - K1) + abs(L3 - K2)
            else:
                if K2 <= K1 <= L2:
                    workload = K1 - K2
                elif L2 < K1:
                    workload = L2 + L3 + abs(L2 - K1) + abs(L3 - K2)
                else:
                    workload = abs(L2 - K1) + abs(L3 - K2)
        if workload < min_workload:
            min_workload = workload
            best_lift = L1
    best_lifts.append(best_lift)
for answer in best_lifts:
    print(">>", answer)

6632174621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.34
>> 4
>> 4
>> 4
>> 43
>> 43
>> 42
>> 42
>> 41
>> 41
[]
test_main_50.75
>> 1
>> 3
>> 3
>> 3
>> 34
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.64
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 13
>> 3
>> 13
>> 13
>> 13
>> 1
>> 6
>> 6
>> 6
>> 6
>> 63
>> 4
>> 4
>> 4
>> 4
>> 4
>> 25
[]
bytecount: {'code': 440, 'const': 119, 'code+const': 559}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = []
for _ in range(n):
    lift_info = list(map(int, input().split()))
    lifts.append(lift_info)
m = int(input())
best_lifts = []
for _ in range(m):
    current_floor, target_floor = map(int, input().split())
    min_workload = float('inf')
    best_lift = None
    # หาลิฟต์ที่เหมาะสมที่สุด
    for lift_num, current, target in lifts:
        if current == target:
                workload = abs(target - current_floor )+abs(current_floor-target_floor)
        else:
         if current < target:  # ลิฟต์ขึ้น
            if current <= current_floor <= target_floor:  # ถ้าคนอยู่ระหว่างชั้นที่ลิฟต์กำลังขึ้น
                workload = target_floor - (current_floor - current)
            elif current_floor < current:  # ถ้าคนอยู่ด้านล่างของลิฟต์
                workload = current + target + abs(current - current_floor) + abs(target - target_floor)
            else:  # ถ้าคนอยู่ด้านบนของลิฟต์
                workload = current_floor + target_floor + abs(current - current_floor) + abs(target - target_floor)
         else:  # ลิฟต์ลง
            if target_floor <= current_floor <= current:  # ถ้าเราอยู่ระหว่างชั้นที่ลิฟต์กำลังลง
                workload = current_floor - target_floor
            elif current < current_floor:  # ถ้าเราอยู่ด้านบนของลิฟต์
                workload = current + target + abs(current - current_floor) + abs(target - target_floor)
            else:  # ถ้าคนอยู่ด้านล่างของลิฟต์
                workload =  abs(current - current_floor) + abs(target - target_floor)
        if workload < min_workload:
            min_workload = workload
            best_lift = lift_num
    best_lifts.append(best_lift)
for answer in best_lifts:
    print(">>", answer)

6630096021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 34
>> 4
>> 3
>> 3
>> 2
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.92
>> 3
>> 3
>> 43
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.46
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.41
>> 2
>> 1
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 63
>> 63
>> 3
>> 21
>> 36
>> 36
>> 36
>> 6
>> 3
>> 54
>> 54
>> 54
>> 4
>> 5
[]
bytecount: {'code': 612, 'const': 147, 'code+const': 759}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
i = 0
ln = []
lh = []
lg = []
while i < n:
    lift = input().split()
    lift_num = lift[0]
    lift_here = lift[1]
    lift_go = lift[2]
    i += 1
    ln.append(int(lift_num))
    lh.append(int(lift_here))
    lg.append(int(lift_go))
x = int(input())
a = 0
yh = []
yg = []
while a < x:
    you = input().split()
    you_here = you[0]
    you_go = you[1]
    yh.append(int(you_here))
    yg.append(int(you_go))
    a += 1
a = 0
while a < x:
    pa = []
    i = 0
    while i < n:
        if (lh[i] <= yh[a] <= yg[a] <= lg[i]) or (lh[i] >= yh[a] >= yg[a] >= lg[i]):
            pa.append(0)
        elif (lh[i] <= yh[a] <= lg[i] < yg[a]) or (lh[i] >= yh[a] >= lg[i] > yg[a]) :
            pa.append(abs(yg[a] - lg[i]))
        else:
            pa.append(abs(yh[a] - lh[i]) + abs(lg[i] - yh[a]))
        i += 1
    min_para = min(pa)
    ans = ln[pa.index(min_para)]
    print(">>", ans)
    a += 1

6630008821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.2
1>> 4
1>> 4
1>> 4
1>> 3
1>> 3
1>> 2
1>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.83
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
4>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.29
1
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
2>> 1
4>> 6
4>> 6
4>> 6
4>> 6
>> 3
6>> 4
6>> 4
6>> 4
6>> 4
>> 5
[]
bytecount: {'code': 582, 'const': 174, 'code+const': 756}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
ele = input()
l1 = []
l2 = []
list_ans = []
for a in range(int(ele)):
    stri = input()
    lstring = stri.split(" ")
    l1.append(int(lstring[1]))
    l2.append(int(lstring[2]))
#print(liststart[3])
x = input()
for a in range(int(x)) :
    diff = 0
    noi = 1000
    stri = input()
    lstring = stri.split(" ")
    start = int(lstring[0])
    go = int(lstring[1])
    for b in range(int(ele)) :
        elevatorstart = l1[b]
        elevatorgo = l2[b]
        if start >= elevatorstart and start <= elevatorgo and go >= start and elevatorgo >= elevatorstart and go > elevatorgo:
            diff = go - elevatorgo
        elif start <= elevatorstart and start >= elevatorgo and go <= start and elevatorgo <= elevatorstart and go < elevatorgo:
            diff = elevatorgo - go
        elif (start >= elevatorstart and start <= elevatorgo and go >= start and elevatorgo >= elevatorstart) or (start <= elevatorstart and start >= elevatorgo and go <= start and elevatorgo <= elevatorstart):
            diff = 0
        elif start <= elevatorgo and go <= start :
            diff = (elevatorgo - start) + (start - go)
        elif start >= elevatorgo and go >= start :
            diff = (start - elevatorgo) + (go - start)
        elif elevatorstart <= start and start >= go :
            diff = abs(start - elevatorgo) + abs(start - go)
        elif elevatorgo >= go and go >= start :
            diff = abs(elevatorgo - start) + abs(go - start)
        if noi > diff :
            noi = diff
            kumtob = b+1
    list_ans.append(kumtob)
for a in range(int(x)) :
    print(list_ans[a])

6631503221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.2
1>> 4
1>> 4
1>> 4
1>> 3
1>> 3
1>> 2
1>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.83
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
4>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.29
1
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
2>> 1
4>> 6
4>> 6
4>> 6
4>> 6
>> 3
6>> 4
6>> 4
6>> 4
6>> 4
>> 5
[]
bytecount: {'code': 610, 'const': 270, 'code+const': 880}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator = input()
liststart = []
listend = []
def func(now,end):
    sum = 0
    mini = 999
    ans = 0
    for i in range(int(elevator)):
        elestart = liststart[i]
        eleend = listend[i]
        if now >= elestart and now <= eleend and end >= now and eleend >= elestart:
            if end > eleend:
                sum = end - eleend
            else:
                sum = 0
        elif now <= elestart and now >= eleend and end <= now and eleend <= elestart:
            if end < eleend:
                sum = eleend - end
            else:
                sum = 0
        elif now >= eleend and end >= now:
            sum = (now - eleend) + (end - now)
        elif elestart >= end and end >= now:
            if eleend > now:
                sum = (eleend - now) + (end - now)
            elif eleend < now:
                sum = (now - eleend) + (end - now)
        elif now <= eleend and end <= now:
            sum = (eleend - now) + (now - end)
        elif elestart <= now and now >= end:
            if eleend < now:
                sum = (now - eleend) + (now - end)
            elif eleend > now:
                sum = (eleend - now) + (now - end)
        if mini > sum:
            mini = sum
            ans = i
    return ans+1
for i in range(int(elevator)):
    x = input()
    s = x.split(" ")
    liststart.append(int(s[1]))
    listend.append(int(s[2]))
question = input()
listtob = []
for i in range(int(question)):
    mini = 999
    x = input()
    s = x.split(" ")
    now = s[0]
    end = s[1]
    ans = func(int(now),int(end))
    listtob.append(ans)
for i in range(int(question)):
    print(listtob[i])

6631108021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('min() arg is an empty sequence')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 54
>> 54
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.0IndexError('list index out of range')
>> 2
>> 1
>> 21
>> 1
>> 1
>> 1
>> 3
>> 23
>> 23
>> 23
>> 23
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 820, 'const': 197, 'code+const': 1017}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรมแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
count = int(input())
Elevator = []
for i in range(count) :
  A = input().split(' ')
  for j in A :
   j = int(j)
  Elevator.append(A)
count_q = int(input())
question = []
for i in range(count_q) :
  A = input().split(' ')
  for j in A:
    j = int(j)
  question.append(A)
for i in range(0,len(question)) :
  q = question[i]
  count_q = []
  for j in range(0,len(Elevator)) :
    l =Elevator[j]
    if int( Elevator[j][1] ) > int( Elevator[j][2] ) and int( question[i][0] ) > int( question[i][1] ) :
      if int( Elevator[j][1] ) >= int( question[i][0] ) and int( Elevator[j][2] ) >= int( question[i][1] ) :
        w = abs( int( Elevator[j][2]) - int( question[i][1]) )
        count_q.append(w)
      if int( Elevator[j][1] ) >= int( question[i][0] ) and int( Elevator[j][2] ) <= int( question[i][1] ) :
        count_q.append(0)
    if int( Elevator[j][1] ) < int( Elevator[j][2] ) and int( question[i][0] ) < int( question[i][1] ) :
      if int( Elevator[j][1] ) <= int( question[i][0] ) and int( Elevator[j][2] )  <= int( question[i][1] ) :
        w = abs( int( Elevator[j][2] ) - int( question[i][1] ) )
        count_q.append(w)
      if int( Elevator[j][1] ) <= int( Elevator[i][0] ) and int( Elevator[j][2] ) >= int( question[i][1] ) :
        count_q.append(0)
    else :
      w = abs( int( question[i][0] ) - int( Elevator[j][2] ) ) + abs( int( question[i][1] ) - int( question[i][0] ) )
      count_q.append(w)
  print( '>>' , count_q.index(min(count_q)) + 1 )

6631510621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 42
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.34
>> 4
>> 4
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.69
>> 2
>> 21
>> 21
>> 1
>> 1
>> 1
>> 6
>> 6
>> 3
>> 3
>> 3
>> 23
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 63
>> 4
>> 4
>> 4
>> 4
>> 45
[]
bytecount: {'code': 1052, 'const': 199, 'code+const': 1251}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevator = []
for i in range(n):
     elevator_data = input().split()
     elevator_number = int(elevator_data[0])
     current_floor = int(elevator_data[1])
     target_floor = int(elevator_data[2])
     elevator.append((elevator_number, current_floor, target_floor))
m = int(input())
for i in range(m):
     current_floor, target_floor = map(int, input().split())
     min_workload = float('inf')
     chosen_elevator = None
     for elevator_number, current, target in elevator:
          if  (current > target and current_floor < target_floor) or (current == target and current_floor < target_floor) or (current > target and current_floor > target_floor and target == target_floor) or (target_floor > current_floor and target > current_floor) or (current < target and current_floor > current) or (current == target and current_floor > target_floor) or (target == current_floor) or (target > current and current_floor > target_floor) or (target > current and current_floor > current) or (current < target and current_floor > target_floor) or (current < current_floor and target < target_floor) or (current > current_floor and target_floor > target and current > target_floor) or (current > target_floor and target > current_floor) or (current > target and current_floor > current and target_floor > current_floor) or (current > target_floor and current_floor > target and target_floor > current_floor):
              workload = abs(target - current_floor) + abs(current_floor - target_floor)
          elif (current_floor <= target and target_floor > target) or (current < current_floor and target < target_floor) or (current < current_floor and target > current_floor and target_floor > target) or (current == target and current < current_floor and target_floor > current_floor) or (current > target and current_floor > target_floor) or (current > target and current_floor > target_floor) or (current >= target and target > current_floor):
              workload = abs(target_floor - target)
          elif (current < current_floor and target > target_floor) or (current_floor == current and target_floor < target):
              workload = 0
          elif (current < current_floor and target < target_floor) or (current > target and current_floor < target_floor) or (target > current_floor and current_floor > target_floor) or (target > current_floor and target_floor < target) or (current_floor > target and target_floor > target) or (current_floor == current and target_floor < target) or (current < target and current_floor < target_floor) or (current >= target and current_floor > target_floor) or (target < current_floor and current > current_floor) or (target <= current_floor and current_floor > target_floor) or (current == current_floor and target_floor > target) or (target < current_floor and current > target_floor) or (target <= current_floor and target_floor < target) or (target <= target_floor and current < current_floor) or (current_floor <= target and target_floor > target):
              workload = abs(target_floor - target)
          elif (current == current_floor and target_floor > target):
                  workload = abs(current - target_floor)
          if workload < min_workload:
             min_workload = workload
             chosen_elevator = elevator_number
     print(">>", chosen_elevator)

6631212621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('min() arg is an empty sequence')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 54
>> 54
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 710, 'const': 147, 'code+const': 857}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) #จำนวนลิฟต์
elev = [] #ข้อมูลลิฟต์
for i in range(n):
    E = input().split()
    E = [int(j) for j in E]
    elev.append(E)
m = int(input()) #จำนวนคำถาม
m_list = [] #รายละเอียดคำถาม
for i in range(m):
    E = input().split()
    E = [int(j) for j in E]
    m_list.append(E)
for i in range(len(m_list)):
    q = m_list[i]
    min_distances = []
    for j in range(len(elev)):
        l = elev[j]
        if elev[j][1] > elev[j][2] and m_list[i][0] > m_list[i][1]:
            if elev[j][1] >= m_list[i][0] and elev[j][2] >= m_list[i][1]:
                t = abs(elev[j][2] - m_list[i][1])
                min_distances.append(t)
            if elev[j][1] >= m_list[i][0] and elev[j][2] <= m_list[i][1]:
                min_distances.append(0)
        if elev[j][1] < elev[j][2] and m_list[i][0] < m_list[i][1]:
            if elev[j][1] <= m_list[i][0] and elev[j][2] <= m_list[i][1]:
                t = abs(elev[j][2] - m_list[i][1])
                min_distances.append(t)
            if elev[j][1] <= m_list[i][0] and elev[j][2] >= m_list[i][1]:
                min_distances.append(0)
        else:
            t = abs(m_list[i][0] - elev[j][2]) + abs(m_list[i][1] - m_list[i][0])
            min_distances.append(t)
    print('>>', min_distances.index(min(min_distances)) + 1)

6631228721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.0ValueError('min() arg is an empty sequence')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 54
>> 54
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 784, 'const': 197, 'code+const': 981}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
f = []
for y in range( n ) :
  A = input().split(' ')
  f.append(A)
question = int(input())
s = []
for x in range( question ) :
  B = input().split(' ')
  s.append(B)
for x in range(0,len(s)) :
  t = s[x]
  q = []
  for y in range(0,len(f)) :
    r = f[y]
    if int(f[y][1]) > int(f[y][2]) and int(s[x][0]) > int(s[x][1]) :
      if int(f[y][1]) >= int(s[x][0]) and int(f[y][2]) >= int(s[x][1]) :
        w = abs(int(f[y][2]) - int(s[x][1]))
        q.append(w)
      if int(f[y][1]) >= int(s[x][0]) and int(f[y][2]) <= int(s[x][1]) :
        q.append(0)
    if int(f[y][1]) < int(f[y][2]) and int(s[x][0]) < int(s[x][1]) :
      if int(f[y][1]) <= int(s[x][0]) and int(f[y][2]) <= int(s[x][1]) :
        w = abs(int(f[y][2]) - int(s[x][1]))
        q.append(w)
      if int(f[y][1]) <= int(s[x][0]) and int(f[y][2]) >= int(s[x][1]) :
        q.append(0)
    else :
      w = abs(int(s[x][0]) - int(f[y][2])) + abs(int(s[x][1]) - int(s[x][0]))
      q.append(w)
  print('>>' , q.index(min(q)) + 1)

6631528021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.59
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
>> 2
>> 61
>> 6
>> 6
>> 6
>> 6
>> 3
>> 34
>> 4
>> 34
>> 34
>> 35
[]
bytecount: {'code': 868, 'const': 220, 'code+const': 1088}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def main(LN):
    n = []
    m = []
    while LN > 0:
      x = input().split()
      n = n + x
      LN -= 1
    LN = int(input())
    f = LN
    while LN > 0:
        x = input().split()
        m = m + x
        LN -= 1
    #CALCULATE
    a = n[1::3]
    b = n[2::3]
    c = m[0::2]
    d = m[1::2]
    e = n[0::3]
    j = 0
    #print(a,b,c,d,e) #a=lift start b=lift end c=we start d=we end
    while j < f:
      work = []
      i = 0
      while i < int(e[-1]):
        if int(a[i]) > int(b[i]) and int(c[j]) > int(d[j]): #Down
            if int(d[j]) < int(b[i]):
                work.append(abs(int(b[i])-int(d[j])))
            elif int(c[j]) <= int(a[i]) and int(b[i]) <= int(d[j]):
                work.append(0)
            else:
                work.append((abs(int(b[i])-int(c[j])))+(abs(int(c[j])-int(d[j]))))
        elif int(a[i]) < int(b[i]) and int(c[j]) < int(d[j]): #Up
            if int(d[j]) > int(b[i]):
                work.append(abs(int(b[i])-int(d[j])))
            elif int(c[j]) >= int(a[i]) and int(b[i]) >= int(d[j]):
                work.append(0)
            else:
                work.append((abs(int(b[i])-int(c[j])))+(abs(int(c[j])-int(d[j]))))
        else:
            work.append((abs(int(b[i])-int(c[j])))+(abs(int(c[j])-int(d[j]))))
        i += 1
        #print(work)
      num = min(work)
      num = work.index(num)
      print(">> "+str(e[num]))
      j += 1
a = int(input())
main(a)

6631023321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 3
>>1 4
[]
test_main_30.89
>>2 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.89
>>0 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.42
>>1 3
>>1 3
>>1 3
>>1 4
>>1 4
>>1 2
>>1 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
wtf 12
>>1
wtf 10
>>1
wtf 10
>>1
wtf 10
wtf 8
>> 2
wtf 8
>> 2
wtf 8
wtf 6
>> 3
wtf 6
>> 3
wtf 6
wtf 4
>>4
wtf 4
>>4
wtf 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>>1 2
>>2 1
>>2 1
>>2 1
>>2 1
>>2 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>>1
wtf 76
>>4
wtf 6
>>4
wtf 56
>>4
wtf 6
>>4
wtf 73
>> 4
wtf 7
>>6
wtf 64
>>6
wtf 54
>>6
wtf 64
>>6 5
[]
bytecount: {'code': 1816, 'const': 326, 'code+const': 2142}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
arr1 = []
arr2 = []
for x in range(n):
  arr = input().split()
  arr1.append(int(arr[1]))
  arr2.append(int(arr[-1]))
q = int(input())
p = 0
for x in range(q):
  a, b = [int(e) for e in input().split()]
  mn = 9999999
  p=0
  for i in range(n):
    s = arr1[i]
    e = arr2[i]
    # ---> and --->
    if s <= e and a <= b:
      if a <= s and b <= s:
        mnn = mn
        mn = min(mn, abs(a-b) + abs(e-a))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a <= s and s <= b and b <= e:
        mnn = mn
        mn = min(mn, abs(a-b) + abs(e-a))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif s <= a and a <= e and s <= b and b <= e:
        mn = 0
        p = i+1
      elif s <= a and a <= e and e <= b:
        mnn = mn
        mn = min(mn, abs(b-e))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif e <= a and e <= b:
        mnn = mn
        mn = min(mn, abs(b-e))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
    # ---> and <---
    elif s <= e and b <= a:
      if a <= s and b <= s:
        mnn = mn
        mn = min(mn, abs(a-b) + abs(e-a))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a >= s and b <= s:
        mnn = mn
        mn = min(mn, abs(a-b) + abs(e-a))
        if mn != mnn:
          p = i+1
          print("wtf", mn)
        else:
          mn = mnn
      elif s <= a and a <= e and s <= b:
        mnn = mn
        mn = min(mn, abs(b-e))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a >= e and e >= b:
        mnn = mn
        mn = min(mn, abs(b-a) + abs(e-a))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif e <= a and e <= b:
        mnn = mn
        mn = min(mn, abs(a-e) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
    # <--- and <---
    elif e <= s and b <= a:
      if s >= b and b >= e and s >= a and a >= e:
        mn = 0
        p = i+1
      elif b <= e and a <= e:
        mnn = mn
        mn = min(mn, abs(b-e))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a >= e and b <= e:
        mnn = mn
        mn = min(mn, abs(b-e))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif s <= a and b <= s:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a >= s and b >= s:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
    # <--- and --->
    elif e <= s and a <= b:
      if e >= a and e >= b:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a <= e and b >= e and b <= s:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a >= e and a <= s and b >= e and b <= s:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a <= s and b >= s:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
      elif a >= s and b >= s:
        mnn = mn
        mn = min(mn, abs(e-a) + abs(a-b))
        if mn != mnn:
          p = i+1
        else:
          mn = mnn
  print(">>", p, sep='')

6630026021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.67
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 1
>> 21
>> 21
>> 21
>> 21
>> 23
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 2580, 'const': 148, 'code+const': 2728}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n =int(input())
start = [0]*n
stop = [0]*n
i = 0
while i < n:
    a = input().split()
    start[i] = int(a[1])
    stop[i] = int(a[2])
    i += 1
m =int(input())
people = [0]*m
des = [0]*m
j = 0
while j < m:
    b = input().split()
    people[j] = int(b[0])
    des[j] = int(b[1])
    j += 1
u = 0
z = [0]*m
ans = [0]*n*m
k = 0
while u < m:
    v = 0
    while v < n: #up
        if start[v]>= stop[v]>= people[u]>= des[u]:
            g = stop[v] - des[u]
            ans[k] = int(g)
        elif start[v]>= stop[v]>= des[u]>= people[u]:
            g = (stop[v] - people[u]) + des[u]
            ans[k] = int(g)
        elif start[v]>= people[u]>= stop[v]>= des[u]:
            g = stop[v] - des[u]
            ans[k] = int(g)
        elif start[v]>= people[u]>= des[u]>= stop[v]:
            g = 0
            ans[k] = int(g)
        elif start[v]>= des[u]>= stop[v]>= people[u]:
            g = (stop[v] - people[u]) + des[u]
            ans[k] = int(g)
        elif start[v]>= des[u]>= people[u]>= stop[v]:
            g = des[u] - stop[v]
            ans[k] = int(g)
        elif stop[v]>= start[v]>= people[u]>= des[u]:
            g = stop[v] - des[u]
            ans[k] = int(g)
        elif stop[v]>= start[v]>= des[u]>= people[u]:
            g = (stop[v] - people[u]) + des[u]
            ans[k] = int(g)
        elif stop[v]>= people[u]>= start[v]>= des[u]:
            g = stop[v] - des[u]
            ans[k] = int(g)
        elif stop[v]>= people[u]>= des[u]>= start[v]:
            g = stop[v] - des[u]
            ans[k] = int(g)
        elif stop[v]>= des[u]>= start[v]>= people[u]:
            g = (stop[v] - people[u]) + des[u]
            ans[k] = int(g)
        elif stop[v]>= des[u]>= people[u]>= start[v]:
            g = 0
            ans[k] = int(g)
        elif people[u]>= start[v]>= stop[v]>= des[u]:
            g = people[u] - stop[v] + people[u] - des[u]
            ans[k] = int(g)
        elif people[u]>= start[v]>= des[u]>= stop[v]:
            g = people[u] + people[u] - des[u]
            ans[k] = int(g)
        elif people[u]>= stop[v]>= start[v]>= des[u]:
            g = people[u] - stop[v] + people[u] - des[u]
            ans[k] = int(g)
        elif people[u]>= stop[v]>= des[u]>= start[v]:
            g = people[u] - stop[v] + people[u] - des[u]
            ans[k] = int(g)
        elif people[u]>= des[u]>= start[v]>= stop[v]:
            g = people[u] - stop[v] + people[u] - des[u]
            ans[k] = int(g)
        elif people[u]>= des[u]>= stop[v]>= start[v]:
            g = people[u] - stop[v] + people[u] - des[u]
            ans[k] = int(g)
        elif des[u]>= start[v]>= stop[v]>= people[u]:
            g = stop[v] - people[u] + des[u]
            ans[k] = int(g)
        elif des[u]>= start[v]>= people[u]>= stop[v]:
            g = des[u] - stop[v]
            ans[k] = int(g)
        elif des[u]>= stop[v]>= start[v]>= people[u]:
            g = stop[v] - people[u] + des[u]
            ans[k] = int(g)
        elif des[u]>= stop[v]>= people[u]>= start[v]:
            g = des[u] - stop[v]
            ans[k] = int(g)
        elif des[u]>= people[u]>= start[v]>= stop[v]:
            g = des[u] - stop[v]
            ans[k] = int(g)
        else:
            g = des[u]-stop[v]
            ans[k] = int(g)
        v +=1
        k += 1
    u += 1
l = 0
while l < m:
    rans = ans[(l*n):(n*(l+1))]
    y = min(rans)
    z[l] = rans.index(int(y)) + 1
    l += 1
e = 0
while e < m:
    print(">> " + str(z[int(e)]))
    e += 1
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631502621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 638, 'const': 239, 'code+const': 877}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
nL = []
mL = []
for i in range(n):
    a,b,c=[int(e1) for e1 in input().split()]
    nL.append(b)
    mL.append(c)
def rule(d,f):
    x = 0
    inf = float('inf')
    y = 0
    for i in range(n):
        es = nL[i]
        ee = mL[i]
        if d >= es and d <= ee and f >= d and ee >= es:
            if f > ee:
                x = f - ee
            else:
                x = 0
        elif d <= es and d >= ee and f <= d and ee <= es:
            if es < ee:
                x = ee - f
            else:
                x = 0
        elif d >= ee and f >= d:
            x = (d - ee) + (f - d)
        elif es >= ee and f >= d:
            if ee > d:
                x = (ee - d) + (f - d)
            elif ee < d:
                x = (d - ee) + (f - d)
        elif d <= ee and f <= d:
            x = (ee - d) + (d - f)
        elif es <= d and d >=  ee:
            if ee < d:
                x = (d - ee) + (d - f)
            elif ee > d:
                x = (ee - d) + (d - f)
        if inf > x:
            inf = x
            y = i
    return y+1
m = int(input())
lt = []
for i in range(m):
    inf = float('inf')
    d,f=[int(e2) for e2 in input().split()]
    y = rule(int(d),int(f))
    lt.append(y)
for i in range(m):
    print('>>',lt[i])

6630005921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 14
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.59
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 2
>> 21
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.41
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 16
>> 6
>> 16
>> 16
>> 43
>> 4
>> 4
>> 4
>> 4
>> 6
>> 65
[]
bytecount: {'code': 586, 'const': 147, 'code+const': 733}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
L = int(input())
d1 = []
for n in range(L):
    x = input()
    d1.append(x)
#d1[0] is lift_no_1, d[1] lift_no_2...
Q = int(input())
d2 = []
for n in range(Q):
    y = input()
    d2.append(y)
i = 0 # lift number
a = 0
d3 = []
while a < Q:
    while i < L:
        A = int(d1[i].split()[1])
        B = int(d1[i].split()[2])
        C = int(d2[a].split()[0])
        D = int(d2[a].split()[1])
        if A <= C and B >= A and C < D:
            z = abs(A - C) + abs(C - D) - abs(B - A)
        elif A <= C and B <= A and C > D:
            z = abs(A - C) + abs(C - D) - abs(B - A)
        else:
            z = abs(B - C) + abs(C - D)
        d3.append(z)
        i += 1
    i = 0
    a += 1
e = 0
X = int(len(d3)/Q)
n = 0
p = 0
while e < Q:
    x = min(d3[X*n:X*(n+1)])
    for i in range(len(d3[X*n:X*(n+1)])):
        y = d3[X*n:X*(n+1)]
        if x == y[i]:
            p = i
            break
    n += 1
    e += 1
    print(">>", p+1)

6630097621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 612, 'const': 321, 'code+const': 933}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elev = input()
listเริ่ม = []
listจบ = []
def func(n,e):
    sum = 0
    min = 100
    ans = 0
    for i in range(int(elev)):
        elevเริ่ม = listเริ่ม[i]
        elevจบ = listจบ[i]
        if n >= elevเริ่ม and n <= elevจบ and e >= n and elevจบ >= elevเริ่ม:
            if e > elevจบ:
                sum = e - elevจบ
            else:
                sum = 0
        elif n <= elevเริ่ม and n >= elevจบ and e <= n and elevจบ <= elevเริ่ม:
            if e < elevจบ:
                sum = elevจบ - e
            else:
                sum = 0
        elif n >= elevจบ and e >= n:
            sum = (n - elevจบ) + (e - n)
        elif elevเริ่ม >= e and e >= n:
            if elevเริ่ม > n:
                sum = (elevจบ - n) + (e - n)
            elif elevจบ < n:
                sum = (n - elevจบ) + (e - n)
        elif n <= elevจบ and e <= n:
            sum = (elevจบ - n) + (n - e)
        elif elevเริ่ม <= n and n >= e:
            if elevจบ < n:
                sum = (n - elevจบ) + (n - e)
            elif elevจบ > now:
                sum = (elevจบ - n) + (n - e)
        if min > sum:
            min = sum
            ans = i
    return ans+1
for i in range(int(elev)):
    x = input()
    s = x.split(" ")
    listเริ่ม.append(int(s[1]))
    listจบ.append(int(s[2]))
โจทย์ = input()
listตอบ = []
for i in range(int(โจทย์)):
    min = 100
    x = input()
    s = x.split(" ")
    n = s[0]
    e = s[1]
    ans = func(int(n),int(e))
    listตอบ.append(ans)
for i in range(int(โจทย์)):
    print('>>' ,listตอบ[i])

6630308021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 604, 'const': 321, 'code+const': 925}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator = int(input())
liststart = []
listend = []
def func(now,end):
    sum = 0
    mini = 999
    ans = 0
    for i in range(elevator):
        elestart = liststart[i]
        eleend = listend[i]
        if now >= elestart and now <= eleend and end >= now and eleend >= elestart:
            if end > eleend:
                sum = end - eleend
            else:
                sum = 0
        elif now <= elestart and now >= eleend and end <= now and eleend <= elestart:
            if end < eleend:
                sum = eleend - end
            else:
                sum = 0
        elif now >= eleend and end >= now:
            sum = (now - eleend) + (end - now)
        elif elestart >= end and end >= now:
            if eleend > now:
                sum = (eleend - now) + (end - now)
            elif eleend < now:
                sum = (now - eleend) + (end - now)
        elif now <= eleend and end <= now:
            sum = (eleend - now) + (now - end)
        elif elestart <= now and now >= end:
            if eleend < now:
                sum = (now - eleend) + (now - end)
            elif eleend > now:
                sum = (eleend - now) + (now - end)
        #print(sum)
        if mini > sum:
            mini = sum
            ans = i
    return ans+1
for i in range(elevator):
    x = input()
    s = x.split(" ")
    liststart.append(int(s[1]))
    listend.append(int(s[2]))
#print(liststart[3])
question = int(input())
listtob = []
for i in range(question):
    mini = 999
    x = input()
    s = x.split(" ")
    now = s[0]
    end = s[1]
    ans = func(int(now), int(end))
    listtob.append(ans)
for i in range(question):
    print(">>", listtob[i])

6631521521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 598, 'const': 369, 'code+const': 967}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
lift = input()
present = []
last = []
def func(there,go):
    pala = 0
    min = float('inf')
    y = 0
    for i in range(int(lift)):
        presentlift = present[i]
        lastlift = last[i]
        if there >= presentlift and there <= lastlift and go >= there and lastlift >= presentlift:
            if go > lastlift:
                pala = go - lastlift
            else:
                pala = 0
        elif there <= presentlift and there >= lastlift and go <= there and lastlift <= presentlift:
            if go < lastlift:
                pala = lastlift - go
            else:
                pala = 0
        elif there >= lastlift and go >= there:
            pala = (there - lastlift) + (go - there)
        elif presentlift >= go and go >= there:
            if lastlift > there:
                pala = (lastlift - there) + (go - there)
            elif lastlift < there:
                pala = (there - lastlift) + (go - there)
        elif there <= lastlift and go <= there:
            pala = (lastlift - there) + (there - go)
        elif presentlift <= there and there >= go:
            if lastlift < there:
                pala = (there - lastlift) + (there - go)
            elif lastlift > there:
                pala = (lastlift - there) + (there - go)
        if min > pala:
            min = pala
            y = i
    return y+1
for i in range(int(lift)):
    a = input()
    x = a.split(" ")
    present.append(int(x[1]))
    last.append(int(x[2]))
where = input()
SME = []
for i in range(int(where)):
    min = float('inf')
    a = input()
    x = a.split(" ")
    there = x[0]
    go = x[1]
    y = func(int(there),int(go))
    SME.append(y)
    print(">>", y)

6631541021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>>1 4
>>1 4
>>1 4
>>1 3
>>1 3
>>1 2
>>1 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>>4 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>>1 2
>>2 1
>>2 1
>>2 1
>>2 1
>>2 1
>> 3
>> 3
>> 3
>> 3
>> 3
>>2 1
>>4 6
>>4 6
>>4 6
>>4 6
>> 3
>>6 4
>>6 4
>>6 4
>>6 4
>> 5
[]
bytecount: {'code': 618, 'const': 321, 'code+const': 939}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
#print("love34")
elevator = input()
liststart = []
listend = []
def func(now,end):
    sum = 0
    mini = 999
    ans = 0
    for i in range(int(elevator)):
        elestart = liststart[i]
        eleend = listend[i]
        if now >= elestart and now <= eleend and end >= now and eleend >= elestart:
            if end > eleend:
                sum = end - eleend
            else:
                sum = 0
        elif now <= elestart and now >= eleend and end <= now and eleend <= elestart:
            if end < eleend:
                sum = eleend - end
            else:
                sum = 0
        elif now >= eleend and end >= now:
            sum = (now - eleend) + (end - now)
        elif elestart >= end and end >= now:
            if eleend > now:
                sum = (eleend - now) + (end - now)
            elif eleend < now:
                sum = (now - eleend) + (end - now)
        elif now <= eleend and end <= now:
            sum = (eleend - now) + (now - end)
        elif elestart <= now and now >= end:
            if eleend < now:
                sum = (now - eleend) + (now - end)
            elif eleend > now:
                sum = (eleend - now) + (now - end)
        #print(sum)
        if mini > sum:
            mini = sum
            ans = i
    return ans+1
for i in range(int(elevator)):
    x = input()
    s = x.split(" ")
    liststart.append(int(s[1]))
    listend.append(int(s[2]))
#print(liststart[3])
question = input()
listtob = []
for i in range(int(question)):
    mini = 999
    x = input()
    s = x.split(" ")
    now = s[0]
    end = s[1]
    ans = func(int(now),int(end))
    listtob.append(ans)
for i in range(int(question)):
    print(">>" + str(listtob[i]))

6630076421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.6
>> 4
>> 4
>> 4
4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.68
3
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.74
>> 2
2>> 1
>> 1
>> 1
>> 1
>> 1
6>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
3>> 6
>> 3
>> 4
>> 4
>> 4
5>> 4
>> 5
[]
bytecount: {'code': 648, 'const': 96, 'code+const': 744}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) #จำนวนลิฟท์ที่มี
c1 = [0]*n ; c2 = [0]*n ; c3 = [0]*n
for i in range(n):
    a = input().split()
    b = a[0]
    c = a[1]
    d = a[2]
    c1[i] = int(b)
    c2[i] = int(c)
    c3[i] = int(d)
nq = int(input()) #จำนวนคำถาม
qi = [0]*nq ; qf = [0]*nq
for i in range(nq):
    e = input().split()
    f = e[0]
    g = e[1]
    qi[i] = int(f) #ชั้นที่อยู่
    qf[i] = int(g) #ชั้นที่จะไป
#นำอินพุทมาทดสอบ
works =[0]*n
for i in range(nq):
    for j in range(n):
        if c2[j]<qi[i] and c3[j]>qi[i]:
            work = abs(c3[j]-qf[i])
        elif c2[j]>qi[i] and c3[j]<qi[i]:
            work = abs(c3[j]-qf[i])
        #เป็นทางผ่าน
        elif c2[j] <= qi[i] <= c3[j] and c2[j] <= qf[i] <= c3[j] :
            work = 0
        elif c3[j] <= qi[i] <= c2[j] and c3[j] <= qf[i] <= c2[j] :
            work = 0
        else :
            work = abs(qi[i]-c3[j])+abs(qf[i]-qi[i])
        works[j] = int(work)
    x = n
    for j in range(n):
        if min(works) == works[j]:
            if c1[j]<=x:
                 x = c1[j]
    print(x)

6630358421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 43
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.59
>> 1
>> 1
>> 1
>> 12
>> 12
>> 14
>> 23
>> 23
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.37
>> 12
>> 21
>> 21
>> 21
>> 1
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 36
>> 3
>> 64
>> 64
>> 64
>> 54
>> 5
[]
bytecount: {'code': 650, 'const': 341, 'code+const': 991}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
import math
ele_num = int(input())
id_ele = []
c_f_ele = []
f_f_ele = []
if ele_num > 0:
  for i in range(ele_num):
    num, c_f, f_f = input().split()
    id_ele.append(int(num))
    c_f_ele.append(int(c_f))
    f_f_ele.append(int(f_f))
else:
    print("Invalid Number of Elevator")
def lift_check(current,final):
    sum = 0
    min = 999
    ans = 0
    for i in range(int(ele_num)):
        current_ele = c_f_ele[i]
        final_ele = f_f_ele[i]
        if current >= current_ele and current <= final_ele and final >= current and final_ele >= current_ele:
            if final > final_ele:
                sum = current - final_ele
            else:
                sum = 0
        elif current <= current_ele and current >= final_ele and current <= current and final_ele <= current_ele:
            if current < final_ele:
                sum = final_ele - current
            else:
                sum = 0
        elif current >= final_ele and current >= current:
            sum = (current - final_ele) + (current - current)
        elif current_ele >= current and current >= current:
            if final_ele > current:
                sum = (final_ele - current) + (current - current)
            elif final_ele < current:
                sum = (current - final_ele) + (current - current)
        elif current <= final_ele and current <= current:
            sum = (final_ele - current) + (current - current)
        elif current_ele <= current and current >= current:
            if final_ele < current:
                sum = (current - final_ele) + (current - current)
            elif final_ele > current:
                sum = (final_ele - current) + (current - final)
        if min > sum:
            min = sum
            ans = i
    return ans+1
personcount = input()
final = []
for i in range(int(personcount)):
    personint = input()
    x = personint.split(" ")
    c_f_per = x[0]
    f_f_per = x[1]
    ans = lift_check(int(c_f_per),int(f_f_per))
    final.append(ans)
for i in range(int(personcount)):
    print(">> " + str(final[i]))

6631519321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.75
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.73
>> 2
>> 21
>> 1
>> 1
>> 1
>> 6
>> 61
>> 3
>> 3
>> 3
>> 43
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 6
>> 43
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 514, 'const': 175, 'code+const': 689}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevator = []
for i in range(n):
  e = input().strip().split()
  elevator.append(e)
m = int(input())
person = []
for i in range(m):
  p = input().strip().split()
  person.append(p)
for p in person:
  on = int(p[0])
  off = int(p[1])
  ans_labor = 999
  ans_e = 999
  for n in elevator:
    e = int(n[0])
    e1 = int(n[1])
    e2 = int(n[2])
    if e1 == e2:
      labor = abs(on - e1) + abs(off - on)
      if labor <= ans_labor:
        ans_labor = labor
        ans_e = e
      continue
    if on > off and e1 > e2: #p down e down
      if on <= e1 and off >= e2:
        labor = 0
      elif on <= e1 and off <= e2:
        labor = e2 - off
      else:
        labor = (on - e2) + (on - off)
    elif on > off and e1 < e2: #p down e up
      if on < e2:
        labor = e2 - off
      else:
        labor = (on - e2) + (on - off)
    elif on < off and e1 > e2: #p up e down
      if on > e2:
        labor = off - e2
      else:
        labor = (e2 - on) + (off - on)
    else: #p up e up
      if on >= e1 and off <= e2:
        labor = 0
      elif on <= e1:
        labor = (e2 - on) + (off - on)
      else:
        labor = off - e2
    if labor <= ans_labor:
      ans_labor = labor
      ans_e = e
  print(">>", ans_e)

6630028321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.29
1
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
2>> 1
4>> 6
4>> 6
4>> 6
4>> 6
>> 3
6>> 4
6>> 4
6>> 4
6>> 4
>> 5
[]
bytecount: {'code': 746, 'const': 124, 'code+const': 870}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift1 = []
lift2 = []
lift_name = []
for i in range(n) :
    lift,s1,s2 = input().split()
    lift_name.append(lift)
    lift1.append(int(s1))
    lift2.append(int(s2))
m = int(input())
lift_answer = []
for i in range(m):
    request1,request2 = input().split()
    request1 = int(request1)
    request2 = int(request2)
    distant_list= []
    minanswer = 10000
    liftpos = -1
    for j in range(len(lift1)):
        now = lift1[j]
        goto = lift2[j]
        #lift stay
        if now==goto:
            distant = abs(request1-now)+abs(request2-request1)
        #lift go up and request go up
        elif now< goto and request1 < request2 :
            if request1 < now :
                distant = abs(goto-request1)+abs(request2-request1)
            elif now <= request1 <= goto and now <= request2 <= goto :
                distant = 0
            elif now <= request1 <= goto and request2 > goto :
                distant = abs(request2-goto)
            elif request1 > goto:
                distant = abs(request1-goto)+abs(request2-request1)
        #lift go down and request go down
        elif now > goto and request1 > request2 :
            if request1 > now :
                distant = abs(goto-request1)+abs(request2-request1)
            elif now >= request1 >= goto and now >= request2 >= goto :
                distant = 0
            elif now >= request1 >= goto and request2 < goto :
                distant = abs(request2-goto)
            elif request1 < goto:
                distant = abs(request1-goto)+abs(request2-request1)
        else :
            distant = abs(goto-request1)+abs(request2-request1)
        distant_list.append(distant)
    for i in range(len(lift1)) :
        if minanswer > distant_list[i] :
            minanswer = distant_list[i]
            liftpos = i
    lift_answer.append(liftpos+1)
for i in range(len(lift_answer)) :
    print(lift_answer[i])

6631303021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.29
1
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
2>> 1
4>> 6
4>> 6
4>> 6
4>> 6
>> 3
6>> 4
6>> 4
6>> 4
6>> 4
>> 5
[]
bytecount: {'code': 780, 'const': 96, 'code+const': 876}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
i = 0
lift = []
while i < n :
    x = [int(e) for e in input().split()]
    lift.append(x)
    i += 1
m = int(input())
j = 0
while j < m :
    compar = []
    y = [int(e) for e in input().split()]
    for path in lift :
        if path[2]-path[1] >= 0 and y[1]-y[0] > 0 :
            if path[1] <= y[0] <= path[2] :
                if path[1] <= y[1] <= path[2] :
                    par = 0
                else :
                    par = y[1]-path[2]
            elif y[0] < path[1] :
                par = (path[2]-y[0])+(y[1]-y[0])
            elif path[2] < y[0] :
                par = (y[0]-path[2])+abs(y[1]-y[0])
        elif path[2]-path[1] <= 0 and y[1]-y[0] < 0 :
            if path[2] <= y[0] <= path[1] :
                if path[2] <= y[1] <= path[1] :
                    par = 0
                else :
                    par = path[2]-y[1]
            elif y[0] < path[2] :
                par = (path[2]-y[0])+(y[0]-y[1])
            elif path[1] < y[0] :
                par = (y[0]-path[2])+abs(y[1]-y[0])
        else :
            par = abs(path[2]-y[0])+abs(y[1]-y[0])
        compar.append(par)
    copy_compar = compar.copy()
    compar.sort()
    ans = compar[0]
    ans = copy_compar.index(ans)
    print(ans+1)
    j += 1

6631505521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.29
1
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
2>> 1
4>> 6
4>> 6
4>> 6
4>> 6
>> 3
6>> 4
6>> 4
6>> 4
6>> 4
>> 5
[]
bytecount: {'code': 542, 'const': 306, 'code+const': 848}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator = []
questions = []
elevNum = int(input("Enter The Number of Elevators: "))
for i in range(elevNum):
  inputs = input().split()
  inputs = [int(x) for x in inputs]
  elevCount = inputs[0]
  elevStart = inputs[1]
  elevStop = inputs[2]
  elevator.append([elevStart, elevStop])
questionNum = int(input("Number of Q: "))
for i in range(questionNum):
  inputs = input().split()
  inputs = [int(x) for x in inputs]
  your_start = inputs[0]
  your_dest = inputs[1]
  questions.append([your_start, your_dest])
def rangeCheck(elevNum, questionCount):
  elevStart = elevator[elevNum][0]
  elevDest = elevator[elevNum][1]
  your_start = questions[questionCount][0]
  your_dest = questions[questionCount][1]
  workToStart = abs(elevDest - your_start)
  workToEnd = abs(your_dest - your_start)
  for i in range(min(elevStart, elevDest), max(elevStart, elevDest) + 1):
    if (i == your_start and elevStart - elevDest <= 0
        and your_start - your_dest <= 0):
      workToStart = 0
      workToEnd -= abs(your_start - elevDest)
    elif (i == your_start and elevStart - elevDest >= 0
          and your_start - your_dest >= 0):
      workToStart = 0
      workToEnd -= abs(your_start - elevDest)
  if (workToEnd < 0):
    workToEnd = 0
  return workToStart + workToEnd
for i in range(questionNum):
  elevCheck = []
  for j in range(elevNum):
    elevCheck.append(rangeCheck(j, i))
  lowest_value = min(elevCheck)
  lowest_index = elevCheck.index(lowest_value)
  print(lowest_index+1)

6631546221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.29
1
>> 2
2>> 1
2>> 1
2>> 1
2>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
2>> 1
4>> 6
4>> 6
4>> 6
4>> 6
>> 3
6>> 4
6>> 4
6>> 4
6>> 4
>> 5
[]
bytecount: {'code': 996, 'const': 146, 'code+const': 1142}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
liftall = []
for i in range(n):
    lift1 = str(input())
    liftall.append(lift1)
m = int(input())
floorall = []
for i in range(m):
    floor = str(input())
    floorall.append(floor)
for i in floorall:
    plan = []
    floor = i.split(' ')
    if int(floor[0]) - int(floor[1]) > 0:
        for j in liftall:
            FF = 0
            lift = j.split(' ')
            if int(lift[1]) - int(lift[2]) > 0:
                if int(lift[1]) >= int(floor[0]):
                    if int(lift[2]) <= int(floor[1]):
                        FF = 0
                    else:
                        FF = abs(int(floor[1])-int(lift[2]))
                else:
                    FF = abs(int(lift[2])-int(floor[0]))+abs(int(floor[0])-int(floor[1]))
            elif int(lift[1]) - int(lift[2]) < 0:
                FF = abs(int(lift[2])-int(floor[0]))+abs(int(floor[0])-int(floor[1]))
            else:
                FF = abs(int(lift[2])-int(floor[0]))+abs(int(floor[0])-int(floor[1]))
            plan.append(FF)
        for k in range(len(plan)):
            if plan[k] == min(plan):
                print(k+1)
                break
    elif int(floor[0]) - int(floor[1]) < 0:
        for j in liftall:
            FF = 0
            lift = j.split(' ')
            if int(lift[1]) - int(lift[2]) < 0:
                if int(lift[1]) <= int(floor[0]):
                    if int(lift[2]) >= int(floor[1]):
                        FF = 0
                    else:
                        FF = abs(int(floor[1])-int(lift[2]))
                else:
                    FF = abs(int(lift[2])-int(floor[0]))+abs(int(floor[0])-int(floor[1]))
            elif int(lift[1]) - int(lift[2]) > 0:
                FF = abs(int(lift[2])-int(floor[0]))+abs(int(floor[0])-int(floor[1]))
            else:
                FF = abs(int(lift[2])-int(floor[0]))+abs(int(floor[0])-int(floor[1]))
            plan.append(FF)
        for k in range(len(plan)):
            if plan[k] == min(plan):
                print(k+1)
                break
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631125721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
[8, 1, 7, 6]
[9, 6, 8, 7]
[0, 6, 2, 1]
>> 2
>>2 4
>> 1
[]
test_main_21.0
[5, 12, 14, 10]
[11, 4, 6, 6]
[14, 7, 5, 9]
[6, 7, 9, 5]
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
[3, 5, 7, 9]
[2, 4, 6, 8]
[3, 3, 5, 7]
[4, 2, 4, 6]
[5, 3, 3, 5]
[6, 4, 2, 4]
[7, 5, 3, 3]
[8, 6, 4, 2]
[9, 7, 5, 3]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.34
[21, 19, 17, 15]
[19, 17, 15, 13]
[17, 15, 13, 11]
[15, 13, 11, 9]
[13, 11, 9, 7]
[11, 9, 7, 7]
[9, 7, 5, 7]
[7, 5, 5, 7]
[5, 3, 5, 7]
>> 4
>> 4
>> 4
>>4 3
>>4 3
>>3 2
>>3 2
>>2 1
>>2 1
[]
test_main_50.84
[23, 21, 17, 19]
[21, 19, 15, 17]
[19, 17, 13, 15]
[17, 15, 11, 13]
[15, 13, 9, 11]
[13, 3, 7, 9]
[11, 3, 7, 7]
[1, 3, 7, 5]
[1, 3, 7, 5]
[1, 3, 7, 5]
[1, 3, 7, 5]
[1, 3, 7, 5]
>> 3
>> 3
>> 3
>>3 4
>>3 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
[12, 14, 16, 18]
[10, 12, 14, 16]
[10, 10, 12, 14]
[10, 8, 10, 12]
[10, 8, 8, 10]
[10, 8, 6, 8]
[10, 8, 6, 6]
[10, 8, 6, 4]
[10, 8, 6, 4]
[10, 8, 6, 4]
[10, 8, 6, 4]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
[13, 15, 19, 17]
[11, 13, 17, 15]
[11, 11, 15, 13]
[11, 9, 13, 11]
[11, 9, 11, 9]
[11, 9, 9, 7]
[11, 9, 7, 7]
[11, 9, 5, 7]
[11, 9, 5, 7]
[11, 9, 5, 7]
[11, 9, 5, 7]
[11, 9, 5, 7]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.78
[9, 6, 14, 16, 19, 11]
[2, 5, 13, 15, 18, 10]
[3, 6, 12, 14, 17, 9]
[4, 7, 11, 13, 16, 8]
[5, 8, 10, 12, 15, 7]
[6, 9, 9, 11, 14, 6]
[7, 10, 8, 10, 13, 5]
[8, 11, 7, 9, 12, 6]
[9, 12, 6, 8, 11, 7]
[10, 13, 5, 7, 10, 8]
[11, 14, 6, 6, 9, 9]
[6, 9, 9, 11, 14, 6]
[7, 10, 8, 10, 13, 5]
[8, 11, 7, 9, 12, 6]
[9, 12, 6, 8, 11, 7]
[10, 13, 5, 7, 10, 8]
[11, 14, 6, 6, 9, 9]
[12, 15, 7, 5, 8, 10]
[13, 16, 8, 6, 7, 11]
[14, 17, 9, 7, 6, 12]
[15, 18, 10, 2, 5, 13]
[16, 19, 11, 9, 6, 14]
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>>6 3
>>6 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>>3 6
>>3 6
>> 3
>> 4
>> 4
>>5 4
>> 4
>> 5
[]
bytecount: {'code': 872, 'const': 235, 'code+const': 1107}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
a = int(input())
b = 0
x = []
while b<a:
    x += [input().split()]
    b += 1
x1 = sorted(x, key=lambda item: item[0])
q = int(input())
q1 = 0
k = []
while q1<q:
    k += [input().split()]
    q1 += 1
o = []
for i in k:
  z = []
  for j in x1:
    if i[0]<i[1] and j[1]<j[2] and int(j[1]) <= int(i[0]) <= int(j[2]) :
     if  int(j[1]) <= int(i[1]) <= int(j[2]):
         z1 = 0
         z.append(z1)
     elif  int(j[2]) <= int(i[1]):
         z1 = abs(int(i[1]) - int(j[2]))
         z.append(z1)
     else:
        z1 = abs(int(j[2])-int(i[0]))+abs(int(i[1])-int(i[0]))
        z.append(z1)
    elif  i[1]<i[0] and j[2]<j[1] and int(j[2]) <= int(i[0]) <= int(j[1]):
      if int(j[2]) <= int(i[1]) <= int(j[1]) :
         z1 = 0
         z.append(z1)
      elif int(i[1]) <= int(j[2]) :
         z1 = abs(int(i[1]) - int(j[2]))
         z.append(z1)
      else:
        z1 = abs(int(j[2])-int(i[0]))+abs(int(i[1])-int(i[0]))
        z.append(z1)
    else:
        z1 = abs(int(j[2])-int(i[0]))+abs(int(i[1])-int(i[0]))
        z.append(z1)
  print(z)
  minz = z.index(min(z))
  o.append(minz+1)
for l in o:
  print(">>"+str(l))

6631344821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>>4 3
>> 3
>>3 2
>> 2
>>2 1
>> 1
[]
test_main_50.75
>> 3
>> 3
>> 3
>>3 4
>> 4
>>4 2
>> 2
>>2 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>>1 2
>> 3
>>2 3
>> 4
>>3 4
>> 4
>> 4
[]
test_main_70.75
>> 1
>> 1
>> 1
>> 2
>> 2
>>1 4
>> 3
>>2 3
>> 3
>>4 3
>> 3
>> 3
[]
test_main_80.73
>> 2
>>2 1
>> 1
>> 1
>>2 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>>3 6
>> 6
>> 6
>>3 6
>> 3
>>5 4
>> 4
>> 4
>>5 4
>> 5
[]
bytecount: {'code': 366, 'const': 147, 'code+const': 513}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
xn=int(input())
x=[]
for i in range(xn):
    x.append((input().split()))
yn=int(input())
y=[]
for i in range(yn):
    y.append((input().split()))
for e in range(yn):
    k = []
    for i in range(xn):
        x1 = int(x[i][1])
        x2 = int(x[i][2])
        y1 = int(y[e][0])
        y2 = int(y[e][1])
        if x2 > y1 > x1 or x1 > y1 > x2:
            a = abs(x2 - y2)
            k.append(a)
        elif x1 == y1:
            a = abs(x1 - y2)
            k.append(a)
        else:
            a = abs(x2 - y1) + abs(y1 - y2)
            k.append(a)
    d = min(k)
    r = k.index(d)
    print('>>' + str(x[r][0]))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6531523721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>  2
>>  4
>>  1
[]
test_main_21.0
>>  1
>>  2
>>  3
>>  4
[]
test_main_31.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
[]
test_main_40.89
>>  4
>>  4
>>  4
>>  3
>>  3
>>  42
>>  2
>>  1
>>  1
[]
test_main_50.92
>>  3
>>  3
>>  3
>>  4
>>  4
>>  2
>>  32
>>  1
>>  1
>>  1
>>  1
>>  1
[]
test_main_60.46
>>  1
>>  21
>>  21
>>  32
>>  32
>>  43
>>  43
>>  4
>>  4
>>  4
>>  4
[]
test_main_70.59
>>  1
>>  21
>>  21
>>  42
>>  42
>>  34
>>  3
>>  3
>>  3
>>  3
>>  3
>>  3
[]
test_main_80.82
>>  2
>>  1
>>  1
>>  1
>>  61
>>  1
>>  3
>>  3
>>  3
>>  43
>>  3
>>  1
>>  16
>>  6
>>  6
>>  6
>>  3
>>  34
>>  4
>>  4
>>  4
>>  5
[]
bytecount: {'code': 552, 'const': 176, 'code+const': 728}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
import math
n = int(input())
number = []
for i in range (n):
  number.append(input().split())
m = int(input())
info = []
result = []
for i in range(m):
  info.append(input().split())
  eiei = []
  for j in range(n):
      if (int(info[i][0]) <= int(number[j][-2]) and int(info[i][0]) >= int(number[j][-1])) or (int(info[i][0]) <= int(number[j][-1]) and int(info[i][0]) >= int(number[j][-2])):
          eiei.append(abs(int(info[i][1]) - int(number[j][-1])))
      else:
          eiei.append(abs(int(info[i][0]) - int(number[j][-1])) + abs(int(info[i][0]) - int(number[j][-1])))
  result.append(eiei)
for i in range (m):
  low = result[i][0]
  Number_of_elevator = int(number[0][0])
  for j in range (1,n):
    if result[i][j] < low:
      low = result[i][j]
      Number_of_elevator = int(number[j][0])
    elif result[i][j] == low and Number_of_elevator > int(number[j][0]):
      Number_of_elevator = int(number[j][0])
  print(">> ",Number_of_elevator)

6630042021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.42
>> 13
>> 13
>> 13
>> 14
>> 14
>> 12
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.28
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 46
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 6
>> 6
>> 6
>> 6
>> 65
[]
bytecount: {'code': 1476, 'const': 239, 'code+const': 1715}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
N = int(input())
x = [0,0,0]*N
i=1
while i <= N :
    r=input().split()
    x[3*i-3]=int(r[0])
    x[3*i-2]=int(r[1])
    x[3*i-1]=int(r[2])
    i+=1
M = int(input())
y = [0,0]*M
j=0
while j<M :
    t=input().split()
    y[2*j]=int(t[0])
    y[2*j+1]=int(t[1])
    j+=1
s=1
q=1
power=[0]*N
while q <=M :
#    power=[0]*N
    while s <= N :
          T=[x[3*s-2],x[3*s-1],y[2*q-2],y[2*q-1]]
          if T[1]>T[0] and T[3]>T[2]:
             if T[1]<=T[2]:
                 power[s-1]=T[3]-T[1]
             if T[0]<=T[2]<=T[1] and T[0]<=T[3]<=T[1]:
                 power[s-1]=0
             if T[2]<=T[0]<=T[3]:
                 power[s-1]=abs(T[1]-T[2])+abs(T[3]-T[2])
             if T[1]>T[3] :
                 power[s-1]=abs(T[1]-T[2])+abs(T[3]-T[2])
             if T[0]<=T[2]<=T[1]:
                 power[s-1]=T[3]-T[1]
          if T[1]>T[0] and T[3]<T[2]:
               power[s-1]=abs(T[1]-T[2])+(T[2]-T[3])
          if T[0]>T[1] and T[2]<T[3]:
              power[s-1]=abs(T[1]-T[2])+(T[3]-T[2])
          if T[0]>T[1] and T[2]>T[3]:
             if T[3]<=T[1]<=T[2]:
                 power[s-1]=T[1]-T[3]
             if T[1]<=T[2]<=T[0] and T[1]<=T[3]<=T[0]:
                 power[s-1]=0
             if T[2]>T[0] and T[3]>=T[0]:
                 power[s-1]=abs(T[2]-T[1])+abs(T[2]-T[3])
             if T[2]>T[0] and T[1]<=T[3]<=T[0]:
                 power[s-1]=abs(T[2]-T[3])+abs(T[1]-T[2])
             if T[0]>T[2] and T[1]>T[2]:
                 power[s-1]=abs(T[2]-T[1])+abs(T[2]-T[3])
          if T[0]==T[1]:
                 power[s-1]=abs(T[3]-T[2])+abs(T[2]-T[1])
          #if T[1]-T[3]>0 or T[0]-T[2]>0:
          #    power[s-1]=abs(T[0]-T[1])+abs(T[2]-T[0])+abs(T[3]-T[2])
          s+=1
    min_po=min(power)
    print(">>",power.index(min_po)+1)
    s=1
    q+=1

6631701121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 23
>> 4
[]
test_main_30.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 5166, 'const': 226, 'code+const': 5392}
#HW02
#6631701121
n0=[]
m0=[]
Elavator=""
m=int(input())
for i in range(m):
  mdata=input().split()
  m0.append(mdata)
n=int(input())
for i in range(n):
  ndata=input().split()
  n0.append(ndata)
for b in n0:
  Delta=10**5
  Reset=10**5
  for a in m0:
    if int(b[1])-int(b[0]) > 0 and int(a[2])-int(a[1]) > 0:
      if int(a[1])<=int(a[2])<=int(b[0])<=int(b[1]) :
        Dif=abs(int(b[1])-int(a[2]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[0]) <= int(b[1]) <= int(a[1]) <= int(a[2]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[1]) <= int(b[0]) <= int(b[1]) <= int(a[2]):
        Dif= 0
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[0]) <= int(a[1]) <= int(a[2]) <= int(b[1]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[0]) <= int(a[1]) <= int(b[1]) <= int(a[2]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[1]) <= int(b[0]) <= int(a[2]) <= int(b[1]):
        Dif=abs(int(b[1])-int(a[2]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
    if int(b[1])-int(b[0]) < 0 and int(a[2])-int(a[1]) < 0:
      if int(b[1])<=int(b[0])<=int(a[2])<=int(a[1]):
        Dif=abs(int(b[1])-int(a[2]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[2]) <= int(a[1]) <= int(b[1]) <= int(b[0]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[2]) <= int(b[1]) <= int(b[0]) <= int(a[1]):
        Dif= 0
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[1]) <= int(a[2]) <= int(a[1]) <= int(b[0]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[1]) <= int(a[2]) <= int(b[0]) <= int(a[1]):
        Dif=abs(int(b[1])-int(a[2]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[2]) <= int(b[1]) <= int(a[1]) <= int(b[0]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
    if int(b[1])-int(b[0]) > 0 and int(a[2])-int(a[1]) < 0:
      if int(b[0]) <= int(b[1]) <= int(a[2]) <= int(a[1]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[2]) <= int(a[1]) <= int(b[0]) <= int(b[1]):
        Dif= abs(int(a[2])-int(b[1]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[0]) <= int(a[2]) <= int(a[1]) <= int(b[1]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[2]) <= int(b[0]) <= int(a[1]) <= int(b[1]):
        Dif= abs(int(a[2])-int(b[1]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[0]) <= int(a[2]) <= int(b[1]) <= int(a[1]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[2]) <= int(b[0]) <= int(a[1]) <= int(b[1]):
        Dif= abs(int(a[2])-int(b[1]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
    if int(b[1])-int(b[0]) < 0 and int(a[2])-int(a[1]) > 0:
      if int(b[1])<=int(b[0])<=int(a[1])<=int(a[2]):
        Dif=abs(int(a[2])-int(b[1]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[1])<=int(a[2])<=int(b[1])<=int(b[0]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[1]) <= int(b[1]) <= int(b[0]) <= int(a[2]):
        Dif=abs(int(a[2])-int(b[1]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[1])<=int(a[1])<=int(a[2])<=int(b[0]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(a[1])<=int(b[1])<=int(a[2])<=int(b[0]):
        Dif= abs(int(a[2])-int(b[0]))+abs(int(b[1])-int(b[0]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
      if int(b[1])<=int(a[1])<=int(b[0])<=int(a[2]):
        Dif=abs(int(a[2])-int(b[1]))
        if Dif< Delta:
          Elavator=a[0]
          Delta=Dif
        if Dif==Delta:
          if int(Elavator)<int(a[0]):
            Elavator=Elavator
          if int(Elavator)>int(a[0]):
            Elavator=a[0]
  print(">>",Elavator)

6630071221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>> 2
>> 24
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.56
>> 4
>> 34
>> 4
>> 3
>> 2
>> 23
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.75
>> 3
>> 3
>> 3
>> 24
>> 24
>> 12
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.82
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 34
>> 54
>> 54
>> 54
>> 5
[]
bytecount: {'code': 618, 'const': 333, 'code+const': 951}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lifts = int(input())
elevator_number = []
elevator_start = []
elevator_stop = []
for i in range(lifts):
    num, start, stop = [int(i) for i in input().split()]
    elevator_number.append(num)
    elevator_start.append(start)
    elevator_stop.append(stop)
people = int(input())
p_start = []
p_stop = []
for i in range(people):
    start, stop = [int(i) for i in input().split()]
    p_start.append(start)
    p_stop.append(stop)
def direction(start,stop):
    if stop > start:
        return 'up'
    elif start > stop:
        return 'down'
    else:
        return 'fixed'
def between(start,check,stop):
    if start <= check <= stop:
        return True
    elif start >= check >= stop:
        return True
    else:
        return False
for i in range(people):
    all_lifts_dis = []
    for j in range(lifts):
        if direction(p_start[i],p_stop[i]) == direction(elevator_start[j],elevator_stop[j])               and between(elevator_start[j],p_start[i],elevator_stop[j])               and between(elevator_start[j],p_stop[i],elevator_stop[j]):
                   d = 0
                   all_lifts_dis.append(d)
        elif direction(p_start[i],p_stop[i]) == direction(elevator_start[j],elevator_stop[j])                    and between(elevator_start[j],p_start[i],elevator_stop[j]):
                         d = abs(elevator_stop[j]-p_stop[i])
                         all_lifts_dis.append(d)
        else:
            d = abs (elevator_stop[j]-p_start[i])+abs(p_stop[i]-p_start[i])
            all_lifts_dis.append(d)
            minimum = min(all_lifts_dis)
    index = all_lifts_dis.index(minimum)
    print('>>',elevator_number[index])

6631213221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.67
>>4 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.34
>> 4
>> 4
>> 4
>>4 3
>>4 3
>>3 2
>>3 2
>>2 1
>>2 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.82
>> 2
>>2 1
>>2 1
>> 1
>> 1
>> 1
>>6 3
>>6 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 450, 'const': 147, 'code+const': 597}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator_count = int(input())
elevator_marub = []
for i in range(elevator_count) :
  elevator_data = [int(data) for data in input().split()]
  elevator_marub.append(elevator_data)
user_count = int(input())
for i in range(user_count) :
  distance = []
  user_now, user_go = [int(data) for data in input().split()]
  for data in elevator_marub :
    if ((data[1] <= user_now <= data[2]) and ((user_go >= user_now and data[2] >= data[1]))
      or (data[1] >= user_now >= data[2])) and ((user_go <= user_now and data[2] <= data[1])) :
      if (data[1] <= user_go <= data[2]) or (data[2] <= user_go <= data[1]) :
        distance.append(0)
      else :
        distance.append(abs(user_go - data[2]))
    else :
      distance.append(abs(user_now - data[2]) + abs(user_go - user_now))
  b = min(distance)
  c = elevator_marub[distance.index(b)][0]
  print('>>' + str(c))

6631523821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.34
>> 32
>> 34
>> 1
[]
test_main_20.5
>> 1
>> 32
>> 3
>> 14
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 660, 'const': 267, 'code+const': 927}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lifts = []
for _ in range(n):
    x = list(map(int, input().split()))
    lifts.append(x)
m = int(input())
quests = []
for _ in range(m):
    y = list(map(int, input().split()))
    quests.append(y)
def calculate(lift, quest):
    a, b, c, d = lift[1], lift[2], quest[0], quest[1]
    if a == c  :
        if b > c and d > c :
            cost = abs(d - a)
        elif b < c and d < c :
            cost = abs(d - a)
        else :
            cost = abs(b - a) + abs(b - c) + abs(c - d)
    elif a > c :
        if b < a and d < c :
            cost = abs(a - c) + abs(d - c)
        elif b == a and d < c :
            cost = abs(b - c) + abs(d - c)
        else :
            cost = abs(b - a) + abs(b - c) + abs(c - d)
    elif a < c :
        if b > a and d > c:
            cost = abs(a - c) + abs(d - c)
        elif b == a and d > c  :
            cost = abs(b - c) + abs(d - c)
        else :
            cost = abs(b - a) + abs(b - c) + abs(c - d)
    else:
        cost = abs(b - a) + abs(b - c) + abs(c - d)
    return cost
for quest in quests:
    min_cost = float('inf')
    best_lift = -1
    for lift in lifts:
        cost = calculate(lift, quest)
        if cost < min_cost:
            min_cost = cost
            best_lift = lift[0]
    print(">>", best_lift)

6630040821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 5
>> 4
>> 4
[]
test_main_70.84
>> 1
>> 1
>> 1
>> 2
>> 2
>> 54
>> 3
>> 43
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 31
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 56
>> 46
>> 46
>> 46
>> 3
>> 74
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 882, 'const': 175, 'code+const': 1057}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
Cn = 0
Cm = 0
L = []
P = []
NP = []
while Cn < n :
     L += [ int(l) for l in input().split() ]
     Cn += 1
m = int(input())
while Cm < m :
     P += [ int(p) for p in input().split() ]
     Cm += 1
for i in range(m) :
    Sum = []
    for j in range(n) :
        if P[2*i] < P[2*i+1] :
           if (L[3*j+2] >= P[2*i+1]) and (P[2*i] >= L[3*j+1]) :
               Sum += [0]
           if (L[3*j+2] <= P[2*i+1]) and (P[2*i] >= L[3*j+1]) :
               Sum += [abs(L[3*j+2]-P[2*i+1])]
           if (P[2*i] <= L[3*j+1]) :
               Sum += [abs(L[3*j+2]-P[2*i])+abs(P[2*i]-P[2*i+1])]
        if P[2*i] > P[2*i+1] :
           if (L[3*j+2] <= P[2*i+1]) and (P[2*i] <= L[3*j+1]) :
               Sum += [0]
           if (L[3*j+2] >= P[2*i+1]) and (P[2*i] <= L[3*j+1]) :
               Sum += [abs(L[3*j+2]-P[2*i+1])]
           if (P[2*i] >= L[3*j+1]) :
               Sum += [abs(L[3*j+2]-P[2*i])+abs(P[2*i]-P[2*i+1])]
    In = Sum.index(min(Sum))
    NP += [In+1]
for i in range(m) :
    print('>>',NP[i])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630311921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.89
>> 21
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.89
>> 04
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.84
>> 01
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 42
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 620, 'const': 243, 'code+const': 863}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# อ่านจำนวนลิฟต์
elevator_count = int(input())
# สร้างรายการลิฟต์
elevators = []
for _ in range(elevator_count):
    x = input().split()
    start, end = int(x[1]), int(x[2])
    elevators.append((start, end))
# คำนวณลิฟต์ที่ใกล้ที่สุด
def find_closest_elevator(now, end):
    min_distance = float('inf')
    closest_elevator = 0
    for i in range(elevator_count):
        ele_start, ele_end = elevators[i]
        distance = min_distance
        if now >= ele_start and now <= ele_end and end >= now and ele_end >= ele_start:
            distance = end - ele_end if end > ele_end else 0
        elif now <= ele_start and now >= ele_end and end <= now and ele_end <= ele_start:
            distance = ele_end - end if end < ele_end else 0
        elif now >= ele_end and end >= now:
            distance = abs(now - ele_end) + abs(end - now)
        elif ele_start >= end and end >= now:
            if ele_end > now:
                distance = abs(ele_end - now) + abs(end - now)
            elif ele_end < now:
                distance = abs(now - ele_end) + abs(end - now)
        elif now <= ele_end and end <= now:
            distance = abs(ele_end - now) + abs(now - end)
        elif ele_start <= now and now >= end:
            if ele_end < now:
                distance = abs(now - ele_end) + abs(now - end)
            elif ele_end > now:
                distance = abs(ele_end - now) + abs(now - end)
        if min_distance > distance:
            min_distance = distance
            closest_elevator = i + 1
    return closest_elevator
# อ่านจำนวนคำถาม
question_count = int(input())
# คำนวณและแสดงผลลัพธ์
results = []
for _ in range(question_count):
    now, end = input().split()
    now, end = int(now), int(end)
    result = find_closest_elevator(now, end)
    results.append(result)
for result in results:
    print(">>",result)

6631112521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.75
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.82
>> 2
>> 1
>> 1
>> 1
>> 1
>> 61
>> 3
>> 3
>> 3
>> 3
>> 43
>> 61
>> 6
>> 6
>> 6
>> 6
>> 43
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 520, 'const': 197, 'code+const': 717}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
n=int(input())
list=[]
for i in range(n):
    f=input().split()
    a=int(f[0])
    b=int(f[1])
    c=int(f[2])
    list.append([a, b, c])
m=int(input())
people=[]
for i in range(m):
    f=input().split()
    a=int(f[0])
    b=int(f[1])
    people.append([a, b])
for a, b in people:
    min_lif=0
    min_name_lif="x"
    pre_ans=0
    if a<=b:
        for t1, t2, t3 in list:
            if t2<=t3:
                if a<t2:
                    pre_ans=abs(t3-a)+abs(b-a)
                else:
                    if b<=t3:
                        pre_ans=0
                    else:
                        pre_ans=abs(b-t3)
            else:
                pre_ans=abs(a-t3)+abs(b-a)
            if min_lif==0 and min_name_lif=="x":
                min_lif=pre_ans
                min_name_lif=t1
            else:
                if min_lif>=pre_ans:
                    min_lif=pre_ans
                    min_name_lif=t1
    else:
        for t1, t2, t3 in list:
            if t2<=t3:
                pre_ans=abs(a-t3)+abs(b-a)
            else:
                if a>t2:
                    pre_ans=abs(a-t3)+abs(a-b)
                else:
                    if b>=t3:
                        pre_ans=0
                    else:
                        pre_ans=abs(t3-b)
            if min_lif==0 and min_name_lif=="x":
                min_lif=pre_ans
                min_name_lif=t1
            else:
                if min_lif>=pre_ans:
                    min_lif=pre_ans
                    min_name_lif=t1
    print(">>", min_name_lif)
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630077021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.75
>> 3
>> 3
>> 3
3>> 4
3>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.82
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
6>> 1
>> 6
>> 6
>> 6
>> 6
4>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 872, 'const': 271, 'code+const': 1143}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input(""))
Elevator=[] #Info
Elevator_C=[] #Info
Elevator_D=[] #Info
Elevator_status=[]
ans=[]
def UD_check(C,D):
    C = int(C)
    D = int(D)
    if(C>D):
        return -1
    elif(D>C):
        return 1
    elif(D==C):
        return 0
for x in range(n):
    Elevator += input().split()
    Elevator_C.append(int(Elevator[(3*x)+1]))
#     print(Elevator_C)
    Elevator_D.append(int(Elevator[(3*x)+2]))
#     print(Elevator_D)
    Elevator_status.append(UD_check(int(Elevator_C[x]),int(Elevator_D[x])))
#     print(Elevator_status)
m = int(input(""))
for x in range(m):
    Step=[]
    c,d = input().split()
    for y in range(n):
#         print(UD_check(c,d))
        if(UD_check(c,d) == int(Elevator_status[y])):
#             print("Same_Direct")
#             print(Elevator_C[y])
#             print(Elevator_D[y])
            if(int(c) in range(int(Elevator_C[y]),int(Elevator_D[y]),Elevator_status[y])):
#                 print("Elevator pass current level")
                if(int(d) in range(int(Elevator_C[y]),int(Elevator_D[y]),Elevator_status[y])):
#                     print("Elevator pass destination level")
                    Step.append(0)
                else:
                    Step.append(abs(int(d)-int(c)))
            elif(int(d) in range(int(Elevator_C[y]),int(Elevator_D[y]),Elevator_status[y])):
#                 print("Elevator pass destination level")
                if(int(c) in range(int(Elevator_C[y]),int(Elevator_D[y]),Elevator_status[y])):
#                     print("Elevator pass current level")
                    Step.append(0)
                else:
                    Step.append(abs(int(Elevator_D[y])-int(c)))
            else:
                if(UD_check(c,d) == UD_check(Elevator_D[y],c)):
                    Step.append(abs(int(Elevator_D[y])-int(d)))
                elif(int(Elevator_D[y] == int(c))):
                    Step.append(abs(int(d)-int(c)))
                else:
                    Step.append(abs(int(Elevator_D[y])-int(Elevator_C[y])) + abs(int(c)-int(Elevator_D[y])) + abs(int(d)-int(c)))
        else:
#             print("Opposite_Direct")
            Step.append(abs(int(Elevator_D[y])-int(Elevator_C[y])) + abs(int(c)-int(Elevator_D[y])) + abs(int(d)-int(c)))
#         print("Step:")
#         print(Step[y])
#     print("ALL_STEP")
#     print(Step)
#     print(min(Step))
    min_ele = Step.index(min(Step))
#    anx = int(min_ele)+1
#    anx = int(min_ele)+1
    anx = Elevator[3*min_ele]
#     print(anx)
    ans.append(anx)
for x in range(m):
#     print("ans")
    print(ans[x])

6531009521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 1
>> 21
>> 21
>> 21
>> 21
>> 43
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 712, 'const': 215, 'code+const': 927}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def elevator(data,now,des):
    a,move=[],0
    for i in range(len(data)):
        if (data[i][2]>des>data[i][1] and data[i][2]>now>data[i][1] and des>now) or (data[i][2]<=des<=data[i][1] and data[i][2]<=now<=data[i][1] and des<=now):
            move = 0
        elif (data[i][2]<=now<=data[i][1] and des - now<0 and data[i][2] - data[i][1]<0) or (data[i][2]>now>data[i][1] and des - now>0 and data[i][2] - data[i][1]>0):
            move = abs(data[i][2]-des)
        else:
            move = abs(data[i][2]-now) + abs(now-des)
        a.append(move)
    minn=min(a)
    for k in range(len(a)):
        if a[k]==minn:
            return k+1
n = int(input())
data = []
for i in range(n):
    tmp=input().split()
    for j in range(len(tmp)):
        tmp[j]=int(tmp[j])
    data.append(tmp)
m = int(input())
data2 = []
for i in range(m):
    tmp=input().split()
    for j in range(len(tmp)):
        tmp[j]=int(tmp[j])
    data2.append(tmp)
for i in range(m):
    print('>>',elevator(data,data2[i][0],data2[i][1]))

6632029321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.67
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 474, 'const': 175, 'code+const': 649}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
num1=int(input())
a=[]
for i in range(1,num1+1):
  i=i+1
  a+=input().split()
num2=int(input())
s=0
f=[]
for j in range(1,num2+1):
 e=[]
 b=input().split()
 comefrom=int(b[0])
 goto=int(b[1])
 for i in range(1,num1+1):
    liftcomefrom=int(a[3*i-2])
    liftgoto=int(a[3*i-1])
    if comefrom not in range(liftcomefrom,liftgoto+1) and comefrom not in range(liftgoto,liftcomefrom+1) :
     s+=abs(comefrom-liftgoto)+abs(comefrom-goto)
    if comefrom in range(liftcomefrom,liftgoto+1) :
      if goto>comefrom:
        s+=abs(goto-liftgoto)
      if goto<=comefrom:
        s+=abs(liftgoto-comefrom)+abs(comefrom-goto)
    if comefrom in range(liftgoto,liftcomefrom+1) :
      if goto<=comefrom:
       s+=abs(liftgoto-goto)
      if goto>comefrom:
        s+=abs(liftgoto-comefrom)+abs(comefrom-goto)
    e+=[s]
    s=0
 f+=[e.index(min(e))+1]
for n in f:
  print(">>",n)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630075821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0EOFError('EOF when reading a line')
>> 2
>> 4
>> 1
[]
test_main_21.0EOFError('EOF when reading a line')
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0EOFError('EOF when reading a line')
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84EOFError('EOF when reading a line')
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 12
>> 3
>> 23
>> 4
>> 34
>> 4
>> 4
[]
test_main_70.75EOFError('EOF when reading a line')
>> 1
>> 1
>> 1
>> 2
>> 2
>> 14
>> 3
>> 23
>> 3
>> 43
>> 3
>> 3
[]
test_main_80.73EOFError('EOF when reading a line')
>> 2
>> 21
>> 1
>> 1
>> 21
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 3
>> 6
>> 6
>> 36
>> 36
>> 53
>> 4
>> 4
>> 54
>> 4
>> 5
[]
bytecount: {'code': 704, 'const': 199, 'code+const': 903}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = []
for i in range(n):
    lift_info = input().split()
    lift_num = int(lift_info[0])
    current_lift = int(lift_info[1])
    dest_lift = int(lift_info[2])
    lifts.append((lift_num,  current_lift, dest_lift))
m = int(input())
results = []
for i in range(m):
    current_user, dest_user = map(int, input().split())
    fastest_lift = None
    min_workload = float('inf')
    for lift_num, current_lift,  dest_lift in lifts:
        if(current_user == current_lift):
          fastest_lift = lift_num
          break
        elif( dest_lift == current_user ):
          fastest_lift = lift_num
          break
        elif(current_lift < current_user <=  dest_lift and  dest_lift <= dest_user) or            (dest_user <=  dest_lift < current_user and current_user <= current_lift) :
              fastest_lift = lift_num
              break
        else :
            work_load = abs(current_user -  dest_lift) + abs(dest_user -  current_user)
            if work_load < min_workload:
                min_workload = work_load
                fastest_lift = lift_num
    results.append(fastest_lift)
for result in results:
    print(">>", result)
n = int(input())
lifts = []
for i in range(n):
    lift_info = input().split()
    lift_num = int(lift_info[0])
    current_lift = int(lift_info[1])
    dest_lift = int(lift_info[2])
    lifts.append((lift_num,  current_lift, dest_lift))
m = int(input())
results = []
for i in range(m):
    current_user, dest_user = map(int, input().split())
    fastest_lift = None
    min_workload = float('inf')
    for lift_num, current_lift,  dest_lift in lifts:
        if(current_user == current_lift):
          fastest_lift = lift_num
          break
        elif( dest_lift == current_user ):
          fastest_lift = lift_num
          break
        elif(current_lift < current_user <=  dest_lift and  dest_lift <= dest_user) or            (dest_user <=  dest_lift < current_user and current_user <= current_lift) :
              fastest_lift = lift_num
              break
        else :
            work_load = abs(current_user -  dest_lift) + abs(dest_user -  current_user)
            if work_load < min_workload:
                min_workload = work_load
                fastest_lift = lift_num
    results.append(fastest_lift)
for result in results:
    print(">>", result)

6631119021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>> 12
>> 3
>> 23
>> 4
>> 34
>> 4
>> 4
[]
test_main_70.75
>> 1
>> 1
>> 1
>> 2
>> 2
>> 14
>> 3
>> 23
>> 3
>> 43
>> 3
>> 3
[]
test_main_80.73
>> 2
>> 21
>> 1
>> 1
>> 21
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 3
>> 6
>> 6
>> 36
>> 36
>> 53
>> 4
>> 4
>> 54
>> 4
>> 5
[]
bytecount: {'code': 352, 'const': 199, 'code+const': 551}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n_elev = int(input())
elev = []
for i in range(n_elev) :
    elev_info = input().split()
    no_elev = int(elev_info[0])
    start_floor = int(elev_info[1])
    end_floor = int(elev_info[2])
    elev.append((no_elev, start_floor, end_floor))
x = int(input())
results = []
for i in range(x) :
    user_start_floor, user_end_floor = map(int, input().split())
    best_elev = None
    min_workload = float('inf')
    for no_elev, start_floor, end_floor in elev :
        if user_start_floor == start_floor :
            best_elev = no_elev
            break
        elif end_floor == user_start_floor :
            best_elev = no_elev
            break
        elif start_floor < user_start_floor <= end_floor and end_floor <= user_end_floor :
            best_elev = no_elev
            break
        elif user_end_floor <= end_floor < user_start_floor and user_start_floor <= start_floor :
            best_elev = no_elev
            break
        else :
            workload = abs(user_start_floor - end_floor) + abs(user_end_floor - user_start_floor)
            if workload < min_workload :
                min_workload = workload
                best_elev = no_elev
    results.append(best_elev)
for result in results :
    print(">>", result)

6631122821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.73
>> 1
>> 1
>> 1
>> 2
>> 12
>> 3
>> 23
>> 4
>> 34
>> 4
>> 4
[]
test_main_70.75
>> 1
>> 1
>> 1
>> 2
>> 2
>> 14
>> 3
>> 23
>> 3
>> 43
>> 3
>> 3
[]
test_main_80.73
>> 2
>> 21
>> 1
>> 1
>> 21
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 3
>> 6
>> 6
>> 36
>> 36
>> 53
>> 4
>> 4
>> 54
>> 4
>> 5
[]
bytecount: {'code': 344, 'const': 199, 'code+const': 543}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lifts = []
for i in range(n):
  lift_info = input().split()
  liftnum = int(lift_info[0])
  liftFloornow = int(lift_info[1])
  liftwillgo = int(lift_info[2])
  lifts.append((liftnum , liftFloornow , liftwillgo))
m = int(input())
results = []
for i in range(m):
  userfloornow , userwillgo = map(int,input().split())
  best_lift = None
  min_workload = float("inf")
  for liftnum , liftFloornow , liftwillgo in lifts:
    if(userfloornow == liftFloornow):
      best_lift = liftnum
      break
    elif(liftwillgo == userfloornow):
      best_lift = liftnum
      break
    elif(liftFloornow < userfloornow <= liftwillgo and liftwillgo <= userwillgo ) or (userwillgo <= liftwillgo < userfloornow and userfloornow <= liftFloornow):
      best_lift = liftnum
      break
    else:
      workload = abs(userfloornow - liftwillgo) + abs(userwillgo - userfloornow)
      if workload < min_workload :
        min_workload = workload
        best_lift = liftnum
  results.append(best_lift)
for result in results:
  print(">>",result)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632219221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_20.75
>> 1
>> 2
>> 23
>> 4
[]
test_main_30.34
>> 1
>> 1
>> 1
>> 12
>> 12
>> 13
>> 13
>> 14
>> 14
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1064, 'const': 148, 'code+const': 1212}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lift_num=[0]*n
lift_s=[0]*n
lift_d=[0]*n
for i in range(n):
    x = input() #1 3 1
    y = x.split() #seperate the information
    lift_num[i] = int(y[0])
    lift_s[i] = int(y[1]) #start
    lift_d[i] = int(y[2]) #stop
m= int(input())#num of q
user_s=[0]*m
user_d=[0]*m
for j in range(m):
    q = input() #1 6
    z= q.split()
    user_s[j] = int(z[0]) #user
    user_d[j] = int(z[1]) #destination
lift_direction=[0]*n #up or down
for i in range(n):
    lift_direction[i]=(lift_d[i])-(lift_s[i])
user_direction=[0]*m
for i in range(m):
    user_direction[i]=(user_d[i])-(user_s[i])
list_dist=[0]*n
for j in range(m):
    dist = 0
    for i in range(n):
        if lift_direction[i] > 0 and user_direction[j] > 0: #same direction(up)
            if user_s[j] in range(lift_s[i],lift_d[i]+1)               and user_d[j] in range(lift_s[i],lift_d[i]+1):
                dist = 0
            elif user_s[j] in range(lift_s[i],lift_d[i]+1)               and user_d[j] not in range(lift_s[i],lift_d[i]+1):
                dist = abs(user_d[j]-lift_d[i])
            elif user_s[j] not in range(lift_s[i],lift_d[i]+1):
                dist = abs(user_s[j]-lift_d[i]) + abs(user_d[j]-user_s[j])
        elif lift_direction[i] < 0 and user_direction[j] < 0: #same direction(down)
            if user_s[j] in range(lift_d[i],lift_s[i]+1)               and user_d[j] in range(lift_d[i],lift_s[i]+1):
                dist = 0
            elif user_s[j] in range(lift_d[i],lift_s[i]+1)               and user_d[j] not in range(lift_d[i],lift_s[i]+1):
                dist = abs(user_d[j]-lift_d[i])
            elif user_s[j] not in range(lift_d[i],lift_s[i]+1):
                dist = abs(user_s[j]-lift_d[i])+abs(user_d[j]-user_s[j])
        elif lift_direction[i] < 0 and user_direction[j] >= 0           or lift_direction[i] >= 0 and user_direction[j] < 0: #opposite direction
            dist =  abs(lift_d[i]-user_s[j])+ abs(user_d[j]-user_s[j])
        list_dist[i] = dist
        solution=0
        for k in range(n):
            if list_dist[k] < list_dist[solution]:
                solution = k
            if list_dist[k] == list_dist[solution]:
                if lift_num[k] < lift_num[solution]:
                    solution = k
    print(">> " + str(lift_num[solution]))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632093421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.87
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 5
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 798, 'const': 289, 'code+const': 1087}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# Function
# มีไว้สำหรับหาค่าในแต่ละลิฟต์ ทีละลิฟต์ ว่าลิฟต์นั้นเสียพลังงานคิดเป็นเท่าใด
def test_per_lift(il,fl,iu,fu):
            #ทิศทางเดียวกัน				จุดเริ่ม-เรนจ์	จุดจบ-เรนจ์			ทิศเดียวกัน-ลบ					จุดเริ่ม-จบ-เรนจ์
    if ((fl-il)>0 and (fu-iu>0) and (iu>=il) and (fu<=fl)) or ((fl-il<0 and fu-iu<0) and (iu <= il) and (fu >= fl)):
        return 0
    elif ((fl-il>0) and (fu-iu>0) and (iu>=fl) and (fu>fl)) or ((fl-il<0 and fu-iu<0) and (iu <= il) and (fu < fl)):
        return abs(fl-fu)
    elif (fl-il>0 and fu-iu>0 and iu<fl and fu>fl) or (fl-il<0 and fu-iu<0 and iu <= il and fu < fl):
        return abs(fl-fu)
    else:
        return abs(fl-iu)+abs(fu-iu)
#section input
n = int(input())
lift = []
for i in range(n):
    lift.append(str(input()))
m = int(input())
user = []
for i in range(m):
    user.append(str(input()))
#Prepare Data
list_lift = []
for j in range(len(lift)):
    split_lift = lift[j].split(' ')
    int_lift = [int(n) for n in split_lift] #ยัดกล่อง ลงกล่อง
    list_lift.append(int_lift)
list_user = []
for j in range(len(user)):
    split_user = user[j].split(' ')
    int_user = [int(n) for n in split_user] #ยัดกล่อง ลงกล่อง
    list_user.append(int_user)
#function use
#เอา user เป็นหลัก
list_value_per_user = []
for m in range(len(list_user)):
    values_for_user = []
    for n in range(len(list_lift)):
        result = test_per_lift(list_lift[n][1], list_lift[n][2], list_user[m][0], list_user[m][1])
        values_for_user.append(result)
    list_value_per_user.append(values_for_user)
#เก็บค่าที่ได้จากการคำนวนพลังงาน
#หาค่า min สำหรับ list_value_per_user[p] เป็นค่าเฉพาะตัว
#หาค่า index สำหรับ min และเทียบ index ของ list_lift
#เทียบค่า index บน list_lift ที่ตำที่สุด
for p in range(len(list_user)):
    min_value = min(list_value_per_user[p])
    min_index = int()
    min_lift_index = float('inf')
    #loop หาค่าซ้ำ
    for i in range(len(list_value_per_user[p])):
        if list_value_per_user[p][i] == min_value:
            lift_id = list_lift[i][0]
            if lift_id < min_lift_index:
                min_lift_index = lift_id
                min_index = i
    if min_index != None:
        print('>>',list_lift[min_index][0])

6630061021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.96
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 628, 'const': 239, 'code+const': 867}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = int(input())
list_1 = [0]*lift
list_2 = [0]*lift
def func(whreweat,final):
    sumofall = 0
    minimum = 999e100
    hehe = 0
    for i in range(lift):
        liftstart = list_1[i]
        liftend2222 = list_2[i]
        if whreweat >= liftstart and whreweat <= liftend2222 and final >= whreweat and liftend2222 >= liftstart:
            if final > liftend2222:
                sumofall = final - liftend2222
            else:
                sumofall = 0
        elif whreweat <= liftstart and whreweat >= liftend2222 and final <= whreweat and liftend2222 <= liftstart:
            if final < liftend2222:
                sumofall = liftend2222 - final
            else:
                sumofall = 0
        elif whreweat >= liftend2222 and final >= whreweat:
            sumofall = (whreweat - liftend2222) + (final - whreweat)
        elif liftstart >= final and final >= whreweat:
            if liftend2222 > whreweat:
                sumofall = (liftend2222 - whreweat) + (final - whreweat)
            elif liftend2222 < whreweat:
                sumofall = (whreweat - liftend2222) + (final - whreweat)
        elif whreweat <= liftend2222 and final <= whreweat:
            sumofall = (liftend2222 - whreweat) + (whreweat - final)
        elif liftstart <= whreweat and whreweat >= final:
            if liftend2222 < whreweat:
                sumofall = (whreweat - liftend2222) + (whreweat - final)
            elif liftend2222 > whreweat:
                sumofall = (liftend2222 - whreweat) + (whreweat - final)
        if minimum > sumofall:
            minimum = sumofall
            hehe = i
    return hehe+1
for i in range(lift):
    x = input()
    s = x.split()
    list_1[int(s[0])-1]=int(s[1])
    list_2[int(s[0])-1]=int(s[2])
qq = int(input())
listwth = []
for i in range(qq):
    x = input().split()
    now = x[0]
    end = x[1]
    ans = func(int(now),int(end))
    listwth.append(ans)
for i in range(int(qq)):
    print(">>", listwth[i])

6631115421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.96
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 628, 'const': 239, 'code+const': 867}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = int(input())
liststart = [0]*lift
listend = [0]*lift
def func(now,end):
    sum = 0
    mini = 999e100
    ans = 0
    for i in range(lift):
        liftstart = liststart[i]
        liftend = listend[i]
        if now >= liftstart and now <= liftend and end >= now and liftend >= liftstart:
            if end > liftend:
                sum = end - liftend
            else:
                sum = 0
        elif now <= liftstart and now >= liftend and end <= now and liftend <= liftstart:
            if end < liftend:
                sum = liftend - end
            else:
                sum = 0
        elif now >= liftend and end >= now:
            sum = (now - liftend) + (end - now)
        elif liftstart >= end and end >= now:
            if liftend > now:
                sum = (liftend - now) + (end - now)
            elif eleend < now:
                sum = (now - liftend) + (end - now)
        elif now <= liftend and end <= now:
            sum = (liftend - now) + (now - end)
        elif liftstart <= now and now >= end:
            if liftend < now:
                sum = (now - liftend) + (now - end)
            elif liftend > now:
                sum = (liftend - now) + (now - end)
        #print(sum)
        if mini > sum:
            mini = sum
            ans = i
    return ans+1
for i in range(lift):
    x = input()
    s = x.split()
    liststart[int(s[0])-1]=int(s[1])
    listend[int(s[0])-1]=int(s[2])
#print(liststart[3])
question = int(input())
listtob = []
for i in range(question):
    x = input().split()
    now = x[0]
    end = x[1]
    ans = func(int(now),int(end))
    listtob.append(ans)
for i in range(int(question)):
    print(">>", listtob[i])

6631511221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.23
>> 14
>> 14
>> 14
>> 13
>> 13
>> 12
>> 12
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.92
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.96
>> 12
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 628, 'const': 239, 'code+const': 867}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = int(input())
liststart = [0]*lift
listend = [0]*lift
def func(now,end):
    sum = 0
    mini = 999e100
    ans = 0
    for i in range(lift):
        liftstart = liststart[i]
        liftend = listend[i]
        if now >= liftstart and now <= liftend and end >= now and liftend >= liftstart:
            if end > liftend:
                sum = end - liftend
            else:
                sum = 0
        elif now <= liftstart and now >= liftend and end <= now and liftend <= liftstart:
            if end < liftend:
                sum = liftend - end
            else:
                sum = 0
        elif now >= liftend and end >= now:
            sum = (now - liftend) + (end - now)
        elif liftstart >= end and end >= now:
            if liftend > now:
                sum = (liftend - now) + (end - now)
            elif eleend < now:
                sum = (now - liftend) + (end - now)
        elif now <= liftend and end <= now:
            sum = (liftend - now) + (now - end)
        elif liftstart <= now and now >= end:
            if liftend < now:
                sum = (now - liftend) + (now - end)
            elif liftend > now:
                sum = (liftend - now) + (now - end)
        #print(sum)
        if mini > sum:
            mini = sum
            ans = i
    return ans+1
for i in range(lift):
    x = input()
    s = x.split()
    liststart[int(s[0])-1]=int(s[1])
    listend[int(s[0])-1]=int(s[2])
#print(liststart[3])
question = int(input())
listtob = []
for i in range(question):
    x = input().split()
    now = x[0]
    end = x[1]
    ans = func(int(now),int(end))
    listtob.append(ans)
for i in range(int(question)):
    print(">>", listtob[i])

6632009821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.83
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
4>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 788, 'const': 96, 'code+const': 884}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
l = []
flr = []
load = []
for k in range (n):
  l.append( [int(e) for e in input().split()] )
m = int(input())
for k in range (m):
  flr.append([int(e) for e in input().split()])
  load.append([])
for i in range(len(flr)):
 for e in range(len(l)):
    if l[e][1] <=  flr[i][0] <= l[e][2]  or  l[e][1] >=  flr[i][0] >= l[e][2] : #แวะรับ
      if l[e][1] < l[e][2]: #ลิฟต์ขึ้น
       if l[e][1] <= flr[i][1] < l[e][2] and flr[i][0] < flr[i][1] :
          load[i].append([l[e][0],0])
       else:
          load[i].append([l[e][0], abs(flr[i][1] - l[e][2])])
      else:
         if l[e][1] > flr[i][1] >= l[e][2] and flr[i][0] > flr[i][1] :
            load[i].append([l[e][0],0])
         else:
            load[i].append([l[e][0], abs(flr[i][1] - l[e][2])])
    else: #ไม่แวะรับ
        load[i].append([l[e][0],abs(flr[i][0] - l[e][2]) + abs(flr[e][0] - flr[e][1])])
for m in load:
   for n in m:
      n[0],n[1] = n[1],n[0]
for m in load:
   print((min(m))[1])

6630090121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 6
>> 3
>> 3
>> 64
>> 64
>> 64
>> 54
>> 5
[]
bytecount: {'code': 696, 'const': 172, 'code+const': 868}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
import math
x=int(input())
y=[]
ev=[]
for i in range(x):
    y.append(input())
ev=[]
for i in range(len(y)):
    ev.append(list(map(int,y[i].split())))
m=int(input())
b=[]
for i in range(m):
    b.append(input())
q=[]
for i in range(len(b)):
    q.append(list(map(int,b[i].split())))
for i in range(len(q)):
    cost=[]
    eachq=q[i]
    qway_up=eachq[0]<eachq[1]
    for c in range(len(ev)):
        eachev=ev[c]
        evway_up=eachev[1]<eachev[2]
        if qway_up and evway_up:   #ขึ้นทั้งคู่
            if eachev[1]<=eachq[0] and eachev[2]>=eachq[0]:#แวะรับ
                if eachev[2]>=eachq[1]:#แวะรับแวะส่ง
                    cost.append(0)
                elif eachev[2]<eachq[1]:#แวะรับ ภาระส่ง
                    cost.append(eachq[1]-eachev[2])
            else:
                cost.append(abs(eachq[0]-eachev[2])+abs(eachq[1]-eachq[0]))
        elif qway_up==False and evway_up==False: #ลงทั้งค่
            if eachev[1]>=eachq[0] and eachev[2]<=eachq[0]: #แวะรับ
                if eachev[2]<=eachq[1]:#แวะรับแวะส่ง
                    cost.append(0)
                elif eachev[2]>eachq[1]:#แวะรับ ภาระส่ง
                    cost.append(eachq[0]-eachq[1])
            else:
                cost.append(abs(eachev[2]-eachq[0])+abs(eachq[0]-eachq[1]))
        else:
            cost.append(abs(eachq[0]-eachev[2])+abs(eachq[1]-eachq[0]))
    x=cost.index(min(cost))+1
    print(">>"+" "+str(x))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630003621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 646, 'const': 318, 'code+const': 964}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def extras(now,go,start,stop):
    if start == max(start,stop):
        wayl = 'down'
    else: wayl = 'up'
    if now == max(now,go):
        wayme='down'
    else: wayme = 'up'
    if wayme == wayl:
        extra1=abs(stop-now)
        extra2=abs(now-go)
        if now in range (min(start,stop),max(start,stop)+1):
            extra1=0
            extra2=abs(stop-go)
        if go in range (min(start,stop),max(start,stop)+1) and now in range (min(start,stop),max(start,stop)+1):
            extra2=0
    else:
        extra1=abs(stop-now)
        extra2=abs(now-go)
    return extra1+extra2
a=int(input()) #total lift no
liftlist=[]
i=0
while i<a:
    liftlist.append(input().split(' '))
    i+=1
b=int(input()) #total person question
manlist=[]
o=0
while o<b:
    manlist.append(input().split(' '))
    o+=1
mannum=0
while mannum < b:
    p=0
    while p < a:
        if p != 0:
            ex2=int(minex)
        ex1=extras(int(manlist[mannum][0]),int(manlist[mannum][1]),int(liftlist[p][1]),int(liftlist[p][2])) #return to make it ans to all que
        if p==0:
            ex2=ex1+1
        minex=min(ex1,ex2)
        p+=1
    q=0
    while q < len(liftlist):
        if extras(int(manlist[mannum][0]),int(manlist[mannum][1]),int(liftlist[q][1]),int(liftlist[q][2])) == minex:
            print(liftlist[q][0])
            break
        q+=1
    mannum+=1

6630023121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 696, 'const': 136, 'code+const': 832}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
x,y = [],[]
m = int(input())
for k in range(m):
  a = input().split()
  for i in range(len(a)):
    a[i]= int(a[i])
  x.append(a)
def distance(a,b,c,d):
  if a >= b and c >= d:
    if b <= c <= a and b <= d <=a:
      return 0
    elif b <= c <= a and d <= b:
      return abs(d-b)
    else:
      return abs(c-b)+abs(c-d)
  if a >= b and c <= d:
      return abs(c-b)+abs(c-d)
  if a <= b and c >= d:
      return abs(c-b)+abs(c-d)
  if a <= b and c <= d:
    if a <= c <= b and a <= d <= b:
      return 0
    elif a <= c <= b and d >= b:
      return abs(d-b)
    else:
      return abs(c-b)+abs(c-d)
n = int(input())
gg = []
for k in range(n):
  a = input().split()
  for i in range(len(a)):
    a[i]= int(a[i])
  y.append(a)
for g in range(n):
  uwu = y[g]
  p1,p2 = [],[]
  for r in range(m):
    owo = x[r]
    v = distance(owo[1],owo[2],uwu[0],uwu[1])
    p1.append(owo[0])
    p2.append(v)
  gg.append(p1[p2.index(min(p2))])
for i in range(len(gg)):
  print(gg[i])

6630060321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 640, 'const': 68, 'code+const': 708}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
Q_num = input()
Ele_num = []
Floor_at = []
Floor_togo = []
for i in range(int(Q_num)):
  Ele,At,Go = input().split()
  Ele_num.append(int(Ele))
  Floor_at.append(int(At))
  Floor_togo.append(int(Go))
People_num = input()
People_at = []
People_togo = []
for i in range(int(People_num)):
  at,go = input().split()
  People_at.append(int(at))
  People_togo.append(int(go))
for i in range(int(People_num)):
  duty = []
  for j in range(int(Q_num)):
    if Floor_at[j] < Floor_togo[j]:
      if People_at[i] in range(Floor_at[j],Floor_togo[j]+1):
        move_topick = 0
        if People_togo[i] in range(Floor_at[j],Floor_togo[j]+1) and People_at[i] < People_togo[i]:
          move_togo = 0
        else:
          move_togo = abs(Floor_togo[j]-People_togo[i])
      else:
        move_topick = abs(Floor_togo[j]-People_at[i])
        move_togo = abs(People_at[i]-People_togo[i])
    elif Floor_at[j] > Floor_togo[j]:
      if People_at[i] in range(Floor_togo[j],Floor_at[j]+1):
        move_topick = 0
        if People_togo[i] in range(Floor_togo[j],Floor_at[j]+1) and People_at[i] > People_togo[i]:
          move_togo = 0
        else:
          move_togo = abs(Floor_togo[j]-People_togo[i])
      else:
        move_topick = abs(Floor_togo[j]-People_at[i])
        move_togo = abs(People_at[i]-People_togo[i])
    elif Floor_at[j] == Floor_togo[j]:
      move_topick = abs(Floor_togo[j]-People_at[i])
      move_togo = abs(People_at[i]-People_togo[i])
    duty.append(move_topick+move_togo)
  print(Ele_num[duty.index(min(duty))])

6630065521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1016, 'const': 100, 'code+const': 1116}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
listn=[]
listm=[]
d1=[]
d2=[]
p=[]
n=int(input())
for i in range(1,n+1):
    x=[int(e) for e in input().split()]
    listn+=x
    d2.append(listn[3*i-3])
m=int(input())
for j in range(1,m+1):
    y=[int(e) for e in input().split()]
    listm+=y
    for i in range(1,n+1):
        if listm[2*j-1]>listm[2*j-2]:
            if listn[3*i-1]<=listm[2*j-2]:
                z=abs(listn[3*i-1]-listm[2*j-1])
                d1.append(z)
            elif  listn[3*i-2]>listm[2*j-2]:
                z=abs(listn[3*i-1]-listm[2*j-2])+abs(listm[2*j-2]-listm[2*j-1])
                d1.append(z)
            elif listn[3*i-1]<listm[2*j-1]:
                z=abs(listn[3*i-1]-listm[2*j-1])
                d1.append(z)
            else:
                z=abs(listn[3*i-1]-listm[2*j-1])
                d1.append(z)
        else:
            if listn[3*i-1]>=listm[2*j-2]:
                z=abs(listn[3*i-1]-listm[2*j-1])
                d1.append(z)
            elif listn[3*i-2]<listm[2*j-2]:
                z=abs(listn[3*i-1]-listm[2*j-2])+abs(listm[2*j-2]-listm[2*j-1])
                d1.append(z)
            elif listn[3*i-1]>listm[2*j-1]:
                z=abs(listn[3*i-1]-listm[2*j-1])
                d1.append(z)
            else:
                z=abs(listn[3*i-2]-listm[2*j-1])
                d1.append(z)
    for k in range(1,n+1):
        if d1[k-1]==min(d1):
            p.append(d2[k-1])
        else:
            pass
    #print(d1,d2)
    print(min(p))
    p.clear()
    d1.clear() ##
d2.clear() ####
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630078721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 862, 'const': 96, 'code+const': 958}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
Elevator = int(input())
x = []
y=[]
for a in range(Elevator):
  x += [input().split()]
People = int(input())
for b in range(People):
  y += [input().split()]
for i in range(People) :
    r =[]
    k = 0
    for j in range(Elevator):
     if int(x[j][1]) <= int(x[j][2]):
         if int(x[j][1]) <= int(y[i][0]) <= int(y[i][1]) <= int(x[j][2]) :
             r += [0]
         elif int(x[j][1]) <= int(y[i][0]) <= int(x[j][2])<= int(y[i][1]) :
             r += [int(y[i][1])-int(x[j][2])]
         else :
             r += [abs(int(x[j][2])-int(y[i][0]))+abs(int(y[i][0])-int(y[i][1]))]
     if int(x[j][1]) > int(x[j][2]):
         if int(x[j][1]) >= int(y[i][0]) >= int(y[i][1]) >= int(x[j][2]) :
             r += [0]
         elif int(x[j][1]) >= int(y[i][0]) >= int(x[j][2]) >= int(y[i][1]) :
             r += [abs(int(y[i][1])-int(x[j][2]))]
         else :
             r += [abs(int(x[j][2])-int(y[i][0]))+abs(int(y[i][0])-int(y[i][1]))]
    while min(r) != r[k] :
        k += 1
    print (x[k][0])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630080921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 452, 'const': 96, 'code+const': 548}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
N_of_Elevator = int(input())
Elevetors = []
for _ in range(N_of_Elevator) :
    Lifts = [int(e) for e in input().split()]
    Elevetors.append(Lifts)
goal_floor = int(input())
for _ in range(goal_floor):
    Floor_now, Floor_final = [int(e) for e  in input().split()]
    floors_on_each_elevator = []
    for Lifts in Elevetors :
        floor_used = 0
        elev_now = Lifts[1]
        elev_final = Lifts[2]
        if elev_final >= Floor_final and Floor_final >= Floor_now and Floor_now >= elev_now :
            floor_used += 0
        elif Floor_final >= elev_final and elev_final>= Floor_now and Floor_now >= elev_now :
            floor_used += abs(Floor_final - elev_final)
        elif elev_now >= Floor_now and Floor_now >= elev_final and elev_final >= Floor_final :
            floor_used += abs(Floor_final - elev_final)
        elif elev_now >= Floor_now and Floor_now >= Floor_final and Floor_final >= elev_final :
            floor_used += 0
        else :
            floor_used += abs(Floor_now - elev_final) + abs(Floor_final - Floor_now)
        floors_on_each_elevator.append(floor_used)
    floor_used_min = floors_on_each_elevator[0]
    No_Elevetors = Elevetors[0][0] 
    for i in range(len(floors_on_each_elevator)) :
        if floors_on_each_elevator[i] < floor_used_min :
            No_Elevetors = Elevetors[i][0]
            floor_used_min = floors_on_each_elevator[i]
    print(No_Elevetors)

6631010121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 368, 'const': 148, 'code+const': 516}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n_elevator = int(input())
elevators = []
for i in range(n_elevator):
    elevators.append(input().split())
    # print(elevators)
n_me = int(input())
mes = []
for i in range(n_me):
    mes.append(input().split())
for i in range(n_me):
    work = float('inf')
    elevator_id = None
    for j in range(n_elevator):
        me_current = int(mes[i][0])
        me_terminal = int(mes[i][1])
        elevator_current = int(elevators[j][1])
        elevator_terminal = int(elevators[j][2])
        # print("I am on ", me_current)
        # print("elevator on ", elevator_current, ", go to ", elevator_terminal)
        if ((elevator_current <= me_current and elevator_terminal >= me_current) or (elevator_current >= me_current and elevator_terminal <= me_current)) and ((elevator_terminal > elevator_current and me_terminal > me_current) or (elevator_current > elevator_terminal and me_current > me_terminal)):
            # print("I am on the path")
            if (elevator_current <= me_terminal and elevator_terminal >= me_terminal) or (elevator_current >= me_terminal and elevator_terminal <= me_terminal):
                calculated_work = 0
            else:
                calculated_work = abs(elevator_terminal - me_terminal)
        else:
            # print("I am out of the path")
            calculated_work = abs(elevator_terminal - me_current) + abs(me_current - me_terminal)
        # print("elevator ", elevators[j][0], " use work ", calculated_work)
        if calculated_work < work:
            work = calculated_work
            elevator_id = elevators[j][0]
    print(elevator_id)

6631022721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 784, 'const': 96, 'code+const': 880}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
a = 0
lift = []
while a < n :
    x = [int(e) for e in input().split()]
    lift.append(x)
    a += 1
m = int(input())
b = 0
while b < m :
    Base = []
    y = [int(e) for e in input().split()]
    for floor in lift :
        if floor[2]-floor[1] >= 0 and y[1]-y[0] > 0 :
            if floor[1] <= y[0] <= floor[2] :
                if floor[1] <= y[1] <= floor[2] :
                    base = 0
                else :
                    base = y[1] - floor[2]
            elif y[0] < floor[1] :
                base = (floor[2]-y[0]) + (y[1]-y[0])
            elif floor[2] < y[0] :
                base = (y[0]-floor[2]) + abs(y[1]-y[0])
        elif floor[2]-floor[1] <= 0 and y[1]-y[0] < 0 :
            if floor[2] <= y[0] <= floor[1] :
                if floor[2] <= y[1] <= floor[1] :
                    base = 0
                else :
                    base = floor[2]-y[1]
            elif y[0] < floor[2] :
                base = (floor[2] - y[0]) + (y[0]-y[1])
            elif floor[1] < y[0] :
                base = (y[0]-floor[2]) + abs(y[1]-y[0])
        else :
            base = abs(floor[2]-y[0]) + abs(y[1]-y[0])
        Base.append(base)
    NewBase = Base.copy()
    Base.sort()
    answer = Base[0]
    answer = NewBase.index(answer)
    print(lift[answer][0])
    b += 1

6631206921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 476, 'const': 96, 'code+const': 572}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
l = []
question = []
for i in range(n):
    x = [int(e) for e in input().split()]
    l.append(x)
    #x = [1, 3 ,1]
#print(list)
m = int(input())
for i in range(m):
    x = [int(e) for e in input().split()]
    question.append(x)
for lp in question:
  currentFloor = lp[0]
  destination = lp[1]
  extraWork =[]
  for e in l: # e = [1,3,1]
        if (e[1] <= currentFloor <= e[2] or e[2] <= currentFloor <= e[1]) and ((e[2] >= e[1] and destination >= currentFloor) or (e[1] >= e[2] and destination <= currentFloor)):
            if (e[1] <= destination <= e[2] or e[2] <= destination <= e[1]):
                extraWork.append(0)
            else:
                extraWork.append(abs(destination-e[2]))
        else:
            extraWork.append(abs(currentFloor - e[2])+abs(destination - currentFloor))
  mn = min(extraWork)
  ind = extraWork.index(mn)
  print(l[ind][0])

6631208121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 548, 'const': 96, 'code+const': 644}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
num1 = int(input())
list1 = []
list2 = []
for i in range(num1):
    elevator_num,initiation,destination = input().split()
    list1.append([int(elevator_num),int(initiation),int(destination)])
num2 = int(input())
for i in range(num2):
    start,end = input().split()
    list2.append([int(start),int(end)])
for i in range(num2):
    blanklist = []
    for j in range(num1):
        init = list1[j][1]
        dest = list1[j][2]
        stt = list2[i][0]
        ed = list2[i][1]
        if  ed < stt and dest < init:
            if ed >= dest:
                if stt <= init:
                    blanklist.append(0)
                else: #b>d
                    blanklist.append(abs(stt-dest)+abs(ed-stt))
            else: #a<c
                if stt <= init:
                    blanklist.append(dest-ed)
                else: #b>d
                    blanklist.append(abs(stt-dest)+abs(ed-stt))
        elif ed > stt and dest > init:
            if stt >= init:
                if ed <= dest:
                    blanklist.append(0)
                else:
                    blanklist.append(abs(ed-dest))
            else:
                if ed <= dest:
                    blanklist.append(abs(stt-dest)+abs(ed-stt))
                else:
                    blanklist.append(abs(stt-dest)+abs(ed-stt))
        else:
            blanklist.append(abs(stt-dest)+abs(ed-stt))
        index = blanklist.index(min(blanklist))
    print(list1[index][0])

6631321321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 426, 'const': 96, 'code+const': 522}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
import math
num_elevators = int(input())
elevators = []
for _ in range(num_elevators) :
    elevator = [int(e) for e in input().split()]
    elevators.append(elevator)
num_goals = int(input())
goals = []
for _ in range(num_goals) :
    goal = [int(e) for e in input().split()]
    goals.append(goal)
for goal in goals :
    min_floor_used = math.inf
    for elevator in elevators :
        floor_used = 0
        my_now = goal[0]
        my_final = goal[1]
        lift_now = elevator[1]
        lift_final = elevator[2]
        if my_final >= lift_final and lift_final >= my_now and my_now >= lift_now :
            floor_used += abs(my_final - lift_final)
        elif lift_now >= my_now and my_now >= lift_final and lift_final >= my_final:
            floor_used += abs(my_final - lift_final)
        elif lift_final >= my_final and my_final >= my_now and my_now >= lift_now :
            pass
        elif lift_now >= my_now and my_now >= my_final and my_final >= lift_final:
            pass
        else :
            floor_used += abs(my_now - lift_final)
            floor_used += abs(my_final - my_now)
        if floor_used < min_floor_used :
            no_elevator = elevator[0]
            min_floor_used = floor_used
    print(no_elevator)

6631506121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 584, 'const': 292, 'code+const': 876}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def zero():
    return 0
def maxi(l1, l2, t1, t2):
    return abs(l2-t1) + abs(t2-t1)
def mini(l1, l2, t1, t2):
    return abs(t2-l2)
def samedir(l1,l2,t1,t2):
    if(l2-l1 >= 0):
        if(t2-t1 >= 0):
            return True
        else:
            return False
    else:
        if(t2-t1 < 0):
            return True
        else:
            return False
def main(lift, task):
    scoreList = []
    t1 = task[0]
    t2 = task[1]
    for l in lift:
        l1 = l[0]
        l2 = l[1]
        if(samedir(l1,l2,t1,t2) and not(abs(l1-t1) + abs(l2-t1) == abs(l1-l2))) or (not(samedir(l1,l2,t1,t2))):
            scoreList.append(maxi(l1, l2, t1, t2))
        elif abs(l1-t2) + abs(l2-t2) == abs(l1-l2):
            scoreList.append(zero())
        else:
            scoreList.append(mini(l1, l2, t1, t2))
    return scoreList.index(min(scoreList))+1
lift = []
task = []
ans = []
for i in range(int(input())):
    temp = [ int(x) for x in input().split()]
    lift.append(temp)
lift = [ n[1:] for n in sorted(lift)]
for i in range(int(input())):
    task = [ int(x) for x in input().split()]
    ans.append(main(lift,task))
for n in ans:
    print(n)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632228921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_10.9
>> 2
>> 4
>> 1
[]
test_main_20.9
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.9
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.9
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.9
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.9
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 848, 'const': 253, 'code+const': 1101}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift_n =  int(input())
lift = ""
quation = ""
for i in range(lift_n):
  lift = str(lift) + " " + str(input())
quation_n = int(input())
for i in range(quation_n):
  quation = str(quation) + " " + str(input())
lift = lift.split()
quation = quation.split()
lift_position = []
lift_start = []
lift_final = []
quation_start = []
quation_final = []
for i in range(lift_n):
  lift_position.append(int(lift[3*i]))
for i in range(lift_n):
  lift_start.append(int(lift[3*i+1]))
for i in range(lift_n):
  lift_final.append(int(lift[3*i+2]))
for i in range(quation_n):
  quation_start.append(int(quation[2*i]))
for i in range(quation_n):
  quation_final.append(int(quation[2*i+1]))
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
for index_quation in range(quation_n):
  lift_distance = []
  quation_diff = (quation_final[index_quation] - quation_start[index_quation])
  if quation_diff < 0:
    quation_direc = 1
  elif quation_diff == 0:
    quation_direc = 0
  elif quation_diff > 0:
    quation_direc = -1
  for index_lift in range(lift_n):
    lift_diff = (lift_final[index_lift] - lift_start[index_lift])
    if lift_diff < 0:
      lift_direc = 1
    elif lift_diff == 0:
      lift_direc = 0
    elif lift_diff > 0:
      lift_direc = -1
    if (lift_start[index_lift] <= quation_start[index_quation] <= lift_final[index_lift]       or lift_final[index_lift] <= quation_start[index_quation] <= lift_start[index_lift])       and quation_direc == lift_direc       and (lift_start[index_lift] <= quation_final[index_quation] <= lift_final[index_lift]       or lift_final[index_lift] <= quation_final[index_quation] <= lift_start[index_lift]):
      lift_distance.append(int(0))
    elif (lift_start[index_lift] <= quation_start[index_quation] <= lift_final[index_lift]       or lift_final[index_lift] <= quation_start[index_quation] <= lift_start[index_lift])       and quation_direc == lift_direc:
      lift_distance.append(abs(quation_final[index_quation] - lift_final[index_lift]))
    else:
      lift_distance.append(abs(lift_final[index_lift] - quation_start[index_quation]) + abs(quation_start[index_quation] - quation_final[index_quation]))
  min_distance = min(lift_distance)
  ans_lift = lift_position[(lift_distance.index(min_distance))]
  print(ans_lift)

6630316021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.28
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 4
>> 3
>> 21
>> 26
>> 46
>> 46
>> 46
>> 3
>> 34
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 1000, 'const': 147, 'code+const': 1147}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n1 = int(input())
c1=0
l=[]
while c1<n1:
  l.append(input().split())
  c1 += 1
n2=int(input())
f=[]
c2=0
while c2 < n2 :
  f.append(input().split())
  c2+=1
for e in range(len(f)):
  f1=int(f[e][0])
  f2=int(f[e][1])
  x=[]
  for i in range(len(l)):
    l1=int(l[i][1])
    l2=int(l[i][2])
    if f2-f1 > 0 and l2-l1>0:
      if f1>l1 and l2>f2 and l2>f1:
        x.append(0)
      elif f1>l1 and f2>l2 and l2>f1:
        x.append(f2-l2)
      elif f1>l1 and f2-l2 and f1>l2:
        x.append((f1-l2)+(f2-f1))
      elif f1<l1 and f2<l2 and f2>l1:
        x.append((l2-f1)+(f2-f1))
      elif f1<l1 and f2<l1:
        x.append((l2-f1)+(f2-f1))
      elif f1<l1 and l2<f2:
        x.append((l2-f1)+(f2-f1))
      elif f1 == l1 and f2>l2:
        x.append(abs(f2-l2))
    if f2-f1<0 and l2-l1>0:
      x.append((abs(l2-f1)+abs(f2-f1)))
    if f2-f1<0 and l2-l1<0:
      if f1>l1:
        x.append((abs(l2-f1)+abs(f2-f1)))
      elif f1<l1 and l2>f2 and f1>l2:
        x.append(abs(l2-f2))
      elif f1<l1 and f1<l2:
        x.append(abs(l2-f1)+abs(f2-f1))
      elif f1<l1 and f2>l2:
        x.append(f2-f1)
      elif f1 == l1 and l2>f2:
        x.append(0)
      elif f1 == l1 and l2 <f2:
        x.append(l2-f2)
    if f2-f1>0 and l2-l1<0:
      x.append(abs(l2-f1)+abs(f2-f1))
    if l1 == l2:
      x.append(abs(l2-f1)+abs(f2-f1))
  print(">>",x.index(min(x))+1)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6531025521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 776, 'const': 147, 'code+const': 923}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
x = int(input())
n = []
for k in range(int(x)):
  a = input().split()
  n.append(a) #+=
y = int(input())
m = []
for k in range(int(y)):
  b = input().split()
  m.append(b)
for t in m:
  l = []
  for s in n:
    if int(t[1]) - int(t[0]) > 0:
      if int(s[2]) - int(s[1]) > 0:
        if int(s[1]) <= int(t[0]) <= int(s[2]):
          if int(t[1]) <= int(s[2]):
            l += [0]
          else:
            l += [abs(int(t[1]) - int(s[2]))]
        else:
          l += [abs(int(s[2]) - int(t[0])) + abs(int(t[1]) - int(t[0]))]
      else:
        l += [abs(int(s[2]) - int(t[0])) + abs(int(t[1]) - int(t[0]))]
    elif int(t[1]) - int(t[0]) < 0:
      if int(s[2]) - int(s[1]) < 0:
        if int(s[1]) >= int(t[0]) >= int(s[2]):
          if int(t[1]) >= int(s[2]):
            l += [0]
          else:
            l += [abs(int(t[1]) - int(s[2]))]
        else:
          l += [abs(int(s[2]) - int(t[0])) + abs(int(t[1]) - int(t[0]))]
      else:
        l += [abs(int(s[2]) - int(t[0])) + abs(int(t[1]) - int(t[0]))]
  print('>>',l.index(min(l))+ 1)

6531503121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 464, 'const': 175, 'code+const': 639}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
label = [0] * n
start = [0] * n
end = [0] * n
for i in range(n) :
    a, b, c = input().split()
    label[i] = int(a)
    start[i] = int(b)
    end[i] = int(c)
m = int(input())
for i in range(m) :
    x, y = input().split()
    x = int(x); y = int(y)
    best_lift = -1; min_load = 1000000
    for j in range(n) :
        if (start[j] <= end[j] and x <= y and start[j] <= x and y <= end[j]) or (start[j] >= end[j] and x >= y and start[j] >= x and y >= end[j]) :
            if min_load > 0 :
                min_load = 0; best_lift = j
        elif min(start[j], end[j]) <= x and x <= max(start[j], end[j]) :
            if min_load > abs(end[j] - y) :
                min_load = abs(end[j] - y); best_lift = j
        else :
            if min_load > abs(end[j] - x) + abs(x - y) :
                min_load = abs(end[j] - x) + abs(x - y); best_lift = j
    print(">>", best_lift + 1)

6532030821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 724, 'const': 175, 'code+const': 899}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
number_of_elevators = int(input().strip())
start_floor = []
stop_floor = []
for i in range(number_of_elevators):
  a = input().strip().split()
  start_floor.append(a[1])
  stop_floor.append(a[2])
number_of_request = int(input().strip())
start_request = []
stop_request = []
for i in range(number_of_request):
  a = input().strip().split()
  start_request.append(a[0])
  stop_request.append(a[1])
list_of_answer = []
for a in range(number_of_request):
    list_of_elevators = []
    for i in range(number_of_elevators):
        ref = int(start_floor[i]) - int(stop_floor[i])
        want = int(start_request[a]) - int(stop_request[a])
        check = [ref, want]
        finish = []
        for r in check:
            if abs(r) == r:
                fin = 1
                if r == 0:
                    fin = 0
            else:
                fin = -1
            finish.append(fin)
        if finish[0] == finish[1] != 0:
            if finish[0] == 1:
                work = abs(int(start_request[a]) - int(stop_floor[i])) + abs(want)
                if int(start_request[a]) <= int(start_floor[i]):
                    work = abs(int(stop_request[a]) - int(stop_floor[i]))
                    if int(stop_request[a]) > int(stop_floor[i]):
                        work = 0
            if finish[1] == -1:
                work = abs(int(start_request[a]) - int(stop_floor[i])) + abs(want)
                if int(start_request[a]) >= int(start_floor[i]):
                    work = abs(int(stop_request[a]) - int(stop_floor[i]))
                    if int(stop_request[a]) < int(stop_floor[i]):
                        work = 0
        else:
            work = abs(int(start_request[a]) - int(stop_floor[i])) + abs(want)
        list_of_elevators.append([abs(work), i+1])
    list_of_elevators.sort()
    list_of_answer.append(list_of_elevators[0][1])
for i in range(number_of_request):
    print('>>', list_of_answer[i])

6630004221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>>1 2
>>2 1
>>2 1
>>2 1
>>2 1
>>2 1
>> 3
>> 3
>> 3
>> 3
>> 3
>>2 1
>>4 6
>>4 6
>>4 6
>>4 6
>> 3
>>6 4
>>6 4
>>6 4
>>6 4
>> 5
[]
bytecount: {'code': 648, 'const': 420, 'code+const': 1068}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
#ประกาศlists
lift = []
go = []
#รับn แล้วเก็บข้อมูลในlists
n = int(input(''))
for x in range(n):
    liftforx = input('').split()
    lift.append(liftforx[0])
    lift.append(int(liftforx[1]))
    lift.append(int(liftforx[2]))
#รับm แล้วเก็บข้อมูลในlists
m = int(input(''))
for x in range(m):
    goforx = input('').split()
    go.append(str(x+1))
    go.append(int(goforx[0]))
    go.append(int(goforx[1]))
#
for i in range(m):#each Question
    question_no = go[3*i]
    c = go[3*i+1]
    d = go[3*i+2]
    e_lists = [] #[0, 4, 5, 7]
    for l in range(n):#each Elevator
        lift_no = lift[3*l]
        a = lift[3*l+1]
        b = lift[3*l+2]
        e = -999
        #ขึ้น
        if ((c-d)<0):
            #ผ่าน
            if (((a-b)<0) and (a<=c<=b)):
                #เลย => ไม่เลยหรือพอดี
                if ((d-b)>0):
                    e = d-b
                #ไม่เลยหรือพอดี => เลย
                elif ((d-b)<=0):
                    e = 0
            #ไม่ผ่าน
            else:
                e = abs(c-b) + (d-c)
        #ลง
        elif ((c-d)>0):
            #ผ่าน
            if (((a-b)>0) and (a>=c>=b)):
                #เลย => ไม่เลยหรือพอดี
                if ((b-d)>0):
                    e = b-d
                #ไม่เลยหรือพอดี => เลย
                elif ((b-d)<=0):
                    e = 0
            #ไม่ผ่าน
            else:
                e = abs(c-b) + (c-d)
        #ไม่ไป
        elif ((c-d)==0):
            print("อย่ากดลิฟต์เล่นครับประหยัดไฟหน่อย")
        #ใส่eไปในlists
        e_lists.append(e)
    #e_lists
    min_e = min(e_lists)
    min_position = -1
    for i in range(len(e_lists)):
        if min_e == e_lists[i]:
            min_position = i
            break
    bestlift = min_position + 1
    print(">>"+str(bestlift))

6630047221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
INPUT
OUTPUT
>> 2
>> 4
>> 1
[]
test_main_21.0
INPUT
OUTPUT
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
INPUT
OUTPUT
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
INPUT
OUTPUT
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
INPUT
OUTPUT
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
INPUT
OUTPUT
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
INPUT
OUTPUT
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
INPUT
OUTPUT
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 834, 'const': 790, 'code+const': 1624}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def optimize_lift(lno,x1,x2,y1,y2):
    if x1>x2: # Lift Down
        if y1 > y2: # Down, Down
            if y1 <= x1 and y1 >= x2: # Between Down
                if y2 < x2: # to Floor
                    x3 = abs(x2-y2)
                else:
                    x3 = 0
            else:
                x3 = abs(x2-y1)+abs(y1-y2)
        else:
            x3 = abs(x2-y1)+abs(y1-y2)
    else: # Lift Up
        if y1 > y2: # Up, Down
            x3 = abs(x2-y1)+abs(y1-y2)
        else:
            if y1 >= x1 and y1 <= x2: # Between up
                if y2 > x2: # to Celling
                    x3 = abs(x2-y2)
                else:
                    x3 = 0
            else:
                x3 = abs(x2-y1)+abs(y1-y2)
    return x3
print("INPUT")
n = int(input())
n_lift = []
for _ in range(n):
    n_lift.append(input())
n_a = [item.split(' ', 1)[0] for item in n_lift]
n_b = [item.split(' ', 2)[1] for item in n_lift]
n_c = [item.split(' ', 3)[2] for item in n_lift]
ln = [int(x) for x in n_a]
x1 = [int(x) for x in n_b]
x2 = [int(x) for x in n_c]
m = int(input())
m_lift = []
for _ in range(m):
    m_lift.append(input())
m_a = [item.split(' ', 1)[0] for item in m_lift]
m_b = [item.split(' ', 2)[1] for item in m_lift]
y1 = [int(x) for x in m_a]
y2 = [int(x) for x in m_b]
opt_lift = []
i = 0
j = 0
print("OUTPUT")
for j in range(m):
    for i in range(n):
        opt_lift.append(optimize_lift(ln[i],x1[i],x2[i],y1[j],y2[j]))
    else:
        min_opt_lift = min(opt_lift)
        print(">>",opt_lift.index(min_opt_lift)+1)
        opt_lift = []

6630230721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
[['1', '3', '1'], ['2', '1', '8'], ['3', '2', '2'], ['4', '12', '3']]
[['5', '9'], ['6', '2'], ['3', '2']]
>> 2
>> 4
>> 1
[]
test_main_21.0
[['1', '3', '1'], ['2', '2', '8'], ['3', '10', '10'], ['4', '12', '6']]
[['1', '6'], ['8', '12'], ['11', '15'], ['4', '1']]
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
[['1', '2', '2'], ['2', '4', '4'], ['3', '6', '6'], ['4', '8', '8']]
[['1', '3'], ['2', '4'], ['3', '5'], ['4', '6'], ['5', '7'], ['6', '8'], ['7', '9'], ['8', '10'], ['9', '11']]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
[['1', '8', '11'], ['2', '6', '9'], ['3', '4', '7'], ['4', '2', '5']]
[['1', '12'], ['2', '12'], ['3', '12'], ['4', '12'], ['5', '12'], ['6', '12'], ['7', '12'], ['8', '12'], ['9', '12']]
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
[['1', '6', '2'], ['2', '8', '4'], ['3', '12', '8'], ['4', '10', '6']]
[['13', '1'], ['12', '1'], ['11', '1'], ['10', '1'], ['9', '1'], ['8', '1'], ['7', '1'], ['6', '1'], ['5', '1'], ['4', '1'], ['3', '1'], ['2', '1']]
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
[['1', '8', '11'], ['2', '6', '9'], ['3', '4', '7'], ['4', '2', '5']]
[['12', '1'], ['11', '1'], ['10', '1'], ['9', '1'], ['8', '1'], ['7', '1'], ['6', '1'], ['5', '1'], ['4', '1'], ['3', '1'], ['2', '1']]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
[['1', '6', '2'], ['2', '8', '4'], ['3', '12', '8'], ['4', '10', '6']]
[['1', '13'], ['2', '13'], ['3', '13'], ['4', '13'], ['5', '13'], ['6', '13'], ['7', '13'], ['8', '13'], ['9', '13'], ['10', '13'], ['11', '13'], ['12', '13']]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
[['2', '5', '2'], ['1', '2', '5'], ['3', '7', '10'], ['6', '10', '7'], ['5', '12', '15'], ['4', '15', '12']]
[['1', '6'], ['2', '7'], ['3', '8'], ['4', '9'], ['5', '10'], ['6', '11'], ['7', '12'], ['8', '13'], ['9', '14'], ['10', '15'], ['11', '16'], ['6', '1'], ['7', '2'], ['8', '3'], ['9', '4'], ['10', '5'], ['11', '6'], ['12', '7'], ['13', '8'], ['14', '9'], ['15', '10'], ['16', '11']]
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 524, 'const': 266, 'code+const': 790}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def find_lowest (lst):
    lowest = min(lst)
    counter = 0
    for i in lst:
        if i == lowest:
            counter += 1
            return counter
        counter += 1
x = int(input())
elevator = []
for y in range(x):
  i = input()
  elevator += [i.split(" ")]
print(elevator)
x2 = int(input())
human = []
for y2 in range(x2):
  i2 = input()
  human += [i2.split(" ")]
print(human)
for h1 in range(x2):
  human1, human2 = int(human[h1][0]), int(human[h1][1])
  elevator_score = []
  for e1 in range(x):
    ele1, ele2 = int(elevator[e1][1]), int(elevator[e1][2])
    if (ele1 >= ele2 and human1 >= human2) or (ele1 <= ele2 and human1 <= human2)  :
      if ele1 <= human1 <= ele2 and ele1 <= human2 <= ele2:
        elevator_score +=[0]
      elif (ele1 >= human1 >= ele2) or  (ele1 <= human1 <= ele2) :
        elevator_score += [abs(ele2 - human2)]
      else :
        elevator_score +=[abs(ele2-human1) + abs(human2-human1)]
    else: elevator_score += [abs(ele2 - human1) + abs(human2 - human1)]
  print(f'>> {find_lowest(elevator_score)}')

6630328621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 494, 'const': 265, 'code+const': 759}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
l=int(input())
x1=[]
x2=[]
for i in range (l):
    n = input().split()
    x1.append(int(n[1]))
    x2.append(int(n[2]))
k=int(input())
y1=[]
y2=[]
for j in range (k):
    m = input().split(' ')
    y1.append(int(m[0]))
    y2.append(int(m[1]))
def parha(a,b):
  s=0
  list_s=[]
  minl=0
  for j in range (l):
    if (x1[j] <= a <= b <= x2[j]) or (x1[j] >= a >= b >= x2[j]) :
      s = 0
    elif (x1[j] <= a <= x2[j] <= b) or (x1[j] >= a >= x2[j] >= b):
      s = abs(b-x2[j])
    else :
      s = abs(x2[j]-a)+ abs(a-b)
    list_s.append(s)
  minl=int(list_s.index(min(list_s)))+1
  return print(">>",minl)
for c in range(k):
  parha(y1[c],y2[c])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631003821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 4
>> 4
>>4 3
>> 3
>>3 2
>> 2
>>2 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>>3 4
>>3 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.82
>> 2
>>2 1
>> 1
>> 1
>> 1
>> 1
>>6 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>>3 6
>> 3
>> 4
>> 4
>> 4
>>5 4
>> 5
[]
bytecount: {'code': 1856, 'const': 286, 'code+const': 2142}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
import math
def get_workload(curuse, desuse, curlift, deslift):
    if curuse <= desuse <= curlift <= deslift :
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curuse <= desuse <= deslift <= curlift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curuse <= curlift <= desuse <= deslift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curuse <= curlift <= deslift <= desuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curuse <= deslift <= desuse <= curlift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curuse <= deslift <= curlift <= desuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif desuse <= curuse <= curlift <= deslift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif desuse <= curuse <= deslift <= curlift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif desuse <= curlift <= curuse <= deslift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif desuse <= curlift <= deslift <= curuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)#
    elif desuse <= deslift <= curuse <= curlift:
        workload = abs(desuse-curuse)#
    elif desuse <= deslift <= curlift <= curuse:
        workload = abs(deslift-curuse) + abs(desuse-curuse)
    elif curlift <= curuse <= desuse <= deslift:
        workload = 0
    elif curlift <= curuse <= deslift <= desuse:
        workload = abs(desuse-curuse)
    elif curlift <= desuse <= curuse <= deslift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curlift <= desuse <= deslift <= curuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curlift <= deslift <= curuse <= desuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif curlift <= deslift <= desuse <= curuse:
        workload = abs(deslift - curuse) + abs(curuse-desuse)
    elif deslift <= curuse <= desuse <= curlift:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif deslift <= curuse <= curlift <= desuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif deslift <= desuse <= curuse <= curlift:
        workload = 0
    elif deslift <= desuse <= curlift <= curuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif deslift <= curlift <= curuse <= desuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    elif deslift <= curlift <= desuse <= curuse:
        workload = abs(deslift - curuse) + abs(desuse-curuse)
    return workload
def main():
    n = int(input())
    liftdata = []
    for _ in range (n):
        liftid, curlift, deslift = [int(e) for e in input().split()]
        liftdata.append([liftid, curlift, deslift])
    m = int(input())
    usedata = []
    for _ in range (m):
        curuse, desuse = [int(e) for e in input().split()]
        usedata.append([curuse, desuse])
    for e in usedata :
        curuser,desuser = e
        for i,ee in enumerate(liftdata) :
            workload = get_workload(curuser,desuser,ee[1],ee[2])
            if i==0 :
                minwork = workload
                lift_to_use = ee[0]
            else :
                if workload < minwork :
                    minwork = workload
                    lift_to_use = ee[0]
        print('>>%d'%lift_to_use)
if __name__ == '__main__' :
    main()
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631106821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>  2
>>  4
>>  1
[]
test_main_21.0
>>  1
>>  2
>>  3
>>  4
[]
test_main_31.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
[]
test_main_41.0
>>  4
>>  4
>>  4
>>  3
>>  3
>>  2
>>  2
>>  1
>>  1
[]
test_main_51.0
>>  3
>>  3
>>  3
>>  4
>>  4
>>  2
>>  2
>>  1
>>  1
>>  1
>>  1
>>  1
[]
test_main_61.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
>>  4
>>  4
[]
test_main_71.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  4
>>  3
>>  3
>>  3
>>  3
>>  3
>>  3
[]
test_main_80.32
>> 2
>> 1
>>  2
>>  21
>>  21
>>  21
>>  21
>>  3
>>  3
>>  3
>>  3
>>  3
>>  21
>>  46
>>  46
>>  46
>>  46
>>  3
>>  64
>>  64
>>  64
>>  64
>>  5
[]
bytecount: {'code': 930, 'const': 148, 'code+const': 1078}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = []
x = []
c = []
result = []
for i in range (n):
    a = input()
    templist =[]
    templist += a.split()
    for p in range (len(templist)):
        templist[p] = int(templist[p])
    lift.append(templist)
y = int(input())
for i in range (y):
    a = input()
    templist=[]
    templist += a.split()
    for p in range (len(templist)):
        templist[p] = int(templist[p])
    x.append(templist)
for i in range (y):
    for j in range (n):
        if (lift[j][2] - lift[j][1] > 0):
            if (x[i][1] - x[i][0] > 0):
                if(x[i][0] >= lift[j][1]):
                    if (x[i][1] <= lift[j][2]):
                        c.append(0)
                    else: c.append(x[i][1] - lift[j][2])
                else: c.append((lift[j][2]-x[i][0])+(x[i][1]-x[i][0]))
            else: c.append(abs(lift[j][2]-x[i][0])+(x[i][0]-x[i][1]))
        elif (lift[j][2] - lift[j][1] < 0):
            if(x[i][1] - x[i][0] < 0):
                if(lift[j][1] >= x[i][0]):
                    if(lift[j][2]<=x[i][1]):
                        c.append(0)
                    else: c.append(lift[j][2]-x[i][1])
                else: c.append((x[i][0]-lift[j][2])+(x[i][0]-x[i][1]))
            else: c.append(abs(lift[j][2]-x[i][0])+(x[i][1]-x[i][0]))
        elif (lift[j][2] == lift[j][1]):
            temp = abs(lift[j][2] - x[i][0])
            temp += abs(x[i][0]-x[i][1])
            c.append(temp)
    low = min(c)
    result.append(c.index(low)+1)
    c = []
for i in range (len(result)):
    print(">> ",result[i])

6631219021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 998, 'const': 197, 'code+const': 1195}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
A = []
for i in range(n) :
  E = input().split(' ')
  for j in E :
   j = int(j)
  A.append(E)
m = int(input())
B = []
for i in range(m) :
  E = input().split(' ')
  for j in E:
    j = int(j)
  B.append(E)
for i in range(0,len(B)) :
  q = B[i]
  m = []
  for j in range(0,len(A)) :
    l = A[j]
    if int( A[j][1] ) > int( A[j][2] ) and int( B[i][0] ) > int( B[i][1] ) :
      if int( A[j][1] ) >= int( B[i][0] ) and int( A[j][2] ) >= int( B[i][1] ) :
        t = abs( int( A[j][2]) - int( B[i][1]) )
        m.append(t)
      elif int( A[j][1] ) >= int( B[i][0] ) and int( A[j][2] ) <= int( B[i][1] ) :
        m.append(0)
      else :
        t = abs( int(B[i][0]) - int(A[j][2]) ) + abs( int(B[i][1]) - int(B[i][0]) )
        m.append(t)
    elif int( A[j][1] ) < int( A[j][2] ) and int( B[i][0] ) < int( B[i][1] ) :
      if int( A[j][1] ) <= int( B[i][0] ) and int( A[j][2] )  <= int( B[i][1] ) :
        t = abs( int( A[j][2] ) - int( B[i][1] ) )
        m.append(t)
      elif int( A[j][1] ) <= int( B[i][0] ) and int( A[j][2] ) >= int( B[i][1] ) :
        m.append(0)
      else :
        t = abs( int(B[i][0]) - int(A[j][2]) ) + abs( int( B[i][1] ) - int( B[i][0] ) )
        m.append(t)
    else :
      t = abs( int( B[i][0] ) - int( A[j][2] ) ) + abs( int( B[i][1] ) - int( B[i][0] ) )
      m.append(t)
  print( '>>' , m.index(min(m)) + 1 )
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631456421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 842, 'const': 199, 'code+const': 1041}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input(''))
i = 0
elevator = []
while i < n:
    a = input('')
    elevator.append(a)
    i += 1
work = []
for item in elevator:
    level = item.split()
    start = level[1]
    finish = level[2]
    work.append(start)
    work.append(finish)
m = int(input(''))
i = 0
user = []
while i < m:
    a = input('')
    user.append(a)
    i += 1
order = []
for item in user:
    goal = item.split()
    now = goal[0]
    end = goal[1]
    order.append(now)
    order.append(end)
i = 0
j = 0
for i in range(m):
  now = None
  ans = 0
  for j in range(n):
      if( int(work[j*2]) <= int(order[i*2]) < int(work[j*2+1]) and int(order[i*2]) < int(order[i*2+1])):
        a = int(order[i*2+1]) - int(work[j*2+1])
      elif( int(work[j*2]) >= int(order[i*2]) > int(work[j*2+1]) and int(order[i*2]) > int(order[i*2+1])):
        a = int(work[j*2+1]) - int(order[i*2+1])
      elif((int(order[i*2+1])) > (int(order[i*2]))):
        a = abs(int(order[i*2]) - int(work[j*2+1])) + abs(int(order[i*2+1]) - int(order[i*2]) )
      else:
        a = abs(int(order[i*2]) - int(work[j*2+1])) + abs(int(order[i*2]) - int(order[i*2+1]) )
      if(now is None or a < now):
        now = a
        ans = j
      j+=1
  i+=1
  print(f'>> {ans+1}')

6631530121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>  2
>>  4
>>  1
[]
test_main_21.0
>>  1
>>  2
>>  3
>>  4
[]
test_main_31.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
[]
test_main_41.0
>>  4
>>  4
>>  4
>>  3
>>  3
>>  2
>>  2
>>  1
>>  1
[]
test_main_51.0
>>  3
>>  3
>>  3
>>  4
>>  4
>>  2
>>  2
>>  1
>>  1
>>  1
>>  1
>>  1
[]
test_main_61.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
>>  4
>>  4
[]
test_main_71.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  4
>>  3
>>  3
>>  3
>>  3
>>  3
>>  3
[]
test_main_80.32
>> 2
>> 1
>>  2
>>  21
>>  21
>>  21
>>  21
>>  3
>>  3
>>  3
>>  3
>>  3
>>  21
>>  46
>>  46
>>  46
>>  46
>>  3
>>  64
>>  64
>>  64
>>  64
>>  5
[]
bytecount: {'code': 1708, 'const': 216, 'code+const': 1924}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def main():
  #number of lift
  lift_num = int(input())
  #list of lift order, present floor, destination floor
  num = []
  pre = []
  des = []
  #data of each lift
  for i in range(lift_num):
    order, present, destination = [int (e) for e in input(). split()]
    pre += [present]
    des += [destination]
  #number of question
  question_num = int(input())
  #list of lives and wants
  live = []
  want = []
  #data of each question
  for i in range(question_num):
    lives, wants = [int(e) for e in input().split()]
    live += [lives]
    want += [wants]
  for ques in range(question_num):
    bur = [] #burden list
    for lift in range(lift_num):
      list_numbers = [pre[lift], des[lift]]
      #ผ่านชั้นที่อยู่
      if find_min(list_numbers) <= live[ques] <= find_max(list_numbers):
        #same floor
        if pre[lift] == des[lift]:
          if pre[lift] == live[ques]:
            burden = abs(want[ques]-live[ques])
            bur += [burden]
          else:
            burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
            bur += [burden]
        #not same floor
        else:
          if pre[lift] < want[ques] < des[lift]:
            if pre[lift] < des[lift]: #up
              if want[ques] > live[ques]:
                burden = abs(want[ques]-live[ques])
                bur += [burden]
              elif want[ques] < live[ques]:
                burden = abs(live[ques]-des[lift])+abs(live[ques]-want[ques])
                bur += [burden]
            elif pre[lift] > des[lift]: #down
               if want[ques] < live[ques]:
                 burden = abs(live[ques]-want[ques])+abs(des[lift]-want[ques])
                 bur += [burden]
          else:
            burden = abs(des[lift]-want[ques])
            bur += [burden]
      #ไม่ผ่านชั้นที่อยู่
      else:
        #same floor
        if pre[lift] == des[lift]:
          if des[lift] - live[ques] < 0: #up
            if want[ques] - live[ques] < 0: #down
              burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
              bur += [burden]
            else:
              burden = abs(des[lift]-want[ques])
              bur += [burden]
          elif des[lift] - live[ques] > 0: #down
            if want[ques] - live[ques] > 0: #up
              burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
              bur += [burden]
            else:
              burden = abs(des[lift]-want[ques])
              bur += [burden]
        #low to high
        elif pre[lift] < des[lift]: #up
          if des[lift] - live[ques] < 0: #up
            if want[ques] - live[ques] < 0: #down
              burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
              bur += [burden]
            else:
              burden = abs(des[lift]-want[ques])
              bur += [burden]
          elif des[lift] - live[ques] > 0: #down
            if want[ques] - live[ques] > 0: #up
              burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
              bur += [burden]
            else:
              burden = abs(des[lift]-want[ques])
              bur += [burden]
        #high to low
        elif pre[lift] > des[lift]: #down
          if des[lift] - live[ques] < 0: #up
            if want[ques] - live[ques] < 0: #down
              burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
              bur += [burden]
            else:
              burden = abs(des[lift]-want[ques])
              bur += [burden]
          elif des[lift] - live[ques] > 0: #down
            if want[ques] - live[ques] > 0: #up
              burden = abs(des[lift]-live[ques])+abs(live[ques]-want[ques])
              bur += [burden]
            else:
              burden = abs(des[lift]-want[ques])
              bur += [burden]
          elif des[lift] == live[ques]: #same floor
            burden = abs(des[lift]-want[ques])
            bur += [burden]
    index = bur.index(find_min(bur)) + 1
    print(">> ", index)
def find_max(list):
  max = list[0]
  for i in list:
    if i > max:
      max = i
  return max
def find_min(list):
  min = list[0]
  for i in list:
    if i < min:
      min = i
  return min
main()

6631545621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 698, 'const': 199, 'code+const': 897}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift_list = []
lifti_list = []
liftf_list = []
istay_list = []
igo_list = []
cal = []
for _ in range(n):
    lift_no, lift_i, lift_f = input().split()
    lift_no = int(lift_no)
    lift_i = int(lift_i)
    lift_f = int(lift_f)
    lift_list = lift_list + [(lift_no,lift_i,lift_f)]
m = int(input())
for _ in range(m):
    istay, igo = input().split()
    istay = int(istay)
    igo = int(igo)
    istay_list = istay_list + [istay]
    igo_list = igo_list + [igo]
for i in range(1,m+1):
    bestlift = float("inf")
    cal = [0] * n
    for j in range(1,n+1):
        lift_info = lift_list[j-1]
        lift_no = lift_info[0]
        lift_i = lift_info[1]
        lift_f = lift_info[2]
        if lift_i > lift_f:
            if lift_f <= istay_list[i-1] <= lift_i:
                cal[j-1] = abs(igo_list[i-1] - lift_f)
            else:
                cal[j-1] = abs(istay_list[i-1] - lift_f) + abs(igo_list[i-1] - istay_list[i-1])
            bestlift = min(bestlift, cal[j-1])
        elif lift_i < lift_f:
            if lift_i <= istay_list[i - 1] <= lift_f:
                cal[j-1] = abs(igo_list[i-1] - lift_f)
            else:
                cal[j-1] = abs(istay_list[i-1] - lift_f) + abs(igo_list[i-1] - istay_list[i-1])
            bestlift = min(bestlift, cal[j-1])
        else:
            cal[j-1] = abs(istay_list[i-1] - lift_f) + abs(igo_list[i-1] - istay_list[i-1])
            bestlift = min(bestlift, cal[j-1])
    for j in range(1,n+1):
        if bestlift == cal[j-1]:
            print('>>', j)
            break

6631805821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 1774, 'const': 175, 'code+const': 1949}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
nl = 1
lift = [int(e) for e in input().split()]
while nl in range(n) :
  nl += 1
  lift += [int(e) for e in input().split()]
lift_num = (lift[::3])
start_floor = (lift[1::3])
end_floor = (lift[2::3])
m = int(input())
nrq=1
request = [int(e) for e in input().split()]
while nrq in range(m) :
  nrq += 1
  request += [int(e) for e in input().split()]
start = (request[::2])
end = (request[1::2])
ans = []
loop = 1
while loop in range(m+1) :
  round = 1
  while round in range(n+1) :
    x = start_floor[int(round)-1]
    y = end_floor[int(round)-1]
    s = start[int(loop)-1]
    f = end[int(loop)-1]
    if x == y :
      if s >= y and f > s :
        d = abs(f-y)
      if s <= y and f < s :
        d = abs(f-y)
      if s <= y and f > y :
        d = abs(s-y) + abs(f-s)
      if s >= y and f < y :
        d = abs(s-y) + abs(f-s)
    if y < x :
      if f < y and s in range(y,x+1) :
        d = abs(f-y)
      if f < y and s > x :
        d = abs(s-y) + abs(f-s)
      if s and f in range(y,x+1) and s > f :
        d = 0
      if s and f in range(y,x+1) and f > s :
        d = abs(f-y)
      if f > x and s < y :
        d = abs(s-y) + abs(f-s)
      if s < y :
        d = abs(y-s) + abs(f-s)
      if f > x and s in range(y,x+1) :
        d = abs(f-min(x,y,s))
      if s and f > x and f > s :
        d = abs(f-y)
      if s and f > x and f < s :
        d = abs(s-y) + abs(f-s)
      if s > x :
        d = abs(s-y) + abs(f-s)
      if s <= y and f > s :
        d = abs(s-y) + abs(f-s)
    if y > x :
      if f > y and s in range(x,y+1) :
        d = abs(f-y)
      if f > y and s < x :
        d = abs(s-y) + abs(f-s)
      if s and f in range(x,y+1) and f > s :
        d = 0
      if s and f in range(x,y+1) and f < s :
        d = abs(f-y)
      if f < x and s > y :
        d = abs(s-y) + abs(f-s)
      if f < x and s in range(x,y+1) :
        d = abs(f-max(x,y,s))
      if s < x and f in range(x,y+1) :
        d = abs(max(x,y,f)-s) + abs(f-s)
      if s and f > y and f > s :
        d = abs(f-y)
      if s and f > y and f < s :
        d = abs(s-y) + abs(f-s)
      if s < x and f > y :
        d = abs(s-y) + abs(f-s)
      if s >= y and f < s :
        d = abs(s-y) + abs(f-s)
      if s < x and f < s :
        d = abs(f-y)
    ans.append(d)
    round += 1
  loop += 1
loop2 = 0
while loop2 < m*n :
  w = min(ans[loop2:loop2+n])
  print(">>",int(ans[loop2:loop2+n].index(w))+1)
  loop2 += n

6632153421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 478, 'const': 203, 'code+const': 681}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def createlist(i,j):
    lis = []
    m1 = min(i,j)
    m2 = max(i,j)
    while m1 < m2 + 1:
        lis.append(m1)
        m1 += 1
    return lis
def dis(i, f, s, d):
    r = createlist(i,f)
    if s in r and (i-f)*(s-d) > 0:
        if d in r:
            dis = 0
        else:
            dis = abs(d-f)
    else:
        dis = abs(f-s) + abs(d-s)
    return dis
n_el = int(input())
el = []
for i in range(n_el):
    no, i, j = input().split()
    el.append([int(i), int(j)])
n_pas = int(input())
el_dis = {}
path = []
for i in range(n_pas):
    d = [int(e) for e in input().split()]
    n = 1
    for i in el:
        distance = dis(i[0], i[1], d[0], d[1])
        el_dis[n] = distance
        n += 1
    m = min(list(el_dis.values()))
    sp = list(el_dis.keys())[list(el_dis.values()).index(m)]
    path.append(sp)
for i in range(n_pas):
    print('>>', int(path[i]))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632217021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
number_of_lifts
number_of_quest
>> 2
>> 4
>> 1
[]
test_main_21.0
number_of_lifts
number_of_quest
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
number_of_lifts
number_of_quest
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
number_of_lifts
number_of_quest
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
number_of_lifts
number_of_quest
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
number_of_lifts
number_of_quest
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
number_of_lifts
number_of_quest
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
number_of_lifts
number_of_quest
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 820, 'const': 315, 'code+const': 1135}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
import math
print("number_of_lifts")
number_of_lifts = int(input()) #ถามจน.ลิฟต์
lifts = []
for _ in range(number_of_lifts):
    lifts.append([int(i) for i in input().split()])
print("number_of_quest")
number_of_quest = int(input()) #ถามหาจน.คำถาม
quest = []
for _ in range(number_of_quest):
    quest.append([int(i) for i in input().split()])
def find() :
  for q in range(number_of_quest):
      lift_works = []
      mini_quest = quest[q]
      mini_quest_from = mini_quest[0]
      mini_quest_to = mini_quest[1]
      for n in range(number_of_lifts):
          lift = lifts[n]
          lift_number = lift[0]
          lift_form = lift[1]
          lift_goto = lift[2]
          if mini_quest_to >= mini_quest_from: #ถ้าปลายทางมากกว่าต้นทาง (ขึ้น)
              if lift_goto >= lift_form: #และถ้าเส้นเดินลิฟต์ขึ้น
                  if lift_form <= mini_quest_from <= lift_goto: #และถ้าอยู่ระหว่างเส้นทางลิฟต์
                      if mini_quest_to <= lift_goto: #ถ้าปลายทางไม่สุดเส้นทางเดิน
                          lift_works.append( 0 )
                      else: #แต่ถ้าปลายทางเกินเส้นทาง
                          lift_works.append(abs(int(mini_quest_to)-int(lift_goto)))
                  else: #ไม่อยู่ในเส้นทางเดินของลิฟต์
                      lift_works.append(abs(int(mini_quest_from)-int(lift_goto)) + abs(int(mini_quest_to)-int(mini_quest_from)))
              elif lift_form>=lift_goto: #ถ้าเส้นเดินลิฟต์ลง
                  if lift_goto <= mini_quest_from <= lift_form: #แต่ถ้าขึ้นระหว่างทางเดินลง
                      lift_works.append(abs(int(mini_quest_to)-int(lift_goto)))
                  else: #ไม่อยู่ในเส้นทางเดินของลิฟต์
                      lift_works.append(abs(int(mini_quest_from)-int(lift_goto)) + abs(int(mini_quest_to)-int(mini_quest_from)))
          elif mini_quest_to<=mini_quest_from: #ถ้าปลายทางน้อยกว่าต้นทาง (ลง)
              if lift_goto>=lift_form: #และถ้าเส้นเดินลิฟต์ขึ้น
                  if lift_form <= mini_quest_from <= lift_goto: #แต่ถ้าขึ้นระหว่างทางเดินลง
                          lift_works.append(abs(int(mini_quest_to)-int(lift_goto)))
                  else: #ไม่อยู่ในเส้นทางเดินของลิฟต์
                      lift_works.append(abs(int(mini_quest_from)-int(lift_goto)) + abs(int(mini_quest_to)-int(mini_quest_from)))
              elif lift_form >= lift_goto: #และถ้าเส้นเดินลิฟต์ลง
                  if lift_goto <= mini_quest_from <= lift_form: #แต่ถ้าขึ้นระหว่างทางเดินลง
                      if lift_goto <= mini_quest_to: #และถ้าอยู่ระหว่างเส้นทางเดินลิฟต์
                          work = 0
                          lift_works.append(work)
                      else: #ถ้าปลายทางไม่สุดเส้นทางเดิน
                          lift_works.append(abs(int(mini_quest_to)-int(lift_goto)))
                  else: #ไม่อยู่ในเส้นทางเดินของลิฟต์
                      lift_works.append(abs(int(mini_quest_from)-int(lift_goto)) + abs(int(mini_quest_to)-int(mini_quest_from)))
      best_lift = lift_works.index(min(lift_works))
      print('>>', best_lift + 1)
find()

6632263821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.32
>> 12
>> 21
>> 21
>> 21
>> 21
>> 21
>> 3
>> 3
>> 3
>> 3
>> 3
>> 21
>> 46
>> 46
>> 46
>> 46
>> 3
>> 64
>> 64
>> 64
>> 64
>> 5
[]
bytecount: {'code': 844, 'const': 307, 'code+const': 1151}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def cal(liftPos1, liftPos2, userPos1, userPos2):
    Lift = liftPos2 > liftPos1
    User = userPos2 > userPos1
    work = 0
    order = [0,0,0]
    if (liftPos1 == liftPos2):
        order[0] = liftPos1
        order[1] = userPos1
        order[2] = userPos2
        work = abs(userPos1 - liftPos1) + abs(userPos1 - userPos2)
    elif (Lift != User):
        order[0] = liftPos2
        order[1] = userPos1
        order[2] = userPos2
        work = abs(liftPos2 - userPos1) + abs(userPos1 - userPos2)
    elif (Lift == User):
        if (Lift == True):
            if (liftPos1 > userPos1):
                order[0] = liftPos2
                order[1] = userPos1
                order[2] = userPos2
                work = (liftPos2-userPos1) + (userPos2-userPos1)
            elif (liftPos1 < userPos1):
                if (liftPos2 < userPos2):
                    order[0] = liftPos2
                    order[1] = userPos2
                    work = userPos2 - liftPos2
                elif (liftPos2 > userPos2):
                    order[0] = 0
                    work = 0
                elif (liftPos2 == userPos2):
                    order[0] = 0
                    work = 0
            elif (liftPos1 == userPos1):
                if (userPos2 > liftPos2):
                    work = userPos2 - liftPos2
                else :
                  order[0] = 0
                  work = 0
        else :
          if (liftPos1 < userPos1):
            order[0] = liftPos2
            order[1] = userPos1
            order[2] = userPos2
            work = (userPos1-liftPos2) + (userPos1-userPos2)
          elif (liftPos1 > userPos1):
              if (liftPos2 > userPos2):
                  order[0] = liftPos2
                  order[1] = userPos2
                  work = liftPos2 - userPos2
              elif (liftPos2 < userPos2):
                  order[0] = 0
                  work = 0
              elif (liftPos2 == userPos2):
                  order[0] = 0
                  work = 0
          elif (liftPos1 == userPos1):
              if (userPos2 < liftPos2):
                  work = liftPos2 - userPos2
              else:
                  order[0] = 0
                  work = 0
    return work
n_lift = int(input())
lift_level = []
for i in range(n_lift):
    n, pos1, pos2 = map(int, input().split())
    lift_level.append([pos1, pos2])
n_user = int(input())
user_want = []
for i in range(n_user):
    pos1, pos2 = map(int, input().split())
    user_want.append([pos1, pos2])
min = 0
for i in range(n_user):
    index = 0
    min = cal(lift_level[0][0], lift_level[0][1], user_want[i][0], user_want[i][1])
    for j in range(1, n_lift):
        calculated = cal(lift_level[j][0], lift_level[j][1], user_want[i][0], user_want[i][1])
        if calculated < min:
            min = calculated
            index = j
    print('>>',index + 1)

6631001521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_40.67
>> 4
>> 3
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.75
>> 3
>> 4
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.91
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 63
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 36
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1110, 'const': 91, 'code+const': 1201}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
num_lifts = int(input())
lift_numbers = []
lift_start_times = []
lift_end_times = []
for i in range(num_lifts):
    lift_num, lift_start, lift_end = map(int, input().split())
    lift_numbers.append(lift_num)
    lift_start_times.append(lift_start)
    lift_end_times.append(lift_end)
num_queries = int(input())
query_start_times = []
query_end_times = []
for i in range(num_queries):
    query_start, query_end = map(int, input().split())
    query_start_times.append(query_start)
    query_end_times.append(query_end)
for q_idx in range(num_queries):
    min_time = 0
    lift_times = [0] * num_lifts
    for lift_idx in range(num_lifts):
        is_upward = query_end_times[q_idx] - query_start_times[q_idx] > 0
        lift_direction_upward = lift_end_times[lift_idx] - lift_start_times[lift_idx] > 0
        same_floor = lift_end_times[lift_idx] - lift_start_times[lift_idx] == 0
        if same_floor:
            min_time = abs(lift_start_times[lift_idx] - query_start_times[q_idx]) + abs(query_start_times[q_idx] - query_end_times[q_idx])
        elif is_upward and lift_direction_upward:
            if lift_end_times[lift_idx] == query_end_times[q_idx]:
                if lift_start_times[lift_idx] > query_start_times[q_idx]:
                    min_time = lift_end_times[lift_idx] - query_end_times[q_idx] + query_end_times[q_idx] - query_start_times[q_idx]
                else:
                    min_time = 0
            if lift_end_times[lift_idx] > query_end_times[q_idx]:
                if lift_start_times[lift_idx] <= query_start_times[q_idx]:
                    min_time = 0
                elif lift_start_times[lift_idx] > query_start_times[q_idx]:
                    min_time = lift_end_times[lift_idx] - query_start_times[q_idx] + query_end_times[q_idx] - query_start_times[q_idx]
            elif lift_end_times[lift_idx] < query_end_times[q_idx]:
                if lift_start_times[lift_idx] < query_start_times[q_idx]:
                    min_time = query_end_times[q_idx] - lift_end_times[lift_idx]
                elif lift_start_times[lift_idx] > query_start_times[q_idx]:
                    min_time = lift_end_times[lift_idx] - query_start_times[q_idx] + query_end_times[q_idx] - query_start_times[q_idx]
        elif not is_upward and not lift_direction_upward:
            if lift_end_times[lift_idx] == query_end_times[q_idx]:
                if lift_start_times[lift_idx] >= query_start_times[q_idx]:
                    min_time = 0
                else:
                    min_time = query_start_times[q_idx] - lift_end_times[lift_idx] + query_start_times[q_idx] - query_end_times[q_idx]
            elif lift_end_times[lift_idx] > query_end_times[q_idx]:
                if lift_start_times[lift_idx] < query_start_times[q_idx]:
                    min_time = query_start_times[q_idx] - lift_end_times[lift_idx] + query_start_times[q_idx] - query_end_times[q_idx]
                elif lift_start_times[lift_idx] > query_start_times[q_idx]:
                    min_time = lift_end_times[lift_idx] - query_end_times[q_idx]
            elif lift_end_times[lift_idx] < query_end_times[q_idx]:
                if lift_start_times[lift_idx] < query_start_times[q_idx]:
                    min_time = query_start_times[q_idx] - lift_end_times[lift_idx] + query_start_times[q_idx] - query_end_times[q_idx]
                elif lift_start_times[lift_idx] >= query_start_times[q_idx]:
                    min_time = 0
        elif (is_upward and not lift_direction_upward) or (not is_upward and lift_direction_upward):
            min_time = abs(lift_end_times[lift_idx] - query_start_times[q_idx]) + abs(query_start_times[q_idx] - query_end_times[q_idx])
        lift_times[lift_idx] = min_time
    min_lift_time = min(lift_times)
    chosen_lift = lift_times.index(min_lift_time)
    compare_lifts = [idx for idx, time in enumerate(lift_times) if time == min_lift_time and idx > chosen_lift]
    if not compare_lifts:
        print(">>", lift_numbers[chosen_lift])
    else:
        compare_lift = min(compare_lifts)
        if lift_numbers[chosen_lift] < lift_numbers[compare_lift]:
            print(">>", lift_numbers[chosen_lift])
        else:
            print(">>", lift_numbers[compare_lift])

6530427021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.34
>> 1
>> 1
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 2784, 'const': 175, 'code+const': 2959}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
number = []
start = []
target = []
result = []
for i in range(n):
    x = input().split()
    result.append((int(x[0]),int(x[1]),int(x[2])))
m = int(input())
now = []
target2 = []
result2 = []
for i in range(m):
    y = input().split()
    result2.append((int(y[0]),int(y[1])))
for j in result2:
    now , target2 = j
    min_additional_floors = 100
    best_lift = 0
    for i in range(n):
        number, start, target = result[i]
        if start<=target and start<=now<=target:
            if target2>=target and target2>=target>=now:
                additional_floors = target2-target
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target2<=target and target>=target2>=now:
                additional_floors = 0
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target2<=target and target>=now>=target2:
                additional_floors = target-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target>=target2 and target>=now>=target2:
                additional_floors = target-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
        if start>=target and target<=now<=start:
            if target2>=target and now<target2:
                additional_floors = target2-target
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target2<=target:
                additional_floors = target-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target2>=target and now>=target2:
                additional_floors = 0
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target2>=target and target2>=now>=target:
                additional_floors = target2-target
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
        if start<target:
            if now<=start and target2>=target>=now:
                 additional_floors = target-now+target2-now
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and now<=target2<=target:
                 additional_floors = target-now+target2-now
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and now<=target<=target2:
                 additional_floors = target-now+target2-now
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and target2<=now<=target:
                 additional_floors = target-target2
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start and target2>=now>=target:
                 additional_floors = target2-target
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start and target2<=target<=now:
                 additional_floors = now-target+now-target2
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start and target<=target2<=now:
                 additional_floors = now-target+now-target2
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start>=target2 and target2<=target<=now:
                 additional_floors = now-target+now-target2
                 if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
        if start>target:
            if now>=start and target2<=target<=now:
                additional_floors = now-target+now-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start and target2>=now>=target:
                additional_floors = target2-target
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and target2<=now<=target:
                additional_floors = target-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and now<=target2<=target:
                additional_floors = target-now+target2-now
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and now<=target<=target2:
                additional_floors = target-now+target2-now
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start and now>=target2>=target:
                additional_floors = now-target+now-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=start and target>=now>=target2:
                additional_floors = target-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=start and now>=start>=target2>=target:
                additional_floors = now-target+now-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
        if start==target:
            if now>=target and target2<=target:
                additional_floors = now-target+now-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now>=target and target2>=target:
                additional_floors = now-target+now-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=target and target2<=now<=target:
                additional_floors = target-target2
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=target and target2>=target:
                additional_floors = target-now+target2-now
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if target<=now<=target2:
                additional_floors = target2-target
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
            if now<=target and target>=target2>=now:
                additional_floors = target-now+target2-now
                if 0<=additional_floors < min_additional_floors:
                    min_additional_floors = additional_floors
                    best_lift = number
    print(">>", best_lift)

6630303921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.5
>> 3
>> 3
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 968, 'const': 372, 'code+const': 1340}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้def create_list(num_elevators):
def create_list(num_elevators):
    elevator_ids = []  # Elevator IDs
    initial_floors = []  # Initial floors
    final_floors = []  # Final floors
    while num_elevators > 0:
        id, initial, final = input().split()
        elevator_ids.append(int(id))
        initial_floors.append(int(initial))
        final_floors.append(int(final))
        num_elevators -= 1
    return elevator_ids, initial_floors, final_floors
def calculate_waiting_time(initial_floors, final_floors, current_floor, destination_floor, elevator_index):
    elevator_index -= 1
    if initial_floors[elevator_index] - final_floors[elevator_index] < 0:  # Go up
        if initial_floors[elevator_index] <= current_floor:  # Elevator goes up and is below us
            if final_floors[elevator_index] > current_floor:
                if final_floors[elevator_index] >= destination_floor:
                    if destination_floor > current_floor:
                        wait_time = 0
                    elif destination_floor < current_floor:
                        wait_time = abs(final_floors[elevator_index] - destination_floor)
                    elif destination_floor == current_floor:
                        wait_time = 0
                elif final_floors[elevator_index] < destination_floor:
                    wait_time = destination_floor - final_floors[elevator_index]
            elif final_floors[elevator_index] < current_floor:
                wait_time = abs(current_floor - final_floors[elevator_index]) + abs(destination_floor - current_floor)
            elif final_floors[elevator_index] == current_floor:
                wait_time = abs(destination_floor - current_floor)
        elif initial_floors[elevator_index] > current_floor:  # Elevator goes up and is above us
            wait_time = (final_floors[elevator_index] - current_floor) + abs(destination_floor - current_floor)
    elif initial_floors[elevator_index] - final_floors[elevator_index] > 0:  # Go down
        if initial_floors[elevator_index] >= current_floor:  # Elevator goes down and is above us
            if final_floors[elevator_index] < current_floor:
                if final_floors[elevator_index] <= destination_floor:
                    if destination_floor < current_floor:
                        wait_time = 0
                    elif destination_floor > current_floor:
                        wait_time = abs(final_floors[elevator_index] - destination_floor)
                    elif destination_floor == current_floor:
                        wait_time = 0
                elif final_floors[elevator_index] > destination_floor:
                    wait_time = destination_floor - final_floors[elevator_index]
            elif final_floors[elevator_index] > current_floor:
                wait_time = abs(current_floor - final_floors[elevator_index]) + abs(destination_floor - current_floor)
            elif final_floors[elevator_index] == current_floor:
                wait_time = abs(destination_floor - current_floor)
        elif initial_floors[elevator_index] < current_floor:  # Elevator goes down and is below us
            wait_time = abs(final_floors[elevator_index] - current_floor) + abs(destination_floor - current_floor)
    elif initial_floors[elevator_index] - final_floors[elevator_index] == 0:
        wait_time = abs(final_floors[elevator_index] - current_floor) + abs(destination_floor - current_floor)
    return wait_time
def choose_optimal_elevator(elevator_ids, initial_floors, final_floors, num_elevators, num_requests):
    selected_elevators = []
    for _ in range(num_requests):
        i = num_elevators
        current_floor, destination_floor = input().split()
        wait_times = []
        while i > 0:
            wait_time = calculate_waiting_time(initial_floors, final_floors, int(current_floor), int(destination_floor), i)
            wait_times.append(wait_time)
            i -= 1
        wait_times = wait_times[::-1]
        selected_elevator_index = elevator_ids[wait_times.index(min(wait_times))]
        selected_elevators.append(selected_elevator_index)
    return selected_elevators
def main():
    num_elevators = int(input())
    elevator_ids, initial_floors, final_floors = create_list(num_elevators)
    num_requests = int(input())
    selected_elevators = choose_optimal_elevator(elevator_ids, initial_floors, final_floors, num_elevators, num_requests)
    for elevator in selected_elevators:
        print(">>", elevator)
if __name__ == "__main__":
    main()

6530433721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.89
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 43
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.91
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 43
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.84
>> 1
>> 1
>> 1
>> 2
>> 42
>> 4
>> 43
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.91
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 43
>> 1
>> 6
>> 6
>> 6
>> 6
>> 43
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 604, 'const': 271, 'code+const': 875}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# Function to calculate the additional burden for a given elevator
def calculate(elevator, c, d):
    ec = elevator[1]
    ed = elevator[2]
    if ec < ed:
        if (min(ec, ed, c, d) == ec) or (min(ec, ed, c, d) == d):
            return max(ec, ed, c, d)-ec + max(max(ec, ed, c, d)-d,0) - abs(ed-ec)
        else:
            return ed-ec + ed-c + d-c - abs(ed-ec)
    elif ec > ed:
        if (max(ec, ed, c, d) == ec) or (max(ec, ed, c, d) == d):
            if c>d:
                return ec - min(ec, ed, c, d) - abs(ed-ec)
            else:
                return ec - min(ec, ed, c, d) + d - min(ec, ed, c, d) - abs(ed-ec)
        else:
            return ec-ed + c-ed + c-d - abs(ed-ec)
    else:
        return abs(ec-c)+abs(c-d)
n = int(input())
elevators = []
for i in range(n):
    data = input().split()
    data = [int(e) for e in data]
    elevators.append(data)
m = int(input())
answer = []
for i in range(m):
    c, d = input().split()
    c = int(c)
    d = int(d)
    chosen = 0
    min_b = 10**9
    for j in range(n,-1,-1):
        b = calculate(elevators[j-1], c, d)
        if (b <= min_b):
            min_b = b
            chosen = elevators[j-1][0]
    answer.append(chosen)
for i in range(m):
    print(">>", answer[i])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# ใช้วิถีกรรมกรนั่งหาทุกความเป็นไปได้แล้วค่อยกรุ๊ปเอาค่ะ แหะ ๆ ;w;
'''
*ec < ed*
ec, ed, c, d = d-ec
ec, ed, d, c = c-ec + c-d
ec, c, ed, d = d-ec
ec, c, d, ed = ed-ec
ec, d, ed, c = c-ec + c-d
ec, d, c, ed = ed-ec + ed-d
d, ec, ed, c = c-ec + c-d
d, ec, c, ed = ed-ec + ed-d
d, c, ec, ed = ed-ec + ed-d
c, ec, ed, d = ed-ec + ed-c + d-c
c, ec, d, ed = ed-ec + ed-c + d-c
c, d, ec, ed = ed-ec + ed-c + d-c
*ec > ed*
ed, ec, c, d = ec-ed + d-ed
c, ed, ec, d = ec-c + d-c
ed, c, ec, d = ec-ed + d-ed
ed, c, d, ec = ec-ed + d-ed
c, ed, d, ec = ec-c + d-c
c, d, ed, ec = ec-c + d-c
ed, d, c, ec = ec-ed
d, ed, c, ec = ec-d
d, c, ed, ec = ec-d
ed, ec, d, c = ec-ed + c-ed + c-d
ed, d, ec, c = ec-ed + c-ed + c-d
d, ed, ec, c = ec-ed + c-ed + c-d
*ec = ed*
e, c, d = d-e
e, d, c = c-e + c-d
c, e, d = e-c + d-c
c, d, e = e-c + d-c
d, e, c = c-e + c-d
d, c, e = e-d
'''

6632106021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_30.89
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 13
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_60.91
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 13
>> 4
>> 4
>> 4
>> 4
[]
test_main_70.84
>> 1
>> 1
>> 1
>> 2
>> 12
>> 4
>> 13
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.91
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 13
>> 1
>> 6
>> 6
>> 6
>> 6
>> 13
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 926, 'const': 221, 'code+const': 1147}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
enumber = int(input())
elevator = [0]*enumber
for i in range (0,enumber):
    elevator[i] = input().split(' ')
    elevator[i][0] = int(elevator[i][0])
    elevator[i][1] = int(elevator[i][1])
    elevator[i][2] = int(elevator[i][2])
ereq = int(input())
req = [0]*ereq
for i in range (0,ereq):
    req[i] = input().split(' ')
    req[i][0] = int(req[i][0])
    req[i][1] = int(req[i][1])
# input for elevator info and request
# elevator = [name , initial floor, final floor]
# request = [initial, final]
load = [[0] * enumber for _ in range(ereq)]
# load = [load elevator 1 - req 1, load elevator 2 - req1, load elevator 3 - req 1, ...],[load elevator 1 - req 2, ...
for a in range(0,ereq):#load verification for all request
    for i in range(0,enumber): #load verification for a single request
        if req[a][0] in range (min(elevator[i][2],elevator[i][1]),max(elevator[i][2],elevator[i][1])+1):
            if (elevator[i][2]-elevator[i][1])/(req[a][1]-req[a][0]) < 0:
                load[a][i] =  abs(elevator[i][2]-req[a][0]) + abs(req[a][0] - req[a][1])
            else:
                if abs(req[a][0]-elevator[i][1]) + abs(req[a][0] - req[a][1]) <= abs(elevator[i][2]-elevator[i][1]):
                    load[a][i] = 0
                else:
                    load[a][i] = abs(elevator[i][2]-req[a][1])
        else:
            load[a][i] = abs(elevator[i][2]-req[a][0]) + abs(req[a][0] - req[a][1])
ans = [0]*ereq
rep = []
for a in range (0,ereq):
    r = 0
    list = load[a]
    minload = min(list)
    for i in range (0,enumber):
        if load[a][i] == minload and r < 1:
            ans[a] = elevator[i][0]
            rep.append(elevator[i][0])
            r+= 1
        elif load[a][i] == minload and r >= 1:
            rep.append(elevator[i][0])
            if i == enumber-1:
                ans[a] = min(rep)
    print(">>",ans[a])

6530334221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.87
>> 2
>> 21
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 36
>> 3
>> 4
>> 4
>> 4
>> 54
>> 5
[]
bytecount: {'code': 474, 'const': 199, 'code+const': 673}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
lifts=[]
best_list=[]
for i in range(n):
  data=input().split()
  lift_number=int(data[0])
  now_floor=int(data[1])
  target_floor=int(data[2])
  lifts.append((lift_number,now_floor,target_floor))
m=int(input())
for e in range(m):
  user=input().split()
  start=int(user[0])
  stop=int(user[1])
  check=float('inf')
  best=0
  for lift_number,now_floor,target_floor in lifts:
    if target_floor-now_floor >= 0 and stop-start >= 0:
      if start>=target_floor and start>=now_floor:
        total=(start-target_floor)+(stop-start)
      elif start>=now_floor and start<=target_floor:
        total=stop-start
      elif start<now_floor:
        total=(target_floor-start)+(stop-start)
    elif target_floor-now_floor <= 0 and stop-start <= 0:
      if start<now_floor and start<=target_floor:
        total=(target_floor-start)+(start-stop)
      elif start<=now_floor and start>=target_floor:
        total=start-stop
      elif start>now_floor:
        total=(start-target_floor)+(start-stop)
    else:
      total=abs(start-target_floor)+abs(stop-start)
    if total<check:
      check=total
      best=lift_number
  best_list.append(best)
for i in best_list:
  print('>>',i)

6631808721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 3
>> 3
>> 34
>> 34
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.91
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 36
>> 3
>> 4
>> 4
>> 4
>> 54
>> 5
[]
bytecount: {'code': 1084, 'const': 176, 'code+const': 1260}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
amountliftchange = []
liftnumber = []
i = 1
n = int(input())
l1 = []
while i <= n:
    i += 1
    ldet = input().split()
    l1.append(ldet)
for v in range(0, n):
    liftnumber.append(l1[v][0])
i = 1
m = int(input())
l2 = []
while i <= m:
    i += 1
    qdet = input().split()
    l2.append(qdet)
for a in range(0, n):
    for b in range(0, m):
        o = int(l1[a][1])
        p = int(l1[a][2])
        q = int(l2[b][0])
        r = int(l2[b][1])
        if o <= p and q < r:
            if q >= o and r <= p:
                change = 0
            if q >= o and r > p:
                change = abs(r - p)
            if q < o and r >= p:
                change = abs(q - p) + abs(r - q)
            if q < o and r <= p:
                change = abs(q - p) + abs(r - q)
        if o <= p and q > r:
            if o <= q <= p:
                change = abs(r - p)
            else:
                change = abs(q - p) + abs(r - q)
        if o > p and q < r:
            if o >= q >= p:
                change = abs(r - p)
            else:
                change = abs(q - p) + abs(r - q)
        if o > p and q > r:
            if o >= q >= p and r >= p:
                change = 0
            if o >= q >= p and r < p:
                change = abs(r - q)
            if q > o and o >= r >= p:
                change = abs(q - p) + abs(r - q)
            if q > o and r < p:
                change = abs(q - p) + abs(r - q)
            if q > o and r > o:
                change = abs(q - p) + abs(r - q)
            if q < p and r < p:
                change = abs(q - p) + abs(r - q)
        amountliftchange.append(change)
j = 0
lifttuatee = []
liftnumberreal = []
for x in range(0, m):
    anotherlist = []
    e = amountliftchange[x:len(amountliftchange):m]
    anotherlist.append(e)
    aa = anotherlist[0][0]
    bb = anotherlist[0][1]
    cc = anotherlist[0][2]
    dd = anotherlist[0][3]
    mins = min(anotherlist[0])
    ind = str(int(anotherlist[0].index(mins))+1)
    lifttuatee = liftnumber[int(ind)-1]
    liftnumberreal.append(lifttuatee)
    print('>> ' + str(lifttuatee))

6631807021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
1 3 1
2 1 8
3 2 2
4 12 3
>> 2
>> 4
>> 1
[]
test_main_21.0
1 3 1
2 2 8
3 10 10
4 12 6
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
1 2 2
2 4 4
3 6 6
4 8 8
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
1 8 11
2 6 9
3 4 7
4 2 5
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
1 6 2
2 8 4
3 12 8
4 10 6
>> 3
>> 3
>> 3
>> 3
>> 34
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
1 8 11
2 6 9
3 4 7
4 2 5
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
1 6 2
2 8 4
3 12 8
4 10 6
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.96
2 5 2
1 2 5
3 7 10
6 10 7
5 12 15
4 15 12
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 36
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 746, 'const': 482, 'code+const': 1228}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def check_up_or_down(start, stop):
    if start > stop:  # go down
        return "down"
    if stop > start:  # go up
        return "up"
    return "stay"
def calculate_total_num_floor(lift_direction, lift_start, lift_stop, person_direction, person_start, person_stop):
    if (not (lift_start <= person_start <= lift_stop or lift_stop <= person_start <= lift_start)) or lift_direction == "stay":
        return abs(lift_stop - person_start) + abs(person_stop - person_start)
    if person_direction == lift_direction:
        return abs(person_stop - person_start)
    return abs(lift_stop - person_start) + abs(person_stop - person_start)
def find_indices(my_list, val):
    indices = []
    for i in range(len(my_list)):
        if val == my_list[i]:
            indices.append(i)
    return indices
num_lift = int(input())
lifts = []
for _ in range(num_lift):
    x = input()
    x = x.split()
    x = [int(i) for i in x]
    if len(x) == 2:
        x.append(x[1])
        print(x[0], x[1])
    else:
        print(x[0], x[1], x[2])
    lifts.append(x)
num_person = int(input())
destination = []
for _ in range(num_person):
    x = input()
    x = x.split()
    x = [int(i) for i in x]
    destination.append(x)
for person in destination:
    person_direction = check_up_or_down(person[0], person[1])
    result = [float('inf') for _ in range(num_lift)]
    for i in range(len(lifts)):
        lift = lifts[i]
        lift_direction = check_up_or_down(lift[1], lift[2])
        result[i] = calculate_total_num_floor(lift_direction, lift[1], lift[2], person_direction, person[0], person[1])
    if result.count(min(result)) == 1:
        index = result.index(min(result))
        print(f">> {lifts[index][0]}")
    else:
        indices = find_indices(result, min(result))
        lift_number_min_val = [lifts[i][0] for i in indices]
        print(f">> {min(lift_number_min_val)}")

6630180021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_80.82
>> 2
>> 21
>> 1
>> 1
>> 1
>> 1
>> 63
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 36
>> 3
>> 4
>> 4
>> 4
>> 54
>> 5
[]
bytecount: {'code': 836, 'const': 175, 'code+const': 1011}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
N = [list(map(int, input().split())) for _ in range(n)]
m = int(input())
M = [list(map(int, input().split())) for _ in range(m)]
for i in range (m):
    best_lift = 0
    loadmin = 100
    for j in range (n):
        load = 0
        if M[i][1] > M[i][0]:
            if N[j][2] < M[i][0] or (N[j][1] > M[i][0] and N[j][2] > M[i][0]):
                load += abs(M[i][0] - N[j][2]) + abs(M[i][1] - M[i][0])
            elif N[j][1] <= M[i][0] and M[i][0] <= N[j][2] and M[i][1] < N[j][2]:
                load += 0
            elif N[j][1] <= M[i][0] and M[i][0] <= N[j][2]:
                load += abs(M[i][1]-N[j][2])
        else:
            if N[j][2] > M[i][0] or (N[j][1] < M[i][0] and N[j][2] < M[i][0]):
                load += abs(M[i][0] - N[j][2]) + abs(M[i][1] - M[i][0])
            elif N[j][1] >= M[i][0] and M[i][0] >= N[j][2] and M[i][1] > N[j][2]:
                load += 0
            elif N[j][1] >= M[i][0] and M[i][0] >= N[j][2]:
                load += abs(M[i][1]-N[j][2])
        if load < loadmin:
            loadmin = load
            best_lift = N[j][0]
    print(">>",best_lift)

6630099921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 43
>> 43
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 518, 'const': 175, 'code+const': 693}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
x = int(input())
el1 = []
el2 = []
el3 = []
for i in range(x):
    a = input().split()
    el1.append(int(a[0]))
    el2.append(int(a[1]))
    el3.append(int(a[2]))
y = int(input())
for j in range(y):
    b = input().split()
    b[0],b[1] = int(b[0]),int(b[1])
    lowest_energy = 2000000
    for i in range(x):
         if(b[0] <= b[1] and el2[i] <= el3[i]):
            if(el2[i] <= b[0] <= el3[i]):
                b[0] = el3[i]
                if(el2[i] <= b[1] <= el3[i]):
                    b[1] = el3[i]
         elif(b[0] >= b[1] and el2[i] >= el3[i]):
            if(el2[i] >= b[0] >= el3[i]):
                b[0] = el3[i]
                if(el2[i] >= b[1] >= el3[i]):
                    b[1] = el3[i]
         energy_lift = abs(el3[i]-b[0]) + abs(b[0]-b[1])
         if(energy_lift < lowest_energy):
            lowest_energy = energy_lift
            lift = el1[i]
    print(">>",lift)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631469621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 43
>> 43
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 516, 'const': 199, 'code+const': 715}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n_lifts = int(input())
lifts = []
for i in range(n_lifts):
  lifts.append([int(j) for j in input().split()])
n_people = int(input())
people = []
for i in range(n_people):
  people.append([int(j) for j in input().split()])
for person in people:
  lowest_time = float('inf')
  best_lift = None
  for lift in lifts:
    time = 0
    if person[0] <= person[1] and lift[1] <= lift[2]:
      if lift[1] <= person[0] <= lift[2]:
        person[0] = lift[2]
        if lift[1] <= person[1] <= lift[2]:
          person[1] = lift[2]
    elif person[0] >= person[1] and lift[1] >= lift[2]:
      if lift[1] >= person[0] >= lift[2]:
        person[0] = lift[2]
        if lift[1] >= person[1] >= lift[2]:
          person[1] = lift[2]
    time = abs(lift[2] - person[0]) + abs(person[0] - person[1])
    if time < lowest_time:
      lowest_time = time
      best_lift = lift[0]
  print(">>", best_lift)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631514121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_50.84
>> 3
>> 43
>> 43
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 502, 'const': 175, 'code+const': 677}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
x = []
for i in range(n):
    j = input().split()
    x.append([int(j[0]),int(j[1]),int(j[2])])
m = int(input())
l = []
for i in range(m):
    k = input().split()
    l.append([int(k[0]),int(k[1])])
for i in l:
    lowest = 10**9
    for j in x:
        if(i[0] <= i[1] and j[1] <= j[2]):
            if(j[1] <= i[0] <= j[2]):
                i[0] = j[2]
                if(j[1] <= i[1] <= j[2]):
                    i[1] = j[2]
        elif(i[0] >= i[1] and j[1] >= j[2]):
            if(j[1] >= i[0] >= j[2]):
                i[0] = j[2]
                if(j[1] >= i[1] >= j[2]):
                    i[1] = j[2]
        t = abs(j[2]-i[0]) + abs(i[0]-i[1])
        if(t < lowest):
            lowest = t
            lift = j[0]
    print(">>",lift)

6331007021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 842, 'const': 1238, 'code+const': 2080}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
from typing import List, Tuple
import numpy as np
from  functools import cmp_to_key
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def list_to_int(l: List)-> List:
  return [int(x) for x in l]
lift = {}
q = []
num_lift = int(input().strip())
while(num_lift > 0):
  temp = list_to_int(input().strip().split(" "))
  is_up = temp[2] - temp[1] > 0
  lift[temp[0]] = (temp[1],temp[2], is_up)
  num_lift -= 1
num_q = int(input().strip())
while(num_q > 0):
  temp = list_to_int(input().strip().split(" "))
  is_up = temp[1] - temp[0] > 0
  q.append((temp[0],temp[1],is_up))
  num_q -= 1
def is_along_the_way(l_from: int, l_to: int, q_from: int, q_to: int, is_up: bool) -> bool:
  if is_up:
    if q_from < l_from:
      return False
    else:
      return True
  else:
    if q_from > l_from:
      return False
    else:
      return True
def is_in_range(v, l_from,l_to, is_up):
  if is_up:
    return v >= l_from and v <= l_to
  else:
    return v >= l_to and v <= l_from
def find_min_para(para1 : Tuple, para2: Tuple)-> int:
  if para1[1] > para2[1]:
    return 1
  elif para1[1] < para2[1]:
    return -1
  elif para1[1] == para2[1] and para1[0] < para2[0]:
    return -1
  else:
    return 0
def calculate_para(dest_from: int, dest_to: int, is_up: bool) -> int:
  paras = []
  for k,v in lift.items():
    is_altw = is_along_the_way(v[0],v[1], dest_from, dest_to, is_up)
    para = 0
    if v[2] == is_up and is_altw:
      is_to_in_range = is_in_range(dest_to,v[0],v[1],is_up)
      is_from_in_range = is_in_range(dest_from,v[0],v[1],is_up)
      if is_to_in_range and is_from_in_range:
        para = 0
      else:
        para = np.abs(v[1] - dest_to)
    else:
      para = np.abs(v[1] - dest_from) + np.abs(dest_to - dest_from)
    paras.append((k, para,is_altw))
  return sorted(paras, key=cmp_to_key(find_min_para))
for i in range(len(q)):
  result = calculate_para(q[i][0],q[i][1],q[i][2])
  print(">>",result[0][0])

6331507521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 326, 'const': 147, 'code+const': 473}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevator = []
for i in range(n):
    x = input().split()
    name = int(x[0]); start = int(x[1]); stop = int(x[2])
    elevator.append([name,start,stop])
m = int(input())
for f in range(m) :
    question = input().split()
    start = int(question[0])
    stop= int(question[1])
    for i in range(len(elevator)) :
        if (max(elevator[i][1],elevator[i][2]) >= start and min(elevator[i][1],elevator[i][2]) <= start) :
            power = abs(stop-elevator[i][2])
        else :
            power = abs(start-elevator[i][2]) + abs(stop-start)
        if (i == 0 or power < minpower) :
            minpower = power
            ans = elevator[i][0]
    print('>>',ans)

6331512621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 546, 'const': 147, 'code+const': 693}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n_lift = int(input())#รับจำนวนลิฟต์
info = []#หมายเลขลิฟต์(เท่ากับจำนวน n_lift) ชั้นปัจจุบัน ชั้นปลายาง
for i in range(n_lift):
    x = input().split()
    info.append(x)
ques = int(input())
go = []
for i in range(ques):
    y = input().split()
    go.append(y)
begin = []
for i in range(n_lift):
    begin.append(int(info[i][1]))
end = []
for i in range(n_lift):
    end.append(int(info[i][2]))
now = []
for i in range(ques):
    now.append(int(go[i][0]))
want = []
for i in range(ques):
    want.append(int(go[i][1]))
lift_number = []
for i in range(n_lift):
    lift_number.append(info[i][0])
for e in range(ques):
    load = []
    for i in range(n_lift):
        if begin[i]<= now[e]<= end[i] or begin[i]>= now[e]>= end[i] :
            load.append(abs(want[e] - end[i]))
        else:
            load.append((abs(now[e] - end[i])) + abs(want[e] - now[e]))
    minimum_load = load[0]
    answer = lift_number[0]
    for i in range(len(load)):
        if load[i] < minimum_load:
            minimum_load = load[i]
            answer = lift_number[i]
    print(">>",answer)

6530110021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1608, 'const': 147, 'code+const': 1755}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
a = int(input())
e = []
e_s = []
e_f = []
c1  = 0
while c1 < a :
    s = input()
    s1 = s.split()
    e = e + [s1[0]]
    e_s = e_s +[s1[1]]
    e_f = e_f +[s1[2]]
    c1 += 1
b = int(input())
p_s = []
p_f = []
c2  = 0
while c2 < b:
    ss = input()
    s2 = ss.split()
    p_s = p_s + [s2[0]]
    p_f = p_f + [s2[1]]
    c2 += 1
c3 = 0
g = 0
para = []
while c3 < b:
 while g < a:
    if int(e_f[g]) - int(e_s[g]) > 0 and int(p_f[c3]) - int(p_s[c3]) > 0: #ขข
        if int(p_s[c3]) - int(e_s[g]) >= 0 and int(p_f[c3]) - int(e_f[g]) >= 0 :
            para = para + [abs(int(p_f[c3]) - int(e_f[g]))]
        if int(p_s[c3]) - int(e_s[g]) < 0:
            para = para + [abs((int(e_f[g]) - int(p_s[c3]))) + abs((int(p_f[c3]) - int(p_s[c3])))]
        if int(e_f[g]) - int(p_f[c3]) >= 0 and int(p_s[c3]) - int(e_s[g]) >= 0 :
            para = para + [0]
    if int(e_f[g]) - int(e_s[g]) < 0 and int(p_f[c3]) - int(p_s[c3]) < 0: #ลล
        if int(e_f[g]) - int(p_f[c3]) <= 0 and int(p_s[c3]) - int(e_s[g]) <= 0 :
            para = para + [0]
        if int(p_s[c3]) - int(e_s[g]) <= 0 and int(e_f[g]) - int(p_f[c3]) > 0:
            para = para + [abs(int(e_f[g]) - int(p_f[c3]))]
        if int(p_s[c3]) - int(e_s[g]) > 0:
            para = para + [abs((int(p_s[c3]) - int(e_f[g]))) + abs((int(p_s[c3]) - int(p_f[c3])))]
    if int(e_f[g]) - int(e_s[g]) > 0 and int(p_f[c3]) - int(p_s[c3]) < 0:#สลับ
        para = para + [abs(int(e_f[g]) - int(p_s[c3])) + abs(int(p_f[c3]) - int(p_s[c3]))]
    if int(e_f[g]) - int(e_s[g]) < 0 and int(p_f[c3]) - int(p_s[c3]) > 0:#สลับ
        para = para + [abs(int(e_f[g]) - int(p_s[c3])) + abs(int(p_f[c3]) - int(p_s[c3]))]
    if int(e_f[g]) - int(e_s[g]) == 0 and int(p_f[c3]) - int(p_s[c3]) > 0:
        if int(e_s[g]) - int(p_s[c3]) >= 0:
            para = para +[abs(int(e_s[g]) - int(p_s[c3])) + abs(int(p_f[c3]) - int(p_s[c3]))]
        if int(e_s[g]) - int(p_s[c3]) < 0:
            para = para + [abs(int(p_f[c3]) - int(e_s[g]))]
    if int(e_f[g]) - int(e_s[g]) == 0 and int(p_f[c3]) - int(p_s[c3]) < 0:
        if int(p_f[c3]) - int(e_s[g]) >= 0:
            para = para + [abs(int(e_s[g]) - int(p_s[c3])) + abs(int(p_f[c3]) - int(p_s[c3]))]
        if int(p_f[c3]) - int(e_s[g]) < 0:
            para = para + [abs(int(p_f[c3]) - int(e_s[g]))]
    g   +=1
 c3 += 1
 g   = 0
 min_para = min(para)
 min_index = para.index(min_para)
 print(">>",e[min_index])
 para = []

6530145021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 318, 'const': 231, 'code+const': 549}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = []
while(True):
    if (n==0):
        break;
    a,b,c= input().split()
    a = int(a)
    b = int(b)
    c = int(c)
    lift.append([a,b,c])
    n-=1
m = int(input())
while(True) :
    if (m == 0):
        break;
    x,y = input().split()
    x = int(x)
    y= int(y)
    minpower = 100000
    ans = 9999
    for i in range(len(lift)) :
        k = lift[i]
        if (max(k[1],k[2]) >= x and min(k[1],k[2]) <= x) :
            power = abs(y-k[2])
        else :
            power = abs(x-k[2]) + abs(y-x)
        if (power < minpower or i == 0) :
            minpower = power
            ans = k[0]
    print('>>',ans)
    m-=1

6530157521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 288, 'const': 147, 'code+const': 435}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
l = []
for i in range(int(input())) :
    a,b,c= input().split()
    l.append([int(a),int(b),int(c)])
lans = []
for j in range(int(input())) :
    x,y = input().split()
    x = int(x)
    y= int(y)
    latestpower = 0
    ans = 0
    for i in range(len(l)) :
        k = l[i]
        if (max(k[1],k[2]) >= x and min(k[1],k[2]) <= x) :
            power = abs(y-k[2])
        else :
            power = abs(x-k[2]) + abs(y-x)
        if (power < latestpower or i == 0) :
            latestpower = power
            ans = k[0]
    print('>>',ans)

6530193021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 626, 'const': 197, 'code+const': 823}
3 # HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
r = []
a = []
bb = []
for n in range(int(input())):
    a.append(input().split(' '))
for m in range(int(input())):
    bb.append(input().split(' '))
for b in bb :
    r = []
    d = []
    for e in a :
        if int(e[1])<=int(e[2]) :#up
            if int(e[1])<=int(b[0]) and int(e[2])>=int(b[1]) and int(b[0])<=int(b[1]) :
                c = 0
            elif int(e[1])<=int(b[0])<=int(e[2]):
                c = abs(int(b[1])-int(e[2]))
            else :
                c = abs(int(e[2])-int(b[0]))+abs(int(b[0])-int(b[1]))
        else : #down
            if int(e[1])>=int(b[0]) and int(e[2])<=int(b[1]) and int(b[0])>=int(b[1]) :
                c = 0
            elif int(e[2])<=int(b[0])<=int(e[1]):
                c = abs(int(b[1])-int(e[2]))
            else :
                c = abs(int(e[2])-int(b[0]))+abs(int(b[0])-int(b[1]))
        d.append(int(c))
        r.append(e[0])
    print('>>',r[d.index(min(d))])

6530377221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 586, 'const': 119, 'code+const': 705}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
s1,d1,m1 = [0]*n,[0]*n,[0]*n
s2,d2,m2 = [],[],[]
f = []
for _ in range(n):
    a,b,c = [int(e) for e in input().split()]
    s1[a-1],d1[a-1],m1[a-1] = b,c,c-b
m = int(input())
for _ in range(m):
    a,b = [int(e) for e in input().split()]
    s2.append(a)
    d2.append(b)
    m2.append(b-a)
for i in range(len(s2)):
    p = []
    for j in range(len(s1)):
        if m1[j]/m2[i] < 0: p.append(abs(d1[j]-s2[i])+abs(m2[i]))
        else:
            if s1[j] <= s2[i] <= d1[j]: p.append(abs(d1[j]-d2[i]))
            elif s1[j] >= s2[i] >= d1[j]: p.append(abs(d1[j]-d2[i]))
            else: p.append(abs(d1[j]-s2[i])+abs(m2[i]))
    f.append(p.index(min(p)))
for e in f: print(">>", e+1)

6530403921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 412, 'const': 147, 'code+const': 559}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
l = []
for i in range(n):
  l.append(input().split())
m = int(input())
p = []
for i in range(m):
  p.append(input().split())
for q in p:
  x = int(q[0])
  y = int(q[1])
  z = []
  for t in l:
    a = int(t[1])
    b = int(t[2])
    if min(a,b) <= x <= max(a,b):
      if min(a,b) <= y <= max(a,b):
        if (x>y and a>b) or (x<y and a<b):
          z.append([0,t[0]])
        else:
          z.append([abs(b-y),t[0]])
      else:
        z.append([abs(b-y),t[0]])
    else:
      z.append([abs(x-b)+(abs(y-x)),t[0]])
  z.sort()
  print('>>',str(z[0][1]))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6531505421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 724, 'const': 283, 'code+const': 1007}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def calculate_cost(question, lift):
        if (lift[2] >= lift[1]) and (question[1] >= question[0]):
                if (question[0] < lift[1]):
                        return (lift[2] - question[0]) + (question[1] - question[0])
                elif (lift[0] <= question[0] <= lift[1]):
                        if (question[1] <= lift[2]):
                                return (0)
                        else:
                                return (question[1] - lift[2])
                else:
                        return (question[0] - lift[2]) + (question[1] - question[0])
        elif (lift[2] <= lift[1]) and (question[1] < question[0]):
                if (question[0] > lift[1]):
                        return (question[0] - lift[2]) + (question[0] - question[1])
                elif (lift[2] <= question[0] <= lift[1]):
                        if (lift[2] <= question[1]):
                                return (0)
                        else:
                                return (lift[2] - question[1])
                else:
                        return (lift[2] - question[0]) + (question[0] - question[1])
        else:
                return abs(lift[2] - question[0]) + abs(question[1] - question[0])
def solve(question, lifts):
        costs = []
        ids = []
        for i in range(len(lifts)):
                costs.append(calculate_cost(question, lifts[i]))
                ids.append(lifts[i][0])
        min_cost = min(costs)
        for i in range(len(lifts)):
                if (costs[i] == min_cost):
                        print(">>", ids[i])
                        return
n = int(input())
lifts = []
for i in range(n):
        lift = input().split()
        lifts.append([int(lift[0]), int(lift[1]), int(lift[2])])
m = int(input())
questions = []
for i in range(m):
        question = input().split()
        questions.append([int(question[0]), int(question[1])])
for question in questions:
        solve(question, lifts)

6531519221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>  2
>>  4
>>  1
[]
test_main_21.0
>>  1
>>  2
>>  3
>>  4
[]
test_main_31.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
[]
test_main_41.0
>>  4
>>  4
>>  4
>>  3
>>  3
>>  2
>>  2
>>  1
>>  1
[]
test_main_51.0
>>  3
>>  3
>>  3
>>  4
>>  4
>>  2
>>  2
>>  1
>>  1
>>  1
>>  1
>>  1
[]
test_main_61.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
>>  4
>>  4
[]
test_main_71.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  4
>>  3
>>  3
>>  3
>>  3
>>  3
>>  3
[]
test_main_81.0
>>  2
>>  1
>>  1
>>  1
>>  1
>>  1
>>  3
>>  3
>>  3
>>  3
>>  3
>>  1
>>  6
>>  6
>>  6
>>  6
>>  3
>>  4
>>  4
>>  4
>>  4
>>  5
[]
bytecount: {'code': 396, 'const': 164, 'code+const': 560}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def diffNum (a, b):
  return abs(a - b)
n = int(input())
num = []
for i in range (n):
  num.append(input().split())
m = int(input())
com = []
res = []
for i in range (m):
  com.append(input().split())
  cur = int(com[i][0])
  to = int(com[i][1])
  subres = []
  for j in range (n):
    curflr = int(num[j][1])
    desflr = int(num[j][2])
    if (cur <= desflr and cur >= curflr) or (cur <= curflr and cur >= desflr):
      subres.append(diffNum(to, desflr))
    else:
      subres.append(diffNum(cur, desflr) + diffNum(cur, to))
  res.append(subres)
#print(num)
#print(res)
for i in range (m):
  low = res[i][0]
  elev = int(num[0][0])
  for j in range (1,n):
    if res[i][j] < low:
      low = res[i][j]
      elev = int(num[j][0])
  print(">> ",elev)

6531809221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 412, 'const': 147, 'code+const': 559}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n=int(input())
lift=[]
for i in range(n):
  lift.append(input().split())
m=int(input())
people=[]
for i in range(m):
  people.append(input().split())
for p in people:
  sp=int(p[0])
  ep=int(p[1])
  ans=[]
  for l in lift:
    sl=int(l[1])
    el=int(l[2])
    if min(sl,el)<=sp<=max(sl,el):
      if min(sl,el)<=ep<=max(sl,el):
        if (sp>ep and sl>el)or(sp<ep and sl<el):
          ans.append([0,l[0]])
        else:
          ans.append([abs(el-ep),l[0]])
      else:
        ans.append([abs(el-ep),l[0]])
    else:
      ans.append([abs(sp-el)+(abs(ep-sp)),l[0]])
  ans.sort()
  print('>>',str(ans[0][1]))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6532098521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 510, 'const': 147, 'code+const': 657}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cwell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
x=[]
for i in range(n):
    u=input().split()
    x.append(u)
y=[]
m=int(input())
for e in range(m):
    v=input().split()
    y.append(v)
ANS=[]
for m1 in range(m):
    for n1 in range(n):
        if int(x[n1][1]) <= int(y[m1][0]) <=int(x[n1][2]) or int(x[n1][1]) >= int(y[m1][0]) >=int(x[n1][2]) :
            if int(y[m1][1]) <= int(x[n1][2])and int(y[m1][1])>=int(y[m1][0]):
                ANS.append([0,x[n1][0]])
            else:
                ANS.append([abs(int(x[n1][2])-int(y[m1][1])),x[n1][0]])
        else:
            ANS.append([(abs(int(x[n1][2])-int(y[m1][0]))+abs(int(y[m1][0])-int(y[m1][1]))),x[n1][0]])
    ANS_key = min(ANS)
    print(">>",ANS_key[1])
    ANS=[]

6630001321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 840, 'const': 147, 'code+const': 987}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elvt = [0]*n
start = [0]*n
stop = [0]*n
for i in range(n) :
    e = input().split()
    elvt[i] = int(e[0])
    start[i] = int(e[1])
    stop[i] = int(e[2])
m = int(input())
pick = [0]*m
des = [0]*m
for i in range(m) :
    t = input().split()
    pick[i] = int(t[0])
    des[i] = int(t[1])
for j in range(m) :
    min = 0
    min_e = 0
    for i in range(n) :
        p = 0
        if start[i] < stop[i] and pick[j] <= des[j] :
            if stop[i] <= pick[j] :
                p = des[j]-stop[i]
            elif start[i] <= pick[j] < stop[i] and des[j] <= stop[i] :
                p = 0
            elif start[i] <= pick[j] < stop[i] :
                p = des[j]-stop[i]
            elif pick[j] < start[i] :
                p = (stop[i]-pick[j])+(des[j]-pick[j])
        elif start[i] > stop[i] and pick[j] >= des[j] :
            if pick[j] <= stop[i] :
                p = stop[i]-des[j]
            elif stop[i] < pick[j] <= start[i] and stop[i] <= des[j] :
                p = 0
            elif stop[i] < pick[j] <= start[i] :
                p = stop[i]-des[j]
            elif pick[j] > start[i] :
                p = (pick[j]-stop[i])+(pick[j]-des[j])
        else :
            p = abs(stop[i]-pick[j])+abs(des[j]-pick[j])
        if i == 0 or p < min :
            min = p
            min_e = elvt[i]
        elif p == min and elvt[i] < min_e :
            min_e = elvt[i]
    print('>>',str(min_e))

6630002021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 548, 'const': 147, 'code+const': 695}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
num_ele = [0]*n
elenow = [0]*n
elegoto = [0]*n
for i in range(n) :
    e = input().split()
    num_ele[i] = int(e[0])
    elenow[i] = int(e[1])
    elegoto[i] = int(e[2])
m = int(input())
floor = [0]*m
st_floor = [0]*m
for k in range(m) :
    e = input().split()
    floor[k] = int(e[0])
    st_floor[k] = int(e[1])
for k in range(m) :
    work = 0
    delt_1 = 0
    delt_2 = 0
    for i in range (n) :
        if (elenow[i] <= floor[k] <= st_floor[k] <= elegoto[i]) or (elenow[i] >= floor[k] >= st_floor[k] >= elegoto[i]) :
            work = 0
        elif (elenow[i] <= floor[k] <= elegoto[i] <= st_floor[k]) or (elenow[i] >= floor[k] >= elegoto[i] >= st_floor[k]) :
            work = abs(st_floor[k]-elegoto[i])
        else :
            work = abs(elegoto[i]-floor[k]) + abs(floor[k]-st_floor[k])
        if i == 0 or work < delt_1 :
            delt_1 = work
            delt_2 = num_ele[i]
    print('>>',delt_2)

6630006521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 424, 'const': 222, 'code+const': 646}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
i1 = []
for x in range(n):
    i1 += [[int(e) for e in input().split()]]
m = int(input())
for x in range(m):
    i2 = [int(e) for e in input().split()]
    u_start = i2[0]
    u_end = i2[1]
    e_no = "x"
    best = 2e9
    for i in range(n):
        e_start = i1[i][1]
        e_end = i1[i][2]
        if e_start <= u_start <= e_end or e_start >= u_start >= e_end:
            if e_start <= e_end and u_start <= u_end and u_end <= e_end:
                pwr = 0
            elif e_start >= e_end and u_start >= u_end and u_end >= e_end:
                pwr = 0
            else:
                pwr = abs(e_end - u_end)
        else:
            pwr = abs(e_end - u_start) + abs(u_start - u_end)
        if pwr < best:
            best = pwr
            e_no = i1[i][0]
        if pwr == best and i1[i][0] < e_no:
            e_no = i1[i][0]
    print(">> " + str(e_no))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630011621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 426, 'const': 171, 'code+const': 597}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
Elist = []
for A in range(n):
    Elevator = input().split()
    Elist.append([ int(Elevator[0]), int(Elevator[1]), int(Elevator[2]) ])
m = int(input())
for B in range(m) :
    Question = input().split()
    first, secound =int(Question[0]), int(Question[1])
    number = 0
    work = 2e9
    for i in range(n):
        Elevator = Elist[i]
        diQ =  secound - first
        diE =  Elevator[2] - Elevator[1]
        this_work = 0
        #print(diQ, diE)
        if diQ > 0 and diE > 0:
            if first>= Elevator[1] and first <= Elevator[2]:
                this_work  = (secound - Elevator[2] )
            else:
                this_work = abs(first-Elevator[2]) + abs(secound- first)
        elif diQ < 0 and diE < 0:
            if first <= Elevator[1] and first >= Elevator[2]:
                this_work = ( Elevator[2] -secound)
            else:
                this_work = abs(first-Elevator[2]) + abs(secound- first)
        else : this_work = abs(first-Elevator[2])+abs(secound-first)
        #print(this_work)
        if this_work < work:
         work = this_work
         number = Elevator[0]
    print(">>",number)

6630012221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 688, 'const': 147, 'code+const': 835}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
e = [0]*n
e_first = [0]*n
e_last = [0]*n
distance = [0]*n
for i in range(n):
    x = input().split()
    e[i] = int(x[0])
    e_first[i] = int(x[1])
    e_last[i] = int(x[2])
p = int(input())
p_first = [0]*p
p_last = [0]*p
for i in range(p):
    x = input().split()
    p_first[i] = int(x[0])
    p_last[i] = int(x[1])
dist = 0
for i in range(p) :
    for j in range(n) :
        a = e_first[j]
        b = e_last[j]
        c = p_first[i]
        d = p_last[i]
        if b-a < 0 :
            if d-c < 0 :
                if d < b and b <= c <= a :
                    dist = abs(b-d)
                elif b <= d <= a and b <= c <= a :
                    dist = 0
                else:
                    dist = abs(b - c)+abs(c - d)
            else :
                dist = abs(b - c) + abs(c - d)
        else :
            if d-c >= 0 :
                if a <= c <= b and d > b :
                    dist = abs(d-b)
                elif a <= d <= b and a <= c <= b :
                    dist = 0
                else :
                    dist = abs(b - c)+abs(d - c)
            else :
                dist = abs(b - c) + abs(d - c)
        distance[j] = dist
    #print(distance)
    index = 0
    for j in range(n):
        #print("j : ",j)
        if distance[j] < distance[index] :
            index = j
    print(">>",e[index])

6630013921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 606, 'const': 252, 'code+const': 858}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
e = []
for x in range(n):
  elevator = input().split()
  e.append(elevator)
m = int(input())
p = []
for y in range(m):
  people = input().split()
  p.append(people)
for z in range(m):
  floorp1 = int(p[z][0])
  floorp2 = int(p[z][1])
  distancep = floorp2 - floorp1
  if distancep >= 0:
    directionp = "up"
  else:
    directionp = "down"
  q = []
  for z in range(n):
    floore1 = int(e[z][1])
    floore2 = int(e[z][2])
    distancee = floore2 - floore1
    if distancee >= 0:
      directione = "up"
    else:
      directione = "down"
    if directionp == directione == "up":
      if floorp1 < floore1:
        d = abs(floorp1 - floore2) + abs(floorp2 - floorp1)
      elif floore1 <= floorp1 <= floore2:
        d = abs(floorp2 - floore2)
      elif floore2 < floorp1:
        d = abs(floorp1 - floore2) + abs(floorp2 - floorp1)
    elif directionp == directione == "down":
      if floorp1 > floore1:
        d = abs(floorp1 - floore2) + abs(floorp2 - floorp1)
      elif floore1 >= floorp1 >= floore2:
        d = abs(floorp2 - floore2)
      elif floore2 > floorp1:
        d = abs(floorp1 - floore2) + abs(floorp2 - floorp1)
    else:
      d = abs(floorp1 - floore2) + abs(floorp2 - floorp1)
    q.append(d)
  d = min(q)
  for i in q:
    if i == d:
      a = q.index(i)
      numbere = e[a][0]
  print(">> " + numbere)

6630014521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1076, 'const': 147, 'code+const': 1223}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
n1 = []
for i in range(n):
  a = input().split()
  n1.append(a)
q = int(input())
q1 = []
for i in range(q):
  a = input().split()
  q1.append(a)
v = []
for i in range(q):
  z = q1[i]
  x = []
  for i in range(n):
    y = n1[i]
    if int(y[2]) < int(y[1]):
      if int(z[0]) > int(z[1]):
        if int(y[2]) <= int(z[0]) <= int(y[1]):
          a = max((int(y[2]) - int(z[1])),0)
          x.append([a,y[0]])
        else :
          if int(z[0]) > int(y[1]):
            a = int(z[0])*2 - int(y[2]) - int(z[1])
            x.append([a,y[0]])
          else :
            a = int(y[2]) - int(z[1])
            x.append([a,y[0]])
      else :
        if int(y[2]) <= int(z[0]) <= int(y[1]):
          a = int(z[1]) - int(y[2])
          x.append([a,y[0]])
        else :
          a = (abs(int(y[2]) - int(z[0]))) + int(z[1]) - int(z[0])
          x.append([a,y[0]])
    else :
      if int(z[0]) < int(z[1]):
        if int(y[2]) <= int(z[0]) <= int(y[1]):
          a = max((int(z[1]) - int(y[2])),0)
          x.append([a,y[0]])
        else :
          if int(z[0]) < int(y[1]):
            a = int(y[2]) - int(z[0])*2 + int(z[1])
            x.append([a,y[0]])
          else :
            a = int(z[1]) - int(y[2])
            x.append([a,y[0]])
      else :
        if int(y[2]) <= int(z[0]) <= int(y[1]):
          a = int(z[1]) - int(z[0])
          x.append([a,y[0]])
        else :
          a = (abs(int(z[0]) - int(y[2]))) + int(z[0]) - int(z[1])
          x.append([a,y[0]])
  x.sort()
  m = x.pop(0)
  v.append(m)
for e in v :
  print (">>",e[1])

6630016821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 610, 'const': 215, 'code+const': 825}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
import math
def distance(x, y, a, b) :
    evt = 0
    user = 0
    count = 0
    if y - x >= 0: evt = 1
    else: evt = -1
    if b - a >= 0: user = 1
    else: user = -1
    if evt != user :
        count = abs(a-y)+abs(b-a)
    elif evt == user and user == 1 :
        if a <= y and a >= x and b >= y :
            count = abs(b-y)
        elif a >= x and b <= y :
            count = 0
        else :
            count = abs(a - y) + abs(b - a)
    elif evt == user and user == -1 :
        if a >= y and a <= x and b <= y :
            count = abs(b-y)
        elif a <= x and b >= y :
            count = 0
        else :
            count = abs(a - y) + abs(b - a)
    return count
num_elevator = []
elevator_on = []
elevator_goto = []
ans = -1
for i in range(int(input())) :
    temp_1, temp_2, temp_3 = input().split()
    num_elevator.append(int(temp_1))
    elevator_on.append(int(temp_2))
    elevator_goto.append(int(temp_3))
for i in range(int(input())) :
    user_on,user_goto = input().split()
    user_on = int(user_on)
    user_goto = int(user_goto)
    for j in range(len(num_elevator)) :
        if j == 0 :
            count = distance(elevator_on[j], elevator_goto[j], user_on, user_goto)
            ans = num_elevator[j]
        else :
            temp_count = distance(elevator_on[j], elevator_goto[j], user_on, user_goto)
            if temp_count == count :
                if num_elevator[j] < ans : ans = num_elevator[j]
            if temp_count < count :
                count = temp_count
                ans = num_elevator[j]
    print(">>",ans)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630019721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 476, 'const': 272, 'code+const': 748}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def main():
    n = int(input())
    elevators = []
    for i in range(n):
        elevator_info = input().split()
        elevators.append([int(elevator_info[0]), int(elevator_info[1]), int(elevator_info[2])])
    m = int(input())
    for i in range(m):
        question_info = input().split()
        user_floor, user_target = int(question_info[0]), int(question_info[1])
        elevator_answer = 0
        floor_work = float('inf')
        for i in range(n):
            elevator_data = elevators[i]
            user = user_target - user_floor
            elevator_goto = elevator_data[2] - elevator_data[1]
            min_work = 0
            if user > 0 and elevator_goto > 0:
                if elevator_data[1] <= user_floor <= elevator_data[2]:
                    min_work = user_target - elevator_data[2]
                else:
                    min_work = abs(user_floor - elevator_data[2]) + abs(user_target - user_floor)
            elif user < 0 and elevator_goto < 0:
                if elevator_data[1] >= user_floor >= elevator_data[2]:
                    min_work = elevator_data[2] - user_target
                else:
                    min_work = abs(user_floor - elevator_data[2]) + abs(user_target - user_floor)
            else:
                min_work = abs(user_floor - elevator_data[2]) + abs(user_target - user_floor)
            if min_work < floor_work:
                floor_work = min_work
                elevator_answer = elevator_data[0]
        print(">>", elevator_answer)
if __name__ == "__main__":
    main()

6630022521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 958, 'const': 211, 'code+const': 1169}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def direction (a,b,c,d): #คิดทิศทางลิฟว่าทางเดียวกันมั้ย
  if b-a >= 0 and d-c >= 0 :
    return True
  if b-a <= 0 and d-c <= 0 :
    return True
  return False
n = int(input())
s = [0]*n
for i in range(n):
    in_lift = input().split() #ข้อมูลลิฟแต่ละตัว
    s[int(in_lift[0])-1]=in_lift[1:] #ระบุชั้นเริ่มกับจบ
m= int(input())
answer= []
for i in range(m):
    st,en=[int(a) for a in input().split()]
    for e in range(n):
        x = int(s[e][0])
        y = int(s[e][1])
        if not direction (x,y,st,en) : #เคสทั่วไป
            if e==0 or abs(y-st) + abs(en-st) <minn :
                minn = abs(y-st) + abs(en-st)
                numberlift = e + 1
        elif y>x and x <= st <= y and x <= en <= y : #case 2
            if e ==0 or 0 < minn:
                minn = 0
                numberlift = e + 1
        elif x>y and y <= st <= x and y <= en <= x : #case 6
            if e ==0 or 0 < minn:
                minn = 0
                numberlift = e + 1
        elif y>x and x <= st <=y  and en >y: #case 3
            if e ==0 or abs(en-y) < minn :
                minn = abs(en-y)
                numberlift = e + 1
        elif x>y and x >= st >= y and y > en : #case 5
            if e ==0 or abs(en-y) < minn:
                minn = abs(en-y)
                numberlift = e + 1
        elif y>x and st >= y : #case 18
            if e == 0 or abs(en-y)< minn:
                minn = abs(en-y)
                numberlift = e + 1
        elif x>y and st <=y : #case 21
            if e == 0 or abs(en-y)< minn:
                minn = abs(en-y)
                numberlift = e + 1
        else: #เคสทั่วไป
            if e ==0 or abs(y-st) + abs(en-st) < minn :
                minn = abs(y-st) + abs(en-st)
                numberlift = e + 1
    answer.append(numberlift)
for j in answer:
  print('>>',j)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630024821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 548, 'const': 147, 'code+const': 695}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) ; lift_n = [0]*n ; start = [0]*n ; stop = [0]*n
for i in range(n) :
    m = input().split()
    lift_n[i]=int(m[0]) ; start[i]=int(m[1]) ; stop[i]=int(m[2])
N = int(input())
stay = [0]*N
go = [0]*N
for I in range(N) :
    M = input().split()
    stay[I]=int(M[0]) ; go[I]=int(M[1])
    #endinput
for e in range(N) :
    delta = 0 ; d = 0 ;l = 0
    for i in range(n) :
        if (start[i] <= stay[e] <= go[e] <= stop[i]) or           (start[i] >= stay[e] >= go[e] >= stop[i]) :
            delta = 0
        elif (start[i] <= stay[e] <= stop[i] <= go[e]) or             (start[i] >= stay[e] >= stop[i] >= go[e]):
            delta = abs(go[e]-stop[i])
        else :
            delta = abs(stop[i]-stay[e]) + abs(stay[e]-go[e])
        if i == 0 or delta < d :
            d = delta
            l = lift_n[i]
    print('>>',l)

6630027721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 534, 'const': 147, 'code+const': 681}
3# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
num = [0]*n
now = [0]*n
next = [0]*n
for i in range(n) :
    x = input().split()
    num[i] = int(x[0])
    now[i] = int(x[1])
    next[i] = int(x[2])
m = int(input())
stay = [0]*m
go = [0]*m
for j in range(m) :
    y = input().split()
    stay[j] = int(y[0])
    go[j] = int(y[1])
    diff = 0
    min_diff = 0
    ans = 0
    for i in range(n) :
        if (now[i] <= stay[j] <= next[i] <= go[j]) or (now[i] >= stay[j] >= next[i] >= go[j]) :
            diff = abs(go[j]-next[i])
        elif (now[i] <= stay[j] <= go[j] <= next[i]) or (now[i] >= stay[j] >= go[j] >= next[i]) :
            diff = 0
        else :
            diff = abs(next[i]-stay[j]) + abs(stay[j]-go[j])
        if i ==0 or diff < min_diff :
            min_diff = diff
            ans = num[i]
    print(">>",ans)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630031121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 858, 'const': 175, 'code+const': 1033}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input()) #Lift_num/now_floor/point_lift(1:n+1)
d=[0]*n
l=[]
j=[]
L=[]
J=[]
for i in range(n):
    x=[int(e)for e in input().split()]
    if x[1] < x[2] :
        for k in range (x[1],x[2]+1):
            l.append(k)
        j.append(x[0])
        j.append(l)
        l=[]
    elif x[1] > x[2] :
        for k in range (x[1],x[2]-1,-1):
            l.append(k)
        j.append(x[0])
        j.append(l)
        l=[]
    else:
        j.append(x[0])
        j.append([x[1]])
        l=[]
#เก็บลำดับชั้นที่ไปเสร็จสิ้น
m=int(input()) #IM_NOW/IM_WANT
B=[0]*m
for i in range(m):
    y=[int(e)for e in input().split()]
    if y[0] < y[1] :
        for k in range (y[0],y[1]+1):
            L.append(k)
        J.append(L)
        L=[]
    elif y[0] > y[1] :
        for k in range (y[0],y[1]-1,-1):
            L.append(k)
        J.append(L)
        L=[]
    else:
        J.append([0])
        L=[]
o=j[0::2]
j=j[1::2]
for i in range(len(J)):
    for k in range(len(j)):
        s=j[k]
        S=J[i]
        if S[0] in s :
           if S[-1] not in s[S[0]+1:s[-1]+1] :
               d[k]=abs(s[-1]-S[-1])
           elif S[-1] in s[S[0]+1:s[-1]+1] :
               d[k]=0
        elif S[0] not in s :
            d[k]=abs(s[-1]-S[0])+abs(S[0]-S[-1])
    B[i]+=d.index(min(d))
for i in B:
    print(">>",str(o[i]))

6630033421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1314, 'const': 147, 'code+const': 1461}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift=[]
for i in range(n):
  lst=input().split()
  lift.append(lst)
m = int(input())
des=[]
for i in range(m):
  lst=input().split()
  des.append(lst)
for i in range(m):
  for j in range(n):
    sum=0
    if (int(lift[j][1])>=int(des[i][0]))and(int(lift[j][2])<=int(des[i][1])):
      if int(lift[j][1])==int(des[i][0]):
        sum+=int(des[i][1])-int(lift[j][2])
      else:
        if int(des[i][1])<int(des[i][0]):
          sum=0
        else:
          sum+=abs(int(des[i][0])-int(lift[j][2]))
          sum+=int(des[i][1])-int(des[i][0])
    elif (int(lift[j][1])<=int(des[i][0]))and(int(lift[j][2])>=int(des[i][1])):
      if int(lift[j][2])>int(des[i][0]):
        if int(des[i][1])<int(des[i][0]):
          sum+=abs(int(lift[j][2])-int(des[i][0]))
          sum+=int(des[i][0])-int(des[i][1])
        else:
          sum=0
      else:
        if int(lift[j][1])==int(des[i][0]):
          sum+=int(lift[j][2])-int(des[i][1])
        else:
          if int(des[i][1])<int(des[i][0]):
            sum+=abs(int(des[i][0])-int(lift[j][2]))
            sum+=int(des[i][0])-int(des[i][1])
          else:
            sum=0
    elif (int(lift[j][1])>=int(des[i][0]))and(int(lift[j][2])>int(des[i][1])):
      if int(des[i][1])<int(des[i][0]):
        sum+=int(lift[j][2])-int(des[i][1])
      else:
        sum+=abs(int(lift[j][2])-int(des[i][0]))
        sum+=int(des[i][1])-int(des[i][0])
    elif (int(lift[j][1])<=int(des[i][0]))and(int(lift[j][2])<int(des[i][1])):
      if int(des[i][1])<int(des[i][0]):
        sum+=abs(int(des[i][0])-int(lift[j][2]))
        sum+=int(des[i][0])-int(des[i][1])
      else:
        sum+=int(des[i][1])-int(lift[j][2])
    if j==0:
      temp=sum
      where=int(lift[j][0])
    else:
      if sum<temp:
        temp=sum
        where=int(lift[j][0])
  print(">>",where)

6630034021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1620, 'const': 171, 'code+const': 1791}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
i = int(input())
n = i
l = i
u = i
liftname = [0.0]*i
s = [0.0]*i
d = [0.0]*i
while i > 0 :
    a = input()
    a = a.split()
    liftname[i-1] = a[0]
    s[i-1] = int(a[1])
    d[i-1] = int(a[2])
    i -= 1
q = int(input())
do = q
hus = [0.0]*q
hud = [0.0]*q
while q > 0 :
    b = input()
    b = b.split()
    hus[q-1] = int(b[0])
    hud[q-1] = int(b[1])
    q -= 1
k = [0.0]*n
while do > 0 :
    n = u
    while n > 0 :
        if ((d[n-1]-s[n-1])> 0 and (hud[do-1]-hus[do-1]) > 0 ) or ( (((d[n-1]-s[n-1])<= 0) and ((hud[do-1]-hus[do-1])) <= 0)) :
            if (d[n-1]-s[n-1]) > 0 : #up up
                if d[n-1] > hud[do-1] : #1
                    if s[n-1] <= hus[do-1] :
                        k[n-1] = 0
                    else :
                        k[n-1] = abs((d[n-1]-hus[do-1])+(hud[do-1]-hus[do-1]))
                else :
                    if d[n-1] == hud[do-1] : #2
                        if hus[do-1] < s[n-1] :
                            k[n-1] = abs((d[n-1]-hus[do-1])+(hud[do-1]-hus[do-1]))
                        else :
                            k[n-1] = 0
                    else : #3
                        if hus[do-1] < s[n-1] :
                            k[n-1] = abs((d[n-1]-hus[do-1])+(hud[do-1]-hus[do-1]))
                        else :
                            k[n-1] = abs(hud[do-1] - d[n-1])
            else :# down down
                if hud[do-1] > d[n-1] : #1
                    if s[n-1] < hus[do-1] :
                        k[n-1] = abs((hus[do-1]-d[n-1])+(hus[do-1]-hud[do-1]))
                    else :
                        k[n-1] = 0
                else :
                    if d[n-1] == hud[do-1] : #2
                        if s[n-1] < hus[do-1] :
                            k[n-1] = abs((hus[do-1]-d[n-1])+(hus[do-1]-hud[do-1]))
                        else :
                            k[n-1] = 0
                    else :#3
                        if s[n-1] >= hus[do-1] :
                            k[n-1] = abs(d[n-1]-hud[do-1])
                        else :
                            k[n-1] = abs(d[n-1]-hus[do-1])+abs(hus[do-1]-hud[do-1])
        else :#สวน
            k[n-1] =   abs(hus[do-1]-hud[do-1])  + abs(d[n-1]-hus[do-1])
        n   -= 1
    min_k = min(k)
    m = 0
    for c in k :
        if c == min_k :
            m += 1
    if m == 1 :
        v = l-1
        p = l
        while p >0 :
            if min_k == k[v] : break
            v -= 1
            p -= 1
        print(">>",liftname[v])
    else :
        x = [0.0]*m ; y = [0.0]*m
        v = l-1
        p = l
        h = m
        while m>0 :
            if min_k == k[v] :
                x[m-1] = v
                m-=1
            v -= 1
        while h > 0 :
            y[h-1] = liftname[int(x[h-1])]
            h -= 1
        print(">>",str(min(y)))
    do -= 1
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630035721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1258, 'const': 199, 'code+const': 1457}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
numlift = int(input())
liftnumber = []
liftstart = []
liftend = []
for i in range(numlift):
    a, b, c = map(int, input().split())
    liftnumber.append(a)
    liftstart.append(b)
    liftend.append(c)
nq = int(input())
startme = []
endme = []
for i in range(nq):
    d, e = map(int, input().split())
    startme.append(d)
    endme.append(e)
for i in range(nq):
    problem = 0
    numberofproblem = [0] * numlift
    for j in range(numlift):
        updown = endme[i] - startme[i] > 0
        liftupdown = True
        samefloor = False
        if liftend[j] - liftstart[j] == 0:
            samefloor = True
        elif liftend[j] - liftstart[j] > 0:
            liftupdown = True
        else:
            liftupdown = False
        if samefloor:
            problem = abs(liftstart[j] - startme[i]) + abs(startme[i] - endme[i])
            numberofproblem[j] = problem
        elif updown and liftupdown:
            if liftend[j] == endme[i]:
                if liftstart[j] > startme[i]:
                    problem = liftend[j] - endme[i] + endme[i] - startme[i]
                    numberofproblem[j] = problem
                else:
                    problem = 0
                    numberofproblem[j] = problem
            if liftend[j] > endme[i]:
                if liftstart[j] <= startme[i]:
                    problem = 0
                    numberofproblem[j] = problem
                elif liftstart[j] > startme[i]:
                    problem = liftend[j] - startme[i] + endme[i] - startme[i]
                    numberofproblem[j] = problem
            elif liftend[j] < endme[i]:
                if liftstart[j] < startme[i]:
                    problem = endme[i] - liftend[j]
                    numberofproblem[j] = problem
                elif liftstart[j] > startme[i]:
                    problem = liftend[j] - startme[i] + endme[i] - startme[i]
                    numberofproblem[j] = problem
        elif not updown and not liftupdown:
            if liftend[j] == endme[i]:
                if liftstart[j] >= startme[i]:
                    problem = 0
                    numberofproblem[j] = problem
                else:
                    problem = startme[i] - liftend[j] + startme[i] - endme[i]
                    numberofproblem[j] = problem
            elif liftend[j] > endme[i]:
                if liftstart[j] < startme[i]:
                    problem = startme[i] - liftend[j] + startme[i] - endme[i]
                    numberofproblem[j] = problem
                elif liftstart[j] > startme[i]:
                    problem = liftend[j] - endme[i]
                    numberofproblem[j] = problem
            elif liftend[j] < endme[i]:
                if liftstart[j] < startme[i]:
                    problem = startme[i] - liftend[j] + startme[i] - endme[i]
                    numberofproblem[j] = problem
                elif liftstart[j] >= startme[i]:
                    problem = 0
                    numberofproblem[j] = problem
        elif (updown and not liftupdown) or (not updown and liftupdown):
            problem = abs(liftend[j] - startme[i]) + abs(startme[i] - endme[i])
            numberofproblem[j] = problem
    minproblem = numberofproblem[0]
    answer = 0
    compareequal = 999
    for i in range(1, numlift):
        if numberofproblem[i] < minproblem:
            minproblem = numberofproblem[i]
            answer = i
    for j in range(answer + 1, numlift):
        if numberofproblem[j] == minproblem:
            compareequal = j
    if compareequal == 999:
        print(">>", liftnumber[answer])
    elif liftnumber[answer] < liftnumber[compareequal]:
        print(">>", liftnumber[answer])
    else:
        print(">>", liftnumber[compareequal])

6630036321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 608, 'const': 392, 'code+const': 1000}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input()) # ใส่จำนวนลิฟต์ท่ีเราต้องการ
ele_number = []
cur_flo = []
des_flo = []
for i in range(n) :
    inform = input().split()
    # แปลงค่า string เป็นจำนวนเต็ม
    elevat = int(inform[0])
    ele_number.append(elevat)
    current = int(inform[1])
    cur_flo.append(current)
    destina = int(inform[2])
    des_flo.append(destina)
m = int(input())
start = []
end = []
for i in range(m) :
    quest = input().split()
    # แปลงค่าเป็นจำนวนเต็ม
    sta = int(quest[0])
    start.append(sta)
    sto = int(quest[1])
    end.append(sto)
def moves(start,end) :
    if end > start :
        return 'up'
    elif end < start :
        return 'down'
    else :
        return 'standing'
def compare(start,cp,end) :
    if start <= cp <= end :
        return True
    elif start >= cp >= end :
        return True
    else :
        return False
for i in range(m) : # คำถาม
    ele_move = []
    for j in range(n) : # ลิฟท์
        if moves(start[i],end[i]) == moves(cur_flo[j],des_flo[j])           and compare(cur_flo[j],start[i],des_flo[j])           and compare(cur_flo[j],end[i],des_flo[j]) :
            e = 0
            ele_move.append(e)
        elif moves(start[i],end[i]) == moves(cur_flo[j],des_flo[j])             and compare(cur_flo[j],start[i],des_flo[j]):
            e = abs(des_flo[j] - end[i])
            ele_move.append(e)
        else :
            e = abs(des_flo[j] - start[i]) + abs(end[i] - start[i])
            ele_move.append(e)
    min_ele = min(ele_move)
    best_elevator = ele_move.index(min_ele)
    print('>>', ele_number[best_elevator])

6630038621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 742, 'const': 228, 'code+const': 970}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def work(my_start,my_stop,lift_start,lift_stop) :
    phara = 0
    if (lift_start <= my_start <= my_stop <= lift_stop) or (  lift_stop <= my_stop  <= my_start  <= lift_start) :
        phara = 0
    elif (lift_start <= my_start <= lift_stop < my_stop) or (my_stop < lift_stop <= my_start <= lift_start) :
        phara = abs(my_stop - lift_stop)
    else :
        phara = abs(lift_stop - my_start) + abs(my_start- my_stop)
    return phara
def lowest(x,d) :
    min_list = x[0][d]
    for m in range(0,len(x)) :
        if x[m][d] < min_list:
            min_list = x[m][d]
    return min_list
n_lift = int(input())
lift_num = [0]*n_lift
lift_i= [0]*n_lift
lift_f= [0]*n_lift
for i in range(n_lift):
    x = input()
    x = x.split()
    lift_num[i] = int(x[0])
    lift_i[i] = int(x[1])
    lift_f[i] = int(x[2])
n_me = int(input())
me_i = [0]*n_me
me_f = [0]*n_me
for u in range(n_me):
    y = input().split()
    me_i[u]= int(y[0])
    me_f[u]= int(y[1])
1
x = []
choice = []
for l in range(0,n_me):
    my_start = int(me_i[l])
    my_stop = int(me_f[l])
    for k in range(0,n_lift):
        lift_name = int(lift_num[k])
        lift_start = int(lift_i[k])
        lift_stop = int(lift_f[k])
        x.append([lift_name,work(my_start,my_stop,lift_start,lift_stop)])
    minor = lowest(x,1)
    for a in range(0,len(x)):
        if x[a][1] == minor:
            choice.append(x[a])
    if len(choice) == 1 :
        print('>> '+str(choice[0][0]))
    else :
        print('>> '+str(lowest(choice,0)))
    x.clear()
    choice.clear()

6630039221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 562, 'const': 91, 'code+const': 653}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lnum = [0]*n
lb = [0]*n
ls = [0]*n
for i in range(n):
    num,b,s = [int(a) for a in input().split()]
    lnum[i] = num
    lb[i] = b
    ls[i] = s
m = int(input())
pb = [0]*m
ps = [0]*m
for i in range(m):
    b,s = [int(a) for a in input().split()]
    pb[i] = b
    ps[i] = s
for j in range(m):
    for i in range(n):
        if (lb[i] <= pb[j] <= ps[j] <= ls[i]) or (ls[i] <= ps[j] <= pb[j] <= lb[i]):
            para = 0
        elif (lb[i] <= pb[j] <= ls[i] <= ps[j]) or (ps[j] <= ls[i] <= pb[j] <= lb[i]):
            para = abs( ls[i] - ps[j] )
        else:
            para = abs( pb[j] - ls[i] ) + abs( pb[j] - ps[j] )
        if i == 0 or para < min_para:
            min_para = para
            min_l = lnum[i]
    print(">>",min_l)

6630041421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 688, 'const': 187, 'code+const': 875}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
number_of_elevator = int(input())
i = 0; y = 0
lift_num=[];lift_start = [];lift_desti = []
user_start = []; user_desti = []
for x in range(number_of_elevator):
    a, b, c = input().split()
    lift_num.append(a); lift_start.append(b); lift_desti.append(c)
number_of_user = int(input())
for x in range(number_of_user):
    d, e = input().split()
    user_start.append(d); user_desti.append(e)
#----------//FOR TEST//----------Display Input--------------
''''
print("lift num   :",lift_num)
print("lift start :",lift_start)
print("lift dist  :",lift_desti)
print("user :",number_of_user)
print("user start :",user_start)
print("user fin   :",user_desti)
'''
#-------//FUNCTION//-----Calculate Number of floor----------
def calcu_floors (num,lift_sta,lift_fin,user_sta,user_fin) :
    if lift_fin == lift_sta or lift_fin == user_sta: #lift is stop/finish in user_start
        lift_floor_add = abs(user_fin - user_sta) + abs(lift_fin - user_sta)
    elif lift_sta <= user_sta <= lift_fin or lift_sta >= user_sta >= lift_fin : #user_start between lift way
        delta_user = user_fin - user_sta ; delta_lift = lift_fin - lift_sta
        if delta_user / delta_lift >= 0: #in same way
            if delta_lift >= 0: lift_floor_add = user_fin - lift_fin #up
            else : lift_floor_add = -(user_fin - lift_fin) #down
        else : # another way
            lift_floor_add = abs(lift_fin - user_sta) + abs(user_fin - user_sta)
    elif (user_fin - user_sta) / (lift_fin - lift_sta) >= 0 : #check in same way
        lift_floor_add = abs(lift_fin - user_sta) + abs(user_fin - user_sta)
    elif (user_fin - user_sta) / (lift_fin - lift_sta) <= 0 :#check in another way
        lift_floor_add = abs(lift_fin - user_sta) + abs(user_fin - user_sta)
    else : lift_floor_add = 9999 #error code
    return [num, lift_floor_add]
#---------------Calculate Number of floor-----------------
l1 = [] ; l2 = []
while i < number_of_user :
    y = 0
    while y < number_of_elevator :
        num,add = calcu_floors(int(lift_num[y]),int(lift_start[y]),int(lift_desti[y]),int(user_start[i]),int(user_desti[i]))
        l1.append(num); l2.append(add)
        y += 1
    i += 1
'''print("lift no :",l1)
   print("lift add:",l2)'''
#--------------------Display Output------------------------
for i in range(number_of_user) :
    l3 = l2[i * number_of_elevator : i * number_of_elevator + number_of_elevator]
    print(">>",l1 [l3.index(min(l3))])

6630043721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 786, 'const': 147, 'code+const': 933}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
num_ele = []
start_ele = []
end_ele = []
i = 0
j = 0
while i < n:
    i1 = input().split()
    num_ele.append(int(i1[0]))
    start_ele.append(int(i1[1]))
    end_ele.append(int(i1[2]))
    i += 1
m = int(input())
start_human = []
end_human = []
i = 0
while i < m:
    i2 = input().split()
    start_human.append(int(i2[0]))
    end_human.append(int(i2[1]))
    i += 1
i = 0
while i < m:
    box = []
    j = 0
    while j < n:
        dm = end_human[i] - start_human[i]
        dl = end_ele[j] - start_ele[j]
        if dl < 0 and dm < 0:
            if end_ele[j] <= end_human[i] <= start_human[i] <= start_ele[j]:
                box.append(0)
            elif end_ele[j] <= start_human[i] <= start_ele[j]:
                box.append(abs(end_human[i] - end_ele[j]))
            else:
                box.append(abs(end_ele[j] - start_human[i]) + abs(start_human[i] - end_human[i]))
        elif dl > 0 and dm > 0:
            if start_ele[j] <= start_human[i] <= end_human[i] <= end_ele[j]:
                box.append(0)
            elif start_ele[j] <= start_human[i] <= end_ele[j]:
                box.append(abs(end_human[i] - end_ele[j]))
            else:
                box.append(abs(end_ele[j] - start_human[i]) + abs(start_human[i] - end_human[i]))
        else:
            box.append(abs(end_ele[j] - start_human[i]) + abs(start_human[i] - end_human[i]))
        j += 1
    min_box = min(box)
    ans = num_ele[box.index(min_box)]
    print('>>', ans)
    i += 1

6630044321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 720, 'const': 147, 'code+const': 867}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
x = []
y = []
num_elevator = []
elevator_start = []
elevator_end = []
human_start = []
human_end = []
for i in range(n) :
  x = input().split()
  num_elevator.append(int(x[0]))
  elevator_start.append(int(x[1]))
  elevator_end.append(int(x[2]))
m = int(input())
for i in range(m) :
  y = input().split()
  human_start.append(int(y[0]))
  human_end.append(int(y[1]))
for i in range(m) :
  lift = []
  for j in range(n) :
    drh = human_end[i] - human_start[i]
    dre = elevator_end[j] - elevator_start[j]
    if dre < 0 and drh < 0 :
      if elevator_end[j] <= human_end[i] <= human_start[i] <= elevator_start[j] :
        lift.append(0)
      elif elevator_end[j] <= human_start[i] <= elevator_start[j] :
        lift.append(abs(human_end[i] - elevator_end[j]))
      else:
        lift.append(abs(elevator_end[j] - human_start[i]) + abs(human_start[i] - human_end[i]))
    elif dre > 0 and drh > 0:
      if elevator_start[j] <= human_start[i] <= human_end[i] <= elevator_end[j]:
        lift.append(0)
      elif elevator_start[j] <= human_start[i] <= elevator_end[j]:
        lift.append(abs(human_end[i] - elevator_end[j]))
      else :
        lift.append(abs(elevator_end[j] - human_start[i]) + abs(human_start[i] - human_end[i]))
    else:
      lift.append(abs(elevator_end[j] - human_start[i]) + abs(human_start[i] - human_end[i]))
  lift_chosen = num_elevator[lift.index(min(lift))]
  print('>>', lift_chosen)

6630048921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 416, 'const': 171, 'code+const': 587}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
l = [0]*n
for i in range(n) :
    l[i] = [int(e) for e in input().split()]
m = int(input())
me = [0]*m
for i in range(m) :
    me[i] = [int(e) for e in input().split()]
for i in range(len(me)):
    a = 10e100
    start_me =  me[i][0]
    stop_me =  me[i][1]
    for j in range(len(l)):
        if min(l[j][1],l[j][2]) <= start_me <= max(l[j][1],l[j][2]):
            total = abs(l[j][2] - stop_me)
        else:
            total = abs(l[j][2] - start_me) + abs(stop_me - start_me)
        if a > total :
            a = total
            num_lift = l[j][0]
        elif a == total :
            a = total
            num_lift = min(num_lift,l[j][0])
        else:
            pass
        #print(a,num_lift)
    print('>>', num_lift)

6630049521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 664, 'const': 1044, 'code+const': 1708}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input());lift = [[int(i) for i in input().split()] for _ in range(n)];m = int(input());go_to = [[0]+[int(i) for i in input().split()] for _ in range(m)]
def direction(l:list):return 'up' if l[2] - l[1] > 0 else 'stationary' if l[2] - l[1] == 0 else 'down'
def same_direction(l1:list,l2:list):return True if direction(l1) == direction(l2) else False
def between(check:int,parameter1:int,parameter2:int):return True if parameter1 <= check <= parameter2 or parameter1 >= check >= parameter2 else False
def workload(go_to_i:list,lift_i:list):return 0 if same_direction(go_to_i,lift_i) and between(go_to_i[1],lift_i[1],lift_i[2]) and between(go_to_i[2],lift_i[1],lift_i[2]) else abs(lift_i[2] - go_to_i[2]) if same_direction(go_to_i,lift_i) and between(go_to_i[1],lift_i[1],lift_i[2]) else abs(lift_i[2] - go_to_i[1]) + abs(go_to_i[2]-go_to_i[1])
for i in range(m):print(">> {}".format(lift[[workload(go_to[i],lift[j]) for j in range(n)].index(min([workload(go_to[i],lift[j]) for j in range(n)]))][0]))

6630050021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1320, 'const': 147, 'code+const': 1467}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
num = [0]*n
start = [0]*n
stop = [0]*n
for i in range(n):
    x = [int(e) for e in input().split()]
    num[i] = x[0]
    start[i] = x[1]
    stop[i] = x[2]
m = int(input())
start_ip = [0]*m
stop_ip = [0]*m
for i in range(m):
    x = [int(i) for i in input().split()]
    start_ip[i] = x[0]
    stop_ip[i] = x[1]
c = [0]*m*n
for i in range(n):
    if start[i] == stop[i] :
        for e in range(m):
            if start_ip[e] < stop_ip[e]: #กดup
                if start[i] <= start_ip[e]:
                    c[i*m+e] = stop_ip[e]-start[i]
                elif start_ip[e] < start[i]:
                    c[i*m+e] = (start[i]-start_ip[e])+(stop_ip[e]-start_ip[e])
            else: # down
                if start[i] <= start_ip[e]:
                    c[i*m+e] = (start_ip[e]-start[i])+(start_ip[e]-stop_ip[e])
                elif start_ip[e] < start[i]:
                    c[i*m+e] = start[i]-stop_ip[e]
    elif start[i] < stop[i] : #up
        for e in range(m):
            if start_ip[e]<stop_ip[e]:
                if start[i]<=start_ip[e]<=stop[i] and start[i]<=stop_ip[e]<=stop[i]:
                    c[i*m+e]=0
                elif start_ip[e]<start[i]:
                    c[i*m+e] =(stop[i]-start_ip[e])+(stop_ip[e]-start_ip[e])
                elif start_ip[e]>start[i]:
                    stop_ip[e]>=stop[i]
                    c[i*m+e] = stop_ip[e]-stop[i]
            else :
                if start_ip[e]>=stop[i]:
                    c[i*m+e] = (start_ip[e]-stop[i])+(start_ip[e]-stop_ip[e])
                else:
                    c[i*m+e] = (stop[i]-stop_ip[e])
    else : #down
        for e in range(m):
            if start_ip[e]>stop_ip[e]:
                if start[i]<=start_ip[e]<=stop[i] and start[i]<=stop_ip[e]<=stop[i]:
                    c[i*m+e] = 0
                elif start_ip[e]>start[i]:
                    c[i*m+e] = (start_ip[e]-stop[i])+start_ip[e]-stop_ip[e]
                elif start_ip[e]<start[i]:
                    c[i*m+e] = stop[i]-stop_ip[e]
            else :
                if stop[i]>=start_ip[e]:
                    c[i*m+e] = (stop[i]-start_ip[e])+(stop_ip[e]-start_ip[e])
                else :
                    c[i*m+e] = stop_ip[e]-stop[i]
for i in range(m):
    woke = c[i:n*m:m]
    low = woke.index(min(woke))
    print(">>",num[low])

6630051721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 732, 'const': 147, 'code+const': 879}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
nl=int(input())
nol=[]
sl=[]
el=[]
for e in range(nl):
    l = [int(h) for h in input().split()]
    nol.append(l[0])
    sl.append(l[1])
    el.append(l[2])
nq=int(input())
sm=[]
em=[]
for i in range(nq):
    m = [int(j) for j in input().split()]
    sm.append(m[0])
    em.append(m[1])
for e in range(nq):
    weight=[]
    for i in range(nl):
        diff_l=el[i]-sl[i]
        diff_m=em[e]-sm[e]
        if diff_l>0 and diff_m>0:
            if el[i]>=em[e] and sl[i]<=sm[e]:
                weight.append(0)
            elif sm[e]>=sl[i] and em[e]>el[i]:
                weight.append(abs(em[e]-el[i]))
            else:
                weight.append(abs(el[i]-sm[e])+abs(em[e]-sm[e]))
        elif diff_l<0 and diff_m<0:
            if sm[e]<=sl[i] and em[e]>=el[i]:
                weight.append(0)
            elif sm[e]<=sl[i] and em[e]<el[i]:
                weight.append(abs(el[i]-em[e]))
            else:
                weight.append(abs(sm[e]-el[i])+abs(sm[e]-em[e]))
        else:
            weight.append(abs(el[i]-sm[e])+abs(sm[e]-em[e]))
    min_weight=min(weight)
    for i in range(nl):
        if min_weight==weight[i]:
            print('>>',nol[i])
            break

6630055221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1096, 'const': 148, 'code+const': 1244}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
quantity = int(input())
lift =[]
l_first =[]
l_last =[]
which_lift =[]
for i in range(quantity):
    lift = [int(i) for i in input().split()]
    l_first.append(lift[1])
    l_last.append(lift[2])
    which_lift.append(lift[0])
n_q = int(input())
q =[]
q_first =[]
q_last = []
cal =[]
ans =[]
cacu =0
for i in range(n_q):
    q = [int(i) for i in input().split()]
    q_first.append( q[0])
    q_last.append( q[1])
for i in range(len(q_first)):
    for x in range(len(l_first)):
        if l_first[x] > l_last[x]:
            if q_first [i]> q_last[i]:
                if q_first[i] in range(l_last[x],l_first[x]+1) and q_last[i] in range(l_last[x],l_first[x]+1) :
                    cal.append(0)
                elif l_first[x] < q_first[i] :
                    cacu = abs(l_last[x] - q_first[i])+ abs(q_first[i] - q_last[i])
                    cal.append(cacu)
                elif l_last[x] >= q_last[i]:
                    cacu = abs(l_last[x] -q_last[i] )
                    cal.append(cacu)
            else:
                cacu = abs(q_first[i] - l_last[x]) + abs(q_first[i] - q_last[i])
                cal.append(cacu)
        elif l_first[x] < l_last[x]:
            if q_first [i] < q_last[i]:
                if q_first[i] in range(l_first[x],l_last[x]+1) and q_last[i] in range(l_first[x],l_last[x]+1) :
                    cal.append(0)
                elif l_last[x] <= q_last[i] and q_first[i] in range(l_first[x], l_last[x]+1):
                    cacu = abs(q_last[i] - l_last[x])
                    cal.append(cacu)
                elif l_last[x] <= q_first[i] :
                    cacu = abs(q_first[i] - l_last[x])+abs(q_first[i] - q_last[i])
                    cal.append(cacu)
                elif l_first[x] > q_first[i] :
                    cacu =abs(l_last[x] - q_first[i]) + abs(q_first[i] - q_last[i])
                    cal.append(cacu)
                elif l_first[x] == q_first[i]:
                    cacu = abs(l_last[x]  - q_last[i])
                    cal.append(cacu)
            else:
                cacu = abs(q_first[i] - l_last[x]) + abs(q_first[i] - q_last[i])
                cal.append(cacu)
        else:
            cacu = abs(q_first[i] - l_last[x])+abs(q_first[i] - q_last[i])
            cal.append(cacu)
    ans.append(which_lift[cal.index(min(cal))])
    cal =[]
for i in ans:
    print('>> '+str(i))

6630056921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 568, 'const': 148, 'code+const': 716}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) #รับค่า จำนวน ลิฟต์
Lift = []
Para = [] #ภาระ
for i in range(n+1):
  Lift.append([])
  Para.append(0)
for i in range(n):
  k,a,b = map(int,input().split())
  Lift[k]=[a,b]
m = int(input())
while m>0:
  m -= 1
  p,q = map(int,input().split())
  Ele = int(3000)
  for i in range(1,n+1):
    if Lift[i][0]>Lift[i][1]:
      if p <= Lift[i][0] and p >= Lift[i][1]:
        Para[i] = abs(q - Lift[i][1])
      else:
        Para[i] = abs(p-Lift[i][1])+abs(p-q)
      Ele = min(Ele,Para[i])
    elif Lift[i][0]<Lift[i][1]:
      if p >= Lift[i][0] and p <= Lift[i][1]:
        Para[i] = abs(q - Lift[i][1])
      else:
        Para[i] = abs(p-Lift[i][1])+abs(p-q)
      Ele = min(Ele,Para[i])
    else:
      Para[i] = abs(p-Lift[i][0])+abs(p-q)
    Ele = min(Ele,Para[i])
  for i in range(1,n+1):
   if Ele == Para[i]:
      print (f'>> {i}')
      break

6630057521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 596, 'const': 147, 'code+const': 743}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
k = int(input())
n = [0]*k
s = [0]*k
f = [0]*k
for i in range(k):
    x1 = input().split()
    n[i] = int(x1[0])
    s[i] = int(x1[1])
    f[i] = int(x1[2])
k1 = int(input())
sm = [0]*k1
fm = [0]*k1
for i in range(k1):
    y1 = input().split()
    sm[i] = int(y1[0])
    fm[i] = int(y1[1])
a = [0]*k
for j in range(k1):
    for i in range(k):
        if s[i]<=sm[j]<=fm[j]<=f[i] :
            d = 0
        elif s[i]>=sm[j]>=fm[j]>=f[i] :
            d = 0
        elif s[i]<=sm[j]<=f[i]<=fm[j] :
            d = abs(f[i]-fm[j])
        elif s[i]>=sm[j]>=f[i]>=fm[j] :
            d = abs(f[i]-fm[j])
        else :
            d = abs(fm[j]-sm[j]) + abs(sm[j]-f[i])
        a[i] = d
    for i in range(k):
        if min(a) == a[i]:
            print(">>",n[i])
            break
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630059821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 608, 'const': 119, 'code+const': 727}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
number_lift = []
p_floor = []
f_floor = []
a = 0
while a < n:
    x, y, z = input().split()
    number_lift.append(int(x))
    p_floor.append(int(y))
    f_floor.append(int(z))
    a += 1
total_case = int(input())
p_yu = []
p_pai = []
b = 0
while b < total_case:
    p, q = input().split()
    p_yu.append(int(p))
    p_pai.append(int(q))
    b += 1
z1 = [0]*n
for i in range(total_case):
    for j in range(n):
        if p_floor[j] <= p_yu[i] and f_floor[j] >= p_yu[i]:
            z = abs(f_floor[j]-p_pai[i])
        elif p_floor[j] >= p_yu[i] and f_floor[j] <= p_yu[i]:
            z = abs(f_floor[j]-p_pai[i])
        elif p_yu[i] <= p_floor[j] and p_yu[i] >= f_floor[j] and p_pai[i] <= p_floor[j] and p_pai[i] >= f_floor[j]:
            z = 0
        elif p_yu[i] >= p_floor[j] and p_yu[i] <= f_floor[j] and p_pai[i] >= p_floor[j] and p_pai[i] <= f_floor[j]:
            z = 0
        else:
            z = abs(abs(p_yu[i]-f_floor[j]) + abs(p_pai[i]-p_yu[i]))
        z1[j] = z
    x = n
    for j in range(n):
        if min(z1) == z1[j]:
            if number_lift[j] <= x:
                x = number_lift[j]
    print(">>", x)

6630063221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 542, 'const': 172, 'code+const': 714}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
b =[]
l =[]
for i in range(10000):
  b.append(0)
  l.append([])
for i in range(n):
  k,a,bb = map(int,input().split())
  l[k]=[a,bb]
m=int(input())
for i in range(m):
  mn=2e9
  s,e=map(int,input().split())
  for k in range(1,n+1):
    if l[k][0]>l[k][1]:
      if s<=l[k][0]and s >=l[k][1]:
        b[k]=abs(e-l[k][1])
      else:
        b[k]=abs(s-l[k][1])+abs(e-s)
      mn=min(mn,b[k])
    elif l[k][0]<l[k][1]:
      if s>=l[k][0]and s<=l[k][1]:
        b[k]=abs(e-l[k][1])
      else:
        b[k]=abs(s-l[k][1])+abs(e-s)
      mn=min(mn,b[k])
    else:
      b[k]=abs(s-l[k][1])+abs(e-s)
      mn=min(mn,b[k])
  for k in range(1,n+1):
     if(mn==b[k]):
      print(f'>> {k}')
      break

6630066121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 754, 'const': 175, 'code+const': 929}
# HW02
n =int(input())
x = 0
lift = []
while x < n :
    lift_ = [int(e) for e in input().split()]
    lift.extend(lift_)
    x += 1
m = int(input())
y = 0
quiz = []
while y < m :
    quiz_ = [int(e) for e in input().split()]
    quiz.extend(quiz_)
    y += 1
diff = []
for k in range(m) :
    diff_ = []
    for j in range(n) :
        if lift[3*j+1] <= quiz[2*k] <= lift[3*j+2] <= quiz[2*k+1] or            lift[3*j+1] >= quiz[2*k] >= lift[3*j+2] >= quiz[2*k+1] :
            diff__ = abs(lift[3*j+2] - quiz[2*k+1])
        elif lift[3*j+1] <= quiz[2*k] <= quiz[2*k+1] <= lift[3*j+2] or            lift[3*j+1] >= quiz[2*k] >= quiz[2*k+1] >= lift[3*j+2] :
            diff__ = 0
        else :
            diff__ = abs(lift[3*j+2] - quiz[2*k]) + abs(quiz[2*k] - quiz[2*k+1])
        diff_.append(diff__)
    diff.append(diff_)
lift_n = []
for q in range(n) :
    lift_n.append(lift[3*q])
for r in range(m) :
    print('>>',lift_n[diff[r].index(min(diff[r]))])

6630067821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 600, 'const': 91, 'code+const': 691}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
number=int(input())
a=[0]*number
b=[0]*number
c=[0]*number
for i in range(number):
    x,y,z=input().split()
    a[i]=int(x)
    b[i]=int(y)
    c[i]=int(z)
zen=int(input())
d=[0]*zen
e=[0]*zen
for i in range(zen):
    r,n=input().split()
    d[i]=int(r)
    e[i]=int(n)
#test case math
cal1=[0]*number
for i in range(zen):
    for j in range(number):
        if b[j]<=d[i] and c[j]>=d[i]:
            cal=abs(c[j]-e[i])
        elif b[j]>=d[i] and c[j]<=d[i]:
            cal=abs(c[j]-e[i])
        elif d[i]<=b[j] and d[i]>=c[j] and e[i]<=b[j] and e[i]>=c[j]:
            cal=0
        elif d[i]>=b[j] and d[i]<=c[j] and e[i]>=b[j] and e[i]<=c[j]:
            cal=0
        else :
            cal=abs(abs(d[i]-c[j])+abs(e[i]-d[i]))
        cal1[j]=cal
    x=number
    for j in range(number):
        if min(cal1)==cal1[j]:
            if a[j]<=x:
                x=a[j]
    print(">>",x)

6630069021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1208, 'const': 175, 'code+const': 1383}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
nlift = int(input()) #รับจำนวนลิฟต์
a = [] #ลิสต์ใส่ลิฟต์
for i in range(nlift):
    a += input().split()
for n in range(len(a)):
    a[n] = int(a[n])
lift = [0]*3*nlift
for i in range(nlift):
    for o in range(nlift):
        if a[3*o] == i+1:
            lift[3*i],lift[3*i+1],lift[3*i+2] = a[3*o],a[3*o+1],a[3*o+2]
nkon = int(input()) #รับจำนวนคน
kon = [] #ลิสต์ใส่คน
for n in range(nkon):
    kon += input().split()
for n in range(len(kon)):
    kon[n] = int(kon[n])
for n in range(nkon): #คำนวณลิฟต์รายคน
    konn = kon[2*n:2*n+2:] #ชั้นที่อยู่ ชั้นที่ไป
    tier = []
    for i in range(nlift):
        liftt = lift[3*i:3*i+3:] #ลำดับ ที่อยู่ กำลังไป
        if liftt[1] < liftt[2]: #ลิฟต์ขึ้น
            if konn[1] > konn[0]: #คนขึ้น
                if liftt[1] <= konn[0] and liftt[2] >= konn[1]: # รับขึ้น แวะส่ง
                    tier += [0]
                elif liftt[1] <= konn[0] and liftt[2] < konn[1]:# รับขึ้น ขึ้นส่ง
                    tier += [konn[1] - liftt[2]]
                elif liftt[2] < konn[0]: # ขึ้นรับ ขึ้นส่ง
                    tier += [konn[1] - liftt[2]]
                elif liftt[1] > konn[0]:# ลงรับ ขึ้นส่ง
                    tier += [liftt[2] + konn[1] - 2*konn[0]]
            elif konn[1] < konn[0]:#คนลง
                if konn[0] >= liftt[2]:#ขึ้นรับ ลงส่ง
                    tier += [2*konn[0] - liftt[2] - konn[1]]
                elif konn[0] < liftt[2]:#ลงรับ ลงส่ง
                    tier += [liftt[2] - konn[1]]
        elif liftt[1] > liftt[2]: #ลิฟต์ลง
            if konn[1] > konn[0]: #คนขึ้น
                if konn[0] >= liftt[2]:#ขึ้นรับ ขึ้นส่ง
                    tier += [konn[1] - liftt[2]]
                elif konn[0] < liftt[2]:#ลงรับ ขึ้นส่ง
                    tier += [liftt[2] + konn[1] - 2*konn[0]]
            elif konn[1] < konn[0]:#คนลง
                if konn[0] <= liftt[1] and konn[1] >= liftt[2]:#รับลง แวะส่ง
                    tier += [0]
                elif konn[0] <= liftt[1] and konn[1] < liftt[2]:#รับลง ลงส่ง
                    tier += [liftt[2] - konn[1]]
                elif konn[0] < lift[2]:#ลงรับ ลงส่ง
                    tier += [liftt[2] - konn[1]]
                elif konn[0] > liftt[2]:#ขึ้นรับ ขึ้นส่ง
                    tier += [2*konn[0] - liftt[2] - konn[1]]
        elif liftt[1] == liftt[2]: #ลิฟต์จอด
            tier += [abs(konn[0] - liftt[1]) + abs(konn[0] - konn[1])]
    c = 0
    while tier[c] != min(tier):
        c += 1
    print('>>',c+1)

6630070621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 416, 'const': 147, 'code+const': 563}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
l = []
p = []
x = int(0)
g = []
for i in range(1,n+1):
    l.append(input().split())
m = int(input())
for j in range(m):
    p.append(input().split())
for j in range(m):
    for i in range(n):
        sl=int(l[i][1])
        el=int(l[i][2])
        sp=int(p[j][0])
        ep=int(p[j][1])
        if min(sl,el) <= sp <= max(sl,el):
            if min(sl,el) <= ep <= max(sl,el):
                if (sl>el and sp>ep) or (sl<el and sp<ep):
                    x = 0
                else:
                    x = abs(el - ep)
            else:
                x = abs(el - ep)
        else:
            x = abs(el - sp) + abs(ep - sp)
        g.append([x,l[i][0]])
    A = min(g)
    B = A[1]
    print(">>",B)
    g = []

6630072921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 716, 'const': 147, 'code+const': 863}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
num_lift = []
start_lift = []
end_lift = []
for i in range(n):
    d1 = input().split()
    num_lift.append(int(d1[0]))
    start_lift.append(int(d1[1]))
    end_lift.append(int(d1[2]))
m = int(input())
start_me = []
end_me = []
for i in range(m):
    d2 = input().split()
    start_me.append(int(d2[0]))
    end_me.append(int(d2[1]))
for i in range(m):
    para = []
    for k in range(n):
        direc_me = end_me[i] - start_me[i]
        direc_lift = end_lift[k] - start_lift[k]
        if direc_lift < 0 and direc_me < 0:
            if end_lift[k] <= end_me[i] <= start_me[i] <= start_lift[k]:
                para.append(0)
            elif end_lift[k] <= start_me[i] <= start_lift[k]:
                para.append(abs(end_me[i] - end_lift[k]))
            else:
                para.append(abs(end_lift[k] - start_me[i]) + abs(start_me[i] - end_me[i]))
        elif direc_lift > 0 and direc_me > 0:
            if start_lift[k] <= start_me[i] <= end_me[i] <= end_lift[k]:
                para.append(0)
            elif start_lift[k] <= start_me[i] <= end_lift[k]:
                para.append(abs(end_me[i] - end_lift[k]))
            else:
                para.append(abs(end_lift[k] - start_me[i]) + abs(start_me[i] - end_me[i]))
        else:
            para.append(abs(end_lift[k] - start_me[i]) + abs(start_me[i] - end_me[i]))
    min_para = min(para)
    ans = num_lift[para.index(min_para)]
    print('>>', ans)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630073521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 598, 'const': 215, 'code+const': 813}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# Elevators Input
n = int(input())
elevators = [0] * n
for i in range(n):
    x, y, z = [int(j) for j in input().split()]
    while x < 1 or x > n or y < 1 or z < 1:
        print("INVALID")
        x, y, z = [int(j) for j in input().split()]
    elevators[x - 1] = [y, z]
# Users Input
m = int(input())
users = []
for i in range(m):
    x, y = [int(j) for j in input().split()]
    users.append( [x, y] )
def calculate_step(user, elevator):
    user_from, user_to = user
    elevator_from, elevator_to = elevator
    is_same_way = (elevator_to <= elevator_from) == (user_to <= user_from)
    going_up = elevator_to > elevator_from
    step = 0
    # ลิฟท์มารับ
    if not is_same_way: # going wrong way
        step += abs(elevator_to - user_from)
    elif elevator_from == elevator_to: # stuck
        step += abs(elevator_from - user_from)
    elif going_up and (elevator_from > user_from or elevator_to < user_from): # going up
        step += abs(elevator_to - user_from)
    elif not going_up and (elevator_to > user_from or elevator_from < user_from): # going down
        step += abs(elevator_to - user_from)
    # ลิฟท์ไปส่ง
    if step == 0:
        step += abs(user_to - elevator_to)
    else:
        step += abs(user_to - user_from)
    return step
for user in users:
    steps = []
    for elevator in elevators:
        steps.append(calculate_step(user, elevator))
    lowest = min(steps)
    elevator_number = steps.index(lowest) + 1
    print(">>", elevator_number)

6630081521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 654, 'const': 198, 'code+const': 852}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
nlif = int(input())
x = [""]*nlif
for i1 in range(nlif) :
    x[i1] = input().split()
nhow = int(input())
y = [""]*nhow
for i2 in range(nhow) :
    y[i2] = input().split()
i=0
ii=0
count=[0]*nlif
while ii<nhow :
    i=0
    ya = int(y[ii][0])
    yb = int(y[ii][1])
    while i<nlif :
        xa = int(x[i][1])
        xb = int(x[i][2])
        if xa<xb : #ลิฟขึ้น
            if ya<yb : #คนขึ้น
                if xa<=ya<=xb and xa<=yb<=xb:#ทางผ่าน
                    z=0
                elif xa<=ya<=xb :#รับทางผ่าน ต้องไปส่ง
                    z=abs(yb-xb)
                else :#ไปรับไปส่ง
                    z=abs(xb-ya)+abs(ya-yb)
            elif yb<ya : #คนลง
                z=abs(xb-ya)+abs(ya-yb)
            else : #คนชั้นเดิม
                pass
        elif xb<xa : #ลิฟลง
            if yb<ya : #คนลง
                if xb<=ya<=xa and xb<=yb<=xa:#ทางผ่าน
                    z=0
                elif xb<=ya<=xa :#รับทางผ่าน ต้องไปส่ง
                    z=abs(yb-xb)
                else :#ไปรับไปส่ง
                    z=abs(xb-ya)+abs(ya-yb)
            elif ya<yb : #คนขึ้น
                z=abs(xb-ya)+abs(ya-yb)
            else : #คนชั้นเดิม
                pass
        else : #ลิฟจอดชั้นเดิม
            z=abs(xa-ya)+abs(ya-yb)
        count[i]=z
        i+=1
    ans = count.index(min(count))
    print(">>",x[ans][0])
    ii+=1

6630085021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 666, 'const': 91, 'code+const': 757}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
l_s=[0]*n
l_d=[0]*n
num=[0]*n
for i in range(n):
    x,y,z=[int(e) for e in input().split()]
    l_s[i]=y
    num[i]=x
    l_d[i]=z
n1=int(input())
u_s=[0]*n1
u_d=[0]*n1
for j in range(n1):
    a,b=[int(e) for e in input().split()]
    u_s[j]= a
    u_d[j]= b
result=[0]*n
for i in range(n1):
    for j in range(n):
        if l_s[j] <=u_s[i] <=l_d[j] and l_s[j] <= u_d[i] <=l_d[j] and u_s[i]<=u_d[i]:
            re=0
        elif l_s[j] >=u_s[i] >=l_d[j] and l_s[j] >= u_d[i] >=l_d[j] and u_s[i]>=u_d[i]:
            re=0
        elif l_s[j]<=u_s[i] and l_d[j] >=u_s[i]:
            re=abs(u_d[i]-l_d[j])
        elif l_s[j]>=u_s[i] and l_d[j] <=u_s[i]:
            re=abs(u_d[i]-l_d[j])
        else:
            re=abs(u_d[i]-u_s[i])+abs(u_s[i]-l_d[j])
        result[j]=re
    for i in range(len(result)):
        min_x= result.index(min(result))
    print('>>',num[min_x])

6630087321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
[['1', '3', '1', 'd'], ['2', '1', '8', 'u'], ['3', '2', '2', 's'], ['4', '12', '3', 'd']]
>> 2
>> 4
>> 1
[]
test_main_21.0
[['1', '3', '1', 'd'], ['2', '2', '8', 'u'], ['3', '10', '10', 's'], ['4', '12', '6', 'd']]
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
[['1', '2', '2', 's'], ['2', '4', '4', 's'], ['3', '6', '6', 's'], ['4', '8', '8', 's']]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
[['1', '8', '11', 'u'], ['2', '6', '9', 'u'], ['3', '4', '7', 'u'], ['4', '2', '5', 'u']]
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
[['1', '6', '2', 'd'], ['2', '8', '4', 'd'], ['3', '12', '8', 'd'], ['4', '10', '6', 'd']]
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
[['1', '8', '11', 'u'], ['2', '6', '9', 'u'], ['3', '4', '7', 'u'], ['4', '2', '5', 'u']]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
[['1', '6', '2', 'd'], ['2', '8', '4', 'd'], ['3', '12', '8', 'd'], ['4', '10', '6', 'd']]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
[['2', '5', '2', 'd'], ['1', '2', '5', 'u'], ['3', '7', '10', 'u'], ['6', '10', '7', 'd'], ['5', '12', '15', 'u'], ['4', '15', '12', 'd']]
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 600, 'const': 470, 'code+const': 1070}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def main():
    totalLift = int(input())
    liftCollection = list()
    for _ in range(totalLift):
        lift = input().split()
        state = isUpOrDown(int(lift[1]), int(lift[2]))
        lift.append(state)
        liftCollection.append(lift)
    print(liftCollection)
    totalHuman = int(input())
    for _ in range(totalHuman):
        start, end = input().split()
        state = isUpOrDown(int(start), int(end))
        result = list()
        for lift in liftCollection:
            extraWork = 0
            liftNo = lift[0]
            liftStartFloor = int(lift[1])
            liftEndFloor = int(lift[2])
            liftState = lift[3]
            if(liftState == state and isBetweenProcess(liftStartFloor, liftEndFloor, int(start))):
                if end in range(min(liftStartFloor, liftEndFloor), max(liftStartFloor, liftEndFloor)+1):
                    extraWork = 0
                else :
                    extraWork = abs(liftEndFloor - int(end))
                result.append([liftNo, extraWork])
                continue
            extraWork = abs(liftEndFloor - int(start)) + abs(int(start) - int(end))
            result.append([liftNo, extraWork])
        print(">> " + getLeastValue(result))
def isUpOrDown(floorStart, floorEnd):
    # u = up
    # d = down
    # s = stay
    if(floorStart < floorEnd):
        return 'u'
    if(floorStart > floorEnd):
        return 'd'
    return 's'
def isBetweenProcess(liftStartFloor, liftEndFloor, start):
    floorRange = range(min(liftStartFloor, liftEndFloor), max(liftStartFloor, liftEndFloor)+1)
    return start in floorRange
def getLeastValue(collection):
    tempNo = collection[0][0]
    tempValue = collection[0][1]
    for result in collection:
        if(result[1] < tempValue):
            tempNo = result[0]
            tempValue = result[1]
        elif(result[1] == tempValue):
            if int(result[0]) < int(tempNo):
              tempNo = result[0]
              tempValue = result[1]
    return tempNo
main()
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630088021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 600, 'const': 91, 'code+const': 691}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
number=int(input())
a=[0]*number
b=[0]*number
c=[0]*number
for i in range(number):
    x,y,z=input().split()
    a[i]=int(x)
    b[i]=int(y)
    c[i]=int(z)
jumnungchan=int(input())
d=[0]*jumnungchan
e=[0]*jumnungchan
for i in range(jumnungchan):
    r,n=input().split()
    d[i]=int(r)
    e[i]=int(n)
#test case math
cal1=[0]*number
for i in range(jumnungchan):
    for j in range(number):
        if b[j]<=d[i] and c[j]>=d[i]:
            cal=abs(c[j]-e[i])
        elif b[j]>=d[i] and c[j]<=d[i]:
            cal=abs(c[j]-e[i])
        elif d[i]<=b[j] and d[i]>=c[j] and e[i]<=b[j] and e[i]>=c[j]:
            cal=0
        elif d[i]>=b[j] and d[i]<=c[j] and e[i]>=b[j] and e[i]<=c[j]:
            cal=0
        else :
            cal=abs(abs(d[i]-c[j])+abs(e[i]-d[i]))
        cal1[j]=cal
    x=number
    for j in range(number):
        if min(cal1)==cal1[j]:
            if a[j]<=x:
                x=a[j]
    print(">>",x)

6630089621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 600, 'const': 91, 'code+const': 691}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
l=int(input())
a=[0]*l
b=[0]*l
c=[0]*l
for i in range(l):
  d,e,f=input().split()
  a[i]=int(d)
  b[i]=int(e)
  c[i]=int(f)
q=int(input())
g=[0]*q
h=[0]*q
for i in range(q):
  k,m=input().split()
  g[i]=int(k)
  h[i]=int(m)
loadall=[0]*l
for i in range(q):
    for j in range(l):
        if b[j]<=g[i] and c[j]>=g[i]:
            load=abs(c[j]-h[i])
        elif b[j]>=g[i] and c[j]<=g[i]:
            load=abs(c[j]-h[i])
        elif g[i]<=b[j] and g[i]>=c[j] and h[i]<=b[j] and h[i]>=c[j]:
            load=0
        elif g[i]>=b[j] and g[i]<=c[j] and h[i]>=b[j] and h[i]<=c[j]:
            load=0
        else :
            load=abs(abs(g[i]-c[j])+abs(h[i]-g[i]))
        loadall[j]=load
    x=l
    for j in range(l):
       if min(loadall)==loadall[j]:
              if a[j]<=x:
                   x=a[j]
    print(">>",x)

6630091821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 498, 'const': 203, 'code+const': 701}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
elevator_no = []
start = []
stop = []
for i in range(n):
    ss = input().split()
    elevator_no.append(int(ss[0]))
    start.append(int(ss[1]))
    stop.append(int(ss[2]))
question = int(input())
ans = []
while(question):
    question -= 1
    ss = input().split()
    qstart = int(ss[0])
    qstop = int(ss[1])
    mincost = 99999999999999999999999999999999999999999999999999999999999999999999
    ans_elevator = 0
    for i in range(n):
        if (start[i]<=qstart<=qstop<=stop[i] or stop[i]<=qstop<=qstart<=start[i]):
              mincost = abs(qstart-qstop)
              ans_elevator = i
        elif(start[i]<=qstart<=stop[i] or stop[i]<=qstart<=start[i]):
            if(mincost > abs(stop[i]-qstop)):
                mincost = abs(stop[i]-qstop)
                ans_elevator = i
        else:
            if(mincost > abs(stop[i]-qstart)+abs(qstop-qstart)):
                mincost = abs(stop[i]-qstart)+abs(qstop-qstart)
                ans_elevator = i
    ans.append(elevator_no[ans_elevator])
for a in ans: print(">>"+ str(a))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6630093021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1216, 'const': 148, 'code+const': 1364}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
info = [0] * n
for i in range(n) :
    info[i] = input()
q = int(input())
want = [0] * q
for j in range(q) :
    want[j] = input()
for k in range(q) :
    b = want[k].split()
    s = [0] * n
    for l in range(n) :
        a = info[l].split()
        if int(a[1]) > int(a[2]) and int(b[0]) > int(b[1]) :
            if int(a[1]) >= int(b[0]) :
                s[l] = int(a[2]) - int(b[1])
                if s[l] > 0 :
                    s[l] = s[l]
                else :
                    s[l] = 0
            else :
                s[l] = (int(b[0]) - int(a[2])) + (int(b[0]) - int(b[1]))
        elif int(a[2]) > int(a[1]) and int(b[0]) > int(b[1]) :
            if int(a[2]) > int(b[0]) :
                s[l] = int(a[2]) - int(b[1])
            else :
                s[l] = (int(b[0]) - int(a[2])) + (int(b[0]) - int(b[1]))
        elif int(a[1]) > int(a[2]) and int(b[1]) > int(b[0]) :
            if int(a[2]) > int(b[0]) :
                s[l] = (int(a[2]) - int(b[0])) + (int(b[1]) - int(b[0]))
            else :
                s[l] = (int(b[0]) - int(a[2])) + (int(b[1]) - int(b[0]))
        elif int(a[2]) > int(a[1]) and int(b[1]) > int(b[0]) :
            if int(a[1]) > int(b[0]) :
                s[l] = (int(a[2]) - int(b[0])) + (int(b[1]) - int(b[0]))
            else :
                s[l] = int(b[1]) - int(a[2])
        elif int(a[1]) == int(a[2]) and int(b[0]) > int(b[1]) :
            if int(a[1]) > int(b[0]) :
                s[l] = int(a[1]) - int(b[1])
            else :
                s[l] = (int(b[0]) - int(a[1])) + (int(b[0]) - int(b[1]))
        else :
            s[l] = abs(int(a[1]) - int(b[0])) + (int(b[1]) - int(b[0]))
    y = 0
    z = 0
    for m in range(n) :
        if min(s) == s[m] :
            y += 1
    out = [0] * y
    for p  in range(n) :
        if min(s) == s[p] :
            r = info[p].split()
            out[z] = r[0]
            z += 1
    print('>> ' + str(min(out)))

6630098221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 614, 'const': 122, 'code+const': 736}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = [0]*(n+1)
for i in range(n):
  x=[int(a) for a in input().split()]
  lift[x[0]]=x[1:]
m=int(input())
for i in range(m):
  s,e=[int(a) for a in input().split()]
  for i in range(1,n+1):
    if (s-e)*(lift[i][0]-lift[i][1])<0:
      y = abs(lift[i][1]-s) + abs(e-s)
    elif lift[i][1]>lift[i][0] and s>=lift[i][0] and e<=lift[i][1]:
      y=0
    elif lift[i][1]<lift[i][0] and s<=lift[i][0] and e>=lift[i][1]:
      y=0
    elif lift[i][1]>lift[i][0] and s>=lift[i][0] and e>=lift[i][1]:
      y=abs(e-lift[i][1])
    elif lift[i][1]<lift[i][0] and s<=lift[i][0] and e<=lift[i][1]:
      y=abs(e-lift[i][1])
    else:
      y = abs(lift[i][1]-s) + abs(e-s)
    if i==1 or y<mn:
      mn=y
      num=i
  print('>> {}'.format(num))

6630174221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1530, 'const': 199, 'code+const': 1729}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# Input number of elevators
n = int(input())
elevators = []
# Input elevator details
for _ in range(n):
    elevator_info = input().split()
    elevator_number = int(elevator_info[0])
    start = int(elevator_info[1])
    stop = int(elevator_info[2])
    elevators.append([elevator_number, start, stop])
# Input number of questions
m = int(input())
# Process each question and find the best elevator
for _ in range(m):
    f1, f2 = map(int, input().split())
    best_elevator = None
    min_work = float('inf')
    for elevator in elevators:
        elevator_number = elevator[0]
        start = elevator[1]
        stop = elevator[2]
        if (start <= stop <= f1 <= f2):
            work = abs(f1 - f2) + f1 - stop
        elif (start <= f1 <= stop <= f2):
            work = f2 - stop
        elif (start <= f1 <= f2 <= stop):
            work = 0
        elif (start <= f2 <= f1 <= stop):
            work = stop - f1 + f1 - f2
        elif (start <= f2 <= stop <= f1):
            work = f1 - stop + f1 - f2
        elif (start <= stop <= f2 <= f1):
            work = f1 - stop + f1 - f2
        elif (f1 <= start <= stop <= f2):
            work = stop - f1 + f2 - f1
        elif (f1 <= start <= f2 <= stop):
            work = stop - f1 + f2 - f1
        elif (f1 <= f2 <= start <= stop):
            work = stop - f1 + f2 - f1
        elif (f1 <= f2 <= stop <= start):
            work = stop - f1
        elif (f1 <= stop <= start <= f2):
            work = stop - f1 + f2 - f1
        elif (f1 <= stop <= f2 <= start):
            work = stop - f1 + f2 - f1
        elif (stop <= start <= f1 <= f2):
            work = f2 - stop
        elif (stop <= start <= f2 <= f1):
            work = f1 - stop + f1 - f2
        elif (stop <= f1 <= start <= f2):
            work = f1 - stop + f2 - f1
        elif (stop <= f1 <= f2 <= start):
            work = f2 - stop
        elif (stop <= f2 <= f1 <= start):
            work = 0
        elif (stop <= f2 <= start <= f1):
            work = f1 - stop + f1 - f2
        elif(f2 <= f1 <= start <= stop):
            work = stop - f1 + f1 - f2
        elif(f2 <= f1 <= stop <= start):
            work = stop - f2
        elif(f2 <= start <= f1 <= stop):
            work = stop - f1 + f1 - f2
        elif(f2 <= start <= stop <= f1):
            work = f1 - stop + f1 - f2
        elif(f2 <= stop <= f1 <= start):
            work = stop - f2
        elif(f2 <= stop <= start <= f1):
            work = f1 - stop + f1 - f2
        if work < min_work:
            min_work = work
            best_elevator = elevator_number
    print(">>", best_elevator)

6630220421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 716, 'const': 147, 'code+const': 863}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
num_lift = []
start_lift = []
end_lift = []
for i in range(n) :
    a1 = input().split()
    num_lift.append(int(a1[0]))
    start_lift.append(int(a1[1]))
    end_lift.append(int(a1[2]))
m =int(input())
start_me = []
end_me = []
for i in range(m) :
    a2 = input().split()
    start_me.append(int(a2[0]))
    end_me.append(int(a2[1]))
for i in range(m) :
    para = []
    for p in range(n) :
        direc_me = end_me[i] - start_me[i]
        direc_lift = end_lift[p] - start_lift[p]
        if direc_lift < 0 and direc_me < 0 :
            if end_lift[p] <=end_me[i] <= start_me[i] <=start_lift[p] :
                para.append(0)
            elif end_lift[p] <= start_me[i] <=start_lift[p] :
                para.append(abs(end_me[i] - end_lift[p]))
            else :
                para.append(abs(end_lift[p] - start_me[i]) + abs(start_me[i] - end_me[i]))
        elif direc_lift > 0 and direc_me > 0 :
            if start_lift[p]<= start_me[i] <= end_me[i] <= end_lift[p] :
                para.append(0)
            elif start_lift[p] <= start_me[i] <= end_lift[p] :
                para.append(abs(end_me[i] - end_lift[p]))
            else :
                para.append(abs(end_lift[p] -start_me[i]) + abs(start_me[i] - end_me[i]))
        else :
            para.append(abs(end_lift[p] - start_me[i]) + abs(start_me[i] - end_me[i]))
    min_para = min(para)
    ans = num_lift[para.index(min_para)]
    print('>>', ans )

6630221021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 730, 'const': 147, 'code+const': 877}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
N = int(input())
Elevator = []
Sawaddee = []
for i in range(N):
    x = input().split()
    Sawaddee.append(x)
Sawaddee.sort()
for i in range(len(Sawaddee)):
    x = Sawaddee[i][1:]
    Elevator.append(x)
n = int(input())
Human = []
for i in range(n):
    x = input().split()
    Human.append(x)
Win = []
#-----------------------------------------------------------
for i in range(len(Human)): # เช็คทีละคน
    winner = 0
    hstart,hstop = int(Human[i][0]) , int(Human[i][1])
    hh = hstop - hstart
    # ไปทางเดียวกับลิฟต์
        #ระหว่างทาง
        #ลิฟต์เลยไป
    #ไปคนละทางกับลิฟต์
        #ลิฟต์ย้อนกลับ
    min = 100000000
    for j in range(len(Elevator)):
        movesneeded = 0
        estart,estop = int(Elevator[j][0]),int(Elevator[j][1])
        ee = estop - estart
        #ไปทางเดียวกัน
        if hh > 0 and ee > 0: #ขึ้นเหมือนกัน
            if estart <= hstart <= estop: #ระหว่างทาง
                if hstop <= estop:
                    movesneeded = 0 #จอดระหว่างทาง
                else:#จอดเลยไปอีก
                    movesneeded = hstop - estop
            elif hstart > estop : #ลิฟต์ขึ้นยังไม่ถึง
                movesneeded = hstop - estop
            else:
                movesneeded = estop - hstart + (hstop-hstart) #อยู่ก่อนลิฟต์ รอลิฟต์ย้อนไปรับ
        elif hh < 0 and ee < 0: #ลิฟต์ลงเหมือนกัน
            if estart >= hstart >= estop: #ระหว่างทาง
                if hstop >= estop:
                    movesneeded = 0 #จอดระหว่างทาง
                else: #จอดเลยไปอีก
                    movesneeded = estop - hstop
            elif estop > hstart :#ลิฟต์ลงยังไม่ถึง
                movesneeded = estop - hstop
            else:
                movesneeded = hstart - estop + (hstart-hstop) #อยู่ก่อนลิฟต์ รอลิฟต์ย้อนไปรับ
        elif hh < 0 and ee > 0: #เราจะลง ลิฟต์ขึ้น
            if estop >= hstart:
                movesneeded = estop - hstart + (hstart-hstop)
            else:
                movesneeded = hstart - estop + (hstart-hstop)
        elif hh > 0 and ee < 0: #เราจะขึ้น ลิฟต์ลง
            if hstart >= estop:
                movesneeded = hstart - estop + (hstop-hstart)
            else:
                movesneeded = estop - hstart + (hstop-hstart)
        elif ee == 0:
                movesneeded = abs(estop-hstart) + abs(hstop-hstart)
        # เอา movesneeded ไปเทียบทีละตัวว่าถ้าตัวนี้น้อยกว่าตัวก่อนหน้าก็ให้ตัวนี้ชนะ
        if movesneeded < min:
            winner = j #เริ่มที่ 0 ลิฟต์ตัวที่ j+1
            min = movesneeded
        else:
            pass
    Win.append(winner)
for e in range(len(Human)):
    print(">>", Win[e]+1)

6630226221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 430, 'const': 199, 'code+const': 629}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
elevators = []
for i in range(n):
    Elevator = input().split()
    elevators.append([int(Elevator[0]), int(Elevator[1]), int(Elevator[2])])
m = int(input())
for i in range(m):
    Question = input().split()
    user_floor, user_target = int(Question[0]), int(Question[1])
    chosen_elavator = 0
    floor_work = float('inf')
    for i in range(n):
        Elevator = elevators[i]
        user = user_target - user_floor
        Elevator_move = Elevator[2] - Elevator[1]
        min_work = 0
        if user > 0 and Elevator_move > 0:
            if user_floor >= Elevator[1] and user_floor <= Elevator[2]:
                min_work = (user_target - Elevator[2])
            else:
                min_work = abs(user_floor - Elevator[2]) + abs(user_target - user_floor )
        elif user < 0 and Elevator_move < 0:
            if  user_floor <= Elevator[1] and user_floor >= Elevator[2]:
                min_work = (Elevator[2] - user_target)
            else:
                min_work = abs(user_floor - Elevator[2]) + abs(user_target - user_floor)
        else:
            min_work = abs(user_floor - Elevator[2]) + abs(user_target - user_floor)
        if min_work < floor_work:
            floor_work = min_work
            chosen_elavator = Elevator[0]
    print(">>", chosen_elavator)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631002121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 514, 'const': 147, 'code+const': 661}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
elev=[]
elev_cur=[]
elev_dest=[]
for i in range(n):
    inp=input().split()
    elev.append(int(inp[0]))
    elev_cur.append(int(inp[1]))
    elev_dest.append(int(inp[2]))
m=int(input())
ans=[]
for i in range(m):
    all_distances=[]
    inp=input().split()
    cur=int(inp[0])
    dest=int(inp[1])
    for e in range(n):
        if (dest-cur)*(elev_dest[e]-elev_cur[e])>=0: #in the same way
            if (elev_cur[e]<=cur<=elev_dest[e]) or (elev_dest[e]<=cur<=elev_cur[e]):
                all_distances.append(abs(elev_dest[e]-dest))
            else:
                all_distances.append(abs(elev_dest[e]-cur)+abs(cur-dest))
        else: #in opposite way
            if (elev_cur[e]<=cur<=elev_dest[e]) or (elev_dest[e]<=cur<=elev_cur[e]):
                all_distances.append(abs(elev_dest[e]-cur)+abs(cur-dest))
            else:
                all_distances.append(abs(elev_dest[e]-cur)+abs(cur-dest))
    ans.append(elev[all_distances.index(min(all_distances))])
for i in ans:
    print('>>',str(i))

6631004421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 674, 'const': 274, 'code+const': 948}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def df(a,b):
    return abs(a-b)
n_L = int(input())
L_n = []
L_i = []
L_f = []
for i in range(n_L):
    n,i,f = [int(i) for i in input().split()]
    L_n.append(n)
    L_i.append(i)
    L_f.append(f)
n_P = int(input())
P_i = []
P_f = []
for i in range(n_P):
    i,f = [int(i) for i in input().split()]
    P_i.append(i)
    P_f.append(f)
def drct(start,dest):
    if dest > start:
        direction = 1
    elif start > dest:
        direction = -1
    else:
        direction = 0
    return direction
def betw(start,dest,pos):
    if start >= pos >= dest or start <= pos <= dest:
        return True
    else:
        return False
b_L = []
for i in range(n_P):
    work_L = []
    for j in range(n_L):
        if drct(P_i[i],P_f[i]) == drct(L_i[j],L_f[j]) and betw(L_i[j],L_f[j],P_i[i]) and betw(L_i[j],L_f[j],P_f[i]):
            W = 0
            work_L.append(W)
        elif drct(P_i[i],P_f[i]) == drct(L_i[j],L_f[j]) and betw(L_i[j],L_f[j],P_i[i]):
            W = df(P_f[i],L_f[j])
            work_L.append(W)
        else:
            W = df(P_i[i],L_f[j]) + df(P_i[i],P_f[i])
            work_L.append(W)
    work_min = min(work_L)
    indices = work_L.index(work_min)
    b_L.append(L_n[indices])
for e in b_L:
    print(">> {}".format(e))

6631007321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 600, 'const': 91, 'code+const': 691}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
u = [0]*n
v = [0]*n
w = [0]*n
for i in range(n):
  f,g,h = input().split()
  u[i] = int(f)
  v[i] = int(g)
  w[i] = int(h)
m = int(input())
s = [0]*m
t = [0]*m
for i in range(m):
  p,q = input().split()
  s[i] = int(p)
  t[i] = int(q)
sleep = [0]*n
for i in range(m):
  for j in range(n):
      if v[j]<=s[i] and w[j]>=s[i]:
          KNK = abs(w[j]-t[i])
      elif v[j]>=s[i] and w[j]<=s[i]:
          KNK = abs(w[j]-t[i])
      elif s[i]<=v[j] and s[i]>=w[j] and t[i]<=v[j] and t[i]>=w[j]:
          KNK = 0
      elif s[i]>=v[j] and s[i]<=w[j] and t[i]>=v[j] and t[i]<=w[j]:
          KNK = 0
      else :
          KNK = abs(abs(s[i]-w[j])+abs(t[i]-s[i]))
      sleep[j] = KNK
  NK = n
  for j in range(n):
      if min(sleep) == sleep[j]:
          if u[j]<=NK:
              NK = u[j]
  print('>>',NK)

6631011821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 636, 'const': 338, 'code+const': 974}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
a=int(input())
liftnumber=[]
liftstart=[]
liftstop=[]
for i in range(a):
 number,start,stop=[int(i) for i in input().split()]
 liftnumber.append(number)
 liftstart.append(start)
 liftstop.append(stop)
b=int(input())
ppstart=[]
ppstop=[]
for i in range(b):
 start,stop=[int(i) for i in input().split()]
 ppstart.append(start)
 ppstop.append(stop)
def directions(start,stop):
  if stop > start:
    direction='up'
  elif stop < start:
    direction='down'
  else :
    direction='stationary'
  return direction
def between(start,current_pos,stop):
  if start <= current_pos <= stop or start >= current_pos >= stop:
    return True
  else :
    return False
ans_lift=[]
for i in range(b):
    num_of_lifts = []
    for j in range(a):
        if directions(ppstart[i],ppstop[i]) == directions(liftstart[j],liftstop[j])        and between(liftstart[j],ppstart[i],liftstop[j])        and between(liftstart[j],ppstop[i],liftstop[j]):
            n = 0
            num_of_lifts.append(n)
        elif directions(ppstart[i],ppstop[i]) == directions(liftstart[j],liftstop[j])        and between(liftstart[j],ppstart[i],liftstop[j]):
            n = abs(liftstop[j]-ppstop[i])
            num_of_lifts.append(n)
        else :
            n = abs(liftstop[j] - ppstart[i]) + abs(ppstop[i]-ppstart[i])
            num_of_lifts.append(n)
    mins = min(num_of_lifts)
    index = num_of_lifts.index(mins)
    print(">>",liftnumber[index])

6631012421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 414, 'const': 199, 'code+const': 613}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# lift information
amount_of_lift = int(input())
i = 0
all_lift = []
while i < amount_of_lift:
     order_lift = input().split()
     all_lift.append(order_lift)
     i += 1
# people information
amount_of_man = int(input())
j = 0
all_man = []
while j < amount_of_man:
     order_man = input().split()
     all_man.append(order_man)
     j += 1
#find the best lift for them
for person in all_man:
    person_start = int(person[0])
    person_dest = int(person[1])
    best_lift = None
    best_extra_work = float('inf')
    # Iterate through each lift
    for lift in all_lift:
        lift_order = int(lift[0])
        lift_start = int(lift[1])
        lift_dest = int(lift[2])
        # Calculate the extra work for this lift and person
        if lift_start <= person_start <= lift_dest and person_start - person_dest < 0: #in range go up
           if lift_dest >= person_dest:
              extra_work = 0
           else:
              extra_work = person_dest - lift_dest
        elif lift_start >= person_start >= lift_dest and person_start - person_dest > 0:#in range go down
           if lift_dest <= person_dest:
              extra_work = 0
           else:
              extra_work = abs(person_dest - lift_dest)
        else:                                                                       #out range
          extra_work = abs(person_start - person_dest) + abs(person_start - lift_dest)
        # Check if this lift is better than the current best lift
        if extra_work < best_extra_work :
            best_extra_work = extra_work
            best_lift = lift_order
        elif extra_work == best_extra_work :
            # If two lifts are equally good, choose the one with a lower order
            best_lift = min(best_lift, lift_order)
    print('>>',best_lift)

6631014721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 800, 'const': 147, 'code+const': 947}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
total_lift = int(input())
elevator_list = []
position = []
for i in range(total_lift):
    number,present_floor,dest_floor = [int(e) for e in input().split()]
    elevator_list.append([number,present_floor,dest_floor])
    position.append(number)
desire_list = []
total_prob = int(input())
for j in range(total_prob):
    present_user_floor,dest_floor_user = [int(e) for e in input().split()]
    desire_list.append([present_user_floor,dest_floor_user])
big_ans_list = []
for i in desire_list:
    Us = i[0]
    Ud = i[1]
    small_ans_list = []
    for j in elevator_list:
        Ls = j[1]
        Ld = j[2]
        total_floor = 0
        if(Ls>Ld) and (Us<Ud): #ลิฟลง คนขึ้น ***
            if (Ld>Us):
                total_floor = Ld-Us+Ud-Us
            else:
                total_floor = Ud-Ld
        if(Ld>Ls) and (Us>Ud):#ลิฟขึ้น คนลง ***
            if (Ld < Us):
                total_floor = Us-Ld+Us-Ud
            if (Ld==Us):
                total_floor = Us-Ud
            if (Ld>Us):
                total_floor = Ld-Ud
        if (Ld>Ls) and (Ud>Us): # ลิฟขึ้น คนขึ้น ***
            if (Ls==Us):
                if (Ld>=Ud):
                    total_floor = 0
                else:
                    total_floor = Ud-Ld
            if (Us>Ls):
                total_floor = Ud-Ld
            if (Us<Ls):
                total_floor = Ld-Us+Ud-Us
        if (Ls>Ld) and (Us>Ud): #ลิฟลง คนลง  ***
            if (Us>Ls):
                total_floor = Us-Ld+abs(Us-Ud)
            if (Ls==Us):
                if(Ld>Ud):
                    total_floor = Ld-Ud
                else:
                    total_floor = 0
            if (Ls>Us) and (Ld<Us):
                if (Ud>=Ld):
                    total_floor = 0
                else:
                    total_floor = Ld - Ud
            if (Ld==Us):
                total_floor = Ld-Ud
            if (Ld>Us):
                total_floor = Ld-Ud
        if (Ls==Ld): #ลิฟอยู่กับที่
            if (Ud>Us):
                if (Us>=Ls):
                    total_floor = Ud-Ls
                else:
                    total_floor = Ls-Us + Ud - Us
            if(Ud<Us):
                if(Us>Ls):
                    total_floor = Us-Ls+Us-Ud
                else:
                    total_floor = Ls-Ud
        small_ans_list.append(total_floor)
    big_ans_list.append(small_ans_list)
for i in big_ans_list:
    min_val = min(i)
    min_index = i.index(min_val) + 1
    print(">>",position[min_index-1])

6631027921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 568, 'const': 148, 'code+const': 716}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
Lift = []
load = []
for i in range(n+1):
  Lift.append([])
  load.append(0)
for i in range(n):
  x,y,z = map(int,input().split())
  Lift[x]=[y,z]
k = int(input())
while k>0:
  k -= 1
  a,b = map(int,input().split())
  lowest = int(3000)
  for i in range(1,n+1):
    if Lift[i][0]>Lift[i][1]:
      if a <= Lift[i][0] and a >= Lift[i][1]:
        load[i] = abs(b - Lift[i][1])
      else:
        load[i] = abs(a-Lift[i][1])+abs(a-b)
      lowest = min(lowest,load[i])
    elif Lift[i][0]<Lift[i][1]:
      if a >= Lift[i][0] and a <= Lift[i][1]:
        load[i] = abs(b - Lift[i][1])
      else:
        load[i] = abs(a-Lift[i][1])+abs(a-b)
      lowest = min(lowest,load[i])
    else:
      load[i] = abs(a-Lift[i][0])+abs(a-b)
    lowest = min(lowest,load[i])
  for i in range(1,n+1):
   if lowest == load[i]:
      print (f'>> {i}')
      break

6631028521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 580, 'const': 784, 'code+const': 1364}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้\
n = int(input("ระบุจำนวนลิฟต์ที่มี: "))
lift_num = []        # ลิฟต์หมายเลข
lift_a = []            # จุดปัจจุบันของลิฟต์
lift_b = []            # จุดที่จะไปของลิฟต์
lift_c = []            # มากกว่า 0 ลง / น้อยกว่า 0 ขึ้น / เท่ากับ 0 แปลว่าอยู่กับที่
for i in range(n):
    lift_numm, lift_aa, lift_bb = map(int, input("หมายเลขลิฟต์ เลขชั้นปัจจุบันของลิฟต์ และชั้นปลายทางที่ลิฟต์กำลังเคลื่อนที่ไป (คั่นด้วยช่องว่าง): ").split())
    lift_cc = lift_aa - lift_bb
    lift_num.append(lift_numm)
    lift_a.append(lift_aa)
    lift_b.append(lift_bb)
    lift_c.append(lift_cc)
length = [0] * n
m = int(input("ระบุจำนวนคำถามที่มี: "))
while m > 0:
    start, end = map(int, input("แทนเลขชั้นที่เราอยู่ กับเลขชั้นที่เราอยากไป: ").split())
    for i in range(n):
        if (start >= lift_a[i] and start <= lift_b[i]) or (start <= lift_a[i] and start >= lift_b[i]):
            length[i] = abs(end - lift_b[i])
            if end <= lift_b[i] and (start >= lift_a[i] and start <= lift_b[i]) and end >= start:
                length[i] = 0
            if end >= lift_a[i] and (start <= lift_a[i] and start >= lift_b[i]) and start >= end:
                length[i] = 0
        elif lift_c[i] != 0:
            length[i] = abs(start - lift_b[i]) + abs(end - start)
        elif lift_c[i] == 0:
            length[i] = abs((start - lift_b[i])) + abs((end - start))
    min_length = length[0]
    min_lift = lift_num[0]
    for i in range(n):
        if min_length > length[i]:
            min_length = length[i]
            min_lift = lift_num[i]
        elif min_length == length[i]:
            if lift_num[i] < min_lift:
                min_lift = lift_num[i]
    print(f">> {min_lift}")
    m -=1 #เพื่อจบคำถามการ input ของจำนวนคำถามที่ใส่

6631101621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 404, 'const': 191, 'code+const': 595}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
Elevator = []
for i in range(n):
    x = input().split()
    for i in range(len(x)):
        x[i] = int(x[i])
    Elevator.append(x)
def oper(Elevator,B):
    min = 100
    for i in range(len(Elevator)):
        L = 0
        estart = Elevator[i][1]
        eend = Elevator[i][2]
        pplstart = B[0]
        pplend = B[1]
        if eend - estart == 0:
            L = abs(estart - pplstart) + abs(pplstart - pplend)
        elif (estart <= pplstart and pplstart <= eend) or (estart >= pplstart and pplstart >= eend):
            L = abs(eend - pplend)
        else:
            L = abs(eend - pplstart) + abs(pplstart - pplend)
        if L < min:
            min = L
            use = Elevator[i][0]
    return use
ans = []
m = int(input())
for i in range(m):
    s = input().split()
    for i in range(len(s)):
        s[i] = int(s[i])
    ans.append(oper(Elevator,s))
for i in ans: print(">>", i)

6631104521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 404, 'const': 191, 'code+const': 595}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lift = []
for i in range(n):
    x = input().split()
    for i in range(len(x)):
        x[i] = int(x[i])
    lift.append(x)
def oper(lift,dem):
    min = 100
    for i in range(len(lift)):
        dt = 0
        lf = lift[i][1]
        lfgo = lift[i][2]
        me = dem[0]
        mego = dem[1]
        if lfgo - lf == 0:
            dt = abs(lf - me) + abs(me - mego)
        elif (lf <= me and me <= lfgo) or (lf >= me and me >= lfgo):
            dt = abs(lfgo - mego)
        else:
            dt = abs(lfgo - me) + abs(me - mego)
        if dt < min:
            min = dt
            best = lift[i][0]
    return best
ans = []
m = int(input())
for i in range(m):
    s = input().split()
    for i in range(len(s)):
        s[i] = int(s[i])
    ans.append(oper(lift,s))
for i in ans: print(">>",i)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631109721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 454, 'const': 263, 'code+const': 717}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
def is_between(start, target, end):
    return (start <= target <= end) or (end <= target <= start)
def get_additional_work(elevator_start, elevator_end, person_start, person_end):
    if not is_between(elevator_start, person_start, elevator_end):
        return abs(elevator_end - person_start) + abs(person_start - person_end)
    elif (
        not is_between(elevator_start, person_end, elevator_end)
        or not is_between(person_start, person_end, elevator_end)
    ):
        return abs(elevator_end - person_end)
    else:
        return 0
def get_smart_lift_id(elevators, person_start, person_end):
    elevator_id = elevators[0]
    elevator_start = elevators[1]
    elevator_end = elevators[2]
    min_additional_work = get_additional_work(elevator_start, elevator_end, person_start, person_end)
    min_elevator_id = elevator_id
    for i in range(3, len(elevators), 3):
        elevator_id = elevators[i]
        elevator_start = elevators[i+1]
        elevator_end = elevators[i+2]
        curr_additional_work = get_additional_work(elevator_start, elevator_end, person_start, person_end)
        if (
            curr_additional_work < min_additional_work
            or (curr_additional_work == min_additional_work and elevator_id < min_elevator_id)
        ):
            min_additional_work = curr_additional_work
            min_elevator_id = elevator_id
    return min_elevator_id
def main():
    elevator_count = int(input())
    elevators = []
    for j in range(elevator_count):
        elevators.extend(list(map(int, input().split())))
    people_count = int(input())
    for j in range(people_count):
        person_start, person_end = input().split()
        person_start = int(person_start)
        person_end = int(person_end)
        print(">>", get_smart_lift_id(elevators, person_start, person_end))
main()
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631111921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 398, 'const': 171, 'code+const': 569}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input()) #รับจำนวนลิฟต์ที่มี
ele_num = []  # สร้างลิสต์เลขลิฟต์แต่ละตัว
ele_now = []  # สร้างลิสต์เชั้นปัจจุบันของลิฟต์
ele_to = []  # สร้างลิสต์เชั้นปลายทางของลิฟต์ที่กำลังไป
for i in range(n):
    info = input().split()
    ele_num.append(int(info[0]))
    ele_now.append(int(info[1]))
    ele_to.append(int(info[2]))
m = int(input()) #รับจำนวนคำถามที่มี
ans = [] #สร้างลิสต์คำตอบ
while(m):
    m -= 1
    que = input().split()
    now = int(que[0]) #เลขชั้นที่เราอยู่
    goal = int(que[1]) #เลขชั้นที่เราอยากไป
    minn = 2e18
    idx = 0
    for i in range(n):
        if(ele_now[i] <= now <= ele_to[i] or ele_to[i] <= now <= ele_now[i]):
            if(minn > abs(ele_to[i] - goal)):
                minn = abs(ele_to[i] - goal)
                idx = i
        else:
            if(minn > abs(ele_to[i] - now) + abs(goal - now)):
                minn = abs(ele_to[i] - now) + abs(goal - now)
                idx = i
    ans.append(ele_num[idx])
for k in ans: print(">>" + str(k))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631113121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 380, 'const': 229, 'code+const': 609}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator = []
question = []
x=int(input())
while x>0:
    y = input().split(" ")
    elevator.append(y)
    x = x-1
x=int(input())
while x>0:
    y = input().split(" ")
    question.append(y)
    x = x-1
for i in question:
    min = 10**10
    for j in elevator:
        p = 0
        startman = int(i[0])
        desman = int(i[1])
        startelevator = int(j[1])
        deselevator = int(j[2])
        if deselevator > startelevator :
            a = startelevator
            b = deselevator
        else:
            a = deselevator
            b = startelevator
        if (startman-desman)*(startelevator-deselevator)>0:
            if startman >= a and startman <= b:
                if desman >= a and desman <= b:
                    p = 0
                else:
                    p = abs(deselevator-desman)
            else:
                p = abs(startman-deselevator)+abs(startman-desman)
        else:
            p = abs(startman-deselevator)+abs(startman-desman)
        if p < min:
            min = p
            ans = j[0]
    print(">>"+ans)

6631114821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 422, 'const': 199, 'code+const': 621}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevators = []
for _ in range(n):
    data = input().split()
    ee, x, y = int(data[0]), int(data[1]), int(data[2])
    elevators.append((ee, x, y))
m = int(input())
for _ in range(m):
    data = input().split()
    x, y = int(data[0]), int(data[1])
    best_elevator = 0
    min_work = float('inf')
    for ee, start, stop in elevators:
        if ((x >= start and x <= stop) and (y >= start and y <= stop) and (x <= y)):
            sum = 0
            if (sum < min_work):
                min_work = sum
                best_elevator = ee
        elif ((x <= start and x >= stop) and (y <= start and y >= stop) and (y <= x)):
            sum = 0
            if (sum < min_work):
                min_work = sum
                best_elevator = ee
        elif ((x >= start and x <= stop) or (x <= start and x >= stop)):
            sum = abs(y-stop)
            if (sum < min_work):
                min_work = sum
                best_elevator = ee
        else:
            sum = abs(stop - x) + abs(x - y)
            if (sum < min_work):
                min_work = sum
                best_elevator = ee
    print(">>", best_elevator)

6631124021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>> 2
>>> 4
>>> 1
[]
test_main_21.0
>>> 1
>>> 2
>>> 3
>>> 4
[]
test_main_31.0
>>> 1
>>> 1
>>> 1
>>> 2
>>> 2
>>> 3
>>> 3
>>> 4
>>> 4
[]
test_main_41.0
>>> 4
>>> 4
>>> 4
>>> 3
>>> 3
>>> 2
>>> 2
>>> 1
>>> 1
[]
test_main_51.0
>>> 3
>>> 3
>>> 3
>>> 4
>>> 4
>>> 2
>>> 2
>>> 1
>>> 1
>>> 1
>>> 1
>>> 1
[]
test_main_61.0
>>> 1
>>> 1
>>> 1
>>> 2
>>> 2
>>> 3
>>> 3
>>> 4
>>> 4
>>> 4
>>> 4
[]
test_main_71.0
>>> 1
>>> 1
>>> 1
>>> 2
>>> 2
>>> 4
>>> 3
>>> 3
>>> 3
>>> 3
>>> 3
>>> 3
[]
test_main_81.0
>>> 2
>>> 1
>>> 1
>>> 1
>>> 1
>>> 1
>>> 3
>>> 3
>>> 3
>>> 3
>>> 3
>>> 1
>>> 6
>>> 6
>>> 6
>>> 6
>>> 3
>>> 4
>>> 4
>>> 4
>>> 4
>>> 5
[]
bytecount: {'code': 570, 'const': 148, 'code+const': 718}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) #รับจำนวนตัวลิฟต์
ele = []
o = []
x= []
for i in range(n) :
    m = (input().split())
    ele.append(m)
ele.sort()
for j in range(len(ele)):
    o.append(int(ele[j][1]))
    x.append(int(ele[j][2]))
q = int(input()) #รับจำนวนคำถาม
t = []
u = []
y = []
for b in range(q) :
    p = (input().split())
    t.append(p)
for e in range(len(t)):
    u.append(int(t[e][1]))
    y.append(int(t[e][0]))#(
for i in range(q) :
    min_gu = []
    for j in range(n) :
        if u[i] > y[i] :#ทิศที่เราต้องการ=ขึ้น
            if x[j] > o[j] and o[j] <= y[i] <= x[j] :#ลิฟต์ขึ้น ผ่านเรา
               mmm = u[i]-x[j]
               if mmm < 0 :
                    mmm = 0
            else :
                 #ลิฟต์ขึ้น ไม่ผ่านเรา
                mmm = abs(y[i]-x[j]) + (u[i]-y[i])
        else :#ทิศที่เราต้องการจะลง
            if x[j] < o[j] and o[j] >= y[i] >= x[j] :
                mmm = x[j]-u[i]
                if mmm < 0 :
                    mmm = 0
            else :
              mmm = abs(x[j]-y[i]) + (y[i]-u[i])
        min_gu.append([mmm,j+1])
    print('>>>',min(min_gu)[1])

6631126321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 562, 'const': 172, 'code+const': 734}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = []
burden = []
for i in range(1000):
  lift.append([])
  burden.append(0)
for i in range(n):
   a,b,c = map(int,input().split())
   lift[a]=[b,c]
m = int(input())
while m>0:
  m -= 1
  mn = 2e9
  x,y = map(int,input().split())
  for i in range(1,n+1,1):
    if lift[i][0] > lift[i][1]:
      if x <= lift[i][0] and x >= lift[i][1]:
        burden[i] = abs(y-lift[i][1])
      else:
        burden[i] = abs(x-lift[i][1])+abs(x-y)
      mn = min(mn,burden[i])
    elif lift[i][0] < lift[i][1]:
      if x >= lift[i][0] and x <= lift[i][1]:
        burden[i] = abs(y-lift[i][1])
      else:
        burden[i] = abs(x-lift[i][1]) + abs(x-y)
      mn = min(mn,burden[i])
    else:
      burden[i] = abs(x-lift[i][1]) + abs(x-y)
      mn = min(mn,burden[i])
  for i in range(1,n+1,1):
    if(mn == burden[i]):
      print(f'>> {i}')
      break

6631130821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>  2
>>  4
>>  1
[]
test_main_21.0
>>  1
>>  2
>>  3
>>  4
[]
test_main_31.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
[]
test_main_41.0
>>  4
>>  4
>>  4
>>  3
>>  3
>>  2
>>  2
>>  1
>>  1
[]
test_main_51.0
>>  3
>>  3
>>  3
>>  4
>>  4
>>  2
>>  2
>>  1
>>  1
>>  1
>>  1
>>  1
[]
test_main_61.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  3
>>  3
>>  4
>>  4
>>  4
>>  4
[]
test_main_71.0
>>  1
>>  1
>>  1
>>  2
>>  2
>>  4
>>  3
>>  3
>>  3
>>  3
>>  3
>>  3
[]
test_main_81.0
>>  2
>>  1
>>  1
>>  1
>>  1
>>  1
>>  3
>>  3
>>  3
>>  3
>>  3
>>  1
>>  6
>>  6
>>  6
>>  6
>>  3
>>  4
>>  4
>>  4
>>  4
>>  5
[]
bytecount: {'code': 630, 'const': 148, 'code+const': 778}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = []
floor = []
des = []
n = int(input())
for i in range (n):
    a = input().split()
    for i in range (len(a)):
        a[i] = int(a[i])
    lift.append(a[0])
    floor.append(a[1])
    des.append(a[2])
mynow = []
mydes = []
m = int(input())
for i in range (m):
    a = input().split()
    for i in range (len(a)):
        a[i] = int(a[i])
    mynow.append(a[0])
    mydes.append(a[1])
ans = []
work = []
for i in range (m):
    for k in range(n):
        if floor[k] == des[k]:
            x = abs(mynow[i]-des[k]) + abs(mydes[i]-mynow[i])
            work.append(x)
        elif floor[k] < des[k]:
            if floor[k] <= mynow[i] <= des[k]:
                x = abs(mydes[i]-des[k])
            else:
                x = abs(mynow[i]-des[k]) + abs(mydes[i]-mynow[i])
            work.append(x)
        else:
            if floor[k] >= mynow[i] >= des[k]:
                x = abs(mydes[i]-des[k])
            else:
                x = abs(mynow[i]-des[k]) + abs(mydes[i]-mynow[i])
            work.append(x)
    y = work.index(min(work))
    ans.append(lift[y])
    work = []
for i in range (m):
    print('>> ',ans[i])

6631133721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 562, 'const': 172, 'code+const': 734}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = []
burden = []
for i in range(1000):
  lift.append([])
  burden.append(0)
for i in range(n):
  k,a,b = map(int,input().split())
  lift[k]=[a,b]
m = int(input())
while m>0:
  m -= 1
  mn = 2e9
  s,e = map(int,input().split())
  for i in range(1,n+1,1):
    if lift[i][0] > lift[i][1]:
      if s <= lift[i][0] and s >= lift[i][1]:
        burden[i] = abs(e-lift[i][1])
      else:
        burden[i] = abs(s-lift[i][1])+abs(e-s)
      mn = min(mn,burden[i])
    elif lift[i][0] < lift[i][1]:
      if s >= lift[i][0] and s <= lift[i][1]:
        burden[i] = abs(e-lift[i][1])
      else:
        burden[i] = abs(s-lift[i][1]) + abs(e-s)
      mn = min(mn,burden[i])
    else:
      burden[i] = abs(s-lift[i][1]) + abs(e-s)
      mn = min(mn,burden[i])
  for i in range(1,n+1,1):
    if(mn == burden[i]):
      print(f'>> {i}')
      break

6631137221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 288, 'const': 143, 'code+const': 431}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
x = int(input())
lifts = []
for i in range(x):
    number, lift_start, lift_stop = map(int, input().split())
    lifts.append((number, lift_start, lift_stop))
y = int(input())
for i in range(y):
    human_start, human_stop = map(int, input().split())
    min_cost = float('inf')
    best_lift = None
    for number, lift_start, lift_stop in lifts:
        if (lift_stop >= human_start >= lift_start or lift_stop <= human_start <= lift_start) and (lift_stop - lift_start) / (human_stop - human_start) > 0:
            cost = abs(human_stop - lift_stop)
        else:
            cost = abs(human_start - lift_stop) + abs(human_start - human_stop)
        if cost < min_cost or (cost == min_cost and number < best_lift):
            min_cost = cost
            best_lift = number
    print(">>", best_lift)

6631138921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 654, 'const': 199, 'code+const': 853}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
liftnumber = list()
delta = list()
for i in range(10**4):
    liftnumber.append([])
    delta.append(0)
for i in range(n):
    x,y,z = [int(e) for e in input().split()]
    liftnumber[x] = [y,z]
m  = int(input())
while m > 0 :
    m = m - 1
    bestlift = float("inf")
    stay,go = [int(e) for e in input().split()]
    for i in range (1,n+1) :
        if liftnumber[i][0] > liftnumber[i][1]:
            if liftnumber[i][1] <= stay <= liftnumber[i][0]:
                delta[i] = abs(go - liftnumber[i][1])
            else:
                delta[i] = abs(stay - liftnumber[i][1])+abs(go - stay)
            bestlift = min(bestlift,delta[i])
        elif liftnumber[i][1] > liftnumber[i][0]:
            if liftnumber[i][0] <= stay <= liftnumber[i][1]:
                delta[i] = abs(go - liftnumber[i][1])
            else:
                delta[i] = abs(stay - liftnumber[i][1])+abs(go - stay)
            bestlift = min(bestlift,delta[i])
        elif liftnumber[i][0] == liftnumber[i][1]:
            delta[i] = abs(stay - liftnumber[i][1])+abs(go - stay)
            bestlift = min(bestlift,delta[i])
    for i in range(1,n+1):
        if (bestlift == delta[i]):
            print('>>',i)
            break

6631139521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 600, 'const': 91, 'code+const': 691}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
number=int(input())
a=[0]*number
b=[0]*number
c=[0]*number
for i in range(number):
            x,y,z=input().split()
            a[i]=int(x)
            b[i]=int(y)
            c[i]=int(z)
step_lift=int(input())
d=[0]*step_lift
e=[0]*step_lift
for i in range(step_lift):
            r,n=input().split()
            d[i]=int(r)
            e[i]=int(n)
        #test case math
cal1=[0]*number
for i in range(step_lift):
            for j in range(number):
                if b[j]<=d[i] and c[j]>=d[i]:
                    cal=abs(c[j]-e[i])
                elif b[j]>=d[i] and c[j]<=d[i]:
                    cal=abs(c[j]-e[i])
                elif d[i]<=b[j] and d[i]>=c[j] and e[i]<=b[j] and e[i]>=c[j]:
                    cal=0
                elif d[i]>=b[j] and d[i]<=c[j] and e[i]>=b[j] and e[i]<=c[j]:
                    cal=0
                else :
                    cal=abs(abs(d[i]-c[j])+abs(e[i]-d[i]))
                cal1[j]=cal
            x=number
            for j in range(number):
                if min(cal1)==cal1[j]:
                    if a[j]<=x:
                        x=a[j]
            print(">>",x)

6631202321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1476, 'const': 203, 'code+const': 1679}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lif = []
quest = []
point = []
loop1 = 0
loop2 = 0
loop3 = 0
spot = 0
while loop1 < n :#เก็บตัวแปล
  d = input().split()
  e = [float(x) for x in d]
  lif += e
  loop1 += 1
m = int(input())
while loop3 < m :
  q = input().split()
  qr = [float(x) for x in q]
  quest += qr
  loop3 += 1#เก็บคำถาม
while loop2 < m :
  i1 = (loop2*2)
  f1 = (loop2*2) + 1
  while spot < n :
    i = (spot*3) + 1
    f = (spot*3) + 2
    spot += 1
    if lif[i] == lif[f] :#stand up down
      if quest[i1] > quest[f1] :#ขาลง
        if lif[i] < quest[i1] :
          a = ((quest[i1] - lif[i]) + (quest[i1] - quest[f1]))
          point.append(a)
        if lif[i] > quest[i1] :
          a = ((lif[i] - quest[i1]) + (quest[i1] - quest[f1]))
          point.append(a)
        if lif[i] == quest[i1] :
          a = quest[i1] - quest[f1]
          point.append(a)
      if quest[i1] < quest[f1] :
        if lif[i] < quest[i1] :
          a = (quest[i1] - lif[i]) + (quest[f1] - quest[i1])
          point.append(a)
        if lif[i] > quest[i1] :
          a = ((lif[i] - quest[i1]) + (quest[f1] - quest[i1]))
          point.append(a)
        if lif[i] == quest[i1] :
          a = quest[f1] - quest[i1]
          point.append(a)
    if quest[i1] < quest[f1] and lif[i] < lif[f] :#up up
      if lif[i] > quest[i1] :
        a = (lif[f] - quest[i1]) + (quest[f1] - quest[i1])
        point.append(a)
      if lif[i] <= quest[i1] :
        if lif[f] < quest[f1] :
          a = quest[f1] - lif[f]
          point.append(a)
        if lif[f] >= quest[f1] :
          a = 0
          point.append(a)
    if quest[i1] < quest[f1] and lif[i] > lif[f] :#up down
      if lif[f] <= quest[i1] :
        a = (quest[f1] - lif[f])
        point.append(a)
      if lif[f] > quest[i1] :
        a = ((lif[f] - quest[i1]) + (quest[f1] - quest[i1]))
        point.append(a)
    if quest[i1] > quest[f1] and lif[i] < lif[f] :#down up
      if lif[f] >= quest[i1] :
        a = (lif[f] - quest[f1])
        point.append(a)
      if lif[f] < quest[i1] :
        a = ((quest[i1] - lif[f]) + (quest[i1] - quest[f1]))
        point.append(a)
    if quest[i1] > quest[f1] and lif[i] > lif[f] :#down down
      if lif[i] >= quest[i1]:
        if lif[f] <= quest[f1] :
          a = 0
          point.append(a)
        if lif[f] > quest[f1] :
          a = (lif[f] - quest[f1])
          point.append(a)
      if lif[i] < quest[i1] :
        a = ((quest[i1] - lif[f]) + (quest[i1] - quest[f1]))
        point.append(a)
  loop2 += 1 #หาคำตอบ
  spot = 0
  al = []
  t = 0
  num1 = min(point)
  b = num1 in point
  while b == True :
    num2 = point.index(num1)
    ans = lif[(num2 + t)*3]
    al.append(ans)
    point.remove(num1)
    b = num1 in point
    t += 1
  else :
     finalan = min(al)
     finalans = int(finalan)
     print(">>",finalans)
  point = []
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631203021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 648, 'const': 147, 'code+const': 795}
1# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
nl = int(input())
a2 = []
for n in range (nl):
    a = input().split()
    a1 = [int(x) for x in a]
    a2 += [a1]
b2 = []
q = int(input())
for m in range (q):
    b = input(). split()
    b1 = [int(y) for y in b]
    b2 += [b1]
for i in range (q):
    z = 0
    min = 0
    ind = 1
    for j in range (nl):
        if (a2[j][1] <= b2[i][0] <= a2[j][2] or a2[j][2] <= b2[i][0] <= a2[j][1])           and ((a2[j][2] <= b2[i][1] and b2[i][1] <= b2[i][0]) or (b2[i][0] <= b2[i][1] and b2[i][1] <= a2[j][2])):
            z = 0
        if a2[j][1] <= b2[i][0] <= a2[j][2] or a2[j][2] <= b2[i][0] <= a2[j][1] :
             #and b2[i][1] <= a2[j][1] <= a2[j][2] or b2[i][1] >= a2[j][1] >= a2[j][2]:
            z = abs(a2[j][2]-b2[i][1])
        else :
            z = abs(b2[i][0] - a2[j][2]) + abs(b2[i][0]-b2[i][1])
        if j == 0 :
            min = z
            ind = a2[0][0]
        elif min > z :
            min = z
            ind = a2[j][0]
    print ('>>', ind)

6631220621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>>> 2
>>> 4
>>> 1
[]
test_main_21.0
>>> 1
>>> 2
>>> 3
>>> 4
[]
test_main_31.0
>>> 1
>>> 1
>>> 1
>>> 2
>>> 2
>>> 3
>>> 3
>>> 4
>>> 4
[]
test_main_41.0
>>> 4
>>> 4
>>> 4
>>> 3
>>> 3
>>> 2
>>> 2
>>> 1
>>> 1
[]
test_main_51.0
>>> 3
>>> 3
>>> 3
>>> 4
>>> 4
>>> 2
>>> 2
>>> 1
>>> 1
>>> 1
>>> 1
>>> 1
[]
test_main_61.0
>>> 1
>>> 1
>>> 1
>>> 2
>>> 2
>>> 3
>>> 3
>>> 4
>>> 4
>>> 4
>>> 4
[]
test_main_71.0
>>> 1
>>> 1
>>> 1
>>> 2
>>> 2
>>> 4
>>> 3
>>> 3
>>> 3
>>> 3
>>> 3
>>> 3
[]
test_main_81.0
>>> 2
>>> 1
>>> 1
>>> 1
>>> 1
>>> 1
>>> 3
>>> 3
>>> 3
>>> 3
>>> 3
>>> 1
>>> 6
>>> 6
>>> 6
>>> 6
>>> 3
>>> 4
>>> 4
>>> 4
>>> 4
>>> 5
[]
bytecount: {'code': 1046, 'const': 148, 'code+const': 1194}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lift = []
num_lift = int(input())
i = 1
while i <= num_lift:
  a = (input().split())
  e = list(map(int, a))
  lift.append(e)
  i += 1
Question = []
num_Question  = int(input())
i = 1
while i <= num_Question :
  p = (input().split())
  t = list(map(int, p))
  Question.append(t)
  i += 1
for f in Question:
  stay = f[0]
  point = f[1]
  k_diff = []
  for y in lift:
    start = y[1]
    end = y[2]
    if start < end:  # หัว 1
      if stay > end or stay < start:
        o = abs(int(end) - int(stay)) + abs(int(point)-int(stay))
        k_diff.append(y[0])
        k_diff.append(o)
      elif stay <= end :
        if point > start :
          if stay <= point and point <= end :
            k_diff.append(y[0])
            k_diff.append(0)
          elif stay > point:
            o = abs(int(end) - int(stay)) + abs(int(point)-int(stay))
            k_diff.append(y[0])
            k_diff.append(o)
          elif stay < point and point > end:
            h = abs(int(point)-int(end))
            k_diff.append(y[0])
            k_diff.append(h)
        elif point <= start:
          h = abs(int(point)-int(end))
          k_diff.append(y[0])
          k_diff.append(h)
    elif start > end: #หัว 2
      if stay < end or stay > start:
        o = abs(int(end) - int(stay)) + abs(int(point)-int(stay))
        k_diff.append(y[0])
        k_diff.append(o)
      elif stay >= end :
        if point < start :
          if stay >= point and point > end:
            k_diff.append(y[0])
            k_diff.append(0)
          elif stay < point:
            o = abs(int(end) - int(stay)) + abs(int(point)-int(stay))
            k_diff.append(y[0])
            k_diff.append(o)
          elif stay > point and point < end:
            h = abs(int(point)-int(end))
            k_diff.append(y[0])
            k_diff.append(h)
        elif point >= start:
          h = abs(int(point)-int(end))
          k_diff.append(y[0])
          k_diff.append(h)
    elif start == end : # หัว 3
      g = abs(int(start) - int(stay)) + abs(int(point)-int(stay))
      k_diff.append(y[0])
      k_diff.append(g)
  direct_min = k_diff[1: :2]
  No_lift = k_diff[0: :2]
  print('>>>',No_lift[(direct_min.index(min(direct_min)))])

6631223521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 546, 'const': 147, 'code+const': 693}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
#จำนวนลิฟท์ทั้งหมด
n= int(input())
lift=[1]*n
start_l = [1]*n
stop_l=[1]*n
#การรับค่า ของลิฟท์
for i in range(n):
  lift[i],start_l[i],stop_l[i]=[int(e) for e in input().split()]
#การรับค่าของuser
p= int(input())
start_f= [1]*p
stop_f= [1]*p
for j in range(p):
  start_f[j],stop_f[j] = [int(e) for e in input().split()]
#งาน
for j in range(p):
  burden=0
  minburden=1000
  min_lift=0 #ชื่อลิฟท์ภาระน้อยสุด
  for i in range(n):
    if start_l[i] <= start_f[j] <=stop_l[i] <= stop_f[j] or stop_f[j] <= stop_l[i] <= start_f[j] <= start_l[i]:
      burden=abs(stop_f[j]-stop_l[i])
    elif start_l[i] <= start_f[j] <= stop_f[j] <= stop_l[i] or start_l[i] >= start_f[j]>= stop_f[j]>= stop_l[i]:
      burden=0
    else :
      burden= abs(stop_l[i]-start_f[j])+ abs(start_f[j]-stop_f[j])
    if burden<minburden:
      minburden= burden
      min_lift= lift[i]
  print(">>",min_lift)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631229321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 550, 'const': 147, 'code+const': 697}
2 # HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = [0]*n
bl = [0]*n
stopl = [0]*n
for i in range(n) :
    a = input().split()
    lift[i]=int(a[0])
    bl[i]=int(a[1])
    stopl[i]=int(a[2])
m = int(input())
bu = [0]*m
stopu = [0]*m
for j in range(m) :
    a = input().split()
    bu[j]=int(a[0])
    stopu[j]=int(a[1])
for j in range(m) :
    dist = 0
    min_d = 0
    min_l = 0
    for i in range(n) :
        if (bl[i] <= bu[j] <= stopu[j] <= stopl[i]) or (bl[i] >= bu[j] >= stopu[j] >= stopl[i]) :
            dist = 0
        elif (bl[i] <= bu[j] <= stopl[i] <= stopu[j]) or (bl[i] >= bu[j] >= stopl[i] >= stopu[j]):
            dist = abs(stopu[j]-stopl[i])
        else :
            dist = abs(stopl[i]-bu[j])+ abs(bu[j]-stopu[j])
        if i == 0 or dist < min_d :
            min_d = dist
            min_l = lift[i]
    print('>>',min_l)

6631315621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 814, 'const': 203, 'code+const': 1017}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด) 
n = int(input()) 
lift = []
for i in range(n) :
    x = input().split()
    p = []
    for j in range(3) :
        p.append(int(x[j])) #เลข ชั้นปัจจุบัน ชั้นจุดหมาย
    lift.append(p)
    lift.sort()
m = int(input())
what = []
for i in range(m) :
    y = input().split()
    p = []
    for j in range(2) :
        p.append(int(y[j])) # ชั้นอยู่ ชั้นไป
    what.append(p)
for i in range(len(what)) :
    load = 10000
    for j in range(len(lift)) :
        up_we = what[i][1]-what[i][0] > 0
        down_we = what[i][1]-what[i][0] < 0
        up_lift = lift[j][2] - lift[j][1] > 0
        down_lift = lift[j][2] - lift[j][1] < 0
        m = up_lift and up_we and lift[j][1] <= what[i][0] <=lift[j][2]
        n = down_lift and down_we and lift[j][2] <= what[i][0] <=lift[j][1]
        a = up_lift and up_we and what[i][0] >= lift[j][1] and lift[j][2] >= what[i][1]  
        b = down_lift and down_we and what[i][0] <= lift[j][1] and lift[j][2] <= what [i][1] 
        if a or b : 
            c = 0
        elif m or n :
            c = abs(what[i][1] - lift[j][2])
        elif up_lift or down_lift : 
           c = abs(lift[j][2] - what[i][0]) + abs(what[i][0] - what[i][1])
        elif lift[j][1] == lift[j][2] :
            c = abs(what[i][0] - lift[j][2]) + abs(what[i][1] - what[i][0])
        if load > c :
            load = c
            z = j
    print('>>', lift[z][0])

6631453521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 644, 'const': 654, 'code+const': 1298}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def sameDirection(liftDirection, targetDirection):
    if liftDirection[0] > liftDirection[1] and targetDirection[0] > targetDirection[1]:
        return [True, 'down']
    elif liftDirection[1] > liftDirection[0] and targetDirection[1] > targetDirection[0]:
        return [True, 'up']
    else:
        return [False, None]
def liftPass(lift1, lift2, target1):
    low = min(lift1, lift2)
    high = max(lift1, lift2)
    if target1 in range(low, high+1):
        return True
    else:
        return False
def calculate(lift1, lift2, target1, target2):
    Dirc = sameDirection([lift1, lift2], [target1, target2])
    if Dirc[0]:
        if liftPass(lift1, lift2, target1):
            if Dirc[1] == 'up':
                ans = target2 - lift2
            else:
                ans = lift2 - target2
            if ans < 0:
                return 0
            else:
                return ans
    ans = abs((target1 - lift2)) + abs((target2 - target1))
    return ans
def minLift(move):
    j = 0
    for i in move:
        if min(move) == i:
            return j + 1
        j += 1
n = int(input())
x = [0]*n
result = [0]*n
for i in range(0, n):
    x[i] = input().split()
for i in range(0, n):
    index = int(x[i][0]) - 1
    x[index],x[i] = x[i],x[index]
m = int(input())
y = [0]*m
finale = [0]*m
for i in range(0, m):
    y[i] = input().split()
    for j in range(0, n):
        result[j] = calculate(int(x[j][1]), int(x[j][2]), int(y[i][0]), int(y[i][1]))
    finale[i] = minLift(result)
for i in range(0, m):
    print(">>", finale[i])

6631455821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 470, 'const': 208, 'code+const': 678}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
#enter number of lift
numberOfLift = abs(int(input()))
ArrayOfLift = []
while (len(ArrayOfLift) != numberOfLift):
    myliftInput = input().split()
    ArrayOfLift.append(myliftInput)
NumberofTestCase = abs(int(input()))
ArrayOfTestCase = []
while (len(ArrayOfTestCase) != NumberofTestCase):
    myCaseInput = input().split()
    ArrayOfTestCase.append(myCaseInput)
theLift = -1
for n in ArrayOfTestCase:
    UserStartingFloor = int(n[0])
    UserdestinationFloor = int(n[1])
    theLeastDistance = 999999999999
    userUoD = UserdestinationFloor - UserStartingFloor
    if userUoD > 0:
        userUoD = 1
    else :
        userUoD = 0
    for index in range(numberOfLift):
      initailFloor = int(ArrayOfLift[index][1])
      FinalFloor = int(ArrayOfLift[index][2])
      LiftUoD = FinalFloor - initailFloor
      if LiftUoD > 0:
        LiftUoD = 1
      else:
         LiftUoD = 0
      escortD = UserStartingFloor - FinalFloor
      travelD = abs(UserdestinationFloor - UserStartingFloor)
      sumTravel = travelD + abs(UserStartingFloor - FinalFloor)
      if(userUoD == 0 and LiftUoD ==0):
          if(UserStartingFloor >= initailFloor):
             sumTravel = travelD + (UserStartingFloor - FinalFloor)
          if(UserStartingFloor <= initailFloor):
             sumTravel = FinalFloor - UserdestinationFloor
             if(UserdestinationFloor >FinalFloor ):
                 sumTravel = 0
      if(userUoD == 1 and LiftUoD ==1 ):
          if( UserStartingFloor <= initailFloor):
              sumTravel = travelD + (FinalFloor - UserStartingFloor)
          if( UserStartingFloor >= initailFloor):
              sumTravel = UserdestinationFloor - FinalFloor
              if(UserdestinationFloor < FinalFloor):
                  sumTravel = 0
      if theLeastDistance > sumTravel:
          theLeastDistance = sumTravel
          theLift = ArrayOfLift[index][0]
    print(f'>> {theLift}')
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631465021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 906, 'const': 175, 'code+const': 1081}
4# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input()) #จำนวนลิฟต์
i = 0
j = 0
k = 0
l = 0
lift = []
pos = []
move1 = []
sort1 = []
lift2 = []
while i < n:
  a,b,c = [int(e) for e in input().split()]
  lift.append(a)
  lift.append(b)
  lift.append(c)
  i=i+1
m = int(input()) #จำนวนคำถาม
while j < m:
  d,f = [int(e) for e in input().split()]
  pos.append(d)
  pos.append(f)
  j=j+1
i=0
while i < n: #เรียงลำดับใหม่สำหรับในกรณีที่ลิฟต์มีภาระงานเท่ากันแล้วต้องเลือกลิฟต์ที่มีหมายเลขน้อยที่สุด
 sort1.append(lift[i*3])
 i = i+1
sort2 = sort1.sort()
i=0
while i < n:
  b = sort1.index(lift[i*3])
  lift2.insert(b*3,lift[i*3])
  lift2.insert((b*3)+1,lift[(i*3)+1])
  lift2.insert((b*3)+2,lift[(i*3)+2])
  i = i+1
k = 0
l = 0
while k < m:
  while l < n:
    x1 = lift2[(l*3)+1]
    x2 = lift2[(l*3)+2]
    y1 = pos[k*2]
    y2 = pos[(k*2)+1]
    if (x1-x2)*(y1-y2) >= 0: #ถ้ามากกว่า 0 แสดงว่าลิฟต์กับคนขึ้นลิฟต์ไปทางเดียวกัน
     maxx = max(x1,x2)
     minx = min(x1,x2)
     if y1 in range(minx,maxx+1) and y2 in range(minx,maxx+1):
      move1.append(0)
     elif y1 in range(minx,maxx+1) and y2 not in range(minx,maxx+1):
      dis1 = abs(y2-x2)
      move1.append(dis1)
     else:
      dis2 = abs(y1-x2)+abs(y1-y2)
      move1.append(dis2)
    else:
     dis3 = abs(y1-x2)+abs(y1-y2)
     move1.append(dis3)
    l=l+1
  l=0
  k=k+1
x=0
while x < m:
  a = move1[n*x:n*(x+1)].index(min(move1[n*x:n*(x+1)]))+1
  print('>>',lift2[3*(a-1)])
  x=x+1

6631466721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 720, 'const': 147, 'code+const': 867}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
x =[]
for i in range(n):
  i+=1
  x.append([int(e) for e in input().split()])
m = int(input())
y =[]
for i in range(m):
  i+=1
  y.append([int(e) for e in input().split()])
i = 0
j = 0
load = []
bbb = []
dd = []
for i in range(m):
  me = y[i]
  for j in range(n):
    lift = x[j]
    l1 = lift[1]
    l2 = lift[2]
    me1 = me[0]
    me2 = me[1]
    if l1-l2>0:
      a=1
    else:
      a=0
    if me1-me2>0:
      b=1
    else:
      b=0
    if a==b:
      if l1-l2 < 0:
        l3 = l1
        l4 = l2
      else:
        l3 = l2
        l4 = l1
      if me1 in range(l3,l4+1) and me2 in range(l3,l4+1):
        load.append(0)
      elif me1 in range(l3,l4+1) and me2 not in range(l3,l4+1):
        ans = abs(l2-me2)
        load.append(ans)
      else:
        ans = abs(me1-l2)+abs(me2-me1)
        load.append(ans)
    else:
      ans = abs(me1-l2)+abs(me2-me1)
      load.append(ans)
    j+=1
  min = load[0]
  for k in load:
    if k<min:
      min = k
  aaa = 0
  for kk in load:
    if kk == min:
      bbb = x[aaa]
      ccc = bbb[0]
      dd.append(ccc)
      mindd = dd[0]
      for p in dd:
        if p<mindd:
          mindd = p
    aaa = aaa+1
  aa = load.index(min)+1
  bb = x[aa-1]
  mindd = bb[0]
  j=0
  print(">>",mindd)
  load=[]
  i+=1

6631501021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 562, 'const': 148, 'code+const': 710}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
x = []
y = []
for i in range(100):
    x.append([])
    y.append(0)
for i in range(n):
    a,b,c = map(int,input().split())
    x[a]=[b,c]
m = int(input())
while m>0:
    m-=1
    xx= 100
    z,d = map(int,input().split())
    for i in range(1,n+1,1):
        if x[i][0] > x[i][1]:
            if z <= x[i][0] and z >= x[i][1]:
                y[i] = abs(d-x[i][1])
            else:
                y[i] = abs(z-x[i][1])+abs(d-z)
            xx = min(xx,y[i])
        else :
            if x[i][0] < x[i][1]:
                if z >= x[i][0] and z <= x[i][1]:
                    y[i] = abs(d-x[i][1])
                else:
                    y[i] = abs(z-x[i][1]) + abs(d-z)
                xx = min(xx,y[i])
            else:
                y[i] = abs(z-x[i][1]) + abs(d-z)
                xx = min(xx,y[i])
    for i in range(1,n+1,1):
        if(xx == y[i]):
            print(f'>> {i}')
            break
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631507821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1090, 'const': 119, 'code+const': 1209}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
import math
lift_num = int(input())
lift = 0
ln = []
li = []
lf = []
while lift < lift_num:
    a,b,c = [int(i) for i in input().split()]
    ln.append(a)
    li.append(b)
    lf.append(c)
    lift += 1
people_num = int(input())
people = 0
pi = []
pf = []
while people < people_num:
    a,b = [int(i) for i in input().split()]
    pi.append(a)
    pf.append(b)
    people += 1
m = 0
for p in pi:
    n = 0
    works = []
    for l in ln:
        if pf[m]>=pi[m]: #คนกำลังจะขึ้น
            if lf[n]>=li[n]: #ลิฟท์กำลังขึ้น
                if li[n] <= pi[m] <= lf[n]: #เริ่มระหว่างชั้นที่ไปอยู่เเล้ว
                    if pf[m] <= lf[n]: #ถ้าไปชั้นที่ไปอยู่เเล้ว
                        work = 0
                        works.append(work)
                    else: #ถ้าขึ้นมาระหว่างทางเเต่ไปชั้นอื่น
                        work = abs(int(pf[m])-int(lf[n]))
                        works.append(work)
                else: #ไม่เกี่ยวเลย ไปรับเเละส่งเต็ม
                    work = abs(int(pi[m])-int(lf[n])) + abs(int(pf[m])-int(pi[m]))
                    works.append(work)
            elif li[n]>=lf[n]: #ลิฟท์กำลังลง
                if lf[n] <= pi[m] <= li[n]: #เริ่มระหว่างชั้นที่ไปอยู่เเล้ว
                    work = abs(int(pf[m])-int(lf[n]))
                    works.append(work)
                else: #ไม่เกี่ยวเลย ไปรับเเละส่งเต็ม
                    work = abs(int(pi[m])-int(lf[n])) + abs(int(pf[m])-int(pi[m]))
                    works.append(work)
        elif pf[m]<=pi[m]: #คนกำลังจะลง
            if lf[n]>=li[n]: #ลิฟท์กำลังขึ้น
                if li[n] <= pi[m] <= lf[n]: #เริ่มระหว่างชั้นที่ไปอยู่เเล้ว
                        work = abs(int(pf[m])-int(lf[n]))
                        works.append(work)
                else: #ไม่เกี่ยวเลย ไปรับเเละส่งเต็ม
                    work = abs(int(pi[m])-int(lf[n])) + abs(int(pf[m])-int(pi[m]))
                    works.append(work)
            elif li[n]>=lf[n]: #ลิฟท์กำลังลง
                if lf[n] <= pi[m] <= li[n]: #เริ่มระหว่างชั้นที่ไปอยู่เเล้ว
                    if lf[n] <= pf[m]: #ถ้าไปชั้นที่ไปอยู่เเล้ว
                        work = 0
                        works.append(work)
                    else: #ถ้าขึ้นมาระหว่างทางเเต่ไปชั้นอื่น
                        work = abs(int(pf[m])-int(lf[n]))
                        works.append(work)
                else: #ไม่เกี่ยวเลย ไปรับเเละส่งเต็ม
                    work = abs(int(pi[m])-int(lf[n])) + abs(int(pf[m])-int(pi[m]))
                    works.append(work)
        n += 1
    bl = works.index(min(works))
    print('>>',ln[bl])
    m += 1

6631508421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 560, 'const': 143, 'code+const': 703}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
lif_quantity = int(input()) #จำนวนลิฟต์
lif = []
for i in range(lif_quantity): #ช้อมูล [เลขลิฟต์ , ลิฟต์ตอนนี้ , ลิฟต์จะไป]
    lifs = list(map(int,input().split()))
    lif.append(lifs)
question = int(input()) #จำนวนคำถาม
for e in range(question):
    floor_now , floor_go = map(int,input().split()) # คนตอนนี้ , คนจะไป
    lif_best = None
    phase_min = float('inf')
    for lifs in lif:
        lif_num , now , go = lifs # เลขลิฟต์ , ลิฟต์ตอนนี้ , ลิฟต์จะไป
        if now > go and floor_now > floor_go:
            if floor_now > now :
                phase = abs(go - floor_now) + abs(floor_now - floor_go)
                if phase < phase_min:
                    phase_min = phase
                    lif_best = lif_num
            elif floor_now <= now :
                if floor_go >= go:
                    phase = 0
                elif floor_go < go:
                    phase = abs(go - floor_go)
                if phase < phase_min:
                    phase_min = phase
                    lif_best = lif_num
        if now < go and floor_now < floor_go:
            if floor_now < now :
                phase = abs(go - floor_now) + abs(floor_now - floor_go)
                if phase < phase_min:
                    phase_min = phase
                    lif_best = lif_num
            elif floor_now >= now:
                if floor_go <= go:
                    phase = 0
                elif floor_go > go:
                    phase = abs(go - floor_go)
                if phase < phase_min:
                    phase_min = phase
                    lif_best = lif_num
        if now > go and floor_now < floor_go:
            phase = abs(go - floor_now) + abs(floor_now - floor_go)
            if phase < phase_min:
                phase_min = phase
                lif_best = lif_num
        if now < go and floor_now > floor_go:
            phase = abs(go - floor_now) + abs(floor_now - floor_go)
            if phase < phase_min:
                phase_min = phase
                lif_best = lif_num
        if now == go:
            phase = abs(go - floor_now) + abs(floor_now - floor_go)
            if phase < phase_min:
                phase_min = phase
                lif_best = lif_num
    print(">>", lif_best)

6631509021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 562, 'const': 172, 'code+const': 734}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lift = []
burden = []
for i in range(1000):
  lift.append([])
  burden.append(0)
for i in range(n):
  k,a,b = map(int,input().split())
  lift[k]=[a,b]
m = int(input())
while m>0:
  m -= 1
  mn = 2e9
  s,e = map(int,input().split())
  for i in range(1,n+1,1):
    if lift[i][0] > lift[i][1]:
      if s <= lift[i][0] and s >= lift[i][1]:
        burden[i] = abs(e-lift[i][1])
      else:
        burden[i] = abs(s-lift[i][1])+abs(e-s)
      mn = min(mn,burden[i])
    elif lift[i][0] < lift[i][1]:
      if s >= lift[i][0] and s <= lift[i][1]:
        burden[i] = abs(e-lift[i][1])
      else:
        burden[i] = abs(s-lift[i][1]) + abs(e-s)
      mn = min(mn,burden[i])
    else:
      burden[i] = abs(s-lift[i][1]) + abs(e-s)
      mn = min(mn,burden[i])
  for i in range(1,n+1,1):
    if(mn == burden[i]):
      print(f'>> {i}')
      break

6631512921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 622, 'const': 199, 'code+const': 821}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lft = []
for i in range(n):
    lft_info = input().split()
    lft_num = int(lft_info[0])
    start = int(lft_info[1])
    stop = int(lft_info[2])
    lft.append((lft_num, start, stop))
m = int(input())
for i in range(m):
    floor = input().split()
    start = int(floor[0])
    stop = int(floor[1])
    floor.append((start,stop))
    load_min = float('inf')
    for lfts in lft:
        lft_num , lft_curr , lft_stop = lfts
        if lft_curr > lft_stop and start > stop:
            if start > lft_curr :
                load = abs(lft_stop - start) + abs(start - stop)
                if load < load_min:
                    load_min = load
                    lft_best = lft_num
            elif start <= lft_curr :
                if stop >= lft_stop:
                    load = 0
                elif stop < lft_stop:
                    load = abs(lft_stop - stop)
                if load < load_min:
                    load_min = load
                    lft_best = lft_num
        if lft_curr < lft_stop and start < stop:
            if start < lft_curr :
                load = abs(lft_stop - start) + abs(start - stop)
                if load < load_min:
                    load_min = load
                    lft_best = lft_num
            elif start >= lft_curr:
                if stop <= lft_stop:
                    load = 0
                elif stop > lft_stop:
                    load = abs(lft_stop - stop)
                if load < load_min:
                    load_min = load
                    lft_best = lft_num
        if lft_curr > lft_stop and start < stop:
            load = abs(lft_stop - start) + abs(start- stop)
            if load < load_min:
                load_min = load
                lft_best = lft_num
        if lft_curr < lft_stop and start > stop:
            load = abs(lft_stop - start) + abs(start- stop)
            if load < load_min:
                load_min = load
                lft_best = lft_num
        if lft_curr == lft_stop:
            load = abs(lft_stop - start) + abs(start - stop)
            if load < load_min:
                load_min = load
                lft_best = lft_num
    print(">>", lft_best)

6631513521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 434, 'const': 172, 'code+const': 606}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
answer = []
n = int(input())
elevator = [[0, 0] for i in range(n)]
for i in range(n):
    num, f1, f2 = input().split()
    f1 = int(f1)
    f2 = int(f2)
    num = int(num)
    elevator[num - 1] = [f1, f2]
m = int(input())
for i in range(m):
    initial,finish = input().split()
    initial = int(initial)
    finish = int(finish)
    min_distance = 100_000_000
    min_num = None
    for num, (f1, f2) in enumerate(elevator):
        total_distance = 0
        if f1 <= initial <= f2:
            if finish > initial and finish <= f2:
                total_distance = 0
            else:
                total_distance = abs(finish - f2)
        elif f2 <= initial <= f1:
            if finish < initial and finish >= f2:
                total_distance = 0
            else:
                total_distance = abs(f2 - finish)
        else:
            total_distance = abs(initial - f2) + abs(finish - initial)
        if total_distance < min_distance:
            min_distance = total_distance
            min_num = num
        elif total_distance == min_distance:
            if num < min_num:
                min_num = num
    answer.append(min_num+1)
for ans in answer:
  print(f">> {ans}")

6631515821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 924, 'const': 216, 'code+const': 1140}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift_info = []
lift_ans = []
for i in range(n) :
    a = []
    l = input().split()
    for i in l :
        a.append(int(i))
    lift_info.append(a)
m = int(input())
for i in range(m):
    a = []
    l = input().split()
    for i in l :
        a.append(int(i))
    lift_ans.append(a)
def lift_check(a,b) :
    s,a1,a2 = a[0],a[1],a[2]
    b1,b2 = b[0],b[1]
    if a1 > a2:
        if a1 >= b1 >= a2:
            if b1 < b2:
                return [abs(b1 - a2) + abs(b2 - b1), s]
            else:
                if a1 >= b1 >= b2 >= a2 :
                    return [0, s]
                elif a1 >= b1 >= a2 >= b2 :
                    return [abs(a2 - b2), s]
        else:
            return [abs(b1 - a2) + abs(b2 - b1), s]
    elif a1 < a2:
        if a1 <= b1 <= a2 :
            if b1 > b2 :
                return [abs(b1 - a2) + abs(b2 - b1), s]
            else:
                if a1 <= b1 <= b2 <= a2 :
                    return [0, s]
                elif a1 <= b1 <= a2 <= b2 :
                    return [abs(a2 - b2), s]
        else:
            return [abs(b1 - a2) + abs(b2 - b1), s]
    elif a1 == a2:
        return [abs(b1 - a1) + abs(b2 - b1), s]
for i in lift_ans :
    x = []
    for j in lift_info :
        ans = lift_check(j,i)
        x.append(ans)
    for y in range(len(x)):
        for z in range(len(x) - 1 - y):
            if x[y][0] > x[y + 1 + z][0]:
                x[y], x[y + 1 + z] = x[y + 1 + z], x[y]
            elif x[y][0] == x[y + 1 + z][0] and x[y][1] > x[y + 1 + z][1]:
                x[y], x[y + 1 + z] = x[y + 1 + z], x[y]
    print('>> ' + str(x[0][1]))

6631516421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 544, 'const': 384, 'code+const': 928}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
total_lift = input()
lifts = []
for i in range(int(total_lift)): # for lift input
    num, start, stop = input().split()
    num = int(num)
    start = int(start)
    stop = int(stop)
    lifts.append((num, start, stop))
result_lst = []
total_user = input()
for i in range(int(total_user)):
    user_start, user_stop = input().split()
    user_start = int(user_start)
    user_stop = int(user_stop)
    if user_stop - user_start > 0: # going up
        user_dir = 'UP'
    elif user_stop - user_start < 0:
        user_dir = 'DOWN'
    result = ''
    lowest_load = -1
    for j in lifts:
        lift_start = j[1]
        lift_stop = j[2]
        if lift_stop - lift_start > 0: # going up
            lift_dir = 'UP'
        elif lift_stop - lift_start < 0:
            lift_dir = 'DOWN'
        else:
            lift_dir = 'STILL'
        if lift_dir == user_dir: # have a chance to off load
            if lift_dir == 'UP':
                if lift_start <= user_start and user_start <= lift_stop:
                    if lift_start <= user_stop and user_stop <= lift_stop:
                        cur_load = 0
                    else:
                        cur_load = user_stop - lift_stop
                else:
                    cur_load = abs(lift_stop - user_start) + abs(user_start - user_stop)
            elif lift_dir == 'DOWN':
                if lift_start >= user_start and user_start >= lift_stop:
                    if lift_start >= user_stop and user_stop >= lift_stop:
                        cur_load = 0
                    else:
                        cur_load = lift_stop - user_stop
                else:
                    cur_load = abs(lift_stop - user_start) + abs(user_start - user_stop)
        else:
            cur_load = abs(lift_stop - user_start) + abs(user_start - user_stop)
        if lowest_load > cur_load or lowest_load == -1:
            lowest_load = cur_load
            result = j[0]
        elif lowest_load == cur_load and j[0] < result:
            result = j[0]
    result_lst.append(result)
for i in result_lst:
    print(f'>>{i}')
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631517021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 816, 'const': 1021, 'code+const': 1837}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = []
for i in range(n):
  name, current, destination = [int(e) for e in input().split()]
  lifts.append([name, current, destination])
m = int(input())
passengers = []
for i in range(m):
  current, destination = [int(e) for e in input().split()]
  passengers.append([current, destination])
def direction(l_start, l_end):
  direction = 'same'
  # up / down
  if l_start > l_end:
    direction = 'down'
  elif l_start < l_end:
    direction = 'up'
  return direction
def is_duplicated(l_start, l_end, u_start, u_end):
  if direction(l_start, l_end) == direction(u_start, u_end):
    return True
  return False
def carry(l_start, l_end, u_start, u_end):
  check = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
  if l_start < l_end:
    check = check[l_start: l_end+1]
  else:
    check = check[l_end: l_start+1:]
  if u_start in check and u_end in check:
    return True
  return False
def p_carry(l_start, l_end, u_start, u_end):
  check = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
  if l_start < l_end:
    check = check[l_start: l_end+1]
  else:
    check = check[l_end: l_start+1:]
  if u_start in check and not u_end in check:
    return True
  return False
import math
floor_kept = [0] * m
distance = 0
count = 0
for up, down in passengers:
  minn = math.inf
  user = direction(up, down)
  for name, start, stop in lifts:
    if is_duplicated(start, stop, up, down):
      if carry(start, stop, up, down):
        floor_kept[count] = name
        minn = 0
        break
      elif p_carry(start, stop, up, down):
        if abs(down - stop) < minn:
          minn = abs(down - stop)
          floor_kept[count] = name
      else:
        if abs(stop - up) + abs(up - down)  < minn:
          minn = abs(stop - up) + abs(up - down)
          floor_kept[count] = name
    else:
      if p_carry(start, stop, up, down) and direction(start, stop) != 'same':
        if abs(down - stop) < minn:
          minn = abs(down - stop)
          floor_kept[count] = name
      else:
        if abs(stop - up) + abs(up - down)  < minn:
          minn = abs(stop - up) + abs(up - down)
          floor_kept[count] = name
  count += 1
for i in floor_kept:
  print(">>",i)

6631522121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 628, 'const': 147, 'code+const': 775}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
liftNo = []
liftStart = []
liftEnd = []
for i in range(n):
    a = input().split()
    liftNo.append(a[0])
    liftStart.append(int(a[1]))
    liftEnd.append(int(a[2]))
m = int(input())
for i in range(m):
    a = input().split()
    a[0] = int(a[0])
    a[1] = int(a[1])
    for j in range(n):
        if(a[0] <= a[1] and liftStart[j] <= liftEnd[j]):
            if(liftStart[j] <= a[0] <= liftEnd[j]):
                if(liftStart[j] <= a[1] <= liftEnd[j]):
                    floor = 0
                else:
                    floor = abs(liftEnd[j]-a[1])
            else:
                floor = abs(liftEnd[j]-a[0]) + abs(a[0]-a[1])
        elif(a[0] >= a[1] and liftStart[j] >= liftEnd[j]):
            if(liftStart[j] >= a[0] >= liftEnd[j]):
                if(liftStart[j] >= a[1] >= liftEnd[j]):
                    floor = 0
                else:
                    floor = abs(liftEnd[j]-a[1])
            else:
                floor = abs(liftEnd[j]-a[0]) + abs(a[0]-a[1])
        else:
            floor = abs(liftEnd[j]-a[0]) + abs(a[0]-a[1])
        if(j == 0):
            min = floor
            minLift = liftNo[j]
        else:
            if(floor < min):
                min = floor
                minLift = liftNo[j]
    print(">>",minLift)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631529621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 322, 'const': 163, 'code+const': 485}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def findload(start, end, current, target):
    distant = end - start
    lenght = target - current
    station = lenght == 0
    person_direction = distant > 0
    lift_direction = lenght > 0
    if not station and person_direction == lift_direction:
        difference = start - current
        incoming = difference > 0
        if not difference or lift_direction is incoming:
            lack = target - end
            return 0 if (lack > 0) == lift_direction else abs(lack)
    return abs(target - start) + abs(distant)
1
data, moves = [[
        tuple(map(int, input().split()))
        for _ in range(int(input()))
    ] for _ in range(2)
]
for move in moves:
    load = [
        (findload(*move, *trip), lift)
        for lift, *trip in data
    ]
    #print(*load)
    print('>>', min(load)[1])

6631532421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 716, 'const': 147, 'code+const': 863}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
#จำนวนลิฟต์ที่มี
n = int(input())
elevator = []
start_elevator = []
end_elevator = []
for i in range(n):
    elevator_data = input().split()
    elevator.append(int(elevator_data[0]))
    start_elevator.append(int(elevator_data[1]))
    end_elevator.append(int(elevator_data[2]))
#จำนวนคำถามที่มี
m = int(input())
current_floor = []
target_floor = []
for i in range(m):
    my_data = input().split()
    current_floor.append(int(my_data[0]))
    target_floor.append(int(my_data[1]))
#เงื่อนไข
for i in range(m):
    elevator_list = []
    for j in range(n):
        my_target = target_floor[i] - current_floor[i]
        elevator_target = end_elevator[j] - start_elevator[j]
        if elevator_target < 0 and my_target < 0:
            if end_elevator[j] <= target_floor[i]            <= current_floor[i] <= start_elevator[j]:
                elevator_list.append(0)
            elif end_elevator[j] <= current_floor[i]            <= start_elevator[j]:
                elevator_list.append(abs(target_floor[i] - end_elevator[j]))
            else:
                elevator_list.append(abs(end_elevator[j] - current_floor[i])                            + abs(current_floor[i] - target_floor[i]))
        elif elevator_target > 0 and my_target > 0:
            if start_elevator[j] <= current_floor[i]            <= target_floor[i] <= end_elevator[j]:
                elevator_list.append(0)
            elif start_elevator[j] <= current_floor[i]            <= end_elevator[j]:
                elevator_list.append(abs(target_floor[i] - end_elevator[j]))
            else:
                elevator_list.append(abs(end_elevator[j] - current_floor[i])                            + abs(current_floor[i] - target_floor[i]))
        else:
            elevator_list.append(abs(end_elevator[j] - current_floor[i])                        + abs(current_floor[i] - target_floor[i]))
    min_workload = min(elevator_list)
    best_elevator = elevator[elevator_list.index(min_workload)]
    print(">>", best_elevator)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631537621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 464, 'const': 144, 'code+const': 608}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
# n total elevator number
n = int(input())
elevator_info = []
# Input: Elevator information
for i in range(n) :
    elevator_no, elevator_cur, elevator_dest = map(int, input().split())
    elevator_info.append((elevator_no, elevator_cur, elevator_dest))
# m total question
m = int(input())
output = [] # List to store the output for each question
# Input: Person information and determine best elevator for each person
for i in range(m):
    person_cur, person_dest = map(int, input().split())
    # Initialize variables for best elevator selection
    best_elevator = None
    best_work = float('inf')
    # Calculate work based on elevator direction and person's location
    for elevator_no, elevator_cur, elevator_dest in elevator_info:
        if elevator_cur == elevator_dest:
            # Elevator is not moving
            # print(f'Elevator {elevator_no} is not moving')
            work = abs(person_cur - elevator_cur) + abs(person_cur - person_dest)
        elif elevator_cur < elevator_dest:
            # Elevator is moving up
            # print(f'Elevator {elevator_no} is moving up')
            if elevator_cur <= person_cur <= person_dest <= elevator_dest:
                work = 0
            elif elevator_cur <= person_cur <= elevator_dest <= person_dest:
                work = abs(person_dest - elevator_dest)
            else:
                work = abs(person_cur - elevator_dest) + abs(person_dest - person_cur)
        else:
            # Elevator is moving down
            # print(f'Elevator {elevator_no} is moving down')
            if elevator_cur >= person_cur >= person_dest >= elevator_dest:
                work = 0
            elif elevator_cur >= person_cur >= elevator_dest >= person_dest:
                work = abs(person_dest - elevator_dest)
            else:
                work = abs(person_cur - elevator_dest) + abs(person_dest - person_cur)
        # Update the best elevator if the current elevator is better
        if work < best_work:
            best_elevator = elevator_no
            best_work = work
        # print(f'elevator {elevator_no}, work {work}')
    # Store the chosen elevator for the current person in the output list
    output.append(f">> {best_elevator}")
# Print the output line by line
for line in output:
    print(line)

6631539921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 384, 'const': 199, 'code+const': 583}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
Elevators = []
for _ in range(n):
  elevator = input().split()
  elevatornumber = int(elevator[0])
  a = int(elevator[1])
  b = int(elevator[2])
  Elevators.append((elevatornumber,a,b))
q = int(input())
for _ in range(q):
  question = input().split()
  c = int(question[0])
  d = int(question[1])
  closest = None
  minwork = float('inf')
  for elevatornumber,a,b in Elevators:
    if (a>=c and c>=d and d>=b) or (a<=c and c<=d and d<=b):
       work = 0
       if work < minwork:
        minwork = work
        closest = elevatornumber
    elif (a<=c and c<=b and b<d) or (a>=c and c>=b and b>d):
       work = abs(d - b)
       if work < minwork:
        minwork = work
        closest = elevatornumber
    else:
       work = abs(b - c) + abs(d - c)
       if work < minwork:
        minwork= work
        closest = elevatornumber
  print(">>"+str(closest))

6631550721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 266, 'const': 171, 'code+const': 437}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
lifts = []
for i in range(n):
    lift_num, lift_current_floor, lift_destination_floor = map(int, input().split())
    lifts.append((lift_num, lift_current_floor, lift_destination_floor))
m = int(input())
for i in range(m):
    a = input().split()
    user = int(a[0])
    target_f = int(a[1])
    minf = float("inf")
    best = None
    for lift_n, current_f, target in lifts :
        if current_f <= user and target_f >= user :
            add = abs(target_f - target)
        elif current_f >= user and target_f <= user :
            add = abs(target_f - target)
        else:
            add = abs(target - user) + abs(target_f - user)
        if add < minf:
            minf = add
            best = lift_n
    print(">>", best)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631551321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
1
>> 2
1
>> 4
0
>> 1
[]
test_main_21.0
5
>> 1
4
>> 2
5
>> 3
5
>> 4
[]
test_main_31.0
3
>> 1
2
>> 1
3
>> 1
2
>> 2
3
>> 2
2
>> 3
3
>> 3
2
>> 4
3
>> 4
[]
test_main_41.0
15
>> 4
7
>> 4
7
>> 4
5
>> 3
5
>> 3
3
>> 2
3
>> 2
1
>> 1
1
>> 1
[]
test_main_51.0
17
>> 3
7
>> 3
7
>> 3
5
>> 4
5
>> 4
3
>> 2
3
>> 2
1
>> 1
1
>> 1
1
>> 1
1
>> 1
1
>> 1
[]
test_main_61.0
12
>> 1
10
>> 1
10
>> 1
8
>> 2
8
>> 2
6
>> 3
6
>> 3
4
>> 4
4
>> 4
4
>> 4
4
>> 4
[]
test_main_71.0
13
>> 1
11
>> 1
11
>> 1
9
>> 2
9
>> 2
7
>> 4
7
>> 3
5
>> 3
5
>> 3
5
>> 3
5
>> 3
5
>> 3
[]
test_main_81.0
6
>> 2
2
>> 1
3
>> 1
4
>> 1
5
>> 1
6
>> 1
2
>> 3
3
>> 3
4
>> 3
5
>> 3
6
>> 3
6
>> 1
5
>> 6
4
>> 6
3
>> 6
2
>> 6
6
>> 3
5
>> 4
4
>> 4
3
>> 4
2
>> 4
6
>> 5
[]
bytecount: {'code': 744, 'const': 228, 'code+const': 972}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift_no = [0]*n
startl = [0]*n
stopl = [0]*n
for i in range(0,n):
 x = input().split()
 lift_no[i] = int(x[0])
 startl[i] = int(x[1])
 stopl[i] = int(x[2])
m = int(input())
startp = [0]*m
stopp = [0]*m
for k in range(0,m):
 u = input().split()
 startp[k] = int(u[0])
 stopp[k] = int(u[1])
 def a(stal,stol,stap,stp):
  if (stal <= stap <= stol < stp) or (stp < stol <= stap <= stal) :
    out = abs(stp-stol)
  elif (stal <= stap <= stp <= stol) or (stol <= stp <= stap <= stal) :
    out = 0
  else :
    out = abs(stol-stap)+abs(stap-stp)
  return out
 def min_l(yeah,s):
  min = yeah[0][s]
  for t in range(0,len(yeah)):
    if yeah[t][s] < min :
      min = yeah[t][s]
  return min
j = []
z = []
for q in range(0,m):
  stap = int(startp[q])
  stp = int(stopp[q])
  for h in range(0,n):
    lift = int(lift_no[h])
    stal = int(startl[h])
    stol = int(stopl[h])
    j.append([lift,a(stal,stol,stap,stp)])
  mini = min_l(j,1)
  print(mini)
  for v in range(0,len(j)):
    if j[v][1] == mini:
      z.append(j[v])
  if len(z) == 1:
    print(">> "+str(z[0][0]))
  else :
    print(">> "+str(min_l(z,0)))
  j.clear()
  z.clear()

6631702821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 492, 'const': 179, 'code+const': 671}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
nlift=int(input())
number=[]
now=[]
go=[]
final=[]
for i in range(nlift):
    numberlift,nowlift,golift=(int(e) for e in input().split())
    number.append(numberlift)
    now.append(nowlift)
    go.append(golift)
mquestion=int(input())
for i in range(mquestion):
    nowfloor,gofloor=(int(e) for e in input().split())
    minimum=1000
    solution=1000
    for j in range(nlift):
        if (go[j]>now[j]) and (gofloor>nowfloor) and (now[j]<=nowfloor):
            ans=gofloor-go[j]
            if ans<minimum:
                minimum=ans
                solution=number[j]
            if gofloor<go[j]:
                ans=0
        if (go[j]<now[j]) and (gofloor<nowfloor) and (now[j]>=nowfloor):
            ans=go[j]-gofloor
            if ans<minimum:
                minimum=ans
                solution=number[j]
            if go[j]<gofloor:
                ans=0
        else:
            ans=abs(go[j]-nowfloor)+abs(nowfloor-gofloor)
            if ans<minimum:
                minimum=ans
                solution=number[j]
    final.append(solution)
i=0
while i<mquestion:
    print(">>",final[i])
    i+=1

6631801221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 480, 'const': 115, 'code+const': 595}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
many_lift = int(input())
x = []
y = []
z = []
ans = []
i = 0
for i in range(many_lift):
    num_lift, lift_stay , lift_go = [int(i) for i in input().split()]
    x.append(num_lift)
    y.append(lift_stay)
    z.append(lift_go)
many_q = int(input())
for i in range(many_q):
    i_stay , i_go = [int(i) for i in input().split()]
    inx = 0
    minn = 2e18
    for k in range(many_lift):
        if i_stay < i_go and y[k] < z[k]  and i_stay >= y[k]: #ขึ้น
            f = (i_go - z[k])
            if minn > f:
                minn = f
                inx = x[k]
            if f < 0:
                f = 0
        if i_stay > i_go and y[k] > z[k]  and i_stay <= y[k]:#ลง
            f = (z[k] - i_go)
            if minn > f:
                minn = f
                inx = x[k]
            if f < 0:
                f = 0
        else: #ลิฟไม่ผ่าน
            if minn > abs(i_stay - z[k]) + abs(i_go - i_stay):
                minn = abs(i_stay - z[k]) + abs(i_go - i_stay)
                inx = x[k]
    ans.append(inx)
for e in ans:
    print(">>" + str(e))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6631804121: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 478, 'const': 147, 'code+const': 625}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n_elevator = int(input()) #รับค่าจำนวนลิฟต์
lnumber_elevator = [] #สร้างlistเพื่อเก็บค่า
lstart_elevator = []
lend_elevator = []
lanswer = []
for i in range(0,n_elevator):
    number_elevator , start_elevator , end_elevator = [int(e) for e in input().split()]
    lnumber_elevator.append(number_elevator) #เก็บค่าหมายเลขลิฟต์
    lstart_elevator.append(start_elevator)#เก็บค่าจุดที่ลิฟต์อยู่
    lend_elevator.append(end_elevator)#เก็บค่าจุดหมายของลิฟต์
question  = int(input())#รับจำนวนคำถาม
for i in range(0,question):
    start_question , end_question = [int(e) for e in input().split()]
    Min = 999999999 #เช็คค่าน้อยสุด
    answer = -1 #
    for j in range(n_elevator):
        if start_question <= lstart_elevator[j] and end_question - start_question <0 and lend_elevator[j] - lstart_elevator[j] < 0 : #เช็คว่าผ่านและเราต้องการลง
            distance = lend_elevator[j] - end_question
            if distance < 0:
                distance = 0
            if distance < Min:
                Min = distance
                answer = lnumber_elevator[j]
        if start_question >= lstart_elevator[j] and end_question - start_question > 0 and lend_elevator[j] - lstart_elevator[j] > 0 : #เช็คว่าผ่านและเราต้องการขึ้น
            distance = end_question - lend_elevator[j]
            if distance < 0:
                distance = 0
            if distance < Min:
                Min = distance
                answer = lnumber_elevator[j]
        else:
            distance = abs(start_question -lend_elevator[j] ) + abs(end_question-start_question)
            if distance < Min :
                Min = distance
                answer = lnumber_elevator[j]
    lanswer.append(answer)
for i in range(question):
    print(">>",lanswer[i])

6631806421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 590, 'const': 215, 'code+const': 805}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
elevator = []
q = []
number = []
def calculate_burden(floor, destination, reqfloor, reqdestination):
    if (destination - floor >= 0 and reqdestination - reqfloor >= 0) or        (destination - floor <= 0 and reqdestination - reqfloor <= 0):
        if reqfloor in range(floor,destination+1):
            burden = abs(reqdestination - destination)
        elif reqfloor in range(destination, floor+1):
            burden = abs(reqdestination - destination)
        else:
            burden = abs(reqfloor - destination) + abs(reqdestination - reqfloor)
    else:
        burden = abs(reqfloor - destination) + abs(reqdestination - reqfloor)
    return burden
for i in range(n):
    elevator.append([int(e) for e in input().split()])
    number.append(elevator[i][0])
m = int(input())
for i in range(m):
    q.append([int(e) for e in input().split()])
burden_list = []
for i in range(m):
    for j in range(n):
        burden_list.append(calculate_burden(elevator[j][1], elevator[j][2], q[i][0], q[i][1]))
question_list = []
for i in range(0,len(burden_list),n)  :
    question_list.append(burden_list[i:i+n])
min_list = []
for i in range(len(question_list)):
    min_list.append(min(question_list[i]))
min_num = []
for i in range(len(min_list)):
    min_num.append(number[question_list[i].index(min_list[i])])
    print('>>',min_num[i])

6631810921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 726, 'const': 147, 'code+const': 873}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
i = 0
num = []
li = []
lf = []
for i in range(n)  :
  x = [int(e) for e in input().split()]
  num += [x[0]]
  li += [x[1]]
  lf += [x[2]]
  i += 1
m = int(input())
j = 0
mi = []
mf = []
for j in range(m) :
  y = [int(e) for e in input().split()]
  mi += [y[0]]
  mf += [y[1]]
  j += 1
min_num = []
for k in range(m) :
  burden_list = []
  for z in range(n) :
    if mf[k]-mi[k] >= 0 and lf[z]-li[z] > 0 :
      if li[z] <= mi[k] <= lf[z] :
        if mf[k] <= lf[z] : burden = 0
        else : burden = abs(mf[k] - lf[z])
      else : burden = abs(lf[z]-mi[k]) + abs(mf[k]-mi[k])
    elif mf[k]-mi[k] <= 0 and lf[z]-li[z] < 0 :
      if li[z] >= mi[k] >= lf[z] :
        if mf[k] >= lf[z] : burden = 0
        else : burden =  abs(lf[z] - mf[k])
      else : burden = abs(lf[z]-mi[k]) + abs(mf[k]-mi[k])
    else : burden = abs(lf[z]-mi[k]) + abs(mf[k]-mi[k])
    burden_list += [burden]
  min_index = min([burden_list.index(min(burden_list))])
  min_num += [num[min_index]]
for w in range(m) :
  print('>>',min_num[w])

6632017821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 992, 'const': 534, 'code+const': 1526}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def minimum(arr):
    temp = arr
    l = len(arr)
    for i in range(l-1):
        temp[i+1] = min(temp[i],temp[i+1])
    return temp[l-1]
def posmin(arr):
    l = len(arr)
    p = 0
    m = minimum(arr)
    while arr[p] != m:
        p+=1
    return p+1
def adist(a,b,x,y):
    if ((a>=b and x>=y) or (a<b and x<y)) and (b<=x<=a or a<=x<=b):
        if y<=a:
            return abs(a-min(b,y))
        if y>a:
            return abs(max(b,y)-a)
    else:
        return abs(a-b)+abs(b-x)+abs(x-y)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
N = int(input())
p1 = [0]*N
l = [[0 for i in range(3)] for j in range(N)]
for i in range(N):
    p1[i] = input()
    for j in range(3):
        l[i][j] = int(p1[i].split(' ')[j])
nab = [[0 for i in range(10)] for j in range(N)]
for i in range(N):
    k = l[i][0]
    nab[k-1][1] = l[i][1]
    nab[k-1][2] = l[i][2]
Q = int(input())
p2 = [0]*Q
nxy = [[0 for i in range(2)] for j in range(Q)]
for i in range(Q):
    p2[i] = input()
    for j in range(2):
        nxy[i][j] = int(p2[i].split(' ')[j])
h = [[0 for i in range(N)] for j in range(Q)]
for i in range(Q):
    for j in range(N):
        h[i][j] = adist(nab[j][1],nab[j][2],nxy[i][0],nxy[i][1])-abs(nab[j][1]-nab[j][2])
for i in range(Q):
    print('>> '+str(posmin(h[i])))

6632034421: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 470, 'const': 147, 'code+const': 617}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
l = [] #list
a = [] #answer all
for i in range(n):
    l.append([int(e) for e in input().split()])
for i in range(int(input())):
    a.append([int(e) for e in input().split()])
for q in a:
    c = q[0]#c=currentfloor
    d = q[1]#d=destination
    workload = []
    for e in l :
        if (e[1] <= c <= e[2] or e[2]<= c <=e[1]) and ((e[2] >= e[1] and d >= c ) or (e[1] >= e[2] and d <= c)):
            if  (e[1] <= d <= e[2] or e[2]<= d <=e[1]):
                workload.append(0)
            else :
                A = abs(d-e[2])
                workload.append(A)
        else :
            B = abs(c-e[2])+abs(d-c)
            workload.append(B)
    Index = workload.index(min(workload))
    print(">>", l[Index][0])
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632038021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 498, 'const': 176, 'code+const': 674}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
l = []
for i in range(n):
  lift = input().split()
  l.append(lift)
m = int(input())
h = []
for i in range(m):
  human = input().split()
  h.append(human)
for k in range(m):
  f_h1 = int(h[k][0])
  f_h2 = int(h[k][1])
  di_h = f_h2 - f_h1
  if di_h >= 0:
    di_h2 = 1
  else:
    di_h2 = -1
  x = []
  for j in range(n):
    n_l = int(l[j][0])
    f_l1 = int(l[j][1])
    f_l2 = int(l[j][2])
    di_l = f_l2 - f_l1
    if di_l >= 0:
      di_l2 = 1
    else:
      di_l2 = -1
    if di_h2 != di_l2:
      a = abs(f_h1 - f_l2) + abs(di_h)
    else:
      if di_h2 == 1:
        if f_l1 <= f_h1 <= f_l2:
          a = abs(f_h2 - f_l2)
        else:
          a = abs(f_h1 - f_l2) + abs(di_h)
      elif di_h2 == -1:
        if f_l1 >= f_h1 >= f_l2:
          a = abs(f_h2 - f_l2)
        else:
          a = abs(f_h1 - f_l2) + abs(di_h)
    x.append(a)
  b = min(x)
  for a in x:
    if a == b:
      c = x.index(a)
      d = l[c][0]
  print(">> " + d)

6632078021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 548, 'const': 147, 'code+const': 695}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n=int(input())
number=[0]*n
numnow=[0]*n
numlast=[0]*n
for u in range(n):
    x = input().split()
    number[u]=int(x[0])
    numnow[u]=int(x[1])
    numlast[u]=int(x[2])
m=int(input())
kodlift=[0]*m
wantgo=[0]*m
for me in range(m):
    x=input().split()
    kodlift[me]=int(x[0])
    wantgo[me]=int(x[1])
for me in range(m) :
    distance = 0
    ans1 = 0
    ans2 = 0
    for u in range (n) :
        if (numnow[u] <=  kodlift[me] <= wantgo[me] <= numlast[u]) or (numnow[u] >=  kodlift[me] >= wantgo[me] >= numlast[u])  :
            distance = 0
        elif (numnow[u] <=  kodlift[me] <= numlast[u] <= wantgo[me]) or (numnow[u] >=  kodlift[me] >= numlast[u] >= wantgo[me]) :
            distance = abs(wantgo[me]-numlast[u])
        else :
            distance = abs(numlast[u]-kodlift[me]) + abs(kodlift[me]-wantgo[me])
        if u == 0 or distance < ans1:
            ans1 = distance
            ans2 = number[u]
    print('>>',ans2)

6632092821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 562, 'const': 351, 'code+const': 913}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
import math
def create_list(n):
    lift_list = [] ## lift_list = [[id, f_i, f_f]]
    while n > 0:
        lift = []
        id, f_i, f_f = input().split()
        lift.append(int(id))
        lift.append(int(f_i))
        lift.append(int(f_f))
        lift_list.append(lift)
        n -= 1
    return lift_list
def check_lift(lift, n, g, i):
    i -= 1
    f_i, f_f= lift[i][1], lift[i][2]
    lowi = min(f_i, f_f)
    maxi = max(f_i, f_f)
    if lowi <= n <= maxi:
        if lowi <= g <= maxi and ((lift[i][1] <= lift[i][2] and n <= g) or (lift[i][1] >= lift[i][2] and n >= g)):
            return 0
        return abs(g - f_f)
    else:
        return abs(n - f_f) + abs(g - n)
def M(n, m, lift_list):
  id_final = []
  while m > 0:
    i = n
    now, go = input().split()
    w_list = []
    while i > 0:
      w = check_lift(lift_list, int(now), int(go), i)
      w_list.append(w)
      i -= 1
    w_list = w_list[::-1]
    id_final.append(lift_list[w_list.index(min(w_list))][0])
    m -= 1
  return id_final
n = int(input())
lift_list = sorted(create_list(n))
m = int(input())
for i in M(n, m, lift_list):
  print(">>", i)

6632107621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 408, 'const': 215, 'code+const': 623}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def burden(i, c, d) :
  a, b = int(first[i][1]), int(first[i][2])
  if a <= c <= b or b <= c <=a :
    if b <= d <= c or c <= d <= b :
      return 0
    else : return abs(b-d)
  else : return abs(b-c) + abs(c-d)
n = int(input())
first = [0]
for i in range(n) :
  first.append(input().split())
m = int(input())
for i in range(m) :
  y1, y2 = [int(e) for e in input().split()]
  for i in range(1,n+1) :
    if i == 1 :
      min = burden(i, y1, y2); ind = int(first[1][0])
    if min > burden(i, y1, y2) :
      min = burden(i, y1, y2); ind = int(first[i][0])
  print(">>", ind)

6632111021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 432, 'const': 408, 'code+const': 840}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def calculate_load(a, b, c, d, n):
  # a = current
  # b = destination
  # c = p_current
  # d = p_destination
  # n = lift_number
  if a >= c >= d >= b or a <= c <= d <= b:
    way = 0
  elif a >= c >= b or a <= c <= b:
    way = abs(b-d)
  else:
    way = abs(b-c)+abs(c-d)
  return {n : way}
lift_amount = int(input())
lift = dict({})
for i in range(lift_amount):
  lift_details = input().split()
  lift.update({int(lift_details[0]): {"current": int(lift_details[1]), "destination": int(lift_details[2])}})
lift = dict(sorted(lift.items()))
test_amount = int(input())
for i in range(test_amount):
    test_details = input().split()
    p_current, p_destination = int(test_details[0]), int(test_details[1])
    lift_load = dict({})
    for lift_number in lift:
      lift_load.update(calculate_load(lift[lift_number]['current'], lift[lift_number]['destination'], p_current, p_destination, lift_number))
    print(">> " + str(min(lift_load, key=lift_load.get)))
# def intersect(a, b, c, d):
#   if a > b:
#     a, b = b, a
#   if c > d:
#     c, d = d, c
#   if a >= c and b <= d:
#     return a - b
#   elif c >= a and d <= b:
#     return d - c
#   elif b > c:
#     return b - c
#   elif d > a:
#     return d - a
#   else:
#     return 0
# def calculate_load(a, b, c, d, n):
#   # a = current
#   # b = destination
#   # c = p_current
#   # d = p_destination
#   # n = lift_number
#   way_1 = abs(b-c)+abs(c-d) # a -> b -> c -> d
#   way_2 = abs(a-c)+abs(c-d)+abs(d-b)-intersect(a, b, c, d) # a -> c -> d -> b
#   # if a > c > d or d > c > a:
#   #   way_2 -= abs(a-d)
#   way_3 = abs(a-c)+abs(c-b)+abs(b-d)-intersect(a, b, c, d) # a -> c -> b -> d
#   # if a > c > b or b > c > a:
#   #   way_3 -= abs(a-b)
#   return {n :min(way_1, way_2, way_3)}
# The method above is smarter but contradicts with the test case thus is unusable.

6632123621: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1450, 'const': 175, 'code+const': 1625}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
elevator = [] #ข้อมูลลิฟท์
n_of_elevator = int(input())
for i in range(n_of_elevator):
  elevator.append(input().split()) # มี 3 columns
#############################################
user = [] #ข้อมูลคนใช้ลิฟท์
n_of_user = int(input())
for j in range(n_of_user):
  user.append(input().split()) # มี 2 columns
############################################################
check = 9999999
flag = 0;
for i in range(n_of_user):
  #คนขึ้น
  if int(user[i][1]) - int(user[i][0]) > 0:
    for j in range(n_of_elevator):
      #ลิฟต์ขึ้น
      if int(elevator[j][2]) - int(elevator[j][1]) > 0:
        # user start < elevator start
        if int(user[i][0]) < int(elevator[j][1]):
          min = int(elevator[j][2]) + int(user[i][1]) - (2*int(user[i][0]))
          if min < check:
            check = min
            flag = elevator[j][0]
        # user start > elevator start
        elif int(user[i][0]) >= int(elevator[j][1]):
          min = int(user[i][1]) - int(elevator[j][2])
          if min < check:
            check = min
            flag = elevator[j][0]
      #ลิฟต์ลง
      elif int(elevator[j][2]) - int(elevator[j][1]) < 0:
        # user start < elevator destination
        if int(user[i][0]) < int(elevator[j][2]):
          min = int(elevator[j][2]) + int(user[i][1]) - (2*int(user[i][0]))
          if min < check:
            check = min
            flag = elevator[j][0]
        # user start > elevator destination
        elif int(user[i][0]) >= int(elevator[j][2]):
          min = int(user[i][1]) - int(elevator[j][2])
          if min < check:
            check = min
            flag = elevator[j][0]
      #ลิฟต์อยู่กับที่ -> elevator[j][2] - elevator[j][1] == 0
      elif int(elevator[j][2]) - int(elevator[j][1]) == 0:
        min = abs(int(elevator[j][2]) - int(user[i][0])) + abs(int(user[i][1])-int(user[i][0]))
        if min < check:
          check = min
          flag = elevator[j][0]
    print('>>',flag)
    check = 9999999
  #คนลง -> user[i][1] - user[i][0] < 0
  elif int(user[i][1]) - int(user[i][0]) < 0:
    for j in range(n_of_elevator):
      #ลิฟต์ลง
      if int(elevator[j][2]) - int(elevator[j][1]) < 0:
        # user start <= elevator start
        if int(user[i][0]) <= int(elevator[j][1]):
          min = - (int(user[i][1]) - int(elevator[j][2]))
          if min < check:
            check = min
            flag = elevator[j][0]
        # user start > elevator start
        else :
          min = - (int(elevator[j][2]) + int(user[i][1]) - (2*int(user[i][0])))
          if min < check:
            check = min
            flag = elevator[j][0]
      #ลิฟต์ขึ้น
      elif int(elevator[j][2]) - int(elevator[j][1]) > 0:
        # user start <= elevator destination
        if int(user[i][0]) <= int(elevator[j][2]):
          min = - (int(user[i][1]) - int(elevator[j][2]))
          if min < check:
            check = min
            flag = elevator[j][0]
        # user start > elevator destination
        else:
          min = - (int(elevator[j][2]) + int(user[i][1]) - (2*int(user[i][0])))
          if min < check:
            check = min
            flag = elevator[j][0]
      #ลิฟต์อยู่กับที่ -> elevator[j][2] - elevator[j][1] == 0
      elif int(elevator[j][2]) - int(elevator[j][1]) == 0:
        min = abs(int(elevator[j][2]) - int(user[i][0])) + abs(int(user[i][1])-int(user[i][0]))
        if min < check:
          check = min
          flag = elevator[j][0]
    print('>>',flag)
    check = 9999999

6632140221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 548, 'const': 211, 'code+const': 759}
8# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
num = int(input().strip())
lif = []
for i in range(num):
    temp = [int(e) for e in input().split()]
    lif.append(temp)
num = int(input().strip())
for i in range(num):
    def Func(ans):
        return ans[1]
    ans = []
    t = [int(e) for e in input().split()]
    for a, b, c in lif:
        if b > c and t[0] > t[1]:
            if t[0] <= b:
                if c <= t[1]:
                    ans.append([a, 0])
                else:
                    ans.append([a, abs(c - t[1])])
            else:
                ans.append([a, abs(t[0] - c) + abs(t[0] - t[1])])
        elif b < c and t[0] < t[1]:
            if t[0] >= b:
                if c >= t[1]:
                    ans.append([a, 0])
                else:
                    ans.append([a, abs(c - t[1])])
            else:
                ans.append([a, abs(t[0] - c) + abs(t[0] - t[1])])
        else:
            ans.append([a, abs(t[0] - c) + abs(t[0] - t[1])])
    ans.sort(key=Func)
    print(">>", ans[0][0])

6632149021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 900, 'const': 516, 'code+const': 1416}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def in_put(n):
  list = []
  for i in range(0,n):
    a = input()
    a = a.split()
    list.extend(a)
  return list
def split(list,n):
  list = [list[i:i+n] for i in range(0,len(list),n)]
  return list
def up_down(a,b):
  if a-b>0:
    direct = 0
  elif a-b<0:
    direct = 1
  else :
    direct = 2
  return direct
def find(a,b,c,d):
  if up_down(a,b) == up_down(c,d):
    if ((a<b) and (c in range(a,b+1) and d in range(a,b+1))) or ((a>b) and (c in range(b,a+1) and d in range(b,a+1))):
      t = 0
    elif (a<b) and (c in range(a,b+1) and d not in range(a,b+1)) or ((a>b) and (c in range(b,a+1) and d not in range(b,a+1))):
      t = abs(d-b)
    else:
      t = abs(c-b)+abs(c-d)
  else:
    t = abs(c-b)+abs(c-d)
  return t
def min2D(y,arr) :
  min = arr[0][y]
  for i in range(1,len(arr)):
    if arr[i][y] < min:
      min = arr[i][y]
  return min
n = int(input())
n = in_put(n)
n = split(n,3)
test = int(input())
test = in_put(test)
test = split(test,2)
top = []
min_index = []
for i in range(0,len(test)):
    c = int(test[i][0])
    d = int(test[i][1])
    for v in range(0,len(n)):
        name = int(n[v][0])
        a = int(n[v][1])
        b = int(n[v][2])
        top.append([name,a,b,c,d,find(a,b,c,d)])
    min = min2D(5,top)
    for i in range(0,len(top)):
      if top[i][5] == min:
          min_index.append(top[i])
    if len(min_index) == 1:
      print(">> "+str(min_index[0][0]))
    else :
      print(">> "+str(min2D(0,min_index)))
    min_index.clear()
    top.clear()

6632163721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 466, 'const': 147, 'code+const': 613}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
import math
n = int(input())
l_i = [0]*n
l_f = [0]*n
for i in range(n):
  x = input().split()
  l_i[int(x[0])-1] = int(x[1])
  l_f[int(x[0])-1] = int(x[2])
m = int(input())
h_i = [0]*m
h_f = [0]*m
for i in range(m):
  x = input().split()
  h_i[i] = int(x[0])
  h_f[i] = int(x[1])
for i in range(m):#question
  num = [0]*n
  for j in range(n):#lift
    if (min(l_i[j],l_f[j]) <= h_i[i] <= max(l_i[j],l_f[j])):
      if not(min(h_i[i],l_f[j]) <= h_f[i] <= max(h_i[i],l_f[j])):
        num[j] += abs(l_f[j]-h_f[i])
    else:
      num[j] += abs(l_f[j]-h_i[i]) + abs(h_i[i]-h_f[i])
  print(">>", num.index(min(num)) + 1)

6632171721: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
Lift Data: [['1', '3', '1', 'down', 8, 9, 1], ['2', '1', '8', 'up', 1, 6, 6], ['3', '2', '2', 'stay', 7, 8, 2], ['4', '12', '3', 'down', 6, 1, 1]]
>> 2
>> 4
>> 1
[]
test_main_21.0
Lift Data: [['1', '3', '1', 'down', 5, 11, 14, 6], ['2', '2', '8', 'up', 12, 4, 7, 7], ['3', '10', '10', 'stay', 14, 6, 5, 9], ['4', '12', '6', 'down', 10, 6, 9, 5]]
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
Lift Data: [['1', '2', '2', 'stay', 3, 2, 3, 4, 5, 6, 7, 8, 9], ['2', '4', '4', 'stay', 5, 4, 3, 2, 3, 4, 5, 6, 7], ['3', '6', '6', 'stay', 7, 6, 5, 4, 3, 2, 3, 4, 5], ['4', '8', '8', 'stay', 9, 8, 7, 6, 5, 4, 3, 2, 3]]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
Lift Data: [['1', '8', '11', 'up', 21, 19, 17, 15, 13, 11, 9, 1, 1], ['2', '6', '9', 'up', 19, 17, 15, 13, 11, 3, 3, 3, 3], ['3', '4', '7', 'up', 17, 15, 13, 5, 5, 5, 5, 5, 5], ['4', '2', '5', 'up', 15, 7, 7, 7, 7, 7, 7, 7, 7]]
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
Lift Data: [['1', '6', '2', 'down', 23, 21, 19, 17, 15, 13, 11, 1, 1, 1, 1, 1], ['2', '8', '4', 'down', 21, 19, 17, 15, 13, 3, 3, 3, 3, 3, 3, 3], ['3', '12', '8', 'down', 17, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7], ['4', '10', '6', 'down', 19, 17, 15, 5, 5, 5, 5, 5, 5, 5, 5, 5]]
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
Lift Data: [['1', '8', '11', 'up', 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10], ['2', '6', '9', 'up', 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8], ['3', '4', '7', 'up', 16, 14, 12, 10, 8, 6, 6, 6, 6, 6, 6], ['4', '2', '5', 'up', 18, 16, 14, 12, 10, 8, 6, 4, 4, 4, 4]]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
Lift Data: [['1', '6', '2', 'down', 13, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11], ['2', '8', '4', 'down', 15, 13, 11, 9, 9, 9, 9, 9, 9, 9, 9, 9], ['3', '12', '8', 'down', 19, 17, 15, 13, 11, 9, 7, 5, 5, 5, 5, 5], ['4', '10', '6', 'down', 17, 15, 13, 11, 9, 7, 7, 7, 7, 7, 7, 7]]
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
Lift Data: [['2', '5', '2', 'down', 6, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], ['1', '2', '5', 'up', 9, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], ['3', '7', '10', 'up', 14, 13, 12, 11, 10, 9, 2, 3, 4, 5, 6, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 11], ['6', '10', '7', 'down', 11, 10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 6, 5, 4, 3, 2, 9, 10, 11, 12, 13, 14], ['5', '12', '15', 'up', 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 6], ['4', '15', '12', 'down', 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 9]]
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1156, 'const': 739, 'code+const': 1895}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
num_lift = int(input())
data_lift = []
data_question = []
a = []
b =[]
load = 0
for i in range(num_lift):
    x = input().split()
    data_lift.append(x)
num_question = int(input())
for i in range(num_question):
    x = input().split()
    data_question.append(x)
def check_lift(data_lift):
    for i in range(len(data_lift)):
        if int(data_lift[i][2])-int(data_lift[i][1]) < 0:
            a.append(data_lift[i]+["down"])
        elif int(data_lift[i][2])-int(data_lift[i][1]) == 0:
            a.append(data_lift[i]+["stay"])
        else:
            a.append(data_lift[i]+["up"])
    return a
def check_demand(data_question):
    for i in range(len(data_question)):
        if int(data_question[i][1])-int(data_question[i][0]) < 0:
            b.append(data_question[i]+["down"])
        else :
            b.append(data_question[i]+["up"])
    return b
A = check_lift(data_lift)
B = check_demand(data_question)
for i in range(len(B)):
    for k in range(len(A)):
        if A[k][3] != B[i][2]:
         load += abs(int(B[i][0])-int(A[k][2]))+abs(int(B[i][1])-int(B[i][0]))
         A[k].append(load)
         load = 0
        elif A[k][3] == B[i][2] and (int(A[k][1]) <= int(B[i][0]) <= int(A[k][2]) or int(A[k][2]) <= int(B[i][0]) <= int(A[k][1])):
          load += abs(int(B[i][1]) - int(A[k][2]))
          A[k].append(load)
          load = 0
        elif A[k][3] == B[i][2] and not(int(A[k][1]) <= int(B[i][0]) <= int(A[k][2]) or int(A[k][2]) <= int(B[i][0]) <= int(A[k][1])):
          load += abs(int(B[i][0])-int(A[k][2]))+abs(int(B[i][1])-int(B[i][0]))
          A[k].append(load)
          load = 0
print("Lift Data:", A)
best_lifts = []
for i in range(num_question):
    min_load = float('inf')
    best_lift = None
    for k in range(num_lift):
        if A[k][i + 4] < min_load:
            min_load = A[k][i + 4]
            best_lift = A[k][0]
    best_lifts.append(best_lift)
for e in best_lifts:
    print(">>",e)

6632175221: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 398, 'const': 171, 'code+const': 569}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
n = int(input())
a = []
s = []
e = []
for i in range(n):
    ss = input().split()
    a.append(int(ss[0]))
    s.append(int(ss[1]))
    e.append(int(ss[2]))
t = int(input())
ans = []
while(t):
    t-=1
    ss = input().split()
    mems = int(ss[0])
    meme = int(ss[1])
    minn = 2e18
    idx=0
    for i in range(n):
        if(s[i]<=mems<=e[i] or e[i]<=mems<=s[i]):
            if(minn>abs(e[i]-meme)):
                minn=abs(e[i]-meme)
                idx=i
        else:
            if(minn>abs(e[i]-mems)+abs(meme-mems)):
                minn=abs(e[i]-mems)+abs(meme-mems)
                idx=i
    ans.append(a[idx])
for k in ans: print(">>"+str(k))
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้

6632184921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 464, 'const': 315, 'code+const': 779}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
def sign(num):
    return 1 if num > 0 else -1 if num < 0 else 0
def in_range(num, val1, val2):
    if val1 <= val2:
        return val1 <= num <= val2
    return val2 <= num <= val1
n = int(input())
lifts = []          # [no., from, to, lift_dir]
for i in range(n):
    lifts.append([int(x) for x in input().split()])
    lifts[i].append(sign(lifts[i][2] - lifts[i][1]))
m = int(input())
for i in range(m):
    u_st, u_ed = [int(x) for x in input().split()]
    u_dir = sign(u_ed - u_st)
    u_cost = abs(u_ed - u_st)
    idx, min_cost = 0, 99999999
    for num, lift_st, lift_ed, lift_dir in lifts:
        cost = 0
        if lift_st != lift_ed:
            if in_range(u_st, lift_st, lift_ed):
                if (lift_dir != u_dir or not in_range(u_ed, lift_st, lift_ed)):
                    cost += abs(lift_ed - u_ed)
            else:
                cost += abs(lift_ed - u_st) + u_cost
        else:
            cost += abs(u_st - lift_st) + u_cost
        if cost < min_cost:
            idx = num
            min_cost = cost
    print('>>', idx)

6632187821: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 796, 'const': 304, 'code+const': 1100}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = [0]*n
for i in range(n) :
    lift[i] = input().split()
q = int(input())
me = [0]*q
for i in range(q) :
    me[i] = input().split()
lstate = [0]*n
for k in range(n) :
    if int(lift[k][2]) - int(lift[k][1]) > 0 :
        lstate[k] = 'up'
    if int(lift[k][2]) - int(lift[k][1]) < 0 :
        lstate[k] = 'down'
    if int(lift[k][2]) - int(lift[k][1]) == 0 :
        lstate[k] = 'rest'
mstate = [0]*q
for k in range(q) :
    if int(me[k][1]) - int(me[k][0]) > 0 :
        mstate[k] = 'up'
    if int(me[k][1]) - int(me[k][0]) < 0 :
        mstate[k] = 'down'
eq = [0]*q
el = [0]*n
for i in range(q) :
    for j in range(n) :
        x = min(int(lift[j][1]),int(lift[j][2]))
        y = max(int(lift[j][1]),int(lift[j][2]))
        if mstate[i] == lstate[j] and x <= int(me[i][0]) <= y :
            if x <= int(me[i][1]) <= y :
                el[j] = 0
            else :
                el[j] = abs(int(me[i][1])-int(lift[j][2]))
        else :
            el[j] = abs(int(me[i][0])-int(lift[j][2])) + abs(int(me[i][1])-int(me[i][0]))
    eq[i] = el
    el = [0]*n
    ans = min(eq[i])
    for k in range(n) :
        if eq[i][k] == ans : break
    print('>>',lift[k][0])

6632189021: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1256, 'const': 147, 'code+const': 1403}
# HW02
#รับค่า n
n = int(input())
z1 = n
nlist = []
nlv = 0
while n != 0:
    x = input()
    nlist.append(x)
    n = n - 1
#print(nlist)
#รับค่า m
m = int(input())
z2 = m
mlist = []
mlv = 0
while m != 0:
    x = input()
    mlist.append(x)
    m = m - 1
#print(mlist)
cal = 0
calcal = []
lift = []
pos = 0
#ลูปคำนวนหาค่าภาระของลิฟท์
while mlv != z2:
    j = mlist[mlv].split()
    i = nlist[nlv].split()
    #print(nlv,i)
    #print(mlv,j)
    #อยู่ระหว่างลิฟท์กำลังขึ้น
    if int(j[0]) >= int(i[1]) and int(j[1]) <= int(i[2]) and int(j[0]) in range (int(i[1]), int(i[2]) + 1) and int(j[1]) in range (int(i[1]), int(i[2]) + 1) and int(i[2]) - int(i[1]) > 0 and int(j[1]) - int(j[0]) > 0:
        cal = 0
        #print(cal)
        calcal.append(cal)
        lift.append(int(i[0]))
    #อยู่ระหว่างลิฟท์กำลังลง
    elif int(j[0]) <= int(i[1]) and int(j[1]) >= int(i[2]) and int(j[0]) in range (int(i[2]), int(i[1]) + 1) and int(j[1]) in range (int(i[2]), int(i[1]) + 1) and int(i[2]) - int(i[1]) < 0 and int(j[1]) - int(j[0]) < 0:
        cal = 0
        #print(cal)
        calcal.append(cal)
        lift.append(int(i[0]))
    #อยู่ระหว่างลิฟท์กำลังขึ้นแต่ไปสูงกว่าลิฟท์กำลังขึ้น
    elif int(j[0]) >= int(i[1]) and int(j[1]) > int(i[2]) and int(j[0]) in range (int(i[1]), int(i[2]) + 1) and int(i[2]) - int(i[1]) > 0 and int(j[1]) - int(j[0]) > 0:
        cal = abs(int(j[1]) - int(i[2]))
        #print(cal)
        calcal.append(cal)
        lift.append(int(i[0]))
    #อยู่ระหว่างลิฟท์กำลังลงแต่ไปต่ำกว่าลิฟท์กำลังลง
    elif int(j[0]) <= int(i[1]) and int(j[1]) < int(i[2]) and int(j[0]) in range (int(i[2]), int(i[1]) + 1) and int(i[2]) - int(i[1]) < 0 and int(j[1]) - int(j[0]) < 0:
        cal = abs(int(j[1]) - int(i[2]))
        #print(cal)
        calcal.append(cal)
        lift.append(int(i[0]))
    #นอกกรณี(ลิฟท์กับที่ต้องการไปสวนทางกัน)
    else:
        cal = abs(int(i[2])-int(j[0])) + abs(int(j[1])-int(j[0]))
        ##print(cal)
        calcal.append(cal)
        lift.append(int(i[0]))
    #วนลูปไปคำนวนใหม่
    if nlv != z1 - 1:
        nlv = nlv + 1
        pos = pos + 1
        #print(calcal)
    #จบลูป ไปคำนวนใหม่ และแสดงค่าภาระน้อยสุด
    elif nlv == z1 - 1:
        nlv = 0
        mlv = mlv + 1
        #print(calcal)
        #print(lift)
        print('>>', lift[calcal.index(min(calcal))])
        calcal = []
        lift = []
        pos = 0

6632199321: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 922, 'const': 148, 'code+const': 1070}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lifts = []
for i in range(n) :
    lift_num,initial,final = [int(e) for e in input().split()]
    lifts.append((lift_num,initial,final))
    lifts.sort()
m = int(input())
ques = []
for i in range(m) :
    current,wanttogo = [int(e) for e in input().split()]
    ques.append((current,wanttogo))
j = m
work_elevs = []
while j >= 1 :
    i = n
    while i >= 1 :
        if ques[m-j][1]- ques[m-j][0] >=  0 :
            if ques[m-j][0] not in range (lifts[n-i][1],lifts[n-i][2]+1) :
                work_elev = abs(ques[m-j][0]-lifts[n-i][2]) + abs(ques[m-j][0] - ques[m-j][1])
            elif ques[m-j][0] in range (lifts[n-i][1],lifts[n-i][2]+1) :
                work_elev = abs(lifts[n-i][2] - ques[m-j][1])
        elif ques[m-j][1]- ques[m-j][0] < 0 :
            if ques[m-j][0] in range(lifts[n-i][2],lifts[n-i][1]+1):
                work_elev = abs(lifts[n-i][2]-ques[m-j][1])
            elif ques[m-j][0] not in range(lifts[n-i][2],lifts[n-i][1]+1) :
                work_elev = abs(ques[m-j][0]-lifts[n-i][2]) + abs(ques[m-j][0] - ques[m-j][1])
        work_elevs.append(work_elev)
        i -= 1
    j -= 1
chunk_size = n
sublists = []
for i in range(0,len(work_elevs),chunk_size):
    sublist = work_elevs[i:i + chunk_size]
    sublists.append(sublist)
i = m
while i >= 1 :
    a = sublists[m-i]
    min_val_insublists = min(a)
    min_index = a.index(min_val_insublists)
    print(">> " + str(min_index + 1))
    i -= 1

6632210521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 1068, 'const': 197, 'code+const': 1265}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
#elevator setting
lift = []
n = int(input())
for i in range(n):
    lift.append(input())
#customer setting
man = []
m = int(input())
for i in range(m):
    man.append(input())
#=========================================================#
#elevator list
lift_list = []
for i in range(n):
    lift_mod = list(map(int,lift[i].split(" ")))
    lift_list.append(lift_mod)
Ls = []
Ld = []
for i in range(n):
    Ls.append(lift_list[i][1])
    Ld.append(lift_list[i][2])
#==========================================================#
#customer list
man_list = []
for i in range(m):
    man_mod = list(map(int,man[i].split(" ")))
    man_list.append(man_mod)
Us = []
Ud = []
for i in range(m):
    Us.append(man_list[i][0])
    Ud.append(man_list[i][1])
#=========================================================#
for i in range(m):
    load_list = []
    for j in range(n):
        if Ud[i] - Us[i] > 0 : #check user direction(up)
            if Ld[j] - Ls[j] > 0 :  #check lift direction(up)
                if Us[i] < Ls[j] :
                    load = Ld[j] + Ud[i] - 2*Us[i] #case1
                    load_list.append(load)
                elif Us[i] >= Ls[j] :
                    load = Ud[i] - Ld[j] #case2
                    load_list.append(load)
            elif Ld[j] - Ls[j] < 0: #check lift direction(down)
                if Us[i] < Ld[j] :
                    load = Ld[j] + Ud[i] - 2*Us[i] #case3
                    load_list.append(load)
                elif Us[i] >= Ld[j] :
                    load = Ud[i] - Ld[j] #case4
                    load_list.append(load)
            elif Ld[j] - Ls[j] == 0: #lift don't move
                    load = abs(Ld[j]-Us[i])+abs(Ud[i]-Us[i])
                    load_list.append(load)
        elif Ud[i] - Us[i] < 0 : #check user direction(down)
            if Ld[j] - Ls[j] < 0 :  #check lift direction(down)
                if Us[i] <= Ls[j] :
                    load = -(Ud[i] - Ld[j]) #case5
                    load_list.append(load)
                elif Us[i] > Ls[j] :
                    load = -(Ld[j] + Ud[i] - 2*Us[i]) #case6
                    load_list.append(load)
            elif Ld[j] - Ls[j] > 0: #check lift direction(up)
                if Us[i] <= Ld[j] :
                    load = -(Ud[i] - Ld[j]) #case7
                    load_list.append(load)
                elif Us[i] > Ld[j] :
                    load = -(Ld[j] + Ud[i] - 2*Us[i]) #case8
                    load_list.append(load)
            elif Ld[j] - Ls[j] == 0: #lift don't move
                    load = abs(Ld[j]-Us[i])+abs(Ud[i]-Us[i])
                    load_list.append(load)
    index = load_list.index(min(load_list))
    print(">>",lift_list[index][0])

6632237521: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 628, 'const': 230, 'code+const': 858}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
num=[]; curr=[]; dest=[]; res=[0]*n
for i in range(n):
    a = input().split()
    num.append(int(a[0]))
    curr.append(int(a[1]))
    dest.append(int(a[2]))
m = int(input())
start=[]; end=[]
for i in range(m):
    a = input().split()
    start.append(int(a[0]))
    end.append(int(a[1]))
for i in range(m):
    if start[i]<=end[i]:
        going_up = True
    else:
        going_up = False
    for j in range(n):
        if curr[j]<=dest[j]:
            i_go_up = True
        else:
            i_go_up = False
        if going_up == i_go_up:
            if going_up == True and curr[j]<=start[i] and dest[j]>=end[i]:
                res[j]=0
            elif going_up == False and curr[j]>=start[i] and dest[j]<=end[i]:
                res[j]=0
            #if (curr[j]<=start[i] and dest[j]>=end[i]) or (curr[j]>=start[i] and dest[j]<=end[i]):
            #    res[j]=0
            elif (curr[j]<=start[i] and start[i]<=dest[j]) or (curr[j]>=start[i] and start[i]>=dest[j]):
                res[j]=abs(dest[j]-end[i])
            else:
                res[j]=abs(dest[j]-start[i])+abs(start[i]-end[i])
        else:
            res[j]=abs(dest[j]-start[i])+abs(start[i]-end[i])
    mi=123456789
    tmp=0
    for j in range(n):
        if res[j]<mi:
            mi=res[j]
            tmp=num[j]
    print(">> {}".format(tmp))

6632260921: HW02
testfuncscerrstu_stdoutstu_keptstu_fout
test_main_11.0
>> 2
>> 4
>> 1
[]
test_main_21.0
>> 1
>> 2
>> 3
>> 4
[]
test_main_31.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
[]
test_main_41.0
>> 4
>> 4
>> 4
>> 3
>> 3
>> 2
>> 2
>> 1
>> 1
[]
test_main_51.0
>> 3
>> 3
>> 3
>> 4
>> 4
>> 2
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
[]
test_main_61.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 3
>> 3
>> 4
>> 4
>> 4
>> 4
[]
test_main_71.0
>> 1
>> 1
>> 1
>> 2
>> 2
>> 4
>> 3
>> 3
>> 3
>> 3
>> 3
>> 3
[]
test_main_81.0
>> 2
>> 1
>> 1
>> 1
>> 1
>> 1
>> 3
>> 3
>> 3
>> 3
>> 3
>> 1
>> 6
>> 6
>> 6
>> 6
>> 3
>> 4
>> 4
>> 4
>> 4
>> 5
[]
bytecount: {'code': 640, 'const': 147, 'code+const': 787}
# HW02 (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# เขียนทั้งโปรแกรมใน cell นี่ cell เดียวเท่านั้น
# จะเขียนฟังก์ชันใด ๆ เพิ่ม ก็เขียนใน cell นี้
n = int(input())
lift = []
for i in range(n):
    lift.append([int(e) for e in input().split()])
m = int(input())
go = []
for i in range(m):
    go.append([int(e) for e in input().split()])
for i in range(m):
    cal = []
    x = 0
    for j in range(n):
        if (lift[j][1]<=go[i][0]<=lift[j][2] or lift[j][1]>=go[i][0]>=lift[j][2]) and (((go[i][0]-go[i][1])>0 and (lift[j][1]-lift[j][2])>0) or ((go[i][0]-go[i][1])<0 and (lift[j][1]-lift[j][2])<0)):
            if (lift[j][1]<=go[i][1]<=lift[j][2]) or (lift[j][1]>=go[i][1]>=lift[j][2]):
                move = 0
            else:
                move = abs(go[i][1]-lift[j][2])
            cal.append(move)
        else:
            move = abs(go[i][0]-lift[j][2])+abs(go[i][1]-go[i][0])
            cal.append(move)
    x += cal.index(min(cal))
    print(">>",str(lift[x][0]))