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



Sample input:
1222


Sample output:
1+2+2+2=7

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

A,B,C,D = map(int,list(S()))

op = [1,-1]
dic = {1:"+",-1:"-"}

for i in range(2):
  for j in range(2):
    for k in range(2):
      if A+B*op[i]+C*op[j]+D*op[k] == 7:
        PE(str(A)+dic[op[i]]+str(B)+dic[op[j]]+str(C)+dic[op[k]]+str(D)+"=7")

Submission status: Accepted

Solution code:
def dfs(i, f, result):
    if i == l - 1:
        if result == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i + 1, f + '-' + s[i + 1], result - int(s[i + 1]))
        dfs(i + 1, f + '+' + s[i + 1], result + int(s[i + 1]))


s = input()
l = len(s)

dfs(0, s[0], int(s[0]))

Submission status: Accepted

Solution code:
a = list(map(int,input()))

sep = []
for i in range(2**3):
    sep.append([])
    tmp = a[0]
    for j in range(3):
        if i>>j&1:
            sep[i].append("+")
            tmp += a[j+1]
        else:
            sep[i].append("-")
            tmp -= a[j+1]
    if tmp == 7:
        ans = i
b = []
for i in range(3):
    b.append(str(a[i]))
    b.append(str(sep[ans][i]))
b.append(str(a[3]))
b.append("=7")        
print("".join(b))

Submission status: Accepted

Solution code:
from itertools import product

A, B, C, D = input()
for op1, op2, op3 in product("+-", repeat=3):
    expr = "{}{}{}{}{}{}{}".format(A, op1, B, op2, C, op3, D)
    if eval(expr) == 7:
        print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s_4digits = input().rstrip()



    for bit in range(1 << len(s_4digits)-1):
        # 一文字目は必ずプラス
        ans = int(s_4digits[0])
        op_list = []
        plus_list = []
        for i in range(len(s_4digits)-1):

            if bit & (1<<i):
                plus_list.append(i)

        # 式の組み立て
        for j in range(len(s_4digits)-1):
            op_list.append("-")

        for num in plus_list:
            op_list[num] = "+"
        for i, op in enumerate(op_list):
            if op == "+":
                ans += int(s_4digits[i+1])
            else:
                ans -= int(s_4digits[i+1])

        if ans == 7:
            ans_str = s_4digits[0]
            for i, op in enumerate(op_list):
                ans_str += op + s_4digits[i+1]
            print(ans_str + "=7")
            exit()




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
k = input()
for bit in range(1 << 3):
    tmp = int(k[0])
    s = k[0]
    for i in range(3):
        if bit & (1 << i):
            tmp += int(k[i+1])
            s += '+' + k[i+1]
        else:
            tmp -= int(k[i+1])
            s += '-'+k[i+1]
    if tmp == 7:
        print(s + '=7')
        exit(0)

Submission status: Accepted

Solution code:

import itertools

nn = input()
for ss in itertools.product(["+", "-"], repeat=3):
    tmp = "".join([s1 + s2 for (s1, s2) in zip(nn, ss)]) + nn[-1]
    if eval(tmp) == 7:
        print(tmp + "=7")
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

s = input()

for i in range(1<<3):
    sum = int(s[0])
    ans = s[0]
    for k in range(3):
        # print(k)
        if i>>k&1:
            sum += int(s[k+1])
            ans += '+' + s[k+1]
        else:
            sum -= int(s[k+1])
            ans += '-' + s[k+1]
    if sum == 7:
        print(ans + '=7')
        break

Submission status: Accepted

Solution code:
abcd = list(input())
op = ['+', '-']

for op1 in op:
    for op2 in op:
        for op3 in op:
            formula = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(formula) == 7:
                print(formula + '=7')
                exit()

Submission status: Accepted

Solution code:
A = input()

op = ['+', '-']

for i in range(len(op)):
    for j in range(len(op)):
        for k in range(len(op)):
            if eval(A[0]+op[i]+A[1]+op[j]+A[2]+op[k]+A[3]) == 7:
                print(A[0]+op[i]+A[1]+op[j]+A[2]+op[k]+A[3]+'=7')
                exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    abcd = list(map(int, list(readstr())))
    l = [['+', '+', '+'], ['+', '+', '-'], ['+', '-', '+'], ['+', '-', '-'], ['-', '+', '+'], ['-', '+', '-'], ['-', '-', '+'], ['-', '-', '-']]
    for ll in l:
        ans = abcd[0]
        for i, x in enumerate(ll):
            if x == '+':
                ans += abcd[i + 1]
            else:
                ans -= abcd[i + 1]
        if ans == 7:
            s = ''
            for i in range(3):
                s += str(abcd[i]) + ll[i]
            s += str(abcd[3])
            print(s + '=7')
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
def saiki(i,s):
    if i == 3:
        if eval(s) == 7:
            print(str(s) + "=7")
            exit()
        else:
            return
    saiki(i+1,s+"+"+S[i+1])
    saiki(i+1,s+"-"+S[i+1])

saiki(0,S[0])

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, d = map(int, input())
#print(a, b, c, d)
if a+b+c+d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    exit()
if a+b-c+d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    exit()
if a+b+c-d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    exit()
if a+b-c-d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    exit()
if a-b+c+d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    exit()
if a-b-c+d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    exit()
if a-b+c-d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    exit()
if a-b-c-d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    exit()

Submission status: Accepted

Solution code:
A, B, C, D = input()
A1 = int(A)
B1 = int(B)
C1 = int(C)
D1 = int(D)
if A1+B1+C1+D1 == 7:
  print(A+'+'+B+'+'+C+'+'+D+'=7')
elif A1+B1+C1-D1 == 7:
  print(A+'+'+B+'+'+C+'-'+D+'=7')
elif A1+B1-C1+D1 == 7:
  print(A+'+'+B+'-'+C+'+'+D+'=7')
elif A1+B1-C1-D1 == 7:
  print(A+'+'+B+'-'+C+'-'+D+'=7')
elif A1-B1+C1+D1 == 7:
  print(A+'-'+B+'+'+C+'+'+D+'=7')
elif A1-B1+C1-D1 == 7:
  print(A+'-'+B+'+'+C+'-'+D+'=7')
elif A1-B1-C1+D1 == 7:
  print(A+'-'+B+'-'+C+'+'+D+'=7')
elif A1-B1-C1-D1 == 7:
  print(A+'-'+B+'-'+C+'-'+D+'=7')

Submission status: Accepted

Solution code:
def dfs(i, s, sum):
    if i == 3:
        if sum == 7:
            print(s + "=7")
            exit()
    else:
        dfs(i + 1, s + "+" + abcd[i + 1], sum + int(abcd[i + 1]))
        dfs(i + 1, s + "-" + abcd[i + 1], sum - int(abcd[i + 1]))
abcd = input()
dfs(0, abcd[0], int(abcd[0]))

Submission status: Accepted

Solution code:
import itertools
n = input()
a, b, c, d = n

for i, j, k in itertools.product(["+", "-"], repeat=3):
    if eval(a + i + b + j + c + k + d) == 7:
        print(a+i+b+j+c+k+d + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
s = input()
a = ""
for i in range(1 << 3):
    bit = bin(i)[2:].zfill(3)
    total = int(s[0])
    for j in range(3):
        if bit[j] == "1":
            total += int(s[j + 1])
        else:
            total -= int(s[j + 1])
    if total == 7:
        a = bit
        break
# print(a)
ans = ""
for i in range(4):
    if i == 0:
        ans += s[i]
    else:
        if bit[i - 1] == "1":
            ans += "+" + s[i]
        else:
            ans += "-" + s[i]
ans += "=7"
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=input()
l=[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
for i in range(len(l)):
    s=int(n[0])
    if l[i][0]==0:
        s+=int(n[1])
        t1="+"
    else:
        s-=int(n[1])
        t1="-"
    if l[i][1]==0:
        s+=int(n[2])
        t2="+"
    else:
        s-=int(n[2])
        t2="-"
    if l[i][2]==0:
        s+=int(n[3])
        t3="+"
    else:
        s-=int(n[3])
        t3="-"

    if s==7:
        print(n[0]+t1+n[1]+t2+n[2]+t3+n[3]+"=7")
        exit()
print("No")

Submission status: Accepted

Solution code:
S = input().strip()
a = S[0]
b = S[1]
c = S[2]
d = S[3]

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            cal = a + op1 + b + op2 + c + op3 + d
            left = int(eval(cal))
            if left == 7:
                print(cal + "=7")
                exit()

Submission status: Accepted

Solution code:
from itertools import product
A,B,C,D =list(input())
for z in product(("+","-"),repeat=3):
    if eval(A+z[0]+B+z[1]+C+z[2]+D)==7:
        print(A+z[0]+B+z[1]+C+z[2]+D+"=7")
        break

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

ABCD = list(input())

for i in range(2 ** 3):
    tmp = int(ABCD[0])
    for j in range(3):
        if (i >> j) & 1:
            tmp += int(ABCD[j + 1])
        else:
            tmp -= int(ABCD[j + 1])
    if tmp == 7:
        print (ABCD[0], end = '')
        print ('+' if (i >> 0) & 1 else '-', end = '')
        print (ABCD[1], end = '')
        print ('+' if (i >> 1) & 1 else '-', end = '')
        print (ABCD[2], end = '')
        print ('+' if (i >> 2) & 1 else '-', end = '')
        print (ABCD[3], end = '=7\n')
        exit()

Submission status: Accepted

Solution code:
a = list(map(int, list(input())))
f = lambda x: '+' if x==1 else '-'
for i in range(-1, 2, 2):
    for j in range(-1, 2, 2):
        for k in range(-1, 2, 2):
            if a[0]+i*a[1]+j*a[2]+k*a[3]==7:
                print(str(a[0])+f(i)+str(a[1])+f(j)+str(a[2])+f(k)+str(a[3])+'=7')
                exit()

Submission status: Accepted

Solution code:
import sys
s = str(input())

A = []
for i in range(len(s)):
  A.append(s[i])
  
for i in range(2**3):
  p = []
  for j in range(3):
    if (i>>j)&1 == 1:
      p.append("+")
    else:
      p.append("-")
  temp = s[0]
  for t in range(3):
    temp += p[t]
    temp += s[t+1]
  #print(temp)
  if eval(temp) == 7:
    ans = temp+"=7"
    print(ans)
    sys.exit()

Submission status: Accepted

Solution code:
def resolve():
  s = input()
  for i in range(1<<3):
    e = s[0]
    e += '+' if ((i>>0) & 1) else '-'
    e += s[1]
    e += '+' if ((i>>1) & 1) else '-'
    e += s[2]
    e += '+' if ((i>>2) & 1) else '-'
    e += s[3]
    if eval(e) == 7:
      e += '=7'
      print(e)
      return
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    ABCD = list(input())

    for pattern in product(["+", "-"], repeat=3):
        pattern = list(pattern) + [" "]
        fomula = []
        for op, num in zip(pattern, ABCD):
            fomula.append(num)
            fomula.append(op)
        fomula = "".join(fomula).rstrip()
        if eval(fomula) == 7:
            print(fomula + "=" + "7")
            break
        else:
            continue
        break


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a = list(input())
a = [int(i) for i in a]
for fl in itertools.product(range(2),repeat=3):
    now = a[0]
    for i,x in enumerate(fl):
        if x:
            now += a[i+1]
        else:
            now -= a[i+1]
    if now == 7:
        L = str(a[0])
        for i,x in enumerate(fl):
            tmp = '+' if x else '-'
            L += tmp + str(a[i+1])
        print(L+'=7')
        quit()

Submission status: Accepted

Solution code:
import itertools
a = list(input())

for v in itertools.product(["+", "-"], repeat=3):
  x = a[0] + v[0] + a[1] + v[1] + a[2] + v[2] + a[3]
  if eval(x) == 7: break
print(x+"=7")

Submission status: Accepted

Solution code:
from itertools import product

s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
L = [a, b, c, d]
kumiawase = list(product([1, 0], repeat=3))

for kumi in kumiawase:
    res = a
    for i in range(3):
        if kumi[i] == 0:
            res += L[i + 1]
        else:
            res -= L[i + 1]
    if res == 7:
        break
ans = s[0]
for i in range(3):
    if kumi[i] == 0:
        ans += "+"
    else:
        ans += "-"
    ans += s[i + 1]
ans += "=7"
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement, permutations


def main():
    abcd = list(input())
    can_break = False
    for pp in combinations_with_replacement(["+", "-"], 3):
        if can_break:
            break
        for p in permutations(pp):
            now = [abcd[0]]
            for i in range(3):
                now.append(p[i])
                now.append(abcd[i + 1])
            now_f = "".join(now)
            if eval(now_f) == 7:
                print(now_f + "=7")
                can_break = True
                break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
for i in range(2**3):
    l = []
    for j in range(3):
        if (i>>j)&1:
            l.append("+")
        else:
            l.append("-")
    if eval("{}{}{}{}{}{}{}".format(s[0],l[0],s[1],l[1],s[2],l[2],s[3])) == 7:
        print("{}{}{}{}{}{}{}=7".format(s[0],l[0],s[1],l[1],s[2],l[2],s[3]))
        break

Submission status: Accepted

Solution code:
A = list(input())

A,B,C,D = A[0],A[1],A[2],A[3]

for op1 in ['+','-']:
    for op2 in ['+','-']:
        for op3 in ['+','-']:
            if eval(A+op1+B+op2+C+op3+D) == 7:
                print(A+op1+B+op2+C+op3+D+'=7')
                exit()

Submission status: Accepted

Solution code:
s=input()
A=int((list(s))[0])
B=int((list(s))[1])
C=int((list(s))[2])
D=int((list(s))[3])

for i in range(2**3):
    a=[]
    b=A
    for k in range(3):
        if (i>>k)&1==1:
            a.append("+")
            b+=int(list(s)[k+1])
        else:
            a.append("-")
            b-=int(list(s)[k+1])
    if b==7:
        print(A,a[0],B,a[1],C,a[2],D,"=7",sep="")
        break

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,list(_in[0])))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    arr = [B,C,D]
    N = len(arr)
    for bit in range(1<<N):
        # bit = 0: '-', 1: '+'
        sum_ = A
        for i,x in enumerate(arr):
            if bit&(1<<i):
                sum_ += x
            else:
                sum_ -= x
        if sum_ == 7:
            str_ = str(A)
            for i,x in enumerate(arr):
                if bit&(1<<i):
                    str_ += '+'+str(x)
                else:
                    str_ += '-'+str(x)
            str_ += '=7'
            break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(str_)

Submission status: Accepted

Solution code:
S = input()

def saiki(i,s = S[0]):
    if i == 3:
        if eval(s) == 7:
            print(str(s) + "=7")
            exit()
        else:
            return            
    saiki(i + 1, s + "+" + S[i+1])
    saiki(i + 1, s + "-" + S[i+1])

saiki(0)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    S = input()
    l = len(S)-1
    for i in range(2**l):
        fs = S[0]
        for j in range(l):
            if (i>>j & 1) == 1:
                fs += '+'
            else:
                fs += '-'
            fs += S[j+1]
        if eval(fs)==7:
            ret = fs + '=7'
            break
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ABCD=str(input())
A=int(ABCD[0])
B=int(ABCD[1])
C=int(ABCD[2])
D=int(ABCD[3])
listA=[A,B,C,D]
for i in range(2**3):
    listn=[0]*3
    for j in range(3):
        if ((i>>j)&1):
            listn[j]=1
    num=A
    for k in range(3):
        if listn[k]==0:
            num+=listA[k+1]
            listn[k]="+"
        elif listn[k]==1:
            num-=listA[k+1]
            listn[k]="-"
    if num==7:
        print(str(A)+listn[0]+str(B)+listn[1]+str(C)+listn[2]+str(D)+"=7")
        break

Submission status: Accepted

Solution code:
S = input()
a = len(str(S))-1
 
for i in range(2**a):  
    temp = str(S)[0]  
    for j in range(a):
        if i & (1<<j):
            temp += "+"
        else:
            temp += "-"
        temp+=str(S)[j+1]
    
    if eval(temp) == 7:
        print("{}=7".format(temp))
        break

Submission status: Accepted

Solution code:
import sys
abcdf=list(input()) #　a1
abcd=[int(i) for i in abcdf]


for i in range(2 ** 3):
  nsum=abcd[0]
  op=[]
  for j in range(3):  # このループが一番のポイント
    if ((i >> j) & 1):
      nsum+=abcd[j+1]
      op.append('+')
    else:
      nsum-=abcd[j+1]
      op.append('-')
  if nsum==7:
    print(abcdf[0]+op[0]+abcdf[1]+op[1]+abcdf[2]+op[2]+abcdf[3]+'=7')
    sys.exit(0)

Submission status: Accepted

Solution code:
S=input()
for bit in range(1<<3):
    f=int(S[0])
    s=S[0]
    for i in range(3):
        if bit&(1<<i):
            f+=int(S[i+1])
            s+="+"+S[i+1]
        else :
            f-=int(S[i+1])
            s+="-"+S[i+1]
    if f==7:
        print(s+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()

for i in range(8):
    siki = s[0]
    for j in range(3):
        bitchk = 2 ** j
        if i & bitchk:
            siki += '+'
        else:
            siki += '-'
        siki += s[j+1]
    ans = eval(siki)
    if ans == 7:
        print(siki, '=7', sep='')
        exit()

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
if a+b+c+d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d ==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d ==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d ==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d ==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d ==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d ==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d ==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Submission status: Accepted

Solution code:
ans=0
a=input()
def dfs(i,s=''):
  global ans
  if i==len(a)-1:
    if eval(s+a[-1])==7:
      ans=s+a[-1] + '=7'
      return 

    else:
      return
  dfs(i+1,s+a[i]+'-')
  dfs(i+1,s+a[i]+'+')

dfs(0)
print(ans)

Submission status: Accepted

Solution code:
listi = list(input())
a=listi[0]
b=listi[1]
c=listi[2]
d=listi[3]

 

res = ""


def hugou(i):
    if i=="0":
        return "+"
    else:
        return "-"
    

for x in range(2 ** 3):

    z = str(format(x, '03b')) #2進数に変換
    ans = 0
    ans += int(a)
    if z[0]=="0":
        ans += int(b)
    else:
        ans += int(b) * -1
    if z[1]=="0":
        ans += int(c)
    else:
        ans += int(c) * -1   
    if z[2]=="0":
        ans += int(d)
    else:
        ans += int(d) * -1        
        
    
    
    if ans == 7:
        res += a
        res += hugou(z[0])
        res += b
        res += hugou(z[1]) 
        res += c
        res += hugou(z[2])
        res += d 
        
        res += "=7"
        print(res)
        break

Submission status: Accepted

Solution code:
def op(x):
    return '+' if x==0 else '-'
# -*- coding: utf-8 -*-
N = int(input())
a=N//1000
b=N%1000//100
c=N%100//10
d=N%10
for i in range(2**3):
    total=0
    for j,num in zip(range(3),[b,c,d]):
        if (i>>j)&1==0:
            total+=num
        else:
            total-=num
    if a+total==7:
        print('{}{}{}{}{}{}{}=7'.format(a,op(i>>0&1),b,op(i>>1&1),c,op(i>>2&1),d))
        break

Submission status: Accepted

Solution code:
list_s = list(str(input()))
for i in range(4):
    list_s[i] = int(list_s[i])

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            if i == 0:
                ans += list_s[0] + list_s[1]
            else:
                ans += list_s[0] - list_s[1]
            if j == 0:
                ans += list_s[2]
            else:
                ans -= list_s[2]
            if k == 0:
                ans += list_s[3]
            else:
                ans -= list_s[3]
            if ans == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
list_sgn = ["+","-"]
print(str(list_s[0]) + list_sgn[i] + str(list_s[1]) + list_sgn[j] + str(list_s[2]) + list_sgn[k] + str(list_s[3]) + "=7")

Submission status: Accepted

Solution code:
n = input()
for i in range(2 ** 3):
    op = ['+'] * 3
    for j in range(3):
        if i >> j & 1:
            op[j] = '-'
    f = [0] * 7
    f[::2] = n
    f[1::2] = op
    f = ''.join(f)
    if eval(f) == 7:
        print(''.join([f, '=7']))
        exit()

Submission status: Accepted

Solution code:
l=list(map(int,list(input())))

for i in range(2**3):
    count=l[0]
    s=str(l[0])
    for j in range(3):
        if i&(2**j):
            count+=l[j+1]
            s=s+'+'+str(l[j+1])
        else:
            count-=l[j+1]
            s=s+'-'+str(l[j+1])
    if count==7:
        print(s+'=7')
        exit()

Submission status: Accepted

Solution code:
nums = list(input())
calc_cnt = len(nums) - 1

def vaule_check():
    for i in range(2**calc_cnt):
        formation = str(nums[0])
        for j in range(calc_cnt):
            if ((i >> j) & 1):
                formation+='+' + nums[j+1]
            else:
                formation+='-' + nums[j+1]
        
        if eval(formation) == 7:
            return formation + '=7'

print(vaule_check())

Submission status: Accepted

Solution code:
from itertools import product

A, B, C, D = map(int, input())

for operators in product(('+', '-'), repeat=3):
    a = A
    b = B
    c = C
    d = D
    if operators[0] == '-':
        b *= -1
    if operators[1] == '-':
        c *= -1
    if operators[2] == '-':
        d *= -1

    if a + b + c + d == 7:
        print('{}{}{}{}{}{}{}=7'.format(A, operators[0], B, operators[1], C, operators[2], D))
        break