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:
A = input()
n = len(A)-1
for i in range(2**n):
  pn = ['-']*n
  for j in range(n):
    if ((i>>j)&1):
      pn[n-1-j] = '+'
  ans = A[0]+pn[0]+A[1]+pn[1]+A[2]+pn[2]+A[3]
  
  if eval(ans) == 7:
    print(ans+'=7')
    break

Submission status: Accepted

Solution code:
ABCD = list(input())

a, b, c, d = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]), int(ABCD[3])

if a+b+c+d == 7:
    print('{0}+{1}+{2}+{3}=7'.format(a, b, c, d))
elif a+b+c-d == 7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif a+b-c+d == 7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif a-b+c+d == 7:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))
elif a-b-c+d == 7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
elif a+b-c-d == 7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif a-b+c-d == 7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
elif a-b-c-d == 7:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))

Submission status: Accepted

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

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
input = sys.stdin.readline

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

ans = ''
for i in range(2):
    if ans != '':
        break
    for j in range(2):
        if ans != '':
            break
        for k in range(2):
            t = A + (2*i-1)*B + (2*j-1)*C + (2*k-1)*D
            if t == 7:
                op1 = '-' if i == 0 else '+'
                op2 = '-' if j == 0 else '+'
                op3 = '-' if k == 0 else '+'
                ans = "{}{}{}{}{}{}{}=7".format(A,op1,B,op2,C,op3,D)
                break

print(ans)

Submission status: Accepted

Solution code:
num = str(input())
a = num[0]
b = num[1]
c = num[2]
d = num[3]
plus = ["+", "+", "+"]
minus = ["-", "-", "-"]
for i in range(2**3):
    key = []
    for j in range(3):
        if ((i>>j) &1):
            key.append("+")
        else:
            key.append("-")
    ans = a + key[0] + b + key[1] + c + key[2] + d
    if eval(ans) == 7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
tmp=input()
solution=7
numbers=[]
for i in range(len(tmp)):
    numbers.append(int(tmp[i]))

n = len(numbers)
for i in range(n ** 2):
    ops = ["-"] * (n-1)
    for j in range(n-1):
        if ((i>>j) & 1):
            ops[n-1-j-1]="+"
    #print(ops)
    shiki = str(numbers[0])
    for j in range(n-1):
        shiki = shiki + ops[j] + str(numbers[j+1])
    #print(shiki)
    if int(eval(shiki)) == int(solution):
        print(shiki+"="+str(solution))
        break

Submission status: Accepted

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

ops = [
        ['+', '+', '+'],
        ['+', '+', '-'],
        ['+', '-', '+'],
        ['+', '-', '-'],
        ['-', '+', '+'],
        ['-', '+', '-'],
        ['-', '-', '+'],
        ['-', '-', '-'],
        ]


def solve(ABCD: str):
    a = int(ABCD[0])
    b = int(ABCD[1])
    c = int(ABCD[2])
    d = int(ABCD[3])
    for i in range(8):
        t = a
        if ops[i][0] == "+":
            t += b
        else:
            t -=b
        if ops[i][1] == "+":
            t += c
        else:
            t -=c
        if ops[i][2] == "+":
            t += d
        else:
            t -=d
        if t == 7:
            print(f"{a}{ops[i][0]}{b}{ops[i][1]}{c}{ops[i][2]}{d}=7")
            break

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)  # type: str
    solve(ABCD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations

s = input()

ans = ['-','-','-']
for i in range(4):
    for comb in combinations(range(3),i):
        temp = int(s[0])
        for j in range(3):
            if j in comb:
                temp += int(s[j+1])
            else:
                temp -= int(s[j+1])
        if temp==7:
            for j in comb:
                ans[j] = "+"
            break 
print("{a}{op1}{b}{op2}{c}{op3}{d}=7".format(a=s[0],op1=ans[0],b=s[1],op2=ans[1],c=s[2],op3=ans[2],d=s[3]))

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
# row = [int(input().rstrip()) for _ in range(n)]

def resolve():
    import sys
    input = sys.stdin.readline

    a, b, c, d = [int(x) for x in input().rstrip()]

    for o1 in [True, False]:
        for o2 in [True, False]:
            for o3 in [True, False]:
                ans = a
                ans += b if o1 else -b
                ans += c if o2 else -c
                ans += d if o3 else -d

                if ans == 7:
                    s = str(a)
                    s += "+" if o1 else "-"
                    s += str(b)
                    s += "+" if o2 else "-"
                    s += str(c)
                    s += "+" if o3 else "-"
                    s += str(d)
                    s += "=7"

                    print(s)
                    return


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
A=list(input())
for i in range(4):
    A[i]=int(A[i])
for i in range(8):
    x=A[0]
    for j in range(3):
        if (i//(2**j))%2==1:
            x+=A[j+1]
        else:
            x-=A[j+1]
    if x==7:
        print(A[0],end='')
        for j in range(3):
            if (i//(2**j))%2==1:
                print('+',end='')
            else:
                print('-',end='')
            print(A[j+1],end='')
        print('=7')
        break

Submission status: Accepted

Solution code:
x = input()

for i in range(1 << 3):
    start = ["+", "+", "+"]
    for j in range(3):
        if (i >> j) & 1:
            start[j] = "-"
    #print(start, i)
    ans = int(x[0])
    for k in range(3):
        if start[k] == "+":
            ans += int(x[k + 1])
        else:
            ans -= int(x[k + 1])
    #print(ans)
    if ans == 7:
        print(x[0] + str(start[0]) + x[1] + str(start[1]) + x[2] + str(start[2]) + x[3] + "=7")
        break

Submission status: Accepted

Solution code:
import itertools
L = ['+', '-']
s = list(input())
for l in itertools.product(L, repeat=3):
  if 7 == eval(s[0]+l[0]+s[1]+l[1]+s[2]+l[2]+s[3]):
    print(s[0]+l[0]+s[1]+l[1]+s[2]+l[2]+s[3]+'=7')
    break

Submission status: Accepted

Solution code:
A=list(input())
b=[]
for i in range(2**3):
  b.clear()
  for j in range(3):
    if (i>>j)&1:
      b.append("+")
    else:
      b.append("-")
  c=eval(A[0]+b[0]+A[1]+b[1]+A[2]+b[2]+A[3])
  if c==7:
    print(A[0]+b[0]+A[1]+b[1]+A[2]+b[2]+A[3]+"=7")
    exit()

Submission status: Accepted

Solution code:
def dfs(i,sumnum,sums):
    global ans
    if i == 4:
        if sumnum == 7:
            print(sums + "=7")
            exit()
    else:
        dfs(i+1,sumnum + int(s[i]),sums + "+" + s[i])
        dfs(i+1,sumnum - int(s[i]),sums + "-" + s[i])
s = input()
dfs(1,int(s[0]),s[0])

Submission status: Accepted

Solution code:
def dfs(i,sumnum,sums):
    global ans
    if i == 4:
        if sumnum == 7:
            print(sums + "=7")
            exit()
    else:
        dfs(i+1,sumnum + int(s[i]),sums + "+" + s[i])
        dfs(i+1,sumnum - int(s[i]),sums + "-" + s[i])
s = input()
ans = ""
dfs(1,int(s[0]),s[0])

Submission status: Accepted

Solution code:
def dfs(i,sumnum,sums):
    global ans
    if i == 4:
        if sumnum == 7:
            ans = sums + "=7"
    else:
        dfs(i+1,sumnum + int(s[i]),sums + "+" + s[i])
        dfs(i+1,sumnum - int(s[i]),sums + "-" + s[i])
s = input()
ans = ""
dfs(1,int(s[0]),s[0])
print(ans)

Submission status: Accepted

Solution code:
def dfs(i,sum1,sum2):
    global ans
    if i == 4 and sum1 != 7:
        return 0
    elif i == 4 and sum1 == 7:
        ans = sum2 + "=7"
        return 0
    else:
        dfs(i + 1,sum1 + int(s[i]),sum2 + "+" + s[i])
        dfs(i + 1, sum1 - int(s[i]), sum2 + "-" + s[i])

s = input()
ans = ""
dfs(1,int(s[0]),s[0])
print(ans)

Submission status: Accepted

Solution code:
num = list(input())
for i in range(2**3):
    n = []
    pm = ["+","+","+"]
    for j in range(3):
        if ((i >> j) & 1):
            pm[j] = "-"
    for k in range(3):
        n.append(num[k])
        n.append(pm[k])
    n.append(num[3])
    formula = ""
    for j in range(7):
        formula += n[j] 
    if eval(formula) == 7:
        [print(n[k],end="") for k in range(7)]
        print("=7")
        exit()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
#print(n)
ans=0
for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    #print("bit",bit,bin(bit))
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            # フラグが立っているならば "+" を式の末尾に追加する
            f += "+"
        else:
          f+="-"
        f += s[i + 1]
        #print("i",i,"1 << i",bin(1 << i),"f",f)
    #print(f)
    ans=eval(f)
    if ans==7:
      f+="=7"
      print(f)
      exit()

Submission status: Accepted

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

for i in [-1,1]:
  for j in [-1,1]:
    for k in [-1,1]:
      if A + B*i+ C*j + D*k == 7:
        it = "-" if i == -1 else "+"
        jt = "-" if j == -1 else "+"
        kt = "-" if k == -1 else "+"
        print(str(A)+it+str(B)+jt+str(C)+kt+str(D)+"=7")
        exit(0)

Submission status: Accepted

Solution code:
def si(p):
  if p == 0:
    return "-"
  else:
    return "+"
N = int(input())
X = [N // 1000, (N % 1000) // 100, (N % 100) // 10, N % 10]
f = 0
for i in range(2):
  for j in range(2):
    for k in range(2):
      x = X[0] + (2 * i - 1) * X[1] + (2 * j - 1) * X[2] + (2 * k - 1) * X[3]
      if x == 7:
        print(str(X[0]) + si(i) + str(X[1]) + si(j) + str(X[2]) + si(k) + str(X[3]) + "=7")
        f = 1
        break
    if f == 1:
      break
  if f == 1:
    break

Submission status: Accepted

Solution code:
def dfs(i,sum1,sum2):
    global ans
    #print(sum1,sum2)
    if i == 4 and sum1 != 7:
        return 0
    elif i == 4 and sum1 == 7:
        ans = sum2 + "=7"
    else:
        dfs(i + 1,sum1 - int(s[i]),sum2 + "-" +s[i])
        dfs(i + 1,sum1 + int(s[i]),sum2 + "+" +s[i])

ans = ""
s = input()
dfs(1,int(s[0]),s[0])
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
for i in range(8):
  t = s[0]
  x = int(t)
  if i%2 == 0:
    t = t + "+"+ s[1]
    x += int(s[1])
  else:
    t = t + "-" + s[1]
    x -= int(s[1])
  if (i//2)%2 == 0:
    t = t + "+" + s[2]
    x += int(s[2])
  else:
    t = t + "-" + s[2]
    x -= int(s[2])
  if (i//4)%2 == 0:
    t = t + "+" + s[3]
    x += int(s[3])
  else:
    t = t + "-" + s[3]
    x -= int(s[3])
  if x == 7:
    print(t+"=7")
    exit()

Submission status: Accepted

Solution code:
a,b,c,d=input()
s='+-'
for p in s:
 for q in s:
  for r in s:
   f=a+p+b+q+c+r+d
   if eval(f)==7:print(f+'=7');exit()

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input())
if a+b-c+d == 7:
        print('%d+%d-%d+%d=7' %(a,b,c,d))
        exit()
elif a+b-c-d == 7:
        print('%d+%d-%d-%d=7' %(a,b,c,d))
        exit()
elif a-b-c+d == 7:
        print('%d-%d-%d+%d=7' %(a,b,c,d))
        exit()
elif a-b-c-d == 7:
        print('%d-%d-%d-%d=7' %(a,b,c,d))
        exit()
elif a+b+c+d ==7:
        print('%d+%d+%d+%d=7' %(a,b,c,d))
        exit()
elif a+b+c-d ==7:
        print('%d+%d+%d-%d=7' %(a,b,c,d))
        exit()
elif a-b+c+d ==7:
        print('%d-%d+%d+%d=7' %(a,b,c,d))
        exit()
elif a-b+c-d ==7:
        print('%d-%d+%d-%d=7' %(a,b,c,d))
        exit()

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
for i in range(2 ** 3):
    a = list([str(n[0]), '-', str(n[1]), '-', str(n[2]), '-', str(n[3])])
    total = n[0]
    for j in range(3):
        if ((i >> j) & 1):
            a[int(2*j)+1] = '+'
            total = total + n[j+1]
        else:
            total = total - n[j+1]
    if total == 7:
        a.append('=7')
        print(''.join(a))
        exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!




def insert_str(target, i, char):
    return target[:i] + char + target[i:]

def calc(target, i):
    global ans
    
    if ans != "":
        return
    
    if i == 7:
        if eval(target) == 7:
            ans = target+"=7"
            return ans
        return
    calc(insert_str(target, i, "+"), i+2)
    calc(insert_str(target, i, "-"), i+2)
        
S = input()
N = len(S)
ans = ""
calc(S, 1)


print(ans)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(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))
elif a - b - c - d == 7:
    print("{}-{}-{}-{}=7".format(a, b, c, d))

Submission status: Accepted

Solution code:
m = input()
m = list(m)
m = list(map(int,m))
for i in range(2**3):
    n = m[0]
    x = i
    t = []
    for _ in range(3):
        if x % 2 != 0:
            n += m[_+1]
            t.append('+')
        else:
            n -= m[_+1]
            t.append('-')
        x = x // 2
    if n == 7:
        l = [m[0],t[0],m[1],t[1],m[2],t[2],m[3],'=',7]
        l = list(map(str,l))
        print(''.join(l))
        break

Submission status: Accepted

Solution code:
s = input()

def dfs(i,f,sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    
    else:
        dfs(i+1,f + "+" + s[i+1],sum + int(s[i+1]))
        dfs(i+1,f + "-" + s[i+1],sum - int(s[i+1]))

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input())
tfs = []
rt = str(A)
for bt in (True, False):
  for ct in (True, False):
    for dt in (True, False):
      tfs.append([bt,ct,dt])
for bt,ct,dt in tfs:
  tmp=7-A
  tmp = tmp-B if bt else tmp+B
  tmp = tmp-C if ct else tmp+C
  tmp = tmp-D if dt else tmp+D
  if tmp == 0:
    rt+="+" if bt else "-"
    rt+=str(B)
    rt+="+" if ct else "-"
    rt+=str(C)
    rt+="+" if dt else "-"
    rt+=str(D)
    rt+="=7"
    break

print(rt)

Submission status: Accepted

Solution code:
data=list(input())
if eval(data[0]+"+"+data[1]+"+"+data[2]+"+"+data[3])==7:
    print(data[0]+"+"+data[1]+"+"+data[2]+"+"+data[3]+"=7")
elif eval(data[0]+"+"+data[1]+"+"+data[2]+"-"+data[3])==7:
    print(data[0]+"+"+data[1]+"+"+data[2]+"-"+data[3]+"=7")
elif eval(data[0]+"+"+data[1]+"-"+data[2]+"-"+data[3])==7:
    print(data[0]+"+"+data[1]+"-"+data[2]+"-"+data[3]+"=7")
elif eval(data[0]+"+"+data[1]+"-"+data[2]+"+"+data[3])==7:
    print(data[0]+"+"+data[1]+"-"+data[2]+"+"+data[3]+"=7")
elif eval(data[0]+"-"+data[1]+"+"+data[2]+"+"+data[3])==7:
    print(data[0]+"-"+data[1]+"+"+data[2]+"+"+data[3]+"=7")
elif eval(data[0]+"-"+data[1]+"+"+data[2]+"-"+data[3])==7:
    print(data[0]+"-"+data[1]+"+"+data[2]+"-"+data[3]+"=7")
elif eval(data[0]+"-"+data[1]+"-"+data[2]+"-"+data[3])==7:
    print(data[0]+"-"+data[1]+"-"+data[2]+"-"+data[3]+"=7")
elif eval(data[0]+"-"+data[1]+"-"+data[2]+"+"+data[3])==7:
    print(data[0]+"-"+data[1]+"-"+data[2]+"+"+data[3]+"=7")
else:
    pass

Submission status: Accepted

Solution code:
abcd = input()

for i in range(1 << 3):
    res = int(abcd[0])
    op = abcd[0]
    for k in range(3):
        if i >> k & 1:
            res += int(abcd[k + 1])
            op += "+" + abcd[k + 1]
        else:
            res -= int(abcd[k + 1])
            op += "-" + abcd[k + 1]
    if res == 7:
        op += "=7"
        print(op)
        break

Submission status: Accepted

Solution code:
import sys
s = input()
for i in range(8):
    siki = s[0]
    tmp = int(s[0])
    for j in range(3):
        if i&(1<<j):
            siki = siki+'+'+s[j+1]
            tmp+=int(s[j+1])
        else:
            siki = siki + '-' + s[j+1]
            tmp-=int(s[j+1])
    if tmp==7:
        print(siki,"=7",sep="")
        exit()

Submission status: Accepted

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

for mask in range(2**n):
    total = L[0]
    s = str(L[0])
    for i in range(1, n):
        num = L[i]
        # maskのi番目にフラグが立っているかどうか
        if mask & (1 << i):
            total += num
            s += '+' + str(num)
        else:
            total -= num
            s += '-' + str(num)
    if total == 7:
        print(s+'=7')
        exit()

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')
        exit()

Submission status: Accepted

Solution code:
a = input()

for x in range(1<<3):
  s = a[0]

  for i in range(3):
    if x & (1<<i):
      s += '+'
    else:
      s += '-'
    s += a[i+1]

  if eval(s) == 7:
    print(s + '=7')
    exit()

Submission status: Accepted

Solution code:
S= input()
List=list(S)
mid=int(List[0])
opList = ["+"]*3
res="a"
# 010 なら2番目のみ派閥 
for bits in range(2**3): 
  for j in range(3):
    if((bits>>j) & 1):
      opList[j] = "+"
      mid = mid + int(List[j+1])
    else:
      opList[j] = "-"
      mid = mid - int(List[j+1])
  if mid == 7:
    res = List[0]+opList[0]+List[1]+opList[1]+List[2]+opList[2]+List[3]+"=7"
    break
  else:
    mid = int(List[0])
    opList = ["+"]*3
print(res)

Submission status: Accepted

Solution code:
S = input()
A, B, C, D = [int(s) for s in S]
op_l = ["+", "-"]

ex = ""
for op_1 in op_l:
    for op_2 in op_l:
        for op_3 in op_l:
            ans = A + B if op_1 == "+" else A - B
            ans = ans + C if op_2 == "+" else ans - C
            ans = ans + D if op_3 == "+" else ans - D
            if ans == 7:
                ex = str(A) + op_1 + str(B) + op_2 + str(C) + op_3 \
                     + str(D) + "=7"

print(ex)

Submission status: Accepted

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

for i in range(1<<(l-1)):
  Q=[]
  ans=int(S[0])
  for j in range(l-1):
    if (i>>j)&1:
      Q.append('+')
    else:
      Q.append('-')
  for k in range(l-1):
    if Q[k]=='+':
      ans+=int(S[k+1])
    else:
      ans-=int(S[k+1])
  if ans==7:
    ret=str(S[0])
    for k in range(l-1):
      ret+=Q[k]
      ret+=S[k+1]
    ret+='=7'
    print(ret)
    exit()

Submission status: Accepted

Solution code:
def solve():
    a, b, c, d = map(int, list(input()))
    op = ["+", "-"]
    ans = ""
    for op1 in range(2):
        for op2 in range(2):
            for op3 in range(2):
                s = "a"+op[op1]+"b"+op[op2]+"c"+op[op3]+"d"
                if eval(s) == 7:
                    return str(a)+op[op1]+str(b)+op[op2]+str(c)+op[op3]+str(d)+"=7"


print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    abcd = list( map( int , list( input() ) ) )

    for i in range( 2 ** 3 ):
        ans = str( abcd[0] )
        sum = abcd[0]
        x = i

        for j in range( 1,4 ):
                
            y = x % 2
            if y:
                sum += abcd[ j ]
                ans += '+'
            else:
                sum -= abcd[ j ]
                ans += '-'
            
            ans += str( abcd[ j ] )

            x = x // 2
        if sum == 7:
            ans += '=7'
            break
    print(ans)





main()

Submission status: Accepted

Solution code:
n=input()
l=len(n)-1
s=[n[0]]
for i in range(2**l):
    x=['-']*l
    for j in range(l):
          if ((i >> j) & 1):
              x[l - 1 - j]='+'
    for i in range(l):
        s.append(x[i])
        s.append(n[i+1])
    if eval(''.join(s))==7:
        s+='=7'
        print(''.join(s))
        exit()
    s=[n[0]]

Submission status: Accepted

Solution code:
import itertools

s = input()
op = ["+","-"]
for ops in itertools.product(op, repeat=3):
  result = int(s[0]) 
  for i in range(len(ops)):
    if ops[i] == "+":
      result += int(s[i+1]) 
    else :
      result -= int(s[i+1]) 
  if result == 7:
    print(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3]+"="+str(result))
    break

Submission status: Accepted

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

for i in [True, False]:
    for j in [True, False]:
        for k in [True, False]:
            if i:
                ans = a[0] + a[1]
            else:
                ans = a[0] - a[1]
            if j:
                ans += a[2]
            else:
                ans -= a[2]
            if k:
                ans += a[3]
            else:
                ans -= a[3]
            if ans == 7:
                ans = str(a[0])
                if i:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(a[1])
                if j:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(a[2])
                if k:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(a[3]) + '=7'
                print(ans)
                exit()

Submission status: Accepted

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

ss = []

def numToString(s):
    if s >= 0:
        s = '+' + str(s)
    else:
        s = str(s)
    return s

for i in range(2):
    if sum(s) == 7:
        ss += str(s[0])
        ss += list(map(numToString, s[1:4]))
        ss = ''.join(ss)
        print(ss + '=7')
        exit()

    for j in range(2):
        if sum(s) == 7:
            ss += str(s[0])
            ss += list(map(numToString, s[1:4]))
            ss = ''.join(ss)
            print(ss + '=7')
            exit()

        for k in range(2):
            if sum(s) == 7:
                ss += str(s[0])
                ss += list(map(numToString, s[1:4]))
                ss = ''.join(ss)
                print(ss + '=7')
                exit()

            s[3] *= -1
        s[2] *= -1
    s[1] *= -1

Submission status: Accepted

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

for i in range(2**n):
  res=int(a[0])
  ans=[a[0]]
  for j in range(1,n):
    if i&(1<<j):
      ans.append('+')
      ans.append(a[j])
      res+=int(a[j])
    else:
      ans.append('-')
      ans.append(a[j])
      res-=int(a[j])
  if res==7:
    print(*ans,'=7',sep='')
    exit()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    abcd = list(map(int,list(S())))
    bits = itertools.product([0,1],repeat=3)

    for bit in bits:
        cnt = abcd[0]
        for i,op in zip(abcd[1:],bit):
            if op == 0:
                cnt += i
            else:
                cnt -= i
        if cnt == 7:
            ans = str(abcd[0])
            for i,op in zip(abcd[1:],bit):
                ans += "+" if op == 0 else "-"
                ans += str(i)
            break
    ans += "=7"
    print(ans)
main()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

for i in range(2**3):
  argo = ["-","-","-"]
  
  for j in range(3):
    if i>>j & 1:
      argo[3-1-j] = "+"
  #print(argo)
  
  if eval(str(A)+argo[0]+str(B)+argo[1]+str(C)+argo[2]+str(D)) == 7:
    print(str(A)+argo[0]+str(B)+argo[1]+str(C)+argo[2]+str(D)+"=7")
    break

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
for i in range(1 << n):
    p_or_m = ['-'] * n
    for j in range(n):
        if i >> j & 1:
            p_or_m[n-j-1] = '+'
    
    formula = ''
    for k in range(n):
        formula += s[k] + p_or_m[k]
    formula += s[3]
    if  eval(formula) == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

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

for i in range(2**(l-1)):
    ans = 0
    a = s[0]
    for j in range(l-1):
        if i >> j & 1 == 0:
            a += '+' + s[j+1]
        elif i >> j & 1 == 1:
            a += '-' + s[j+1]
    ans = eval(a)
    if ans == 7:
        print(a + '=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import zip_longest

s = list(input())

for i in range(2**3) :
    lis = []
    c = ""
    for j in range(3) :
        if (i >> j) & 1 :
            lis.append("+")
        else:
            lis.append("-")
        
    for a, b in zip_longest(s, lis, fillvalue = "") :
        c += a + b
    
    if eval(c) == 7 :
        print(f"{c}=7")
        break

Submission status: Accepted

Solution code:
def main():
    import sys
    a = input()
    ans =0
    for i in range(2**3):
        t = a[0]
        for j in range(3):
            if i & (1 <<j):
                t = t +'+'
            else:
                t = t +'-'
            t = t +a[j+1]
        ans =eval(t)
        if ans == 7:
            print(t+'=7')
            sys.exit()
if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
import re

def dfs(i, formula_str):
    if i == 4:
        res = int(formula_str[0])
        for j in range(2, 7, 2):
            if formula_str[j-1] == "+":
                res += int(formula_str[j])
            else:
                res -= int(formula_str[j])
        if res == 7:
            return True, formula_str
        return False, formula_str
    else:
        f_1, formula_str_1 = dfs(i+1, formula_str + "+" + s[i])
        f_2, formula_str_2 = dfs(i+1, formula_str + "-" + s[i])
        if f_1:
            return True, formula_str_1
        elif f_2:
            return True, formula_str_2
        else:
            return False, None

s = input()
f, ans = dfs(1, s[0])
print(ans + "=7")

Submission status: Accepted

Solution code:
S = [a for a in input()]
N = [int(a) for a in S]
M = [N[0]] + [-N[i] for i in range(1,4)]

S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]
    
    if sum(N) == 7:
        
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()
    else: N[i] = -N[i]

for i in range(1, 4):
    S[1], S[3], S[5] = '-', '-', '-'
    
    M[i] = -M[i]
    
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()
    else:
      M[i] = -M[i]

Submission status: Accepted

Solution code:
from itertools import permutations
a = list(map(int, input()))

op = ['+', '+', '+', '-', '-', '-']
for ops in permutations(op, 3):
    now = a[0]
    for i in range(3):
        if ops[i] == '+':
            now += a[i+1]
        else:
            now -= a[i+1]
    if now == 7:
        print("{}{}{}{}{}{}{}=7".format(
            a[0], ops[0], a[1], ops[1], a[2], ops[2], a[3]))
        exit()

Submission status: Accepted

Solution code:
abcd=input()

res=''
for i in range(2**3):
    B=format(i,'b').zfill(3)
    sum_=int(abcd[0])
    res=abcd[0]
    j=1
    for k in range(3):
        if B[k]=='1':
            sum_+=int(abcd[j])
            res+='+'
        else:
            sum_-=int(abcd[j])
            res+='-'
        res+=abcd[j]
        j+=1
    if sum_==7:
        break

print('{}=7'.format(res))

Submission status: Accepted

Solution code:
lsnum = list(input())
lsnum1 = [int(i) for i in lsnum]
ls = ['+','-']
for i in range(2 ** 3):
    ans = lsnum1[0]
    for j in range(3):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
           ans += lsnum1[j+1]
        else:
            ans -= lsnum1[j+1]
    if ans == 7:
        bit = i
        break
ans2 = lsnum[0]
for i in range(3):
    if ((bit >> i) & 1):
        ans2 += '+'+lsnum[i+1]
    else:
        ans2 += '-'+lsnum[i+1]
print(ans2+'=7')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
numbers=[]
[numbers.append(int(s[i])) for i in range(4)]
for i in range(2**3):
  opes=[]
  count=numbers[0]
  for j in range(3):
    if (i>>j)&1:
      opes.append("+")
      count+=numbers[j+1]
    else:
      opes.append("-")
      count-=numbers[j+1]
  if count==7:
    print(numbers[0],end="")
    for k in range(3):
      print(opes[k],end="")
      print(numbers[k+1],end="")
    print("=",end="")
    print(count)
    exit()

Submission status: Accepted

Solution code:
S = list(input())
total=int(S[0])
i = 0
j = 0
k = 0
while True:
    if i == 0:
        total += int(S[1])
    else:
        total -= int(S[1])
    if j == 0:
        total += int(S[2])
    else:
        total -= int(S[2])
    if k == 0:
        total += int(S[3])
    else:
        total -= int(S[3])

    if total == 7:
        break
    else:
        if k == 0:
            k = 1
        else:
            k = 0
            if j == 0:
                j = 1
            else:
                j = 0
                i = 1
    total = int(S[0])
if i == 0:
    op1 = '+'
else:
    op1 = '-'
if j == 0:
    op2 = '+'
else:
    op2 = '-'
if k == 0:
    op3 = '+'
else:
    op3 = '-'


print(S[0]+op1+S[1]+op2+S[2]+op3+S[3]+'=7')