Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- using namespace std;
- typedef long long int ll;
- typedef pair<int,int> pii;
- typedef vector<pii> vpii;
- typedef vector<ll> vll;
- const ll MOD = 1e9 + 7;
- /* Commonly used stuff */
- ll gcd(ll a, ll b){
- if(b == 0)
- return a;
- return gcd(b, a % b);
- }
- bool isPrime(ll n){
- if(n <= 1)
- return false;
- for(ll i = 2; i <= sqrt(n); ++i){
- if(n % i == 0)
- return false;
- }
- return true;
- }
- ll modExp(ll b, ll e, ll mod){
- ll res = 1;
- while(e > 0){
- if(e & 1)
- res = res * b % mod;
- b = b * b % mod;
- e>>=1;
- }
- return res % mod;
- }
- ll factorial(ll n){
- ll r = 1;
- for(ll i = 1; i <= n; ++i){
- r *= i;
- }
- return r;
- }
- //////////////////////////
- /* Put globals here */
- string n, result="";
- unordered_map<string,unordered_map<int, string>> dp;
- ll r = 0;
- string go(string &a, int i, string curr, int val){
- if(i >= a.size())
- return "";
- if(dp.count(curr)){
- if(dp[curr].count(i))
- return dp[curr][i];
- }
- string withCurr = curr + a[i];
- int nextVal = ((val * 10) + (a[i] - '0')) % 8;
- if(nextVal == 0)
- return withCurr;
- string withoutResult = go(a, i + 1, curr, val);
- if(withoutResult.size() > 0)
- return dp[curr][i] = withoutResult;
- return dp[curr][i] = go(a, i + 1, withCurr, nextVal);
- }
- int main(){
- cin>>n;
- string r = go(n, 0, "", 0);
- if(r.size() > 0){
- cout<<"YES"<<endl;
- cout<<r<<endl;
- } else {
- cout<<"NO"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement