#include <iostream>
#include <stdexcept>
#include <vector>
class DeviceModel {
    enum class State {empty,uploaded,complete};State state=State::empty;
    std::vector<int> memory;
public:
    void upload(const std::vector<int>& input) {memory=input;state=State::uploaded;}
    void run() {
        if(state!=State::uploaded) throw std::logic_error("input not ready");
        for(auto& x:memory) x*=2;state=State::complete;
    }
    std::vector<int> download() const {
        if(state!=State::complete) throw std::logic_error("output not ready");return memory;
    }
};
int main() {
    DeviceModel device;bool rejected=false;
    try {
        const auto unexpected=device.download();
        std::cout<<"unexpected early result size="<<unexpected.size()<<'\n';
        return 1;
    } catch(const std::logic_error&){rejected=true;}
    const std::vector<int> input{1,2,3};device.upload(input);device.run();const auto output=device.download();
    if(!rejected || output!=std::vector<int>{2,4,6} || input!=std::vector<int>{1,2,3}) throw std::runtime_error("model");
    device.upload({});device.run();if(!device.download().empty()) throw std::runtime_error("empty");
    std::cout<<"result=2,4,6 early_read_rejected=1\n";
}
