Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.

Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!

Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.

Help Polycarpus and find any suitable method to cut the public key.


-----Input-----

The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 10^6 digits. The second line contains a pair of space-separated positive integers a, b (1 ≤ a, b ≤ 10^8).


-----Output-----

In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.

If there is no answer, print in a single line "NO" (without the quotes).


-----Examples-----
Input
116401024
97 1024

Output
YES
11640
1024

Input
284254589153928171911281811000
1009 1000

Output
YES
2842545891539
28171911281811000

Input
120
12 1

Output
NO

Difficulty: MEDIUM_HARD
Tags: Number theory

Complete search

Mathematics

String algorithms
Skill types: Complete search

Starter code:

Solutions:
(s, x, pfx) = (input(), 0, [])
(a, b) = map(int, input().split())
try:
	for (i, c) in enumerate(s, 1):
		x = (x * 10 + int(c)) % a
		if not x and s[i] != '0':
			pfx.append(i)
except IndexError:
	pass
(x, p, i) = (0, 1, len(s))
for stop in reversed(pfx):
	for i in range(i - 1, stop - 1, -1):
		x = (x + int(s[i]) * p) % b
		p = p * 10 % b
	if not x:
		print('YES')
		print(s[:i])
		print(s[i:])
		exit()
print('NO')


s = list(input())
(a, b) = map(int, input().split())
l = len(s)
s1 = [0] * (l + 1)
s2 = [0] * (l + 1)
for i in range(l):
	s[i] = ord(s[i]) - ord('0')
p = 1
for i in range(l - 1, -1, -1):
	s1[i] = (s1[i + 1] + s[i] * p) % b
	p = p * 10 % b
p = 0
for i in range(l - 1):
	p = (p * 10 + s[i]) % a
	if p == 0 and s1[i + 1] == 0 and s[i + 1]:
		print('YES')
		print(''.join(map(str, s[:i + 1])))
		print(''.join(map(str, s[i + 1:])))
		exit()
print('NO')


def solve(s, a, b):
	x = int(s[0]) % a
	y = 0
	temp = 1
	aa = []
	bb = []
	bbb = [0] * len(s)
	for i in range(0, 11):
		aa.append(i % a)
		bb.append(i % b)
	temp2 = bb[1]
	bbb[0] = bb[1]
	for i in range(1, len(s)):
		y = y % b * (bb[10] % b)
		y = y % b
		y = y + bb[int(s[i])] % b
		y = y % b
		temp2 = temp2 * bb[10] % b
		bbb[i] = temp2
	temp3 = aa[10]
	if x == 0 and y == 0:
		return 1
	for i in range(1, len(s) - 1):
		x = x % a * (aa[10] % a)
		x = x % a
		x = x + aa[int(s[i])] % a
		x = x % a
		z = bb[int(s[i])] * bbb[len(s) - 1 - i]
		z = z % b
		y = y - z
		y = y % b
		if x == 0 and y == 0:
			return i + 1
	return -1
s = input()
(a, b) = map(int, input().split())
i = solve(s, a, b)
if i == -1:
	print('NO')
else:
	while i < len(s) and s[i] == '0':
		i += 1
	if i == len(s):
		print('NO')
	else:
		print('YES')
		print(s[0:i])
		print(s[i:])


import sys
from collections import *
input = sys.stdin.readline
s = input()[:-1]
n = len(s)
(a, b) = [int(x) for x in input().split()]
y = [0] * (n - 1)
num = 0
t = 1
for i in range(n - 1, 0, -1):
	num = (num + int(s[i]) * t % b) % b
	t = t * 10 % b
	if s[i] == '0':
		y[i - 1] = 1
	else:
		y[i - 1] = num
res = 0
num = 0
for i in range(n - 1):
	num = (num * 10 % a + int(s[i]) % a) % a
	if num == 0 and y[i] == 0 and (s[i + 1] != '0'):
		res = 1
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		break
if res == 0:
	print('NO')


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	s = input()
	(a, b) = read()
	pre_rem = [0] * len(s)
	suf_rem = [0] * len(s)
	pre_rem[0] = int(s[0]) % a
	suf_rem[len(s) - 1] = int(s[-1]) % b
	for i in range(1, len(s)):
		j = -(i + 1)
		pre_rem[i] = (pre_rem[i - 1] * 10 + int(s[i])) % a
		suf_rem[j] = (int(s[j]) * pow(10, abs(j + 1), b) + suf_rem[j + 1]) % b
	for i in range(len(s)):
		if i != len(s) - 1 and s[i + 1] != '0':
			if pre_rem[i] == 0 and suf_rem[i + 1] == 0:
				print('YES')
				print(s[:i + 1])
				print(s[i + 1:])
				exit()
	print('NO')
