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:
import sys
num = list(map(int, list(input())))
p, m = "+", "-"
for op1 in [p, m]:
    for op2 in [p, m]:
        for op3 in [p, m]:
            x = num[0]
            if op1 == p:
                x += num[1]
            else:
                x -= num[1]
            if op2 == p:
                x += num[2]
            else:
                x -= num[2]
            if op3 == p:
                x += num[3]
            else:
                x -= num[3]

            if x == 7:
                print(
                    "{}{}{}{}{}{}{}=7".format(
                        num[0], op1, num[1], op2, num[2], op3, num[3]
                    )
                )
                sys.exit()
            else:
                pass

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
l = [a+b+c+d, a+b+c-d, a+b-c+d, a+b-c-d, a-b+c+d, a-b+c-d, a-b-c+d, a-b-c-d]

if l.index(7) == 0:
    print(a, '+', b, '+', c, '+', d, '=7', sep='')
elif l.index(7) == 1:
    print(a, '+', b, '+', c, '-', d, '=7', sep='')
elif l.index(7) == 2:
    print(a, '+', b, '-', c, '+', d, '=7', sep='')
elif l.index(7) == 3:
    print(a, '+', b, '-', c, '-', d, '=7', sep='')
elif l.index(7) == 4:
    print(a, '-', b, '+', c, '+', d, '=7', sep='')
elif l.index(7) == 5:
    print(a, '-', b, '+', c, '-', d, '=7', sep='')
elif l.index(7) == 6:
    print(a, '-', b, '-', c, '+', d, '=7', sep='')
elif l.index(7) == 7:
    print(a, '-', b, '-', c, '-', d, '=7', sep='')

Submission status: Accepted

Solution code:
s=input()

for bit in range(1<<3):
    sum=int(s[0])
    op=list("+++")
    for i in range(3):
        if bit & (1<<i):
            sum+=int(s[i+1])
        else:
            sum-=int(s[i+1])
            op[i]='-'
    if sum==7:
        print(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+"=7")
        break

Submission status: Accepted

Solution code:
number=input()
list(number)
number=list(map(int,number))
a=[]
def f(i,s):
    if i==len(number):
        return s==7
    if f(i+1,s+number[i]):
        a.append("+")
        return True  
    if f(i+1,s-number[i]):
        a.append("-")
        return True

if f(1,number[0]):
    print(str(number[0])+a[2]+str(number[1])+a[1]+str(number[2])+a[0]+str(number[3])+"=7")
else:
    print("no")

Submission status: Accepted

Solution code:
N = [int(i) for i in list(input())]
for i in range(8):
    ans = [str(N[0])]
    s = N[0]
    for b, n in enumerate(N[1:]):
        if i & (1 << b):
            s += n
            ans.append("+")
        else:
            s -= n
            ans.append("-")
        ans.append(str(n))
    if s == 7:
        ans.append("=7")
        print(''.join(ans))
        exit()

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(input()))

if A-B-C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '-', C, '-', D, '=7'))
elif A-B-C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '-', C, '+', D, '=7'))
elif A-B+C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '+', C, '-', D, '=7'))
elif A-B+C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '+', C, '+', D, '=7'))
elif A+B-C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '-', C, '-', D, '=7'))
elif A+B-C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '-', C, '+', D, '=7'))
elif A+B+C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '+', C, '-', D, '=7'))
elif A+B+C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '+', C, '+', D, '=7'))

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1

for bit in range(1 << n):
  buf = s[0]
  result = 0
  for i in range(n):
    if bit & (1 << i):
      buf += "+{}".format(s[i+1])
    else:
      buf += "-{}".format(s[i+1])
  if eval(buf) == 7:
    print("{}=7".format(buf))
    break

Submission status: Accepted

Solution code:
li = [int(i) for i in input()]

for i in range(2**3):
    ans = str(li[0])
    tmp = li[0]
    for j in range(3):
        if (i>>j)&1:
            tmp += li[j+1]
            ans += '+'+str(li[j+1])
        else:
            tmp -= li[j+1]
            ans += '-'+str(li[j+1])
    if tmp == 7:
        ans += '=7'
        print(ans)
        exit()

Submission status: Accepted

Solution code:
tex = input()
num = [int(i) for i in tex]

n = 3
pos = []

for i in range(2 ** n):
    tes = num[0]
    shiki = ""
    sep = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            sep[j] = 1
    for ind, su in enumerate(num):
        shiki += str(num[ind])
        if ind < len(sep):
            if sep[ind] == 1:
                tes += num[ind + 1]
                shiki += "+"
            if sep[ind] == 0:
                tes -= num[ind + 1]
                shiki += "-"
    shiki += "=7"
    if tes == 7:
        print(shiki)
        break

Submission status: Accepted

Solution code:
from itertools import product

l = list(input())
f = lambda x: '+' if x == 1 else '-'

for o in product(range(2), repeat=3):
    ret = l[0] + f(o[0]) + l[1] + f(o[1]) + l[2] + f(o[2]) + l[3]
    if eval(ret) == 7:
        print(ret + '=7')
        break

Submission status: Accepted

Solution code:
n = input()
a = [int(n[i]) for i in range(4)]

li = [(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 li:
    sum1 = a[0]
    for j in range(3):
        if i[j] == 0:
            sum1 += a[j+1]
        else:
            sum1 -= a[j+1]
    if sum1 == 7:
        ans = ''
        for j in range(3):
            ans += str(a[j])
            if i[j] == 0:
                ans += '+'
            else:
                ans += '-'
        ans += str(a[3]) + '=7'
        print(ans)
        exit()

Submission status: Accepted

Solution code:
def main():
  import itertools
  s=list(input())
  n=len(s)

  for pm in itertools.product("+-", repeat=3):
    tmp=""
    for i,j in zip(s,pm):
      tmp+=i+j
    else:
      tmp+=s[-1]
    if eval(tmp)==7:
      print(tmp+"=7")
      exit()
  
  
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
def main():
  import itertools
  s=list(input())
  n=len(s)
  t=[ s[i//2] if i%2==0 else None for i in range(2*n-1)]

  for i in itertools.product("+-", repeat=3):
    k=t
    for j in [0,1,2]:
      k[2*j+1]=i[j]
    l="".join(k)
    if eval(l)==7:
      print(l+"=7")
      exit()
  
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
abcd = input()
for i in range(1 << 3):
    total = int(abcd[0])
    ans = abcd[0]
    b = format(i, "b").zfill(3)
    # print(b)
    for j in range(len(b)):
        if b[j] == "1":
            total += int(abcd[j + 1])
            ans += "+" + abcd[j + 1]
        else:
            total -= int(abcd[j + 1])
            ans += "-" + abcd[j + 1]
    # print(total)
    # print(ans)
    if total == 7:
        ans += "=7"
        print(ans)
        break

Submission status: Accepted

Solution code:
s = input()
OPE_CNT = 3
ANS = 7

def solve(sum, cnt, ope_s):
    if cnt == OPE_CNT:
        if sum == ANS:
            print(ope_s + '=7')
            return True
        else:
            return False
    if solve(sum + int(s[cnt + 1]), cnt + 1, ope_s + '+' + s[cnt + 1]):
        return True
    if solve(sum - int(s[cnt + 1]), cnt + 1, ope_s + '-' + s[cnt + 1]):
        return True
    return False

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

Submission status: Accepted

Solution code:
lst=[int(c) for c in input()]

for i in range(8):
    s=str(lst[0])
    cnt=lst[0]
    idx=1
    while idx<4:
        res=i%2
        if res==0:
            s+='+'+str(lst[idx])
            cnt+=lst[idx]
        else:
            s+='-'+str(lst[idx])
            cnt-=lst[idx]
        i//=2
        idx+=1
    if cnt==7:
        s+='=7'
        print(s)
        break

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)


class Dijkstra:
 
    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point
 
    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]
 
        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)
 
            if dist[src] < prev_cost:
                continue
 
            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]
 
        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count
 
    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal
 
        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]
 
        return list(reversed(path))

        
def main(): #startline--------------------------------------------
    s = input()
    abcd = [i for i in s]
    op = ["-","-","-"]
    for i in range(1<<3):
        for j in range(3):
            if (i>>j)&1:
                op[j] = "+"
        if eval(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]) == 7:
            print(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]+"=7")
            exit()
        op = ["-","-","-"]
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
s = list(map(int,input()))
n = len(s)
for i in range(2**(n-1)):
    bag = []
    for j in range(n-1):
        if ((i>>j)&1):
            bag.append(s[j])
            bag.append('+')
        else:
            bag.append(s[j])
            bag.append('-')
    bag.append(s[n-1])
    bag = list(map(str,bag))
    #ss = ''.join(bag)
    #print(bag)
    total = int(bag[0])
    for m,sss in enumerate(bag):
        if(sss == '+'):
            total += int(bag[m+1])
        elif(sss == '-'):
            total -= int(bag[m+1])
    if(total==7):
        print(''.join(bag)+'=7')
        exit()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2 ** 3):
    op = format(i, '03b')
    op = op.replace('1', '+').replace('0', '-')
    formula = ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
a = list(input())
i = int(a[0])
j = int(a[1])
k = int(a[2])
l = int(a[3])
if i+j+k+l == 7:
    print("%s+%s+%s+%s=7" % (i,j,k,l))
elif i+j+k-l == 7:
    print("%s+%s+%s-%s=7" % (i,j,k,l))
elif i+j-k+l == 7:
    print("%s+%s-%s+%s=7" % (i,j,k,l))
elif i+j-k-l == 7:
    print("%s+%s-%s-%s=7" % (i,j,k,l))
elif i-j+k+l == 7:
    print("%s-%s+%s+%s=7" % (i,j,k,l))
elif i-j+k-l == 7:
    print("%s-%s+%s-%s=7" % (i,j,k,l))
elif i-j-k+l == 7:
    print("%s-%s-%s+%s=7" % (i,j,k,l))
elif i-j-k-l == 7:
    print("%s-%s-%s-%s=7" % (i,j,k,l))

Submission status: Accepted

Solution code:
import sys
num = input()

for bit in range(2**(len(num)-1)):
    lis = [num[0]]
    for i in range(len(num)-1):
        
        if ((bit>>i) & 1):
            lis.append("+")
        else:
            lis.append("-")
        
        lis.append(num[i+1])
    
    ans = "".join(lis)
    if eval(ans) == 7:
        print(ans+"=7")
        sys.exit()

Submission status: Accepted

Solution code:

a, b, c, d = map(int, input())

def i_to_sign(n):
    if n > 0:
        return "+"
    else:
        return "-"

for bits in range(2**3):
    plus = [1] * 3
    for i in range(3):
        if (1 << i & bits) == 0:
            plus[i] = -1
    
    result = a + (b * plus[0]) + (c * plus[1]) + (d * plus[2])

    if result == 7:
        print("{}{}{}{}{}{}{}=7".format(
            a, i_to_sign(plus[0]),
            b, i_to_sign(plus[1]),
            c, i_to_sign(plus[2]),
            d
        ))
        exit()

Submission status: Accepted

Solution code:
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])


def get_op(num):
  if num == -1:
    _ = '-'
  else:
    _ = '+'

  return _
  

for x in [-1,1]:
  for y in [-1,1]:
    for z in [-1,1]:
      _ = A+x*B+y*C+z*D
      if _ == 7:
        op1 = get_op(x)
        op2 = get_op(y)
        op3 = get_op(z)        
        ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)

Submission status: Accepted

Solution code:
def func(i, x, a):
    global ans
    ans = a[0]
    if i == 1:
        if x == 7:
            return True
        else:
            return False

    if func(i-1, x+int(a[i-1]), a):
        ans += '+' + a[i-1]
        return True

    if func(i-1, x-int(a[i-1]), a):
        ans += '-' + a[i-1]
        return True

    else:
        return False

if __name__ == '__main__':
    a = input()
    n = len(a)
    x = int(a[0])
    if func(n, x, a):
        print(ans + '=7')
    else:
        pass

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    s = input()
    abcd = [i for i in s]
    op = ["-","-","-"]
    for i in range(1<<3):
        for j in range(3):
            if (i>>j)&1:
                op[j] = "+"
        if eval(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]) == 7:
            print(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]+"=7")
            exit()
        op = ["-","-","-"]
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
a, b, c, d = (int(s_i) for s_i in input())
if a + b + c + d == 7:
    print("{}+{}+{}+{}=7".format(a, b, c, d))
elif a - b + c + d == 7:
    print("{}-{}+{}+{}=7".format(a, b, c, d))
elif a + b - c + d == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
elif a + b + c - d == 7:
    print("{}+{}+{}-{}=7".format(a, b, c, d))
elif a - b - c + d == 7:
    print("{}-{}-{}+{}=7".format(a, b, c, d))
elif a - b + c - d == 7:
    print("{}-{}+{}-{}=7".format(a, b, c, d))
elif a + b - c - d == 7:
    print("{}+{}-{}-{}=7".format(a, b, c, d))
else: print("{}-{}-{}-{}=7".format(a, b, c, d))

Submission status: Accepted

Solution code:
a=input()

for bit in range(1<<3):
  f=int(a[0])
  s=a[0]
  for i in range(3):
    if bit&(1<<i):
      f+=int(a[i+1])
      s+='+'+a[i+1]
    else:
      f-=int(a[i+1])
      s+='-'+a[i+1]
  if f==7:
    print(s+'=7')
    exit()

Submission status: Accepted

Solution code:
a=input()
for i in range(8):
  b=bin(i)[2:]
  b="q"+"0"*(3-len(b))+b
  b=b.replace("0","-").replace("1","+")
  xv="".join([d+s for s,d in zip(a,b)])
  xv=xv[1:]
  if eval(xv)==7:
    print(xv,"=7",sep="");break

Submission status: Accepted

Solution code:
s=input()
for i in range(2**3):
  op=format(i,'03b')
  op=op.replace('1','+').replace('0','-')
  st=s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]
  if eval(st)==7:
    print(st+"=7")
    break

Submission status: Accepted

Solution code:
def test():
    nums = list(map(int, list(input())))
    end = False
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            end = True
            break
    print('{}=7'.format(res))

if __name__ == '__main__':
    test()

Submission status: Accepted

Solution code:
import sys
a = input()

for bit in range(2**3):
    p_m = ["-","-","-"]
    b = []
    for i in range(len(p_m)):
        if ((bit>>i) & 1):
            p_m[i] = "+"
        b.append(a[i] + p_m[i])
    b.append(a[3])
    c = "".join(b)
    if eval(c) == 7:
        print(c+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
from itertools import product

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

s = ns()

for plus in product([0,1], repeat=3):
    ans = s[0]
    a = int(s[0])
    for i, flag in enumerate(plus):
        if flag == 0:
            a = a + int(s[i+1])
            ans = ans + "+" + s[i+1]
        else:
            a = a - int(s[i+1])
            ans = ans + "-" + s[i+1]
    #print(ans, a)
    if a == 7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
abcd=list(input())
for i in range(2**3):
    if i//4==0:
        op1="+"
    else:
        op1="-"
    i=i%4
    if i//2==0:
        op2="+"
    else:
        op2="-"
    i=i%2
    if i==0:
        op3="+"
    else:
        op3="-"
    siki=abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]
    if eval(siki)==7:
        siki+="=7"
        break
print(siki)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*4
for i in range(3,-1,-1):
    a[i]=n%10
    n=n//10
if a[0]+a[1]+a[2]+a[3]==7:
    print("{0}+{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]+a[2]-a[3]==7:
    print("{0}+{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]+a[3]==7:
    print("{0}+{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]+a[3]==7:
    print("{0}-{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]-a[3]==7:
    print("{0}+{1}-{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]-a[2]+a[3]==7:
    print("{0}-{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]-a[3]==7:
    print("{0}-{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
else:
    print("{0}+{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))

Submission status: Accepted

Solution code:
a = str(input())

ans = []
for i in range(2**3):
    result = int(a[0])
    for j in range(3):
        if (i >> j) & 1:
            result += int(a[j+1])
            ans.append('+')
        else:
            result -= int(a[j+1])
            ans.append('-')
    if result == 7:
        break
    else:
        ans = []

if len(ans) == 0:
    print(-1)
else:
    print(a[0]+ans[0]+a[1]+ans[1]+a[2]+ans[2]+a[3]+'=7')

Submission status: Accepted

Solution code:
inp = list(input())
a = inp[0]
b = inp[1]
c = inp[2]
d = inp[3]
for i in range(8):
    temp = format(i, '03b')
    templist = list(temp)
    if templist[0] == "0":
        op1 = "+"
    else:
        op1 = "-"
    if templist[1] == "0":
        op2 = "+"
    else:
        op2 = "-"
    if templist[2] == "0":
        op3 = "+"
    else:
        op3 = "-"
    ans = eval(a+op1+b+op2+c+op3+d)
    if ans == 7:
        print(a+op1+b+op2+c+op3+d+"=7")
        exit()

Submission status: Accepted

Solution code:
S = input()
def two(n):
    A = []
    x = n
    for i in range(3):
        A.append(x%2)
        x//=2
    return A
for i in range(2**3):
    a = S[0]
    T = two(i)
    for j in range(3):
        a+="+" if T[j] else "-"
        a+=S[j+1]
    if eval(a)==7:
        print(a+"=7")
        break

Submission status: Accepted

Solution code:
import sys
s = input()
n = len(s)

for bit in range(2**(n-1)):
    f = ["-"]*(n-1)
    for i in range(n-1):
        if ((bit>>i) & 1):
            f[i] = "+"
    formula = ""
    for pn,po in zip(s, f + [""]):
        formula += (pn + po)
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()

Submission status: Accepted

Solution code:
N=input()
for i in range(2**(len(N)-1)):
    OP=["-","-","-"]
    for j in range(len(N)-1):
        if ((i>>j)&1):
            OP[3-j-1]="+"
    formula=""
    for n,op in zip(N,OP+[""]):
        formula+=n+op
    if eval(formula)==7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
import itertools
s = input()
a,b,c,d = s
op = ["+","-"]

for op1,op2,op3 in itertools.product(op,repeat = 3):
    ans = a + op1 + b + op2 + c + op3 + d
    if eval(ans) == 7:
        print(ans + "=7")
        break
    else:
        pass

Submission status: Accepted

Solution code:
values = [int(c) for c in input()]
for i in range(8):
  if values[0] + sum([[1, -1][(i >> j) & 1] * values[j + 1] for j in range(3)]) == 7:
    print(str(values[0]) + ''.join([['+', '-'][(i >> j) & 1] + str(values[j + 1]) for j in range(3)]) + '=7')
    break

Submission status: Accepted

Solution code:
s = input()
bitlst = []
for i in range(2**3):
    res = []
    for j in range(3):
        if i>>j &1:
            res.append("+")
        else:
            res.append("-")
    bitlst.append(res)

for i in bitlst:
    ans = int(s[0])
    for j in range(3):
        if i[j] == "+":
            ans +=  int(s[j+1])
        else:
            ans -= int(s[j+1])

    if ans == 7:
        print(s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys

abcd = input()

a, b, c ,d = int(abcd[0]), int(abcd[1]), int(abcd[2]), int(abcd[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:
A, B, C, D = [i for i in input()]
fml = ""
ans = ""
for i in range(2**3):
    fml = A + "-" + B + "-" + C + "-" + D
    for j in range(3):
        if i >> j & 1:
            fml = fml[:2*j+1] + "+" + fml[2*j+2:]
    if eval(fml) == 7:
        ans = fml + "=7"
        break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
num=np.array(list(input()))

for bit in  range(1<<3):
  op=np.array(['-']*3)
  for i in range(3):
    if (bit>>i)&1:
      op[i]='+'
  formula=np.insert(num,[1,2,3],op)
  
  if eval(''.join(formula))==7:
    flag=True
    print(''.join(formula)+'=7')
    break

Submission status: Accepted

Solution code:
s = input()
for i in range(2**3):
    check = [0]*3
    op = []
    tmp = int(s[0])
    ans = s[0]
    for j in range(3):
        if (i>>j)&1:
            check[j] = 1
    for k in range(3):
        if check[k] == 1:
            op.append("+")
        else:
            op.append("-")
    for k in range(1,4):

        if op[k-1] == "+":
            tmp += int(s[k])
            ans = ans+op[k-1]
            ans = ans+s[k]
        else:
            tmp -= int(s[k])
            ans = ans+op[k-1]
            ans = ans+s[k]

    if tmp == 7:
        ans = ans + "=7"
        print(ans)
        exit()

Submission status: Accepted

Solution code:
n = input()
a = int(n[0])

for i in range(8):
    x = "{0:03b}".format(i)
    s = a
    ss = "{0}".format(a)
    for j in range(3):
        if x[j] == '0':
            s -= int(n[j+1])
            ss += "-{0}".format(int(n[j+1]))
        else:
            s += int(n[j+1])
            ss += "+{0}".format(int(n[j+1]))
    if s == 7:
        break
print(ss+"=7")

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

ABCD = input()

for i in range(2**3):
    total = int(ABCD[0])
    op = []
    tmp = i
    for j in range(3):
        if tmp & 1 == 1:
            op.append('+')
            total += int(ABCD[j+1])
        else:
            op.append('-')
            total -= int(ABCD[j+1])
        tmp = tmp >> 1
    if total == 7:
        print(ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] +ABCD[3] + '=7')
        break

Submission status: Accepted

Solution code:
s = input()

def func(ac,s,op):
  next = int(s[0])
  if len(s) ==1:
    if ac + next == 7:
      print(op+'+'+s[0]+'=7')
      exit(0)
    if ac - next == 7:
      print(op+'-'+s[0]+'=7')
      exit(0)
  else:
    func(ac+next,s[1:],op+'+'+str(next))
    func(ac-next,s[1:],op+'-'+str(next))
  
func(int(s[0]),s[1:],s[0])

Submission status: Accepted

Solution code:
import re
s = input()
ans = []

def sum_p(res, i):
    if i == 3:
        res += s[i]
        a = sum(list(map(int, re.split('[+, *]', res))))
        if a == 7:
            res = res.replace("*", "")
            ans.append(res+"=7")
    elif i == 0:
        res1 = res+s[i]+"+"
        sum_p(res1, i+1)
        res2 = res+s[i]+"*"+"-"
        sum_p(res2, i+1)
    else:
        sum_p(res+s[i]+"+", i+1)
        sum_p(res+s[i]+"*"+"-", i+1)

sum_p("", 0)
print(ans[0])

Submission status: Accepted

Solution code:
s=input()
#n進数への変換関数の定義
#Python 3.7とかではデフォであるが，Python 3.4.3(AtCoder仕様)ではまだない
########10進法からn進法への変換関数部分##############
def format(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
############################

########10進法からn進法への変換関数(m桁埋める)部分##############
def format0(X, n, m):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    if len(out) < m:
        out = "0" * (m - len(out)) + out
    return out
############################

for i in range(8):
  j=format0(i,2,3)
  memo=[]
  for i in range(3):
    if j[i]=="0":
      memo.append("+")
    else:
      memo.append("-")
  a = s[0]+memo[0]+s[1]+memo[1]+s[2]+memo[2]+s[3]
  if eval(a)==7:
    print(a + "=7")
    exit()

Submission status: Accepted

Solution code:
from sys import exit
S = input()
t = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            r = S[0]+t[i]+S[1]+t[j]+S[2]+t[k]+S[3]
            if eval(r)==7:
                print(r+'=7')
                exit()

Submission status: Accepted

Solution code:
A,B,C,D=list(input())

op1=["+","-"]
op2=["+","-"]
op3=["+","-"]

def solve(A,B,C,D):
    for o1 in op1:
        for o2 in op2:
            for o3 in op3:
                if eval(A+o1+B+o2+C+o3+D)==7:
                    print(A+o1+B+o2+C+o3+D+"=7")
                    return
    return 

solve(A,B,C,D)