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:
if __name__ == '__main__':
    s = input()
    
    # + or - を入れる位置は間なので-1する
    n = len(s) - 1
    
    for i in range(1<<n):    #2**nと同じ
        ans = s[0]
        for j in range(n):
            #iはどこに＋を挿入するか jはsのこと
            if (i >> j & 1) :
                ans += "+"
            else:
                ans += "-"
            
            ans += s[j+1]
        if eval(ans) == 7:
            print(ans+"=7")
            break

Submission status: Accepted

Solution code:
def main():
  s = input()

  for op in range(16):
    t = s[0]
    for j in range(3):
      if (op & (1 << j)):
        t = t + "+"
      else:
        t = t + "-"
      t = t + s[j+1]
    #print(op,t,eval(t))
    if eval(t) == 7:
      print(t + "=7")
      exit(0)
      
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
S = input()
l = len(S)
ans = 0

for i in range(2**(l-1)):
    T = S[0]
    for j in range(l-1):
        if i>>j & 1:
            T = T + "-"
        else:
            T = T + "+"
        T = T+S[j+1]
    if eval(T) == 7:
        print(T+"=7")
        exit()

Submission status: Accepted

Solution code:
S=input()

for i in range(2**3):
    t=S[0]
    for j in range(3):
        if i & (1<<j):
            t+='+'
        else:
            t+='-'
        t+=S[j+1]
    if eval(t)==7:
        break
print(t+'=7')

Submission status: Accepted

Solution code:
from itertools import product

s=input()

for op in product(["+","-"],repeat=3):
  formula =""
  for i in range(3):
    formula+=s[i]+op[i]
  formula+=s[-1]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

Submission status: Accepted

Solution code:
nums = list(map(int, list(input())))
ans = ''
for n in range(8):
    bits = bin(n)[2:].zfill(3)
    total = nums[0]
    ans = str(nums[0])
    for i, b in enumerate(bits):
        if b == '0':
            total += nums[i+1]
            ans += '+' + str(nums[i+1])
        else:
            total -= nums[i+1]
            ans += '-' + str(nums[i+1])

    if total == 7:
        ans += '=7'
        break

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s=input()

for operators in product(["+","-"],repeat=3):
  formula=""
  for i in range(3):
    formula+=s[i]+operators[i]
  formula+=s[-1]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    ABCD = S()
    A = ABCD[0]
    BCD = ABCD[1:]

    ans = [A, '', BCD[0], '', BCD[1], '', BCD[2], '=', '7']
    for i in range(2 ** 3):
        tmp = int(A)
        for j in range(3):
            if i >> j & 1:
                tmp += int(BCD[j])
                ans[j*2+1] = '+'
            else:
                tmp -= int(BCD[j])
                ans[j*2+1] = '-'
        if tmp == 7:
            print(''.join(ans))
            break

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
abcd=str(input())
n=len(abcd)
ans=int(abcd[0])
sign=[]
for i in range(2**(n-1)):
    for j in range(n-1):
        if (i>>j)&1==True:
            ans+=int(abcd[j+1])
            sign.append("+")
        else:
            ans-=int(abcd[j+1])
            sign.append("-")
    if ans==7:
        print(abcd[0]+sign[0]+abcd[1]+sign[1]+abcd[2]+sign[2]+abcd[3]+"=7")
        sys.exit()
    else:
        ans=int(abcd[0])
        sign=[]

Submission status: Accepted

Solution code:
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
if A + B + C + D == 7:
    op1 = op2 = op3 = "+"
elif A + B + C - D == 7:
    op1 = op2 = "+"
    op3 = "-"
elif A + B - C + D == 7:
    op1 = op3 = "+"
    op2 = "-"
elif A + B - C - D == 7:
    op1 = "+"
    op2 = op3 = "-"
elif A - B + C + D == 7:
    op1 = "-"
    op2 = op3 = "+"
elif A - B + C - D == 7:
    op1 = op3 = "-"
    op2 = "+"
elif A - B - C + D == 7:
    op1 = op2 = "-"
    op3 = "+"
elif A - B - C - D == 7:
    op1 = op2 = op3 = "-"
