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

using namespace std;

typedef pair<int,int> p;

typedef pair<p,p> P;



char mp[60][30];

int w,h;

int cal(){

  bool used[2][60][30]={};

  int dx[9]={1,1,1,1,1,2,2,2,3},dy[9]={2,1,0,-1,-2,1,0,-1,0};

  priority_queue<P,vector<P>,greater<P> > q;

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

    if(mp[h-1][i]=='S')q.push(P(p(0,0),p(i,h-1))),q.push(P(p(0,1),p(i,h-1)));

  while(!q.empty()){

    int s=q.top().first.first,l=q.top().first.second;

    int x=q.top().second.first,y=q.top().second.second;

    q.pop();

    if(mp[y][x]=='T')return s;

    used[l][y][x]=1;

    int f=1,c=0;

    if(l)f=-1;

    if(isdigit(mp[y][x]))c=mp[y][x]-'0';

    for(int d=0;d<9;d++){

      int nx=x+f*dx[d],ny=y+f*dy[d];

      if(nx<0||w<=nx||ny<0||h<=ny||mp[ny][nx]=='X'||used[!l][ny][nx])continue;

      q.push(P(p(s+c,!l),p(nx,ny)));

    }

  }

  return -1;

}



int main(){

  while(cin>>w>>h,w){

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

      for(int j=0;j<w;j++)cin>>mp[i][j];

    cout<<cal()<<endl;

  }

  return 0;

}

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

using namespace std;

typedef pair<int,int> p;

typedef pair<p,p> P;



char mp[60][30];

int w,h;

int cal(){

  bool used[2][60][30]={};

  int dx[9]={1,1,1,1,1,2,2,2,3},dy[9]={2,1,0,-1,-2,1,0,-1,0};

  priority_queue<P,vector<P>,greater<P> > q;

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

    if(mp[h-1][i]=='S')q.push(P(p(0,0),p(i,h-1))),q.push(P(p(0,1),p(i,h-1)));

  while(!q.empty()){

    int s=q.top().first.first,l=q.top().first.second;

    int x=q.top().second.first,y=q.top().second.second;

    q.pop();

    if(mp[y][x]=='T')return s;

    if(used[l][y][x]||mp[y][x]=='X')continue;

    used[l][y][x]=1;

    int f=1,c=0;

    if(l)f=-1;

    if(isdigit(mp[y][x]))c=mp[y][x]-'0';

    for(int d=0;d<9;d++){

      int nx=x+f*dx[d],ny=y+f*dy[d];

      if(nx<0||w<=nx||ny<0||h<=ny)continue;

      q.push(P(p(s+c,!l),p(nx,ny)));

    }

  }

  return -1;

}



int main(){

  while(cin>>w>>h,w){

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

      for(int j=0;j<w;j++)cin>>mp[i][j];

    cout<<cal()<<endl;

  }

  return 0;

}

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

#include <set>



int a[100000];



int main() {

  int n;

  scanf("%d", &n);

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

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

  int xor_sum = 0;

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

    xor_sum ^= a[i];

  std::set<int> s;

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

    s.insert(a[i] ^ (a[i] - 1));

  int ans = 0;

  for (int bit = 29; bit >= 0; bit--) {

    if (((1 << bit) & xor_sum) == 0) {

      continue;

    }

    int x = (1 << (bit + 1)) - 1;



    if (s.count(x)) {

      xor_sum ^= x;

      ans += 1;

    }

  }



  if (xor_sum != 0) {

    printf("-1\n");

  } else {

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

  }

}

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



int check[30];



int main() {

  for (int bit = 29; bit >= 0; bit--) {

    check[bit] = 0;

  }



  int n;

  scanf("%d", &n);

  int xor_sum = 0;

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

    int a;

    scanf("%d", &a);

    xor_sum ^= a;

    a = a ^ (a - 1);

    for (int bit = 29; bit >= 0; bit--) {

      int x = (1 << (bit + 1)) - 1;

      if (a == x) {

        check[bit] = 1;

      }

    }

  }



  int ans = 0;

  for (int bit = 29; bit >= 0; bit--) {

    if (((1 << bit) & xor_sum) == 0) {

      continue;

    }

    int x = (1 << (bit + 1)) - 1;



    if (check[bit] > 0) {

      xor_sum ^= x;

      ans += 1;

    }

  }



  if (xor_sum != 0) {

    printf("-1\n");

  } else {

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

  }

}

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

using namespace std;

int judge(int a,int b,int c,int l)

{

    int k=0;

    if(a<l)

        k++;

    if(b<l)

        k++;

    if(c<l)

        k++;

    return k;

}

int main()

{

    int a,b,c,sum=0,max1=0;

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

    max1=max(a,b);max1=max(max1,c);

    while((max1-a)>=2)

    {

        a+=2;

        sum++;

    }

    while((max1-b)>=2)

    {

        b+=2;

        sum++;

    }

    while((max1-c)>=2)

    {

        c+=2;

        sum++;

    }



    if(judge(a,b,c,max1)==0)

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

    else if(judge(a,b,c,max1)==2)

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

    else

        printf("%d\n",sum+2);

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int a[5];

int cnt=0;

int main()

{

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

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

	int cnt=0;

	int f=1;

	while(f)

	{

		if(a[1]==a[2]&&a[2]==a[3]) break;

		sort(a+1,a+1+3);

		while(a[1]+2<=a[3])a[1]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		while(a[2]+2<=a[3])a[2]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;

	}

	printf("%d",cnt);

}

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

#include<algorithm>

using namespace std;

int a[3];

int main()

{

    cin>>a[0]>>a[1]>>a[2];

    sort(a,a+3);

    int ans=2*a[2]-a[1]-a[0];

    if (ans%2)

        ans+=3;

    ans/=2;

    cout<<ans<<endl;

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

int a[5];

int cnt=0;

int main()

{

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

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

	int cnt=0;

	int f=1;

	while(f)

	{

		if(a[1]==a[2]&&a[2]==a[3]) break;

		sort(a+1,a+1+3);

		while(a[1]+2<=a[3])a[1]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		while(a[2]+2<=a[3])a[2]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;

	}

	printf("%d",cnt);

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cstdlib>

#include<cmath>

#include<vector>

#include<queue>

#define IO ios::sync_with_stdio(false);cin.tie(0);

const int MOD=1e9+7;

typedef long long ll;

using namespace std;

int a[3], cnt=0;

int main()

{

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

		cin >> a[i];

	}

	sort(a, a+3);

	while(a[0] != a[2]){

		cnt++;

		if(a[1] == a[2] || a[2]-a[0]>1)

			a[0] += 2;

		else a[0]++, a[1]++; 

		sort(a, a+3);

	}

	cout << cnt << endl;

	return 0;

} 

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

#include<cstring>

#include<algorithm>

using namespace std;

int a[5];

int cnt=0;

int main()

{

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

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

	int cnt=0;

	int f=1;

	while(f)

	{

		if(a[1]==a[2]&&a[2]==a[3]) break;

		sort(a+1,a+1+3);

		while(a[1]+2<=a[3])a[1]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		while(a[2]+2<=a[3])a[2]+=2,cnt++;

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if(a[2]==a[3]&&a[1]!=a[2]) a[1]+=2,a[2]+=1,a[3]+=1,cnt+=2;\

		if(a[1]==a[2]&&a[2]==a[3]) break;

		if((a[1]+1<=a[3]&&a[2]+1<=a[3]))a[1]+=1,a[2]+=1,cnt++;

	}

	printf("%d",cnt);

}

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

using namespace std;

const int MAXn = 50 + 5, INF = 1e9;

int dp[MAXn][MAXn][MAXn], a, b, c, res = INF;



int main() {

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

	cin >> a >> b >> c;

	if (a == b && b == c)

		return cout << 0,0;

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

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

			for (int x = 0; x < MAXn; x++)

				dp[i][j][x] = INF;

	dp[a][b][c] = 0;

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

		for (int j = 1; j < MAXn; j++)

			for (int x = 1; x < MAXn; x++) {

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i][j-1][x-1] + 1);

				dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + 1);

				if (i >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i-2][j][x] + 1);

				}

				if (j >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j-2][x] + 1);

				}

				if (x >= 2) {

					dp[i][j][x] = min(dp[i][j][x], dp[i][j][x-2] + 1);

				}

				if (i == j && j == x)

					res = min(res, dp[i][j][x]);

			}

	cout << res;

}


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



