stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

#define INF 1e9



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef vector < pair<int, int> > vii;

typedef long double ld;

typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



ll n, x, par[100001], siz[100001], ans, cnt, dp[100001];

priority_queue<int, vector<int> > pq[100001];

queue <int> q;



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cin >> n;

	for(int i = 2; i <= n; i++){

		cin >> par[i];

		siz[par[i]]++;

	}

	for(int i = 2; i <= n; i++){

		if(siz[i]==0){

			q.push(i);

		}

	}

	while(!q.empty()){

		x=q.front();

		q.pop();

		cnt=1;

		while(!pq[x].empty()){

			dp[x]=max(dp[x],pq[x].top()+cnt);

			cnt++;

			pq[x].pop();

		}

		pq[par[x]].push(dp[x]);

		siz[par[x]]--;

		if(siz[par[x]]==0 && x!=1){

			q.push(par[x]);

		}

	}

	cout << dp[1];

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<map>

#include<algorithm>

#include<vector>

using namespace std;

#define MAXN 100005

int n,t[MAXN];

vector<int> G[MAXN];

void dfs(int u,int f)

{

	map<int,int> cnt;

	for(int i=0;i<G[u].size();i++)

	{

		int v=G[u][i];

		if(v==f) continue;

		dfs(v,u);

		cnt[t[v]]++;

	}

	map<int,int>::iterator it;

	for(it=cnt.begin();it!=cnt.end();it++)

	{

		if(it->second>1)

			cnt[(it->first)+1]+=it->second-1;

	}

	//父亲每个时刻只能找一个儿子打 剩下的儿子要推到后面

	if(it!=cnt.begin())//表示有儿子，进去过循环

		it--,t[u]=it->first+1;

}

int main()

{

	scanf("%d",&n);

	for(int i=2;i<=n;i++)

	{

		int x;

		scanf("%d",&x);

		G[i].push_back(x);

		G[x].push_back(i);

	}

	dfs(1,0);

	printf("%d\n",t[1]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

using namespace std;

#define INF (1<<24)

int N;

int t[500],sum[500];

int dp[500][500];

 

int calc(int X,int Y){

 

  int res=0,c=-1,a,b;

  for(int I=0;I<50;I++){

 

    if(c==-1||c+a+b<10)c=0;

    else c=1;

    a=X%10;

    b=Y%10;

    X/=10;

    Y/=10;

    res+=(a*b+c);

  }

 

  return res;

}

int solve(int l,int r){

 

  if(dp[l][r]!=-1)return dp[l][r];

  if(l==r)return 0;

  int res=INF;

  for(int i=l;i<r;i++){

    

    res=min(res, solve(l,i)+solve(i+1,r)+calc(sum[i]-sum[l-1],sum[r]-sum[i]));

  }

 

  return dp[l][r]=res;

}

 

void init(){

  for(int i=0;i<500;i++){

    t[i]=sum[i]=0;

    for(int j=0;j<500;j++)dp[i][j]=-1;

  }

}

 

int main(){

  init();

  cin>>N;

  for(int i=1;i<=N;i++){

    cin>>t[i];

    sum[i]=t[i]+sum[i-1];

  }

 

  cout<<solve(1,N)<<endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



int N;

int a[305],b[305];

int dp[305][305];

int sum[305][305];



int calc(int x,int y){

  int res=0,c=0;



  while(x>0||y>0){

    int px=x%10,py=y%10;

    res+=( px*py + c );

    if(px+py+c<10)c=0;

    else c=1;

    x/=10;

    y/=10;

  }



  return res+c;

}



int solve(int l,int r){

  if(dp[l][r]!=-1)return dp[l][r];

  if(l==r)return 0;

  

  int res=1e8;

  for(int i=l;i<r;i++){

    res=min(res,solve(l,i)+solve(i+1,r)+calc(b[i]-b[l-1],b[r]-b[i]));

  }

  

  return dp[l][r]=res;

}



int main(){

  memset(dp,-1,sizeof(dp));

  cin>>N;

  for(int i=1;i<=N;i++){

    cin>>a[i];

    b[i]=a[i]+b[i-1];

  }





  cout<<solve(1,N)<<endl;

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

using namespace std;



double mysqrt(double x){

	double l = 0 , r = x ;

	for(int i = 0 ; i < 64 ; i++){

		double m = (l+r)/2.0;

		if(m * m < x){

			l = m;

		}else{

			r = m;

		}

	}

	return l;

}





int main(){

	int p,n;

	while(cin >> p >> n , n){

		double sp = mysqrt(p);

		int a1 = 0 , b1 = 1 , a2 = p , b2 = 1;

		

		for(int i = 1 ; i <= n ; i++){

		

			int l = 0 , r = n;

			

			for(int x = 0 ; x < 50 ; x++){

				int m = (l+r+1)/2;

				if( (double)m/i < sp){

					if(__gcd(m,i)==1){

						if(m*b1 > a1*i){

							a1 = m;

							b1 = i;

						}

					}

					l = m;

				}else{

					r = m-1;

				}

			}

	

			l = 0 , r = n;

			for(int x = 0 ; x < 50 ; x++){

				int m = (l+r)/2;

				if( (double)m/i > sp){

					if(__gcd(m,i)==1){

						if(m*b2 < a2*i){

							a2 = m;

							b2 = i;

						}

					}

					r = m;

				}else{

					l = m+1;

				}

			}

			

		}



		cout << a2<< "/" << b2 << " " << a1 << "/" << b1 << endl;

	}

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

using namespace std;



double mysqrt(double x){

	double l = 0 , r = x ;

	for(int i = 0 ; i < 64 ; i++){

		double m = (l+r)/2.0;

		if(m * m < x){

			l = m;

		}else{

			r = m;

		}

	}

	return l;

}





int main(){

	int p,n;

	while(cin >> p >> n , n){

		double sp = mysqrt(p);

		int a1 = 0 , b1 = 1 , a2 = p , b2 = 1;

		

		for(int i = 1 ; i <= n ; i++){

			int o = (int)(sp * i);

			for(int j = 0 ; j <= 1 ; j++){

				int w = o + j;

				if(__gcd(i,w) == 1 && w >= 0 && w <= n){

					if( (double)w/i < sp &&  a1*i < w*b1){

						a1 = w;

						b1 = i;

					}

					if((double)w/i > sp && a2*i > w*b2){

						a2 = w;

						b2 = i;

					}

				}

			}

		}



		cout << a2<< "/" << b2 << " " << a1 << "/" << b1 << endl;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define INF 1e9



class Fraction{

public:;

  double numerator,denominator;

  double div();

};



double Fraction::div(){

  return numerator/denominator;

}



ostream &operator << (ostream &os,const Fraction &f){

  os << f.numerator << '/' << f.denominator;

  return os;

}



int main(){

  double p;

  int n;

  while(cin >> p >> n, p){

    p = sqrt(p);

    Fraction a = (Fraction){-1,1};

    Fraction b = (Fraction){INF,1};

    for(int den = 1 ; den <= n ; den++){

      int l = 0, r = n+1;

      for(int i = 0 ; i < 150 ; i++){

        double mid = (l + r) / 2;

        if(mid < p*den){

          if(mid/den > a.div()){

            a = (Fraction){mid,den};

          }

          l = mid;

        }else{

          r = mid;

        }

      }

      l = 0, r = n+1;

      for(int i = 0 ; i < 150 ; i++){

        double mid = (l + r) / 2;

        if(mid > p*den){

          if(mid/den < b.div()){

            b = (Fraction){mid,den};

          }

          r = mid;

        }else{

          l = mid;

        }

      }

    }

    cout << b << " " << a << endl;

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



#define INF 1e9



class Fraction{

public:;

  double numerator,denominator;

  double div();

};



double Fraction::div(){

  return numerator/denominator;

}



ostream &operator << (ostream &os,const Fraction &f){

  os << f.numerator << '/' << f.denominator;

  return os;

}



int main(){

  double p;

  int n;

  while(cin >> p >> n, p){

    p = sqrt(p);

    Fraction a = (Fraction){-1,1};

    Fraction b = (Fraction){INF,1};

    for(int den = 1 ; den <= n ; den++){

      int l = 0, r = n+1;

      while(l < r){

        double mid = (l + r) / 2;

        if(mid < p*den){

          if(mid/den > a.div()){

            a = (Fraction){mid,den};

          }

          l = mid+1;

        }else{

          r = mid;

        }

      }

      l = 0, r = n+1;

      while(l < r){

        double mid = (l + r) / 2;

        if(mid > p*den){

          if(mid/den < b.div()){

            b = (Fraction){mid,den};

          }

          r = mid;

        }else{

          l = mid+1;

        }

      }

    }

    cout << b << " " << a << endl;

  }

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string.h>

#include<string>

using namespace std;

int main()

{

	long long n;

	while (cin >> n)

	{

		long long m=0;

		n++;

		while (n > 9)

		{

			m += 9;

			n = n / 10;

		}

		cout << m + n - 1 << endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <cmath>

#include <queue>

#include <set>

#include <map>

#include <algorithm>

using namespace std;

char num[20];

int main()

{

	while(~scanf("%s",num))

	{

		int len=strlen(num);

		int i=len-1;

		for(;i>=0;i--)

		{

			if(num[i]!='9') break;

		}

		if(i==-1) printf("%d\n",len*9);

		else if(i==0) printf("%d\n",(len-1)*9+num[0]-'0');

		else printf("%d\n",(len-1)*9+num[0]-'0'-1);

	}

	return 0;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <map>

#include <cmath>

#include <queue>

#include <utility>

#include <functional>

#include <deque>

#include <cctype>

#include <stack>

#include <bitset>



using ll = long long;

typedef unsigned long long ull;

typedef std::pair<ll, ll>p;

struct edge { int to, cost; };

std::vector<int>G[100000];

std::vector<int>I[100000];



ll min(ll a, ll b) {

	if (a >= b)return b;

	else return a;

}

ll max(ll a, ll b) {

	if (a >= b)return a;

	else return b;

}

ll gcd(ll a, ll b) {

	if (b == 0) return a;

	return gcd(b, a%b);

}

ll lcm(ll a, ll b) {

	ll g = gcd(a, b);

	return a / g * b;

}



const ll Z = 1000000007;

const ll INF = 1 << 30;

const ll INF2 = 9000000000000000000LL;

bool flag = true;

bool fl = false;

bool f = false;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };



int main() {

	ll n, ans = 0;

	std::cin >> n;

	std::string s, t;

	s = std::to_string(n);

	t = s;

	for (int i = 0;i < s.size()-1;i++) {

		if (flag) {

			if (s[i + 1] - '0' != 9) {

				int a = s[i] - '0' - 1;

				s[i] = a + '0';

				s[i + 1] = '9';

			}

			else s[i + 1] = '9';

		}

		else s[i + 1] = '9';

		if (s < t)flag = false;

	}

	for (int i = 0;i < s.size();i++) {

		ans += s[i] - '0';

	}

	std::cout << ans << std::endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <map>

#include <cmath>

#include <queue>

#include <utility>

#include <functional>

#include <deque>

#include <cctype>

#include <stack>

#include <bitset>

#include <set>



using namespace std;

using ll = long long;

typedef unsigned long long ull;

typedef pair<ll, ll> P;

typedef pair<ll, pair<ll, ll>> PP;



const ll MOD = 1e9 + 7;

const ll INF = 1 << 30;

const ll INF2 = 9e18;

const double INF3 = 9e14;

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };

#define ALL(x) (x).begin(),(x).end()

#define pb push_back

#define fr first

#define sc second







int main() {

	ll sum = 0;

	string s;

	cin >> s;

	for (int i = 0;i < s.size();i++) {

		sum += s[i] - '0';

	}

	cout << max(sum, (ll)(s[0] - '0' - 1 + (s.size() - 1) * 9)) << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <map>

#include <cmath>

#include <queue>

#include <utility>

#include <functional>

#include <deque>

#include <cctype>

#include <stack>

#include <bitset>



using ll = long long;

typedef unsigned long long ull;

typedef std::pair<ll, ll>p;

struct edge { int to, cost; };

std::vector<int>G[100000];

std::vector<int>I[100000];



ll min(ll a, ll b) {

	if (a >= b)return b;

	else return a;

}

ll max(ll a, ll b) {

	if (a >= b)return a;

	else return b;

}

ll gcd(ll a, ll b) {

	if (b == 0) return a;

	return gcd(b, a%b);

}

ll lcm(ll a, ll b) {

	ll g = gcd(a, b);

	return a / g * b;

}



const ll Z = 1000000007;

const ll INF = 1 << 30;

const ll INF2 = 9000000000000000000LL;

bool flag = true;

bool fl = false;

bool f = false;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };



int main() {

	ll ans = 0;

	std::string s, t;

	std::cin >> s;

	t = s;

	for (int i = 0;i < s.size() - 1;i++) {

		if (flag) {

			if (s[i + 1] - '0' != 9) {

				int a = s[i] - '0' - 1;

				s[i] = a + '0';

				s[i + 1] = '9';

			}

			else s[i + 1] = '9';

		}

		else s[i + 1] = '9';

		if (s < t)flag = false;

	}

	for (int i = 0;i < s.size();i++) {

		ans += s[i] - '0';

	}

	std::cout << ans << std::endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <algorithm>

#include <iomanip>

#include <vector>

#include <map>

#include <cmath>

#include <queue>

#include <utility>

#include <functional>

#include <deque>

#include <cctype>

#include <stack>

#include <bitset>

#include <set>



using namespace std;

using ll = long long;

typedef unsigned long long ull;

typedef pair<ll, ll> P;

typedef pair<ll, pair<ll, ll>> PP;



const ll MOD = 1e9 + 7;

const ll INF = 1 << 30;

const ll INF2 = 9e18;

const double INF3 = 9e14;

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };

#define ALL(x) (x).begin(),(x).end()

#define pb push_back

#define fr first

#define sc second







int main() {

	ll sum = 0;

	string s;

	cin >> s;

	for (int i = 0;i < s.size();i++) {

		sum += s[i] - '0';

	}

	cout << max(sum, (ll)(s[0] - '0' - 1 + (s.size() - 1) * 9)) << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    long int n,i;

    int a,flag=0;



    cin>>n;

    cin>>a;



    for(i=a;i>=0;i--){

        if((n-i)%500==0){

            flag=1;

            break;

        }



    }

    if(flag==1){cout<<"Yes"<<endl;}

    else {cout<<"No"<<endl;}

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()

{

    int n,a,num;



    scanf("%d %d",&n,&a);



    if(n<500)

    {

        if(a>=n)

            printf("Yes");

        else

            printf("No");

    }



    else

    {

        num = n%500;



        if(a>=num)

            printf("Yes");

        else

            printf("No");

    }



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

int n;



int a;



cin>>n;

cin>>a;

n = n%500;

if(a>=n){

cout<<"Yes"<<endl;

}else{

cout<<"No"<<endl;



}

return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()

{

    int n,a,num;



    scanf("%d %d",&n,&a);



    if(n<500)

    {

        if(a>=n)

            printf("Yes");

        else

            printf("No");

    }



    else

    {

        num = n%500;



        if(a>=num)

            printf("Yes");

        else

            printf("No");

    }



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

//#include <stdlib.h>

//#include <string.h>



using namespace std;



int main()

{

    int n,m;

    cin>>n;

    cin>>m;

    n=n%500;

    if(n>m)

        cout<<"No";

    else

        cout<<"Yes";



    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()

{

    int N, A, remainder;



    scanf("%d %d", &N, &A);



    remainder = N % 500;



    if(remainder <= A)

        printf("Yes\n");

    else

        printf("No\n");



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

using namespace std;



int main() {

	

	int a, b;

	cin >> a >> b;

	if (a % 500 <= b) cout << "Yes" << endl;

	else cout << "No" << endl;

	

}


// Optimized solution to the same problem (faster):
#include <stdio.h> 





int main() 



{



long int n,a,e; 



scanf("%ld %ld",&n,&a); 



if(n<500 && n>a)

{

printf("No\n"); 

}

else if(n>=500) 

{

e=n%500; 

if(e==0 || e<=a) 

{ 

printf("Yes\n"); 

}

else if(e>a) 

{

printf("No\n"); 

}

}

else if(n<=a)

{

printf("Yes\n"); 

} 

return 0; 

}  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){

  ios::sync_with_stdio(0);

  int n, a;

  cin >> n >> a;

  int k = n%500;

    if(k<=a)

        cout << "Yes" << endl;

    else

        cout << "No" << endl;

}


// Optimized solution to the same problem (faster):
#include <stdio.h> 





int main() 



{



long int n,a,e; 



scanf("%ld %ld",&n,&a); 



if(n<500 && n>a)

{

printf("No\n"); 

}

else if(n>=500) 

{

e=n%500; 

if(e==0 || e<=a) 

{ 

printf("Yes\n"); 

}

else if(e>a) 

{

printf("No\n"); 

}

}

else if(n<=a)

{

printf("Yes\n"); 

} 

return 0; 

}  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int n,a;

    cin>>n>>a;

    if(a>=n%500)

        cout<<"Yes"<< endl;

    else

        cout<<"No"<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h> 





int main() 



{



long int n,a,e; 



scanf("%ld %ld",&n,&a); 



if(n<500 && n>a)

{

printf("No\n"); 

}

else if(n>=500) 

{

e=n%500; 

if(e==0 || e<=a) 

{ 

printf("Yes\n"); 

}

else if(e>a) 

{

printf("No\n"); 

}

}

else if(n<=a)

{

printf("Yes\n"); 

} 

return 0; 

}  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define nl cout<<'\n';

int main()

{

    long long x,a;

    cin>>x>>a;

    x=x%500;

    if(x<=a)

      cout<<"Yes";

    else

      cout<<"No";

    nl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h> 





int main() 



{



long int n,a,e; 



scanf("%ld %ld",&n,&a); 



if(n<500 && n>a)

{

printf("No\n"); 

}

else if(n>=500) 

{

e=n%500; 

if(e==0 || e<=a) 

{ 

printf("Yes\n"); 

}

else if(e>a) 

{

printf("No\n"); 

}

}

else if(n<=a)

{

printf("Yes\n"); 

} 

return 0; 

}  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <iostream>

#include<math.h>

#include<string>

#include<iomanip>

#include <numeric>

#include <limits>

using namespace std;

 

int main()

{

int n,a; cin>>n>>a;

if(n-(n/500)*500 <= a) cout<<"Yes";

else cout<<"No";

return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h> 





int main() 



{



long int n,a,e; 



scanf("%ld %ld",&n,&a); 



if(n<500 && n>a)

{

printf("No\n"); 

}

else if(n>=500) 

{

e=n%500; 

if(e==0 || e<=a) 

{ 

printf("Yes\n"); 

}

else if(e>a) 

{

printf("No\n"); 

}

}

else if(n<=a)

{

printf("Yes\n"); 

} 

return 0; 

}  

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<algorithm>

#include<iostream>

#include<cstdlib>

#include<cstring>

#include<vector>

#include<string>

#include<cstdio>

#include<cctype>

#include<queue>

#include<stack>

#include<cmath>

#include<ctime>

#include<set>

#include<map>



using namespace std;



int main() {

	int n,a;

	cin>>n>>a;

	cout<<(n%500<=a?"Yes":"No");

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

int A,C;

int main()

{

	scanf("%d%d",&A,&C);

	A-=A/500*500;

	if(C>=A) printf("Yes\n");

	else printf("No\n");

	return 0;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<bits/stdc++.h>

#define fi first

#define sc second

#define pb push_back





using namespace std;

 

 

int N, A;

int main() { 

	

	cin >> N >> A;

	N -= (500 * (N / 500));

	if (N > A) cout << "No\n";

	else cout << "Yes\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int a,n,i,j,s,r;

    scanf("%d%d", &n, &a);

    if(n<=a)

        printf("Yes\n");

    else

    {

        if(n%500<=a)

            printf("Yes\n");

        else

            printf("No\n");

    }



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main(){

    int n,a;

    cin >> n >> a;

    if ((n % 500) <= a) {

        cout << "Yes" << endl;

    } else {

        cout << "No" << endl;

    }

    

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int a,n,i,j,s,r;

    scanf("%d%d", &n, &a);

    if(n<=a)

        printf("Yes\n");

    else

    {

        if(n%500<=a)

            printf("Yes\n");

        else

            printf("No\n");

    }



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// Author : MohamedSameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

#define SZ(a) (int)a.size()

void fo (){fflush(stdout);}

using namespace std;



int main ()

{

  int n , m ;

  cin >> n >> m ;

  n%=500 ;

  if (n <= m )

  {

    cout <<"Yes\n";

  }else

  cout <<"No\n"; 

  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

  return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int a,n,i,j,s,r;

    scanf("%d%d", &n, &a);

    if(n<=a)

        printf("Yes\n");

    else

    {

        if(n%500<=a)

            printf("Yes\n");

        else

            printf("No\n");

    }



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std ;

#define ll long long

inline int D(){

    int t ;

    scanf( "%d" , &t ) ;

    return t ;

}

inline ll LLD(){

    ll t ;

    scanf( "%lld" , &t ) ;

    return t ;

}





//#########################################









int main() {



    int a=D(),b=D();

    if(b>=(a%500)){

        cout<<"Yes";



    } else cout<<"No";





}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int a,n,i,j,s,r;

    scanf("%d%d", &n, &a);

    if(n<=a)

        printf("Yes\n");

    else

    {

        if(n%500<=a)

            printf("Yes\n");

        else

            printf("No\n");

    }



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main()

{

   int n,a,s;

   cin>>n>>a;



   s=n%500;

   if(s<=a)

    cout<<"Yes";

    else cout<<"No";

   return 0;

   }

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int a,n,i,j,s,r;

    scanf("%d%d", &n, &a);

    if(n<=a)

        printf("Yes\n");

    else

    {

        if(n%500<=a)

            printf("Yes\n");

        else

            printf("No\n");

    }



}


// Fastest known solution for this problem: