stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include <algorithm>

using namespace std;



int N;



typedef long long ll;



ll T = 0,AO = 0,ans=0;



struct Data {

  ll  A[100000];

  ll  B[100000];

  ll  C[100000];

};



int main() {

  cin >> N;

  Data data;

  for ( int i = 0; i < 100000; i++ ) data.C[i] = 0;

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

    cin >> data.A[i] >> data.B[i];

    data.C[i] = data.A[i] + data.B[i];

  }



  sort(data.C,data.C+N);



  for ( int i = 0; i < N; i++ ) ans -= data.B[i];

  

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

    ans += data.C[i];

  }



  cout << ans << endl;

  

  return 0;

}


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

#include <algorithm>

#include <vector>

using namespace std;



int N;



typedef long long ll;



ll T = 0,AO = 0,ans = 0;



struct Data {

  ll  A,B,C;

};



int main() {

  cin >> N;

  vector<Data> data(N);

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

    cin >> data[i].A >> data[i].B;

    data[i].C = data[i].A + data[i].B;

  }



   sort(data.begin(),data.end(),[](const Data &l, const Data&r){

  				 return (l.C > r.C); });

 

  

 bool f = true;

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

    if (f)  {

      T += data[i].A;

       f = false;

    }

    else {

      AO += data[i].B;

       f = true;

    }

  }

  ans = T - AO;

    cout << ans << endl;

  

  return 0;

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

#include <algorithm>

using namespace std;



int N;



typedef long long ll;



ll T = 0,AO = 0,ans=0;



struct Data {

  ll  A[100000];

  ll  B[100000];

  ll  C[100000];

};



int main() {

  cin >> N;

  Data data;

  for ( int i = 0; i < 100000; i++ ) data.C[i] = 0;

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

    cin >> data.A[i] >> data.B[i];

    data.C[i] = data.A[i] + data.B[i];

  }



  sort(data.C,data.C+N);



  for ( int i = 0; i < N; i++ ) ans += data.A[i];

  

  for ( int i = N-2; i >= 0; i-=2 ) {

    ans -= data.C[i];

  }



  cout << ans << endl;

  

  return 0;

}


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

#include <algorithm>

#include <vector>

using namespace std;



int N;



typedef long long ll;



ll T = 0,AO = 0,ans = 0;



struct Data {

  ll  A,B,C;

};



int main() {

  cin >> N;

  vector<Data> data(N);

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

    cin >> data[i].A >> data[i].B;

    data[i].C = data[i].A + data[i].B;

  }



   sort(data.begin(),data.end(),[](const Data &l, const Data&r){

  				 return (l.C > r.C); });

 

  

 bool f = true;

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

    if (f)  {

      T += data[i].A;

       f = false;

    }

    else {

      AO += data[i].B;

       f = true;

    }

  }

  ans = T - AO;

    cout << ans << endl;

  

  return 0;

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

using namespace std;



const int N = 36666, MOD = 1e9 + 7;

bool isnp[N];

vector<int> pri;

int val[N];

int fpow(int a, int b) {

  int ans = 1;

  for(; b > 0; b >>= 1, a = 1ll * a * a % MOD) {

    if(b & 1) {

      ans = 1ll * ans * a % MOD;

    }

  }

  return ans;

}



int main() {

  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

  isnp[0] = isnp[1] = true;

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

    if(!isnp[i]) {

      pri.push_back(i);

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

        isnp[j] = true;

      }

    }

  }

  int n; cin >> n;

  vector<int> v(n), oth;

  for(auto &x: v) {

    cin >> x;

    int t = x;

    for(int i = 0; i < int(pri.size()) && pri[i] <= t; i++) {

      if(t % pri[i] == 0) {

        int cnt = 0;

        while(t % pri[i] == 0) {

          t /= pri[i];

          cnt++;

        }

        val[i] = max(val[i], cnt);

      }

    }

    if(t > 1) {

      oth.push_back(t);

    }

  }

  sort(oth.begin(), oth.end());

  oth.erase(unique(oth.begin(), oth.end()), oth.end());

  int lcm = 1;

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

    lcm = 1ll * lcm * fpow(pri[i], val[i]) % MOD;

  }

  for(auto &x: oth) lcm = 1ll * lcm * x % MOD;

  int ans = 0;

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

    ans += 1ll * lcm * fpow(v[i], MOD - 2) % MOD;

    if(ans >= MOD) ans -= MOD;

  }

  cout << ans << "\n";

}


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

#include<string>

#include<set>

#include<algorithm>

#include<vector>

#include<map>

#include<queue>

#include<iomanip>

#include<cmath>

#include<stack>

#define endl '\n'

#define Bedoazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



using namespace std;



const long long mod = 1e9 + 7, N = 1e6 + 5;



long long fact[N], inv[N],  mix = 0, numbers[N];



map<long long, long long>factors;





long long fastpower(int base, int power) {



	if (power == 0)

		return 1;



	long long halfpower = fastpower(base, power / 2) ;



	long long ret = (halfpower * halfpower) % mod;



	if (power % 2) {



		ret = (ret * base) % mod;

	}

	return ret;





}





void primeFactors(long long n) {



	long long fact;



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



		fact = 0;



		while (n % i == 0) {



			fact++;



			n /= i;





		}

		if (factors[i] < fact) {



			factors[i] = fact;



		}









	}

	

	if (n > 1 && factors[n] < 1 ) {



		factors[n] = 1;



	}





	return;





}





int main() {



	Bedoazim



		long long n;



	cin >> n;



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





		cin >> numbers[i];



		primeFactors(numbers[i]);



	}





	long long lcm = 1;



	for (auto x : factors) {



		lcm =((lcm%mod)*(fastpower(x.first, x.second)%mod))%mod;

		



	}



	long long ans = 0;



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



		ans = ((ans%mod) + ((lcm * fastpower(numbers[i], mod - 2)) % mod)) % mod;



	}



	cout << ans%mod;





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

using namespace std;

#define ll long long

#define ull unsigned long long

#define mp make_pair

const ll mod=1e9+7;

typedef pair<int,int> pii;

typedef priority_queue<int,vector<int>,greater<int> > small_heap;

typedef priority_queue<int> big_heap;

int n;

ll a[10009];

ll mx[1000006];

ll power(ll aa,ll b)

{

    ll c=1;

    for(;b;b>>=1){

        if(b&1)c=c*aa%mod;

        aa=aa*aa%mod;

    }

    return c%mod;

}

int main()

{

    scanf("%d",&n);

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

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

        ll x=a[i];

        for(ll v=2;v*v<=x;v++){

            if(x%v)continue;

            ll cur=0;

            while(x%v==0){

                cur++;

                x/=v;

            }

            mx[v]=max(mx[v],cur);

        }

        if(x!=1)mx[x]=max(mx[x],1ll);

    }

    ll lcm=1;

    for(ll i=1;i<=1000006;i++)

    {

        if(mx[i]) lcm = (lcm * power(i, mx[i])) % mod;

    }

    log(lcm);

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

//        ll x=power(a[i]*prelcm,1);

//        ll y=power(__gcd(a[i],prelcm),mod-2);

//        prelcm=x%mod*y%mod;prelcm%=mod;

//    }

    ll sum=0;

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

        sum=(sum+power(lcm,1)%mod*power(a[i],mod-2)%mod)%mod;

    }

    cout<<sum<<endl;

    return 0;

}


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

#include<string>

#include<set>

#include<algorithm>

#include<vector>

#include<map>

#include<queue>

#include<iomanip>

#include<cmath>

#include<stack>

#define endl '\n'

#define Bedoazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



using namespace std;



const long long mod = 1e9 + 7, N = 1e6 + 5;



long long fact[N], inv[N],  mix = 0, numbers[N];



map<long long, long long>factors;





long long fastpower(int base, int power) {



	if (power == 0)

		return 1;



	long long halfpower = fastpower(base, power / 2) ;



	long long ret = (halfpower * halfpower) % mod;



	if (power % 2) {



		ret = (ret * base) % mod;

	}

	return ret;





}





void primeFactors(long long n) {



	long long fact;



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



		fact = 0;



		while (n % i == 0) {



			fact++;



			n /= i;





		}

		if (factors[i] < fact) {



			factors[i] = fact;



		}









	}

	

	if (n > 1 && factors[n] < 1 ) {



		factors[n] = 1;



	}





	return;





}





int main() {



	Bedoazim



		long long n;



	cin >> n;



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





		cin >> numbers[i];



		primeFactors(numbers[i]);



	}





	long long lcm = 1;



	for (auto x : factors) {



		lcm =((lcm%mod)*(fastpower(x.first, x.second)%mod))%mod;

		



	}



	long long ans = 0;



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



		ans = ((ans%mod) + ((lcm * fastpower(numbers[i], mod - 2)) % mod)) % mod;



	}



	cout << ans%mod;





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

#include <algorithm>

#include <cstring>

#include <set>

#include <map>

#include <iostream>

#include <cstring>

#include <cmath>

#include <queue>

#define ull unsigned long long

#define ll long long

#define INF 0x3f3f3f3f

using namespace std;

void close(){

       std::ios::sync_with_stdio(false);

       std::cin.tie(0);

}

const ll mod=1e9+7;

ll qpow(ll a,ll b){

	ll ret=1;

	while(b) {

		if (b&1) ret=(ret*a)%mod;

		a=(a*a)%mod;

		b>>=1;

	}

	return ret;

}

const int maxn=1e4+5;

const int N=1e6+5;

int n,a[maxn],num[N],lcm=1,ans=0;

int main(){

	cin>>n;

	for(int i=1;i<=n;i++) cin>>a[i];

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

		int x=a[i];

		for(int j=2;j*j<=x;j++){

			if(x%j==0){

				int cnt=0;

				while(x%j==0){

					x/=j,cnt++;

				}

				num[j]=max(num[j],cnt);

			}

		}

		if(x!=1) num[x]=max(num[x],1);

	}

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

		if(num[i]){

			lcm=1ll*lcm*qpow(i,num[i])%mod;

		}

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

		ans=(ans+1ll*lcm*qpow(a[i],mod-2)%mod)%mod;

	}

	cout<<ans<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.191620144553457x):
#ifdef ConanYu

#include "local.hpp"

#else

#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void Main();

#define debug(...) do { } while(0)

int main() {

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

  Main();

}

#endif



const int N = 1e4 + 10, MOD = 1e9 + 7;



int a[N], b[N];



int fpow(int a, int b) {

  int ans = 1;

  for(; b; b >>= 1, a = 1ll * a * a % MOD) {

    if(b & 1) {

      ans = 1ll * ans * a % MOD;

    }

  }

  return ans;

}



map<int, int> mp;



void insert(int x, int c) {

  auto it = mp.find(x);

  if(it == mp.end()) {

    mp[x] = c;

  } else {

    it->second = max(it->second, c);

  }

}



void Main() {

  int n; cin >> n;

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

    cin >> a[i];

    int t = a[i];

    for(int j = 2; j * j <= t; j++) {

      if(t % j == 0) {

        int cnt = 0;

        while(t % j == 0) {

          t /= j;

          cnt++;

        }

        insert(j, cnt);

      }

    }

    if(t > 1) {

      insert(t, 1);

    }

  }

  int sum = 1;

  for(auto &x: mp) {

    sum = 1ll * sum * fpow(x.first, x.second) % MOD;

  }

  int ans = 0;

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

    int t = fpow(a[i], MOD - 2);

    ans += 1ll * t * sum % MOD;

    if(ans >= MOD) ans -= MOD;

  }

  cout << ans << "\n";

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