solve()


l = input()
(a, b) = input().split()
a = int(a)
b = int(b)
n = len(l)
ra = []
rb = [0] * n
nn = ''
f = 0
p = 1
ra.append(int(l[0]) % a)
rb[n - 1] = int(l[n - 1]) % b
for i in range(1, n - 1):
	ra.append((ra[i - 1] * 10 + int(l[i])) % a)
for i in range(n - 2, -1, -1):
	rb[i] = (rb[i + 1] + int(l[i]) * p * 10 % b) % b
	p = p * 10 % b
st = ''
for i in range(n - 1):
	if ra[i] == 0 and rb[i + 1] == 0 and (l[i + 1] != '0'):
		print('YES')
		st += str(''.join(l[:i + 1])) + '\n'
		st += str(''.join(l[i + 1:n]))
		break
if len(st) == 0:
	print('NO')
else:
	print(st)


def solve(num, a, b):
	rem_a = [None] * len(num)
	rem_b = [None] * len(num)
	sn = num
	num = [int(x) for x in num]
	rem_a[0] = num[0] % a
	rem_b[-1] = num[-1] % b
	q = 1
	for i in range(1, len(num)):
		rem_a[i] = (rem_a[i - 1] * 10 + num[i]) % a
		q = q * 10 % b
		rem_b[-i - 1] = (num[-i - 1] * q + rem_b[-i]) % b
	for i in range(len(num) - 1):
		if rem_a[i] == 0 and rem_b[i + 1] == 0 and (num[i + 1] != 0):
			return (True, sn[:i + 1], sn[i + 1:])
	return (False, 0, 0)

def __starting_point():
	num = input()
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	(res, q, w) = solve(num, a, b)
	if res:
		print('YES')
		print(q)
		print(w)
	else:
		print('NO')
__starting_point()


s = input()
(a, b) = map(int, input().split())
l = len(s)
su = [0] * (l + 1)
p = 1
flag = 0
for i in range(l - 1, 0, -1):
	su[i] = (su[i + 1] + int(s[i]) * p) % b
	p = p * 10 % b
p = 0
for i in range(0, l - 1):
	p = (p + int(s[i])) % a
	if p == 0 and s[i + 1] != '0' and (su[i + 1] == 0):
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		flag = 1
		break
	p = p * 10 % a
if flag == 0:
	print('NO')


s = list(input())
forans = list(s)
(a, b) = map(int, input().split(' '))
n = len(s)
s.reverse()
prea = [0]
preb = [0]
sa = 0
sb = 0
chk = 0
pow10 = []
sm = 1
for x in range(n + 1):
	pow10.append(sm)
	sm = sm * 10 % b
for x in range(n):
	sb = (sb + int(s[x]) * pow10[x]) % b
	preb.append(sb)
ans = -1
chk = 0
for x in range(n):
	if chk == 0:
		sa = (sa + int(forans[x])) % a
		chk = 1
	else:
		sa = (sa * 10 + int(forans[x])) % a
	prea.append(sa)
for x in range(n - 1):
	if s[x] != '0':
		if preb[x + 1] == 0 and prea[n - x - 1] == 0:
			ans = n - x - 1
			break
if ans == -1:
	print('NO')
else:
	print('YES')
	print(*forans[:ans], sep='')
	print(*forans[ans:], sep='')


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
s = input()
(a, b) = I()
n = len(s)
x = [0] * n
y = [0] * n
x[0] = int(s[0]) % a
y[n - 1] = int(s[n - 1]) % b
p = 10 % b
for i in range(1, n):
	x[i] = (x[i - 1] * 10 + int(s[i])) % a
	y[n - i - 1] = (int(s[n - i - 1]) * p + y[n - i]) % b
	p *= 10
	p %= b
for i in range(n - 1):
	if not x[i] and (not y[i + 1]) and (s[i + 1] != '0'):
		print('YES', s[:i + 1], s[i + 1:], sep='\n')
		break
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def exponentiation(bas, exp, N):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % N
		bas = bas * bas % N
		exp = int(exp / 2)
	return t % N
s = input()
(a, b) = map(int, input().split())
pre = [0]
suf = [0]
n = len(s)
for i in range(0, n):
	v = int(s[i])
	pre.append((v + pre[i] * 10) % a)