using namespace std;



#define int long long



int a[3];

int ans;



int32_t main() {

    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);

    ans = 2 * a[2] - a[1] - a[0];

    return cout << (ans % 2 ? ans / 2 + 2 : ans / 2), 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<queue>

#include<vector>

using namespace std;

#define MOD 7007

struct QUEUE

{

	int a,b,c,tot;

}Push;

int F[6][3]={{1,1,0},{1,0,1},{0,1,1},{2,0,0},{0,2,0},{0,0,2}};

vector<int> Hash[MOD];

bool HASH(int n)

{

	for(int i=0;i<Hash[n%MOD].size();i++)

		if(n==Hash[n%MOD][i])

			return false;

	Hash[n%MOD].push_back(n);

	return true;

}

int main()

{

	Push.tot=0;

	queue<QUEUE> que;

	scanf("%d%d%d",&Push.a,&Push.b,&Push.c);

	que.push(Push);

	while(!que.empty())

	{

		QUEUE Fro=que.front();

		if(Fro.a==Fro.b && Fro.b==Fro.c)

		{

			printf("%d\n",Fro.tot);

			return 0;

		}

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

		{

			Push=Fro;

			Push.tot++;

			Push.a+=F[i][0];Push.b+=F[i][1];Push.c+=F[i][2];

			int n=Push.a*10000+Push.b*100+Push.c;

			if(!HASH(n)) continue;

			que.push(Push);

		}

		que.pop();

	}

	return 0;

}


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

#include<algorithm>

using namespace std;



int main(){

    int A,B,C,Ans=0;

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

    int Max1=max(A,max(B,C));

    int Max2;

    if(A==Max1) Max2=max(B,C);

    else if(B==Max1) Max2=max(A,C);

    else if(C==Max1) Max2=max(A,B);

    int Max3=A+B+C-Max1-Max2;

    int tmp1=Max1-Max2;

    Ans+=tmp1,Max3+=tmp1,Max2+=tmp1;



    if((Max1-Max3)%2) Ans+=(Max1-Max3)/2+2;

    else Ans+=(Max1-Max3)/2;

    printf("%d",Ans);

}

/*

Sample Input 1

2 5 4

Sample Output 1

2



Sample Input 2

2 6 3

Sample Output 2

5



Sample Input 3

31 41 5

Sample Output 3

23

*/


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

#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

    int a,b,c;

    cin>>a>>b>>c;

    int s=max(a,max(b,c));

    int t=3*s-a-b-c;

    if(t%2)

    {

        printf("%d",t/2+2);

    }

    else printf("%d",t/2);

}

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

#include<algorithm>

using namespace std;



int main(){

    int A,B,C,Ans=0;

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

    int Max1=max(A,max(B,C));

    int Max2;

    if(A==Max1) Max2=max(B,C);

    else if(B==Max1) Max2=max(A,C);

    else if(C==Max1) Max2=max(A,B);

    int Max3=A+B+C-Max1-Max2;

    int tmp1=Max1-Max2;

    Ans+=tmp1,Max3+=tmp1,Max2+=tmp1;



    if((Max1-Max3)%2) Ans+=(Max1-Max3)/2+2;

    else Ans+=(Max1-Max3)/2;

    printf("%d",Ans);

}

/*

Sample Input 1

2 5 4

Sample Output 1

2



Sample Input 2

2 6 3

Sample Output 2

5



Sample Input 3

31 41 5

Sample Output 3

23

*/


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

#include<cstdlib>

#include<algorithm>

using namespace std;



int main()

{

    int a[3],count=0,min0,Max,min1,i0,i1;

    cin>>a[0]>>a[1]>>a[2];



   sort(a,a+3);

   while( a[1]!=a[2])

   {

       a[0]++;

       a[1]++;

       count++;

   }

   while(a[0]<a[2])

   {

       a[0]+=2;

       count++;

   }

   if(a[0]>a[2])

   {

       a[1]++;

       a[2]++;

    count++;

   }





    cout<<count<<endl;





}

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