using namespace std;

typedef pair<int,double> P;

int main(){

  int n,m,p,a,b;

  while(cin>>n>>m>>p>>a>>b,n){

    a--,b--;



    double t[8],tp;

    vector<P> e[31];



    for(int i=0;i<n;i++)cin>>t[i];

    for(int j=0,x,y;j<p;j++){

      cin>>x>>y>>tp;

      x--,y--;

      e[x].push_back(P(y,tp)),e[y].push_back(P(x,tp));

    }



    double dp[1<<8][30];

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

	for(int j=0;j<m;j++)dp[i][j]=1e4;

    dp[0][a]=0;



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

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

	for(int k=0;k<m;k++)

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

	    if(!(j&1<<l))

	      for(int w=0;w<e[k].size();w++)

		dp[j+(1<<l)][e[k][w].first]

	   =min(dp[j+(1<<l)][e[k][w].first],dp[j][k]+e[k][w].second/t[l]);



    double ans=1e4;

    for(int i=0;i<1<<n;i++)ans=min(ans,dp[i][b]);

    if(ans==1e4)cout<<"Impossible"<<endl;

    else cout<<ans<<endl;

  }

  return 0;

}

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

using namespace std;

typedef pair<int,double> P;

int main(){

  int n,m,p,a,b;

  while(cin>>n>>m>>p>>a>>b,n){

    a--,b--;



    double t[8],tp;

    vector<P> e[31];



    for(int i=0;i<n;i++)cin>>t[i];

    for(int j=0,x,y;j<p;j++){

      cin>>x>>y>>tp;

      x--,y--;

      e[x].push_back(P(y,tp)),e[y].push_back(P(x,tp));

    }



    double dp[1<<8][30];

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

	for(int j=0;j<m;j++)dp[i][j]=1e4;

    dp[0][a]=0;



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

      for(int k=0;k<m;k++)

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

	  if(!(j&1<<l))

	    for(int w=0;w<e[k].size();w++)

	      dp[j+(1<<l)][e[k][w].first]

		=min(dp[j+(1<<l)][e[k][w].first],dp[j][k]+e[k][w].second/t[l]);

    

    double ans=1e4;

    for(int i=0;i<1<<n;i++)ans=min(ans,dp[i][b]);

    if(ans==1e4)cout<<"Impossible"<<endl;

    else cout<<ans<<endl;

  }

  return 0;

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

#include<string>

#include<vector>

#include<cmath>

#include<queue>

#include<stack>

#include<set>

#include<algorithm>

#include<utility>

#include<map>

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const int INF = 1001001001;



ll pow_mod(ll p, ll n, ll m) {

	if (n == 0) return 1;

	else if (n == 1) return p % m;

	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;

	else {

		ll tmp = pow_mod(p, n / 2, m);

		return (tmp * tmp) % m;

	}

}



ll gcd(ll x, ll y) {

	if (y == 0) {

		return x;

	}

	return gcd(y, x % y);

}



ll com_mod(ll n, ll k, ll m) {

	if (k == 0) return 1;

	else {

		ll x = 1;

		ll y = 1;

		for (ll i = 0; i < k; i++) {

			x = (x * (n - i)) % m;

			y = (y * (i + 1)) % m;

		}

		ll res = (x * pow_mod(y, m - 2, m)) % m;

		return res;

	}

}



int main() {

	int a, b;

	cin >> a >> b;

	if (a % 2 == 0 || b % 2 == 0)cout << "No" << endl;

	else cout << "Yes" << endl;

	return 0;

}

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

int main(){

  int a,b; scanf("%d%d",&a,&b);

  if(a%2==0||b%2==0) printf("No\n");

  else printf("Yes");

  return 0;

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

using namespace std;

int a,b;

main(){

  cin>>a>>b;

  cout<<(a*b%2?"Yes":"No")<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.326943191171124x):
#import<ios>

int a,b;main(){scanf("%d%d",&a,&b)<puts(a*b%2?"Yes":"No");}
// Slower C++ solution:
#include<bits/stdc++.h>

#define model l,mid,num<<1

#define moder mid+1,r,num<<1|1

#define bug(k)  cout<<"text :"<<t<<endl

#define lowbit(k) k&-k

using namespace std;

typedef long long LL;

const LL mod=1e9+7;

const int M=1e5+5;

int main()

{

    int a,b;

    while(cin>>a>>b)

    {

        if((a&1)&&(b&1))puts("Yes");

        else puts("No");

    }

}


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

int main(void)

{

	int a, b, t, c, ji;

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

	if(a > b)

	{

		t = a;

		a = b;

		b = t;

	}

	for(int i = a; i <= b; i++)

	{

		c = i;

		ji = a*b*c;

		if(ji%2 == 1)

		break;

	}

	if(ji%2 == 0)

	printf("No");

	else

	printf("Yes");

	return 0;

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

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int oya;

int D[100001];

int P[100001];

vector<int> V[100001];

int sagasu(int A) {

	if (D[A]) return D[A];

	if (A == oya) return 1;

	int ret = 0;

	for (int i : V[A]) {

		int kari = sagasu(i) + 1;

		if (ret < kari) {

			ret = kari;

			P[A] = i;

		}

	}

	D[A] = ret;

	return ret;

}





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int kodomo[100001] = {};

	rep(i, N + M - 1) {

		int a, b;

		cin >> a >> b;

		V[b].pb(a);

		kodomo[b] = 1;

	}



	rep1(i, N) {

		if (kodomo[i] == 0) {

			oya = i;

			break;

		}

	}



	rep1(i, N) {

		sagasu(i);

		co(P[i]);

	}



	Would you please return 0;

}

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

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define putchar putchar_unlocked

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char ci[cm];

char *cn = ci + cm;

inline char getcha() {

	if (cn - ci == cm) { fread(ci, 1, cm, stdin); cn = ci; }

	return *cn++;

}



inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



inline void putint(int X) {

	if (X == 0) putchar('0');

	int keta = 0;

	char C[10];

	while (X) {

		C[keta] = '0' + X % 10;

		X /= 10;

		keta++;

	}

	for (int i = keta - 1; i >= 0; i--) putchar(C[i]);

	putchar('\n');

}



int oya;

int D[100001];

int P[100001];

pair<int, int> E[100001], EN[100001];

int sagasu(int A) {

	if (*(D + A)) return *(D + A);

	if (A == oya) return 1;

	int ret = 0;

	int p = (*(EN + A)).first;

	int q = (*(EN + A)).second;

	rep(i, q) {

		int j = (*(E + p + i)).second;

		int kari = sagasu(j) + 1;

		if (ret < kari) {

			ret = kari;

			*(P + A) = j;

		}

	}

	*(D + A) = ret;

	return ret;

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	N = getint();

	M = getint();

	bool kodomo[100001] = {};

	rep(i, N + M - 1) {

		int a, b;

		a = getint();

		b = getint();

		E[i] = mp(b, a);

		kodomo[b] = true;

	}



	rep1(i, N) {

		if (!kodomo[i]) {

			oya = i;

			break;

		}

	}



	sort(E, E + N + M - 1);

	int k = 0;

	int mae = 0;

	rep1(i, N) {

		while (k < N + M - 1 && E[k].first == i) k++;

		EN[i] = mp(mae, k - mae);

		mae = k;

	}



	rep1(i, N) {

		sagasu(i);

		putint(P[i]);

	}



	Would you please return 0;

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

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int oya;

int D[100001];

int P[100001];

vector<int> V[100001];

int sagasu(int A) {

	if (D[A]) return D[A];

	if (A == oya) return 1;

	int ret = 0;

	for (int i : V[A]) {

		int kari = sagasu(i) + 1;

		if (ret < kari) {

			ret = kari;

			P[A] = i;

		}

	}

	D[A] = ret;

	return ret;

}





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int kodomo[100001] = {};

	rep(i, N + M - 1) {

		int a, b;

		cin >> a >> b;

		V[b].pb(a);

		kodomo[b] = 1;

	}



	rep1(i, N) {

		if (kodomo[i] == 0) {

			oya = i;

			break;

		}

	}



	rep1(i, N) {

		sagasu(i);

		co(P[i]);

	}



	Would you please return 0;

}

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

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define putchar putchar_unlocked

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char ci[cm];

char *cn = ci + cm;

inline char getcha() {

	if (cn - ci == cm) { fread(ci, 1, cm, stdin); cn = ci; }

	return *cn++;

}



inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



inline void putint(int X) {

	if (X == 0) putchar('0');

	int keta = 0;

	char C[10];

	while (X) {

		*(C + keta) = '0' + X % 10;

		X /= 10;

		keta++;

	}

	for (int i = keta - 1; i >= 0; i--) putchar(*(C + i));

	putchar('\n');

}



int oya;

int D[100001];

int P[100001];

pair<int, int> E[100001];

int EN[100002];

int sagasu(int A) {

	if (*(D + A)) return *(D + A);

	if (A == oya) return 1;

	for (int i = (*(EN + A)); i < (*(EN + A + 1)); i++) {

		int j = (*(E + i)).second;

		int kari = sagasu(j) + 1;

		if (*(D + A) < kari) {

			*(D + A) = kari;

			*(P + A) = j;

		}

	}

	return *(D + A);

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	N = getint();

	M = getint();

	bool kodomo[100001] = {};

	rep(i, N + M - 1) {

		int a, b;

		a = getint();

		b = getint();

		E[i] = mp(b, a);

		kodomo[b] = true;

	}



	rep1(i, N) {

		if (!kodomo[i]) {

			oya = i;

			break;

		}

	}



	sort(E, E + N + M - 1);

	int k = 0;

	int mae = 0;

	EN[1] = 0;

	rep1(i, N) {

		while (k < N + M - 1 && E[k].first == i) k++;

		EN[i + 1] = k;

		mae = k;

	}



	rep1(i, N) {

		if (!(*(D + i))) sagasu(i);

		putint(*(P + i));

	}



	Would you please return 0;

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

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int oya;

int D[100001];

int P[100001];

vector<int> V[100001];

int sagasu(int A) {

	if (D[A]) return D[A];

	if (A == oya) return 1;

	int ret = 0;

	for (int i : V[A]) {

		int kari = sagasu(i) + 1;

		if (ret < kari) {

			ret = kari;

			P[A] = i;

		}

	}

	D[A] = ret;

	return ret;

}





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int kodomo[100001] = {};

	rep(i, N + M - 1) {

		int a, b;

		cin >> a >> b;

		V[b].pb(a);

		kodomo[b] = 1;

	}



	rep1(i, N) {

		if (kodomo[i] == 0) {

			oya = i;

			break;

		}

	}



	rep1(i, N) {

		sagasu(i);

		co(P[i]);

	}



	Would you please return 0;

}

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

using namespace std;

typedef long long ll;

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

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



//当時の自分の方が天才っぽい

int D[100001];

int P[100001];

int to[100001], ne[100001], he[100001];

int sagasu(int A) {

	if (D[A]) return D[A];

	int ret = 1;

	for (int i = he[A]; i; i = ne[i]) {

		int u = to[i];

		int kari = sagasu(u) + 1;

		if (ret < kari) {

			ret = kari;

			P[A] = u;

		}

	}

	return 	D[A] = ret;

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	rep1(i, N + M - 1) {

		int a, b;

		cin >> a >> b;

		to[i] = a;

		ne[i] = he[b];

		he[b] = i;

	}



	rep1(i, N) {

		sagasu(i);

		co(P[i]);

	}



	Would you please return 0;

}