tp = 1
for i in range(n - 1, -1, -1):
	v = int(s[i])
	suf.append((v * tp + suf[n - i - 1]) % b)
	tp = tp * 10 % b
pre.pop()
pre.pop(0)
suf.pop()
suf.pop(0)
suf.reverse()
ci = -1
for i in range(0, n - 1):
	if pre[i] == 0 and suf[i] == 0:
		if s[i + 1] != '0':
			ci = i + 1
			break
if ci == -1:
	print('NO')
else:
	print('YES')
	print(s[:ci] + '\n' + s[ci:])


from sys import stdin
c = list(stdin.readline()[:-1])
(a, b) = map(int, input().split())
pref = []
pref1 = []
summ = 0
summ1 = 0
boo = 0
x = 1
for i in range(len(c)):
	summ = summ * 10 + int(c[i])
	summ %= a
	pref.append(summ)
for i in range(len(c) - 1, -1, -1):
	summ1 += x * int(c[i])
	x *= 10
	x %= b
	summ1 %= b
	pref1.append(summ1)
for i in range(len(c) - 1):
	if pref1[i] == 0 and pref[len(c) - i - 2] == 0 and (int(c[len(c) - i - 1]) != 0):
		print('YES')
		print(''.join(c[:len(c) - i - 1]))
		print(''.join(c[len(c) - i - 1:]))
		boo = 1
		break
if boo == 0:
	print('NO')


s = input()
(a, b) = map(int, input().split())
n = len(s)
(aa, bb) = (set(), set())
v = 0
for i in range(n):
	v = (v * 10 + int(s[i])) % a
	if v == 0:
		aa.add(i + 1)
v = 0
p = 1
for i in range(n - 1, -1, -1):
	v = (v + int(s[i]) * p) % b
	p = p * 10 % b
	if v == 0 and s[i] != '0':
		bb.add(i)
aa &= bb
if len(aa):
	m = min(aa)
	print('YES', s[:m], s[m:], sep='\n')
else:
	print('NO')


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
string = input()
length = len(string)
(a, b) = get_ints()
dp1 = [0] * length
dp2 = [0] * length
dp1[0] = int(string[0]) % a
for i in range(1, length):
	dp1[i] = (dp1[i - 1] * 10 + int(string[i])) % a
dp2[~0] = int(string[~0]) % b
mul = 10
for i in range(1, length):
	dp2[~i] = (int(string[~i]) * mul + dp2[~(i - 1)]) % b
	mul = mul * 10 % b
for i in range(length - 1):
	if dp1[i] == 0 and dp2[i + 1] == 0:
		if string[i + 1] != '0':
			print('YES')
			print(string[:i + 1])
			print(string[i + 1:])
			exit()
print('NO')


import sys
input = sys.stdin.readline
s = list(input().rstrip())
n = len(s)
t = [s[i] for i in range(n)]
for i in range(n):
	s[i] = int(s[i])
(a, b) = map(int, input().split())
(m1, m2) = (0, 0)
pre_a = [0] * (n + 1)
for i in range(n):
	m1 = (m1 * 10 + s[i]) % a
	pre_a[i + 1] = m1
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
	f[i] = f[i - 1] * 10 % b
for i in range(1, n)[::-1]:
	m2 = (m2 + s[i] * f[n - 1 - i]) % b
	if m2 == 0 and pre_a[i + 1 - 1] == 0 and (s[i] != 0):
		print('YES')
		print(''.join(t[:i]))
		print(''.join(t[i:]))
		exit()
(m1, m2) = (0, 0)
pre_b = [0] * (n + 1)
for i in range(n):
	m1 = (m1 * 10 + s[i]) % b
	pre_b[i + 1] = m1
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
	f[i] = f[i - 1] * 10 % a
for i in range(1, n)[::-1]:
	m2 = (m2 + s[i] * f[n - 1 - i]) % a
	if m2 == 0 and pre_b[i + 1 - 1] == 0 and (s[i] != 0):
		print('YES')
		print(''.join(t[:i]))
		print(''.join(t[i:]))
		exit()
print('NO')


s = input()
n = len(s)
(a, b) = map(int, input().split())
ra = [0] * n
ra[0] = int(s[0]) % a
a10 = 10 % a
for i in range(1, n):
	val = int(s[i])
	ra[i] = (ra[i - 1] * a10 + val % a) % a
rb = [0] * n
rb[n - 1] = int(s[n - 1]) % b
b10 = 10 % b
for i in range(n - 2, 0, -1):
	val = int(s[i])
	rb[i] = (val * b10 + rb[i + 1]) % b
	b10 = b10 * (10 % b) % b
for i in range(n - 1):
	if ra[i] == 0 and rb[i + 1] == 0 and (s[i + 1] != '0'):
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		break
else:
	print('NO')


s = input()
(a, b) = map(int, input().split())
ns = len(s)
left = [False] * ns
right = [False] * ns
ys = 0
for (i, c) in enumerate(s):
	ys = (ys * 10 + int(c)) % a
	if ys == 0:
		left[i] = True
ys = 0
ks = 1
for i in range(ns - 1, -1, -1):
	c = int(s[i])
	ys += ks * c
	ys %= b
	if ys == 0 and c > 0:
		right[i] = True
		if i and left[i - 1]:
			print('YES')
			print(s[:i])
			print(s[i:])
			exit()
	ks = ks * 10 % b
print('NO')


s = input()
(a, b) = map(int, input().split())
ans = -1
dp = [0] * (len(s) + 1)
p = 1
for i in range(len(s) - 1, -1, -1):
	dp[i] = (dp[i + 1] + int(s[i]) * p) % b
	p = p * 10 % b
p = 0
for i in range(len(s) - 1):
	p = (p * 10 + int(s[i])) % a
	if p == 0 and s[i + 1] != '0' and (dp[i + 1] == 0):
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		exit()
print('NO')


from sys import stdin
import math

def check_leading_zero(nstring, index):
	if nstring[index] == '0':
		return False
	return True

def cal_first(nstring, a):
	dp1 = [-1] * len(nstring)
	remain = 0
	for i in range(len(nstring)):
		dp1[i] = (remain * 10 + int(nstring[i])) % a
		remain = dp1[i]
	return dp1

def cal_second(nstring, b):
	dp2 = [-1] * len(nstring)
	dp2[-1] = int(nstring[-1]) % b
	mul = 10
	for i in range(len(nstring) - 2, -1, -1):
		dp2[i] = (int(nstring[i]) * mul + dp2[i + 1]) % b
		mul = mul * 10 % b
	return dp2
nstring = stdin.readline().strip()
(a, b) = list(map(int, stdin.readline().split()))
if len(nstring) == 1:
	print('NO')
	return
dp1 = cal_first(nstring, a)
dp2 = cal_second(nstring, b)
for i in range(len(dp1) - 1):
	if dp1[i] == 0 and dp2[i + 1] == 0:
		if check_leading_zero(nstring, i + 1):
			print('YES')
			print(nstring[:i + 1])
			print(nstring[i + 1:])
			return
else:
	print('NO')


def main():
	(s, x, pfx) = (input(), 0, [])
	(a, b) = map(int, input().split())
	try:
		for (i, c) in enumerate(s, 1):
			x = (x * 10 + int(c)) % a
			if not x and s[i] != '0':
				pfx.append(i)
	except IndexError:
		pass
	(x, p, i) = (0, 1, len(s))
	for j in reversed(pfx):
		for i in range(i - 1, j - 1, -1):
			x = (x + int(s[i]) * p) % b
			p = p * 10 % b
		if not x:
			print('YES')
			print(s[:i])
			print(s[i:])
			return
	print('NO')
main()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
n = input()[:-1]
(a, b) = I()
l = []
d = [-1] * len(n)
a1 = b1 = 0
po = 0
x = str(n)
le = len(x)
for i in x:
	i = int(i)
	mu = pow(10, po, b)
	a1 = (a1 * 10 + i) % a
	b1 = (b1 + int(x[le - po - 1]) * mu) % b
	l.append(a1)
	d[le - po - 1] = b1
	po += 1
for i in range(le - 1):
	if x[i + 1] != '0' and l[i] == 0 and (d[i + 1] == 0):
		print('YES')
		print(x[:i + 1])
		print(x[i + 1:])
		break
else:
	print('NO')


s = input()
(a, b) = list(map(int, input().split()))
n = len(s)
flag = 0
p = 0
pfx = []
for (i, c) in enumerate(s, 1):
	p = (p * 10 + int(c)) % a
	if i < n and p == 0 and (s[i] != '0'):
		pfx.append(i)
