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

#include <algorithm>

#include <math.h>

#include <string>

#include <cstdio>

#include <vector>

#include <set>

#include <cassert>

#include <cstdlib>

#include <complex>

#include <cctype>

#include <cmath>

#include <ctime>

#include <deque>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <sstream>

#include <functional>

//#include <windows.h>  //Should be deleted when using AtCoder&POJ

using namespace std;

/**==Info==

*Program:2

*Problem:Fennce VS Snuke

*Date:2017-8-12

*Algorithm:DFS

*Stats:WA for 7 tests(But faster) :)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))*/

int n;

vector<int> nei[100005];

int d[2][100005];

inline void dfs(int root,int dis,int place){ //root:this point,dis:now distance,place:which place to write in Array

	d[place][root]=dis;

	for(int i=0;i<nei[root].size();i++){

		if(d[place][nei[root][i]]>d[place][root]+1){

			d[place][nei[root][i]]=d[place][root]+1;

			dfs(nei[root][i],dis+1,place);

		}

	}

}

int main(){

	scanf("%d",&n);

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

		int a,b;

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

		a--;b--;

		nei[a].push_back(b);

		nei[b].push_back(a);

	}

	for(int i=0;i<n;i++) d[0][i]=d[1][i]=1e8;

	dfs(0,0,0);

	dfs(n-1,0,1);

	

	int f=0,s=0;

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

		//cout<<d[0][i]<<" "<<d[1][i]<<endl;

		if(d[0][i]<=d[1][i]){

			f++;

		}else{

			s++;

		}

	}

	cout<<(f>s?"Fennec":"Snuke");

	return 0;

}


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

#include <vector>

#include <queue>

using namespace std;



inline vector<int> bfs(int n,vector<vector<int> > &g,int s)

{

	vector<int> d(n,1e9);d[s]=0;

	queue<int>q;q.push(s);

	while(!q.empty())

	{

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

		for(auto v:g[cur])

			if(d[v]>d[cur]+1)

			{

				d[v]=d[cur]+1;

				q.push(v);

			}

	}

	return d;

}



int main()

{

	int n;

	cin>>n;

	vector<vector<int> > g(n);

	

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

	{

		int a,b;

		cin>>a>>b;

		a--;b--;

		g[a].push_back(b);g[b].push_back(a);

	}

	

	vector<int> a=bfs(n,g,0);

	vector<int> b=bfs(n,g,n-1);

	

	int f=0,s=0;

	for(int i=0;i<n;i++) if(a[i]<=b[i]) f++; else s++;

	cout<<(f>s?"Fennec":"Snuke");

	

	return 0;

}

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

#include <vector>

#include <cstring>

using namespace std;



int n;

vector<int> pos[100010];

int cnt[100010],l[100010],p[100010];



inline void dfs(int v)

{

	cnt[v]=1;

	for(int i=0;i<pos[v].size();i++)

	{

		int cur=pos[v][i];

		if(p[v]==cur) continue;

		l[cur]=l[v]+1;p[cur]=v;

		dfs(cur);

		cnt[v]+=cnt[cur];

	}

}



int main()

{

	cin>>n;

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

	{

		int a,b;

		cin>>a>>b;

		pos[a].push_back(b);

		pos[b].push_back(a);

	}

	

	dfs(1);

	int sz=(l[n]-1)/2,v=n;

	while(sz--) v=p[v];

	if(cnt[v]>=n-cnt[v]) cout<<"Snuke"; else cout<<"Fennec";

	

	return 0;

}

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

#include <vector>

#include <queue>

using namespace std;



inline vector<int> bfs(int n,vector<vector<int> > &g,int s)

{

	vector<int> d(n,1e9);d[s]=0;

	queue<int>q;q.push(s);

	while(!q.empty())

	{

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

		for(auto v:g[cur])

			if(d[v]>d[cur]+1)

			{

				d[v]=d[cur]+1;

				q.push(v);

			}

	}

	return d;

}



int main()

{

	int n;

	cin>>n;

	vector<vector<int> > g(n);

	

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

	{

		int a,b;

		cin>>a>>b;

		a--;b--;

		g[a].push_back(b);g[b].push_back(a);

	}

	

	vector<int> a=bfs(n,g,0);

	vector<int> b=bfs(n,g,n-1);

	

	int f=0,s=0;

	for(int i=0;i<n;i++) if(a[i]<=b[i]) f++; else s++;

	cout<<(f>s?"Fennec":"Snuke");

	

	return 0;

}

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

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=1e5;

