Problem:


Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7



Sample input:
1222


Sample output:
1+2+2+2=7

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


nums = list(map(int, S()))
ans = ''
for i in range(2 ** 3):
    res = nums[0]
    ans = str(nums[0])
    for j in range(3):
        if i >> j & 1:
            res += nums[j + 1]
            ans += f'+{nums[j + 1]}'
        else:
            res -= nums[j + 1]
            ans += f'-{nums[j + 1]}'
    if res == 7:
        ans += '=7'
        break
print(ans)

Submission status: Accepted

Solution code:
s=input()

for i in range(2**3):
  chk=""
  for j in range(3):
    chk+=s[j]
    if (i>>j)&1==1:
      chk+='+'
    else:
      chk+='-'
  chk+=s[3] 
  if eval(chk)==7:
    break
print(f"{chk}=7")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product

s = input()
op_patterns = product(['+', '-'], repeat=3)

for operators in op_patterns:
    expression = f"{s[0]}{operators[0]}{s[1]}{operators[1]}{s[2]}{operators[2]}{s[3]}"
    if eval(expression) == 7:
        print(f"{expression}=7")
        break

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())


def main():
    ABCD = list(input())
    for ops in range(2**3):
        t = int(ABCD[0])
        ans = ABCD[0]
        for i in range(3):
            if (ops>>i)&1:
                t += int(ABCD[i+1])
                ans += '+'+ABCD[i+1]
            else:
                t -= int(ABCD[i+1])
                ans += '-'+ABCD[i+1]
        if t == 7:
            ans += '=7'
            print(ans)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

for i in range(8):
    cal = ""
    for j in range(3):
        cal += s[j]
        if (i >> j) & 1:
            cal += "+"
        else:
            cal += "-"
    cal += s[3]
    if eval(cal) == 7:
        break

print(f"{cal}=7")

Submission status: Accepted

Solution code:
def a(t,i):
    if i == l - 1:
        if eval(t)==7:
            print(t+"=7")
            exit()
        return
    a(t+"+"+N[i+1],i+1)
    a(t+"-"+N[i+1],i+1)

N = input()
l = len(N)
a(N[0],0)

Submission status: Accepted

Solution code:
S = input()
N = len(S) - 1

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

Submission status: Accepted

Solution code:
abcd = input()

n = ["+","-"]
for i1 in n:
  for i2 in n:
    for i3 in n:
      if eval(abcd[0]+i1+abcd[1]+i2+abcd[2]+i3+abcd[3]) == 7:
        print(abcd[0]+i1+abcd[1]+i2+abcd[2]+i3+abcd[3]+"=7")
        exit()

Submission status: Accepted

Solution code:
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]))
  
if __name__ == '__main__':        
    s = input()
    dfs(0, s[0], int(s[0]))

Submission status: Accepted

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

flag = 7
while flag >= 0:
    S = []
    total = nums[0]
    bin_str = format(flag, "03b")
    for i, bit in enumerate(bin_str, 1):
        if int(bit):
            total += nums[i]
            S.append("+")
        else:
            total -= nums[i]
            S.append("-")
    if total == 7:
        break
    
    flag -= 1
print(f"{nums[0]}{S[0]}{nums[1]}{S[1]}{nums[2]}{S[2]}{nums[3]}=7")

Submission status: Accepted

Solution code:
S = input()
n = len(S)
# bit全探索
for i in range(2 ** (n - 1)):
    ope = S
    cur = 0
    for j in range(n - 1):
        if (i >> j) & 1:
            ope = ope[:-j - cur - 1] + '+' + ope[-j - cur - 1:]
        else:
            ope = ope[:-j - cur - 1] + '-' + ope[-j - cur - 1:]
        cur += 1
    if eval(ope) == 7:
        print(ope + '=7')
        break

Submission status: Accepted

Solution code:
a = list(input())
 
sign = "+-"
 
for i in range(2):  #1つめの正負
 for j in range(2):  #2つ目の正負
  for k in range(2):  #3つ目の正負
    if eval(a[0]+sign[i]+a[1]+sign[j]+a[2]+sign[k]+a[3] ) == 7:
     print(str(a[0]+sign[i]+a[1]+sign[j]+a[2]+sign[k]+a[3])+'=7')
     exit()

Submission status: Accepted

Solution code:
import itertools
A=input()
for i in list(itertools.product(range(2),repeat=3)):
  c=''
  c+=A[0]
  bns=int(A[0])
  for j in range(3):
    if i[j]==0:
      bns+=int(A[j+1])
      c+='+'+A[j+1]
    else:
      bns-=int(A[j+1])
      c+='-'+A[j+1]
  if bns==7:
    print(c+'=7')
    exit()

Submission status: Accepted

Solution code:
ABCD = list(input())

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

AA = ABCD[0]
BB = ABCD[1]
CC = ABCD[2]
DD = ABCD[3]

if A+B+C+D==7:
    print(AA+'+'+BB+'+'+CC+'+'+DD+'=7')
elif A+B+C-D==7:
    print(AA+'+'+BB+'+'+CC+'-'+DD+'=7')
elif A+B-C+D==7:
    print(AA+'+'+BB+'-'+CC+'+'+DD+'=7')
elif A+B-C-D==7:
    print(AA+'+'+BB+'-'+CC+'-'+DD+'=7')
elif A-B+C+D==7:
    print(AA+'-'+BB+'+'+CC+'+'+DD+'=7')
elif A-B+C-D==7:
    print(AA+'-'+BB+'+'+CC+'-'+DD+'=7')
elif A-B-C+D==7:
    print(AA+'-'+BB+'-'+CC+'+'+DD+'=7')
elif A-B-C-D==7:
    print(AA+'-'+BB+'-'+CC+'-'+DD+'=7')

Submission status: Accepted

Solution code:
a = list(input())
 
sign = "+-"
 
for i in range(2):  #1つめの正負
 for j in range(2):  #2つ目の正負
  for k in range(2):  #3つ目の正負
    if eval(a[0]+sign[i]+a[1]+sign[j]+a[2]+sign[k]+a[3] ) == 7:
     print(str(a[0]+sign[i]+a[1]+sign[j]+a[2]+sign[k]+a[3])+'=7')
     exit()

Submission status: Accepted

Solution code:
list = list(input())

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


def plus(items, key):
    if(key == 1):
        return items[0] + items[1]
    else:
        return items[0] - items[1]


def numToOp(num):
    return "+" if num == 1 else "-"


ans = 0
opList = [1, 1, 1]
i = 0
while ans != 7:
    aPlusB = plus([a, b], opList[0])
    aPlusBPlusC = plus([aPlusB, c], opList[1])
    ans = plus([aPlusBPlusC, d], opList[2])
    # print(f"{i}回目：ans == {ans}, opList == {opList}")

    if ans != 7 and i <= 4:
        opList[i % 3] *= -1
        i += 1
    elif ans != 7 and i == 5:
        opList = [1, -1, 1]
        i += 1
    elif ans != 7 and i == 6:
        opList = [-1, 1, -1]
        i += 1

# print(opList)

print(
    f"{a}{numToOp(opList[0])}{b}{numToOp(opList[1])}{c}{numToOp(opList[2])}{d}=7")

Submission status: Accepted

Solution code:
a = list(map(int, input()))
ans = ""
for i in range(2 ** 3):
  b = [i for i in a]
  for j in range(3):
    if (i >> j) & 1:
      b[j + 1] *= -1
  if sum(b) == 7:
    ans += (str)(b[0])
    for j in range(1, 4):
      if b[j] >= 0:
        ans += "+" + (str)(b[j])
      else:
        ans += (str)(b[j])
    ans += "=7"
    break
else:
  print("none")
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

A, B, C, D = input()
for op1, op2, op3 in product("+-", repeat=3):
    exp = f"{A}{op1}{B}{op2}{C}{op3}{D}"
    if eval(exp) == 7:
        print(exp + "=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
for i in range(1<<3):
  tmp=int(s[0])
  S=s[0]  
  for j in range(3):
    if i>>j & 1:
      S=S+'+'+s[j+1]
      tmp+=int(s[j+1])
    else:
      S=S+'-'+s[j+1]
      tmp-=int(s[j+1])  
  if tmp==7:
    print(S+'=7')
    exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
nums = list(map(int, input()))

for n in range(3**2):
    ans = nums[0]
    ops = []
    for i in range(3):
        if 1 & (n >> i):
            ans += nums[i+1]
            ops.append('+')
        else:
            ans -= nums[i+1]
            ops.append('-')

    if ans == 7:
        b = ['%d%s' % (nums[i], ops[i]) for i in range(3)]
        b += ['%d' % nums[3]]
        print(''.join(b) + '=7')
        exit()

Submission status: Accepted

Solution code:
def calc(S: str, cur: int, e: str):
    if S == "":
        if cur == 7:
            print(e+"=7")
            quit()
        else:
            return

    calc(S[1:], cur + int(S[0]), e + "+" + S[0])
    calc(S[1:], cur - int(S[0]), e + "-" + S[0])


S = input().strip()
ans = calc(S[1:], int(S[0]), S[0])

Submission status: Accepted

Solution code:
def resolve():
    A, B, C, D = list(input())
    OP = ("+", "-")
    for i in range(2**3):
        op = ["+" for _ in range(3)]
        for j in range(3):
            if (i >> j) & 1:
                op[j] = OP[0]
            else:
                op[j] = OP[1]
        if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
            print(A + op[0] + B + op[1] + C + op[2] + D + "=7")
            return

resolve()

Submission status: Accepted

Solution code:
import numpy as np

S = input()
ans = int(S[0])
ope = []

while True:
    for i in S[1:]:
        if np.random.randint(2) == 0:
            ans += int(i)
            ope.append("+")
        else:
            ans -= int(i)
            ope.append("-")

    if ans == 7:
        print(S[0]+ope[0]+S[1]+ope[1]+S[2]+ope[2]+S[3]+"=7")
        exit()
    else:
        ans = int(S[0])
        ope = []

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
pm = '+-'
for i in range(2):
  for j in range(2):
    for k in range(2):
      if i == 0:
        temp = a + b
      else:
        temp = a - b
      if j == 0:
        temp += c
      else:
        temp -= c
      if k == 0:
        temp += d
      else:
        temp -= d
      if temp == 7:
        print(s[0] + pm[i] + s[1] + pm[j] + s[2] + pm[k] + s[3] + '=7')
        exit()

Submission status: Accepted

Solution code:
def c_train_ticket():
    from itertools import product
    operands = tuple(input())
    # 演算子の選び方は高々 8 通りなので全探索する
    for operators in product('+-', repeat=3):
        formula = ''.join(ch + op for ch, op in zip(operands, operators + ('',)))
        if eval(formula) == 7:
            return formula + '=7'
    return None  # 1 つは答えがあるような入力なので，ここには来ない

print(c_train_ticket())

Submission status: Accepted

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

for i in range(2**l):
    op=["-"]*l
    for j in range(l):
        if (i>>j)&1:
            op[l - j - 1] = "+" #なぜ i - j - 1 ではなく、l - j - 1なのか、決まっている数から引いたものが知りたい
    formula = ""
    for op_1,op_2 in zip(n,op+[""]): #式の文字列を作るループ
        formula += op_1 + op_2
    if eval(formula)==7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
from itertools import product
import sys

S = str(input())
A = list(product(['+', '-'], repeat=3))

for a in A:
    ans = 0
    tmp = ""
    for i in range(len(S)-1):
        tmp += S[i]+a[i]
    tmp += S[len(S)-1]
    ans += eval(tmp)
    if ans == 7:
        print(tmp+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
n = input()
l = len(n)-1
for i in range(2**l):
    op = ["-"]*l
    for j in range(l):
        if (i>>j)&1:
            op[l-j-1]="+" #lからjだけシフトさせて+に変える

    formula = ""
    for op_num,op_l in zip(n,op+[""]):
        formula += op_num + op_l
    if eval(formula)==7:
        print(formula+"=7")
        break

Submission status: Accepted

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

f, g = a+b, a-b
h, i, j, k = f+c, f-c, g+c, g-c
l, m, n, o, p, q, r, s = h + d, h - d, i + d, i - d, j + d, j - d, k + d, k - d
if(l == 7):
  print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif(m == 7):
  print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif(n == 7):
  print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif(o == 7):
  print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")
elif(p == 7):
  print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif(q == 7):
  print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif(r == 7):
  print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif(s == 7):
  print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import product as pd

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

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

bitAll = pd([0,1],repeat=3)
for i in bitAll:
	t = l[0]
	for j in range(3):
		if i[j]==1:
			t+=l[j+1]
		else:
			t-=l[j+1]
	if t==7:
		tar = "".join([str(j) for j in list(i)])
		break

l = [str(i) for i in l]
tar = tar.replace("1","+")
tar = tar.replace("0","-")
print(l[0]+tar[0]+l[1]+tar[1]+l[2]+tar[2]+l[3]+"=7")

Submission status: Accepted

Solution code:
s=input()
op=[["+", "-"]]*3

for i in range(2**3):
    tmp=[0]*3
    for j in range(3):
        if (i>>j)&1:
            tmp[j]=1
    
    ans=s[0]
    for i in range(3):
        ans=ans+(op[i][tmp[i]]+s[i+1])
    if eval(ans)==7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
abcd = str(input())

op_cnt = len(abcd) - 1
for i in range(2**op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt-1 - j] = "+"

    ans = int(abcd[0])
    for j in range(1, len(abcd)):
        if op[j-1]=="+":
            ans += int(abcd[j])
        else:
            ans -= int(abcd[j])

    if ans==7:
        for j in range(len(abcd)):
            if j==len(abcd)-1:
                print(abcd[j], "=7", sep="")
            else:
                print(abcd[j], op[j], end="", sep="")
        break

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = list(input())
num = [int(i) for i in num]
 
if sum(num) == 7:
    print(f'{num[0]}+{num[1]}+{num[2]}+{num[3]}=7')
elif num[0]+num[1]+num[2]-num[3] == 7:
    print(f'{num[0]}+{num[1]}+{num[2]}-{num[3]}=7')
elif num[0]+num[1]-num[2]+num[3] == 7:
    print(f'{num[0]}+{num[1]}-{num[2]}+{num[3]}=7')
elif num[0]-num[1]+num[2]+num[3] == 7:
    print(f'{num[0]}-{num[1]}+{num[2]}+{num[3]}=7')
elif num[0]+num[1]-num[2]-num[3] == 7:
    print(f'{num[0]}+{num[1]}-{num[2]}-{num[3]}=7')
elif num[0]-num[1]+num[2]-num[3] == 7:
    print(f'{num[0]}-{num[1]}+{num[2]}-{num[3]}=7')
elif num[0]-num[1]-num[2]+num[3] == 7:
    print(f'{num[0]}-{num[1]}-{num[2]}+{num[3]}=7')
else:
    print(f'{num[0]}-{num[1]}-{num[2]}-{num[3]}=7')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c

from itertools import product


S = input()
R = []


for p in product(*((0,1),)*3):
    res = S[0]
    for i, s in enumerate(S[1:]):
        if p[i]:
            res = res + "+" + s
        else:
            res = res + "-" + s
    if eval(res) == 7:
        print(res + "=7")
        exit()

Submission status: Accepted

Solution code:
num = input()
x = ['+', '-']

for i in x:
  for j in x:
    for k in x:
      n = eval(num[0]+ i + num[1] + j + num[2] + k + num[3])
      if n == 7:
        print(num[0] + i + num[1] + j + num[2] + k + num[3] + '=7')
        exit()

Submission status: Accepted

Solution code:
num = input()

x = ["+", "-"]

for i in x:
  for j in x:
    for k in x:
      n = eval(num[0]+i+num[1]+j+num[2]+k+num[3])
      if n == 7:
        print(num[0]+i+num[1]+j+num[2]+k+num[3]+"=7")
        exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
N = input()
lst = []
for i in N:
    lst.append(i)
    

for i in range(2**3):
    op = ['+','+','+']
    for j in range(3):
        #print(i,j)
        #print((i>>j) & 1)
        if (i>>j)&1 == 1:
            #print((i>>j) & 1)
            op[j] = '-'
    tes = [0]*7
    tes[::2] = lst
    tes[1::2] = op
    
    if eval(''.join(tes)) == 7:
        print(''.join(tes)+'=7')
        sys.exit()
    #print(op)

Submission status: Accepted

Solution code:
a=list(input())
for i in range(4):
  a[i]=int(a[i])
x=sum(a)-7
dict={0:'+',1:'-'}
ans=0
for i in range(2):
  for j in range(2):
    for k in range(2):
        if x==(i*a[1]+j*a[2]+k*a[3])*2:
          print(a[0],dict[i],a[1],dict[j],a[2],dict[k],a[3],'=7',sep='')
          ans=1
        if ans==1:
          break
    if ans==1:
      break
  if ans==1:
    break

Submission status: Accepted

Solution code:
nums = [int(x) for x in list(input())]

for bit in range(1 << 3):
    t = str(nums[0])
    s = nums[0]
    for i in range(3):
        if (bit >> i) & 1:
            s += nums[i + 1]
            t += "+" + str(nums[i + 1])
        else:
            s -= nums[i + 1]
            t += "-" + str(nums[i + 1])

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

Submission status: Accepted

Solution code:
def calc(summation, step, operation):
    if step < len(line):
        # plus
        calc(summation+line[step], step+1, operation+"+")
        # minus
        calc(summation - line[step], step + 1, operation+"-")
    if step == len(line):
        if summation == 7:
            ans = str(line[0])+operation[0]+str(line[1])+operation[1] + \
                str(line[2])+operation[2]+str(line[3])+"=7"
            print(ans)
            exit()


line = [int(i) for i in input()]
calc(line[0], 1, "")

Submission status: Accepted

Solution code:
from itertools import product

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

for bit in product([0,1], repeat = 3):
    if bit[0] == 0:
        E = A + B
        op1 = "+"
    else:
        E = A - B
        op1 = "-"
    
    if bit[1] == 0:
        F = E + C
        op2 = "+"
    else:
        F = E - C
        op2 = "-"

    if bit[2] == 0:
        G = F + D
        op3 = "+"
    else:
        G = F - D
        op3 = "-"

    if G == 7:
        ans = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D)
        ans = ans + "=7"
        print(ans)
        break

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
if a + b + c + d == 7:
    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')

Submission status: Accepted

Solution code:
abcd = input()
a, b, c, d = list(map(int, [x for x in abcd]))
A = a + b + c + d
B = a - b + c + d
C = a + b - c + d
D = a + b + c - d
E = a - b - c + d
F = a - b + c - d
G = a + b - c - d
H = a - b - c - d
if A == 7:
  ans = f"{a}+{b}+{c}+{d}=7"
elif B == 7:
  ans = f"{a}-{b}+{c}+{d}=7"
elif C == 7:
  ans = f"{a}+{b}-{c}+{d}=7"
elif D == 7:
  ans = f"{a}+{b}+{c}-{d}=7"
elif E == 7:
  ans = f"{a}-{b}-{c}+{d}=7"
elif F == 7:
  ans = f"{a}-{b}+{c}-{d}=7"
elif G == 7:
  ans = f"{a}+{b}-{c}-{d}=7"
elif H == 7:
  ans = f"{a}-{b}-{c}-{d}=7"
print(ans)

Submission status: Accepted

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

if A + B + C + D == 7:
    print(f"{A}+{B}+{C}+{D}=7")
elif A - B + C + D == 7:
    print(f"{A}-{B}+{C}+{D}=7")
elif A + B - C + D == 7:
    print(f"{A}+{B}-{C}+{D}=7")
elif A + B + C - D == 7:
    print(f"{A}+{B}+{C}-{D}=7")
elif A - B - C + D == 7:
    print(f"{A}-{B}-{C}+{D}=7")
elif A - B + C - D == 7:
    print(f"{A}-{B}+{C}-{D}=7")
elif A + B - C - D == 7:
    print(f"{A}+{B}-{C}-{D}=7")
elif A - B - C - D == 7:
    print(f"{A}-{B}-{C}-{D}=7")

Submission status: Accepted

Solution code:
n=list(map(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 p_n, p_o in zip(n, op+['']):
    # n->p_n: 1
    # op+['']->p_o: +, +, +, ''
    formula += (p_n + p_o)
  if eval(formula) == 7:
    print(formula + '=7')
    break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nums = input()
 
N = 3
for i in range(2**N):
    equation = ''
    for j in range(N):
        equation += nums[j]
        if ((i >> j) & 1):
            equation += '+'
        else:
            equation += '-'
    equation += nums[-1]
    if eval(equation) == 7:
        print(equation + '=7')
        exit()

Submission status: Accepted

Solution code:
def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

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

for i in range(2**3):
    operand = []
    tmp = ["+", "-"]
    
    for j in range(3):
        if (i >> j) & 1:
            operand.append(tmp[0])
        else:
            operand.append(tmp[1])
    
    flg = ABCD[0]
    ans = str(ABCD[0]) 
    
    for k in range(3):
        if operand[k] == "+":
            flg += ABCD[k + 1]
            ans += operand[k]
            ans += str(ABCD[k + 1])
        
        else:
            flg -= ABCD[k + 1]
            ans += operand[k]
            ans += str(ABCD[k + 1])
    
    if flg == 7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
ticket = input()
A,B,C,D = [n for n in ticket]
for i in range(2**3):
  answer = int(ticket[0])
  op = ["-","-","-"]
  for j in range(3):
    if (i>>j)&1 == 1:
      answer += int(ticket[j+1])
      op[j] = "+"
    else:
      answer -= int(ticket[j+1])
  if answer == 7:
    result = A + op[0] + B + op[1] + C + op[2] + D + "=7"
    break
print(result)

Submission status: Accepted

Solution code:
ticket = input()
A,B,C,D = [n for n in ticket]
for i in range(2**3):
  answer = int(ticket[0])
  for j in range(3):
    if (i>>j)&1 == 1:
      answer += int(ticket[j+1])
    else:
      answer -= int(ticket[j+1])
  if answer == 7:
    op = bin(i)[2:]
    if len(op) == 1:
      op = "00"+op
    elif len(op) == 2:
      op = "0"+op
    op = op.replace("1","+").replace("0","-")
    result = A + op[2] + B + op[1] + C + op[0] + D + "=7"
    break
print(result)

Submission status: Accepted

Solution code:
from itertools import product
abcd = list(map(int, list(input())))


for ops in product(['+', '-'], repeat=3):
    temp = abcd[0]
    ans = str(abcd[0])
    for i, op in enumerate(ops):
        if op=='+':
            temp+=abcd[i+1]
            ans+='+'+str(abcd[i+1])
        else:
            temp-=abcd[i+1]
            ans+='-'+str(abcd[i+1])
    if temp==7:
        ans+='=7'
        break
print(ans)

Submission status: Accepted

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            if i%2==0 and j%2==0 and k%2==0:
                ans = a+b+c+d
                ans_s = f"{a}+{b}+{c}+{d}"
            elif i%2==0 and j%2==0 and k%2==1:
                ans = a+b+c-d
                ans_s = f"{a}+{b}+{c}-{d}"
            elif i%2== 0 and j%2==1 and k%2==1:
                ans = a+b-c-d
                ans_s = f"{a}+{b}-{c}-{d}"
            elif i%2== 1 and j%2==1 and k%2==1:
                ans = a-b-c-d
                ans_s = f"{a}-{b}-{c}-{d}"
            elif i%2==1 and j%2==1 and k%2==0:
                ans = a-b-c+d
                ans_s = f"{a}-{b}-{c}+{d}"
            elif i%2==1 and j%2==0 and k%2==0:
                ans = a-b+c+d
                ans_s = f"{a}-{b}+{c}+{d}"
            elif i%2==1 and j%2==0 and k%2==1:
                ans = a+b-c+d
                ans_s = f"{a}+{b}-{c}+{d}"
            else:
                ans = a-b+c-d
                ans_s = f"{a}-{b}+{c}-{d}"
            
            if ans == 7:
                print(ans_s+"=7")
                exit()

Submission status: Accepted

Solution code:
N=list(map(str,input()))
ketasu=len(N)
def dfs(siki,sitei):
    if sitei == ketasu-1 :    
        if eval(siki)==7:
            print(siki+"=7")
            exit()
            return
    else:
        dfs(siki+"+"+N[sitei+1],sitei+1)
        dfs(siki+"-"+N[sitei+1],sitei+1)

dfs(N[0],0)

Submission status: Accepted

Solution code:
def a(s,i):
    if i == l-1:
        if eval(s) == 7:
            print(s+"=7")
            exit()
        return
    a(s+"+"+N[i+1],i+1)
    a(s+"-"+N[i+1],i+1)

N = input()
l = len(N)
a(N[0],0)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
for bit in range(1 << 3):
    start = S[0]
    sumS = int(S[0])
    for i in range(3):
        if bit & (1 << i):
            sumS += int(S[i+1])
            start += "+"
            start += S[i+1]
        else:
            sumS -= int(S[i+1])
            start += "-"
            start += S[i+1]
    if sumS == 7:
        start += "=7"
        print(start)
        exit()

Submission status: Accepted

Solution code:
*A, = map(int, input())
a = A[0]
b = [A[1], -A[1]]
c = [A[2], -A[2]]
d = [A[3], -A[3]]

def f(n):
    if n>=0:
        return '+'+str(n)
    else:
        return str(n)

for bb in b:
    for cc in c:
        for dd in d:
            if a+bb+cc+dd == 7:
                print(a, end='')
                print(f(bb), end='')
                print(f(cc), end='')
                print(f(dd), end='')
                print('=7')
                exit()

Submission status: Accepted

Solution code:
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

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

if s[0]+s[1]+s[2]+s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '+',
          str(s[2]), '+', str(s[3]), '=', 7, sep='')
    exit()
if s[0]+s[1]-s[2]+s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '-', str(s[2]),
          '+', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]+s[2]+s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '+', str(s[2]),
          '+', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]-s[2]+s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '-', str(s[2]),
          '+', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]+s[1]+s[2]-s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '+', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]-s[2]-s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '-', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]+s[2]-s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '+', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]+s[1]-s[2]-s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '-', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()

Submission status: Accepted

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=list(SI())
a=int(s[0])
ops=["+","-"]
for i in product(ops,repeat=3):
    ans=a
    for j in range(3):
        if i[j]=="+":
            ans+=int(s[j+1])
        else:
            ans-=int(s[j+1])
    if ans==7:
        u=i
        #print(i)
        break
print(s[0],end="")
for i in range(3):
    print(u[i]+s[i+1],end="")
print("=7")