int main()

{	 

	int a, b, c, s = 0; 

	

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

	if(a > b) a ^= b, b ^= a, a ^= b;

	if(b > c) b ^= c, c ^= b, b ^= c;

	if(a > b) a ^= b, b ^= a, a ^= b;

	if((b - a) & 1) b++, c++, s++;

	s += ((b - a) >> 1) + c - b;

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

		

	return 0;

}

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

using namespace std;

int main()

{

    int a,b,c,a1,b1,c1,sum=0;

    cin>>a>>b>>c;

    if(a<b){a1=a;

    a=b;

    b=a1;}

    if(a<c)

    {

        a1=a;

        a=c;

        c=a1;

    }

    if(b<c)

    {

        b1=b;

        b=c;

        c=b1;

    }

    a1=a%2;

    b1=b%2;

    c1=c%2;

    if((a1==0&&b1==0&&c1==0)||(a1==1&&b1==1&&c1==1))

    {

     sum+=(a-b)/2;

     sum+=(a-c)/2;

    }

    else

    {

        if(a1==b1)

        {

            a+=1;

            b+=1;

        }

        else if(a1==c1)

        {

            a+=1;

            c+=1;

        }

        else if(b1==c1)

        {

            b+=1;

            c+=1;

        }

        sum+=(a-b)/2;

        sum+=(a-c)/2;

        sum++;



    }

    cout<<sum<<endl;



}


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



int main()

{	 

	int a, b, c, s = 0; 

	

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

	if(a > b) a ^= b, b ^= a, a ^= b;

	if(b > c) b ^= c, c ^= b, b ^= c;

	if(a > b) a ^= b, b ^= a, a ^= b;

	if((b - a) & 1) b++, c++, s++;

	s += ((b - a) >> 1) + c - b;

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

		

	return 0;

}

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

using namespace std;



int main()

{

	int a[3],ans=0;

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

	cin>>a[i];

	sort(a,a+3);

	int x=a[0],y=a[1],z=a[2];

	x+=z-y;

	ans+=z-y;

	y=z;

	int k=y-x;

	

	if(k%2==0)

	cout<<ans+k/2;

	else

	cout<<ans+k/2+2;

}

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



int main()

{	 

	int a, b, c, s = 0; 

	

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

	if(a > b) a ^= b, b ^= a, a ^= b;

	if(b > c) b ^= c, c ^= b, b ^= c;

	if(a > b) a ^= b, b ^= a, a ^= b;

	if((b - a) & 1) b++, c++, s++;

	s += ((b - a) >> 1) + c - b;

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

		

	return 0;

}

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

#include <queue>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

int vis[110][110][110];

struct node

{

	int a,b,c,s;

	node (int aa,int bb,int cc,int ss):a(aa),b(bb),c(cc),s(ss){}

};

int bfs(int a,int b,int c)

{

	queue<node>q;

	q.push(node(a,b,c,0));

	while(!q.empty())

	{

		node t=q.front();

		q.pop();

		if(t.a==t.b&&t.b==t.c)

			return t.s;

		int x,y,z;

		x=t.a+2;y=t.b;z=t.c;

		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}

		x=t.a;y=t.b+2;z=t.c;	

		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}

		x=t.a;y=t.b;z=t.c+2;

		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}	

		x=t.a+1;y=t.b+1;z=t.c;

		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}

		x=t.a;y=t.b+1;z=t.c+1;

		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}

		x=t.a+1;y=t.b;z=t.c+1;

		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)

		{

			q.push(node(x,y,z,t.s+1));

			vis[x][y][z]=1;

		}		

	}

	return -1;

}

int main()

{

	int x,y,z,ans;

	cin>>x>>y>>z;

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

	vis[x][y][z]=1;

	ans=bfs(x,y,z);

	cout<<ans<<endl;

	return 0;

}

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

int main()

{

	long long max,sum,a,b,c;

	while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)

	{

		max=a>b?a:b;

		max=max>c?max:c;

		sum=(max-a)+(max-b)+(max-c);

		if(sum%2==0)

		printf("%lld\n",sum/2);

		else

		{

			printf("%lld\n",sum/2+2);

		}

	}

	return 0;

 } 

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

