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

#include<algorithm>

#include<cstring>

using namespace std;

int a[100005],f[100005];

int main()

  {int n,k;

    cin >> n >> k;

   int i,Min = 0x7fffffff,num = 0;

   memset(a,0,sizeof(a));

   memset(f,0,sizeof(f));

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

          {cin >>a[i];Min = min(a[i],Min);

          }

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

   {  if(a[i] != Min)f[num]++;

      else num++;

   }

   int cnt = 0;

   if(a[n] == Min)num--;

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

   {

    while(f[i] > 0)

        {   cnt ++;

            f[i] -= k-1;

        }

    if(f[i] < 0)

       f[i+1] += f[i];

   }

   cout<<cnt<<endl;

  }


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

#include <string.h>

#include <math.h>

#include <stdlib.h>

#include <ctype.h>



#include <algorithm>

#include <iostream>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <sstream>

#include <stack>

#include <queue>

#include <bitset>



using namespace std;



#define deb(a)    cout<<__LINE__<<"# "<<#a<<" -> "<<a<<endl;

#define pb push_back

#define OO 2e9+10



#define ConPnt(a)   {for(auto it: a){cout<<it<<", ";}cout<<endl;}

#define MapPnt(a)   {for(auto it: a){cout<<it.first<<": "<<it.second<<", ";}cout<<endl;}



typedef long long ll;

typedef pair<int,int>pii;



template<class T> T abs(T x){

    if(x<0) return -x;

    return x;

}

template<class T>T sqr(T a){

    return a*a;

}



const double pi = acos(-1.0);

const double eps = 1e-8;





int main()

{

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

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



    int i,n,k,ans,x;

    while(2==scanf("%d%d",&n,&k))

    {

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

            scanf("%d",&x);

        int ans = 1;

        if(k==n)

        {

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

            continue;

        }

        n-=k;

        ans += (n+k-2)/(k-1);



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

    }



    return 0;

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

#include<algorithm>

#include<cstring>

using namespace std;

int a[100005],f[100005];

int main()

  {int n,k;

    cin >> n >> k;

   int i,Min = 0x7fffffff,num = 0;

   memset(a,0,sizeof(a));

   memset(f,0,sizeof(f));

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

          {cin >>a[i];Min = min(a[i],Min);

          }

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

   {  if(a[i] != Min)f[num]++;

      else num++;

   }

   int cnt = 0;

   if(a[n] == Min)num--;

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

   {

    while(f[i] > 0)

        {   cnt ++;

            f[i] -= k-1;

        }

    if(f[i] < 0)

       f[i+1] += f[i];

   }

   cout<<cnt<<endl;

  }


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

using namespace std;

int main()

{

    long long a,b,c,d,n,ar[100010],i,j,k,mini=100010;

    while(cin>>n>>k)

    {

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

      {

          cin>>ar[i];

      }

      a=0;

      sort(ar,ar+n);

      for(i=0;i<n;)

      {

          i=i+(k-1);

          if(i==n-1)

          {

              a++;

              break;

          }





          if(i>=n)

          {

             a++;

             break;

          }

         else

         {

            a++;

         }

      }

     cout<<a<<endl;



    }

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

#include<algorithm>

#include<cstring>

using namespace std;

int a[100005],f[100005];

int main()

  {int n,k;

    cin >> n >> k;

   int i,Min = 0x7fffffff,num = 0;

   memset(a,0,sizeof(a));

   memset(f,0,sizeof(f));

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

          {cin >>a[i];Min = min(a[i],Min);

          }

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

   {  if(a[i] != Min)f[num]++;

      else num++;

   }

   int cnt = 0;

   if(a[n] == Min)num--;

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

   {

    while(f[i] > 0)

        {   cnt ++;

            f[i] -= k-1;

        }

    if(f[i] < 0)

       f[i+1] += f[i];

   }

   cout<<cnt<<endl;

  }


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



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

typedef pair<int,int> ii;

typedef pair<int,pair<int,int>> iii;

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

typedef vector<vector<int>> vvi;



#define pb push_back

#define mp make_pair

#define fi first

#define se second



const int MAXN = 1e5+10;

int a[MAXN];

int k,n,m;



int main (void) {

    ios_base::sync_with_stdio(false);



    cin >> n >> k;

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

        cin >> a[i];

        if (a[i] == 1) m = i;

    }



    int result = (int)1e6;

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

        int left = max(0, (m-i+k-2)/(k-1));

        int right = max(0, (n-(m+k-i)+k-2)/(k-1));

        result = min(result, left+right+1);

    }



    cout << result << endl;



    return 0;

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

using namespace std;

 

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

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

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

#define int long long

#define mk_p(a,b)	make_pair((a),(b))

using pii = pair<int,int>;

constexpr int INF  = 0x3f3f3f3f;

constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;



int gcd(int a,int b){return b ? gcd(b,a%b) : a;}

int lcm(int a,int b){return a/gcd(a,b)*b;}



vector<int> a(100500);

signed main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n,k;

	cin >> n >> k;

	int minv = INF;

	int pnt = 0;

	reps(i,n){

		cin >> a[i];

		if(a[i] == 1) pnt = i;

	}

	int cnt = 0;

	cnt = (n + k - 1) / k;

	cout << ((n - 1) + (k - 1) - 1)/ (k - 1) << '\n';

	return 0;

}


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

using namespace std;

 

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

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

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

#define int long long

#define mk_p(a,b)	make_pair((a),(b))

using pii = pair<int,int>;

constexpr int INF  = 0x3f3f3f3f;

constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;



int gcd(int a,int b){return b ? gcd(b,a%b) : a;}

int lcm(int a,int b){return a/gcd(a,b)*b;}



signed main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n,k;

	cin >> n >> k;

	cout << ((n - 1) + (k - 1) - 1)/ (k - 1) << '\n';

	return 0;

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

using namespace std;

#define rint register int

inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}

int n, K; int main(){n = read(); K = read(); return !printf("%d\n",(n-2)/(K-1)+1);}

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

using namespace std;

int K,N,ans;

int main(){

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

	if(K==2)ans=N-1;

	else if(K>=N)ans=1;

	else {

		N-=K;

		ans=1;

		if(N%(K-1)==0)ans+=N/(K-1);

		else ans+=N/(K-1)+1;

	}

	printf("%d",ans);

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

using namespace std;

int main()

{

    int n=0,m,k,i=0,s=1;

    cin>>n>>k;

    int a[100005]={0};

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

        cin>>a[i];

    n-=k;

    k--;

    //cout<<n<<endl;

    while(n>0)

    {

        n-=k;

        s++;

    }

    cout<<s<<endl;

    return 0;

}


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

using namespace std;



int main(){

    int N, K; cin >> N >> K; int A[N];

    for (int i = 0; i < N; i++) cin >> A[i];

    cout << (N-1) / (K-1) + ((N-1) % (K-1) != 0) << endl;



    return 0;

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

using namespace std;

int main()

{

    int n=0,m,k,i=0,s=1;

    cin>>n>>k;

    int a[100005]={0};

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

        cin>>a[i];

    n-=k;

    k--;

    //cout<<n<<endl;

    while(n>0)

    {

        n-=k;

        s++;

    }

    cout<<s<<endl;

    return 0;

}


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

using namespace std;

int main()

{

   long long int a,b,item,c=0;

   cin>>a>>b;

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

   {

       cin>>item;

   }

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

   {

       c++;

   }

   cout<<c<<endl;

    return 0;

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

using namespace std;

int main()

{

    int n=0,m,k,i=0,s=1;

    cin>>n>>k;

    int a[100005]={0};

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

        cin>>a[i];

    n-=k;

    k--;

    //cout<<n<<endl;

    while(n>0)

    {

        n-=k;

        s++;

    }

    cout<<s<<endl;

    return 0;

}


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

using namespace std;



int main( )

{

    int n, k;    cin >> n >> k;

    int i, d, c = 0;

    for (i = 1; i <= n; i++)    cin >> d;

    for (i = 1; i < n; i = i + k - 1)   c++;

    cout << c << "\n";

    return 0;

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

using namespace std;

int main()

{

    int n=0,m,k,i=0,s=1;

    cin>>n>>k;

    int a[100005]={0};

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

        cin>>a[i];

    n-=k;

    k--;

    //cout<<n<<endl;

    while(n>0)

    {

        n-=k;

        s++;

    }

    cout<<s<<endl;

    return 0;

}


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

using namespace std;

#define  sf  scanf

#define  pf  printf

int main()

{

    int i,n,k,s=0,a;

    sf("%d %d",&n,&k);

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

    {

        sf("%d",&a);

    }

    for(i=0; ;i+=(k-1))

    {

        if(i>=(n-1))

        {

            break;

        }

        s++;

    }

    pf("%d\n",s);

    return 0;

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

using namespace std;

int main()

{

    int n=0,m,k,i=0,s=1;

    cin>>n>>k;

    int a[100005]={0};

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

        cin>>a[i];

    n-=k;

    k--;

    //cout<<n<<endl;

    while(n>0)

    {

        n-=k;

        s++;

    }

    cout<<s<<endl;

    return 0;

}


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

#include<vector>

#include<algorithm>

using namespace std;

int main() {

	int n,k,x,cnt=0;

	cin>>n>>k;

	vector<int>v;

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

	{

	   cin>>x;

	   v.push_back(x);

	}

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

	for(int i=0;i<v.size()-1;i+=k-1)

    {

        cnt++;

    }

    cout<<cnt<<endl;

	return 0;

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

using namespace std;

int main()

{

    int n=0,m,k,i=0,s=1;

    cin>>n>>k;

    int a[100005]={0};

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

        cin>>a[i];

    n-=k;

    k--;

    //cout<<n<<endl;

    while(n>0)

    {

        n-=k;

        s++;

    }

    cout<<s<<endl;

    return 0;

}


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

using namespace std;



int main(){

    int n, m;

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

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

        int num;

        scanf("%d",&num);

    }

    int ans=ceil((double)(n-1)/(m-1));

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

    return 0;

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

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=1e5+1000;

struct node{

	int v,nxt,c;

}edge[maxn<<2];

int head[maxn],tot;

int vis[maxn],dist[maxn];

int n,m,len=0;

inline void read(int &x){

	x=0;char tmp=getchar();

	while(tmp<'0'||tmp>'9') tmp=getchar();

	while(tmp>='0'&&tmp<='9') x=(x<<1)+(x<<3)+tmp-'0',tmp=getchar();

}

inline void add_edge(int x,int y,int c){

	edge[tot].nxt=head[x];

	edge[tot].v=y;

	edge[tot].c=c;

	head[x]=tot++;

}

inline bool spfa(int x){

	int maxx=0,minn=0;

	dist[x]=0,vis[x]=1;

	queue<int>q;

	q.push(x);

	while(!q.empty()){

		int u=q.front();q.pop();

		for(int i=head[u];i!=-1;i=edge[i].nxt){

			int v=edge[i].v;

			if(!vis[v]){

				dist[v]=dist[u]+edge[i].c;

				maxx=max(dist[v],maxx);

				minn=min(dist[v],minn);

				vis[v]=1;

				q.push(v);

			}

			else if(dist[v]!=dist[u]+edge[i].c)

				return false;

		}

	}

	len=max(len,maxx-minn);

	if(len>1e9) return false;

	return true;

}

int main(){

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

	memset(vis,0,sizeof(vis));

	cin>>n>>m;

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

		int l,r,d;

		read(l),read(r),read(d);

		add_edge(l,r,d);

		add_edge(r,l,-d);

	}

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

		if(!vis[i]){

			if(!spfa(i)){

				printf("No\n");

				return 0;

			}

		}

	}

	printf("Yes\n");

	return 0;

}

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

#define ll long long

#define inf 0x3f3f3f3f

#define il inline

 

namespace io {

 

#define in(a) a = read()

#define out(a) write(a)

#define outn(a) out(a), putchar('\n')

 

#define I_int ll

inline I_int read() {

    I_int x = 0, f = 1;

    char c = getchar();

    while (c < '0' || c > '9') {

        if (c == '-') f = -1;

        c = getchar();

    }

    while (c >= '0' && c <= '9') {

        x = x * 10 + c - '0';

        c = getchar();

    }

    return x * f;

}

char F[200];

inline void write(I_int x) {

    if (x == 0) return (void) (putchar('0'));

    I_int tmp = x > 0 ? x : -x;

    if (x < 0) putchar('-');

    int cnt = 0;

    while (tmp > 0) {

        F[cnt++] = tmp % 10 + '0';

        tmp /= 10;

    }

    while (cnt > 0) putchar(F[--cnt]);

}

#undef I_int

 

}

using namespace io;

 

using namespace std;

 

#define N 200010

 

int n = read(), m = read();

struct edge {

	int to, nxt, v;

}e[N<<1];

int head[N], cnt, d[N], vis[N];

 

int flag = 0;

void dfs(int u) {

	vis[u] = 1;

	for(int i = head[u]; i; i = e[i].nxt) {

		if(vis[e[i].to]) {

			if(d[e[i].to] == d[u] + e[i].v) continue;

			else {

				flag = 1;

				return;

			}

		} else {

			d[e[i].to] = d[u] + e[i].v;

			dfs(e[i].to);

		}

	}

}



void ins(int u, int v, int w) {

	e[++cnt] = {v, head[u], w};

	head[u] = cnt;

}

 

int main() {

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

    	int l = read(), r = read(), t = read();

    	ins(l, r, t); ins(r, l, -t);

	}

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

	if(flag) puts("No");

	else puts("Yes");

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



using namespace std;

typedef long long ll;



struct edge {

  int to, cost;

  edge() {}

  edge(int t, int c) : to(t), cost(c) {}

};



int n, m;

vector<edge> g[100010];

vector<int> d(100010);

vector<bool> used(100010);



bool dfs(int v) {

  bool res = true;

  for (auto &e : g[v]) {

    if (used[e.to]) {

      if (d[e.to] == d[v] + e.cost) continue;

      return false;

    }

    used[e.to] = true;

    d[e.to] = d[v] + e.cost;

    res &= dfs(e.to);

  }

  return res;

}



int main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  

  cin >> n >> m;

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

    int l, r, d;

    cin >> l >> r >> d;

    l--, r--;

    g[l].push_back(edge(r, d));

    g[r].push_back(edge(l, -d));

  }



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

    if (used[i]) continue;

    used[i] = true;

    d[i] = 0;

    if (!dfs(i)) {

      cout << "No\n";

      return 0;

    }

  }

  cout << "Yes\n";



  return 0;

}

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



using namespace std;

using ll = long long;

using pii = pair<int, int>;



using VAL = int;

struct WeightedUnionFind {

  int n;

  vector<int> rank, par;

  vector<VAL> diff_weight;

  WeightedUnionFind() {}

  WeightedUnionFind(int n) : n(n), rank(n, 1), par(n), diff_weight(n) {

    iota(par.begin(), par.end(), 0);

  }

  int root(int x) {

    if (x == par[x]) return x;

    int r = root(par[x]);

    diff_weight[x] += diff_weight[par[x]];

    return par[x] = r;

  }

  bool merge(int x, int y, VAL w) {

    int X = root(x), Y = root(y), W = w;

    W += weight(x); W -= weight(y);

    if (X == Y) return diff(x, y) == w;

    if (rank[X] < rank[Y]) swap(X, Y), W = -W;

    rank[X] += rank[Y];

    par[Y] = X;

    diff_weight[Y] = W;

    return true;

  }

  VAL weight(int x) {

    root(x);

    return diff_weight[x];

  }

  VAL diff(int x, int y) {

    return weight(y) - weight(x);

  }

  bool same(int x, int y) {

    return root(x) == root(y);

  }

  int size(int x) {

    return rank[root(x)];

  }

};



int N, M;



int main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  cout << fixed << setprecision(10);

  

  cin >> N >> M;

  WeightedUnionFind uf(N);

  bool yes = true;

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

    int L, R, D;

    cin >> L >> R >> D;

    L--, R--;

    yes &= uf.merge(L, R, D);

  }

  cout << (yes ? "Yes" : "No") << endl;



  return 0;

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