print(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7")

Submission status: Accepted

Solution code:
s=input()
for i in range(2**3):
    t=s[0]
    for j in range(3):
        if i%2:t+='+'
        else:t+='-'
        i//=2
        t+=s[j+1]
    if eval(t+'==7'):
        print(t+'=7')
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
List = [int(n) for n in input()]
ans = [List[0]] * 4
for i in range(8):
    for j in range(3):
        if i & (1<<j):
            ans[j+1]= -List[j+1]
        else:
            ans[j+1] = List[j+1]
    if sum(ans) == 7:
        break
ans = [str(ans[0])] + ['+' + str(x) if x>=0 else str(x) for x in ans[1:]]
print("".join(ans) + '=7')

Submission status: Accepted

Solution code:
s = input()

def dfs(i,tmp,sum):
    if i == 3:
        if sum == 7:
            print(tmp + "=7")
            exit()

    else:
        dfs(i+1, tmp +"+"+ s[i+1], sum + int(s[i+1]))
        dfs(i+1, tmp +"-"+ s[i+1], sum - int(s[i+1]))

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

Submission status: Accepted

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

num = input()
nums = [int(num[0]), int(num[1]), int(num[2]), int(num[3])]

sum_ = sum(nums)

for bit in range(1 << 3):
    tmp = sum_
    ops = ['+', '+', '+']
    for j in range(3):
        if bit & (1 << j):
            tmp -= 2 * nums[j+1]
            ops[j] = '-'
    if tmp == 7:
        res = str(nums[0]) + ops[0] + str(nums[1]) + ops[1] + str(nums[2]) + ops[2] + str(nums[3]) + '=7'
        print(res)
        break

Submission status: Accepted

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

ans = 0


for bit in range(1 << (n-1)):
    f = s[0]
    for i in range(n - 1):
        if bit & (1 << i):
            f += "+"
        else:
            f += "-"
        f += s[i+1]
    if  eval(f) == 7:
        print(f+"=7")
        break

Submission status: Accepted

Solution code:
import sys

A = list(map(int,sys.stdin.readline().rstrip()))

from itertools import product

X = ['+','-']
for a in product(X,repeat=3):
    b = A[0]
    for i in range(3):
        if a[i] == '+':
            b += A[i+1]
        else:
            b -= A[i+1]
    if b == 7:
        print(str(A[0])+a[0]+str(A[1])+a[1]+str(A[2])+a[2]+str(A[3])+'=7')
        break

Submission status: Accepted

Solution code:
import sys

tmp = list(sys.stdin.readline().strip())
nums = list(map(int, tmp))

for a in range(2):
    for b in range(2):
        for c in range(2):
            tmp = nums[0]
            exp = str(nums[0])
            if a == 0:
                tmp += nums[1]
                exp += "+"
            else:
                tmp -= nums[1]
                exp += "-"
            exp += str(nums[1])
            if b == 0:
                tmp += nums[2]
                exp += "+"
            else:
                tmp -= nums[2]
                exp += "-"
            exp += str(nums[2])
            if c == 0:
                tmp += nums[3]
                exp += "+"
            else:
                tmp -= nums[3]
                exp += "-"
            exp += str(nums[3])
            if tmp == 7:
                print(exp + "=7")
                sys.exit()

Submission status: Accepted

Solution code:
import sys

*S, = input()

op = ['-', '+']
for i in op:
    for j in op:
        for k in op:
            e = f'{S[0]}{i}{S[1]}{j}{S[2]}{k}{S[3]}'
            if eval(e) == 7:
                print(f'{e}=7')
                sys.exit()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

for i in ('+', '-'):
    for j in ('+', '-'):
        for k in ('+', '-'):
            val = A
            if i=='+':
                val += B
            else:
                val -= B

            if j=='+':
                val += C
            else:
                val -= C

            if k=='+':
                val += D
            else:
                val -= D
            
            if val==7:
                print('{}{}{}{}{}{}{}=7'.format(A, i, B, j, C, k, D))
                exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=list(input())
d=["+","-"]
for i in d:
  for j in d:
    for k in d:
      if eval(s[0]+i+s[1]+j+s[2]+k+s[3])==7:
        ans=s[0]+i+s[1]+j+s[2]+k+s[3]
        
print(ans+"=7")

Submission status: Accepted

Solution code:
def main(A,B,C,D):
    list = [A,B,C,D]

    tmp = ['+','-']


    for i in range(2**3):
        ans = A
        back = []
        for j in range(3):
            if ( (i>>j)&1 ):
                ans += list[j+1]
                back.append(tmp[0])
            else:
                ans -= list[j+1]
                back.append(tmp[1])
        if ans == 7:
            return back

tmp = int(input())
D = tmp%10
tmp = tmp//10
C = tmp%10
tmp = tmp//10
B = tmp%10
tmp = tmp//10
A = tmp%10
back = main(A,B,C,D)
print(str(A)+back[0]+str(B)+back[1]+str(C)+back[2]+str(D)+'=7')

Submission status: Accepted

Solution code:
s = input()
a = [int(x) for x in s]
for bit in range(1 << 3):
    tmp = a[0]
    tmps = str(a[0])

    for i in range(3):
        if bit >> i & 1:
            tmp += a[i + 1]
            tmps += '+' + str(a[i + 1])
        else:
            tmp -= a[i + 1]
            tmps += '-' + str(a[i + 1])
    if tmp == 7:
        print(tmps + '=7')
        exit()

Submission status: Accepted

Solution code:
import sys
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
hugo = [1, -1]
for b in hugo:
    AB = A+b*B
    for c in hugo:
        ABC = AB+c*C
        for d in hugo:
            ABCD = ABC+d*D
            if ABCD == 7:
                if b == 1:
                    b = "+"
                else:
                    b = "-"
                if c == 1:
                    c = "+"
                else:
                    c = "-"
                if d == 1:
                    d = "+"
                else:
                    d = "-"
                print(A, b, B, c, C, d, D, "=7", sep="")
                sys.exit()

Submission status: Accepted

Solution code:
s=input()
a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
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:
import sys
from itertools import product

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


def resolve():
    nums = list(input())
    for pattern in product(["+", "-"],repeat=3):
        pattern = list(pattern) + [""]
        fomula = ""
        for op, num in zip(pattern, nums):
            fomula += num + op
        if eval(fomula) == 7:
            print(fomula + "=" + "7")
            break


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from itertools import product
s = input()
A, B, C, D = int(s[0]), int(s[1]), int(s[2]), int(s[3])

P = product([1, -1], repeat=3)

def convert(integer):
    if integer == 1:
        return "+"
    elif integer == -1:
        return "-"

for o1, o2, o3 in P:
    if A + B * o1 + C * o2 + D * o3 == 7:
        print(str(A) + convert(o1) + str(B) + convert(o2) + str(C) + convert(o3) + str(D) + "=7")
        exit()

Submission status: Accepted

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

for i in [-1,1]:
    for j in [-1,1]:
        for k in [-1,1]:
            if a + i*b + j*c + k*d == 7:
                op1 = ['-','+'][i==1]
                op2 = ['-','+'][j==1]
                op3 = ['-','+'][k==1]
                print(f'{a}{op1}{b}{op2}{c}{op3}{d}=7')
                exit()

Submission status: Accepted

Solution code:
s=list(input())

from itertools import product as pr

p = list(pr(['+','-'],repeat=3))

for ope in p:
    f = s[0] + ope[0] + s[1] + ope[1] + s[2] + ope[2] + s[3]

    if eval(f)==7:
        print(f+'=7')
        exit(0)

Submission status: Accepted

Solution code:
x = input()
a=[int(x[0]), int(x[1]), int(x[2]), int(x[3])]
op=['+', '-']
for i in range(2):
  for j in range(2):
    for k in range(2):
      ops = [op[i], op[j], op[k]]
      tmp = a[0]
      for l in range(3):
        if ops[l]=='+':
          tmp = tmp + a[l+1]
        else:
          tmp = tmp - a[l+1]
      if tmp==7:
        break
    if tmp==7:
      break
  if tmp==7:
    break

print(str(a[0])+ops[0]+str(a[1])+ops[1]+str(a[2])+ops[2]+str(a[3])+'=7')

Submission status: Accepted

Solution code:
s = list(input())
ans = []
for i in ['+', '-']:
    for j in ['+', '-']:
        for k in ['+', '-']:
            tmp = int(s[0])
            if i == '+':
                tmp += int(s[1])
            else:
                tmp -= int(s[1])
            if j == '+':
                tmp += int(s[2])
            else:
                tmp -= int(s[2])
            if k == '+':
                tmp += int(s[3])
            else:
                tmp -= int(s[3])
            if tmp == 7:
                ans = [s[0],i,s[1],j,s[2],k,s[3],'=7']
                break
print(''.join(map(str,ans)))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
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()))

s = input()
for pt in itertools.product([0,1],repeat=3):
    now = int(s[0])
    for i,x in enumerate(pt):
        # print(now)
        if x:
            now += int(s[i+1])
        else:
            now -= int(s[i+1])
    if now == 7:
        res = s[0]
        for i in range(1,4):
            tmp = '+' if pt[i-1] else '-'
            res += tmp + s[i]
        print(res+'=7')
        break

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

A = list(map(int,sys.stdin.readline().rstrip()))

from itertools import product

X = ['+','-']
for a in product(X,repeat=3):
    b = A[0]
    for i in range(3):
        if a[i] == '+':
            b += A[i+1]
        else:
            b -= A[i+1]
    if b == 7:
        print(str(A[0])+a[0]+str(A[1])+a[1]+str(A[2])+a[2]+str(A[3])+'=7')
        break

Submission status: Accepted

Solution code:
import sys

a, b, c, d = list(map(int, input().rstrip()))

li = ["+", "-"]

for x in li:
    for y in li:
        for z in li:
            tmp = a
            if x == "+":
                tmp += b
            else:
                tmp -= b
            if y == "+":
                tmp += c
            else:
                tmp -= c
            if z == "+":
                tmp += d
            else:
                tmp -= d
            if tmp == 7:
                print("{}{}{}{}{}{}{}=7".format(a, x, b, y, c, z, d))
                sys.exit()

Submission status: Accepted

Solution code:
import itertools
S = str(input())
L = ("+","-")

kouho = list(itertools.product(L, repeat=3))
#print(kouho)
for x in kouho:
  temp = S[0]+x[0]+S[1]+x[1]+S[2]+x[2]+S[3]
  ans = eval(temp)
  if ans == 7:
    print(temp+"=7")
    exit()

Submission status: Accepted

Solution code:
s = list(input())
# v = list(map(int,s))

for a in ['+','-']:
    for b in ['+','-']:
        for c in ['+','-']:
            cal = s[0]+a+s[1]+b+s[2]+c+s[3]
            v = eval(cal)
            if v == 7:
                print(cal+'=7')
                exit()

Submission status: Accepted

Solution code:
from itertools import product
s = input().strip()
for x in product(("+","-"),repeat=3):
    y = s[0]+x[0]+s[1]+x[1]+s[2]+x[2]+s[3]
    if eval(y)==7:
        break
print(y+"=7")

Submission status: Accepted

Solution code:
import sys
import itertools

a, b, c, d = list(input())

lst = ['-', '+']
for i, j, k in itertools.product(range(2), range(2), range(2)):
    ans = int(a)
    if i:
        ans += int(b)
    else:
        ans -= int(b)
    if j:
        ans += int(c)
    else:
        ans -= int(c)
    if k:
        ans += int(d)
    else:
        ans -= int(d)
        
    if ans == 7:
        print(a,lst[i],b,lst[j],c,lst[k],d,'=7',sep='')
        break

Submission status: Accepted

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

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 + "+" + S[i+1], sum + int(S[i+1]))
    dfs(i+1, s + "-" + S[i+1], sum - int(S[i+1]))

S = str(input())
dfs(0,S[0],int(S[0]))

Submission status: Accepted

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

def dfs(ans, index, cnt):
    if index == 0:
        return dfs(ans + str(L[index]), index + 1, cnt + L[index])
    if index == 4:
        if cnt == 7:
            return ans + '=7'
        else:
            return False
    ans1 = dfs(ans + '+' + str(L[index]), index+1, cnt + L[index])
    ans2 = dfs(ans + '-' + str(L[index]), index+1, cnt - L[index])
    if ans1:
        return ans1
    if ans2:
        return ans2
    return False

ans = dfs('', 0, 0)
print(ans)

Submission status: Accepted

Solution code:
N=str(input())
cc=['+']*3
ans=int(N[0])
for j in range(2**3):
    temp=bin(2**3+j)
    for i in range(3,6):
        if temp[i]=='0':
            ans+=int(N[i-2])
            cc[i-3]='+'
        else:
            ans-=int(N[i-2])
            cc[i-3]='-'
    if ans==7:
        print(N[0]+cc[0]+N[1]+cc[1]+N[2]+cc[2]+N[3]+'=7')
        exit()
    else:
        ans=int(N[0])