using namespace std;

template<class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }



int main() {

    int A, B, C;

    cin >> A >> B >> C;

    int dp[55][55][55];

    fill(dp[0][0], dp[55][0], 1000);

    dp[A][B][C] = 0;

    for(int a = 0; a < 53; ++a) {

        for(int b = 0; b < 53; ++b) {

            for(int c = 0; c < 53; ++c) {

                int tmp = dp[a][b][c] + 1;

                chmin(dp[a][b + 1][c + 1], tmp);

                chmin(dp[a + 1][b][c + 1], tmp);

                chmin(dp[a + 1][b + 1][c], tmp);

                chmin(dp[a + 2][b][c], tmp);

                chmin(dp[a][b + 2][c], tmp);

                chmin(dp[a][b][c + 2], tmp);

            }

        }

    }

    int ans = 1000;

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

        chmin(ans, dp[i][i][i]);

    }

    cout << ans << '\n';

    return 0;

}


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

using namespace std;



int main() {

    vector<int> A(3);

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

        cin >> A[i];

    }

    int ans = 1000;

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

        int tmp = 0;

        bool ng = false;

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

            int dif = i - A[j];

            if(dif < 0) ng = true;

            tmp += dif;

        }

        if(tmp % 2 || ng) continue;

        ans = min(ans, tmp / 2);

    }

    cout << ans << '\n';

    return 0;

}


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

using namespace std;

typedef long long ll;

const int mod=1e9+7;

#define inf 0x3f3f3f3f

int a[15];



int main()

{

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

	cin>>a[i];

	sort(a,a+3);

	int x=a[0],y=a[1],z=a[2];

	int ans=0;

	while(x+2<=y)

	{

		ans++;

		x+=2;

	}

	if(x==y)

	ans+=z-y;

	else

	{

		if(z==y)

		{

			ans+=2;

		}

		else

		{

			ans+=z-y+2;

		}

	 } 

	cout<<ans;

	return 0;

}

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

#include<algorithm>

using namespace std;

int ans;

int main() {

	int a[4];

	scanf("%d%d%d",&a[1],&a[2],&a[3]);

	while(a[1]!=a[2]||a[2]!=a[3]||a[1]!=a[3]) {

		sort(a+1,a+4);

		ans++;

		if(a[2]-a[1]>=2) {

			a[1]+=2;

		}

		else {

			a[1]++;

			a[2]++;

		}

		

	}

	printf("%d",ans);

	return 0;

}

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

#define ha 1000000007

using namespace std;



const int N=2010;

int n,k,f[N][N];



int Pow(int a,int b)

{

	int ans=1;

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

		if(b&1) ans=1ll*ans*a%ha;

	return ans;

}



int main()

{

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

	for(int i=2;i<=n;i++) f[1][i]=1;

	for(int i=1;i<k-1;i++)

	{

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

		for(int j=n-i;j>=2;j--)

			f[i+1][j]=(f[i+1][j+1]+f[i][j])%ha;

	}

	int ans=0;

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

		ans=(ans+f[k-1][i])%ha;

	if(k==1) ans=1;

	if(n-k<=0) printf("%d",ans);

	else printf("%d",1ll*ans*Pow(2,n-1-k)%ha);

	return 0;

}

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

#define mo 1000000007

int n,k,dp[2006][2006],sum[2006];

int main()