vector<int> lj[yuzu|10];

typedef int fuko[yuzu|10];

fuko d1,d2;

int n=read();



void dfs(int u,int fa,int *d){

d[u]=d[fa]+1;

for (int i:lj[u]) if (i^fa) dfs(i,u,d);

}



int main(){

int i,u,v;

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

  u=read(),v=read();

  lj[u].push_back(v);

  lj[v].push_back(u);

  }

dfs(1,0,d1),dfs(n,0,d2);

int cnt=0;

for (i=1;i<=n;++i) cnt+=d1[i]<=d2[i];

puts(cnt*2<=n?"Snuke":"Fennec");

}

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

#include<cstdio>

using namespace std;

int n,a,b,cnt=0,id=0,ne[100005],in[100005],out[100005],cnt1,cnt2,fa[100005][20],len[100005];

struct node{

    int v,next;

}edge[400005];

inline int read(){

	char c=getchar();

	int x=0;

	for(;c>'9'||c<'0';) c=getchar();

	for(;c>='0'&&c<='9';){

		x=(x<<3)+(x<<1)+c-'0';

		c=getchar();

	}

	return x;

}

inline void add(int u,int v){

    edge[cnt]={v,ne[u]};

    ne[u]=cnt++;

    edge[cnt]={u,ne[v]};

    ne[v]=cnt++;

}

inline void dfs(int cur,int pre,int d){

    fa[cur][0]=pre;

    len[cur]=d;

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

        fa[cur][i]=fa[fa[cur][i-1]][i-1];

    in[cur]=++id;

    for(int i=ne[cur];i!=-1;i=edge[i].next){

        int v=edge[i].v;

        if(v==pre) continue;

        dfs(v,cur,d+1);

    }

    out[cur]=id;

}

int main(){

	n=read();

    for(int i=0;i<100005;i++) ne[i]=-1;

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

    	a=read(),b=read();

        add(a,b);

    }

    dfs(1,0,0);

    int tmp=(len[n]-1)>>1,now=n;

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

        if(tmp>>i&1) now=fa[now][i];

    cnt1=n-(out[now]-in[now]+1)-len[n]/2-1,cnt2=out[now]-in[now]+1-tmp-1;

    if(len[n]&1){

        if(cnt1<=cnt2) puts("Snuke");

        else puts("Fennec");

        return 0;

    }

    if(cnt2>cnt1) puts("Snuke");

    else puts("Fennec");

    return 0;

}

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

using namespace std;

vector<int> g[100010];

int clr[100010];

int main(){

	int n;

	cin>>n;

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

		int a,b;

		cin>>a>>b;

		g[a].push_back(b);

		g[b].push_back(a);

	}

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

	clr[1]=1;clr[n]=2;

	queue<int> q;

	q.push(1);q.push(n);

	while(!q.empty()){

		int x=q.front();

		q.pop();

		for(int i=0;i<g[x].size();i++){

			if(clr[g[x][i]]==-1){

				q.push(g[x][i]);

				clr[g[x][i]]=clr[x];

			}

		}

	}

	int fennec=0,snuke=0;

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

		if(clr[i]==1)fennec++;

		else snuke++;

	}

	if(fennec>snuke)cout<<"Fennec"<<endl;

	else cout<<"Snuke"<<endl;

	return 0;

}

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

#include<vector>



const int N=100010;



int n,fa[N],dep[N],sz[N],a[N],sa,b[N],sb;

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



void dfs(int u)

{

	sz[u]=1;

	for(auto v:G[u])if(v^fa[u])

		fa[v]=u,dep[v]=dep[u]+1,dfs(v),sz[u]+=sz[v];

}



int main()

{

	scanf("%d",&n);

	if(n==1)

		return puts("Fennec"),0;

	for(int i=1,x,y; i<n; i++)

	{

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

		G[x].push_back(y);

		G[y].push_back(x);

	}

	dfs(1);

	int lca=0;

	for(int u=1,v=n;;){

		if(dep[u]>dep[v])u=fa[u];

		else v=fa[v];

		if(u==v){

			lca=u;

			break;

		}

	}

	for(int x=1; x!=fa[lca]; x=fa[x])

		a[++sa]=x;

	for(int y=n; y!=lca; y=fa[y])

		b[++sb]=y;

	for(;sb;--sb)a[++sa]=b[sb];

	int p=a[(sa+1)/2];

	int q=a[(sa+1)/2+1];

	int s1=1,s2=0;

	if(p==fa[q])

	{

		s2=sz[q];

		s1=n-s2;

	}

	if(q==fa[p])

	{

		s1=sz[p];

		s2=n-s1;

	}

	if(s1>s2)

		puts("Fennec");

	else

		puts("Snuke");

	return 0;

}


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

#include <string>



const int maxn = 5e5+7;



std::string s;

long long a[maxn];



int main(int argc, char *argv[]) {  

	std::ios::sync_with_stdio(false);

	std::cin.tie(0); 

	std::cin >> s;

	std::fill(a, a+maxn, 0);

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

//		std::cout << s[i] << " \n"[i==s.length()-1];

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

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

		}

	}

	for (int i = s.length(); i >= 0; i--) {

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

			a[i] = std::max(a[i], a[i+1]+1);

		}

	}

	long long ans = 0;

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

//		std::cout << a[i] << " \n"[i==s.length()-1];

		ans += a[i];

	}

	std::cout << ans << '\n';

}

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

using namespace std;



int main(){

	string s;

	cin>>s;

	

	long long int len;

	len=s.size();

	

long long	i=0;

	long long int lt=0,gt=0,ans=0;

	

	while(i<len){

		

		while(i<len&&s[i]=='<'){

			lt++;

			i++;

		}

		while(i<len&&s[i]=='>'){

			gt++;

			i++;

		}

		

		if(lt==0){

			ans+=(gt*(gt+1))/2;

		}

		else if(gt==0){

			ans+=(lt*(lt+1))/2;

		}

		else{

			ans+=max(gt,lt)+((gt-1)*gt)/2+((lt-1)*lt)/2;

		}

		lt=0;gt=0;

			}

	cout<<ans;

}

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

using namespace std;

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define pii pair<int,int>

typedef long long ll;

string s;

ll ans;

int kiri[500005],kanan[500005];

int arr[500005];

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>s;

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

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

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

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

            if(i!=0 && kiri[i-1]!=-1){

                kiri[i]=kiri[i-1]+1;

            }

            else kiri[i]=0;

        }

        

    }

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

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

            if(kanan[i+1]!=-1){

                kanan[i]=kanan[i+1]+1;

            }

            else kanan[i]=1;

        }

        

    }

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

        if(i!=0 && kiri[i-1]!=-1 && kanan[i]!=-1){

            arr[i]=max(kiri[i-1]+1,kanan[i]);

        } 

        else if(kiri[i]!=-1) arr[i]+=kiri[i];

        else if(kanan[i]!=-1)arr[i] += kanan[i];

    }

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

        ans+=arr[i];

    }

    if(s.back()=='>') ans+=0;

    else ans+=kiri[s.size()-1]+1;

    cout<<ans<<endl;

}










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

using namespace std;

using ll = long long;

using ii = pair<ll, ll>;

#define mp make_pair

#define pb push_back

#define fi first

#define se second

const ll MOD = 1e9 + 7;

const ll N = 5e5 + 5;



string s;

ll ans;

ll a[N];



void solve() {

    cin >> s;

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

        if(s[i] == '<') a[i + 1] = a[i] + 1; 

    }

    for(ll i = s.size() - 1; i >= 0; i--) {

        if(s[i] == '>') 

            a[i] = max(a[i], a[i + 1] + 1);

    }

    ans = 0;

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

        ans += a[i];

    }

    cout << ans << "\n";

}



int main() {

    

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    

    solve();

    

}

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

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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

 

const int MOD=1000000007;

const int INF=0x3f3f3f3f;

const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y){

  if(y==0) return x;

  else return gcd(y, x%y);

}

ll lcm(ll x,ll y){

  ll g=gcd(x,y);

  return x/g*y;

}



int main(){

  string s;

  cin >> s;

  ll n=s.size();

  queue<ll>a;

  queue<ll>b;

  ll up=0;

  ll down=0;

  rep(i,n){

    if(i==0 &&s[0]=='>'){

      a.push(0);

      down++;

    }

    if(i!=0 &&s[i]=='>'){

      if(up){

        a.push(up);

        up=0;

      }

      down++;

    }

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

      if(down){

        b.push(down);

        down=0;

      }

      up++;

    }

    if(i==n-1){

      if(up)a.push(up);

      b.push(down);

    }

  }  

  b.push(0);

    

  vector<ll>c(500010);

  c[0]=0;

  rep(i,500010) c[i+1]=c[i]+i+1;

  

  ll ans=0;

  while(!a.empty()){

    if(a.front()>=b.front()){

      ans+=c[a.front()]+c[max(b.front()-1,0ll)];

      a.pop();

      b.pop();

    }

    else{

      ans+=c[max(0ll,a.front()-1)]+c[b.front()];

      a.pop();

      b.pop();

    }

  }

  cout<<ans<<endl;

}


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

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

using namespace std;

typedef long long ll;

const int MOD=1e9+7;

const int MAX = 1000000;

const int INF = 1e9;

const double pi=acos(-1);

using namespace std;



int main(){

  string s;

  cin >> s;

  int n=s.size();

  vector<int>a(n+1,0);

  rep(i,n){

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

      a[i+1]=max(a[i+1],a[i]+1);

    }

  }

  rep(i,n){

    if(s[n-1-i]=='>'){

      a[n-1-i]=max(a[n-1-i],a[n-i]+1);

    }

  }

  ll sum=0;

  rep(i,n+1)sum+=a[i];

  

  cout <<sum<<endl;

  

  return 0;

}

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

#include <cstdio>

#include <cstdint>

#include <cstring>



inline int64_t area(int w) { return (int64_t)w*(w+1)/2; }



int main(int argc, char* argv[])

{

  int N=5e5+1;

  char s[N+1];

  int l[N+1];

  int i=scanf("%s",s);

  int g=0;

  l[g]=1;

  for (char* p=s+1;*p;p++) {

    if (*(p-1) == *p) {

      l[g]++;

    } else {

      l[++g]=1;

    }

  }



  int64_t sum=0;

  int* q=l;

  if (s[0] == '>') {

    sum = area(*q++);

  }

  for (;q<l+g;) {

    auto w1=*q++, w2=*q++;

    if (w1 < w2) { w1--; } else { w2--; }

    sum += area(w1) + area(w2);

  }

  if (*q) {

    sum += area(*q);

  }

  printf("%ld\n", sum);

  return 0;

}

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

#include <cstdio>

#include <cstdint>

#include <cstring>



const int N=5e5;

inline auto a(int64_t w) { return w*(w-1)/2; }

inline char* l(char* p, int s) { for(;*p==s;p++); return p; }



main(int argc, char* argv[])

{

  char s[N+1];

  int64_t sum=0, i=scanf("%s",s);

  char *p,*q,*r;

  for (p=s;*p;p=r) {

    q=l(p,'<'), r=l(q,'>');

    int m=q-p, n=r-q;

    sum += a(m) + a(n) + ((m>n)?m:n);

  }

  printf("%ld\n", sum);

}

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

#include<string>

#include<cstring>

using namespace std;

int main(){

    string a;

    int seq[500005], n, x=-1;

    long long final=0;

    cin >> a;

    n=a.size();

    seq[0]=0;

    memset(seq, 0, sizeof(seq));

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

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

            seq[i+1]=seq[i]+1;

        }

    }

    

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

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

            if(seq[i]<=seq[i+1]){

                seq[i]=seq[i+1]+1;

            }

        }

    }

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

        final+=seq[i];

    }

    cout << final << endl;

    return 0;

}

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

using namespace std;

string s;

long long ans;

int main()

{

    cin>>s;

    int len=s.length();

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

        long long l=0;

        long long r=0;

        while(i<len&&s[i]=='<'){

            l++;

            i++;

        }

        while(i<len&&s[i]=='>'){

            r++;

            i++;

        }

        i--;

        if(l>=r){

            ans+=((l+1)*l)/2;

            r--;

            ans+=((r+1)*r)/2;

        }else{

            ans+=((r+1)*r)/2;

            l--;

            ans+=((l+1)*l)/2;

        }

    }

    printf("%lld",ans);

    return 0;

}

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

#define ll long long

#include <cstring>

using namespace std;



int arr[500005];

int main() {

  string s;

  cin >> s;



  memset(arr, 0, sizeof(arr));



  ll ans = 0;

  int cntr = 0;

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

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

      arr[i+1] = arr[i]+1;

    }

  }



  for (int i = s.length()-1; i >= 0; i--){

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

      if (arr[i] < arr[i+1] + 1)

        arr[i] = arr[i+1] + 1; 

    }

    ans = ans + arr[i];

  }





  cout << ans + arr[s.length()] << endl;

}

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

using namespace std;

string s;

long long ans;

int main()