Submission status: Accepted

Solution code:
import itertools
moji = str(input())
A,B,C,D = int(moji[0]),int(moji[1]),int(moji[2]),int(moji[3])

Bn = [B,B*-1]
Cn = [C,C*-1]
Dn = [D,D*-1]
flg = 0
for i,j,k in itertools.product(Bn, Cn,Dn):
    X = A + i + j + k
    if X == 7:
        break
    
print(str(A) + (str(i),"+"+str(i))[i >= 0]+ (str(j),"+"+str(j))[j >= 0]+ (str(k),"+"+str(k))[k >= 0]+"=7")

Submission status: Accepted

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

Submission status: Accepted

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



if IN[0]+IN[1]+IN[2]+IN[3] ==7:
    print(str(IN[0])+"+"+str(IN[1])+"+"+str(IN[2])+"+"+str(IN[3])+"=7")
elif IN[0]-IN[1]+IN[2]+IN[3] ==7:
    print(str(IN[0])+"-"+str(IN[1])+"+"+str(IN[2])+"+"+str(IN[3])+"=7")
elif IN[0]+IN[1]-IN[2]+IN[3] ==7:
    print(str(IN[0])+"+"+str(IN[1])+"-"+str(IN[2])+"+"+str(IN[3])+"=7")
elif IN[0]-IN[1]-IN[2]+IN[3] ==7:
    print(str(IN[0])+"-"+str(IN[1])+"-"+str(IN[2])+"+"+str(IN[3])+"=7")
elif IN[0]+IN[1]+IN[2]-IN[3] ==7:
    print(str(IN[0])+"+"+str(IN[1])+"+"+str(IN[2])+"-"+str(IN[3])+"=7")
elif IN[0]-IN[1]+IN[2]-IN[3] ==7:
    print(str(IN[0])+"-"+str(IN[1])+"+"+str(IN[2])+"-"+str(IN[3])+"=7")
elif IN[0]+IN[1]-IN[2]-IN[3] ==7:
    print(str(IN[0])+"+"+str(IN[1])+"-"+str(IN[2])+"-"+str(IN[3])+"=7")
else: 
    print(str(IN[0])+"+"+str(IN[1])+"+"+str(IN[2])+"-"+str(IN[3])+"=7")

Submission status: Accepted

Solution code:
def operator(x):
    if x < 0:
        return '-'
    else:
        return '+'


def main():
    abcd = str(input())
    a = int(abcd[0])
    b = int(abcd[1])
    c = int(abcd[2])
    d = int(abcd[3])

    lst = []
    for op_1 in range(2):
            for op_2 in range(2):
                for op_3 in range(2):

                    b1 = b
                    c1 = c
                    d1 = d
                    if op_1 == 1:
                        b1 = -b
                    if op_2 == 1:
                        c1 = -c
                    if op_3 == 1:
                        d1 = -d

                    if b1 + c1 + d1 == 7 - a:
                        lst.append(b1)
                        lst.append(c1)
                        lst.append(d1)
                        break

    op1 = operator(lst[0])
    op2 = operator(lst[1])
    op3 = operator(lst[2])
    answer = str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + '=' + '7'
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=list(input())
A=int(N[0])
B=int(N[1])
C=int(N[2])
D=int(N[3])
if A+B+C+D==7:
  key=N[0]+'+'+N[1]+'+'+N[2]+'+'+N[3]+'=7'
  print(key)
  exit()
if A+B+C-D==7:
  key=N[0]+'+'+N[1]+'+'+N[2]+'-'+N[3]+'=7'
  print(key)
  exit()
if A+B-C+D==7:
  key=N[0]+'+'+N[1]+'-'+N[2]+'+'+N[3]+'=7'
  print(key)
  exit()
if A-B+C+D==7:
  key=N[0]+'-'+N[1]+'+'+N[2]+'+'+N[3]+'=7'
  print(key)
  exit()
if A-B-C+D==7:
  key=N[0]+'-'+N[1]+'-'+N[2]+'+'+N[3]+'=7'
  print(key)
  exit()
