stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/*

author：cmathpo8&&yuanchen&&qiyujun

date:2019/8/17 10:11 

*/

#include<bits/stdc++.h>

#define re register

using namespace std;

int h[100010],t,cnt;

char a[100010];

struct node{

    int fro;

    int to;

}el[100010];

int main(){

       scanf("%s",a+1);

       int cntl=0;

       int sst=strlen(a+1);

       memset(h,0,sizeof(h));

       t=-1;

    for(re int i=1;i<=sst;i++){

        if(a[i]=='L'){

            if(t==-1){

                el[++cnt].fro=i;

                el[cnt].to=i;

                t=0;

            }else el[cnt].to=i;

        }else t=-1;

    } 

    el[0].to=0;

    for(re int i=1;i<=cnt;i++){

        int dis=(el[i].fro-el[i-1].to-1);

        int disl=(el[i].to-el[i].fro+1);

        if(dis%2==1){

            h[el[i].fro]+=(dis/2);

            h[el[i].fro-1]+=(dis/2)+1;

        }else{

            h[el[i].fro]+=(dis/2);

            h[el[i].fro-1]+=(dis/2);

        }

        if(disl%2==1){

            h[el[i].fro-1]+=(disl/2);

            h[el[i].fro]+=(disl/2)+1;

        }else{

            h[el[i].fro-1]+=(disl/2);

            h[el[i].fro]+=(disl/2);

        }

    }

    for(re int i=1;i<=sst;i++){

        printf("%d ",h[i]);

    } 

    /*for(re int i=1;i<=cnt;i++){

        cout<<el[i].fro<<" "<<el[i].to<<" ";

    }*/

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3630622075727439x):
#include<iostream>

#include<string>

using namespace std;

int main(){

    string s;

    cin>>s;

    int n[100000],f=0,f2=0;

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

        n[i]=1;

    }

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

        if(s[i]=='R'&&s[i+1]=='R'){

            f++;

            n[i+1]+=n[i];

            n[i]=0;

        }

        else if(s[i]=='R'&&s[i+1]=='L'){

            n[i+1]+=(f+1)/2;

            n[i]-=(f+1)/2;

            f=0;

        }

        if(s[s.length()-1-i]=='L'&&s[s.length()-i-2]=='L'){

            f2++;

            n[s.length()-i-2]+=n[s.length()-1-i];

            n[s.length()-1-i]=0;

        }

        else if(s[s.length()-i-1]=='L'&&s[s.length()-i-2]=='R'){

            n[s.length()-i-2]+=(f2+1)/2;

            n[s.length()-1-i]-=(f2+1)/2;

            f2=0;

        }

    }

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

        cout<<n[i];

        if(i<s.length()-1){

            cout<<" ";

        }

    }

    cout<<endl;

    return 0;

}
// Slower C++ solution:
/*

author：cmathpo8&&yuanchen&&qiyujun

date:2019/8/17 10:11 

*/

#include<bits/stdc++.h>

#define re register

using namespace std;

int h[100010],t,cnt;

char a[100010];

struct node{

    int fro;

    int to;

}el[100010];

int main(){

       scanf("%s",a+1);

       int cntl=0;

       int sst=strlen(a+1);

       memset(h,0,sizeof(h));

       t=-1;

    for(re int i=1;i<=sst;i++){

        if(a[i]=='L'){

            if(t==-1){

                el[++cnt].fro=i;

                el[cnt].to=i;

                t=0;

            }else el[cnt].to=i;

        }else t=-1;

    } 

    el[0].to=0;

    for(re int i=1;i<=cnt;i++){

        int dis=(el[i].fro-el[i-1].to-1);

        int disl=(el[i].to-el[i].fro+1);

        if(dis%2==1){

            h[el[i].fro]+=(dis/2);

            h[el[i].fro-1]+=(dis/2)+1;

        }else{

            h[el[i].fro]+=(dis/2);

            h[el[i].fro-1]+=(dis/2);

        }

        if(disl%2==1){

            h[el[i].fro-1]+=(disl/2);

            h[el[i].fro]+=(disl/2)+1;

        }else{

            h[el[i].fro-1]+=(disl/2);

            h[el[i].fro]+=(disl/2);

        }

    }

    for(re int i=1;i<=sst;i++){

        printf("%d ",h[i]);

    } 

    /*for(re int i=1;i<=cnt;i++){

        cout<<el[i].fro<<" "<<el[i].to<<" ";

    }*/

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3776276704811343x):
#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

char s[N];

int idxR[N], idxL[N], addup[N];

typedef pair<int, char> PII;

stack<PII> stk;

int main() {

	cin >> s;

	for (int i = 0; s[i]; i ++) {

		if (s[i] == 'R') stk.push({i, s[i]});

		else {

			while(stk.size()) {

				auto t = stk.top();

				idxR[t.first] = i - t.first;

				stk.pop();

			}

		}

	}

	int len = strlen(s);

	for (int i = len - 1; i >= 0; i --) {

		if (s[i] == 'L') stk.push({i, s[i]});

		else {

			while(stk.size()) {

				auto t = stk.top();

				idxL[t.first] = t.first - i;

				stk.pop();

			}

		}

	}



	for (int i = 0; s[i]; i ++) {

		if (s[i] == 'R') {

			if (idxR[i] % 2 == 0) addup[i + idxR[i]] ++;

			else addup[i + idxR[i] - 1] ++;

		}

		else {

			if (idxL[i] % 2 == 0) addup[i - idxL[i]] ++;

			else addup[i - idxL[i] + 1] ++;

		}

	}

	

	for (int i = 0; i < len; i ++) cout << addup[i] << " ";

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <memory.h>



using namespace std;

int main()

{

    long long n,m,a,b,c;



    cin>>n>>m;

if(n==m){

cout<<0;

return 0;

}

if(abs(m)==abs(n))

{

cout<<1;

 return 0;

}

if(n>m&&n<0&&m<0)

{

    n=n*-1;

    b=m*-1;

    cout<<b-n+2;

    return 0;

}

if(n>m&&n>=0&&m<=0 && n>abs(m))

{

    n=n*-1;

    cout<<m-n+1;

    return 0;

}

if(n>m&&n>=0&&m<=0 && n<abs(m))

{

    n=n*-1;

    cout<<abs(m)+n+1;

    return 0;

}

if(n==0 && m>0)

{

    cout<<m-n;

    return 0;

}

if(n<m && m>=0 && n<=0 && abs(n)<m )

{

    n=n*-1;

    cout<<m-n+1;

    return 0;

}

if(n<m && (n>=0 &&m>=0)|| (m<=0 && n<=0))

{

    cout<<m-n;

    return 0;

}

if(n<=0&&m>=0&&abs(n)>m)

{

    m=m*-1;

    cout<<m-n+1;

    return 0;

}

    if(n>m&&n>0&&m>0)//---------------------//

{

    n=n*-1;

    m=m*-1;

    cout<<m-n+2;

    return 0;

}



}


// Faster C++ solution for the same problem (measured speedup: 5.247505651724801x):
#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long x,y,a=0,b=0;

	bool flag;

	scanf("%lld %lld",&x,&y);

	if(abs(x)>abs(y))

	a=abs(x)-abs(y),flag=false;

	else

	a=abs(y)-abs(x),flag=true;

	if(x>=0&&flag){

		if(y<0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0&&flag){

		if(y>0)

		++b;

		else 

		b+=2;

		printf("%lld",a+b);

		return 0;

	}

	if(x>=0){

		if(y>0)

		b+=2;

		else

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0){

		if(y>0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#define MAX 505

#define ll long long

#define pb push_back

#define mk make_pair

#define sc second

#define fr first

#define pii pair < int, int >



const int N = (int)1e4 + 5;

const int INF = (int)1e9 + 7;



int main () {

        long long x, y; cin >> x >> y;

        if (x > 0 && y > 0) { // + +

                if (y > x) {

                        cout << y - x;

                } else if (y < x) {

                        cout << x - y + 2;

                }

        } else {

                if (x < 0 && y > 0) {

                        cout << abs(abs(y) - abs(x)) + 1;

                } else if (x > 0 && y < 0) {

                        cout << abs(abs(y) - abs(x)) + 1;

                } else if (x < 0 && y < 0) { // - -

                        if (abs(x) > abs(y)) {

                                cout << abs(x) - abs(y);

                        } else if (abs(x) < abs(y)) {

                                cout << abs(y) - abs(x) + 2;

                        }

                } else if (x == 0 || y == 0) {

                        if (x == 0) {

                                if (y < 0) {

                                        cout << abs(y) + 1;

                                } else if (y > 0) {

                                        cout << abs(y);

                                }

                        } else {

                                if (x < 0) {

                                        cout << abs(x);

                                } else {

                                        cout << x + 1;

                                }

                        }

                }

        }

        cout << endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.254825445709825x):
#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long x,y,a=0,b=0;

	bool flag;

	scanf("%lld %lld",&x,&y);

	if(abs(x)>abs(y))

	a=abs(x)-abs(y),flag=false;

	else

	a=abs(y)-abs(x),flag=true;

	if(x>=0&&flag){

		if(y<0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0&&flag){

		if(y>0)

		++b;

		else 

		b+=2;

		printf("%lld",a+b);

		return 0;

	}

	if(x>=0){

		if(y>0)

		b+=2;

		else

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0){

		if(y>0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	return 0;

}
// Slower C++ solution:
# include <bits/stdc++.h>

# define fr first

# define sc second

# define mk make_pair

# define pb push_back

# define ll long long



using namespace std;





main()

{

     long long a,b,c=0,h;

     cin>>a>>b;

     if (a==b){

        cout<<0;

        return 0;

     }

     if (a==0)

     {

         if (b>a)

         {

             cout<<abs(b-a);

             return 0;

         }

         else if (a>b)

         {

             cout<<abs(b-a)+1;

             return 0;

         }

     }

     if (b==0&&a<0)

     {

         cout<<abs(a-b);

         return 0;

     }

     if (a==-b){

       cout<<1;

       return 0;

     }

         if (a<=0&&b<=0){

         if (a>b){

         a=-a;

         c++;

         }

        while (a!=b){

            a++;

         c++;

        if (-a==b){

                c++;

            a=-a;

        break;

        }

        }

        cout<<c;

        return 0;

     }

     if (b>a&&a>=0&&b>=0&&-a!=b)

     {

         cout<<b-a;

         return 0;

     }

     if ((b>a&&b<=0||a<=0&&b>a)){

        c+=abs(abs(a)-abs(b))+1;

        cout<<c;

        return 0;

     }

     if (a>b&&b<=0&&a>=0)

     {

         cout<<abs(abs(a)-abs(b))+1;

         return 0;

     }

    if (a>b)

    {

        a=-a;

        c++;

        while (a!=b){

            c++;

            a++;

            if (-a==b){

                a=-a;

            c++;

            }

        }

        cout<<c;

        return 0;

    }

     /*if (a>b)

     {

         a=-a;

         while (a!=b)

         {

             if (abs(-a-abs(b))<=abs(a+1-abs(b))||a==-b){

                a=-a;

                c++;

             }

               if (a==b)

             {

                 break;

             }

             if (-(a+(abs(abs(a)-abs(b))))==b&&a>0)

             {

                 c+=(abs(abs(a)-abs(b)))+1;

                 a=-(a+(abs(abs(a)-abs(b))));

             }

       if (a==b)

             {

                 break;

             }

             if (abs(-a-abs(b))>=abs(a+1-abs(b))||-a>b){

                a++;

                c++;

             }

         }

         cout<<c+1;

         return 0;

     }

*/

}


// Faster C++ solution for the same problem (measured speedup: 5.248295793852679x):
#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long x,y,a=0,b=0;

	bool flag;

	scanf("%lld %lld",&x,&y);

	if(abs(x)>abs(y))

	a=abs(x)-abs(y),flag=false;

	else

	a=abs(y)-abs(x),flag=true;

	if(x>=0&&flag){

		if(y<0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0&&flag){

		if(y>0)

		++b;

		else 

		b+=2;

		printf("%lld",a+b);

		return 0;

	}

	if(x>=0){

		if(y>0)

		b+=2;

		else

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0){

		if(y>0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main(){

	int x,y,n,a,b;

	cin >> x >> y;

	if(y>0){

		if(x>0){

			if(y==x){

				cout << 0;

			}

			else if(y>x){

				cout << y - x;

			}

			else {

				cout << x - y + 2;

			}

		}

		else if(x==0){

			cout << y;

		}

		else {

			// x<0 and y>0

			// x=-3 and y=3, x=-2 and y=4, x=-4 and y=2 

			if(abs(y)==abs(x)){

				cout << 1;

			}

			else 

				cout << abs(abs(y) - abs(x)) + 1;

		}

	}

	else if(y==0){

		if(x>0){

			cout << x + 1;

		}

		else if(x==0) cout << 0;

		else {

			cout << -x;

		}

	}

	else {

		// y<0

		if(x>0){

			// y<0 and x>0

			// x=2 and y=-2, x=4 and y=-2, x=2 and y=-4

			if(abs(y)==abs(x)) cout << 1;

			else cout << abs(abs(x) - abs(y)) + 1;

		}

		else if(x==0) cout << abs(y) + 1;

		else {

			// y<0 and x<0

			// x=-2 and y=-2, x=-4 and y=-2, x=-2 and y=-4

			if(y==x) cout << 0;

			else if(abs(x)>abs(y)) cout << abs(x) - abs(y);

			else cout << abs(y) - abs(x) + 2;

		}

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.25125566665962x):
#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long x,y,a=0,b=0;

	bool flag;

	scanf("%lld %lld",&x,&y);

	if(abs(x)>abs(y))

	a=abs(x)-abs(y),flag=false;

	else

	a=abs(y)-abs(x),flag=true;

	if(x>=0&&flag){

		if(y<0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0&&flag){

		if(y>0)

		++b;

		else 

		b+=2;

		printf("%lld",a+b);

		return 0;

	}

	if(x>=0){

		if(y>0)

		b+=2;

		else

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0){

		if(y>0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include<complex>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



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

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

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 1000 * 1000 + 47;



int main()

{

	//freopen("in.txt", "r", stdin);

	//freopen("out.txt", "w", stdout);

	ios::sync_with_stdio(false); cin.tie(0);

	int x, y;

	cin >> x >> y;

	int res;

	if ((x >= 0 && y >= 0) || (x <= 0 && y <= 0))

	{

		res = abs(y - x);

		//cout << "!!" << res << endl;

		if (x > y)

		{

			res++;

			if (y != 0 && x != 0) res++;

		}



		cout << res << endl;

		return 0;

	}



	res = abs(x + y) + 1;



	cout << res << endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.329302173795778x):
#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long x,y,a=0,b=0;

	bool flag;

	scanf("%lld %lld",&x,&y);

	if(abs(x)>abs(y))

	a=abs(x)-abs(y),flag=false;

	else

	a=abs(y)-abs(x),flag=true;

	if(x>=0&&flag){

		if(y<0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0&&flag){

		if(y>0)

		++b;

		else 

		b+=2;

		printf("%lld",a+b);

		return 0;

	}

	if(x>=0){

		if(y>0)

		b+=2;

		else

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0){

		if(y>0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cmath>

using namespace std;

typedef long long LL;

LL a,b,ans;

int main(){

	cin>>a>>b;

	if(a==b) ans=0;

	else if(a==0){

		if(b>0) ans=b-a;

		else ans=-b+1;

	}

	else if(b==0){

		if(a<0) ans=b-a;

		else ans=a+1;

	}

	else if(a<0&&b<0){

		if(a<b) ans=b-a;

		else ans=a-b+2;

	}	

	else if(a>0&&b>0){

		if(a<b) ans=b-a;

		else ans=a-b+2;

	}

	else if(a>0&&b<0){

		ans=abs(a+b)+1;

	}

	else if(a<0&&b>0){

		ans=abs(a+b)+1;

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.255918766455256x):
#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long x,y,a=0,b=0;

	bool flag;

	scanf("%lld %lld",&x,&y);

	if(abs(x)>abs(y))

	a=abs(x)-abs(y),flag=false;

	else

	a=abs(y)-abs(x),flag=true;

	if(x>=0&&flag){

		if(y<0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0&&flag){

		if(y>0)

		++b;

		else 

		b+=2;

		printf("%lld",a+b);

		return 0;

	}

	if(x>=0){

		if(y>0)

		b+=2;

		else

		++b;

		printf("%lld",a+b);

		return 0;

	}

	if(x<0){

		if(y>0)

		++b;

		printf("%lld",a+b);

		return 0;

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cmath>

#include<string>

#include<cstdlib>

#include<algorithm>

#include<fstream>

using namespace std;

int main()

{

    int i,j,x,y,l;

//    while(777)

//    {

        scanf("%d%d",&x,&y);

    int ss=0;

    if(x<0&&y<0&&x>y)

    {

        x=fabs(x);

        y=fabs(y);

        x=y-x;

        x+=2;

        printf("%d\n",x);

           exit(0);

    }

   else if(x<y)

    {

        if(x>=0||y==0)printf("%d\n",y-x);

        else if(y<0)printf("%d\n",y-x);

        else if(x<0&&-x<y)printf("%d\n",y+x+1);

        else if(x<0&&-x>y)

        {

           printf("%d\n",-x-y+1);

        }

        else if(x<0&&-x==y)printf("%d\n",1);

        else printf("%d\n",y-x);

        exit(0);

    }

    else if(x>y)

    {

        if(y>0)

        {

            ss+=2;

            printf("%d\n",ss+x-y);

        }

        else

        {

            if(-y>x)

            {

                printf("%d\n",-x-y+1);

            }

            else

            {

                printf("%d\n",x+y+1);

            }

        }

         exit(0);

    }

//    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.189952441006361x):
#include<cstdio>

#include<algorithm>

using namespace std;

int s(int x,int y)

{

    if(x<=y) return y-x;

        else return x-y+2;

}

int main()

{

    int x,y;

    scanf("%d %d",&x,&y);

    printf("%d\n",min(s(x,y),min(s(-x,y)+1,min(s(x,-y)+1,s(-x,-y)+2))));

    return 0;

}
// Slower C++ solution:
//program luogu.AT22263

#include <iostream>

#include <cstdio>

#include <cmath>

using namespace std;

#define LL long long



LL a,b,ans;



int main() {

	scanf("%lld %lld",&a,&b);

	if( a == b ) {

		printf("0\n");

		return 0;

	}

	if( a == 0 || b == 0 ) {

		if( a > b )

			ans = a - b + 1;

		else

			ans = b - a;

	}

	else if( ( a > 0 && b < 0 ) || ( a < 0 && b > 0 ) )

		ans = abs( abs( a ) - abs( b ) ) + 1;

	else {

		if( a < b )

			ans = b - a;

		else

			ans = a - b + 2;

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.190262513429653x):
#include<cstdio>

#include<algorithm>

using namespace std;

int s(int x,int y)

{

    if(x<=y) return y-x;

        else return x-y+2;

}

int main()

{

    int x,y;

    scanf("%d %d",&x,&y);

    printf("%d\n",min(s(x,y),min(s(-x,y)+1,min(s(x,-y)+1,s(-x,-y)+2))));

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>



#define	mp			make_pair

#define	rep(i,n)	for(int i=0;i<n;i++)



using namespace std;



typedef	vector<int>		vi;

typedef	pair<int,int>	pii;



class UnionFind{

	vi a;

	int root(int x){ return ~a[x]?a[x]=root(a[x]):x; }

public:

	UnionFind(int n):a(n,-1){}

	bool find(int x,int y){ return root(x)==root(y); }

	bool unite(int x,int y){ return find(x,y)?0:(a[root(y)]=root(x),1); }

};



int main(){

	for(int m,n;scanf("%d%d",&n,&m),n;){

		pair<int,pii> packet[20000];

		rep(i,m)	scanf("%d%d%d",&packet[i].first,&packet[i].second.first,&packet[i].second.second);

		sort(packet,packet+m);



		int ans=1;

		UnionFind link(n+1);

		rep(i,m){

			int src=packet[i].second.first,dst=packet[i].second.second;

			if(link.find(1,src))	ans+=link.unite(src,dst);

		}

		printf("%d\n",ans);

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.47748515332337x):
#include<cstdio>

#include<algorithm>



#define	mp			make_pair

#define	rep(i,n)	for(int i=0;i<n;i++)



using namespace std;



typedef	pair<int,int>	pii;



int main(){

	for(int m,n;scanf("%d%d",&n,&m),n;){

		pair<int,pii> packet[20000];

		rep(i,m)	scanf("%d%d%d",&packet[i].first,&packet[i].second.first,&packet[i].second.second);

		sort(packet,packet+m);



		bool flg[20000]={};	flg[0]=true;

		rep(i,m){

			int src=packet[i].second.first-1,dst=packet[i].second.second-1;

			flg[dst]|=flg[src];

		}

		printf("%d\n",count(flg,flg+n,true));

	}



	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

ll a[100022];

//ll b[100022];

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>a[i];

       // b[i]=a[i]*2;

    }

    int sum=1;

    sort(a,a+n);

    ll maxx=a[0];

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

    {

        if(maxx*2>=a[i])

        {

            sum++;

            maxx+=a[i];

        }

        else

        {

            sum=1;

            maxx+=a[i];

        }

    }

    cout<<sum<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.037771759002082x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int i,n,a[100005],temp=1;

	long long sum;

	scanf("%d",&n);

	for(i=0;i<n;i++)

	 scanf("%d",&a[i]);

	sort(a,a+n);

	sum=(long long)a[0];

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

	{

		if(sum*2<(long long)a[i])

		{

		   temp=1;

		   sum+=(long long)a[i];

		}

		else

		{

			temp++;

			sum+=(long long)a[i];

		}	

	}

   printf("%d\n",temp);

}
// Slower C++ solution:
#include <map>

#include <cmath>

#include <stack>

#include <queue>

#include <string>

#include <vector>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

#define lld long long

#define llu unsigned long long



using namespace std;

long long n,i,s,c,a[100010];

int main()

{



	scanf("%lld",&n);

	for(i=0;i<n;i++)

		scanf("%lld",&a[i]);

	sort(a,a+n);

	for(c=1,s=i=0;i<n-1;i++)

	{

		s+=a[i];

		if(s*2>=a[i+1])			

			c++;

		else

			c=1;			

	}

	printf("%lld\n",c);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.962168836697537x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int i,n,a[100005],temp=1;

	long long sum;

	scanf("%d",&n);

	for(i=0;i<n;i++)

	 scanf("%d",&a[i]);

	sort(a,a+n);

	sum=(long long)a[0];

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

	{

		if(sum*2<(long long)a[i])

		{

		   temp=1;

		   sum+=(long long)a[i];

		}

		else

		{

			temp++;

			sum+=(long long)a[i];

		}	

	}

   printf("%d\n",temp);

}