Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #for a in range(1, 10):
- #for b in range(1, 10):
- #for c in range(1, 10):
- #for d in range(1, 10):
- a, b, c, d = map(int, input().split())
- '''
- ans1 = ''
- #a, b, c, d = map(int, input().split())
- cnt = 0
- mx = 1 << (a + b)
- while(mx > cnt):
- ca = 0
- cb = 0
- cc = 0
- cd = 0
- flag = False
- for i in range(a + b):
- if(cnt & (1 << i)):
- cb += 1
- else:
- ca += 1
- if(i < a + b - 1):
- if((3 << i) & cnt == (1 << i)):
- cc += 1
- elif((3 << i) & cnt == (2 << i)):
- cd += 1
- if(ca > a or cb > b or cc > c or cd > d):
- flag = True
- break
- if(flag or ca != a or cb != b or cc != c or cd != d):
- cnt += 1
- continue
- for i in range(a + b - 1, -1, -1):
- if((1 << i) & cnt):
- ans1 += '9'
- else:
- ans1 += '3'
- break
- else:
- ans1 = (-1)
- '''
- if(abs(c - d) > 1):
- ls = (-1)
- else:
- ls = '39' * c
- if(c == d):
- ls += '3'
- if(c < d):
- ls = '9' + ls + '3'
- c3 = ls.count('3')
- c9 = ls.count('9')
- if(c3 > a or c9 > b):
- nls = ''
- for i in range(len(ls)):
- if(ls[i] == '9'):
- nls += '3'
- else:
- nls += '9'
- ls = nls
- c3, c9 = c9, c3
- if(c3 > a or c9 > b):
- ls = (-1)
- else:
- p3 = 0
- p9 = 0
- for i in range(0, len(ls)):
- if(ls[i] == '3'):
- p3 = i
- break
- for i in range(len(ls) - 1, -1, -1):
- if(ls[i] == '9'):
- p9 = i
- break
- ls = ls[:p9] + '9' * (b - c9) + ls[p9:]
- ls = ls[:p3] + '3' * (a - c3) + ls[p3:]
- print(ls)
- '''
- if(ans1 != ls):
- print(a, b, c, d)
- print(ans1, ls)
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement