human
What is a Python program to find out which rats get eaten by which cats given the following:
I found an interesting problem on https://www.codechef.com/problems/CATSRATS:
and Bengali as well.
There are N$N$ cats (numbered 1$1$ through N$N$) and M$M$ rats (numbered 1$1$ through M$M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats also want to eat the rats when they get a chance. Both the cats and the rats can only move with constant speed 1$1$.
For each valid i$i$, the i$i$-th cat is initially sleeping at a point a_i$a_i$. At a time s_i$s_i$, this cat wakes up and starts moving to a final point b_i$b_i$ with constant velocity and without any detours (so it arrives at this point at the time e_i = s_i + |a_i-b_i|$e_i = s_i + |a_i-b_i|$). After it arrives at the point b_i$b_i$, it falls asleep again.
For each valid i$i$, the i$i$-th rat is initially hiding at a point c_i$c_i$. At a time r_i$r_i$, this rat stops hiding and starts moving to a final point d_i$d_i$ in the same way as the cats ― with constant velocity and without any detours, arriving at the time q_i = r_i + |c_i-d_i|$q_i = r_i + |c_i-d_i|$ (if it does not get eaten). After it arrives at the point d_i$d_i$, it hides again.
If a cat and a rat meet each other (they are located at the same point at the same time), the cat eats the rat, the rat disappears and cannot be eaten by any other cat. A sleeping cat cannot eat a rat and a hidden rat cannot be eaten ― formally, cat i$i$ can eat rat j$j$ only if they meet at a time t$t$ satisfying s_i \le t \le e_i$s_i \le t \le e_i$ and r_j \le t \le q_j$r_j \le t \le q_j$.
Your task is to find out which rats get eaten by which cats. It is guaranteed that no two cats will meet a rat at the same time.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains two space-separated integers N$N$ and M$M$.
- N$N$ lines follow. For each i$i$ (1 \le i \le N$1 \le i \le N$), the i$i$-th of these lines contains three space-separated integers a_i$a_i$, b_i$b_i$ and...

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is Python program to find out which rats get eaten by which cats.

# cook your dish here
class Animal:
    def __init__(self):
        start, end, starting_time = map(int, input().split())
        
        self.ending_time = starting_time + abs(start - end)
        self.velocity = 1 if end >= start else -1 
        
        self.eaten_by = -1, 10 ** 10
        
        self.start = start 
        self.end = end 
        self.starting_time = starting_time 
        
    def will_collide(self, z):
        if self.starting_time > z.ending_time or self.ending_time < z.starting_time:
            return False 
            
        if self.velocity == z.velocity:
            if self.starting_time > z.starting_time:
                self, z = z, self
            if z.start == self.start + self.velocity * (z.starting_time - self.starting_time):
                return z.starting_time
            else:
                return False
        
        if self.velocity == -1:
            self, z = z, self
        
        t = ( z.start - self.start + z.starting_time + self.starting_time ) / 2 
         
        return t if self.starting_time <= t <= self.ending_time and z.starting_time <= t <= z.ending_time else False
                
        
        
def main():
    for _ in range(int(input())):
        no_cats, no_rats = map(int, input().split())
        
        Cats = [Animal() for i in range(no_cats)]
        
        for i in range(no_rats):
            rat = Animal() 
            for j in range(no_cats):
                time = rat.will_collide(Cats[j])
                if time:
                    # print(time)
                    if time < rat.eaten_by[1]:
                        rat.eaten_by = j + 1, time 
                    
                
            print(rat.eaten_by[0])
                
                
            
main()