if A-B+C-D==7:
  key=N[0]+'-'+N[1]+'+'+N[2]+'-'+N[3]+'=7'
  print(key)
  exit()
if A+B-C-D==7:
  key=N[0]+'+'+N[1]+'-'+N[2]+'-'+N[3]+'=7'
  print(key)
  exit()
if A-B-C-D==7:
  key=N[0]+'-'+N[1]+'-'+N[2]+'-'+N[3]+'=7'
  print(key)
  exit()

Submission status: Accepted

Solution code:
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


a = list(_S())
a = list(map(int,a))
l = len(a)-1

for i in range(1<<l):
    t = a[0]
    sign = ['-','-','-']
    # 符号のループ
    for j in range(l):
        # i を j回右にシフトして1との論理積を取り、0であれば+とする
        if (i >> j) & 1 == 0:
            t += a[j+1]
            sign[j]='+'
        else:
            t -= a[j+1]
    # print(t)
    if t == 7:
        break

ans = str(a[0])
for i in range(l):
    ans += sign[i] + str(a[i+1])
ans += '=7'
print(ans)

Submission status: Accepted

Solution code:
num = input()

ls = [0] * 3
for i in range(2 ** 3):
    make7 = int(num[0])
    for j in range(3):
        if (i >> j) & 1:
            make7 += int(num[j+1])
            ls[j] = "+"
        else:
            make7 -= int(num[j+1])
            ls[j] = "-"
    if make7 == 7:
        print(num[0] + ls[0] + num[1] + ls[1] + num[2] + ls[2] + num[3] + "=7")
        exit()

Submission status: Accepted

Solution code:
abcd = input()
n = len(abcd)
for i in range(1<<n-1):
    ans = abcd[0]
    for j in range(n-1):
        if i>>j&1:
            ans += "-" + abcd[j+1]
        else:
            ans += "+" + abcd[j+1]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Submission status: Accepted

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

for flag in range(2**3):
	op=[]
	temp_a=A
	for i in range(3):
		if (flag>>i)&1==1:
			op.append("+")
			temp_a+=int(a[i+1])
		else:
			op.append("-")
			temp_a-=int(a[i+1])
	if temp_a==7:
		print("{}{}{}{}{}{}{}=7".format(a[0],op[0],a[1],op[1],a[2],op[2],a[3]))
		exit()

Submission status: Accepted

Solution code:
n = input()
for i in range(2**3):
    ss =""
    ss +=n[0]
    for j in range(3):
        if((i >> j )&1==True):
            ss += "+"
            ss += n[j+1]
        else:
            ss += "-"
            ss += n[j+1]
    ans = eval(ss)
    if (ans == 7):
        ss += "=7"
        print(ss)
        break

Submission status: Accepted

Solution code:
def operation(a,ops):
    ans = a[0]
    for i in range(3):
        if ops[i]=='+':
            ans += a[i+1]
        else:
            ans -= a[i+1]
    return ans

s = list(input())
a = [int(i) for i in s]
op = ['+','-']

for i in range(1<<3):
    ops = [op[1&(i>>j)] for j in range(3)]
    if operation(a,ops)==7:
        print("{}{}{}{}{}{}{}=7".format(a[0],ops[0],a[1],ops[1],a[2],ops[2],a[3]))
        break

Submission status: Accepted

Solution code:
s = input()
A = [int(s[0]), int(s[1]), int(s[2]), int(s[3])]

for i in range(8):
    b = format(i, "03b")
    S = A[0]
    for j in range(3):
        if b[j] == "0":
            S += A[j + 1]
        else:
            S -= A[j + 1]
    if S == 7:
        break

op = ["+", "-"]
ans = s[0] + op[int(b[0])] + s[1] + op[int(b[1])] + s[2] + op[int(b[2])] + s[3] + "=7"
print(ans)

Submission status: Accepted

Solution code:
s = input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
for j in range(2):
    for k in range(2):
        for l in range(2):
            sm=a
            if j==0:
                B='+'
                sm+=b
            else:
                B='-'
                sm-=b
            if k==0:
                C='+'
                sm+=c
            else:
                C='-'
                sm-=c
            if l==0:
                D='+'
                sm+=d
            else:
                D='-'
                sm-=d
            if sm==7:
                
                m=str(a)+B+str(b)+C+str(c)+D+str(d)+'=7'
                print(m)
                exit()

Submission status: Accepted

Solution code:
abcd=str(input())
for i in range(2**4):
    list=[int(abcd[0])]
    symbol=[]
    for j in range(1,4):
        if (i>>j)&1==True:
            list.append(int(abcd[j]))
            symbol.append('+')
        else:
            list.append(int(abcd[j])*(-1))
            symbol.append('-')
    if sum(list)==7:
        print(str(abcd[0])+symbol[0]+str(abcd[1])+symbol[1]+str(abcd[2])+symbol[2]+abcd[3]+"=7")
        break

Submission status: Accepted

Solution code:
s = input()

for i in range(2**3):
    ss = ''
    for j in range(4):
        ss += s[j]
        if j < 3:
            if (i >> j) & 1 == 1:
                ss += '+'
            else:
                ss += '-'
    if eval(ss) == 7:
        break
print(ss+'=7')

Submission status: Accepted

Solution code:
X = input()

A, B, C, D = [int(X[i]) for i in range(4)]

for i in range(2**3, 2**4):
    s = format(i, 'b')[1:]
    E = A + (-1) ** int(s[0]) * B + (-1) ** int(s[1]) * C + (-1) ** int(s[2]) * D
    if E == 7:
        break

op = ['+', '-']

print(str(A) + op[int(s[0])] + str(B) + op[int(s[1])] + str(C) + op[int(s[2])] + str(D) + '=7')

Submission status: Accepted

Solution code:
s = input()

#±の入る場所
for bit in range(1<<3): 
    ans = int(s[0]) #sをリストとして見る
    f = s[0] #最後に出力する数式

#±に置き換え
    for i in range(3): 
        if bit&(1 << i): #bitのi桁目が0か1か
            ans += int(s[i+1])
            f += "+"
        else:
            ans -= int(s[i+1])
            f += "-"
        f += s[i+1]
    if ans == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
AA=list(input())

A=[int(n) for n in AA]
Q=sum(A)
B=Q-2*A[1]
C=Q-2*A[2]
D=Q-2*A[3]
E=Q-2*A[1]-2*A[2]
F=Q-2*A[1]-2*A[3]
G=Q-2*A[1]-2*A[2]-2*A[3]
H=Q-2*A[2]-2*A[3]
if Q==7:
    print(AA[0]+'+'+AA[1]+'+'+AA[2]+'+'+AA[3]+'='+'7')
elif B==7:
    print(AA[0]+'-'+AA[1]+'+'+AA[2]+'+'+AA[3]+'='+'7')
elif C==7:
    print(AA[0]+'+'+AA[1]+'-'+AA[2]+'+'+AA[3]+'='+'7')
elif D==7:
    print(AA[0]+'+'+AA[1]+'+'+AA[2]+'-'+AA[3]+'='+'7')
elif E==7:
    print(AA[0]+'-'+AA[1]+'-'+AA[2]+'+'+AA[3]+'='+'7')
elif F==7:
    print(AA[0]+'-'+AA[1]+'+'+AA[2]+'-'+AA[3]+'='+'7')
elif G==7:
    print(AA[0]+'-'+AA[1]+'-'+AA[2]+'-'+AA[3]+'='+'7')
elif H==7:
    print(AA[0]+'+'+AA[1]+'-'+AA[2]+'-'+AA[3]+'='+'7')

Submission status: Accepted

Solution code:
def dsf(i,sum1,ans):
    if i == 4:
        if ans == 7:
            print(sum1 + "=7")
            exit()
    else:
        dsf(i+1,sum1+"+"+abcd[i],ans + int(abcd[i]))
        dsf(i+1,sum1+"-"+abcd[i],ans - int(abcd[i]))


abcd = input()
dsf(1,abcd[0],int(abcd[0]))

Submission status: Accepted

Solution code:
x = input()
y = x[0] + 't' + x[1] + 't' + x[2] + 't' + x[3]
for i in range(8):
  for j in range(3):
    if ((i>>j) & 1) == 1:
      z = list(y)
      z[5-2*j] = '+'
      y = ''.join(z)
    else:
      z = list(y)
      z[5-2*j] = '-'
      y = ''.join(z)
      
  if eval(y) == 7:
    print(y+ '=7')
    break