{

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

	dp[0][n+1]=1;

	register int i,j;

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

	{

		sum[n+1]=dp[i-1][n+1];

		for(j=n;j>=1;j--) sum[j]=((sum[j+1]%mo)+(dp[i-1][j]%mo))%mo;

		for(j=1;j<=n-i+1;j++) dp[i][j]=sum[j];

	}

	int x=dp[k][1]-dp[k-1][1];

	if(x<0) x+=mo;

	for(i=1;i<=n-k-1;i++) x=(x<<1)%mo;

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

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=4000;

const int mod=1e9+7;

int n,k;



int read()

{

    int x=0,f=1;char ch=getchar();

    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;

    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';

    return x*f;

}



int power(int a,int k)

{

    if(k<0) return 1;

    int sum=1;

    for (;k;k>>=1,a=1ll*a*a%mod)

	if (k&1)

	    sum=1ll*sum*a%mod;

    return sum;

}



int fac[maxn+10],ifac[maxn+10],inv[maxn+10];



int C(int a,int b){return (a<0)||(b<0)||(a<b)?0:1ll*fac[a]*ifac[b]%mod*ifac[a-b]%mod;}



int F(int i,int j){return 1ll*C(i+j,i)*(i-j+1)%mod*inv[i+1]%mod;}



int main()

{

    fac[0]=inv[0]=inv[1]=ifac[0]=1;

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

	{

	    fac[i]=1ll*fac[i-1]*i%mod;

	}

    for(int i=2; i<=maxn; ++i) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;

    for(int i=1; i<=maxn; ++i) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;

    n=read(),k=read();

    printf("%lld\n",1ll*F(n-1,k-1)*power(2,n-k-1)%mod);

    return 0;

}


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

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int mod=1e9+7;

const int maxn=2000;

int n,k;

int f[maxn+8][maxn+8],g[maxn+8][maxn+8];



int read()

{

    int x=0,f=1;char ch=getchar();

    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;

    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';

    return x*f;

}



int power(int a,int k)

{

    if (k<0) return 1;

    int sum=1;

    for (;k;k>>=1,a=1ll*a*a%mod)

    if (k&1)

        sum=1ll*sum*a%mod;

    return sum;

}



int main()

{

    n=read(),k=read();

    g[0][0]=1;

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

	{

	    f[i][0]=g[i-1][0];

	    g[i][0]=f[i][0];

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

		{

		    f[i][j]=g[i-1][j];

		    g[i][j]=(g[i][j-1]+f[i][j])%mod;

		}

	}

    //for (int i=0;i<n;i++) printf("%d ",g[n-1][i]);

    int ans=g[n-1][k-1];

    ans=1ll*ans*power(2,n-k-1)%mod;

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

    return 0;

}



    


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

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=4000;

const int mod=1e9+7;

int n,k;



int read()

{

    int x=0,f=1;char ch=getchar();

    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;

    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';

    return x*f;

}



int power(int a,int k)

{

    if(k<0) return 1;

    int sum=1;

    for (;k;k>>=1,a=1ll*a*a%mod)

    if (k&1)

        sum=1ll*sum*a%mod;

    return sum;

}



int fac[maxn+10],ifac[maxn+10],inv[maxn+10];



int C(int a,int b){return (a<0)||(b<0)||(a<b)?0:1ll*fac[a]*ifac[b]%mod*ifac[a-b]%mod;}



int F(int i,int j){return (C(i+j,i)-C(i+j,i+1)+mod)%mod;}



int main()

{

    fac[0]=inv[0]=inv[1]=ifac[0]=1;

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

    {

        fac[i]=1ll*fac[i-1]*i%mod;

    }

    for(int i=2; i<=maxn; ++i) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;

    for(int i=1; i<=maxn; ++i) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;

    n=read(),k=read();

    printf("%lld\n",1ll*F(n-1,k-1)*power(2,n-k-1)%mod);

    return 0;

}


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

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int mod=1e9+7;

const int maxn=2000;

int n,k;

int f[maxn+8][maxn+8],g[maxn+8][maxn+8];



int read()

{

    int x=0,f=1;char ch=getchar();

    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;

    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';

    return x*f;

}



int power(int a,int k)

{

    if (k<0) return 1;

    int sum=1;

    for (;k;k>>=1,a=1ll*a*a%mod)

    if (k&1)

        sum=1ll*sum*a%mod;

    return sum;

}



int main()

{

    n=read(),k=read();

    g[0][0]=1;

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

	{

	    f[i][0]=g[i-1][0];

	    g[i][0]=f[i][0];

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

		{

		    f[i][j]=g[i-1][j];

		    g[i][j]=(g[i][j-1]+f[i][j])%mod;

		}

	}

    //for (int i=0;i<n;i++) printf("%d ",g[n-1][i]);

    int ans=g[n-1][k-1];

    ans=1ll*ans*power(2,n-k-1)%mod;

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

    return 0;

}



    


// Fastest known solution for this problem: