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:
s = input()

case = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i ==0:
                a = '+'
            else:
                a = '-'
            if j ==0:
                b = '+'
            else:
                b = '-'
            if k ==0:
                c = '+'
            else:
                c = '-'
            case.append('%s%s%s' % (a,b,c))

for case_i in case:
    print
    if 7 == eval('%s%s%s%s%s%s%s' % (s[0],case_i[0],s[1],case_i[1],s[2],case_i[2],s[3])):
        break

print('%s%s%s%s%s%s%s=7' % (s[0],case_i[0],s[1],case_i[1],s[2],case_i[2],s[3]))

Submission status: Accepted

Solution code:
S = input()

import sys
N = 3
for i in range(2**N):
    L = ["-", "-", "-"]
    ZZ = []
    for j in range(N):
        if ((i>>j) & 1):
            L[j] = "+"
            ZZ = [S[0], L[0], S[1], L[1], S[2], L[2], S[3]]
            if eval("".join(ZZ)) == 7:
                print("".join(ZZ) + "=7")
                sys.exit()

Submission status: Accepted

Solution code:
S = input()

n = len(S) -1 

for i in range(2**n):
    loc = []
    S2 = []
    for j in range(n):
        if (i>>j) & 1:
            loc.append('+')
        else:
            loc.append('-')
    loc.reverse()
    
    for k in range(n):
        S2.append(S[k])
        S2.append(loc[k])
    S2.append(S[-1])
    St = ''.join(S2)
    if eval(St) == 7:
        print(St+'=7')
        break

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])
ls = ["+","-"]
ans = a+b+c+d
if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a+b+c-d
if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
    sys.exit()
ans = a+b-c+d
if ans == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a-b+c+d
if ans == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a-b-c+d
if ans == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a+b-c-d
if ans == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    sys.exit()
ans = a-b+c-d
if ans == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
    sys.exit()
ans = a-b-c-d
if ans == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    sys.exit()

Submission status: Accepted

Solution code:
I = input()
A = I[0:1]
B = I[1:2]
C = I[2:3]
D = I[3:4]

op_dict = {}
for i in range(2**3):
    # [op1, op2, op3]
    if ((i >> 0) & 1):
        op3 = "+"
    else:
        op3 = "-"
    
    if ((i >> 1) & 1):
        op2 = "+"
    else:
        op2 = "-"
        
    if ((i >> 2) & 1):
        op1 = "+"
    else:
        op1 = "-"
    op_dict[i] = [op1, op2, op3]

for k in op_dict:
    op1 = op_dict[k][0]
    op2 = op_dict[k][1]
    op3 = op_dict[k][2]
    siki_str = A + op1 + B + op2 + C + op3 + D
    
    if eval(siki_str) == 7:
        print('{}={}'.format(siki_str, eval(siki_str)))
        break;

Submission status: Accepted

Solution code:
a = input()
input_list = []
for k in a:
    input_list.append(int(k))
n=3
fomul_list = []
for i in range(2 ** n):
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            fomul = fomul + "-" + str(input_list[j+1])
    if eval(fomul) == 7:
        print(fomul + "=7")
        exit()

Submission status: Accepted

Solution code:
a = input()
input_list = []
for k in a:
    input_list.append(int(k))
n=3
bag = []
fomul_list = []
for i in range(2 ** n):
    sum = input_list[0]
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            sum += input_list[j+1]
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            sum -= input_list[j+1]
            fomul = fomul + "-" + str(input_list[j+1])
    bag.append(sum)
    fomul_list.append(fomul)
print(fomul_list[bag.index(7)] + "=7")

Submission status: Accepted

Solution code:
S = input()

op = ["+","-"]

for a in op:
  for b in op:
    for c in op:
      shiki = S[0]+a+S[1]+b+S[2]+c+S[3]
      if eval(shiki)==7:
        print(shiki+"=7")
        exit()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
for i in range(2**(n-1)):
    sum=int(s[0])
    op = []
    for j in range(n-1):
      if ((i>>j)&1):
          sum+=int(s[j+1])
          op.append('+')
      else:
          sum-=int(s[j+1])
          op.append('-')
    if sum == 7:
        ans = s[0]
        for i in range(n-1):
            ans += op[i]
            ans += s[i+1]
        ans += '=7'
        print(ans)
        break

Submission status: Accepted

