local n = io.read("*n", "*l") local s, t = {}, {} for i = 1, n do local tp, w = io.read():match("(%d) (%w)") if tp == "0" then table.insert(s, w) else table.insert(t, w) end end print(table.concat(t):reverse() .. table.concat(s))