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

Solution (Python):

N=input()
lst=list(N)

if (int(lst[0])+int(lst[1])+int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'+'+lst[2]+'+'+lst[3]+'=7')

elif (int(lst[0])-int(lst[1])-int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'-'+lst[2]+'-'+lst[3]+'=7')

elif (int(lst[0])-int(lst[1])+int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'+'+lst[2]+'-'+lst[3]+'=7')

elif (int(lst[0])+int(lst[1])-int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'-'+lst[2]+'+'+lst[3]+'=7')


elif (int(lst[0])+int(lst[1])+int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'+'+lst[2]+'-'+lst[3]+'=7')

elif (int(lst[0])+int(lst[1])-int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'-'+lst[2]+'-'+lst[3]+'=7')

elif (int(lst[0])-int(lst[1])+int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'+'+lst[2]+'+'+lst[3]+'=7')

elif (int(lst[0])-int(lst[1])-int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'-'+lst[2]+'+'+lst[3]+'=7')

Solution (Python):
N = raw_input()
keys = ['+','-']
x = 0
check = True
ans = ''
for key1 in keys:
    if key1 == '+' and check:
        x1 = int(N[0]) + int(N[1])
    elif(key1 == '-' and check):
        x1 = int(N[0]) - int(N[1])
    for key2 in keys:
        if key2 == '+' and check:
            x2 = x1  + int(N[2])
        elif(key2 == '-' and check):
            x2 = x1  - int(N[2])
        
        
        for key3 in keys:
            if key3 == '+' and check:
                
                
                x3 = x2  + int(N[3])
                
                if (x3 == 7):
                    ans = N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False


            elif(key3 == '-' and check):

                x3 = x2  - int(N[3])

                if (x3 == 7):
                    ans =  N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False

            
print ans

Solution (Python):
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

num = int(raw_input())

p_dbg('num : ' + str(num))

array = []

dig = 4
while dig > 0:
    array.append((num % 10))
    num = num / 10
    dig = dig -1

array.reverse()
p_dbg('array : ' + str(array))

def ope_permutation(ope_array):
    ope1 = []
    ope2 = []
    ope3 = []
    ope1[:]=ope_array
    ope2[:]=ope_array
    ope3[:]=ope_array
    perm = []
    for o1 in ope1:
        for o2 in ope2:
            for o3 in ope3:
                perm.append([o1, o2, o3])

    return perm

ope_perm = ope_permutation(['+','-'])
p_dbg('ope_perm'+str(ope_perm))

for perm in ope_perm:
    sig = [1,1,1]
    if perm[0] == '-':
        sig[0] = -1
    else:
        sig[0] = 1
    if perm[1] == '-':
        sig[1] = -1
    else:
        sig[1] = 1
    if perm[2] == '-':
        sig[2] = -1
    else:
        sig[2] = 1
    if array[0] + sig[0]* array[1] + sig[1]* array[2] + sig[2]* array[3] == 7:
        print str(array[0]) + perm[0] + str(array[1]) + perm[1] + str(array[2]) + perm[2] + str(array[3])+'=7'
        break

Solution (Python):
S = input()
a=int(S[0])
b=int(S[1])
c=int(S[2])
d=int(S[3])
op1=[]
op2=[]
op3=[]
func=(('+',lambda x,y:x+y),('-',lambda x,y:x-y))
for f1 in func:
    op1.append((f1[1](a,b),f1[0]))
for o in op1:
    for f2 in func:
        op2.append((f2[1](o[0],c),o[1]+f2[0]))
for o in op2:
    for f3 in func:
        op3.append((f3[1](o[0],d),o[1]+f3[0]))
for o in op3:
    if o[0] == 7:
        print(str(a)+o[1][0]+str(b)+o[1][1]+str(c)+o[1][2]+str(d)+'=7')
        break

Solution (Python):

N = input()
N_list = list(map(int,N))
N_str = str(N)

if   (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Solution (Python):
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
a,b,c,d = s[0],s[1],s[2],s[3]

def calc(i,j,k):
    if i == 0:
        i = 1
    else:
        i = -1
    if j == 0:
        j = 1
    else:
        j = -1
    if k == 0:
        k = 1
    else:
        k = -1       
    return int(a) + int(b)*i + int(c)*j + int(d)*k,i,j,k

def pm(s):
    if s == 0:
        return "+"
    else:
        return "-"
    
for i in range(2):
    for j in range(2):
        for k in range(2):
            if calc(i,j,k)[0] == 7:
                print(a+pm(i)+b+pm(j)+c+pm(k)+d+"=7")
                exit()

Solution (Python):


import sys

x = str(raw_input())
x_list = list(x)
x_int = []

for i in range(len(x_list)):
    x_int.append(int(x_list[i]))

if x_int[0] + x_int[1] + x_int[2] + x_int[3] == 7:
    op = ['+', '+', '+']
elif x_int[0] + x_int[1] + x_int[2] - x_int[3] == 7:
    op = ['+', '+', '-']
elif x_int[0] + x_int[1] - x_int[2] + x_int[3] == 7:
    op = ['+', '-', '+']
elif x_int[0] + x_int[1] - x_int[2] - x_int[3] == 7:
    op = ['+', '-', '-']
elif x_int[0] - x_int[1] + x_int[2] + x_int[3] == 7:
    op = ['-', '+', '+']
elif x_int[0] - x_int[1] + x_int[2] - x_int[3] == 7:
    op = ['-', '+', '-']
elif x_int[0] - x_int[1] - x_int[2] + x_int[3] == 7:
    op = ['-', '-', '+']
elif x_int[0] - x_int[1] - x_int[2] - x_int[3] == 7:
    op = ['-', '-', '-']

sys.stdout.write(x_list[0])
sys.stdout.write(op[0])
sys.stdout.write(x_list[1])
sys.stdout.write(op[1])
sys.stdout.write(x_list[2])
sys.stdout.write(op[2])
sys.stdout.write(x_list[3])
sys.stdout.write('=7')

Solution (Python):

N = input()
N_list = list(map(int,N))
N_str = str(N)

if (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Solution (Python):

def solve(A,op):
    result=[0]*4
    result[0]=A[0]
    for i in range(2):
        if i==0:
            result[1]=result[0]+A[1]
            op[0]="+"
        else:
            result[1]=result[0]-A[1]
            op[0]="-"
        for j in range(2):
            if j==0:
                result[2] = result[1]+A[2]
                op[1]="+"
            else:
                result[2] = result[1]-A[2]
                op[1]="-"
            for k in range(2):
                if k==0:
                    result[3] = result[2]+A[3]
                    op[2]="+"
                else:
                    result[3] = result[2]-A[3]
                    op[2]="-"
                
                
                if result[3]==7:
                    print("{}{}{}{}{}{}{}=7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                    return

def main():
    A=[0]*4
    op=[""]*3
    A=list(map(int,input()))
    solve(A,op)

if __name__=="__main__":
    main()

Solution (Python):
def main():
    op = '+-'
    s = input()

    for x in op:
        for y in op:
            for z in op:
                t = s[0] + x + s[1] + y + s[2] + z + s[3]
                if eval(t) == 7:
                    return t + '=7'

if __name__ == '__main__':
    print(main())

Solution (Python):

N = input()
N_list = list(map(int,N))
N_str = str(N)

if (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3])==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Solution (Python):
sr = input()

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

def calc(one, two, three):
  if a + one*b + two*c + three*d == 7:
    return True
  else:
    return False
  
def change(num):
  if num == 1:
    return "+"
  else:
    return "-"
  
flag = False
for q in [1, -1]:
  for w in [1, -1]:
    for e in [1, -1]:
      if calc(q, w, e):
        r, t, y = change(q), change(w), change(e)
        print(str(a)+r+str(b)+t+str(c)+y+str(d)+"=7")
        flag = True
        break
    if flag:
      break
  if flag:
    break

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

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

Solution (Python):
n = input()
num = [int(n[0]), int(n[1]), int(n[2]), int(n[3])]
if sum(num) == 7:
    print(str(num[0]) + "+" + str(num[1]) + "+" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] + num[1] + num[2] - num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "+" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] + num[1] - num[2] + num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "-" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] + num[1] - num[2] - num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "-" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] - num[1] + num[2] + num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "+" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] - num[1] + num[2] - num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "+" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] - num[1] - num[2] + num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "-" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] - num[1] - num[2] - num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "-" + str(num[2]) + "-" + str(num[3]) + "=7")

