import java.util.*;
import java.lang.*;
import java.io.*;

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;

class Ideone
{
	// single : x -> [x]
	public static String expandSingle (String input)
	{
		String out = "";
		for (String str : input.split(" "))
		{
			out += " ";
			if(str.matches("[0-9]+"))
			{
				out += "["+str+"]";
			}
			else
			{
				out += str;
			}
		}
		return out.substring(1);
	}
	
	// range : {start,end,step} -> [x,..,y]
	public static String expandRange (String input)
	{
		String out = "";
		int a,b,c;
		int i=0;
		for (String str : input.split(" "))
		{
			out += " ";
			if(str.matches("\\{[0-9]+,[0-9]+,[0-9]+\\}"))
			{
				str = str.replaceAll("[\\{\\}]","");
				a = Integer.parseInt(str.split(",")[0]);
				b = Integer.parseInt(str.split(",")[1]);
				c = Integer.parseInt(str.split(",")[2]);
				
				out += "["+a;
				while ((a+=c) <= b) out += ","+a;
				out += "]";
			}
			else
			{
				out += str;
			}
		}
		return out.substring(1);
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		String input = "3 * [3,2] / {0,2,1}";
		System.out.println(" input = "+input);
		input = expandSingle(input);
		input = expandRange(input);
		System.out.println(" expand = "+input);
		evaluate(input);
	}
	
	public static void evaluate (String input) throws java.lang.Exception
	{
		int i = 0, j = 0;
		String t = "";
		ArrayList<String[]> set = new ArrayList<String[]>();
		ArrayList<String> in = new ArrayList<String>();
		ArrayList<String> out = new ArrayList<String>();
		
		// map sets
		for (String str : input.split(" "))
		{
			if(str.matches("\\[[0-9,]+\\]"))
			{
				set.add(str.replaceAll("[\\[\\]]","").split(","));
				t+=" $"+i++;
			}
			else t+=" "+str;
		}
		in.add(t.substring(1));
		
		// generate expressions
		while (j<i)
		{
			out.clear();
			for (String exp : in)
			{
				for (String sub : set.get(j))
				{
					out.add(exp.replace("$"+j,sub));
				}
			}
			in.clear();
			in.addAll(out);
			j++;
		}
		
		ScriptEngineManager mgr = new ScriptEngineManager();
    	ScriptEngine engine = mgr.getEngineByName("JavaScript");
		
		// print expressions
		for (String exp : in)
		{
			System.out.println(" "+exp+" = "+engine.eval(exp).toString().replace("Infinity","NaN"));
		}
	}
}
