#![allow(unused_imports, dead_code)]
use std::io::{self, Write, BufWriter};
use std::collections::VecDeque;

#[derive(Debug)]
enum Expr {
    List(Vec<i32>),
    Concat(Box<(Expr, Expr)>),
    Shuffle(Box<Expr>),
    Sorted(Box<Expr>)
}

use Expr::*;

fn parse_list(stream: &str) -> (Expr, &str) {
    let (list, rem) = stream.split_at(stream.find(']').unwrap() + 1);
    let pattern: &[_] = &['[', ']'];
    let expr = List(list.trim_matches(pattern).split(',')
                        .filter(|token| !token.is_empty())
                        .map(|token| token.parse().unwrap()).collect());
    (expr, rem)
}

fn parse_concat(stream: &str) -> (Expr, &str) {
    let (e1, rem) = parse_expr(&stream["concat".len() + 1..]);
    let (e2, rem) = parse_expr(&rem[1..]);
    (Concat(Box::new((e1, e2))), &rem[1..])
}

fn parse_shuffle(stream: &str) -> (Expr, &str) {
    let (e1, rem) = parse_expr(&stream["shuffle".len() + 1..]);
    (Shuffle(Box::new(e1)), &rem[1..])
}

fn parse_sorted(stream: &str) -> (Expr, &str) {
    let (e1, rem) = parse_expr(&stream["sorted".len() + 1..]);
    (Sorted(Box::new(e1)), &rem[1..])
}

fn parse_expr(stream: &str) -> (Expr, &str) {
    if stream.starts_with("[") { parse_list(stream) }
    else if stream.starts_with("concat") { parse_concat(stream) }
    else if stream.starts_with("shuffle") { parse_shuffle(stream) }
    else { parse_sorted(stream) }
}

fn parse(source: &str) -> Expr {
    parse_expr(source).0
}

#[derive(Debug, PartialEq)]
enum Block {
    Det(Vec<i32>),
    NonDet(Vec<i32>)
}
use Block::*;

fn elements(expr: Expr, mut acc: Vec<i32>) -> Vec<i32> {
    match expr {
        List(mut elems) => {
            acc.append(&mut elems);
            acc
        },
        Concat(exprs) => {
            let (e1, e2) = *exprs;
            elements(e2, elements(e1, acc))
        },
        Shuffle(e) | Sorted(e) => elements(*e, acc)
    }
}

fn flatten(expr: Expr, mut acc: Vec<Block>) -> Vec<Block> {
    match expr {
        List(elems) => {
            acc.push(Det(elems));
            acc
        },
        Concat(exprs) => {
            let (e1, e2) = *exprs;
            flatten(e2, flatten(e1, acc))
        },
        Shuffle(e) => {
            let mut elems = elements(*e, Vec::new());
            elems.sort();
            let first = elems.first();
            let same = (&elems).iter().all(|&x| x == **first.as_ref().unwrap());
            let block = if elems.len() < 2 || same { Det } else { NonDet } (elems);
            acc.push(block);
            acc
        },
        Sorted(e) => {
            let mut elems = elements(*e, Vec::new());
            elems.sort();
            acc.push(Det(elems));
            acc
        },
    }
}

fn simplify(expr: Expr) -> Vec<Block> {
    let blocks = flatten(expr, Vec::new());
    blocks.into_iter().fold(Vec::new(), |mut acc, block| {
        match acc.pop() {
            None => {
                acc.push(block);
                acc
            },
            Some(last) => {
                match (last, block) {
                    (Det(mut b1), Det(mut b2)) => {
                        b1.append(&mut b2);
                        acc.push(Det(b1));
                    }
                    (last, block) => {
                        acc.push(last);
                        acc.push(block);
                    }
                }
                acc
            }
        }
    })
}

fn main() {
    let mut scanner = Scanner::default();
    let writer = &mut BufWriter::new(io::stdout());
    let a: String = scanner.next();
    let b: String = scanner.next();
    let equal = simplify(parse(&a)) == simplify(parse(&b));
    writeln!(writer, "{}", if equal { "equal" } else { "not equal"}).ok();
}



#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr> (&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("failed parsing");
            }
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("failed reading");
            self.buffer = input.split_whitespace().map(String::from).rev().collect();
        }
    }
}