Solution (Python):


def ans(x1, x2, x3, x4, state1, state2, state3):
    return int(eval("{}{}{}{}{}{}{}".format(x1,state1,x2,state2,x3,state3,x4)))

n = input()

x1 = int(n[0])
x2 = int(n[1])
x3 = int(n[2])
x4 = int(n[3])

state1 = "+"
state2 = "+"
state3 = "+"

x = 7

for n in range(8):
    if n == 0:
        k = "000"
    if n == 1:
        k = "001"
    if n == 2:
        k = "010"
    if n == 3:
        k = "011"
    if n == 4:
        k = "100"
    if n == 5:
        k = "101"
    if n == 6:
        k = "110"
    if n == 7:
        k = "111"
    
    if k[0] == "0":
        state1 = "+"
    else:
        state1 = "-"
    try:
        if k[1] == "0":
            state2 = "+"
        else:
            state2 = "-"
    except:
        state2 = "+"
    try:
        if k[2] == "0":
            state3 = "+"
        else:
            state3 = "-"
    except:
        state3 = "+"
    a = ans(x1, x2,x3,x4,state1,state2,state3)
    if a == 7:
        break
print("{}{}{}{}{}{}{}=7".format(x1,state1,x2,state2,x3,state3,x4))

Solution (Python):
r = input()
a = int(r[0])
b = int(r[1])
c = int(r[2])
d = int(r[3])
import sys

if a+b+c+d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"+"+r[2]+"+"+r[3]+"=7")
elif a+b+c-d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"+"+r[2]+"-"+r[3]+"=7")
elif a+b-c+d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"-"+r[2]+"+"+r[3]+"=7")
elif a+b-c-d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"-"+r[2]+"-"+r[3]+"=7")
elif a-b+c+d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"+"+r[2]+"+"+r[3]+"=7")
elif a-b+c-d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"+"+r[2]+"-"+r[3]+"=7")
elif a-b-c+d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"-"+r[2]+"+"+r[3]+"=7")
else:
  sys.stdout.write(r[0]+"-"+r[1]+"-"+r[2]+"-"+r[3]+"=7")

Solution (Python):


from sys import stdin

def eval(ds, ops):
  e = ds[0]
  for i in range(1, len(ds)):
    e = e + (ds[i] if ops[i - 1] == '+' else -ds[i])
  return e

def solve(ds):
  ops = ['+', '-']
  for op1 in ops:
    for op2 in ops:
      for op3 in ops:
        if eval(ds, [op1, op2, op3]) == 7:
          return str(ds[0])+op1+str(ds[1])+op2+str(ds[2])+op3+str(ds[3])+"=7"

ABCD = stdin.readline().strip()
ds = [int(ABCD[i]) for i in range(len(ABCD))]
print(solve(ds))

Solution (Python):

n = list(map(int,input()))

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

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

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

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

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

nums = list(map(int, list(input())))

cand = [(nums[0], [str(nums[0])])]

for num in nums[1:]:
    new_cand = []
    for s, signs in cand:
        new_cand.append((s + num, signs + ['+', str(num)]))
        new_cand.append((s - num, signs + ['-', str(num)]))
    cand = new_cand

for num, signs in cand:
    if num == 7:
        print(''.join(signs) + '=7')
        break

Solution (Python):


n = int(raw_input())
a = n/1000
b = n/100%10
c = n/10%10
d = n%10

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"

Solution (Python):
def my_cal(N1,N2,PM):
    if PM == "+":
        return N1+N2
    else:
        return N1-N2
    
if __name__ == '__main__':
    I = list(map(int,input()))
    ANS = []
    for ele1 in ["+","-"]:
         for ele2 in ["+","-"]:
                for ele3 in ["+","-"]:
                     if my_cal(my_cal(my_cal(I[0],I[1],ele1),I[2],ele2),I[3],ele3) == 7:
                            ANS.append(str(I[0])+ele1+str(I[1])+ele2+str(I[2])+ele3+str(I[3])+"=7")
    print(ANS[0])

Solution (Python):
if __name__=="__main__":
    n = input()
    s = list(n)
    a = int(s[0])
    b = int(s[1])
    c = int(s[2])
    d = int(s[3])

    if a+b+c+d==7:
        print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    elif a-b-c-d==7:
        print(s[0] + "-" + s[1] + "-" + s[2] + "-" + s[3] + "=7")
    elif a-b+c+d==7:
        print(s[0] + "-" + s[1] + "+" + s[2] + "+" + s[3] + "=7")
    elif a-b-c+d==7:
        print(s[0] + "-" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
    elif a+b-c-d==7:
        print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    elif a+b+c-d==7:
        print(s[0] + "+" + s[1] + "+" + s[2] + "-" + s[3] + "=7")
    elif a+b-c+d==7:
        print(s[0] + "+" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
    elif a-b+c-d==7:
        print(s[0] + "-" + s[1] + "+" + s[2] + "-" + s[3] + "=7")

Solution (Python):
input_str = input()
A = int(input_str[0])
B = int(input_str[1])
C = int(input_str[2])
D = int(input_str[3])

list = []
list.append(A + B + C + D)
list.append(A + B + C - D)
list.append(A + B - C + D)
list.append(A + B - C - D)
list.append(A - B + C + D)
list.append(A - B + C - D)
list.append(A - B - C + D)
list.append(A - B - C - D)

num = list.index(7)

if num <= 3:
    op1 = '+'
else:
    op1 = '-'

if num == 0 or num == 1 or num == 4 or num == 5:
    op2 = '+'
else:
    op2 = '-'

if num % 2 == 0:
    op3 = '+'
else:
    op3 = '-'

print('{}{}{}{}{}{}{}=7'.format(A,op1,B,op2,C,op3,D))

Solution (Python):



"""abc079_c"""

import sys
import pprint
import re

import copy
from itertools import tee

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    d = list(map(int, list(input())))

    sentinel = object()
    def solve(v, it, s):
        n = next(it, sentinel)
        if v == 7 and n == sentinel:
            print(s[1:]+'=7')
            sys.exit(0)
        if n == sentinel:
            return
        solve(v+n, copy.copy(it), s+'+'+n.__str__())
        solve(v-n, copy.copy(it), s+'-'+n.__str__())

    solve(0, iter(d), '')

if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
import sys

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

if a+b+c+d==7:
    print ("%d+%d+%d+%d=7" % (a,b,c,d))
elif a+b+c-d==7:
    print ("%d+%d+%d-%d=7" % (a,b,c,d))
elif a+b-c+d==7:
    print ("%d+%d-%d+%d=7" % (a,b,c,d))
elif a+b-c-d==7:
    print ("%d+%d-%d-%d=7" % (a,b,c,d))
elif a-b+c+d==7:
    print ("%d-%d+%d+%d=7" % (a,b,c,d))
elif a-b+c-d==7:
    print ("%d-%d+%d-%d=7" % (a,b,c,d))
elif a-b-c+d==7:
    print ("%d-%d-%d+%d=7" % (a,b,c,d))
elif a-b-c-d==7:
    print ("%d-%d-%d-%d=7" % (a,b,c,d))

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

ans_list = [[0 for _ in range(8)] for __ in range(3)]

ans_list[0][0] = a + b
ans_list[0][1] = a - b
for i in range(2):
    ans_list[1][i * 2] = ans_list[0][i] + c
    ans_list[1][i * 2 + 1] = ans_list[0][i] - c
for i in range(4):
    ans_list[2][i * 2] = ans_list[1][i] + d
    ans_list[2][i * 2 + 1] = ans_list[1][i] - d

for n in range(8):
    if ans_list[2][n] == 7:
        ans = ""
        ans += abcd[0]
        if n > 3:
            ans += "-"
        else:
            ans += "+"
        ans += abcd[1]
        if n == 0 or n == 1 or n == 4 or n == 5:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[2]
        if n % 2 == 0:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[3]
        ans += "=7"
        print(ans)
        break

Solution (Python):
inp = input()
a,b,c,d = [int(x) for x in list(inp)]

def add(a,b):
    return a+b
def sub(a,b):
    return a-b
lis = [0,0,0]
count = 0
while True:
    sum = 0
    if lis[0] == 0:
        sum = add(a,b)
    else:
        sum = sub(a,b)
    if lis[1] == 0:
        sum = add(sum,c)
    else:
        sum = sub(sum,c)
    if lis[2] == 0:
        sum = add(sum, d)
    else:
        sum = sub(sum, d)
    if sum == 7:
        break
    count += 1
    lis[0] = count % 2
    lis[1] = (count // 2) % 2
    lis[2] = (count// 4) % 2

if lis[0] == 0:
    x = '+'
else:
    x = '-'
if lis[1] == 0:
    y = '+'
else:
    y = '-'
if lis[2] == 0:
    z = '+'
else:
    z = '-'
print('{}{}{}{}{}{}{}=7'.format(a,x,b,y,c,z,d))

Solution (Python):


import itertools, sys

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

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

for p in itertools.product((1, -1), (1, -1), (1, -1)):
    n = a + p[0] * b + p[1] * c + p[2] * d
    if n == 7:
        print('%d%+d%+d%+d=7' % (a, p[0] * b, p[1] * c, p[2] * d))
        sys.exit(0)

Solution (Python):
from itertools import chain, combinations
import sys

def all_subsets(ss):
    return chain(*map(lambda x: combinations(ss, x), range(0, len(ss) + 1)))

array=raw_input()

for subset in all_subsets([0,1,2]):
    suma=sum(map(int,str(array)))
    signs=list("+++")

    for ind in subset:
        suma=suma-2*int(array[ind+1])
        signs[ind]='-'

    if suma == 7:
        print array[0],
        for i in range(0,3):
            sys.stdout.write(signs[i])
            sys.stdout.write(array[i+1])
        break

sys.stdout.write("=7")

Solution (Python):


A,B,C,D = (int(x) for x in input())
OP = ['-', '+']

op_list = []
for op1 in (True, False):
    for op2 in (True, False):
        for op3 in (True, False):
            op_list.append((op1,op2,op3))

for ops in op_list:
    ans = A
    for num, op in zip([B,C,D], ops):
        if(op):
            ans += num
        else:
            ans -= num
    if ans == 7:
        print("%d%s%d%s%d%s%d=7" % (A, OP[ops[0]], B, OP[ops[1]], C, OP[ops[2]], D))
        break

Solution (Python):
import numpy as np

C = list(map(int,input()))
op1 = np.array([1,-1,1,1])
op2 = np.array([1,1,-1,1])
op3 = np.array([1,1,1,-1])
C = np.array(C)

if(sum(C) == 7):
    print("{}+{}+{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1) == 7):
    print("{}-{}+{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op2) == 7):
    print("{}+{}-{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op3) == 7):
    print("{}+{}+{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op2) == 7):
    print("{}-{}-{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op3) == 7):
    print("{}-{}+{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op2*op3) == 7):
    print("{}-{}-{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op2*op3) == 7):
    print("{}+{}-{}-{}=7".format(C[0],C[1],C[2],C[3]))

Solution (Python):
n = input()

if (int(n[0]) + int(n[1]) + int(n[2]) + int(n[3]) == 7):
    print("{0}+{1}+{2}+{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) + int(n[1]) + int(n[2]) - int(n[3]) == 7):
    print("{0}+{1}+{2}-{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) + int(n[1]) - int(n[2]) + int(n[3]) == 7):
    print("{0}+{1}-{2}+{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) + int(n[1]) - int(n[2]) - int(n[3]) == 7):
    print("{0}+{1}-{2}-{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) - int(n[1]) + int(n[2]) + int(n[3]) == 7):
    print("{0}-{1}+{2}+{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) - int(n[1]) + int(n[2]) - int(n[3]) == 7):
    print("{0}-{1}+{2}-{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) - int(n[1]) - int(n[2]) + int(n[3]) == 7):
    print("{0}-{1}-{2}+{3}=7".format(n[0], n[1], n[2], n[3]))
elif (int(n[0]) - int(n[1]) - int(n[2]) - int(n[3]) == 7):
    print("{0}-{1}-{2}-{3}=7".format(n[0], n[1], n[2], n[3]))

Solution (Python):
abcd = str(input())

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

if a + b + c + d == 7:
    print("%s+%s+%s+%s=7" % (a, b, c, d))
elif a + b + c - d == 7:
    print("%s+%s+%s-%s=7" % (a, b, c, d))
elif a + b - c + d == 7:
    print("%s+%s-%s+%s=7" % (a, b, c, d))
elif a + b - c - d == 7:
    print("%s+%s-%s-%s=7" % (a, b, c, d))
elif a - b + c + d == 7:
    print("%s-%s+%s+%s=7" % (a, b, c, d))
elif a - b + c - d == 7:
    print("%s-%s+%s-%s=7" % (a, b, c, d))
elif a - b - c + d == 7:
    print("%s-%s-%s+%s=7" % (a, b, c, d))
elif a - b - c - d == 7:
    print("%s-%s-%s-%s=7" % (a, b, c, d))

Solution (Python):
a,b,c,d = [int(i) for i in input()]

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))
else:
    print("該当なし")

Solution (Python):
N = input()
a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])
x = d+7
y = -d+7
while True:
    if a+b+c == x:
        print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
        break
    if a+b+c == y:
        print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
        break
    if a-b+c == x:
        print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
        break
    if a-b+c == y:
        print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
        break
    if a+b-c == x:
        print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
        break
    if a+b-c == y:
        print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
        break
    if a-b-c == x:
        print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
        break
    if a-b-c == y:
        print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
        break

Solution (Python):
n = input()
q = n[0]
w = n[1]
e = n[2]
r = n[3]
a = int(q)
b = int(w)
c = int(e)
d = int(r)

if a + b + c + d == 7:
    print(q+"+"+w+"+"+e+"+"+r+"="+"7")
elif a + b + c - d == 7:
    print(q+"+"+w+"+"+e+"-"+r+"="+"7")
elif a + b - c - d == 7:
    print(q+"+"+w+"-"+e+"-"+r+"="+"7")
elif a - b - c - d == 7:
    print(q+"-"+w+"-"+e+"-"+r+"="+"7")
elif a - b + c - d == 7:
    print(q+"-"+w+"+"+e+"-"+r+"="+"7")
elif a - b - c + d == 7:
    print(q+"-"+w+"-"+e+"+"+r+"="+"7")
elif a + b - c + d == 7:
    print(q+"+"+w+"-"+e+"+"+r+"="+"7")
elif a - b + c + d == 7:
    print(q+"-"+w+"+"+e+"+"+r+"="+"7")

Solution (Python):
S = input()
L = []
for i in range(4): L.append(int(S[i]))


if L[0]+L[1]+L[2]+L[3] == 7:
    print(S[0] +'+'+ S[1] +'+'+ S[2] +'+'+ S[3] +'=7')
elif L[0]+L[1]+L[2]-L[3] == 7:
    print(S[0] +'+'+ S[1] +'+'+ S[2] +'-'+ S[3] +'=7')
elif L[0]+L[1]-L[2]+L[3] == 7:
    print(S[0] +'+'+ S[1] +'-'+ S[2] +'+'+ S[3] +'=7')
elif L[0]+L[1]-L[2]-L[3] == 7:
    print(S[0] +'+'+ S[1] +'-'+ S[2] +'-'+ S[3] +'=7')
elif L[0]-L[1]+L[2]+L[3] == 7:
    print(S[0] +'-'+ S[1] +'+'+ S[2] +'+'+ S[3] +'=7')
elif L[0]-L[1]+L[2]-L[3] == 7:
    print(S[0] +'-'+ S[1] +'+'+ S[2] +'-'+ S[3] +'=7')
elif L[0]-L[1]-L[2]+L[3] == 7:
    print(S[0] +'-'+ S[1] +'-'+ S[2] +'+'+ S[3] +'=7')
elif L[0]-L[1]-L[2]-L[3] == 7:
    print(S[0] +'-'+ S[1] +'-'+ S[2] +'-'+ S[3] +'=7')

Solution (Python):
a = input()
c = map(int,list(a))
b = []
for i in c:
    b.append(i)
if(b[0] + b[1] + b[2] + b[3]==7):
    print(a[0]+"+"+a[1]+"+"+a[2]+"+"+a[3]+"=7")
elif(b[0] + b[1] + b[2] - b[3]==7):
    print(a[0]+"+"+a[1]+"+"+a[2]+"-"+a[3]+"=7")
elif(b[0] + b[1] - b[2] + b[3]==7):
    print(a[0]+"+"+a[1]+"-"+a[2]+"+"+a[3]+"=7")
elif(b[0] + b[1] - b[2] - b[3]==7):
    print(a[0]+"+"+a[1]+"-"+a[2]+"-"+a[3]+"=7")
elif(b[0] - b[1] + b[2] + b[3]==7):
    print(a[0]+"-"+a[1]+"+"+a[2]+"+"+a[3]+"=7")
elif(b[0] - b[1] + b[2] - b[3]==7):
    print(a[0]+"-"+a[1]+"+"+a[2]+"-"+a[3]+"=7")
elif(b[0] - b[1] - b[2] + b[3]==7):
    print(a[0]+"-"+a[1]+"-"+a[2]+"+"+a[3]+"=7")
elif(b[0] - b[1] - b[2] - b[3]==7):
    print(a[0]+"-"+a[1]+"-"+a[2]+"-"+a[3]+"=7")

Solution (Python):


A = map(int, list(raw_input()))

if A[0] + A[1] + A[2] + A[3] == 7:
    print str(A[0]) + "+" + str(A[1]) + "+" + str(A[2]) + "+" + str(A[3]) + "=7"

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

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

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

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

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

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

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

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

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

flag = True
for i in ['+', '-']:
    if flag:
        sumAB = A + B if i == '+' else A - B
        for j in ['+', '-']:
            if flag:
                sumABC = sumAB + C if j == '+' else sumAB - C
                for k in ['+', '-']:
                    if flag:
                        sumABCD = sumABC + D if k == '+' else sumABC - D
                        if sumABCD == 7:
                            print(str(A) + i + str(B) + j + str(C) + k + str(D) + "=7")
                            flag = False