Solution code:
#079C Train Ticket
import sys
S = list(map(int, sys.stdin.readline().strip()))
L=[]
def saiki(i, score, ans):
    if i+1==4:
        if score ==7:
            ans+='=7'
            L.append(ans)
    else:
        saiki(i+1, score+S[i+1], ans+'+'+str(S[i+1]))
        saiki(i+1, score-S[i+1], ans+'-'+str(S[i+1]))


saiki(0, S[0], str(S[0]))
    
print(L[0])

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase

#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True

s=input()
f=list(map(int,list(s)))
show(s,f)

for i in range(2**3):
    t=s[0]
    for j in range(3):
        if i>>j&1:
            t+='+'+s[j+1]
        else:
            t+='-'+s[j+1]
    show(eval(t),t)
    if eval(t)==7:
        print(t+'=7')
        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 sum([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:
abcd=list(input())
abcd=list(map(int,abcd))
for i in range(2**3):
  ret=abcd[0]
  for j in range(3):
    if (i>>j)%2==1:
      ret-=abcd[j+1]
    else:
      ret+=abcd[j+1]
  if ret==7:
    ans=[str(abcd[0])]
    for j in range(3):
      if (i>>j)%2==1:
        ans.append("-")
      else:
        ans.append("+")
      ans.append(str(abcd[j+1]))
    ans.append("=")
    ans.append("7")
    print("".join(ans))
    exit(0)

Submission status: Accepted

Solution code:
n=[int(i) for i in list(input())]
op=[1,-1]
ans=[]
for op1 in op:
	for op2 in op:
		for op3 in op:
			if n[0]+op1*n[1]+op2*n[2]+op3*n[3]==7:
				ans=[op1,op2,op3]
out=''
for i in range(3):
	out+=str(n[i])
	out+='+' if ans[i]==1 else '-'
print(out+str(n[3])+'=7')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = list(input())

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

Submission status: Accepted

Solution code:
N = list(map(str,input()))
n = 3

for i in range(8):
    PlusMinus = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            PlusMinus[n - j - 1] = "+"
    if eval(N[0] + PlusMinus[0] + N[1] + PlusMinus[1] + N[2] + PlusMinus[2] + N[3]) == 7:
        print(N[0] + PlusMinus[0] + N[1] + PlusMinus[1] + N[2] + PlusMinus[2] + N[3] + "=7")
        break

Submission status: Accepted

Solution code:
check = 7
l = list(input())
n = len(l)-1

for i in range(2**n):
    v = ['+']*n
    for j in range(n):
        if (i >> j) & 1 == 1:
            v[j] = '-'
    
    working = l[0]
    for k in range(n):
        if v[k] == '+':
            working += ('+'+str(l[k+1]))
        else:
            working += ('-'+str(l[k+1]))
    ans = eval(working)
    if ans == check:
        print(working+'=7')
        exit()

Submission status: Accepted

Solution code:
import sys
num = [int(x) for x in input()]
sign = ["-","+"]
ans = str(num[0])
for x in range(2 ** (len(num)-1)):
  sum = num[0]
  for i in range(len(num) - 1):
    if ((x >> (2-i)) & 1) == 1:
      sum += num[i+1]
    else:
      sum -= num[i+1]
  if sum == 7:
    for i in range(len(num) - 1):
      ans = "{}{}{}".format(ans,sign[(x >> (2 - i)) & 1],num[i+1])
    print(ans+"=7")
    sys.exit()

Submission status: Accepted

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

for i in range(len(num) ** 2):
  op = []
  for j in range(len(num)):
    if (i >> j) & 1:
      op.append("+")
    else:
      op.append("-")
  sum = num[0]
  for k in range(len(num)-1):
    if op[k] == "+":
      sum += num[k+1]
    elif op[k] == "-":
      sum -= num[k+1]
  if sum == 7:
    print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3]))
    break

Submission status: Accepted

Solution code:
def func(i,x,op):
    #ベースケース
    if i == 4:
        if x == 7: return op
        else: return ""

    #足す場合
    opP = func(i+1, x + int(S[i]),op+"+")
    if opP != "": return opP

    #引く場合
    opM = func(i+1, x - int(S[i]),op+"-")
    if opM != "": return opM

    return ""

S = input()
#S[0]は必ず+扱いなのでi = 1, x = int(S[0])からスタートする
op = func(1,int(S[0]),"")
if len(op) == 3:
    print(S[0]+op[0]+S[1]+op[1]+S[2]+op[2]+S[3]+"=7")

Submission status: Accepted

Solution code:
n=list(input())

