from typing import List

class Twitter:

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.post = []
        self.relation = {}

    def postTweet(self, userId: int, tweetId: int) -> None:
        """
        Compose a new tweet.
        """
        self.post.append([userId, tweetId])

    def getNewsFeed(self, userId: int) -> List[int]:
        """
        Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.
        """
        if userId in self.relation:
            tmp = self.relation[userId]
            tmp.add(userId)
        else:
            tmp = {userId}
        res = []
        count = 0
        for p in self.post[::-1]:
            if p[0] in tmp:
                count += 1
                res.append(p[1])
            if count >= 10:
                break
        return res

    def follow(self, followerId: int, followeeId: int) -> None:
        """
        Follower follows a followee. If the operation is invalid, it should be a no-op.
        """
        if followerId in self.relation:
            self.relation[followerId].add(followeeId)
        else:
            self.relation[followerId] = {followeeId}

    def unfollow(self, followerId: int, followeeId: int) -> None:
        """
        Follower unfollows a followee. If the operation is invalid, it should be a no-op.
        """
        if followerId in self.relation and followeeId in self.relation[followerId]:
            self.relation[followerId].remove(followeeId)

# Your Twitter object will be instantiated and called as such:
# obj = Twitter()
# obj.postTweet(userId,tweetId)
# param_2 = obj.getNewsFeed(userId)
# obj.follow(followerId,followeeId)
# obj.unfollow(followerId,followeeId)