{

    cin>>s;

    int len=s.length();

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

        long long l=0;

        long long r=0;

        while(i<len&&s[i]=='<'){

            l++;

            i++;

        }

        while(i<len&&s[i]=='>'){

            r++;

            i++;

        }

        i--;

        if(l>=r){

            ans+=((l+1)*l)/2;

            r--;

            ans+=((r+1)*r)/2;

        }else{

            ans+=((r+1)*r)/2;

            l--;

            ans+=((l+1)*l)/2;

        }

    }

    printf("%lld",ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 <cctype>

#include <string>

#include <cstring>

#include <ctime>

using namespace std;

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

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

typedef vector<int> VI; typedef vector<VI> VVI;

typedef vector<string> VS; typedef vector<VS> VVS;

typedef pair<int, int> PII;

typedef long long LL;





int main(){

  LL sum = 0;

  VI num(1000000, 0);

  int i = 0;

  string s;

  cin >> s;



  while (i != (s.size())) {

    int a = 0, b = 0, j = 0;



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

      while (s[i] == '<') { a++; i++; }

      for (j = (i-a); j <= i; j++) num[j] += j - (i-a);

    } else  { 

      while (s[i] == '>') { b++; i++; } 

      for (j = i; j >= (i-b); j--) {

        num[j] = (i - j);

      }

      j++;

      if (j != 0 && num[j] <= num[j-1]) num[j] = (num[j-1] + 1);

    }

  }



  //cout << num[0];

  //rep(i, s.size()) {

  //  cout << " " << s[i] << " " << num[i+1];

  //}

  //cout << endl;



  rep(i,s.size()+1) {

    sum += num[i];

  }

  cout << sum << endl;

  return 0;

}


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

using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  

  string S;

  cin >> S;



  int size = S.length();

  vector<int> vi(size + 1);

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

    if (S[i] == '<') {

      vi[i + 1] = vi[i] + 1;

    }

  }



  reverse(vi.begin(), vi.end());

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

    if (S[size - (i + 1)] == '>') {

      if (vi[i] >= vi[i + 1]) {

        vi[i + 1] = vi[i] + 1;

      }

    }

  }



  long long res = 0;

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

    res += vi[i];

  }

  cout << res << '\n';

}


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

#include <algorithm>

#include <vector>

#include <set>

#include <bitset>



const int MOD = 1e9 + 7;



using namespace std;



long long si = 0;



long long inq(long long a, long long b)

{

    if (b == 0) return 1;

    long long l = inq(a, b / 2);

    if (b % 2) return l * l % MOD * a % MOD;

    return l * l % MOD;

}



const int K = 10000;

vector<long long> dp(K);



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n, k;

    cin >> n >> k;

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

    {

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

        {

            si = (si + j * inq(k + 1, n - 1)) % MOD;

        }

    }

    dp[0] = 1;

    for (int i = n; i >= 1; i--)

    {

        vector<long long> dp2(K);

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

        {

            for (int hv = 0; hv < K; hv++)

            {

                if (dp[hv] != 0)

                {

                    if (a <= i) dp2[hv + (hv + a) / i] = (dp2[hv + (hv + a) / i] + dp[hv]) % MOD;

                    else dp2[hv] = (dp2[hv] + dp[hv]) % MOD;

                }

            }

        }

        dp = dp2;

    }

    long long si2 = 0;

    for (int i = 0; i < K; i++) si2 = (si2 + dp[i] * i) % MOD;

    cout << (si + MOD - si2) % MOD;

}


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

#include <algorithm>

#include <vector>

#include <set>

#include <bitset>



const int MOD = 1e9 + 7;



using namespace std;



long long si = 0;



long long inq(long long a, long long b)

{

    if (b == 0) return 1;

    long long l = inq(a, b / 2);

    if (b % 2) return l * l % MOD * a % MOD;

    return l * l % MOD;

}



const int K = 4000;

vector<long long> dp(K);



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n, k;

    cin >> n >> k;

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

    {

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

        {

            si = (si + j * inq(k + 1, n - 1)) % MOD;

        }

    }

    dp[0] = 1;

    for (int i = n; i >= 1; i--)

    {

        vector<long long> dp2(K);

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

        {

            for (int hv = 0; hv < K; hv++)

            {

                if (dp[hv] != 0)

                {

                    if (a <= i) dp2[hv + (hv + a) / i] = (dp2[hv + (hv + a) / i] + dp[hv]) % MOD;

                    else dp2[hv] = (dp2[hv] + dp[hv]) % MOD;

                }

            }

        }

        dp = dp2;

    }

    long long si2 = 0;

    for (int i = 0; i < K; i++) si2 = (si2 + dp[i] * i) % MOD;

    cout << (si + MOD - si2) % MOD;

}


// Fastest known solution for this problem: