C. Divisibility by Eight

链接:https://codeforces.com/contest/550/problem/C

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

Output

Print "NO" (without quotes), if there is no such way to remove some digits from number n.

Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Examples

input

Copy

3454

output

Copy

YES
344

input

Copy

10

output

Copy

YES
0

input

Copy

111111

output

Copy

NO

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,min1=1e9+7,a;
string s;
double m[1000001],b[1000001];
int main()
{
    cin>>s; 
	s="00"+s; 
	n=s.size();
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				a=(s[i]-'0')*100 + (s[j]-'0')*10 + (s[k]-'0');
				if(a%8==0)
				{
					cout<<"YES"<<endl<<a; 
					return 0;
				}
			}
		}
	}
	cout<<"NO";
}

 

全部评论

相关推荐

皮格吉:不,有的厂子面试无手撕,可以试试。都是一边学一边面。哪有真正准备好的时候,别放弃
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务