#include <iostream>
#include <vector>
#include <algorithm>

class IObserver {
public:
    virtual void update(const std::string& data) = 0;

    virtual ~IObserver() = default;
};

class ISubject {
public:
    virtual void attach(IObserver* observer) = 0;
    virtual void detach(IObserver* observer) = 0;
    virtual void notify() = 0;
    virtual ~ISubject() = default;
};

class NewsAgency : public ISubject {
private:
    std::vector<IObserver*> observers;
    std::string news;

public:
    void setNews(const std::string& data) {
        news = data;
        notify();
    }

    void attach(IObserver* observer) override {
        observers.push_back(observer);
    }

    void detach(IObserver* observer) override {
        observers.erase(std::remove(observers.begin(), observers.end(), observer), observers.end());
    }

    void notify() override {
        for (auto observer : observers) {
            observer->update(news);
        }
    }
};

class TVChannel : public IObserver {
public:
    void update(const std::string& data) override {
        std::cout << "TV Breaking News: " << data << std::endl;
    }
};

class RadioChannel : public IObserver {
public:
    void update(const std::string& data) override {
        std::cout << "Radio Update: " << data << std::endl;
    }
};

int main() {
    NewsAgency agency;
    TVChannel tv;
    RadioChannel radio;

    agency.attach(&tv);
    agency.attach(&radio);
    agency.setNews("Earthquake Alert!");
    
    agency.detach(&radio);
    agency.setNews("Update: No casualties");
    
    return 0;
}
