#include<iostream>
#include<cstring>

template<class T>
class Stack {

public:
	Stack() = default;
	Stack(const Stack& other) :size(other.size) {
		this->data = new T[other.size];
		for (size_t i = 0; i < other.size; i++) {
			this->data[i] = other.data[i];
		}
	}

	Stack& operator=(const Stack& x) {
		if (&x != this) {
			delete[] data;

			this->data = new T[x.size];
			for (size_t i = 0; i < x.size; i++) {
				this->data[i] = x.data[i];
			}
			size = x.size;
		}
		return *this;
	}

	Stack(Stack&& other) noexcept : size(other.size), data(other.data) {
		other.data = nullptr;
		other.size = 0;
	}

	Stack& operator=(Stack&& x) noexcept {
		if (&x != this) {
			delete[] data;
			size = x.size;
			data = x.data;

			x.data = nullptr;
			x.size = 0;

		}
		return *this;
	}
	void setSize(size_t size) {
		this->size = size;
	}
	void push(int element) {
		T* copy_arr = new T[size + 1];
		for (size_t i = 0; i < size; i++) {
			copy_arr[i + 1] = data[i];
		}
		copy_arr[0] = element;
		size++;
		delete[] data;
		data = copy_arr;
	}
	void pop() {
		T* copy_arr = new T[size - 1];
		for (size_t i = 0; i < size - 1; i++) {
			copy_arr[i] = data[i + 1];
		}
		size--;
		delete[] data;
		data = copy_arr;
	}
	void swap(Stack& other) {
		if (this == &other)
			return;
		size_t tmpSz = other.size;
		other.size = size;
		size = tmpSz;
		T* tmpData = other.data;
		other.data = data;
		data = tmpData;
	}
	T top() {
		return data[size-1];
	}
	bool isEmpty() {
		return size == 0;
	}
	int get(size_t index) {
		return data[index];
	}
	int getSize() {
		return size;
	}


	~Stack() {
		
	}

private:
	size_t size;
	T* data = new T[size];
};

void print(Stack<int>& stack) {
	for (size_t i = 0; i < stack.getSize(); i++) {
		std::cout.width(7);
		std::cout << stack.get(i);
	}
	std::cout << std::endl;
}

void task1() {

	Stack<int> stack;
	stack.push(1);
	stack.push(2);
	stack.push(3);

	print(stack);
	stack.pop();
	stack.pop();
	print(stack);
	std::cout.width(7);
	std::cout << stack.top();
}
bool brackets(const std::string& line) {
	Stack<char> box;
	const std::string left{ "([{" };
	const std::string rigth{ ")]}" };
	bool balance = true;
	for (auto letter : line) {
		if (rigth.find(letter) != std::string::npos) {
			if (box.isEmpty() || box.top() != letter) {
				balance = false;
				break;
			}
			else box.pop();
		}
		auto pos = left.find(letter);
		if (pos != std::string::npos) box.push(rigth.at(pos));
	}
	return balance;
}
bool brackets(const char* line) {
	return brackets(std::string(line));
}



void task2() {
	std::cout << ">>> ";
	std::string line;
	getline(std::cin, line);
	std::cout << (brackets(line) ? "YES" : "NO") << '\n';
	system("pause");
}

int main() {
	//task1();
	task2();
}