using namespace std;

typedef long long ll;



struct edge {

  int to, cost;

  edge() {}

  edge(int t, int c) : to(t), cost(c) {}

};



int n, m;

vector<edge> g[100010];

vector<int> d(100010);

vector<bool> used(100010);



bool dfs(int v) {

  bool res = true;

  for (auto &e : g[v]) {

    if (used[e.to]) {

      if (d[e.to] == d[v] + e.cost) continue;

      return false;

    }

    used[e.to] = true;

    d[e.to] = d[v] + e.cost;

    res &= dfs(e.to);

  }

  return res;

}



int main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  

  cin >> n >> m;

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

    int l, r, d;

    cin >> l >> r >> d;

    l--, r--;

    g[l].push_back(edge(r, d));

    g[r].push_back(edge(l, -d));

  }



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

    if (used[i]) continue;

    used[i] = true;

    d[i] = 0;

    if (!dfs(i)) {

      cout << "No\n";

      return 0;

    }

  }

  cout << "Yes\n";



  return 0;

}

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

#define int long long

#define uint unsigned int

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

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

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

#define sz(a) (a).size()

#define pb(a) push_back(a)

#define eb(...) emplace_back(__VA_ARGS__)

#define mp(a, b) make_pair(a, b)

#define mt(...) make_tuple(__VA_ARGS__)

using namespace std;

using pii = pair<int, int>;

constexpr int MOD = 1000000007;

constexpr int INF = 1LL << 30;

constexpr double EPS = 1e-10;



struct edge {

  int t, c;

  edge() {}

  edge(int t, int c) : t(t), c(c) {}

};



int N, M;

vector<edge> g[100010];

int dis[100010];



bool dfs(int v, int x) {

  dis[v] = x;

  for (edge e : g[v]) {

    int nv = e.t;

    if (dis[nv] == INF) {

      if (dfs(nv, x+e.c)) continue;

      else return false;

    } else {

      if (dis[nv] == x+e.c) continue;

      return false;

    }

  }

  return true;

}



signed main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  cout << fixed << setprecision(10);

  

  cin >> N >> M;

  rep(i, 0, M) {

    int L, R, D;

    cin >> L >> R >> D;

    L--; R--;

    g[L].eb(R, D);

    g[R].eb(L, -D);

  }



  fill(dis, dis+N, INF);

  rep(i, 0, N) {

    if (dis[i] == INF) {

      if (!dfs(i, 0)) {

        cout << "No" << endl;

        return 0;

      }

    }

  }

  cout << "Yes" << endl;



  return 0;

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

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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

int INF = (1LL << 30) - 1;

int MOD = 1e9+7;

int N,M;

vector<P> graph[200010];

vector<int> dist;

bool dfs(int now, int d){

    //cout << " " << now << endl;

    dist[now] = d;

    for(auto p:graph[now]){

        if(dist[p.first] != INF){

            if(dist[p.first] != d + p.second)return true;

            continue;

        }

        if(dfs(p.first, d + p.second))return true;

    }

    return false;

}

main(){ 

    cin >> N >> M;

    int num = 0;

    rep(i,0,M){

        int a,b,c;

        cin >> a >> b >> c;

        a--,b--;

        graph[a].emplace_back(b,c);

        graph[b].emplace_back(a,-c);

        num = a;

    }

    dist = vector<int>(N,INF);

    rep(i,0,N){

        int cost = dist[i];

        if(cost == INF)cost = 0;

        if(dist[i] == INF && dfs(i, 0) ){

            cout << "No" << endl;

            //cout << i << endl;

            return 0;

        }

        //for(auto i:dist)cout << i << " ";cout << endl;

    }

    cout << "Yes" << endl;

}

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

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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

int INF = (1LL << 30) - 1;

int MOD = 1e9+7;

vector<P> graph[100010];

vector<ll> dist;

bool dfs(int x, int d){

    dist[x] = d;

    for(auto p:graph[x]){

        if(dist[p.first] != INF){

            if(dist[p.first] != d + p.second){

                return true;

            }else continue;

        }

        if(dfs(p.first, d + p.second))return true;

    }

    return false;

}

main(){

    int N,M;

    cin >> N >> M;

    rep(i,0,M){

        int l,r,d;

        cin >> l >> r >> d;

        l--,r--;

        graph[l].emplace_back(r,d);

        graph[r].emplace_back(l,-d);

    }

    dist.resize(N, INF);

    rep(i,0,N){

        if(dist[i] != INF)continue;

        if(dfs(i, 0)){

            //cout << i << endl;

            cout << "No" << endl;

            return 0;

        }

    }

    cout << "Yes" << endl;

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

using namespace std;

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

#define INF 2e9+10

typedef pair<int,int> edge;



vector<edge> g[100010];

bool check[100010];

int p[100010];



bool solve(int v){

    if(abs(p[v]) > int(1e9)) return false;

    for(edge e : g[v]){

        int to = e.first;

        int d = e.second;

        if(p[to] == INF){

            p[to] = p[v] + d;

            if(!solve(to)) return false;

        }else if(p[v] + d != p[to]){

            return false;

        }

    }

    return true;

}



int main(void){

    int n,m;

    cin>>n>>m;

    rep(_,m){

        int l,r,d;

        cin>>l>>r>>d;

        g[l].push_back({r,d});

        g[r].push_back({l,-d});

    }



    rep(i,100010){

        p[i] = INF;

    }



    rep(i,n){

        if(p[i] != INF)continue;

        p[i] = 0;

        if(!solve(i)){

            cout<<"No"<<endl;

            return 0;

        }

    }

    cout<<"Yes"<<endl;

    return 0;

}


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

using namespace std;

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

#define INF 1e9

typedef pair<int,int> edge;



vector<vector<edge>> g;

vector<int> p;



bool solve(int v){

    if(abs(p[v]) > INF) return false;

    for(edge e : g[v]){

        int to = e.first;

        int d = e.second;

        if(p[to] == INF){

            p[to] = p[v] + d;

            if(!solve(to)) return false;

        }else if(p[v] + d != p[to]){

            return false;

        }

    }

    return true;

}



int main(void){

    int n,m;

    cin>>n>>m;

    g.resize(n);

    p.resize(n,INF);

    rep(_,m){

        int l,r,d;

        cin>>l>>r>>d;

        l--,r--;

        g[l].push_back({r,d});

        g[r].push_back({l,-d});

    }



    rep(i,n){

        if(p[i] != INF)continue;

        p[i] = 0;

        if(!solve(i)){

            cout<<"No"<<endl;

            return 0;

        }

    }

    cout<<"Yes"<<endl;

    return 0;

}