for i in range(8):
    v=['+']*3
    for j in range(3):
        if (i>>j) & 1 ==1:
            v[j]='-'

    w=n[0]
    for k in range(3):
        w+=(v[k]+n[k+1])


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

Submission status: Accepted

Solution code:
def dfs(formula, index, sum_number):
    if index + 1 == max_index:
        if sum_number == 7:
            print(formula + "=7")
            exit()

    else:
        dfs(formula + "+" + S[index + 1], index + 1, sum_number + int(S[index + 1]))
        dfs(formula + "-" + S[index + 1], index + 1, sum_number - int(S[index + 1]))


S = input()
max_index = len(S)
print(dfs(S[0], 0, int(S[0])))

Submission status: Accepted

Solution code:
import itertools

S = input()

for op1, op2, op3 in itertools.product('+-', repeat=3):
    if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:
        print(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
for i in range(2 ** 3):
    formula = s[0]
    for j in range(3):
        if (i >> j) & 1:
            formula += "+"
        else:
            formula += "-"
        formula += s[j + 1]
    if eval(formula) == 7:
        print(formula + "=7")
        exit()

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    abcd = tuple(map(int, args[0]))
    ret = str(abcd[0])
    for p in range(2**3):
        tmp = abcd[0]
        for i in range(3):
            if p >> i & 1:
                tmp += abcd[i+1]
            else:
                tmp -= abcd[i+1]
        if tmp == 7:
            op = '{:03b}'.format(p).replace('0', '-').replace('1', '+')[::-1]
            for i in range(3):
                ret += '{}{}'.format(op[i], abcd[i+1])
            ret += '=7'
            break
    return ret


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
S = input()
N = 3


for x in range(1<<N):
    ans = S[0]
    sum = int(S[0])
    for i in range(N):
        if x & (1 << i):
            ans += "+" + S[i+1]
            sum += int(S[i+1])
        else:
            ans += "-" + S[i+1]
            sum -= int(S[i+1])
    if sum == 7:
        break

print(ans + "=7")

Submission status: Accepted

Solution code:
import math

def dig(x,d):
  return (x%(10**(d+1)))//(10**d)

def main():
  N=int(input())
  D=3#int(math.log10(N))
  ans=0
  s=['']*D
  for bits in range(2*N):
    ans=dig(N,D)
    for i in range(1,D+1):
      if (bits>>(D-i))&1:
        ans+=dig(N,D-i)
        s[i-1]='+'
      else:
        ans-=dig(N,D-i)
        s[i-1]='-'
    if ans==7:
      print(dig(N,3),end="")
      for i in range(3):
        print(s[i],end="")
        print(dig(N,2-i),end="")
      print('=7')
      return
main()

Submission status: Accepted

Solution code:
x = ['+++', '++-', '+-+', '+--', '-++', '-+-', '--+', '---']
a = input()
for i in range(8):
    ans = a[0] + x[i][0] + a[1] + x[i][1] + a[2] + x[i][2] + a[3]
    if eval(ans) == 7:
        print(ans + '=7')
        break

Submission status: Accepted

Solution code:
a = list(input())
for i in range(8):
    b = []
    for j in range(4):
        b.append(a[j])
        if j == 3:
            pass
        else:
            if((i>>j)&1):
                b.append('+')
            else:
                b.append('-')
    c = ''.join(b)
    if eval(c) == 7:
        break
    else:
        pass
print(c+'=7')

Submission status: Accepted

Solution code:
A=input()
for i in range(8):
  f=A[0]
  for j in range(3):
    f+=("-+")[(i>>j)&1]+A[j+1]
  if eval(f)==7:
    print(f+"=7")
    break

Submission status: Accepted

Solution code:
A=input()
for i in range(8):
  f=A[0]
  for j in range(3):
    f+=("-","+")[(i>>j)&1]+A[j+1]
  if eval(f)==7:
    print(f+"=7")
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def calc(x,y,op):
    if op=="+":
        return x+y
    else:
        return x-y

if __name__ == '__main__':
    ABCD=input()
    A=int(ABCD[0])
    B=int(ABCD[1])
    C=int(ABCD[2])
    D=int(ABCD[3])
    operators=["+","-"]
    ans=[A,B,C,D,"=7"]
    import itertools

    for ops in itertools.product(operators,repeat=3):
        temp=calc(A,B,ops[0])
        temp=calc(temp,C,ops[1])
        temp=calc(temp,D,ops[2])
        if temp==7:
            print("{}{}{}{}{}{}{}=7".format(A,ops[0],B,ops[1],C,ops[2],D))
            break

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(str(input())))

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

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

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

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

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

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

Submission status: Accepted

Solution code:
import itertools
S=[int(s) for s in list(input())]
op=['+','-']
for (op1, op2, op3) in itertools.product([0,1],[0,1],[0,1]):
  x=S[0]+(1-2*op1)*S[1]+(1-2*op2)*S[2]+(1-2*op3)*S[3]
  if x==7:
    ls=[S[0],op[op1],S[1],op[op2],S[2],op[op3],S[3],'=7']
    print(*ls,sep="")
    break

Submission status: Accepted

Solution code:
N = [int(i) for i in str(input())]
output = list()
num_op = 3

for i in range(2**num_op):
  ans = '{}'.format(str(N[0]))
  res = N[0]
  for j in range(num_op):
    if (i>>j) & 1:
      res += N[j+1]
      ans += '+{}'.format(str(N[j+1]))
    else:
      res -= N[j+1]
      ans += '-{}'.format(str(N[j+1]))
  if res == 7:
    print(ans+'=7')
    exit()

Submission status: Accepted

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

if A + B + C + D == 7:
    print(A, end="+")
    print(B, end="+")
    print(C, end="+")
    print(D, end="=7")
elif A - B + C + D == 7:
    print(A, end="-")
    print(B, end="+")
    print(C, end="+")
    print(D, end="=7")
elif A + B - C + D == 7:
    print(A, end="+")
    print(B, end="-")
    print(C, end="+")
    print(D, end="=7")
elif A + B + C - D == 7:
    print(A, end="+")
    print(B, end="+")
    print(C, end="-")
    print(D, end="=7")
elif A - B - C + D == 7:
    print(A, end="-")
    print(B, end="-")
    print(C, end="+")
    print(D, end="=7")
elif A + B - C - D == 7:
    print(A, end="+")
    print(B, end="-")
    print(C, end="-")
    print(D, end="=7")
elif A - B + C - D == 7:
    print(A, end="-")
    print(B, end="+")
    print(C, end="-")
    print(D, end="=7")
elif A - B - C - D == 7:
    print(A, end="-")
    print(B, end="-")
    print(C, end="-")
    print(D, end="=7")

Submission status: Accepted

Solution code:
A = input()
n = len(A)
ans = ''
for i in range(2**(n-1)):
    tmp = ''
    for j in range(n-1):
        tmp += A[j]
        if i & (1 << j):
            tmp += '+'
        else:
            tmp += '-'
    tmp += A[-1]
    if eval(tmp) == 7:
        ans = tmp
        break

print(tmp + '=7')

Submission status: Accepted

Solution code:
a = list(input())


for x in range(8):
    s = ""
    sum = int(a[0])
    s += a[0]
    for i in range(3):
        if ( x & ( 1 << i)):
            sum += int(a[i+1])
            s += "+"
            s += a[i+1]
        else:
            sum -=int(a[i+1])
            s += "-"
            s += a[i+1]

    if sum == 7:
        print(s + "=7")
        break

Submission status: Accepted

Solution code:
s = input()
lst = [int(i) for i in s]
f1 = lambda x: '+' if x else '-'
f2 = lambda x: 1 if x else - 1
for i in range(16):
  tmp1 = [f1(i >> x & 1) for x in range(3)]
  tmp2 = [f2(i >> x & 1) * lst[x + 1] for x in range(3)]
  if lst[0] + sum(tmp2) == 7:
    print(''.join([s[i] + tmp1[i] for i in range(3)] + [s[3] + '=7']))
    break

Submission status: Accepted

Solution code:
s = input()
lst = [int(i) for i in s]
f1 = lambda x: '+' if x else '-'
f2 = lambda x: 1 if x else - 1
for i in range(16):
  tmp1 = [f1(i >> x & 1) for x in range(3)]
  tmp1.reverse()
  tmp2 = [f2(i >> x & 1) * lst[ - x - 1] for x in range(3)]
  if lst[0] + sum(tmp2) == 7:
    print(''.join([s[i] + tmp1[i] for i in range(3)] + [s[3] + '=7']))
    break

Submission status: Accepted

Solution code:
s = input()

a = 0
b = 0
c = 0

for i in range(2):
	for j in range(2):
		for k in range(2):
			#print(i,j,k)
			check = int(s[0])+int(s[1])*(2*i-1)+int(s[2])*(2*j-1)+int(s[3])*(2*k-1)
			if check ==7:
				a = (2*i-1)
				b = (2*j-1)
				c = (2*k-1)

#print(a,b,c)

if a == 1:
	stra = '+'
else:
	stra = '-'
	
if b == 1:
	strb = '+'
else:
	strb = '-'

if c == 1:
	strc = '+'
else:
	strc = '-'

print(s[0]+stra+s[1]+strb+s[2]+strc+s[3]+'=7')

Submission status: Accepted

Solution code:
import sys
a,b,c,d = map(int, list(input()))
x = [1,-1]
for i in x:
  for j in x:
    for k in x:
      if a+i*b+j*c+k*d==7:
        ans = str(a)
        ans += "+" if i==1 else "-"
        ans += str(b)
        ans += "+" if j==1 else "-"
        ans += str(c)
        ans += "+" if k==1 else "-"
        ans += str(d)
        ans += "=7"
        print(ans)
        sys.exit()

Submission status: Accepted

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

for i in range(2**n):
    op=['-']*n
    for j in range(n):
        if ((i>>j)&1):
            op[n-1-j]='+'

    formula=''
    for x,y in zip(s,op+['']):#sとopの長さをそろえている(多分
        formula+=(x+y)
    if eval(formula)==7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
n=input()

c=len(n)-1
for i in range(2**c):
      L=['-']*c
      for j in range(c):
            if ((i>>j)&1):#「>>」自体に二進数演算が含まれている
                  L[c-1-j]="+"#右詰めにする
      L+=['']
      f=""
      for a,b in zip(n,L):
            f+=a+b
      if eval(f)==7:
            print(f + '=7')
            break

Submission status: Accepted

Solution code:
inp = input()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])
o= ['-','+'] 
def cal(n,i,x,y):
	    if check(n,i):
	    	    return x+y
	    if not check(n,i):
	    	    return x-y

def check(i,j):
	return  (i>>j)%2
for i in range(8):
	    p = cal(i,0,a,b)
	    q = cal(i,1,p,c)
	    r = cal(i,2,q,d)
	    if r == 7:
	    	    s = str(o[check(i,0)])
	    	    t = str(o[check(i,1)])
	    	    u = str(o[check(i,2)])
	    	    print(str(a)+s+str(b)+t+str(c)+u+str(d)+'=7')
	    	    exit(0)
	 
print(-1)

Submission status: Accepted

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

for i in range(2**3):
    ans=[INT[0], L[0]]
    for j in range(3):
        if(i>>j)&1:
            ans[0]+=INT[j+1]
            ans[1]+='+'
            ans[1]+=L[j+1]
        else:
            ans[0]-=INT[j+1]
            ans[1]+='-'
            ans[1]+=L[j+1]
    if ans[0]==7:
        print(ans[1]+'=7')
        break

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(a, b, c, d):
    S = [a, b, c, d]
    for i in range(1<<3):
        ttl = a
        ans = "%s" % a
        for j in range(3):
            if i & (1 << j): # '+'
                ttl += S[j+1]
                ans += "+%s" % S[j+1]
            else:
                ttl -= S[j+1]
                ans += "-%s" % S[j+1]
        if ttl == 7:
            return ans+"=7"
        else:
            assert(True)


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    S = parsed_lines[1][0]
    return n, k, S


if not do_submit:
    a, b, c = input_parse("""
    3 1
    ABC
    """)
    print(sol(a, b, c))

    a, b, c = input_parse("""
    4 3
    CABA
    """)
    print(sol(a, b, c))

else:
    #a, b, c = list(map(int, input().split()))
    S = input()
    a = int(S[0])
    b = int(S[1])
    c = int(S[2])
    d = int(S[3])
    # S = input()
    # T = input()
    print(sol(a, b, c, d))
    # S = input().strip()
    # print(sol(S))

Submission status: Accepted

Solution code:
import sys

s = input()
n = 3

for i in range(2**(n)):
	op = ["-"]*3
	for j in range(n):
		if i & (1<<j):
			op[j] = "+"

	res = ""
	for a,b in zip(s,op+[""]):
		res += a+b
	if eval(res) == 7:
		print(res+'=7')
		sys.exit()

Submission status: Accepted

Solution code:
n =  input()
for i in range(2 ** 3):
    op = ["-"] * 3
    for j in range(3):
        if((i >> j) & 1):
            op[2 - j] = "+"

    fomula = ""
    for value, operator in zip(n, op + [""]):
        fomula += (value + operator)

    if eval(fomula) == 7:
        print(fomula + "=7")
        break

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 a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7");exit()
if a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7");exit()
if a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7");exit()
if a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7");exit()
if a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7");exit()
if a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7");exit()
if a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7");exit()
if a-b-c-d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7");exit()

Submission status: Accepted

Solution code:
import re

S = list(input())

for i in range(2**3):
    bits = [(i>>j)&1 for j in range(3)]
    bits.append("")

    expr = ""
    for b, s in zip(bits, S):
        expr += s
        if b == 0:
            expr += "+"
        elif b == 1:
            expr += "-"
    expr_sum = eval(expr)
    if expr_sum == 7:
        print(expr + "=7")
        break

Submission status: Accepted

Solution code:
S = list(input())
n = len(S)-1
for i in range(2**n):
    op = ['-']*n
    f = S.copy()
    for j in range(n):
        if ((i >> j) & 1):
            op[j] = '+'
    
    for j, k in zip(range(n), [1,3,5]):
        f.insert(k, op[j])
    f = ''.join(f)
    if eval(f) == 7:
        print(f + '=7')
        exit()

Submission status: Accepted

Solution code:
n=input()
a,b,c,d=int(n[0]),int(n[1]),int(n[2]),int(n[3])
l=0
for i in range(2):
    x=a
    if i==0:
        x+=b
    else:
        x-=b
    for j in range(2):
        if j==0:
            x+=c
        else:
            x-=c
        for k in range(2):
            if k==0:
                x+=d
            else:
                x-=d
            if x==7:
                l=1
                m=[i,j,k]
                break
            if k==0:
                x-=d
            else:
                x+=d
        if j==0:
            x-=c
        else:
            x+=c
    if i==0:
        x-=b
    else:
        x+=b

        if l==1:
            break
    if l==1:
        break

ans=""
ans+=str(a)
if m[0]==0:
    ans+="+"
else:
    ans+="-"
ans+=str(b)
if m[1]==0:
    ans+="+"
else:
    ans+="-"
ans+=str(c)
if m[2]==0:
    ans+="+"
else:
    ans+="-"
ans+=str(d)
ans+="=7"
print(ans)

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random


def main():
    # a,b,c,d = map(int, input().strip().split())
    l_abcd = list(map(int,input().strip()))
    eprint("l_abcd ",end=": ")
    eprint(l_abcd)
    for case in range(2 ** 3):     # 場合ループ # nは人とかモノとかの個数
        l_op_bin = list(map(int,(format(case,'b').zfill(3))))
        # eprint("l_op_bin ",end=": ")
        # eprint(l_op_bin)
        
        #flag=0
        sum_x=l_abcd[0]
        l_op=[]
        for index_location in range(3):      # 人とかモノとかループ
            if l_op_bin[index_location]==1:                   # その桁がyesだと仮定している場合
               sum_x += l_abcd[1+index_location]
               l_op.append("+")
            else:                                 # その桁がnoだと仮定している場合
               sum_x -= l_abcd[1+index_location]
               l_op.append("-")
        if sum_x==7:
            print(l_abcd[0], end="")
            print(l_op[0],end="")
            print(l_abcd[1], end="")    
            print(l_op[1],end="")
            print(l_abcd[2], end="")    
            print(l_op[2],end="")
            print(l_abcd[3], end="=7\n")
            return
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=a+op1+b+op2+c+op3+d
      if eval(ans)==7:
        print('{}=7'.format(ans))
        exit()
      else:
        pass

Submission status: Accepted

Solution code:
s=input()
n=3
for i in range(2**n):
    tmp=[]
    for k in range(n):
        tmp.append(s[k])
        if i>>k & 1:
            tmp.append("+")
        else:
            tmp.append("-")
    tmp.append(s[-1])
    if eval("".join(tmp))==7:
        print("".join(tmp)+"=7")
        exit()

Submission status: Accepted

Solution code:
l=list(input())
a,b,c,d=map(str,l)
x=0
y=0
z=0
for i in range(2**3):
    if (i>>0)&1:
        x="+"
    else:
        x="-"
    if (i>>1)&1:
        y="+"
    else:
        y="-"
    if (i>>2)&1:
        z="+"
    else:
        z="-"
    ans=a+x+b+y+c+z+d
    if eval(ans)==7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
from itertools import product

def main():
    s = input() 
    ans = ""
    for p in product(["+", "-"], repeat=3):
        res = ""
        for a,b in zip(s,p):
            res += a+b
        res += s[-1]
        if eval(res) == 7:
            ans = res
            break
    print(ans+"=7")


if __name__ == "__main__":
    main()