q = 0
p = 1
i = len(s)
for j in reversed(pfx):
	for i in range(i - 1, j - 1, -1):
		q = (q + int(s[i]) * p) % b
		p = p * 10 % b
	if not q:
		print('YES')
		print(s[:i])
		print(s[i:])
		return
print('NO')


import math
s = input()
I = lambda : list(map(int, input().strip().split(' ')))
(a, b) = I()
n = len(s)
na = len(str(a))
nb = len(str(b))
A = [None] * n
B = [None] * n
if int(s[:na]) >= a:
	start = na
	r = int(s[:na]) % a
else:
	start = na + 1
	r = int(s[:na + 1]) % a
A[start - 1] = r
for i in range(start, n):
	r = int(str(r) + s[i]) % a
	A[i] = r
if nb > 1 and int(s[n - nb + 1:]) >= b:
	end = n - nb + 1
elif nb == 1 and int(s[-1]) >= b:
	end = n - 1
else:
	end = n - nb
r = int(s[end:]) % b
B[end] = r
for i in range(end - 1, -1, -1):
	r = (r + pow(10, n - i - 1, b) * (int(s[i]) % b) % b) % b
	B[i] = r
out = 0
for i in range(start - 1, min(end + 1, n)):
	if i + 1 <= n - 1 and s[i + 1] != '0' and (A[i] == B[i + 1] == 0):
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		out = 1
		break
if not out:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = [int(s) for s in input()]
	(A, B) = getInts()
	pref = []
	curr = 0
	for j in range(len(N)):
		curr *= 10
		curr += N[j]
		curr %= A
		pref.append(curr)
	suff = []
	curr = 0
	for j in range(len(N) - 1, -1, -1):
		curr += pow(10, len(N) - j - 1, B) * N[j]
		curr %= B
		suff.append(curr)
	suff.reverse()
	N = list(map(str, N))
	for j in range(len(N) - 1):
		if pref[j] == 0 and suff[j + 1] == 0 and (N[j + 1] != '0'):
			print('YES')
			print(''.join(N[:j + 1]))
			print(''.join(N[j + 1:]))
			return
	print('NO')
	return
solve()


def solve(k, a, b):
	prefix = [0]
	for e in k:
		d = ord(e) - ord('0')
		prefix.append((prefix[-1] * 10 + d) % a)
	suffix = [0]
	p10 = 1
	for e in reversed(k):
		d = ord(e) - ord('0')
		suffix.append((suffix[-1] + p10 * d) % b)
		p10 = p10 * 10 % b
	n = len(k)
	for i in range(n - 1):
		if k[i + 1] != '0' and prefix[i + 1] == 0 and (suffix[n - 1 - i] == 0):
			return i + 1
k = input()
(a, b) = map(int, input().split())
res = solve(k, a, b)
if res is None:
	print('NO')
else:
	print('YES')
	print(k[:res])
	print(k[res:])


s = input()
(a, b) = map(int, input().split())
(n, m) = (len(s), 0)
(I, J) = (set(), set())
for i in range(n - 1):
	m = (10 * m + int(s[i])) % a
	if m == 0:
		I.add(i + 1)
(m, k) = (0, 1)
for i in range(1, n)[::-1]:
	(m, k) = ((m + k * int(s[i])) % b, 10 * k % b)
	if m == 0:
		J.add(i)
for i in I & J:
	if s[i] != '0':
		print('YES', s[:i], s[i:], sep='\n')
		break
else:
	print('NO')


from math import pow
s = list(input())
(a, b) = map(int, input().split())
l = len(s)
s1 = [0] * (l + 1)
s2 = [0] * (l + 1)
for i in range(l):
	s[i] = ord(s[i]) - ord('0')
p = 1
for i in range(l - 1, -1, -1):
	s1[i] = (s1[i + 1] + s[i] * p) % b
	p = p * 10 % b
p = 0
for i in range(l - 1):
	p = (p * 10 + s[i]) % a
	if p == 0 and s1[i + 1] == 0 and s[i + 1]:
		print('YES')
		print(''.join(map(str, s[:i + 1])))
		print(''.join(map(str, s[i + 1:])))
		return
print('NO')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
s = input()
(a, b) = value()
status_a = []
status_b = []
n = 0
for i in s:
	n = n + int(i)
	status_a.append(n % a)
	n = n % a * 10
n = 0
places = 1
for i in s[::-1]:
	n += int(i) * places % b
	status_b.append(n % b)
	n = n % b
	places = places * 10 % b
status_b.reverse()
for i in range(len(s) - 1):
	if status_a[i] == 0 and status_b[i + 1] == 0 and (s[i + 1] != '0'):
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		exit()
print('NO')


from bisect import *
s = input()
(a, b) = map(int, input().split())
if len(s) < len(str(a)) + len(str(b)):
	print(-1)
	exit()
ans = []
r = len(str(a))
for i in range(r - 1, len(s)):
	if i == r - 1:
		m = s[0:r]
		m = int(m)
		if int(m) >= a:
			rem = m % a
		else:
			rem = m
	else:
		m = 10 * rem + int(s[i])
		if m < a:
			rem = m
		else:
			rem = m % a
	if rem == 0:
		ans.append(i + 1)
tan = [0 for i in range(len(s))]
for i in range(len(s)):
	tan[i] = pow(10, len(s) - (i + 1), b) * (int(s[i]) % b) % b
tan[-1] %= b
for i in range(len(tan) - 2, -1, -1):
	tan[i] = tan[i + 1] + tan[i]
	tan[i] %= b
tp = []
for i in range(len(s)):
	if s[i] != '0':
		if tan[i] == 0:
			tp.append(len(s) - i)
tp.sort()
if len(tp) == 0:
	print('NO')
	exit()
for i in range(len(ans)):
	m = bisect_left(tp, len(s) - ans[i])
	if m < len(tp) and tp[m] == len(s) - ans[i] and (ans[i] < len(s)):
		print('YES')
		print(s[0:ans[i]])
		print(s[ans[i]:])
		exit()
print('NO')


import sys
l = input()
(a, b) = input().split()
a = int(a)
b = int(b)
n = len(l)
ra = []
rb = [0] * n
nn = ''
f = 0
p = 1
ra.append(int(l[0]) % a)
rb[n - 1] = int(l[n - 1]) % b
for i in range(1, n - 1):
	ra.append((ra[i - 1] * 10 + int(l[i])) % a)
for i in range(n - 2, -1, -1):
	rb[i] = (rb[i + 1] + int(l[i]) * p * 10 % b) % b
	p = p * 10 % b
for i in range(n - 1):
	if ra[i] == 0 and rb[i + 1] == 0 and (l[i + 1] != '0'):
		print('YES')
		print(l[:i + 1])
		print(l[i + 1:n])
		return
if f == 0:
	print('NO')


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		s = input()
		(a, b) = map(int, input().split())
		n = len(s)
		forward = [int(s[0]) % a] + [0] * (n - 1)
		backward = [0] * (n - 1) + [int(s[-1]) % b]
		for i in range(1, n - 1):
			forward[i] = (forward[i - 1] * (10 % a) % a + int(s[i]) % a) % a
		p = 1
		for i in range(n - 2, 0, -1):
			backward[i] = (backward[i + 1] + pow(10, p, b) * int(s[i]) % b) % b
			p += 1
		note = 0
		for i in range(1, n):
			if s[i] != '0' and forward[i - 1] == 0 and (backward[i] == 0):
				note = i
				break
		if note != 0:
			print('YES')
			print(s[:note])
			print(s[note:])
		else:
			print('NO')
	solve()
main()


s = input()
n = len(s)
dp1 = [0] * (n + 1)
dp2 = [0] * (n + 1)
(a, b) = map(int, input().split())
for i in range(n):
	dp1[i + 1] = (dp1[i] * 10 % a + int(s[i])) % a
p = 1
for i in range(n - 1, -1, -1):
	dp2[i] = (dp2[i + 1] + p * int(s[i]) % b) % b
	p = p * 10 % b
idx = -1
for i in range(0, n - 1):
	if s[i + 1] != '0' and dp1[i + 1] == 0 and (dp2[i + 1] == 0):
		idx = i
		break
if idx != -1:
	print('YES')
	print(s[:idx + 1])
	print(s[idx + 1:])
else:
	print('NO')


s = input()
(a, b) = map(int, input().split())
m = 0
ten = 1
ln = len(s)
dp = [0] * ln
now = 0
for i in range(ln):
	now = (10 * now + int(s[i])) % a
	dp[i] = now
id = ln - 1
now = 0
ten = 1
while id > 0:
	t = int(s[id])
	now = (now + ten * t) % b
	ten = ten * 10 % b
	if t != 0 and now == 0 and (dp[id - 1] == 0):
		break
	id -= 1
if id > 0:
	print('YES')
	print(s[:id])
	print(s[id:])
else:
	print('NO')


def main():
	string = input()
	(a, b) = list(map(int, input().split()))
	forward = [-1] * len(string)
	backward = [-1] * len(string)
	x = 1
	for i in range(len(string)):
		cur = int(string[i])
		j = len(string) - i - 1
		curBack = int(string[j])
		if i == 0:
			forward[i] = cur % a
			backward[j] = curBack % b
		else:
			forward[i] = (forward[i - 1] * 10 % a + cur % a) % a
			backward[j] = (backward[j + 1] + curBack * x % b) % b
		x = x * 10 % b
	done = 0
	for i in range(len(string) - 1):
		leftMod = forward[i]
		rightMod = backward[i + 1]
		if leftMod == 0 and rightMod == 0 and (int(string[i + 1]) != 0):
			print('YES')
			print(string[:i + 1])
			print(string[i + 1:])
			done = 1
			break
	if done == 0:
		print('NO')
main()


s = input()
(a, b) = map(int, input().split())
tens = 1
B = 0
A = 0
posa = [False] * (len(s) + 1)
posb = [False] * (len(s) + 1)
tens = 1
for i in range(len(s) - 1, -1, -1):
	B += int(s[i]) * tens % b
	B = B % b
	if B == 0:
		posb[i] = True
	tens = tens * 10 % b
loda = True
for i in range(len(s) - 1):
	A = A * (10 % a) % a
	A += int(s[i]) % a
	A = A % a
	if A == 0:
		posa[i] = True
for i in range(len(s)):
	if posa[i] == True and posb[i + 1] == True and (s[i + 1] != '0'):
		loda = False
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		break
if loda:
	print('NO')


import sys
from math import log2, floor, ceil, sqrt
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
s = ri()
n = len(s)
dp1 = [0] * (n + 1)
dp2 = [0] * (n + 1)
(a, b) = Ri()
for i in range(n):
	dp1[i + 1] = (dp1[i] * 10 % a + int(s[i])) % a
p = 1
for i in range(n - 1, -1, -1):
	dp2[i] = (dp2[i + 1] + p * int(s[i]) % b) % b
	p = p * 10 % b
flag = -1
for i in range(0, n - 1):
	if s[i + 1] != '0' and dp1[i + 1] == 0 and (dp2[i + 1] == 0):
		flag = i
		break
if flag != -1:
	YES()
	print(s[:flag + 1])
	print(s[flag + 1:])
else:
	NO()


from sys import stdin
t = 1

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
for __ in range(t):
	s = list(stdin.readline()[:-1])
	(a, b) = map(int, input().split())
	n = len(s)
	j = n - 1
	i = 0
	rema = [0] * n
	remb = [0] * n
	rema[0] = int(s[0]) % a
	remb[n - 1] = int(s[-1]) % b
	for i in range(1, n - 1):
		rema[i] = (rema[i - 1] * 10 + int(s[i])) % a
	p1 = 1
	for j in range(n - 2, -1, -1):
		p1 = 10 % b * (p1 % b) % b
		remb[j] = (remb[j + 1] + int(s[j]) * p1) % b
	flag = False
	for i in range(n - 1):
		if rema[i] == 0 and remb[i + 1] == 0 and (s[i + 1] != '0'):
			print('YES')
			print(''.join(s[:i + 1]))
			print(''.join(s[i + 1:]))
			flag = True
			break
	if flag == False:
		print('NO')


s = input()
(a, b) = map(int, input().split())
left = [-1 for i in range(len(s))]
right = [-1 for i in range(len(s))]
x = 0
for i in range(len(s)):
	x = (x * 10 + int(s[i])) % a
	left[i] = x % a
x = 0
m = 1
for i in reversed(range(0, len(s))):
	x = (int(s[i]) * m + x) % b
	right[i] = x % b
	m = m * 10 % b
pos = -1
for i in range(len(s) - 1):
	if left[i] == 0 and right[i + 1] == 0 and (s[i + 1] != '0'):
		pos = i
		break
if pos == -1:
	print('NO')
else:
	print('YES')
	print(s[:pos + 1])
	print(s[pos + 1:])


import sys
s = input()
n = len(s)
(a, b) = map(int, input().split())
(pref, suff) = ([0] * n, [0] * n)
curr = 0
for i in range(n):
	pref[i] = (curr * 10 % a + int(s[i])) % a
	curr = pref[i]
curr = 0
for i in reversed(range(n)):
	suff[i] = (int(s[i]) * pow(10, n - i - 1, b) % b + curr) % b
	curr = suff[i]
for i in range(n - 1):
	if pref[i] == suff[i + 1] == 0 and s[i + 1] != '0':
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		exit(0)
print('NO')


number = input()
(a, b) = list(map(int, input().split()))

def prefix_remainder(s, m):
	rem = []
	curr = 0
	for ch in s:
		curr = (curr * 10 + int(ch)) % m
		rem.append(curr)
	return rem

def suffix_remainder(s, m):
	rem = []
	(curr, mul) = (0, 1)
	for i in range(len(s) - 1, -1, -1):
		ch = s[i]
		curr = (int(ch) * mul + curr) % m
		mul = mul * 10 % m
		rem.append(curr)
	rem.reverse()
	return rem
prefix = prefix_remainder(number, a)
suffix = suffix_remainder(number, b)
for i in range(len(number)):
	if i < len(number) - 1:
		if prefix[i] == 0 and suffix[i + 1] == 0 and (number[i + 1] != '0'):
			print('YES')
			print(number[:i + 1])
			print(number[i + 1:])
			exit()
print('NO')


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, input().split()))
pb = [1]
pa = [1]
for _ in range(1):
	s = input()
	(a, b) = lst()
	p = -1
	n = len(s)
	for i in range(n + 6):
		pb += [pb[-1] * 10 % b]
		pa += [pa[-1] * 10 % a]
	rem = [0] * (1 + n)
	c = 0
	for i in range(n - 1, -1, -1):
		rem[i] = (rem[i + 1] + int(s[i]) * pb[c]) % b
		c += 1
	rem1 = [0] * (1 + n)
	c = 1
	rem1[0] = int(s[i]) % a
	for i in range(1, n):
		rem1[i] = (rem1[i - 1] * pa[c] + int(s[i])) % a
	for i in range(n - 1):
		if rem1[i] == rem[i + 1] == 0 and s[i + 1] != '0':
			p = i
	if p == -1:
		print('NO')
	else:
		print('YES', s[:p + 1], s[p + 1:], sep='\n')


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	S = input()
	(a, b) = map(int, input().split())
	s = []
	for i in S:
		if ord('0') <= ord(i) <= ord('9'):
			s.append(int(i))
	pref = []
	suff = []
	curr = 0
	for i in s:
		curr += i
		curr %= a
		pref.append(curr)
		curr *= 10
		curr %= a
	s.reverse()
	pow10 = 1
	curr = 0
	for i in s:
		curr += pow10 * i % b
		curr %= b
		suff.append(curr)
		pow10 *= 10
		pow10 %= b
	suff.reverse()
	f = 1
	s.reverse()
	for i in range(1, len(s)):
		if s[i] != 0 and (suff[i] == 0 and pref[i - 1] == 0):
			f = 0
			print('YES')
			for j in range(i):
				print(s[j], end='')
			j = i
			print('')
			while j < len(s):
				print(s[j], end='')
				j += 1
			break
	if f:
		print('NO')
	return
main()


s = input()
(a, b) = map(int, input().split())
l = len(s)
x = [0] * l
strn = '1'
i = 0
while i < l:
	v = int(strn)
	x[i] = v % b
	strn = str(v % b) + '0'
	i += 1
x.reverse()
strn = ''
y = [0] * (l + 1)
for i in range(l - 1, -1, -1):
	y[i] = (y[i + 1] + int(s[i]) * x[i]) % b
idx = -1
for i in range(l):
	strn += s[i]
	v = int(strn) % a
	if v == 0 and y[i + 1] == 0:
		idx = i + 1
		break
	strn = str(v)
if idx == -1:
	print('NO')
else:
	while idx < l and s[idx] == '0':
		idx += 1
	if idx == l:
		print('NO')
	else:
		print('YES')
		print(s[:idx])
		print(s[idx:])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
s = input()
(a, b) = L()
pref = [0 for i in range(len(s) + 1)]
suff = [0 for i in range(len(s) + 1)]
n = len(s)
for i in range(1, n + 1):
	pref[i] = (pref[i - 1] * 10 + int(s[i - 1])) % a
p = 1
for i in range(n - 1, -1, -1):
	suff[i] = (p * int(s[i]) + suff[i + 1]) % b
	p *= 10
	p %= b
for i in range(n - 1):
	if pref[i + 1] == 0 and suff[i + 1] == 0 and (s[i + 1] != '0'):
		print('YES')
		print(s[:i + 1])
		print(s[i + 1:])
		exit()
print('NO')
endtime = time.time()