Problem:
Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;

#[derive(Clone,Copy)]
pub enum Expr {
	Num(i32),
	Plus,
	Minus,
}
impl fmt::Display for Expr {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		match self {
			&Expr::Num(n) => {
				write!(f, "{}", n)
			},
			&Expr::Plus => {
				write!(f,"+")
			},
			&Expr::Minus => {
				write!(f,"-")
			}
		}
	}
}
fn main() {
	let stdin = stdin();
	let mut scan = InputScanner::new(stdin.lock(),256);

	let s:String = scan.next();

	let chars = s.chars().collect::<Vec<char>>();

	let a = chars[0] as i32 - '0' as i32;
	let b = chars[1] as i32 - '0' as i32;
	let c = chars[2] as i32 - '0' as i32;
	let d = chars[3] as i32 - '0' as i32;

	exec(a,b,c,d,&vec![]);
}
fn exec(a:i32,b:i32,c:i32,d:i32,op:&Vec<Expr>) -> bool {
	if op.len() == 3 {
		solve(Expr::Num(a),Expr::Num(b),Expr::Num(c),Expr::Num(d),op[0],op[1],op[2])
	} else {
		{
			let mut op = op.clone();

			op.push(Expr::Plus);

			if exec(a,b,c,d,&op) {
				return true;
			}
		}

		{
			let mut op = op.clone();

			op.push(Expr::Minus);

			if exec(a,b,c,d,&op) {
				return true;
			}
		}

		false
	}
}
fn solve(a:Expr,b:Expr,c:Expr,d:Expr,op1:Expr,op2:Expr,op3:Expr) -> bool {
	let mut stack = Vec::new();

	stack.push(op3);
	stack.push(d);
	stack.push(op2);
	stack.push(c);
	stack.push(op1);
	stack.push(b);
	stack.push(a);

	while stack.len() > 1 {
		let l = match stack.pop().unwrap() {
			Expr::Num(n) => n,
			_ => panic!(),
		};
		let r = match stack.pop().unwrap() {
			Expr::Num(n) => n,
			_ => panic!(),
		};
		let op = stack.pop().unwrap();

		match op {
			Expr::Plus => {
				stack.push(Expr::Num(l+r));
			},
			Expr::Minus => {
				stack.push(Expr::Num(l-r));
			},
			_ => panic!(),
		}
	}

	match stack.pop().unwrap() {
		Expr::Num(n) if n == 7 => {
			println!("{}{}{}{}{}{}{}=7",a,op1,b,op2,c,op3,d);
			true
		},
		Expr::Num(_) => {
			false
		},
		_ => {
			panic!()
		}
	}
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}